1 /* MIPS-specific support for ELF
2 Copyright (C) 1993-2020 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 "ecoff-bfd.h"
37 #include "elfxx-mips.h"
39 #include "elf-vxworks.h"
42 /* Get the ECOFF swapping routines. */
44 #include "coff/symconst.h"
45 #include "coff/ecoff.h"
46 #include "coff/mips.h"
50 /* Types of TLS GOT entry. */
51 enum mips_got_tls_type
{
58 /* This structure is used to hold information about one GOT entry.
59 There are four types of entry:
61 (1) an absolute address
62 requires: abfd == NULL
65 (2) a SYMBOL + OFFSET address, where SYMBOL is local to an input bfd
66 requires: abfd != NULL, symndx >= 0, tls_type != GOT_TLS_LDM
67 fields: abfd, symndx, d.addend, tls_type
69 (3) a SYMBOL address, where SYMBOL is not local to an input bfd
70 requires: abfd != NULL, symndx == -1
74 requires: abfd != NULL, symndx == 0, tls_type == GOT_TLS_LDM
75 fields: none; there's only one of these per GOT. */
78 /* One input bfd that needs the GOT entry. */
80 /* The index of the symbol, as stored in the relocation r_info, if
81 we have a local symbol; -1 otherwise. */
85 /* If abfd == NULL, an address that must be stored in the got. */
87 /* If abfd != NULL && symndx != -1, the addend of the relocation
88 that should be added to the symbol value. */
90 /* If abfd != NULL && symndx == -1, the hash table entry
91 corresponding to a symbol in the GOT. The symbol's entry
92 is in the local area if h->global_got_area is GGA_NONE,
93 otherwise it is in the global area. */
94 struct mips_elf_link_hash_entry
*h
;
97 /* The TLS type of this GOT entry. An LDM GOT entry will be a local
98 symbol entry with r_symndx == 0. */
99 unsigned char tls_type
;
101 /* True if we have filled in the GOT contents for a TLS entry,
102 and created the associated relocations. */
103 unsigned char tls_initialized
;
105 /* The offset from the beginning of the .got section to the entry
106 corresponding to this symbol+addend. If it's a global symbol
107 whose offset is yet to be decided, it's going to be -1. */
111 /* This structure represents a GOT page reference from an input bfd.
112 Each instance represents a symbol + ADDEND, where the representation
113 of the symbol depends on whether it is local to the input bfd.
114 If it is, then SYMNDX >= 0, and the symbol has index SYMNDX in U.ABFD.
115 Otherwise, SYMNDX < 0 and U.H points to the symbol's hash table entry.
117 Page references with SYMNDX >= 0 always become page references
118 in the output. Page references with SYMNDX < 0 only become page
119 references if the symbol binds locally; in other cases, the page
120 reference decays to a global GOT reference. */
121 struct mips_got_page_ref
126 struct mips_elf_link_hash_entry
*h
;
132 /* This structure describes a range of addends: [MIN_ADDEND, MAX_ADDEND].
133 The structures form a non-overlapping list that is sorted by increasing
135 struct mips_got_page_range
137 struct mips_got_page_range
*next
;
138 bfd_signed_vma min_addend
;
139 bfd_signed_vma max_addend
;
142 /* This structure describes the range of addends that are applied to page
143 relocations against a given section. */
144 struct mips_got_page_entry
146 /* The section that these entries are based on. */
148 /* The ranges for this page entry. */
149 struct mips_got_page_range
*ranges
;
150 /* The maximum number of page entries needed for RANGES. */
154 /* This structure is used to hold .got information when linking. */
158 /* The number of global .got entries. */
159 unsigned int global_gotno
;
160 /* The number of global .got entries that are in the GGA_RELOC_ONLY area. */
161 unsigned int reloc_only_gotno
;
162 /* The number of .got slots used for TLS. */
163 unsigned int tls_gotno
;
164 /* The first unused TLS .got entry. Used only during
165 mips_elf_initialize_tls_index. */
166 unsigned int tls_assigned_gotno
;
167 /* The number of local .got entries, eventually including page entries. */
168 unsigned int local_gotno
;
169 /* The maximum number of page entries needed. */
170 unsigned int page_gotno
;
171 /* The number of relocations needed for the GOT entries. */
173 /* The first unused local .got entry. */
174 unsigned int assigned_low_gotno
;
175 /* The last unused local .got entry. */
176 unsigned int assigned_high_gotno
;
177 /* A hash table holding members of the got. */
178 struct htab
*got_entries
;
179 /* A hash table holding mips_got_page_ref structures. */
180 struct htab
*got_page_refs
;
181 /* A hash table of mips_got_page_entry structures. */
182 struct htab
*got_page_entries
;
183 /* In multi-got links, a pointer to the next got (err, rather, most
184 of the time, it points to the previous got). */
185 struct mips_got_info
*next
;
188 /* Structure passed when merging bfds' gots. */
190 struct mips_elf_got_per_bfd_arg
192 /* The output bfd. */
194 /* The link information. */
195 struct bfd_link_info
*info
;
196 /* A pointer to the primary got, i.e., the one that's going to get
197 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
199 struct mips_got_info
*primary
;
200 /* A non-primary got we're trying to merge with other input bfd's
202 struct mips_got_info
*current
;
203 /* The maximum number of got entries that can be addressed with a
205 unsigned int max_count
;
206 /* The maximum number of page entries needed by each got. */
207 unsigned int max_pages
;
208 /* The total number of global entries which will live in the
209 primary got and be automatically relocated. This includes
210 those not referenced by the primary GOT but included in
212 unsigned int global_count
;
215 /* A structure used to pass information to htab_traverse callbacks
216 when laying out the GOT. */
218 struct mips_elf_traverse_got_arg
220 struct bfd_link_info
*info
;
221 struct mips_got_info
*g
;
225 struct _mips_elf_section_data
227 struct bfd_elf_section_data elf
;
234 #define mips_elf_section_data(sec) \
235 ((struct _mips_elf_section_data *) elf_section_data (sec))
237 #define is_mips_elf(bfd) \
238 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
239 && elf_tdata (bfd) != NULL \
240 && elf_object_id (bfd) == MIPS_ELF_DATA)
242 /* The ABI says that every symbol used by dynamic relocations must have
243 a global GOT entry. Among other things, this provides the dynamic
244 linker with a free, directly-indexed cache. The GOT can therefore
245 contain symbols that are not referenced by GOT relocations themselves
246 (in other words, it may have symbols that are not referenced by things
247 like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
249 GOT relocations are less likely to overflow if we put the associated
250 GOT entries towards the beginning. We therefore divide the global
251 GOT entries into two areas: "normal" and "reloc-only". Entries in
252 the first area can be used for both dynamic relocations and GP-relative
253 accesses, while those in the "reloc-only" area are for dynamic
256 These GGA_* ("Global GOT Area") values are organised so that lower
257 values are more general than higher values. Also, non-GGA_NONE
258 values are ordered by the position of the area in the GOT. */
260 #define GGA_RELOC_ONLY 1
263 /* Information about a non-PIC interface to a PIC function. There are
264 two ways of creating these interfaces. The first is to add:
267 addiu $25,$25,%lo(func)
269 immediately before a PIC function "func". The second is to add:
273 addiu $25,$25,%lo(func)
275 to a separate trampoline section.
277 Stubs of the first kind go in a new section immediately before the
278 target function. Stubs of the second kind go in a single section
279 pointed to by the hash table's "strampoline" field. */
280 struct mips_elf_la25_stub
{
281 /* The generated section that contains this stub. */
282 asection
*stub_section
;
284 /* The offset of the stub from the start of STUB_SECTION. */
287 /* One symbol for the original function. Its location is available
288 in H->root.root.u.def. */
289 struct mips_elf_link_hash_entry
*h
;
292 /* Macros for populating a mips_elf_la25_stub. */
294 #define LA25_LUI(VAL) (0x3c190000 | (VAL)) /* lui t9,VAL */
295 #define LA25_J(VAL) (0x08000000 | (((VAL) >> 2) & 0x3ffffff)) /* j VAL */
296 #define LA25_BC(VAL) (0xc8000000 | (((VAL) >> 2) & 0x3ffffff)) /* bc VAL */
297 #define LA25_ADDIU(VAL) (0x27390000 | (VAL)) /* addiu t9,t9,VAL */
298 #define LA25_LUI_MICROMIPS(VAL) \
299 (0x41b90000 | (VAL)) /* lui t9,VAL */
300 #define LA25_J_MICROMIPS(VAL) \
301 (0xd4000000 | (((VAL) >> 1) & 0x3ffffff)) /* j VAL */
302 #define LA25_ADDIU_MICROMIPS(VAL) \
303 (0x33390000 | (VAL)) /* addiu t9,t9,VAL */
305 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
306 the dynamic symbols. */
308 struct mips_elf_hash_sort_data
310 /* The symbol in the global GOT with the lowest dynamic symbol table
312 struct elf_link_hash_entry
*low
;
313 /* The least dynamic symbol table index corresponding to a non-TLS
314 symbol with a GOT entry. */
315 bfd_size_type min_got_dynindx
;
316 /* The greatest dynamic symbol table index corresponding to a symbol
317 with a GOT entry that is not referenced (e.g., a dynamic symbol
318 with dynamic relocations pointing to it from non-primary GOTs). */
319 bfd_size_type max_unref_got_dynindx
;
320 /* The greatest dynamic symbol table index corresponding to a local
322 bfd_size_type max_local_dynindx
;
323 /* The greatest dynamic symbol table index corresponding to an external
324 symbol without a GOT entry. */
325 bfd_size_type max_non_got_dynindx
;
326 /* If non-NULL, output BFD for .MIPS.xhash finalization. */
328 /* If non-NULL, pointer to contents of .MIPS.xhash for filling in
329 real final dynindx. */
333 /* We make up to two PLT entries if needed, one for standard MIPS code
334 and one for compressed code, either a MIPS16 or microMIPS one. We
335 keep a separate record of traditional lazy-binding stubs, for easier
340 /* Traditional SVR4 stub offset, or -1 if none. */
343 /* Standard PLT entry offset, or -1 if none. */
346 /* Compressed PLT entry offset, or -1 if none. */
349 /* The corresponding .got.plt index, or -1 if none. */
350 bfd_vma gotplt_index
;
352 /* Whether we need a standard PLT entry. */
353 unsigned int need_mips
: 1;
355 /* Whether we need a compressed PLT entry. */
356 unsigned int need_comp
: 1;
359 /* The MIPS ELF linker needs additional information for each symbol in
360 the global hash table. */
362 struct mips_elf_link_hash_entry
364 struct elf_link_hash_entry root
;
366 /* External symbol information. */
369 /* The la25 stub we have created for ths symbol, if any. */
370 struct mips_elf_la25_stub
*la25_stub
;
372 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
374 unsigned int possibly_dynamic_relocs
;
376 /* If there is a stub that 32 bit functions should use to call this
377 16 bit function, this points to the section containing the stub. */
380 /* If there is a stub that 16 bit functions should use to call this
381 32 bit function, this points to the section containing the stub. */
384 /* This is like the call_stub field, but it is used if the function
385 being called returns a floating point value. */
386 asection
*call_fp_stub
;
388 /* If non-zero, location in .MIPS.xhash to write real final dynindx. */
389 bfd_vma mipsxhash_loc
;
391 /* The highest GGA_* value that satisfies all references to this symbol. */
392 unsigned int global_got_area
: 2;
394 /* True if all GOT relocations against this symbol are for calls. This is
395 a looser condition than no_fn_stub below, because there may be other
396 non-call non-GOT relocations against the symbol. */
397 unsigned int got_only_for_calls
: 1;
399 /* True if one of the relocations described by possibly_dynamic_relocs
400 is against a readonly section. */
401 unsigned int readonly_reloc
: 1;
403 /* True if there is a relocation against this symbol that must be
404 resolved by the static linker (in other words, if the relocation
405 cannot possibly be made dynamic). */
406 unsigned int has_static_relocs
: 1;
408 /* True if we must not create a .MIPS.stubs entry for this symbol.
409 This is set, for example, if there are relocations related to
410 taking the function's address, i.e. any but R_MIPS_CALL*16 ones.
411 See "MIPS ABI Supplement, 3rd Edition", p. 4-20. */
412 unsigned int no_fn_stub
: 1;
414 /* Whether we need the fn_stub; this is true if this symbol appears
415 in any relocs other than a 16 bit call. */
416 unsigned int need_fn_stub
: 1;
418 /* True if this symbol is referenced by branch relocations from
419 any non-PIC input file. This is used to determine whether an
420 la25 stub is required. */
421 unsigned int has_nonpic_branches
: 1;
423 /* Does this symbol need a traditional MIPS lazy-binding stub
424 (as opposed to a PLT entry)? */
425 unsigned int needs_lazy_stub
: 1;
427 /* Does this symbol resolve to a PLT entry? */
428 unsigned int use_plt_entry
: 1;
431 /* MIPS ELF linker hash table. */
433 struct mips_elf_link_hash_table
435 struct elf_link_hash_table root
;
437 /* The number of .rtproc entries. */
438 bfd_size_type procedure_count
;
440 /* The size of the .compact_rel section (if SGI_COMPAT). */
441 bfd_size_type compact_rel_size
;
443 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic entry
444 is set to the address of __rld_obj_head as in IRIX5 and IRIX6. */
445 bfd_boolean use_rld_obj_head
;
447 /* The __rld_map or __rld_obj_head symbol. */
448 struct elf_link_hash_entry
*rld_symbol
;
450 /* This is set if we see any mips16 stub sections. */
451 bfd_boolean mips16_stubs_seen
;
453 /* True if we can generate copy relocs and PLTs. */
454 bfd_boolean use_plts_and_copy_relocs
;
456 /* True if we can only use 32-bit microMIPS instructions. */
459 /* True if we suppress checks for invalid branches between ISA modes. */
460 bfd_boolean ignore_branch_isa
;
462 /* True if we are targetting R6 compact branches. */
463 bfd_boolean compact_branches
;
465 /* True if we already reported the small-data section overflow. */
466 bfd_boolean small_data_overflow_reported
;
468 /* True if we use the special `__gnu_absolute_zero' symbol. */
469 bfd_boolean use_absolute_zero
;
471 /* True if we have been configured for a GNU target. */
472 bfd_boolean gnu_target
;
474 /* Shortcuts to some dynamic sections, or NULL if they are not
479 /* The master GOT information. */
480 struct mips_got_info
*got_info
;
482 /* The global symbol in the GOT with the lowest index in the dynamic
484 struct elf_link_hash_entry
*global_gotsym
;
486 /* The size of the PLT header in bytes. */
487 bfd_vma plt_header_size
;
489 /* The size of a standard PLT entry in bytes. */
490 bfd_vma plt_mips_entry_size
;
492 /* The size of a compressed PLT entry in bytes. */
493 bfd_vma plt_comp_entry_size
;
495 /* The offset of the next standard PLT entry to create. */
496 bfd_vma plt_mips_offset
;
498 /* The offset of the next compressed PLT entry to create. */
499 bfd_vma plt_comp_offset
;
501 /* The index of the next .got.plt entry to create. */
502 bfd_vma plt_got_index
;
504 /* The number of functions that need a lazy-binding stub. */
505 bfd_vma lazy_stub_count
;
507 /* The size of a function stub entry in bytes. */
508 bfd_vma function_stub_size
;
510 /* The number of reserved entries at the beginning of the GOT. */
511 unsigned int reserved_gotno
;
513 /* The section used for mips_elf_la25_stub trampolines.
514 See the comment above that structure for details. */
515 asection
*strampoline
;
517 /* A table of mips_elf_la25_stubs, indexed by (input_section, offset)
521 /* A function FN (NAME, IS, OS) that creates a new input section
522 called NAME and links it to output section OS. If IS is nonnull,
523 the new section should go immediately before it, otherwise it
524 should go at the (current) beginning of OS.
526 The function returns the new section on success, otherwise it
528 asection
*(*add_stub_section
) (const char *, asection
*, asection
*);
530 /* Is the PLT header compressed? */
531 unsigned int plt_header_is_comp
: 1;
534 /* Get the MIPS ELF linker hash table from a link_info structure. */
536 #define mips_elf_hash_table(p) \
537 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
538 == MIPS_ELF_DATA ? ((struct mips_elf_link_hash_table *) ((p)->hash)) : NULL)
540 /* A structure used to communicate with htab_traverse callbacks. */
541 struct mips_htab_traverse_info
543 /* The usual link-wide information. */
544 struct bfd_link_info
*info
;
547 /* Starts off FALSE and is set to TRUE if the link should be aborted. */
551 /* MIPS ELF private object data. */
553 struct mips_elf_obj_tdata
555 /* Generic ELF private object data. */
556 struct elf_obj_tdata root
;
558 /* Input BFD providing Tag_GNU_MIPS_ABI_FP attribute for output. */
561 /* Input BFD providing Tag_GNU_MIPS_ABI_MSA attribute for output. */
564 /* The abiflags for this object. */
565 Elf_Internal_ABIFlags_v0 abiflags
;
566 bfd_boolean abiflags_valid
;
568 /* The GOT requirements of input bfds. */
569 struct mips_got_info
*got
;
571 /* Used by _bfd_mips_elf_find_nearest_line. The structure could be
572 included directly in this one, but there's no point to wasting
573 the memory just for the infrequently called find_nearest_line. */
574 struct mips_elf_find_line
*find_line_info
;
576 /* An array of stub sections indexed by symbol number. */
577 asection
**local_stubs
;
578 asection
**local_call_stubs
;
580 /* The Irix 5 support uses two virtual sections, which represent
581 text/data symbols defined in dynamic objects. */
582 asymbol
*elf_data_symbol
;
583 asymbol
*elf_text_symbol
;
584 asection
*elf_data_section
;
585 asection
*elf_text_section
;
588 /* Get MIPS ELF private object data from BFD's tdata. */
590 #define mips_elf_tdata(bfd) \
591 ((struct mips_elf_obj_tdata *) (bfd)->tdata.any)
593 #define TLS_RELOC_P(r_type) \
594 (r_type == R_MIPS_TLS_DTPMOD32 \
595 || r_type == R_MIPS_TLS_DTPMOD64 \
596 || r_type == R_MIPS_TLS_DTPREL32 \
597 || r_type == R_MIPS_TLS_DTPREL64 \
598 || r_type == R_MIPS_TLS_GD \
599 || r_type == R_MIPS_TLS_LDM \
600 || r_type == R_MIPS_TLS_DTPREL_HI16 \
601 || r_type == R_MIPS_TLS_DTPREL_LO16 \
602 || r_type == R_MIPS_TLS_GOTTPREL \
603 || r_type == R_MIPS_TLS_TPREL32 \
604 || r_type == R_MIPS_TLS_TPREL64 \
605 || r_type == R_MIPS_TLS_TPREL_HI16 \
606 || r_type == R_MIPS_TLS_TPREL_LO16 \
607 || r_type == R_MIPS16_TLS_GD \
608 || r_type == R_MIPS16_TLS_LDM \
609 || r_type == R_MIPS16_TLS_DTPREL_HI16 \
610 || r_type == R_MIPS16_TLS_DTPREL_LO16 \
611 || r_type == R_MIPS16_TLS_GOTTPREL \
612 || r_type == R_MIPS16_TLS_TPREL_HI16 \
613 || r_type == R_MIPS16_TLS_TPREL_LO16 \
614 || r_type == R_MICROMIPS_TLS_GD \
615 || r_type == R_MICROMIPS_TLS_LDM \
616 || r_type == R_MICROMIPS_TLS_DTPREL_HI16 \
617 || r_type == R_MICROMIPS_TLS_DTPREL_LO16 \
618 || r_type == R_MICROMIPS_TLS_GOTTPREL \
619 || r_type == R_MICROMIPS_TLS_TPREL_HI16 \
620 || r_type == R_MICROMIPS_TLS_TPREL_LO16)
622 /* Structure used to pass information to mips_elf_output_extsym. */
627 struct bfd_link_info
*info
;
628 struct ecoff_debug_info
*debug
;
629 const struct ecoff_debug_swap
*swap
;
633 /* The names of the runtime procedure table symbols used on IRIX5. */
635 static const char * const mips_elf_dynsym_rtproc_names
[] =
638 "_procedure_string_table",
639 "_procedure_table_size",
643 /* These structures are used to generate the .compact_rel section on
648 unsigned long id1
; /* Always one? */
649 unsigned long num
; /* Number of compact relocation entries. */
650 unsigned long id2
; /* Always two? */
651 unsigned long offset
; /* The file offset of the first relocation. */
652 unsigned long reserved0
; /* Zero? */
653 unsigned long reserved1
; /* Zero? */
662 bfd_byte reserved0
[4];
663 bfd_byte reserved1
[4];
664 } Elf32_External_compact_rel
;
668 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
669 unsigned int rtype
: 4; /* Relocation types. See below. */
670 unsigned int dist2to
: 8;
671 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
672 unsigned long konst
; /* KONST field. See below. */
673 unsigned long vaddr
; /* VADDR to be relocated. */
678 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
679 unsigned int rtype
: 4; /* Relocation types. See below. */
680 unsigned int dist2to
: 8;
681 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
682 unsigned long konst
; /* KONST field. See below. */
690 } Elf32_External_crinfo
;
696 } Elf32_External_crinfo2
;
698 /* These are the constants used to swap the bitfields in a crinfo. */
700 #define CRINFO_CTYPE (0x1)
701 #define CRINFO_CTYPE_SH (31)
702 #define CRINFO_RTYPE (0xf)
703 #define CRINFO_RTYPE_SH (27)
704 #define CRINFO_DIST2TO (0xff)
705 #define CRINFO_DIST2TO_SH (19)
706 #define CRINFO_RELVADDR (0x7ffff)
707 #define CRINFO_RELVADDR_SH (0)
709 /* A compact relocation info has long (3 words) or short (2 words)
710 formats. A short format doesn't have VADDR field and relvaddr
711 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
712 #define CRF_MIPS_LONG 1
713 #define CRF_MIPS_SHORT 0
715 /* There are 4 types of compact relocation at least. The value KONST
716 has different meaning for each type:
719 CT_MIPS_REL32 Address in data
720 CT_MIPS_WORD Address in word (XXX)
721 CT_MIPS_GPHI_LO GP - vaddr
722 CT_MIPS_JMPAD Address to jump
725 #define CRT_MIPS_REL32 0xa
726 #define CRT_MIPS_WORD 0xb
727 #define CRT_MIPS_GPHI_LO 0xc
728 #define CRT_MIPS_JMPAD 0xd
730 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
731 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
732 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
733 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
735 /* The structure of the runtime procedure descriptor created by the
736 loader for use by the static exception system. */
738 typedef struct runtime_pdr
{
739 bfd_vma adr
; /* Memory address of start of procedure. */
740 long regmask
; /* Save register mask. */
741 long regoffset
; /* Save register offset. */
742 long fregmask
; /* Save floating point register mask. */
743 long fregoffset
; /* Save floating point register offset. */
744 long frameoffset
; /* Frame size. */
745 short framereg
; /* Frame pointer register. */
746 short pcreg
; /* Offset or reg of return pc. */
747 long irpss
; /* Index into the runtime string table. */
749 struct exception_info
*exception_info
;/* Pointer to exception array. */
751 #define cbRPDR sizeof (RPDR)
752 #define rpdNil ((pRPDR) 0)
754 static struct mips_got_entry
*mips_elf_create_local_got_entry
755 (bfd
*, struct bfd_link_info
*, bfd
*, bfd_vma
, unsigned long,
756 struct mips_elf_link_hash_entry
*, int);
757 static bfd_boolean mips_elf_sort_hash_table_f
758 (struct mips_elf_link_hash_entry
*, void *);
759 static bfd_vma mips_elf_high
761 static bfd_boolean mips_elf_create_dynamic_relocation
762 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
763 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
764 bfd_vma
*, asection
*);
765 static bfd_vma mips_elf_adjust_gp
766 (bfd
*, struct mips_got_info
*, bfd
*);
768 /* This will be used when we sort the dynamic relocation records. */
769 static bfd
*reldyn_sorting_bfd
;
771 /* True if ABFD is for CPUs with load interlocking that include
772 non-MIPS1 CPUs and R3900. */
773 #define LOAD_INTERLOCKS_P(abfd) \
774 ( ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) != E_MIPS_ARCH_1) \
775 || ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_3900))
777 /* True if ABFD is for CPUs that are faster if JAL is converted to BAL.
778 This should be safe for all architectures. We enable this predicate
779 for RM9000 for now. */
780 #define JAL_TO_BAL_P(abfd) \
781 ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_9000)
783 /* True if ABFD is for CPUs that are faster if JALR is converted to BAL.
784 This should be safe for all architectures. We enable this predicate for
786 #define JALR_TO_BAL_P(abfd) 1
788 /* True if ABFD is for CPUs that are faster if JR is converted to B.
789 This should be safe for all architectures. We enable this predicate for
791 #define JR_TO_B_P(abfd) 1
793 /* True if ABFD is a PIC object. */
794 #define PIC_OBJECT_P(abfd) \
795 ((elf_elfheader (abfd)->e_flags & EF_MIPS_PIC) != 0)
797 /* Nonzero if ABFD is using the O32 ABI. */
798 #define ABI_O32_P(abfd) \
799 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O32)
801 /* Nonzero if ABFD is using the N32 ABI. */
802 #define ABI_N32_P(abfd) \
803 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
805 /* Nonzero if ABFD is using the N64 ABI. */
806 #define ABI_64_P(abfd) \
807 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
809 /* Nonzero if ABFD is using NewABI conventions. */
810 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
812 /* Nonzero if ABFD has microMIPS code. */
813 #define MICROMIPS_P(abfd) \
814 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) != 0)
816 /* Nonzero if ABFD is MIPS R6. */
817 #define MIPSR6_P(abfd) \
818 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32R6 \
819 || (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64R6)
821 /* The IRIX compatibility level we are striving for. */
822 #define IRIX_COMPAT(abfd) \
823 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
825 /* Whether we are trying to be compatible with IRIX at all. */
826 #define SGI_COMPAT(abfd) \
827 (IRIX_COMPAT (abfd) != ict_none)
829 /* The name of the options section. */
830 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
831 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
833 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
834 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
835 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
836 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
838 /* True if NAME is the recognized name of any SHT_MIPS_ABIFLAGS section. */
839 #define MIPS_ELF_ABIFLAGS_SECTION_NAME_P(NAME) \
840 (strcmp (NAME, ".MIPS.abiflags") == 0)
842 /* Whether the section is readonly. */
843 #define MIPS_ELF_READONLY_SECTION(sec) \
844 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
845 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
847 /* The name of the stub section. */
848 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
850 /* The size of an external REL relocation. */
851 #define MIPS_ELF_REL_SIZE(abfd) \
852 (get_elf_backend_data (abfd)->s->sizeof_rel)
854 /* The size of an external RELA relocation. */
855 #define MIPS_ELF_RELA_SIZE(abfd) \
856 (get_elf_backend_data (abfd)->s->sizeof_rela)
858 /* The size of an external dynamic table entry. */
859 #define MIPS_ELF_DYN_SIZE(abfd) \
860 (get_elf_backend_data (abfd)->s->sizeof_dyn)
862 /* The size of a GOT entry. */
863 #define MIPS_ELF_GOT_SIZE(abfd) \
864 (get_elf_backend_data (abfd)->s->arch_size / 8)
866 /* The size of the .rld_map section. */
867 #define MIPS_ELF_RLD_MAP_SIZE(abfd) \
868 (get_elf_backend_data (abfd)->s->arch_size / 8)
870 /* The size of a symbol-table entry. */
871 #define MIPS_ELF_SYM_SIZE(abfd) \
872 (get_elf_backend_data (abfd)->s->sizeof_sym)
874 /* The default alignment for sections, as a power of two. */
875 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
876 (get_elf_backend_data (abfd)->s->log_file_align)
878 /* Get word-sized data. */
879 #define MIPS_ELF_GET_WORD(abfd, ptr) \
880 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
882 /* Put out word-sized data. */
883 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
885 ? bfd_put_64 (abfd, val, ptr) \
886 : bfd_put_32 (abfd, val, ptr))
888 /* The opcode for word-sized loads (LW or LD). */
889 #define MIPS_ELF_LOAD_WORD(abfd) \
890 (ABI_64_P (abfd) ? 0xdc000000 : 0x8c000000)
892 /* Add a dynamic symbol table-entry. */
893 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
894 _bfd_elf_add_dynamic_entry (info, tag, val)
896 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
897 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (abfd, rtype, rela))
899 /* The name of the dynamic relocation section. */
900 #define MIPS_ELF_REL_DYN_NAME(INFO) \
901 (mips_elf_hash_table (INFO)->root.target_os == is_vxworks \
902 ? ".rela.dyn" : ".rel.dyn")
904 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
905 from smaller values. Start with zero, widen, *then* decrement. */
906 #define MINUS_ONE (((bfd_vma)0) - 1)
907 #define MINUS_TWO (((bfd_vma)0) - 2)
909 /* The value to write into got[1] for SVR4 targets, to identify it is
910 a GNU object. The dynamic linker can then use got[1] to store the
912 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
913 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
915 /* The offset of $gp from the beginning of the .got section. */
916 #define ELF_MIPS_GP_OFFSET(INFO) \
917 (mips_elf_hash_table (INFO)->root.target_os == is_vxworks \
920 /* The maximum size of the GOT for it to be addressable using 16-bit
922 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
924 /* Instructions which appear in a stub. */
925 #define STUB_LW(abfd) \
927 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
928 : 0x8f998010)) /* lw t9,0x8010(gp) */
929 #define STUB_MOVE 0x03e07825 /* or t7,ra,zero */
930 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
931 #define STUB_JALR 0x0320f809 /* jalr ra,t9 */
932 #define STUB_JALRC 0xf8190000 /* jalrc ra,t9 */
933 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
934 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
935 #define STUB_LI16S(abfd, VAL) \
937 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
938 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
940 /* Likewise for the microMIPS ASE. */
941 #define STUB_LW_MICROMIPS(abfd) \
943 ? 0xdf3c8010 /* ld t9,0x8010(gp) */ \
944 : 0xff3c8010) /* lw t9,0x8010(gp) */
945 #define STUB_MOVE_MICROMIPS 0x0dff /* move t7,ra */
946 #define STUB_MOVE32_MICROMIPS 0x001f7a90 /* or t7,ra,zero */
947 #define STUB_LUI_MICROMIPS(VAL) \
948 (0x41b80000 + (VAL)) /* lui t8,VAL */
949 #define STUB_JALR_MICROMIPS 0x45d9 /* jalr t9 */
950 #define STUB_JALR32_MICROMIPS 0x03f90f3c /* jalr ra,t9 */
951 #define STUB_ORI_MICROMIPS(VAL) \
952 (0x53180000 + (VAL)) /* ori t8,t8,VAL */
953 #define STUB_LI16U_MICROMIPS(VAL) \
954 (0x53000000 + (VAL)) /* ori t8,zero,VAL unsigned */
955 #define STUB_LI16S_MICROMIPS(abfd, VAL) \
957 ? 0x5f000000 + (VAL) /* daddiu t8,zero,VAL sign extended */ \
958 : 0x33000000 + (VAL)) /* addiu t8,zero,VAL sign extended */
960 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
961 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
962 #define MICROMIPS_FUNCTION_STUB_NORMAL_SIZE 12
963 #define MICROMIPS_FUNCTION_STUB_BIG_SIZE 16
964 #define MICROMIPS_INSN32_FUNCTION_STUB_NORMAL_SIZE 16
965 #define MICROMIPS_INSN32_FUNCTION_STUB_BIG_SIZE 20
967 /* The name of the dynamic interpreter. This is put in the .interp
970 #define ELF_DYNAMIC_INTERPRETER(abfd) \
971 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
972 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
973 : "/usr/lib/libc.so.1")
976 #define MNAME(bfd,pre,pos) \
977 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
978 #define ELF_R_SYM(bfd, i) \
979 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
980 #define ELF_R_TYPE(bfd, i) \
981 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
982 #define ELF_R_INFO(bfd, s, t) \
983 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
985 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
986 #define ELF_R_SYM(bfd, i) \
988 #define ELF_R_TYPE(bfd, i) \
990 #define ELF_R_INFO(bfd, s, t) \
991 (ELF32_R_INFO (s, t))
994 /* The mips16 compiler uses a couple of special sections to handle
995 floating point arguments.
997 Section names that look like .mips16.fn.FNNAME contain stubs that
998 copy floating point arguments from the fp regs to the gp regs and
999 then jump to FNNAME. If any 32 bit function calls FNNAME, the
1000 call should be redirected to the stub instead. If no 32 bit
1001 function calls FNNAME, the stub should be discarded. We need to
1002 consider any reference to the function, not just a call, because
1003 if the address of the function is taken we will need the stub,
1004 since the address might be passed to a 32 bit function.
1006 Section names that look like .mips16.call.FNNAME contain stubs
1007 that copy floating point arguments from the gp regs to the fp
1008 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
1009 then any 16 bit function that calls FNNAME should be redirected
1010 to the stub instead. If FNNAME is not a 32 bit function, the
1011 stub should be discarded.
1013 .mips16.call.fp.FNNAME sections are similar, but contain stubs
1014 which call FNNAME and then copy the return value from the fp regs
1015 to the gp regs. These stubs store the return value in $18 while
1016 calling FNNAME; any function which might call one of these stubs
1017 must arrange to save $18 around the call. (This case is not
1018 needed for 32 bit functions that call 16 bit functions, because
1019 16 bit functions always return floating point values in both
1022 Note that in all cases FNNAME might be defined statically.
1023 Therefore, FNNAME is not used literally. Instead, the relocation
1024 information will indicate which symbol the section is for.
1026 We record any stubs that we find in the symbol table. */
1028 #define FN_STUB ".mips16.fn."
1029 #define CALL_STUB ".mips16.call."
1030 #define CALL_FP_STUB ".mips16.call.fp."
1032 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
1033 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
1034 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
1036 /* The format of the first PLT entry in an O32 executable. */
1037 static const bfd_vma mips_o32_exec_plt0_entry
[] =
1039 0x3c1c0000, /* lui $28, %hi(&GOTPLT[0]) */
1040 0x8f990000, /* lw $25, %lo(&GOTPLT[0])($28) */
1041 0x279c0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
1042 0x031cc023, /* subu $24, $24, $28 */
1043 0x03e07825, /* or t7, ra, zero */
1044 0x0018c082, /* srl $24, $24, 2 */
1045 0x0320f809, /* jalr $25 */
1046 0x2718fffe /* subu $24, $24, 2 */
1049 /* The format of the first PLT entry in an O32 executable using compact
1051 static const bfd_vma mipsr6_o32_exec_plt0_entry_compact
[] =
1053 0x3c1c0000, /* lui $28, %hi(&GOTPLT[0]) */
1054 0x8f990000, /* lw $25, %lo(&GOTPLT[0])($28) */
1055 0x279c0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
1056 0x031cc023, /* subu $24, $24, $28 */
1057 0x03e07821, /* move $15, $31 # 32-bit move (addu) */
1058 0x0018c082, /* srl $24, $24, 2 */
1059 0x2718fffe, /* subu $24, $24, 2 */
1060 0xf8190000 /* jalrc $25 */
1063 /* The format of the first PLT entry in an N32 executable. Different
1064 because gp ($28) is not available; we use t2 ($14) instead. */
1065 static const bfd_vma mips_n32_exec_plt0_entry
[] =
1067 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
1068 0x8dd90000, /* lw $25, %lo(&GOTPLT[0])($14) */
1069 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
1070 0x030ec023, /* subu $24, $24, $14 */
1071 0x03e07825, /* or t7, ra, zero */
1072 0x0018c082, /* srl $24, $24, 2 */
1073 0x0320f809, /* jalr $25 */
1074 0x2718fffe /* subu $24, $24, 2 */
1077 /* The format of the first PLT entry in an N32 executable using compact
1078 jumps. Different because gp ($28) is not available; we use t2 ($14)
1080 static const bfd_vma mipsr6_n32_exec_plt0_entry_compact
[] =
1082 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
1083 0x8dd90000, /* lw $25, %lo(&GOTPLT[0])($14) */
1084 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
1085 0x030ec023, /* subu $24, $24, $14 */
1086 0x03e07821, /* move $15, $31 # 32-bit move (addu) */
1087 0x0018c082, /* srl $24, $24, 2 */
1088 0x2718fffe, /* subu $24, $24, 2 */
1089 0xf8190000 /* jalrc $25 */
1092 /* The format of the first PLT entry in an N64 executable. Different
1093 from N32 because of the increased size of GOT entries. */
1094 static const bfd_vma mips_n64_exec_plt0_entry
[] =
1096 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
1097 0xddd90000, /* ld $25, %lo(&GOTPLT[0])($14) */
1098 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
1099 0x030ec023, /* subu $24, $24, $14 */
1100 0x03e07825, /* or t7, ra, zero */
1101 0x0018c0c2, /* srl $24, $24, 3 */
1102 0x0320f809, /* jalr $25 */
1103 0x2718fffe /* subu $24, $24, 2 */
1106 /* The format of the first PLT entry in an N64 executable using compact
1107 jumps. Different from N32 because of the increased size of GOT
1109 static const bfd_vma mipsr6_n64_exec_plt0_entry_compact
[] =
1111 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
1112 0xddd90000, /* ld $25, %lo(&GOTPLT[0])($14) */
1113 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
1114 0x030ec023, /* subu $24, $24, $14 */
1115 0x03e0782d, /* move $15, $31 # 64-bit move (daddu) */
1116 0x0018c0c2, /* srl $24, $24, 3 */
1117 0x2718fffe, /* subu $24, $24, 2 */
1118 0xf8190000 /* jalrc $25 */
1122 /* The format of the microMIPS first PLT entry in an O32 executable.
1123 We rely on v0 ($2) rather than t8 ($24) to contain the address
1124 of the GOTPLT entry handled, so this stub may only be used when
1125 all the subsequent PLT entries are microMIPS code too.
1127 The trailing NOP is for alignment and correct disassembly only. */
1128 static const bfd_vma micromips_o32_exec_plt0_entry
[] =
1130 0x7980, 0x0000, /* addiupc $3, (&GOTPLT[0]) - . */
1131 0xff23, 0x0000, /* lw $25, 0($3) */
1132 0x0535, /* subu $2, $2, $3 */
1133 0x2525, /* srl $2, $2, 2 */
1134 0x3302, 0xfffe, /* subu $24, $2, 2 */
1135 0x0dff, /* move $15, $31 */
1136 0x45f9, /* jalrs $25 */
1137 0x0f83, /* move $28, $3 */
1141 /* The format of the microMIPS first PLT entry in an O32 executable
1142 in the insn32 mode. */
1143 static const bfd_vma micromips_insn32_o32_exec_plt0_entry
[] =
1145 0x41bc, 0x0000, /* lui $28, %hi(&GOTPLT[0]) */
1146 0xff3c, 0x0000, /* lw $25, %lo(&GOTPLT[0])($28) */
1147 0x339c, 0x0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
1148 0x0398, 0xc1d0, /* subu $24, $24, $28 */
1149 0x001f, 0x7a90, /* or $15, $31, zero */
1150 0x0318, 0x1040, /* srl $24, $24, 2 */
1151 0x03f9, 0x0f3c, /* jalr $25 */
1152 0x3318, 0xfffe /* subu $24, $24, 2 */
1155 /* The format of subsequent standard PLT entries. */
1156 static const bfd_vma mips_exec_plt_entry
[] =
1158 0x3c0f0000, /* lui $15, %hi(.got.plt entry) */
1159 0x01f90000, /* l[wd] $25, %lo(.got.plt entry)($15) */
1160 0x25f80000, /* addiu $24, $15, %lo(.got.plt entry) */
1161 0x03200008 /* jr $25 */
1164 static const bfd_vma mipsr6_exec_plt_entry
[] =
1166 0x3c0f0000, /* lui $15, %hi(.got.plt entry) */
1167 0x01f90000, /* l[wd] $25, %lo(.got.plt entry)($15) */
1168 0x25f80000, /* addiu $24, $15, %lo(.got.plt entry) */
1169 0x03200009 /* jr $25 */
1172 static const bfd_vma mipsr6_exec_plt_entry_compact
[] =
1174 0x3c0f0000, /* lui $15, %hi(.got.plt entry) */
1175 0x01f90000, /* l[wd] $25, %lo(.got.plt entry)($15) */
1176 0x25f80000, /* addiu $24, $15, %lo(.got.plt entry) */
1177 0xd8190000 /* jic $25, 0 */
1180 /* The format of subsequent MIPS16 o32 PLT entries. We use v0 ($2)
1181 and v1 ($3) as temporaries because t8 ($24) and t9 ($25) are not
1182 directly addressable. */
1183 static const bfd_vma mips16_o32_exec_plt_entry
[] =
1185 0xb203, /* lw $2, 12($pc) */
1186 0x9a60, /* lw $3, 0($2) */
1187 0x651a, /* move $24, $2 */
1189 0x653b, /* move $25, $3 */
1191 0x0000, 0x0000 /* .word (.got.plt entry) */
1194 /* The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
1195 as a temporary because t8 ($24) is not addressable with ADDIUPC. */
1196 static const bfd_vma micromips_o32_exec_plt_entry
[] =
1198 0x7900, 0x0000, /* addiupc $2, (.got.plt entry) - . */
1199 0xff22, 0x0000, /* lw $25, 0($2) */
1200 0x4599, /* jr $25 */
1201 0x0f02 /* move $24, $2 */
1204 /* The format of subsequent microMIPS o32 PLT entries in the insn32 mode. */
1205 static const bfd_vma micromips_insn32_o32_exec_plt_entry
[] =
1207 0x41af, 0x0000, /* lui $15, %hi(.got.plt entry) */
1208 0xff2f, 0x0000, /* lw $25, %lo(.got.plt entry)($15) */
1209 0x0019, 0x0f3c, /* jr $25 */
1210 0x330f, 0x0000 /* addiu $24, $15, %lo(.got.plt entry) */
1213 /* The format of the first PLT entry in a VxWorks executable. */
1214 static const bfd_vma mips_vxworks_exec_plt0_entry
[] =
1216 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
1217 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
1218 0x8f390008, /* lw t9, 8(t9) */
1219 0x00000000, /* nop */
1220 0x03200008, /* jr t9 */
1221 0x00000000 /* nop */
1224 /* The format of subsequent PLT entries. */
1225 static const bfd_vma mips_vxworks_exec_plt_entry
[] =
1227 0x10000000, /* b .PLT_resolver */
1228 0x24180000, /* li t8, <pltindex> */
1229 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
1230 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
1231 0x8f390000, /* lw t9, 0(t9) */
1232 0x00000000, /* nop */
1233 0x03200008, /* jr t9 */
1234 0x00000000 /* nop */
1237 /* The format of the first PLT entry in a VxWorks shared object. */
1238 static const bfd_vma mips_vxworks_shared_plt0_entry
[] =
1240 0x8f990008, /* lw t9, 8(gp) */
1241 0x00000000, /* nop */
1242 0x03200008, /* jr t9 */
1243 0x00000000, /* nop */
1244 0x00000000, /* nop */
1245 0x00000000 /* nop */
1248 /* The format of subsequent PLT entries. */
1249 static const bfd_vma mips_vxworks_shared_plt_entry
[] =
1251 0x10000000, /* b .PLT_resolver */
1252 0x24180000 /* li t8, <pltindex> */
1255 /* microMIPS 32-bit opcode helper installer. */
1258 bfd_put_micromips_32 (const bfd
*abfd
, bfd_vma opcode
, bfd_byte
*ptr
)
1260 bfd_put_16 (abfd
, (opcode
>> 16) & 0xffff, ptr
);
1261 bfd_put_16 (abfd
, opcode
& 0xffff, ptr
+ 2);
1264 /* microMIPS 32-bit opcode helper retriever. */
1267 bfd_get_micromips_32 (const bfd
*abfd
, const bfd_byte
*ptr
)
1269 return (bfd_get_16 (abfd
, ptr
) << 16) | bfd_get_16 (abfd
, ptr
+ 2);
1272 /* Look up an entry in a MIPS ELF linker hash table. */
1274 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
1275 ((struct mips_elf_link_hash_entry *) \
1276 elf_link_hash_lookup (&(table)->root, (string), (create), \
1279 /* Traverse a MIPS ELF linker hash table. */
1281 #define mips_elf_link_hash_traverse(table, func, info) \
1282 (elf_link_hash_traverse \
1284 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1287 /* Find the base offsets for thread-local storage in this object,
1288 for GD/LD and IE/LE respectively. */
1290 #define TP_OFFSET 0x7000
1291 #define DTP_OFFSET 0x8000
1294 dtprel_base (struct bfd_link_info
*info
)
1296 /* If tls_sec is NULL, we should have signalled an error already. */
1297 if (elf_hash_table (info
)->tls_sec
== NULL
)
1299 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
1303 tprel_base (struct bfd_link_info
*info
)
1305 /* If tls_sec is NULL, we should have signalled an error already. */
1306 if (elf_hash_table (info
)->tls_sec
== NULL
)
1308 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
1311 /* Create an entry in a MIPS ELF linker hash table. */
1313 static struct bfd_hash_entry
*
1314 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1315 struct bfd_hash_table
*table
, const char *string
)
1317 struct mips_elf_link_hash_entry
*ret
=
1318 (struct mips_elf_link_hash_entry
*) entry
;
1320 /* Allocate the structure if it has not already been allocated by a
1323 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
1325 return (struct bfd_hash_entry
*) ret
;
1327 /* Call the allocation method of the superclass. */
1328 ret
= ((struct mips_elf_link_hash_entry
*)
1329 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1333 /* Set local fields. */
1334 memset (&ret
->esym
, 0, sizeof (EXTR
));
1335 /* We use -2 as a marker to indicate that the information has
1336 not been set. -1 means there is no associated ifd. */
1339 ret
->possibly_dynamic_relocs
= 0;
1340 ret
->fn_stub
= NULL
;
1341 ret
->call_stub
= NULL
;
1342 ret
->call_fp_stub
= NULL
;
1343 ret
->mipsxhash_loc
= 0;
1344 ret
->global_got_area
= GGA_NONE
;
1345 ret
->got_only_for_calls
= TRUE
;
1346 ret
->readonly_reloc
= FALSE
;
1347 ret
->has_static_relocs
= FALSE
;
1348 ret
->no_fn_stub
= FALSE
;
1349 ret
->need_fn_stub
= FALSE
;
1350 ret
->has_nonpic_branches
= FALSE
;
1351 ret
->needs_lazy_stub
= FALSE
;
1352 ret
->use_plt_entry
= FALSE
;
1355 return (struct bfd_hash_entry
*) ret
;
1358 /* Allocate MIPS ELF private object data. */
1361 _bfd_mips_elf_mkobject (bfd
*abfd
)
1363 return bfd_elf_allocate_object (abfd
, sizeof (struct mips_elf_obj_tdata
),
1368 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1370 if (!sec
->used_by_bfd
)
1372 struct _mips_elf_section_data
*sdata
;
1373 size_t amt
= sizeof (*sdata
);
1375 sdata
= bfd_zalloc (abfd
, amt
);
1378 sec
->used_by_bfd
= sdata
;
1381 return _bfd_elf_new_section_hook (abfd
, sec
);
1384 /* Read ECOFF debugging information from a .mdebug section into a
1385 ecoff_debug_info structure. */
1388 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
1389 struct ecoff_debug_info
*debug
)
1392 const struct ecoff_debug_swap
*swap
;
1395 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1396 memset (debug
, 0, sizeof (*debug
));
1398 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
1399 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1402 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
1403 swap
->external_hdr_size
))
1406 symhdr
= &debug
->symbolic_header
;
1407 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1409 /* The symbolic header contains absolute file offsets and sizes to
1411 #define READ(ptr, offset, count, size, type) \
1415 debug->ptr = NULL; \
1416 if (symhdr->count == 0) \
1418 if (_bfd_mul_overflow (size, symhdr->count, &amt)) \
1420 bfd_set_error (bfd_error_file_too_big); \
1421 goto error_return; \
1423 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0) \
1424 goto error_return; \
1425 debug->ptr = (type) _bfd_malloc_and_read (abfd, amt, amt); \
1426 if (debug->ptr == NULL) \
1427 goto error_return; \
1430 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1431 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
1432 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
1433 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
1434 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
1435 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1437 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1438 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1439 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
1440 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
1441 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
1451 free (debug
->external_dnr
);
1452 free (debug
->external_pdr
);
1453 free (debug
->external_sym
);
1454 free (debug
->external_opt
);
1455 free (debug
->external_aux
);
1457 free (debug
->ssext
);
1458 free (debug
->external_fdr
);
1459 free (debug
->external_rfd
);
1460 free (debug
->external_ext
);
1464 /* Swap RPDR (runtime procedure table entry) for output. */
1467 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
1469 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
1470 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
1471 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
1472 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
1473 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
1474 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
1476 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
1477 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1479 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1482 /* Create a runtime procedure table from the .mdebug section. */
1485 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1486 struct bfd_link_info
*info
, asection
*s
,
1487 struct ecoff_debug_info
*debug
)
1489 const struct ecoff_debug_swap
*swap
;
1490 HDRR
*hdr
= &debug
->symbolic_header
;
1492 struct rpdr_ext
*erp
;
1494 struct pdr_ext
*epdr
;
1495 struct sym_ext
*esym
;
1499 bfd_size_type count
;
1500 unsigned long sindex
;
1504 const char *no_name_func
= _("static procedure (no name)");
1512 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1514 sindex
= strlen (no_name_func
) + 1;
1515 count
= hdr
->ipdMax
;
1518 size
= swap
->external_pdr_size
;
1520 epdr
= bfd_malloc (size
* count
);
1524 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1527 size
= sizeof (RPDR
);
1528 rp
= rpdr
= bfd_malloc (size
* count
);
1532 size
= sizeof (char *);
1533 sv
= bfd_malloc (size
* count
);
1537 count
= hdr
->isymMax
;
1538 size
= swap
->external_sym_size
;
1539 esym
= bfd_malloc (size
* count
);
1543 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1546 count
= hdr
->issMax
;
1547 ss
= bfd_malloc (count
);
1550 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1553 count
= hdr
->ipdMax
;
1554 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1556 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1557 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1558 rp
->adr
= sym
.value
;
1559 rp
->regmask
= pdr
.regmask
;
1560 rp
->regoffset
= pdr
.regoffset
;
1561 rp
->fregmask
= pdr
.fregmask
;
1562 rp
->fregoffset
= pdr
.fregoffset
;
1563 rp
->frameoffset
= pdr
.frameoffset
;
1564 rp
->framereg
= pdr
.framereg
;
1565 rp
->pcreg
= pdr
.pcreg
;
1567 sv
[i
] = ss
+ sym
.iss
;
1568 sindex
+= strlen (sv
[i
]) + 1;
1572 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1573 size
= BFD_ALIGN (size
, 16);
1574 rtproc
= bfd_alloc (abfd
, size
);
1577 mips_elf_hash_table (info
)->procedure_count
= 0;
1581 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1584 memset (erp
, 0, sizeof (struct rpdr_ext
));
1586 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1587 strcpy (str
, no_name_func
);
1588 str
+= strlen (no_name_func
) + 1;
1589 for (i
= 0; i
< count
; i
++)
1591 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1592 strcpy (str
, sv
[i
]);
1593 str
+= strlen (sv
[i
]) + 1;
1595 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1597 /* Set the size and contents of .rtproc section. */
1599 s
->contents
= rtproc
;
1601 /* Skip this section later on (I don't think this currently
1602 matters, but someday it might). */
1603 s
->map_head
.link_order
= NULL
;
1621 /* We're going to create a stub for H. Create a symbol for the stub's
1622 value and size, to help make the disassembly easier to read. */
1625 mips_elf_create_stub_symbol (struct bfd_link_info
*info
,
1626 struct mips_elf_link_hash_entry
*h
,
1627 const char *prefix
, asection
*s
, bfd_vma value
,
1630 bfd_boolean micromips_p
= ELF_ST_IS_MICROMIPS (h
->root
.other
);
1631 struct bfd_link_hash_entry
*bh
;
1632 struct elf_link_hash_entry
*elfh
;
1639 /* Create a new symbol. */
1640 name
= concat (prefix
, h
->root
.root
.root
.string
, NULL
);
1642 res
= _bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1643 BSF_LOCAL
, s
, value
, NULL
,
1649 /* Make it a local function. */
1650 elfh
= (struct elf_link_hash_entry
*) bh
;
1651 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
1653 elfh
->forced_local
= 1;
1655 elfh
->other
= ELF_ST_SET_MICROMIPS (elfh
->other
);
1659 /* We're about to redefine H. Create a symbol to represent H's
1660 current value and size, to help make the disassembly easier
1664 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1665 struct mips_elf_link_hash_entry
*h
,
1668 struct bfd_link_hash_entry
*bh
;
1669 struct elf_link_hash_entry
*elfh
;
1675 /* Read the symbol's value. */
1676 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1677 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1678 s
= h
->root
.root
.u
.def
.section
;
1679 value
= h
->root
.root
.u
.def
.value
;
1681 /* Create a new symbol. */
1682 name
= concat (prefix
, h
->root
.root
.root
.string
, NULL
);
1684 res
= _bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1685 BSF_LOCAL
, s
, value
, NULL
,
1691 /* Make it local and copy the other attributes from H. */
1692 elfh
= (struct elf_link_hash_entry
*) bh
;
1693 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1694 elfh
->other
= h
->root
.other
;
1695 elfh
->size
= h
->root
.size
;
1696 elfh
->forced_local
= 1;
1700 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1701 function rather than to a hard-float stub. */
1704 section_allows_mips16_refs_p (asection
*section
)
1708 name
= bfd_section_name (section
);
1709 return (FN_STUB_P (name
)
1710 || CALL_STUB_P (name
)
1711 || CALL_FP_STUB_P (name
)
1712 || strcmp (name
, ".pdr") == 0);
1715 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1716 stub section of some kind. Return the R_SYMNDX of the target
1717 function, or 0 if we can't decide which function that is. */
1719 static unsigned long
1720 mips16_stub_symndx (const struct elf_backend_data
*bed
,
1721 asection
*sec ATTRIBUTE_UNUSED
,
1722 const Elf_Internal_Rela
*relocs
,
1723 const Elf_Internal_Rela
*relend
)
1725 int int_rels_per_ext_rel
= bed
->s
->int_rels_per_ext_rel
;
1726 const Elf_Internal_Rela
*rel
;
1728 /* Trust the first R_MIPS_NONE relocation, if any, but not a subsequent
1729 one in a compound relocation. */
1730 for (rel
= relocs
; rel
< relend
; rel
+= int_rels_per_ext_rel
)
1731 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1732 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1734 /* Otherwise trust the first relocation, whatever its kind. This is
1735 the traditional behavior. */
1736 if (relocs
< relend
)
1737 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1742 /* Check the mips16 stubs for a particular symbol, and see if we can
1746 mips_elf_check_mips16_stubs (struct bfd_link_info
*info
,
1747 struct mips_elf_link_hash_entry
*h
)
1749 /* Dynamic symbols must use the standard call interface, in case other
1750 objects try to call them. */
1751 if (h
->fn_stub
!= NULL
1752 && h
->root
.dynindx
!= -1)
1754 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1755 h
->need_fn_stub
= TRUE
;
1758 if (h
->fn_stub
!= NULL
1759 && ! h
->need_fn_stub
)
1761 /* We don't need the fn_stub; the only references to this symbol
1762 are 16 bit calls. Clobber the size to 0 to prevent it from
1763 being included in the link. */
1764 h
->fn_stub
->size
= 0;
1765 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1766 h
->fn_stub
->reloc_count
= 0;
1767 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1768 h
->fn_stub
->output_section
= bfd_abs_section_ptr
;
1771 if (h
->call_stub
!= NULL
1772 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1774 /* We don't need the call_stub; this is a 16 bit function, so
1775 calls from other 16 bit functions are OK. Clobber the size
1776 to 0 to prevent it from being included in the link. */
1777 h
->call_stub
->size
= 0;
1778 h
->call_stub
->flags
&= ~SEC_RELOC
;
1779 h
->call_stub
->reloc_count
= 0;
1780 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1781 h
->call_stub
->output_section
= bfd_abs_section_ptr
;
1784 if (h
->call_fp_stub
!= NULL
1785 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1787 /* We don't need the call_stub; this is a 16 bit function, so
1788 calls from other 16 bit functions are OK. Clobber the size
1789 to 0 to prevent it from being included in the link. */
1790 h
->call_fp_stub
->size
= 0;
1791 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1792 h
->call_fp_stub
->reloc_count
= 0;
1793 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1794 h
->call_fp_stub
->output_section
= bfd_abs_section_ptr
;
1798 /* Hashtable callbacks for mips_elf_la25_stubs. */
1801 mips_elf_la25_stub_hash (const void *entry_
)
1803 const struct mips_elf_la25_stub
*entry
;
1805 entry
= (struct mips_elf_la25_stub
*) entry_
;
1806 return entry
->h
->root
.root
.u
.def
.section
->id
1807 + entry
->h
->root
.root
.u
.def
.value
;
1811 mips_elf_la25_stub_eq (const void *entry1_
, const void *entry2_
)
1813 const struct mips_elf_la25_stub
*entry1
, *entry2
;
1815 entry1
= (struct mips_elf_la25_stub
*) entry1_
;
1816 entry2
= (struct mips_elf_la25_stub
*) entry2_
;
1817 return ((entry1
->h
->root
.root
.u
.def
.section
1818 == entry2
->h
->root
.root
.u
.def
.section
)
1819 && (entry1
->h
->root
.root
.u
.def
.value
1820 == entry2
->h
->root
.root
.u
.def
.value
));
1823 /* Called by the linker to set up the la25 stub-creation code. FN is
1824 the linker's implementation of add_stub_function. Return true on
1828 _bfd_mips_elf_init_stubs (struct bfd_link_info
*info
,
1829 asection
*(*fn
) (const char *, asection
*,
1832 struct mips_elf_link_hash_table
*htab
;
1834 htab
= mips_elf_hash_table (info
);
1838 htab
->add_stub_section
= fn
;
1839 htab
->la25_stubs
= htab_try_create (1, mips_elf_la25_stub_hash
,
1840 mips_elf_la25_stub_eq
, NULL
);
1841 if (htab
->la25_stubs
== NULL
)
1847 /* Return true if H is a locally-defined PIC function, in the sense
1848 that it or its fn_stub might need $25 to be valid on entry.
1849 Note that MIPS16 functions set up $gp using PC-relative instructions,
1850 so they themselves never need $25 to be valid. Only non-MIPS16
1851 entry points are of interest here. */
1854 mips_elf_local_pic_function_p (struct mips_elf_link_hash_entry
*h
)
1856 return ((h
->root
.root
.type
== bfd_link_hash_defined
1857 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1858 && h
->root
.def_regular
1859 && !bfd_is_abs_section (h
->root
.root
.u
.def
.section
)
1860 && !bfd_is_und_section (h
->root
.root
.u
.def
.section
)
1861 && (!ELF_ST_IS_MIPS16 (h
->root
.other
)
1862 || (h
->fn_stub
&& h
->need_fn_stub
))
1863 && (PIC_OBJECT_P (h
->root
.root
.u
.def
.section
->owner
)
1864 || ELF_ST_IS_MIPS_PIC (h
->root
.other
)));
1867 /* Set *SEC to the input section that contains the target of STUB.
1868 Return the offset of the target from the start of that section. */
1871 mips_elf_get_la25_target (struct mips_elf_la25_stub
*stub
,
1874 if (ELF_ST_IS_MIPS16 (stub
->h
->root
.other
))
1876 BFD_ASSERT (stub
->h
->need_fn_stub
);
1877 *sec
= stub
->h
->fn_stub
;
1882 *sec
= stub
->h
->root
.root
.u
.def
.section
;
1883 return stub
->h
->root
.root
.u
.def
.value
;
1887 /* STUB describes an la25 stub that we have decided to implement
1888 by inserting an LUI/ADDIU pair before the target function.
1889 Create the section and redirect the function symbol to it. */
1892 mips_elf_add_la25_intro (struct mips_elf_la25_stub
*stub
,
1893 struct bfd_link_info
*info
)
1895 struct mips_elf_link_hash_table
*htab
;
1897 asection
*s
, *input_section
;
1900 htab
= mips_elf_hash_table (info
);
1904 /* Create a unique name for the new section. */
1905 name
= bfd_malloc (11 + sizeof (".text.stub."));
1908 sprintf (name
, ".text.stub.%d", (int) htab_elements (htab
->la25_stubs
));
1910 /* Create the section. */
1911 mips_elf_get_la25_target (stub
, &input_section
);
1912 s
= htab
->add_stub_section (name
, input_section
,
1913 input_section
->output_section
);
1917 /* Make sure that any padding goes before the stub. */
1918 align
= input_section
->alignment_power
;
1919 if (!bfd_set_section_alignment (s
, align
))
1922 s
->size
= (1 << align
) - 8;
1924 /* Create a symbol for the stub. */
1925 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 8);
1926 stub
->stub_section
= s
;
1927 stub
->offset
= s
->size
;
1929 /* Allocate room for it. */
1934 /* STUB describes an la25 stub that we have decided to implement
1935 with a separate trampoline. Allocate room for it and redirect
1936 the function symbol to it. */
1939 mips_elf_add_la25_trampoline (struct mips_elf_la25_stub
*stub
,
1940 struct bfd_link_info
*info
)
1942 struct mips_elf_link_hash_table
*htab
;
1945 htab
= mips_elf_hash_table (info
);
1949 /* Create a trampoline section, if we haven't already. */
1950 s
= htab
->strampoline
;
1953 asection
*input_section
= stub
->h
->root
.root
.u
.def
.section
;
1954 s
= htab
->add_stub_section (".text", NULL
,
1955 input_section
->output_section
);
1956 if (s
== NULL
|| !bfd_set_section_alignment (s
, 4))
1958 htab
->strampoline
= s
;
1961 /* Create a symbol for the stub. */
1962 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 16);
1963 stub
->stub_section
= s
;
1964 stub
->offset
= s
->size
;
1966 /* Allocate room for it. */
1971 /* H describes a symbol that needs an la25 stub. Make sure that an
1972 appropriate stub exists and point H at it. */
1975 mips_elf_add_la25_stub (struct bfd_link_info
*info
,
1976 struct mips_elf_link_hash_entry
*h
)
1978 struct mips_elf_link_hash_table
*htab
;
1979 struct mips_elf_la25_stub search
, *stub
;
1980 bfd_boolean use_trampoline_p
;
1985 /* Describe the stub we want. */
1986 search
.stub_section
= NULL
;
1990 /* See if we've already created an equivalent stub. */
1991 htab
= mips_elf_hash_table (info
);
1995 slot
= htab_find_slot (htab
->la25_stubs
, &search
, INSERT
);
1999 stub
= (struct mips_elf_la25_stub
*) *slot
;
2002 /* We can reuse the existing stub. */
2003 h
->la25_stub
= stub
;
2007 /* Create a permanent copy of ENTRY and add it to the hash table. */
2008 stub
= bfd_malloc (sizeof (search
));
2014 /* Prefer to use LUI/ADDIU stubs if the function is at the beginning
2015 of the section and if we would need no more than 2 nops. */
2016 value
= mips_elf_get_la25_target (stub
, &s
);
2017 if (ELF_ST_IS_MICROMIPS (stub
->h
->root
.other
))
2019 use_trampoline_p
= (value
!= 0 || s
->alignment_power
> 4);
2021 h
->la25_stub
= stub
;
2022 return (use_trampoline_p
2023 ? mips_elf_add_la25_trampoline (stub
, info
)
2024 : mips_elf_add_la25_intro (stub
, info
));
2027 /* A mips_elf_link_hash_traverse callback that is called before sizing
2028 sections. DATA points to a mips_htab_traverse_info structure. */
2031 mips_elf_check_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
2033 struct mips_htab_traverse_info
*hti
;
2035 hti
= (struct mips_htab_traverse_info
*) data
;
2036 if (!bfd_link_relocatable (hti
->info
))
2037 mips_elf_check_mips16_stubs (hti
->info
, h
);
2039 if (mips_elf_local_pic_function_p (h
))
2041 /* PR 12845: If H is in a section that has been garbage
2042 collected it will have its output section set to *ABS*. */
2043 if (bfd_is_abs_section (h
->root
.root
.u
.def
.section
->output_section
))
2046 /* H is a function that might need $25 to be valid on entry.
2047 If we're creating a non-PIC relocatable object, mark H as
2048 being PIC. If we're creating a non-relocatable object with
2049 non-PIC branches and jumps to H, make sure that H has an la25
2051 if (bfd_link_relocatable (hti
->info
))
2053 if (!PIC_OBJECT_P (hti
->output_bfd
))
2054 h
->root
.other
= ELF_ST_SET_MIPS_PIC (h
->root
.other
);
2056 else if (h
->has_nonpic_branches
&& !mips_elf_add_la25_stub (hti
->info
, h
))
2065 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
2066 Most mips16 instructions are 16 bits, but these instructions
2069 The format of these instructions is:
2071 +--------------+--------------------------------+
2072 | JALX | X| Imm 20:16 | Imm 25:21 |
2073 +--------------+--------------------------------+
2075 +-----------------------------------------------+
2077 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
2078 Note that the immediate value in the first word is swapped.
2080 When producing a relocatable object file, R_MIPS16_26 is
2081 handled mostly like R_MIPS_26. In particular, the addend is
2082 stored as a straight 26-bit value in a 32-bit instruction.
2083 (gas makes life simpler for itself by never adjusting a
2084 R_MIPS16_26 reloc to be against a section, so the addend is
2085 always zero). However, the 32 bit instruction is stored as 2
2086 16-bit values, rather than a single 32-bit value. In a
2087 big-endian file, the result is the same; in a little-endian
2088 file, the two 16-bit halves of the 32 bit value are swapped.
2089 This is so that a disassembler can recognize the jal
2092 When doing a final link, R_MIPS16_26 is treated as a 32 bit
2093 instruction stored as two 16-bit values. The addend A is the
2094 contents of the targ26 field. The calculation is the same as
2095 R_MIPS_26. When storing the calculated value, reorder the
2096 immediate value as shown above, and don't forget to store the
2097 value as two 16-bit values.
2099 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
2103 +--------+----------------------+
2107 +--------+----------------------+
2110 +----------+------+-------------+
2114 +----------+--------------------+
2115 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
2116 ((sub1 << 16) | sub2)).
2118 When producing a relocatable object file, the calculation is
2119 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2120 When producing a fully linked file, the calculation is
2121 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2122 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
2124 The table below lists the other MIPS16 instruction relocations.
2125 Each one is calculated in the same way as the non-MIPS16 relocation
2126 given on the right, but using the extended MIPS16 layout of 16-bit
2129 R_MIPS16_GPREL R_MIPS_GPREL16
2130 R_MIPS16_GOT16 R_MIPS_GOT16
2131 R_MIPS16_CALL16 R_MIPS_CALL16
2132 R_MIPS16_HI16 R_MIPS_HI16
2133 R_MIPS16_LO16 R_MIPS_LO16
2135 A typical instruction will have a format like this:
2137 +--------------+--------------------------------+
2138 | EXTEND | Imm 10:5 | Imm 15:11 |
2139 +--------------+--------------------------------+
2140 | Major | rx | ry | Imm 4:0 |
2141 +--------------+--------------------------------+
2143 EXTEND is the five bit value 11110. Major is the instruction
2146 All we need to do here is shuffle the bits appropriately.
2147 As above, the two 16-bit halves must be swapped on a
2148 little-endian system.
2150 Finally R_MIPS16_PC16_S1 corresponds to R_MIPS_PC16, however the
2151 relocatable field is shifted by 1 rather than 2 and the same bit
2152 shuffling is done as with the relocations above. */
2154 static inline bfd_boolean
2155 mips16_reloc_p (int r_type
)
2160 case R_MIPS16_GPREL
:
2161 case R_MIPS16_GOT16
:
2162 case R_MIPS16_CALL16
:
2165 case R_MIPS16_TLS_GD
:
2166 case R_MIPS16_TLS_LDM
:
2167 case R_MIPS16_TLS_DTPREL_HI16
:
2168 case R_MIPS16_TLS_DTPREL_LO16
:
2169 case R_MIPS16_TLS_GOTTPREL
:
2170 case R_MIPS16_TLS_TPREL_HI16
:
2171 case R_MIPS16_TLS_TPREL_LO16
:
2172 case R_MIPS16_PC16_S1
:
2180 /* Check if a microMIPS reloc. */
2182 static inline bfd_boolean
2183 micromips_reloc_p (unsigned int r_type
)
2185 return r_type
>= R_MICROMIPS_min
&& r_type
< R_MICROMIPS_max
;
2188 /* Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
2189 on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1
2190 and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions. */
2192 static inline bfd_boolean
2193 micromips_reloc_shuffle_p (unsigned int r_type
)
2195 return (micromips_reloc_p (r_type
)
2196 && r_type
!= R_MICROMIPS_PC7_S1
2197 && r_type
!= R_MICROMIPS_PC10_S1
);
2200 static inline bfd_boolean
2201 got16_reloc_p (int r_type
)
2203 return (r_type
== R_MIPS_GOT16
2204 || r_type
== R_MIPS16_GOT16
2205 || r_type
== R_MICROMIPS_GOT16
);
2208 static inline bfd_boolean
2209 call16_reloc_p (int r_type
)
2211 return (r_type
== R_MIPS_CALL16
2212 || r_type
== R_MIPS16_CALL16
2213 || r_type
== R_MICROMIPS_CALL16
);
2216 static inline bfd_boolean
2217 got_disp_reloc_p (unsigned int r_type
)
2219 return r_type
== R_MIPS_GOT_DISP
|| r_type
== R_MICROMIPS_GOT_DISP
;
2222 static inline bfd_boolean
2223 got_page_reloc_p (unsigned int r_type
)
2225 return r_type
== R_MIPS_GOT_PAGE
|| r_type
== R_MICROMIPS_GOT_PAGE
;
2228 static inline bfd_boolean
2229 got_lo16_reloc_p (unsigned int r_type
)
2231 return r_type
== R_MIPS_GOT_LO16
|| r_type
== R_MICROMIPS_GOT_LO16
;
2234 static inline bfd_boolean
2235 call_hi16_reloc_p (unsigned int r_type
)
2237 return r_type
== R_MIPS_CALL_HI16
|| r_type
== R_MICROMIPS_CALL_HI16
;
2240 static inline bfd_boolean
2241 call_lo16_reloc_p (unsigned int r_type
)
2243 return r_type
== R_MIPS_CALL_LO16
|| r_type
== R_MICROMIPS_CALL_LO16
;
2246 static inline bfd_boolean
2247 hi16_reloc_p (int r_type
)
2249 return (r_type
== R_MIPS_HI16
2250 || r_type
== R_MIPS16_HI16
2251 || r_type
== R_MICROMIPS_HI16
2252 || r_type
== R_MIPS_PCHI16
);
2255 static inline bfd_boolean
2256 lo16_reloc_p (int r_type
)
2258 return (r_type
== R_MIPS_LO16
2259 || r_type
== R_MIPS16_LO16
2260 || r_type
== R_MICROMIPS_LO16
2261 || r_type
== R_MIPS_PCLO16
);
2264 static inline bfd_boolean
2265 mips16_call_reloc_p (int r_type
)
2267 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
2270 static inline bfd_boolean
2271 jal_reloc_p (int r_type
)
2273 return (r_type
== R_MIPS_26
2274 || r_type
== R_MIPS16_26
2275 || r_type
== R_MICROMIPS_26_S1
);
2278 static inline bfd_boolean
2279 b_reloc_p (int r_type
)
2281 return (r_type
== R_MIPS_PC26_S2
2282 || r_type
== R_MIPS_PC21_S2
2283 || r_type
== R_MIPS_PC16
2284 || r_type
== R_MIPS_GNU_REL16_S2
2285 || r_type
== R_MIPS16_PC16_S1
2286 || r_type
== R_MICROMIPS_PC16_S1
2287 || r_type
== R_MICROMIPS_PC10_S1
2288 || r_type
== R_MICROMIPS_PC7_S1
);
2291 static inline bfd_boolean
2292 aligned_pcrel_reloc_p (int r_type
)
2294 return (r_type
== R_MIPS_PC18_S3
2295 || r_type
== R_MIPS_PC19_S2
);
2298 static inline bfd_boolean
2299 branch_reloc_p (int r_type
)
2301 return (r_type
== R_MIPS_26
2302 || r_type
== R_MIPS_PC26_S2
2303 || r_type
== R_MIPS_PC21_S2
2304 || r_type
== R_MIPS_PC16
2305 || r_type
== R_MIPS_GNU_REL16_S2
);
2308 static inline bfd_boolean
2309 mips16_branch_reloc_p (int r_type
)
2311 return (r_type
== R_MIPS16_26
2312 || r_type
== R_MIPS16_PC16_S1
);
2315 static inline bfd_boolean
2316 micromips_branch_reloc_p (int r_type
)
2318 return (r_type
== R_MICROMIPS_26_S1
2319 || r_type
== R_MICROMIPS_PC16_S1
2320 || r_type
== R_MICROMIPS_PC10_S1
2321 || r_type
== R_MICROMIPS_PC7_S1
);
2324 static inline bfd_boolean
2325 tls_gd_reloc_p (unsigned int r_type
)
2327 return (r_type
== R_MIPS_TLS_GD
2328 || r_type
== R_MIPS16_TLS_GD
2329 || r_type
== R_MICROMIPS_TLS_GD
);
2332 static inline bfd_boolean
2333 tls_ldm_reloc_p (unsigned int r_type
)
2335 return (r_type
== R_MIPS_TLS_LDM
2336 || r_type
== R_MIPS16_TLS_LDM
2337 || r_type
== R_MICROMIPS_TLS_LDM
);
2340 static inline bfd_boolean
2341 tls_gottprel_reloc_p (unsigned int r_type
)
2343 return (r_type
== R_MIPS_TLS_GOTTPREL
2344 || r_type
== R_MIPS16_TLS_GOTTPREL
2345 || r_type
== R_MICROMIPS_TLS_GOTTPREL
);
2349 _bfd_mips_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
2350 bfd_boolean jal_shuffle
, bfd_byte
*data
)
2352 bfd_vma first
, second
, val
;
2354 if (!mips16_reloc_p (r_type
) && !micromips_reloc_shuffle_p (r_type
))
2357 /* Pick up the first and second halfwords of the instruction. */
2358 first
= bfd_get_16 (abfd
, data
);
2359 second
= bfd_get_16 (abfd
, data
+ 2);
2360 if (micromips_reloc_p (r_type
) || (r_type
== R_MIPS16_26
&& !jal_shuffle
))
2361 val
= first
<< 16 | second
;
2362 else if (r_type
!= R_MIPS16_26
)
2363 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
2364 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
2366 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
2367 | ((first
& 0x1f) << 21) | second
);
2368 bfd_put_32 (abfd
, val
, data
);
2372 _bfd_mips_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
2373 bfd_boolean jal_shuffle
, bfd_byte
*data
)
2375 bfd_vma first
, second
, val
;
2377 if (!mips16_reloc_p (r_type
) && !micromips_reloc_shuffle_p (r_type
))
2380 val
= bfd_get_32 (abfd
, data
);
2381 if (micromips_reloc_p (r_type
) || (r_type
== R_MIPS16_26
&& !jal_shuffle
))
2383 second
= val
& 0xffff;
2386 else if (r_type
!= R_MIPS16_26
)
2388 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
2389 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
2393 second
= val
& 0xffff;
2394 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
2395 | ((val
>> 21) & 0x1f);
2397 bfd_put_16 (abfd
, second
, data
+ 2);
2398 bfd_put_16 (abfd
, first
, data
);
2401 bfd_reloc_status_type
2402 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
2403 arelent
*reloc_entry
, asection
*input_section
,
2404 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
2408 bfd_reloc_status_type status
;
2410 if (bfd_is_com_section (symbol
->section
))
2413 relocation
= symbol
->value
;
2415 relocation
+= symbol
->section
->output_section
->vma
;
2416 relocation
+= symbol
->section
->output_offset
;
2418 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2419 return bfd_reloc_outofrange
;
2421 /* Set val to the offset into the section or symbol. */
2422 val
= reloc_entry
->addend
;
2424 _bfd_mips_elf_sign_extend (val
, 16);
2426 /* Adjust val for the final section location and GP value. If we
2427 are producing relocatable output, we don't want to do this for
2428 an external symbol. */
2430 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2431 val
+= relocation
- gp
;
2433 if (reloc_entry
->howto
->partial_inplace
)
2435 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
2437 + reloc_entry
->address
);
2438 if (status
!= bfd_reloc_ok
)
2442 reloc_entry
->addend
= val
;
2445 reloc_entry
->address
+= input_section
->output_offset
;
2447 return bfd_reloc_ok
;
2450 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
2451 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
2452 that contains the relocation field and DATA points to the start of
2457 struct mips_hi16
*next
;
2459 asection
*input_section
;
2463 /* FIXME: This should not be a static variable. */
2465 static struct mips_hi16
*mips_hi16_list
;
2467 /* A howto special_function for REL *HI16 relocations. We can only
2468 calculate the correct value once we've seen the partnering
2469 *LO16 relocation, so just save the information for later.
2471 The ABI requires that the *LO16 immediately follow the *HI16.
2472 However, as a GNU extension, we permit an arbitrary number of
2473 *HI16s to be associated with a single *LO16. This significantly
2474 simplies the relocation handling in gcc. */
2476 bfd_reloc_status_type
2477 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2478 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
2479 asection
*input_section
, bfd
*output_bfd
,
2480 char **error_message ATTRIBUTE_UNUSED
)
2482 struct mips_hi16
*n
;
2484 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2485 return bfd_reloc_outofrange
;
2487 n
= bfd_malloc (sizeof *n
);
2489 return bfd_reloc_outofrange
;
2491 n
->next
= mips_hi16_list
;
2493 n
->input_section
= input_section
;
2494 n
->rel
= *reloc_entry
;
2497 if (output_bfd
!= NULL
)
2498 reloc_entry
->address
+= input_section
->output_offset
;
2500 return bfd_reloc_ok
;
2503 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
2504 like any other 16-bit relocation when applied to global symbols, but is
2505 treated in the same as R_MIPS_HI16 when applied to local symbols. */
2507 bfd_reloc_status_type
2508 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2509 void *data
, asection
*input_section
,
2510 bfd
*output_bfd
, char **error_message
)
2512 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
2513 || bfd_is_und_section (bfd_asymbol_section (symbol
))
2514 || bfd_is_com_section (bfd_asymbol_section (symbol
)))
2515 /* The relocation is against a global symbol. */
2516 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2517 input_section
, output_bfd
,
2520 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
2521 input_section
, output_bfd
, error_message
);
2524 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
2525 is a straightforward 16 bit inplace relocation, but we must deal with
2526 any partnering high-part relocations as well. */
2528 bfd_reloc_status_type
2529 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2530 void *data
, asection
*input_section
,
2531 bfd
*output_bfd
, char **error_message
)
2534 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2536 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2537 return bfd_reloc_outofrange
;
2539 _bfd_mips_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2541 vallo
= bfd_get_32 (abfd
, location
);
2542 _bfd_mips_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2545 while (mips_hi16_list
!= NULL
)
2547 bfd_reloc_status_type ret
;
2548 struct mips_hi16
*hi
;
2550 hi
= mips_hi16_list
;
2552 /* R_MIPS*_GOT16 relocations are something of a special case. We
2553 want to install the addend in the same way as for a R_MIPS*_HI16
2554 relocation (with a rightshift of 16). However, since GOT16
2555 relocations can also be used with global symbols, their howto
2556 has a rightshift of 0. */
2557 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
2558 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
2559 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
2560 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
2561 else if (hi
->rel
.howto
->type
== R_MICROMIPS_GOT16
)
2562 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MICROMIPS_HI16
, FALSE
);
2564 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
2565 carry or borrow will induce a change of +1 or -1 in the high part. */
2566 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
2568 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
2569 hi
->input_section
, output_bfd
,
2571 if (ret
!= bfd_reloc_ok
)
2574 mips_hi16_list
= hi
->next
;
2578 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2579 input_section
, output_bfd
,
2583 /* A generic howto special_function. This calculates and installs the
2584 relocation itself, thus avoiding the oft-discussed problems in
2585 bfd_perform_relocation and bfd_install_relocation. */
2587 bfd_reloc_status_type
2588 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2589 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
2590 asection
*input_section
, bfd
*output_bfd
,
2591 char **error_message ATTRIBUTE_UNUSED
)
2594 bfd_reloc_status_type status
;
2595 bfd_boolean relocatable
;
2597 relocatable
= (output_bfd
!= NULL
);
2599 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2600 return bfd_reloc_outofrange
;
2602 /* Build up the field adjustment in VAL. */
2604 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2606 /* Either we're calculating the final field value or we have a
2607 relocation against a section symbol. Add in the section's
2608 offset or address. */
2609 val
+= symbol
->section
->output_section
->vma
;
2610 val
+= symbol
->section
->output_offset
;
2615 /* We're calculating the final field value. Add in the symbol's value
2616 and, if pc-relative, subtract the address of the field itself. */
2617 val
+= symbol
->value
;
2618 if (reloc_entry
->howto
->pc_relative
)
2620 val
-= input_section
->output_section
->vma
;
2621 val
-= input_section
->output_offset
;
2622 val
-= reloc_entry
->address
;
2626 /* VAL is now the final adjustment. If we're keeping this relocation
2627 in the output file, and if the relocation uses a separate addend,
2628 we just need to add VAL to that addend. Otherwise we need to add
2629 VAL to the relocation field itself. */
2630 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
2631 reloc_entry
->addend
+= val
;
2634 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2636 /* Add in the separate addend, if any. */
2637 val
+= reloc_entry
->addend
;
2639 /* Add VAL to the relocation field. */
2640 _bfd_mips_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2642 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
2644 _bfd_mips_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2647 if (status
!= bfd_reloc_ok
)
2652 reloc_entry
->address
+= input_section
->output_offset
;
2654 return bfd_reloc_ok
;
2657 /* Swap an entry in a .gptab section. Note that these routines rely
2658 on the equivalence of the two elements of the union. */
2661 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
2664 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2665 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2669 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
2670 Elf32_External_gptab
*ex
)
2672 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
2673 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
2677 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
2678 Elf32_External_compact_rel
*ex
)
2680 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
2681 H_PUT_32 (abfd
, in
->num
, ex
->num
);
2682 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
2683 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
2684 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
2685 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
2689 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
2690 Elf32_External_crinfo
*ex
)
2694 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2695 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2696 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2697 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2698 H_PUT_32 (abfd
, l
, ex
->info
);
2699 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
2700 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
2703 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2704 routines swap this structure in and out. They are used outside of
2705 BFD, so they are globally visible. */
2708 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
2711 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2712 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2713 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2714 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2715 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2716 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
2720 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
2721 Elf32_External_RegInfo
*ex
)
2723 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2724 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2725 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2726 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2727 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2728 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2731 /* In the 64 bit ABI, the .MIPS.options section holds register
2732 information in an Elf64_Reginfo structure. These routines swap
2733 them in and out. They are globally visible because they are used
2734 outside of BFD. These routines are here so that gas can call them
2735 without worrying about whether the 64 bit ABI has been included. */
2738 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
2739 Elf64_Internal_RegInfo
*in
)
2741 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2742 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
2743 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2744 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2745 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2746 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2747 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
2751 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
2752 Elf64_External_RegInfo
*ex
)
2754 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2755 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
2756 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2757 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2758 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2759 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2760 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2763 /* Swap in an options header. */
2766 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
2767 Elf_Internal_Options
*in
)
2769 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
2770 in
->size
= H_GET_8 (abfd
, ex
->size
);
2771 in
->section
= H_GET_16 (abfd
, ex
->section
);
2772 in
->info
= H_GET_32 (abfd
, ex
->info
);
2775 /* Swap out an options header. */
2778 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
2779 Elf_External_Options
*ex
)
2781 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
2782 H_PUT_8 (abfd
, in
->size
, ex
->size
);
2783 H_PUT_16 (abfd
, in
->section
, ex
->section
);
2784 H_PUT_32 (abfd
, in
->info
, ex
->info
);
2787 /* Swap in an abiflags structure. */
2790 bfd_mips_elf_swap_abiflags_v0_in (bfd
*abfd
,
2791 const Elf_External_ABIFlags_v0
*ex
,
2792 Elf_Internal_ABIFlags_v0
*in
)
2794 in
->version
= H_GET_16 (abfd
, ex
->version
);
2795 in
->isa_level
= H_GET_8 (abfd
, ex
->isa_level
);
2796 in
->isa_rev
= H_GET_8 (abfd
, ex
->isa_rev
);
2797 in
->gpr_size
= H_GET_8 (abfd
, ex
->gpr_size
);
2798 in
->cpr1_size
= H_GET_8 (abfd
, ex
->cpr1_size
);
2799 in
->cpr2_size
= H_GET_8 (abfd
, ex
->cpr2_size
);
2800 in
->fp_abi
= H_GET_8 (abfd
, ex
->fp_abi
);
2801 in
->isa_ext
= H_GET_32 (abfd
, ex
->isa_ext
);
2802 in
->ases
= H_GET_32 (abfd
, ex
->ases
);
2803 in
->flags1
= H_GET_32 (abfd
, ex
->flags1
);
2804 in
->flags2
= H_GET_32 (abfd
, ex
->flags2
);
2807 /* Swap out an abiflags structure. */
2810 bfd_mips_elf_swap_abiflags_v0_out (bfd
*abfd
,
2811 const Elf_Internal_ABIFlags_v0
*in
,
2812 Elf_External_ABIFlags_v0
*ex
)
2814 H_PUT_16 (abfd
, in
->version
, ex
->version
);
2815 H_PUT_8 (abfd
, in
->isa_level
, ex
->isa_level
);
2816 H_PUT_8 (abfd
, in
->isa_rev
, ex
->isa_rev
);
2817 H_PUT_8 (abfd
, in
->gpr_size
, ex
->gpr_size
);
2818 H_PUT_8 (abfd
, in
->cpr1_size
, ex
->cpr1_size
);
2819 H_PUT_8 (abfd
, in
->cpr2_size
, ex
->cpr2_size
);
2820 H_PUT_8 (abfd
, in
->fp_abi
, ex
->fp_abi
);
2821 H_PUT_32 (abfd
, in
->isa_ext
, ex
->isa_ext
);
2822 H_PUT_32 (abfd
, in
->ases
, ex
->ases
);
2823 H_PUT_32 (abfd
, in
->flags1
, ex
->flags1
);
2824 H_PUT_32 (abfd
, in
->flags2
, ex
->flags2
);
2827 /* This function is called via qsort() to sort the dynamic relocation
2828 entries by increasing r_symndx value. */
2831 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
2833 Elf_Internal_Rela int_reloc1
;
2834 Elf_Internal_Rela int_reloc2
;
2837 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
2838 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
2840 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
2844 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
2846 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
2851 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
2854 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
2855 const void *arg2 ATTRIBUTE_UNUSED
)
2858 Elf_Internal_Rela int_reloc1
[3];
2859 Elf_Internal_Rela int_reloc2
[3];
2861 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2862 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
2863 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2864 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
2866 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
2868 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
2871 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
2873 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
2882 /* This routine is used to write out ECOFF debugging external symbol
2883 information. It is called via mips_elf_link_hash_traverse. The
2884 ECOFF external symbol information must match the ELF external
2885 symbol information. Unfortunately, at this point we don't know
2886 whether a symbol is required by reloc information, so the two
2887 tables may wind up being different. We must sort out the external
2888 symbol information before we can set the final size of the .mdebug
2889 section, and we must set the size of the .mdebug section before we
2890 can relocate any sections, and we can't know which symbols are
2891 required by relocation until we relocate the sections.
2892 Fortunately, it is relatively unlikely that any symbol will be
2893 stripped but required by a reloc. In particular, it can not happen
2894 when generating a final executable. */
2897 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
2899 struct extsym_info
*einfo
= data
;
2901 asection
*sec
, *output_section
;
2903 if (h
->root
.indx
== -2)
2905 else if ((h
->root
.def_dynamic
2906 || h
->root
.ref_dynamic
2907 || h
->root
.type
== bfd_link_hash_new
)
2908 && !h
->root
.def_regular
2909 && !h
->root
.ref_regular
)
2911 else if (einfo
->info
->strip
== strip_all
2912 || (einfo
->info
->strip
== strip_some
2913 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2914 h
->root
.root
.root
.string
,
2915 FALSE
, FALSE
) == NULL
))
2923 if (h
->esym
.ifd
== -2)
2926 h
->esym
.cobol_main
= 0;
2927 h
->esym
.weakext
= 0;
2928 h
->esym
.reserved
= 0;
2929 h
->esym
.ifd
= ifdNil
;
2930 h
->esym
.asym
.value
= 0;
2931 h
->esym
.asym
.st
= stGlobal
;
2933 if (h
->root
.root
.type
== bfd_link_hash_undefined
2934 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
2938 /* Use undefined class. Also, set class and type for some
2940 name
= h
->root
.root
.root
.string
;
2941 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2942 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2944 h
->esym
.asym
.sc
= scData
;
2945 h
->esym
.asym
.st
= stLabel
;
2946 h
->esym
.asym
.value
= 0;
2948 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2950 h
->esym
.asym
.sc
= scAbs
;
2951 h
->esym
.asym
.st
= stLabel
;
2952 h
->esym
.asym
.value
=
2953 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2956 h
->esym
.asym
.sc
= scUndefined
;
2958 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2959 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2960 h
->esym
.asym
.sc
= scAbs
;
2965 sec
= h
->root
.root
.u
.def
.section
;
2966 output_section
= sec
->output_section
;
2968 /* When making a shared library and symbol h is the one from
2969 the another shared library, OUTPUT_SECTION may be null. */
2970 if (output_section
== NULL
)
2971 h
->esym
.asym
.sc
= scUndefined
;
2974 name
= bfd_section_name (output_section
);
2976 if (strcmp (name
, ".text") == 0)
2977 h
->esym
.asym
.sc
= scText
;
2978 else if (strcmp (name
, ".data") == 0)
2979 h
->esym
.asym
.sc
= scData
;
2980 else if (strcmp (name
, ".sdata") == 0)
2981 h
->esym
.asym
.sc
= scSData
;
2982 else if (strcmp (name
, ".rodata") == 0
2983 || strcmp (name
, ".rdata") == 0)
2984 h
->esym
.asym
.sc
= scRData
;
2985 else if (strcmp (name
, ".bss") == 0)
2986 h
->esym
.asym
.sc
= scBss
;
2987 else if (strcmp (name
, ".sbss") == 0)
2988 h
->esym
.asym
.sc
= scSBss
;
2989 else if (strcmp (name
, ".init") == 0)
2990 h
->esym
.asym
.sc
= scInit
;
2991 else if (strcmp (name
, ".fini") == 0)
2992 h
->esym
.asym
.sc
= scFini
;
2994 h
->esym
.asym
.sc
= scAbs
;
2998 h
->esym
.asym
.reserved
= 0;
2999 h
->esym
.asym
.index
= indexNil
;
3002 if (h
->root
.root
.type
== bfd_link_hash_common
)
3003 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3004 else if (h
->root
.root
.type
== bfd_link_hash_defined
3005 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3007 if (h
->esym
.asym
.sc
== scCommon
)
3008 h
->esym
.asym
.sc
= scBss
;
3009 else if (h
->esym
.asym
.sc
== scSCommon
)
3010 h
->esym
.asym
.sc
= scSBss
;
3012 sec
= h
->root
.root
.u
.def
.section
;
3013 output_section
= sec
->output_section
;
3014 if (output_section
!= NULL
)
3015 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3016 + sec
->output_offset
3017 + output_section
->vma
);
3019 h
->esym
.asym
.value
= 0;
3023 struct mips_elf_link_hash_entry
*hd
= h
;
3025 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
3026 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3028 if (hd
->needs_lazy_stub
)
3030 BFD_ASSERT (hd
->root
.plt
.plist
!= NULL
);
3031 BFD_ASSERT (hd
->root
.plt
.plist
->stub_offset
!= MINUS_ONE
);
3032 /* Set type and value for a symbol with a function stub. */
3033 h
->esym
.asym
.st
= stProc
;
3034 sec
= hd
->root
.root
.u
.def
.section
;
3036 h
->esym
.asym
.value
= 0;
3039 output_section
= sec
->output_section
;
3040 if (output_section
!= NULL
)
3041 h
->esym
.asym
.value
= (hd
->root
.plt
.plist
->stub_offset
3042 + sec
->output_offset
3043 + output_section
->vma
);
3045 h
->esym
.asym
.value
= 0;
3050 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3051 h
->root
.root
.root
.string
,
3054 einfo
->failed
= TRUE
;
3061 /* A comparison routine used to sort .gptab entries. */
3064 gptab_compare (const void *p1
, const void *p2
)
3066 const Elf32_gptab
*a1
= p1
;
3067 const Elf32_gptab
*a2
= p2
;
3069 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3072 /* Functions to manage the got entry hash table. */
3074 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
3077 static INLINE hashval_t
3078 mips_elf_hash_bfd_vma (bfd_vma addr
)
3081 return addr
+ (addr
>> 32);
3088 mips_elf_got_entry_hash (const void *entry_
)
3090 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
3092 return (entry
->symndx
3093 + ((entry
->tls_type
== GOT_TLS_LDM
) << 18)
3094 + (entry
->tls_type
== GOT_TLS_LDM
? 0
3095 : !entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
3096 : entry
->symndx
>= 0 ? (entry
->abfd
->id
3097 + mips_elf_hash_bfd_vma (entry
->d
.addend
))
3098 : entry
->d
.h
->root
.root
.root
.hash
));
3102 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
3104 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
3105 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
3107 return (e1
->symndx
== e2
->symndx
3108 && e1
->tls_type
== e2
->tls_type
3109 && (e1
->tls_type
== GOT_TLS_LDM
? TRUE
3110 : !e1
->abfd
? !e2
->abfd
&& e1
->d
.address
== e2
->d
.address
3111 : e1
->symndx
>= 0 ? (e1
->abfd
== e2
->abfd
3112 && e1
->d
.addend
== e2
->d
.addend
)
3113 : e2
->abfd
&& e1
->d
.h
== e2
->d
.h
));
3117 mips_got_page_ref_hash (const void *ref_
)
3119 const struct mips_got_page_ref
*ref
;
3121 ref
= (const struct mips_got_page_ref
*) ref_
;
3122 return ((ref
->symndx
>= 0
3123 ? (hashval_t
) (ref
->u
.abfd
->id
+ ref
->symndx
)
3124 : ref
->u
.h
->root
.root
.root
.hash
)
3125 + mips_elf_hash_bfd_vma (ref
->addend
));
3129 mips_got_page_ref_eq (const void *ref1_
, const void *ref2_
)
3131 const struct mips_got_page_ref
*ref1
, *ref2
;
3133 ref1
= (const struct mips_got_page_ref
*) ref1_
;
3134 ref2
= (const struct mips_got_page_ref
*) ref2_
;
3135 return (ref1
->symndx
== ref2
->symndx
3136 && (ref1
->symndx
< 0
3137 ? ref1
->u
.h
== ref2
->u
.h
3138 : ref1
->u
.abfd
== ref2
->u
.abfd
)
3139 && ref1
->addend
== ref2
->addend
);
3143 mips_got_page_entry_hash (const void *entry_
)
3145 const struct mips_got_page_entry
*entry
;
3147 entry
= (const struct mips_got_page_entry
*) entry_
;
3148 return entry
->sec
->id
;
3152 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
3154 const struct mips_got_page_entry
*entry1
, *entry2
;
3156 entry1
= (const struct mips_got_page_entry
*) entry1_
;
3157 entry2
= (const struct mips_got_page_entry
*) entry2_
;
3158 return entry1
->sec
== entry2
->sec
;
3161 /* Create and return a new mips_got_info structure. */
3163 static struct mips_got_info
*
3164 mips_elf_create_got_info (bfd
*abfd
)
3166 struct mips_got_info
*g
;
3168 g
= bfd_zalloc (abfd
, sizeof (struct mips_got_info
));
3172 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
3173 mips_elf_got_entry_eq
, NULL
);
3174 if (g
->got_entries
== NULL
)
3177 g
->got_page_refs
= htab_try_create (1, mips_got_page_ref_hash
,
3178 mips_got_page_ref_eq
, NULL
);
3179 if (g
->got_page_refs
== NULL
)
3185 /* Return the GOT info for input bfd ABFD, trying to create a new one if
3186 CREATE_P and if ABFD doesn't already have a GOT. */
3188 static struct mips_got_info
*
3189 mips_elf_bfd_got (bfd
*abfd
, bfd_boolean create_p
)
3191 struct mips_elf_obj_tdata
*tdata
;
3193 if (!is_mips_elf (abfd
))
3196 tdata
= mips_elf_tdata (abfd
);
3197 if (!tdata
->got
&& create_p
)
3198 tdata
->got
= mips_elf_create_got_info (abfd
);
3202 /* Record that ABFD should use output GOT G. */
3205 mips_elf_replace_bfd_got (bfd
*abfd
, struct mips_got_info
*g
)
3207 struct mips_elf_obj_tdata
*tdata
;
3209 BFD_ASSERT (is_mips_elf (abfd
));
3210 tdata
= mips_elf_tdata (abfd
);
3213 /* The GOT structure itself and the hash table entries are
3214 allocated to a bfd, but the hash tables aren't. */
3215 htab_delete (tdata
->got
->got_entries
);
3216 htab_delete (tdata
->got
->got_page_refs
);
3217 if (tdata
->got
->got_page_entries
)
3218 htab_delete (tdata
->got
->got_page_entries
);
3223 /* Return the dynamic relocation section. If it doesn't exist, try to
3224 create a new it if CREATE_P, otherwise return NULL. Also return NULL
3225 if creation fails. */
3228 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
3234 dname
= MIPS_ELF_REL_DYN_NAME (info
);
3235 dynobj
= elf_hash_table (info
)->dynobj
;
3236 sreloc
= bfd_get_linker_section (dynobj
, dname
);
3237 if (sreloc
== NULL
&& create_p
)
3239 sreloc
= bfd_make_section_anyway_with_flags (dynobj
, dname
,
3244 | SEC_LINKER_CREATED
3247 || !bfd_set_section_alignment (sreloc
,
3248 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
3254 /* Return the GOT_TLS_* type required by relocation type R_TYPE. */
3257 mips_elf_reloc_tls_type (unsigned int r_type
)
3259 if (tls_gd_reloc_p (r_type
))
3262 if (tls_ldm_reloc_p (r_type
))
3265 if (tls_gottprel_reloc_p (r_type
))
3268 return GOT_TLS_NONE
;
3271 /* Return the number of GOT slots needed for GOT TLS type TYPE. */
3274 mips_tls_got_entries (unsigned int type
)
3291 /* Count the number of relocations needed for a TLS GOT entry, with
3292 access types from TLS_TYPE, and symbol H (or a local symbol if H
3296 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
3297 struct elf_link_hash_entry
*h
)
3300 bfd_boolean need_relocs
= FALSE
;
3301 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
3305 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
3306 && (bfd_link_dll (info
) || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
3309 if ((bfd_link_dll (info
) || indx
!= 0)
3311 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3312 || h
->root
.type
!= bfd_link_hash_undefweak
))
3321 return indx
!= 0 ? 2 : 1;
3327 return bfd_link_dll (info
) ? 1 : 0;
3334 /* Add the number of GOT entries and TLS relocations required by ENTRY
3338 mips_elf_count_got_entry (struct bfd_link_info
*info
,
3339 struct mips_got_info
*g
,
3340 struct mips_got_entry
*entry
)
3342 if (entry
->tls_type
)
3344 g
->tls_gotno
+= mips_tls_got_entries (entry
->tls_type
);
3345 g
->relocs
+= mips_tls_got_relocs (info
, entry
->tls_type
,
3347 ? &entry
->d
.h
->root
: NULL
);
3349 else if (entry
->symndx
>= 0 || entry
->d
.h
->global_got_area
== GGA_NONE
)
3350 g
->local_gotno
+= 1;
3352 g
->global_gotno
+= 1;
3355 /* Output a simple dynamic relocation into SRELOC. */
3358 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
3360 unsigned long reloc_index
,
3365 Elf_Internal_Rela rel
[3];
3367 memset (rel
, 0, sizeof (rel
));
3369 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
3370 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
3372 if (ABI_64_P (output_bfd
))
3374 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
3375 (output_bfd
, &rel
[0],
3377 + reloc_index
* sizeof (Elf64_Mips_External_Rel
)));
3380 bfd_elf32_swap_reloc_out
3381 (output_bfd
, &rel
[0],
3383 + reloc_index
* sizeof (Elf32_External_Rel
)));
3386 /* Initialize a set of TLS GOT entries for one symbol. */
3389 mips_elf_initialize_tls_slots (bfd
*abfd
, struct bfd_link_info
*info
,
3390 struct mips_got_entry
*entry
,
3391 struct mips_elf_link_hash_entry
*h
,
3394 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
3395 struct mips_elf_link_hash_table
*htab
;
3397 asection
*sreloc
, *sgot
;
3398 bfd_vma got_offset
, got_offset2
;
3399 bfd_boolean need_relocs
= FALSE
;
3401 htab
= mips_elf_hash_table (info
);
3405 sgot
= htab
->root
.sgot
;
3409 && h
->root
.dynindx
!= -1
3410 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), &h
->root
)
3411 && (bfd_link_dll (info
) || !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
3412 indx
= h
->root
.dynindx
;
3414 if (entry
->tls_initialized
)
3417 if ((bfd_link_dll (info
) || indx
!= 0)
3419 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
3420 || h
->root
.type
!= bfd_link_hash_undefweak
))
3423 /* MINUS_ONE means the symbol is not defined in this object. It may not
3424 be defined at all; assume that the value doesn't matter in that
3425 case. Otherwise complain if we would use the value. */
3426 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
3427 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
3429 /* Emit necessary relocations. */
3430 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
3431 got_offset
= entry
->gotidx
;
3433 switch (entry
->tls_type
)
3436 /* General Dynamic. */
3437 got_offset2
= got_offset
+ MIPS_ELF_GOT_SIZE (abfd
);
3441 mips_elf_output_dynamic_relocation
3442 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3443 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
3444 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
3447 mips_elf_output_dynamic_relocation
3448 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3449 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
3450 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset2
);
3452 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
3453 sgot
->contents
+ got_offset2
);
3457 MIPS_ELF_PUT_WORD (abfd
, 1,
3458 sgot
->contents
+ got_offset
);
3459 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
3460 sgot
->contents
+ got_offset2
);
3465 /* Initial Exec model. */
3469 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
3470 sgot
->contents
+ got_offset
);
3472 MIPS_ELF_PUT_WORD (abfd
, 0,
3473 sgot
->contents
+ got_offset
);
3475 mips_elf_output_dynamic_relocation
3476 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3477 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
3478 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
3481 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
3482 sgot
->contents
+ got_offset
);
3486 /* The initial offset is zero, and the LD offsets will include the
3487 bias by DTP_OFFSET. */
3488 MIPS_ELF_PUT_WORD (abfd
, 0,
3489 sgot
->contents
+ got_offset
3490 + MIPS_ELF_GOT_SIZE (abfd
));
3492 if (!bfd_link_dll (info
))
3493 MIPS_ELF_PUT_WORD (abfd
, 1,
3494 sgot
->contents
+ got_offset
);
3496 mips_elf_output_dynamic_relocation
3497 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3498 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
3499 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
3506 entry
->tls_initialized
= TRUE
;
3509 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
3510 for global symbol H. .got.plt comes before the GOT, so the offset
3511 will be negative. */
3514 mips_elf_gotplt_index (struct bfd_link_info
*info
,
3515 struct elf_link_hash_entry
*h
)
3517 bfd_vma got_address
, got_value
;
3518 struct mips_elf_link_hash_table
*htab
;
3520 htab
= mips_elf_hash_table (info
);
3521 BFD_ASSERT (htab
!= NULL
);
3523 BFD_ASSERT (h
->plt
.plist
!= NULL
);
3524 BFD_ASSERT (h
->plt
.plist
->gotplt_index
!= MINUS_ONE
);
3526 /* Calculate the address of the associated .got.plt entry. */
3527 got_address
= (htab
->root
.sgotplt
->output_section
->vma
3528 + htab
->root
.sgotplt
->output_offset
3529 + (h
->plt
.plist
->gotplt_index
3530 * MIPS_ELF_GOT_SIZE (info
->output_bfd
)));
3532 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
3533 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
3534 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
3535 + htab
->root
.hgot
->root
.u
.def
.value
);
3537 return got_address
- got_value
;
3540 /* Return the GOT offset for address VALUE. If there is not yet a GOT
3541 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
3542 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
3543 offset can be found. */
3546 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3547 bfd_vma value
, unsigned long r_symndx
,
3548 struct mips_elf_link_hash_entry
*h
, int r_type
)
3550 struct mips_elf_link_hash_table
*htab
;
3551 struct mips_got_entry
*entry
;
3553 htab
= mips_elf_hash_table (info
);
3554 BFD_ASSERT (htab
!= NULL
);
3556 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
3557 r_symndx
, h
, r_type
);
3561 if (entry
->tls_type
)
3562 mips_elf_initialize_tls_slots (abfd
, info
, entry
, h
, value
);
3563 return entry
->gotidx
;
3566 /* Return the GOT index of global symbol H in the primary GOT. */
3569 mips_elf_primary_global_got_index (bfd
*obfd
, struct bfd_link_info
*info
,
3570 struct elf_link_hash_entry
*h
)
3572 struct mips_elf_link_hash_table
*htab
;
3573 long global_got_dynindx
;
3574 struct mips_got_info
*g
;
3577 htab
= mips_elf_hash_table (info
);
3578 BFD_ASSERT (htab
!= NULL
);
3580 global_got_dynindx
= 0;
3581 if (htab
->global_gotsym
!= NULL
)
3582 global_got_dynindx
= htab
->global_gotsym
->dynindx
;
3584 /* Once we determine the global GOT entry with the lowest dynamic
3585 symbol table index, we must put all dynamic symbols with greater
3586 indices into the primary GOT. That makes it easy to calculate the
3588 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
3589 g
= mips_elf_bfd_got (obfd
, FALSE
);
3590 got_index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
3591 * MIPS_ELF_GOT_SIZE (obfd
));
3592 BFD_ASSERT (got_index
< htab
->root
.sgot
->size
);
3597 /* Return the GOT index for the global symbol indicated by H, which is
3598 referenced by a relocation of type R_TYPE in IBFD. */
3601 mips_elf_global_got_index (bfd
*obfd
, struct bfd_link_info
*info
, bfd
*ibfd
,
3602 struct elf_link_hash_entry
*h
, int r_type
)
3604 struct mips_elf_link_hash_table
*htab
;
3605 struct mips_got_info
*g
;
3606 struct mips_got_entry lookup
, *entry
;
3609 htab
= mips_elf_hash_table (info
);
3610 BFD_ASSERT (htab
!= NULL
);
3612 g
= mips_elf_bfd_got (ibfd
, FALSE
);
3615 lookup
.tls_type
= mips_elf_reloc_tls_type (r_type
);
3616 if (!lookup
.tls_type
&& g
== mips_elf_bfd_got (obfd
, FALSE
))
3617 return mips_elf_primary_global_got_index (obfd
, info
, h
);
3621 lookup
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3622 entry
= htab_find (g
->got_entries
, &lookup
);
3625 gotidx
= entry
->gotidx
;
3626 BFD_ASSERT (gotidx
> 0 && gotidx
< htab
->root
.sgot
->size
);
3628 if (lookup
.tls_type
)
3630 bfd_vma value
= MINUS_ONE
;
3632 if ((h
->root
.type
== bfd_link_hash_defined
3633 || h
->root
.type
== bfd_link_hash_defweak
)
3634 && h
->root
.u
.def
.section
->output_section
)
3635 value
= (h
->root
.u
.def
.value
3636 + h
->root
.u
.def
.section
->output_offset
3637 + h
->root
.u
.def
.section
->output_section
->vma
);
3639 mips_elf_initialize_tls_slots (obfd
, info
, entry
, lookup
.d
.h
, value
);
3644 /* Find a GOT page entry that points to within 32KB of VALUE. These
3645 entries are supposed to be placed at small offsets in the GOT, i.e.,
3646 within 32KB of GP. Return the index of the GOT entry, or -1 if no
3647 entry could be created. If OFFSETP is nonnull, use it to return the
3648 offset of the GOT entry from VALUE. */
3651 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3652 bfd_vma value
, bfd_vma
*offsetp
)
3654 bfd_vma page
, got_index
;
3655 struct mips_got_entry
*entry
;
3657 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
3658 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
3659 NULL
, R_MIPS_GOT_PAGE
);
3664 got_index
= entry
->gotidx
;
3667 *offsetp
= value
- entry
->d
.address
;
3672 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
3673 EXTERNAL is true if the relocation was originally against a global
3674 symbol that binds locally. */
3677 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3678 bfd_vma value
, bfd_boolean external
)
3680 struct mips_got_entry
*entry
;
3682 /* GOT16 relocations against local symbols are followed by a LO16
3683 relocation; those against global symbols are not. Thus if the
3684 symbol was originally local, the GOT16 relocation should load the
3685 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
3687 value
= mips_elf_high (value
) << 16;
3689 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
3690 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
3691 same in all cases. */
3692 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
3693 NULL
, R_MIPS_GOT16
);
3695 return entry
->gotidx
;
3700 /* Returns the offset for the entry at the INDEXth position
3704 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
3705 bfd
*input_bfd
, bfd_vma got_index
)
3707 struct mips_elf_link_hash_table
*htab
;
3711 htab
= mips_elf_hash_table (info
);
3712 BFD_ASSERT (htab
!= NULL
);
3714 sgot
= htab
->root
.sgot
;
3715 gp
= _bfd_get_gp_value (output_bfd
)
3716 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
3718 return sgot
->output_section
->vma
+ sgot
->output_offset
+ got_index
- gp
;
3721 /* Create and return a local GOT entry for VALUE, which was calculated
3722 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
3723 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
3726 static struct mips_got_entry
*
3727 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3728 bfd
*ibfd
, bfd_vma value
,
3729 unsigned long r_symndx
,
3730 struct mips_elf_link_hash_entry
*h
,
3733 struct mips_got_entry lookup
, *entry
;
3735 struct mips_got_info
*g
;
3736 struct mips_elf_link_hash_table
*htab
;
3739 htab
= mips_elf_hash_table (info
);
3740 BFD_ASSERT (htab
!= NULL
);
3742 g
= mips_elf_bfd_got (ibfd
, FALSE
);
3745 g
= mips_elf_bfd_got (abfd
, FALSE
);
3746 BFD_ASSERT (g
!= NULL
);
3749 /* This function shouldn't be called for symbols that live in the global
3751 BFD_ASSERT (h
== NULL
|| h
->global_got_area
== GGA_NONE
);
3753 lookup
.tls_type
= mips_elf_reloc_tls_type (r_type
);
3754 if (lookup
.tls_type
)
3757 if (tls_ldm_reloc_p (r_type
))
3760 lookup
.d
.addend
= 0;
3764 lookup
.symndx
= r_symndx
;
3765 lookup
.d
.addend
= 0;
3773 entry
= (struct mips_got_entry
*) htab_find (g
->got_entries
, &lookup
);
3776 gotidx
= entry
->gotidx
;
3777 BFD_ASSERT (gotidx
> 0 && gotidx
< htab
->root
.sgot
->size
);
3784 lookup
.d
.address
= value
;
3785 loc
= htab_find_slot (g
->got_entries
, &lookup
, INSERT
);
3789 entry
= (struct mips_got_entry
*) *loc
;
3793 if (g
->assigned_low_gotno
> g
->assigned_high_gotno
)
3795 /* We didn't allocate enough space in the GOT. */
3797 (_("not enough GOT space for local GOT entries"));
3798 bfd_set_error (bfd_error_bad_value
);
3802 entry
= (struct mips_got_entry
*) bfd_alloc (abfd
, sizeof (*entry
));
3806 if (got16_reloc_p (r_type
)
3807 || call16_reloc_p (r_type
)
3808 || got_page_reloc_p (r_type
)
3809 || got_disp_reloc_p (r_type
))
3810 lookup
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_low_gotno
++;
3812 lookup
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_high_gotno
--;
3817 MIPS_ELF_PUT_WORD (abfd
, value
, htab
->root
.sgot
->contents
+ entry
->gotidx
);
3819 /* These GOT entries need a dynamic relocation on VxWorks. */
3820 if (htab
->root
.target_os
== is_vxworks
)
3822 Elf_Internal_Rela outrel
;
3825 bfd_vma got_address
;
3827 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3828 got_address
= (htab
->root
.sgot
->output_section
->vma
3829 + htab
->root
.sgot
->output_offset
3832 rloc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
3833 outrel
.r_offset
= got_address
;
3834 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
3835 outrel
.r_addend
= value
;
3836 bfd_elf32_swap_reloca_out (abfd
, &outrel
, rloc
);
3842 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
3843 The number might be exact or a worst-case estimate, depending on how
3844 much information is available to elf_backend_omit_section_dynsym at
3845 the current linking stage. */
3847 static bfd_size_type
3848 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
3850 bfd_size_type count
;
3853 if (bfd_link_pic (info
)
3854 || elf_hash_table (info
)->is_relocatable_executable
)
3857 const struct elf_backend_data
*bed
;
3859 bed
= get_elf_backend_data (output_bfd
);
3860 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
3861 if ((p
->flags
& SEC_EXCLUDE
) == 0
3862 && (p
->flags
& SEC_ALLOC
) != 0
3863 && elf_hash_table (info
)->dynamic_relocs
3864 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
3870 /* Sort the dynamic symbol table so that symbols that need GOT entries
3871 appear towards the end. */
3874 mips_elf_sort_hash_table (bfd
*abfd
, struct bfd_link_info
*info
)
3876 struct mips_elf_link_hash_table
*htab
;
3877 struct mips_elf_hash_sort_data hsd
;
3878 struct mips_got_info
*g
;
3880 htab
= mips_elf_hash_table (info
);
3881 BFD_ASSERT (htab
!= NULL
);
3883 if (htab
->root
.dynsymcount
== 0)
3891 hsd
.max_unref_got_dynindx
3892 = hsd
.min_got_dynindx
3893 = (htab
->root
.dynsymcount
- g
->reloc_only_gotno
);
3894 /* Add 1 to local symbol indices to account for the mandatory NULL entry
3895 at the head of the table; see `_bfd_elf_link_renumber_dynsyms'. */
3896 hsd
.max_local_dynindx
= count_section_dynsyms (abfd
, info
) + 1;
3897 hsd
.max_non_got_dynindx
= htab
->root
.local_dynsymcount
+ 1;
3898 hsd
.output_bfd
= abfd
;
3899 if (htab
->root
.dynobj
!= NULL
3900 && htab
->root
.dynamic_sections_created
3901 && info
->emit_gnu_hash
)
3903 asection
*s
= bfd_get_linker_section (htab
->root
.dynobj
, ".MIPS.xhash");
3904 BFD_ASSERT (s
!= NULL
);
3905 hsd
.mipsxhash
= s
->contents
;
3906 BFD_ASSERT (hsd
.mipsxhash
!= NULL
);
3909 hsd
.mipsxhash
= NULL
;
3910 mips_elf_link_hash_traverse (htab
, mips_elf_sort_hash_table_f
, &hsd
);
3912 /* There should have been enough room in the symbol table to
3913 accommodate both the GOT and non-GOT symbols. */
3914 BFD_ASSERT (hsd
.max_local_dynindx
<= htab
->root
.local_dynsymcount
+ 1);
3915 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
3916 BFD_ASSERT (hsd
.max_unref_got_dynindx
== htab
->root
.dynsymcount
);
3917 BFD_ASSERT (htab
->root
.dynsymcount
- hsd
.min_got_dynindx
== g
->global_gotno
);
3919 /* Now we know which dynamic symbol has the lowest dynamic symbol
3920 table index in the GOT. */
3921 htab
->global_gotsym
= hsd
.low
;
3926 /* If H needs a GOT entry, assign it the highest available dynamic
3927 index. Otherwise, assign it the lowest available dynamic
3931 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
3933 struct mips_elf_hash_sort_data
*hsd
= data
;
3935 /* Symbols without dynamic symbol table entries aren't interesting
3937 if (h
->root
.dynindx
== -1)
3940 switch (h
->global_got_area
)
3943 if (h
->root
.forced_local
)
3944 h
->root
.dynindx
= hsd
->max_local_dynindx
++;
3946 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
3950 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
3951 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3954 case GGA_RELOC_ONLY
:
3955 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
3956 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3957 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
3961 /* Populate the .MIPS.xhash translation table entry with
3962 the symbol dynindx. */
3963 if (h
->mipsxhash_loc
!= 0 && hsd
->mipsxhash
!= NULL
)
3964 bfd_put_32 (hsd
->output_bfd
, h
->root
.dynindx
,
3965 hsd
->mipsxhash
+ h
->mipsxhash_loc
);
3970 /* Record that input bfd ABFD requires a GOT entry like *LOOKUP
3971 (which is owned by the caller and shouldn't be added to the
3972 hash table directly). */
3975 mips_elf_record_got_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3976 struct mips_got_entry
*lookup
)
3978 struct mips_elf_link_hash_table
*htab
;
3979 struct mips_got_entry
*entry
;
3980 struct mips_got_info
*g
;
3981 void **loc
, **bfd_loc
;
3983 /* Make sure there's a slot for this entry in the master GOT. */
3984 htab
= mips_elf_hash_table (info
);
3986 loc
= htab_find_slot (g
->got_entries
, lookup
, INSERT
);
3990 /* Populate the entry if it isn't already. */
3991 entry
= (struct mips_got_entry
*) *loc
;
3994 entry
= (struct mips_got_entry
*) bfd_alloc (abfd
, sizeof (*entry
));
3998 lookup
->tls_initialized
= FALSE
;
3999 lookup
->gotidx
= -1;
4004 /* Reuse the same GOT entry for the BFD's GOT. */
4005 g
= mips_elf_bfd_got (abfd
, TRUE
);
4009 bfd_loc
= htab_find_slot (g
->got_entries
, lookup
, INSERT
);
4018 /* ABFD has a GOT relocation of type R_TYPE against H. Reserve a GOT
4019 entry for it. FOR_CALL is true if the caller is only interested in
4020 using the GOT entry for calls. */
4023 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
4024 bfd
*abfd
, struct bfd_link_info
*info
,
4025 bfd_boolean for_call
, int r_type
)
4027 struct mips_elf_link_hash_table
*htab
;
4028 struct mips_elf_link_hash_entry
*hmips
;
4029 struct mips_got_entry entry
;
4030 unsigned char tls_type
;
4032 htab
= mips_elf_hash_table (info
);
4033 BFD_ASSERT (htab
!= NULL
);
4035 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4037 hmips
->got_only_for_calls
= FALSE
;
4039 /* A global symbol in the GOT must also be in the dynamic symbol
4041 if (h
->dynindx
== -1)
4043 switch (ELF_ST_VISIBILITY (h
->other
))
4047 _bfd_mips_elf_hide_symbol (info
, h
, TRUE
);
4050 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
4054 tls_type
= mips_elf_reloc_tls_type (r_type
);
4055 if (tls_type
== GOT_TLS_NONE
&& hmips
->global_got_area
> GGA_NORMAL
)
4056 hmips
->global_got_area
= GGA_NORMAL
;
4060 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
4061 entry
.tls_type
= tls_type
;
4062 return mips_elf_record_got_entry (info
, abfd
, &entry
);
4065 /* ABFD has a GOT relocation of type R_TYPE against symbol SYMNDX + ADDEND,
4066 where SYMNDX is a local symbol. Reserve a GOT entry for it. */
4069 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
4070 struct bfd_link_info
*info
, int r_type
)
4072 struct mips_elf_link_hash_table
*htab
;
4073 struct mips_got_info
*g
;
4074 struct mips_got_entry entry
;
4076 htab
= mips_elf_hash_table (info
);
4077 BFD_ASSERT (htab
!= NULL
);
4080 BFD_ASSERT (g
!= NULL
);
4083 entry
.symndx
= symndx
;
4084 entry
.d
.addend
= addend
;
4085 entry
.tls_type
= mips_elf_reloc_tls_type (r_type
);
4086 return mips_elf_record_got_entry (info
, abfd
, &entry
);
4089 /* Record that ABFD has a page relocation against SYMNDX + ADDEND.
4090 H is the symbol's hash table entry, or null if SYMNDX is local
4094 mips_elf_record_got_page_ref (struct bfd_link_info
*info
, bfd
*abfd
,
4095 long symndx
, struct elf_link_hash_entry
*h
,
4096 bfd_signed_vma addend
)
4098 struct mips_elf_link_hash_table
*htab
;
4099 struct mips_got_info
*g1
, *g2
;
4100 struct mips_got_page_ref lookup
, *entry
;
4101 void **loc
, **bfd_loc
;
4103 htab
= mips_elf_hash_table (info
);
4104 BFD_ASSERT (htab
!= NULL
);
4106 g1
= htab
->got_info
;
4107 BFD_ASSERT (g1
!= NULL
);
4112 lookup
.u
.h
= (struct mips_elf_link_hash_entry
*) h
;
4116 lookup
.symndx
= symndx
;
4117 lookup
.u
.abfd
= abfd
;
4119 lookup
.addend
= addend
;
4120 loc
= htab_find_slot (g1
->got_page_refs
, &lookup
, INSERT
);
4124 entry
= (struct mips_got_page_ref
*) *loc
;
4127 entry
= bfd_alloc (abfd
, sizeof (*entry
));
4135 /* Add the same entry to the BFD's GOT. */
4136 g2
= mips_elf_bfd_got (abfd
, TRUE
);
4140 bfd_loc
= htab_find_slot (g2
->got_page_refs
, &lookup
, INSERT
);
4150 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
4153 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
4157 struct mips_elf_link_hash_table
*htab
;
4159 htab
= mips_elf_hash_table (info
);
4160 BFD_ASSERT (htab
!= NULL
);
4162 s
= mips_elf_rel_dyn_section (info
, FALSE
);
4163 BFD_ASSERT (s
!= NULL
);
4165 if (htab
->root
.target_os
== is_vxworks
)
4166 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
4171 /* Make room for a null element. */
4172 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
4175 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
4179 /* A htab_traverse callback for GOT entries, with DATA pointing to a
4180 mips_elf_traverse_got_arg structure. Count the number of GOT
4181 entries and TLS relocs. Set DATA->value to true if we need
4182 to resolve indirect or warning symbols and then recreate the GOT. */
4185 mips_elf_check_recreate_got (void **entryp
, void *data
)
4187 struct mips_got_entry
*entry
;
4188 struct mips_elf_traverse_got_arg
*arg
;
4190 entry
= (struct mips_got_entry
*) *entryp
;
4191 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4192 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
4194 struct mips_elf_link_hash_entry
*h
;
4197 if (h
->root
.root
.type
== bfd_link_hash_indirect
4198 || h
->root
.root
.type
== bfd_link_hash_warning
)
4204 mips_elf_count_got_entry (arg
->info
, arg
->g
, entry
);
4208 /* A htab_traverse callback for GOT entries, with DATA pointing to a
4209 mips_elf_traverse_got_arg structure. Add all entries to DATA->g,
4210 converting entries for indirect and warning symbols into entries
4211 for the target symbol. Set DATA->g to null on error. */
4214 mips_elf_recreate_got (void **entryp
, void *data
)
4216 struct mips_got_entry new_entry
, *entry
;
4217 struct mips_elf_traverse_got_arg
*arg
;
4220 entry
= (struct mips_got_entry
*) *entryp
;
4221 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4222 if (entry
->abfd
!= NULL
4223 && entry
->symndx
== -1
4224 && (entry
->d
.h
->root
.root
.type
== bfd_link_hash_indirect
4225 || entry
->d
.h
->root
.root
.type
== bfd_link_hash_warning
))
4227 struct mips_elf_link_hash_entry
*h
;
4234 BFD_ASSERT (h
->global_got_area
== GGA_NONE
);
4235 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4237 while (h
->root
.root
.type
== bfd_link_hash_indirect
4238 || h
->root
.root
.type
== bfd_link_hash_warning
);
4241 slot
= htab_find_slot (arg
->g
->got_entries
, entry
, INSERT
);
4249 if (entry
== &new_entry
)
4251 entry
= bfd_alloc (entry
->abfd
, sizeof (*entry
));
4260 mips_elf_count_got_entry (arg
->info
, arg
->g
, entry
);
4265 /* Return the maximum number of GOT page entries required for RANGE. */
4268 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
4270 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
4273 /* Record that G requires a page entry that can reach SEC + ADDEND. */
4276 mips_elf_record_got_page_entry (struct mips_elf_traverse_got_arg
*arg
,
4277 asection
*sec
, bfd_signed_vma addend
)
4279 struct mips_got_info
*g
= arg
->g
;
4280 struct mips_got_page_entry lookup
, *entry
;
4281 struct mips_got_page_range
**range_ptr
, *range
;
4282 bfd_vma old_pages
, new_pages
;
4285 /* Find the mips_got_page_entry hash table entry for this section. */
4287 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
4291 /* Create a mips_got_page_entry if this is the first time we've
4292 seen the section. */
4293 entry
= (struct mips_got_page_entry
*) *loc
;
4296 entry
= bfd_zalloc (arg
->info
->output_bfd
, sizeof (*entry
));
4304 /* Skip over ranges whose maximum extent cannot share a page entry
4306 range_ptr
= &entry
->ranges
;
4307 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
4308 range_ptr
= &(*range_ptr
)->next
;
4310 /* If we scanned to the end of the list, or found a range whose
4311 minimum extent cannot share a page entry with ADDEND, create
4312 a new singleton range. */
4314 if (!range
|| addend
< range
->min_addend
- 0xffff)
4316 range
= bfd_zalloc (arg
->info
->output_bfd
, sizeof (*range
));
4320 range
->next
= *range_ptr
;
4321 range
->min_addend
= addend
;
4322 range
->max_addend
= addend
;
4330 /* Remember how many pages the old range contributed. */
4331 old_pages
= mips_elf_pages_for_range (range
);
4333 /* Update the ranges. */
4334 if (addend
< range
->min_addend
)
4335 range
->min_addend
= addend
;
4336 else if (addend
> range
->max_addend
)
4338 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
4340 old_pages
+= mips_elf_pages_for_range (range
->next
);
4341 range
->max_addend
= range
->next
->max_addend
;
4342 range
->next
= range
->next
->next
;
4345 range
->max_addend
= addend
;
4348 /* Record any change in the total estimate. */
4349 new_pages
= mips_elf_pages_for_range (range
);
4350 if (old_pages
!= new_pages
)
4352 entry
->num_pages
+= new_pages
- old_pages
;
4353 g
->page_gotno
+= new_pages
- old_pages
;
4359 /* A htab_traverse callback for which *REFP points to a mips_got_page_ref
4360 and for which DATA points to a mips_elf_traverse_got_arg. Work out
4361 whether the page reference described by *REFP needs a GOT page entry,
4362 and record that entry in DATA->g if so. Set DATA->g to null on failure. */
4365 mips_elf_resolve_got_page_ref (void **refp
, void *data
)
4367 struct mips_got_page_ref
*ref
;
4368 struct mips_elf_traverse_got_arg
*arg
;
4369 struct mips_elf_link_hash_table
*htab
;
4373 ref
= (struct mips_got_page_ref
*) *refp
;
4374 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4375 htab
= mips_elf_hash_table (arg
->info
);
4377 if (ref
->symndx
< 0)
4379 struct mips_elf_link_hash_entry
*h
;
4381 /* Global GOT_PAGEs decay to GOT_DISP and so don't need page entries. */
4383 if (!SYMBOL_REFERENCES_LOCAL (arg
->info
, &h
->root
))
4386 /* Ignore undefined symbols; we'll issue an error later if
4388 if (!((h
->root
.root
.type
== bfd_link_hash_defined
4389 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4390 && h
->root
.root
.u
.def
.section
))
4393 sec
= h
->root
.root
.u
.def
.section
;
4394 addend
= h
->root
.root
.u
.def
.value
+ ref
->addend
;
4398 Elf_Internal_Sym
*isym
;
4400 /* Read in the symbol. */
4401 isym
= bfd_sym_from_r_symndx (&htab
->root
.sym_cache
, ref
->u
.abfd
,
4409 /* Get the associated input section. */
4410 sec
= bfd_section_from_elf_index (ref
->u
.abfd
, isym
->st_shndx
);
4417 /* If this is a mergable section, work out the section and offset
4418 of the merged data. For section symbols, the addend specifies
4419 of the offset _of_ the first byte in the data, otherwise it
4420 specifies the offset _from_ the first byte. */
4421 if (sec
->flags
& SEC_MERGE
)
4425 secinfo
= elf_section_data (sec
)->sec_info
;
4426 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
4427 addend
= _bfd_merged_section_offset (ref
->u
.abfd
, &sec
, secinfo
,
4428 isym
->st_value
+ ref
->addend
);
4430 addend
= _bfd_merged_section_offset (ref
->u
.abfd
, &sec
, secinfo
,
4431 isym
->st_value
) + ref
->addend
;
4434 addend
= isym
->st_value
+ ref
->addend
;
4436 if (!mips_elf_record_got_page_entry (arg
, sec
, addend
))
4444 /* If any entries in G->got_entries are for indirect or warning symbols,
4445 replace them with entries for the target symbol. Convert g->got_page_refs
4446 into got_page_entry structures and estimate the number of page entries
4447 that they require. */
4450 mips_elf_resolve_final_got_entries (struct bfd_link_info
*info
,
4451 struct mips_got_info
*g
)
4453 struct mips_elf_traverse_got_arg tga
;
4454 struct mips_got_info oldg
;
4461 htab_traverse (g
->got_entries
, mips_elf_check_recreate_got
, &tga
);
4465 g
->got_entries
= htab_create (htab_size (oldg
.got_entries
),
4466 mips_elf_got_entry_hash
,
4467 mips_elf_got_entry_eq
, NULL
);
4468 if (!g
->got_entries
)
4471 htab_traverse (oldg
.got_entries
, mips_elf_recreate_got
, &tga
);
4475 htab_delete (oldg
.got_entries
);
4478 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4479 mips_got_page_entry_eq
, NULL
);
4480 if (g
->got_page_entries
== NULL
)
4485 htab_traverse (g
->got_page_refs
, mips_elf_resolve_got_page_ref
, &tga
);
4490 /* Return true if a GOT entry for H should live in the local rather than
4494 mips_use_local_got_p (struct bfd_link_info
*info
,
4495 struct mips_elf_link_hash_entry
*h
)
4497 /* Symbols that aren't in the dynamic symbol table must live in the
4498 local GOT. This includes symbols that are completely undefined
4499 and which therefore don't bind locally. We'll report undefined
4500 symbols later if appropriate. */
4501 if (h
->root
.dynindx
== -1)
4504 /* Absolute symbols, if ever they need a GOT entry, cannot ever go
4505 to the local GOT, as they would be implicitly relocated by the
4506 base address by the dynamic loader. */
4507 if (bfd_is_abs_symbol (&h
->root
.root
))
4510 /* Symbols that bind locally can (and in the case of forced-local
4511 symbols, must) live in the local GOT. */
4512 if (h
->got_only_for_calls
4513 ? SYMBOL_CALLS_LOCAL (info
, &h
->root
)
4514 : SYMBOL_REFERENCES_LOCAL (info
, &h
->root
))
4517 /* If this is an executable that must provide a definition of the symbol,
4518 either though PLTs or copy relocations, then that address should go in
4519 the local rather than global GOT. */
4520 if (bfd_link_executable (info
) && h
->has_static_relocs
)
4526 /* A mips_elf_link_hash_traverse callback for which DATA points to the
4527 link_info structure. Decide whether the hash entry needs an entry in
4528 the global part of the primary GOT, setting global_got_area accordingly.
4529 Count the number of global symbols that are in the primary GOT only
4530 because they have relocations against them (reloc_only_gotno). */
4533 mips_elf_count_got_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
4535 struct bfd_link_info
*info
;
4536 struct mips_elf_link_hash_table
*htab
;
4537 struct mips_got_info
*g
;
4539 info
= (struct bfd_link_info
*) data
;
4540 htab
= mips_elf_hash_table (info
);
4542 if (h
->global_got_area
!= GGA_NONE
)
4544 /* Make a final decision about whether the symbol belongs in the
4545 local or global GOT. */
4546 if (mips_use_local_got_p (info
, h
))
4547 /* The symbol belongs in the local GOT. We no longer need this
4548 entry if it was only used for relocations; those relocations
4549 will be against the null or section symbol instead of H. */
4550 h
->global_got_area
= GGA_NONE
;
4551 else if (htab
->root
.target_os
== is_vxworks
4552 && h
->got_only_for_calls
4553 && h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
)
4554 /* On VxWorks, calls can refer directly to the .got.plt entry;
4555 they don't need entries in the regular GOT. .got.plt entries
4556 will be allocated by _bfd_mips_elf_adjust_dynamic_symbol. */
4557 h
->global_got_area
= GGA_NONE
;
4558 else if (h
->global_got_area
== GGA_RELOC_ONLY
)
4560 g
->reloc_only_gotno
++;
4567 /* A htab_traverse callback for GOT entries. Add each one to the GOT
4568 given in mips_elf_traverse_got_arg DATA. Clear DATA->G on error. */
4571 mips_elf_add_got_entry (void **entryp
, void *data
)
4573 struct mips_got_entry
*entry
;
4574 struct mips_elf_traverse_got_arg
*arg
;
4577 entry
= (struct mips_got_entry
*) *entryp
;
4578 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4579 slot
= htab_find_slot (arg
->g
->got_entries
, entry
, INSERT
);
4588 mips_elf_count_got_entry (arg
->info
, arg
->g
, entry
);
4593 /* A htab_traverse callback for GOT page entries. Add each one to the GOT
4594 given in mips_elf_traverse_got_arg DATA. Clear DATA->G on error. */
4597 mips_elf_add_got_page_entry (void **entryp
, void *data
)
4599 struct mips_got_page_entry
*entry
;
4600 struct mips_elf_traverse_got_arg
*arg
;
4603 entry
= (struct mips_got_page_entry
*) *entryp
;
4604 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4605 slot
= htab_find_slot (arg
->g
->got_page_entries
, entry
, INSERT
);
4614 arg
->g
->page_gotno
+= entry
->num_pages
;
4619 /* Consider merging FROM, which is ABFD's GOT, into TO. Return -1 if
4620 this would lead to overflow, 1 if they were merged successfully,
4621 and 0 if a merge failed due to lack of memory. (These values are chosen
4622 so that nonnegative return values can be returned by a htab_traverse
4626 mips_elf_merge_got_with (bfd
*abfd
, struct mips_got_info
*from
,
4627 struct mips_got_info
*to
,
4628 struct mips_elf_got_per_bfd_arg
*arg
)
4630 struct mips_elf_traverse_got_arg tga
;
4631 unsigned int estimate
;
4633 /* Work out how many page entries we would need for the combined GOT. */
4634 estimate
= arg
->max_pages
;
4635 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
4636 estimate
= from
->page_gotno
+ to
->page_gotno
;
4638 /* And conservatively estimate how many local and TLS entries
4640 estimate
+= from
->local_gotno
+ to
->local_gotno
;
4641 estimate
+= from
->tls_gotno
+ to
->tls_gotno
;
4643 /* If we're merging with the primary got, any TLS relocations will
4644 come after the full set of global entries. Otherwise estimate those
4645 conservatively as well. */
4646 if (to
== arg
->primary
&& from
->tls_gotno
+ to
->tls_gotno
)
4647 estimate
+= arg
->global_count
;
4649 estimate
+= from
->global_gotno
+ to
->global_gotno
;
4651 /* Bail out if the combined GOT might be too big. */
4652 if (estimate
> arg
->max_count
)
4655 /* Transfer the bfd's got information from FROM to TO. */
4656 tga
.info
= arg
->info
;
4658 htab_traverse (from
->got_entries
, mips_elf_add_got_entry
, &tga
);
4662 htab_traverse (from
->got_page_entries
, mips_elf_add_got_page_entry
, &tga
);
4666 mips_elf_replace_bfd_got (abfd
, to
);
4670 /* Attempt to merge GOT G, which belongs to ABFD. Try to use as much
4671 as possible of the primary got, since it doesn't require explicit
4672 dynamic relocations, but don't use bfds that would reference global
4673 symbols out of the addressable range. Failing the primary got,
4674 attempt to merge with the current got, or finish the current got
4675 and then make make the new got current. */
4678 mips_elf_merge_got (bfd
*abfd
, struct mips_got_info
*g
,
4679 struct mips_elf_got_per_bfd_arg
*arg
)
4681 unsigned int estimate
;
4684 if (!mips_elf_resolve_final_got_entries (arg
->info
, g
))
4687 /* Work out the number of page, local and TLS entries. */
4688 estimate
= arg
->max_pages
;
4689 if (estimate
> g
->page_gotno
)
4690 estimate
= g
->page_gotno
;
4691 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
4693 /* We place TLS GOT entries after both locals and globals. The globals
4694 for the primary GOT may overflow the normal GOT size limit, so be
4695 sure not to merge a GOT which requires TLS with the primary GOT in that
4696 case. This doesn't affect non-primary GOTs. */
4697 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
4699 if (estimate
<= arg
->max_count
)
4701 /* If we don't have a primary GOT, use it as
4702 a starting point for the primary GOT. */
4709 /* Try merging with the primary GOT. */
4710 result
= mips_elf_merge_got_with (abfd
, g
, arg
->primary
, arg
);
4715 /* If we can merge with the last-created got, do it. */
4718 result
= mips_elf_merge_got_with (abfd
, g
, arg
->current
, arg
);
4723 /* Well, we couldn't merge, so create a new GOT. Don't check if it
4724 fits; if it turns out that it doesn't, we'll get relocation
4725 overflows anyway. */
4726 g
->next
= arg
->current
;
4732 /* ENTRYP is a hash table entry for a mips_got_entry. Set its gotidx
4733 to GOTIDX, duplicating the entry if it has already been assigned
4734 an index in a different GOT. */
4737 mips_elf_set_gotidx (void **entryp
, long gotidx
)
4739 struct mips_got_entry
*entry
;
4741 entry
= (struct mips_got_entry
*) *entryp
;
4742 if (entry
->gotidx
> 0)
4744 struct mips_got_entry
*new_entry
;
4746 new_entry
= bfd_alloc (entry
->abfd
, sizeof (*entry
));
4750 *new_entry
= *entry
;
4751 *entryp
= new_entry
;
4754 entry
->gotidx
= gotidx
;
4758 /* Set the TLS GOT index for the GOT entry in ENTRYP. DATA points to a
4759 mips_elf_traverse_got_arg in which DATA->value is the size of one
4760 GOT entry. Set DATA->g to null on failure. */
4763 mips_elf_initialize_tls_index (void **entryp
, void *data
)
4765 struct mips_got_entry
*entry
;
4766 struct mips_elf_traverse_got_arg
*arg
;
4768 /* We're only interested in TLS symbols. */
4769 entry
= (struct mips_got_entry
*) *entryp
;
4770 if (entry
->tls_type
== GOT_TLS_NONE
)
4773 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4774 if (!mips_elf_set_gotidx (entryp
, arg
->value
* arg
->g
->tls_assigned_gotno
))
4780 /* Account for the entries we've just allocated. */
4781 arg
->g
->tls_assigned_gotno
+= mips_tls_got_entries (entry
->tls_type
);
4785 /* A htab_traverse callback for GOT entries, where DATA points to a
4786 mips_elf_traverse_got_arg. Set the global_got_area of each global
4787 symbol to DATA->value. */
4790 mips_elf_set_global_got_area (void **entryp
, void *data
)
4792 struct mips_got_entry
*entry
;
4793 struct mips_elf_traverse_got_arg
*arg
;
4795 entry
= (struct mips_got_entry
*) *entryp
;
4796 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4797 if (entry
->abfd
!= NULL
4798 && entry
->symndx
== -1
4799 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
4800 entry
->d
.h
->global_got_area
= arg
->value
;
4804 /* A htab_traverse callback for secondary GOT entries, where DATA points
4805 to a mips_elf_traverse_got_arg. Assign GOT indices to global entries
4806 and record the number of relocations they require. DATA->value is
4807 the size of one GOT entry. Set DATA->g to null on failure. */
4810 mips_elf_set_global_gotidx (void **entryp
, void *data
)
4812 struct mips_got_entry
*entry
;
4813 struct mips_elf_traverse_got_arg
*arg
;
4815 entry
= (struct mips_got_entry
*) *entryp
;
4816 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4817 if (entry
->abfd
!= NULL
4818 && entry
->symndx
== -1
4819 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
4821 if (!mips_elf_set_gotidx (entryp
, arg
->value
* arg
->g
->assigned_low_gotno
))
4826 arg
->g
->assigned_low_gotno
+= 1;
4828 if (bfd_link_pic (arg
->info
)
4829 || (elf_hash_table (arg
->info
)->dynamic_sections_created
4830 && entry
->d
.h
->root
.def_dynamic
4831 && !entry
->d
.h
->root
.def_regular
))
4832 arg
->g
->relocs
+= 1;
4838 /* A htab_traverse callback for GOT entries for which DATA is the
4839 bfd_link_info. Forbid any global symbols from having traditional
4840 lazy-binding stubs. */
4843 mips_elf_forbid_lazy_stubs (void **entryp
, void *data
)
4845 struct bfd_link_info
*info
;
4846 struct mips_elf_link_hash_table
*htab
;
4847 struct mips_got_entry
*entry
;
4849 entry
= (struct mips_got_entry
*) *entryp
;
4850 info
= (struct bfd_link_info
*) data
;
4851 htab
= mips_elf_hash_table (info
);
4852 BFD_ASSERT (htab
!= NULL
);
4854 if (entry
->abfd
!= NULL
4855 && entry
->symndx
== -1
4856 && entry
->d
.h
->needs_lazy_stub
)
4858 entry
->d
.h
->needs_lazy_stub
= FALSE
;
4859 htab
->lazy_stub_count
--;
4865 /* Return the offset of an input bfd IBFD's GOT from the beginning of
4868 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
4873 g
= mips_elf_bfd_got (ibfd
, FALSE
);
4877 BFD_ASSERT (g
->next
);
4881 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
4882 * MIPS_ELF_GOT_SIZE (abfd
);
4885 /* Turn a single GOT that is too big for 16-bit addressing into
4886 a sequence of GOTs, each one 16-bit addressable. */
4889 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
4890 asection
*got
, bfd_size_type pages
)
4892 struct mips_elf_link_hash_table
*htab
;
4893 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
4894 struct mips_elf_traverse_got_arg tga
;
4895 struct mips_got_info
*g
, *gg
;
4896 unsigned int assign
, needed_relocs
;
4899 dynobj
= elf_hash_table (info
)->dynobj
;
4900 htab
= mips_elf_hash_table (info
);
4901 BFD_ASSERT (htab
!= NULL
);
4905 got_per_bfd_arg
.obfd
= abfd
;
4906 got_per_bfd_arg
.info
= info
;
4907 got_per_bfd_arg
.current
= NULL
;
4908 got_per_bfd_arg
.primary
= NULL
;
4909 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
4910 / MIPS_ELF_GOT_SIZE (abfd
))
4911 - htab
->reserved_gotno
);
4912 got_per_bfd_arg
.max_pages
= pages
;
4913 /* The number of globals that will be included in the primary GOT.
4914 See the calls to mips_elf_set_global_got_area below for more
4916 got_per_bfd_arg
.global_count
= g
->global_gotno
;
4918 /* Try to merge the GOTs of input bfds together, as long as they
4919 don't seem to exceed the maximum GOT size, choosing one of them
4920 to be the primary GOT. */
4921 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link
.next
)
4923 gg
= mips_elf_bfd_got (ibfd
, FALSE
);
4924 if (gg
&& !mips_elf_merge_got (ibfd
, gg
, &got_per_bfd_arg
))
4928 /* If we do not find any suitable primary GOT, create an empty one. */
4929 if (got_per_bfd_arg
.primary
== NULL
)
4930 g
->next
= mips_elf_create_got_info (abfd
);
4932 g
->next
= got_per_bfd_arg
.primary
;
4933 g
->next
->next
= got_per_bfd_arg
.current
;
4935 /* GG is now the master GOT, and G is the primary GOT. */
4939 /* Map the output bfd to the primary got. That's what we're going
4940 to use for bfds that use GOT16 or GOT_PAGE relocations that we
4941 didn't mark in check_relocs, and we want a quick way to find it.
4942 We can't just use gg->next because we're going to reverse the
4944 mips_elf_replace_bfd_got (abfd
, g
);
4946 /* Every symbol that is referenced in a dynamic relocation must be
4947 present in the primary GOT, so arrange for them to appear after
4948 those that are actually referenced. */
4949 gg
->reloc_only_gotno
= gg
->global_gotno
- g
->global_gotno
;
4950 g
->global_gotno
= gg
->global_gotno
;
4953 tga
.value
= GGA_RELOC_ONLY
;
4954 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_area
, &tga
);
4955 tga
.value
= GGA_NORMAL
;
4956 htab_traverse (g
->got_entries
, mips_elf_set_global_got_area
, &tga
);
4958 /* Now go through the GOTs assigning them offset ranges.
4959 [assigned_low_gotno, local_gotno[ will be set to the range of local
4960 entries in each GOT. We can then compute the end of a GOT by
4961 adding local_gotno to global_gotno. We reverse the list and make
4962 it circular since then we'll be able to quickly compute the
4963 beginning of a GOT, by computing the end of its predecessor. To
4964 avoid special cases for the primary GOT, while still preserving
4965 assertions that are valid for both single- and multi-got links,
4966 we arrange for the main got struct to have the right number of
4967 global entries, but set its local_gotno such that the initial
4968 offset of the primary GOT is zero. Remember that the primary GOT
4969 will become the last item in the circular linked list, so it
4970 points back to the master GOT. */
4971 gg
->local_gotno
= -g
->global_gotno
;
4972 gg
->global_gotno
= g
->global_gotno
;
4979 struct mips_got_info
*gn
;
4981 assign
+= htab
->reserved_gotno
;
4982 g
->assigned_low_gotno
= assign
;
4983 g
->local_gotno
+= assign
;
4984 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
4985 g
->assigned_high_gotno
= g
->local_gotno
- 1;
4986 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
4988 /* Take g out of the direct list, and push it onto the reversed
4989 list that gg points to. g->next is guaranteed to be nonnull after
4990 this operation, as required by mips_elf_initialize_tls_index. */
4995 /* Set up any TLS entries. We always place the TLS entries after
4996 all non-TLS entries. */
4997 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
4999 tga
.value
= MIPS_ELF_GOT_SIZE (abfd
);
5000 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, &tga
);
5003 BFD_ASSERT (g
->tls_assigned_gotno
== assign
);
5005 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
5008 /* Forbid global symbols in every non-primary GOT from having
5009 lazy-binding stubs. */
5011 htab_traverse (g
->got_entries
, mips_elf_forbid_lazy_stubs
, info
);
5015 got
->size
= assign
* MIPS_ELF_GOT_SIZE (abfd
);
5018 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
5020 unsigned int save_assign
;
5022 /* Assign offsets to global GOT entries and count how many
5023 relocations they need. */
5024 save_assign
= g
->assigned_low_gotno
;
5025 g
->assigned_low_gotno
= g
->local_gotno
;
5027 tga
.value
= MIPS_ELF_GOT_SIZE (abfd
);
5029 htab_traverse (g
->got_entries
, mips_elf_set_global_gotidx
, &tga
);
5032 BFD_ASSERT (g
->assigned_low_gotno
== g
->local_gotno
+ g
->global_gotno
);
5033 g
->assigned_low_gotno
= save_assign
;
5035 if (bfd_link_pic (info
))
5037 g
->relocs
+= g
->local_gotno
- g
->assigned_low_gotno
;
5038 BFD_ASSERT (g
->assigned_low_gotno
== g
->next
->local_gotno
5039 + g
->next
->global_gotno
5040 + g
->next
->tls_gotno
5041 + htab
->reserved_gotno
);
5043 needed_relocs
+= g
->relocs
;
5045 needed_relocs
+= g
->relocs
;
5048 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
5055 /* Returns the first relocation of type r_type found, beginning with
5056 RELOCATION. RELEND is one-past-the-end of the relocation table. */
5058 static const Elf_Internal_Rela
*
5059 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
5060 const Elf_Internal_Rela
*relocation
,
5061 const Elf_Internal_Rela
*relend
)
5063 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
5065 while (relocation
< relend
)
5067 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
5068 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
5074 /* We didn't find it. */
5078 /* Return whether an input relocation is against a local symbol. */
5081 mips_elf_local_relocation_p (bfd
*input_bfd
,
5082 const Elf_Internal_Rela
*relocation
,
5083 asection
**local_sections
)
5085 unsigned long r_symndx
;
5086 Elf_Internal_Shdr
*symtab_hdr
;
5089 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
5090 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5091 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
5093 if (r_symndx
< extsymoff
)
5095 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
5101 /* Sign-extend VALUE, which has the indicated number of BITS. */
5104 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
5106 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
5107 /* VALUE is negative. */
5108 value
|= ((bfd_vma
) - 1) << bits
;
5113 /* Return non-zero if the indicated VALUE has overflowed the maximum
5114 range expressible by a signed number with the indicated number of
5118 mips_elf_overflow_p (bfd_vma value
, int bits
)
5120 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
5122 if (svalue
> (1 << (bits
- 1)) - 1)
5123 /* The value is too big. */
5125 else if (svalue
< -(1 << (bits
- 1)))
5126 /* The value is too small. */
5133 /* Calculate the %high function. */
5136 mips_elf_high (bfd_vma value
)
5138 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
5141 /* Calculate the %higher function. */
5144 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
5147 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
5154 /* Calculate the %highest function. */
5157 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
5160 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
5167 /* Create the .compact_rel section. */
5170 mips_elf_create_compact_rel_section
5171 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5174 register asection
*s
;
5176 if (bfd_get_linker_section (abfd
, ".compact_rel") == NULL
)
5178 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
5181 s
= bfd_make_section_anyway_with_flags (abfd
, ".compact_rel", flags
);
5183 || !bfd_set_section_alignment (s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
5186 s
->size
= sizeof (Elf32_External_compact_rel
);
5192 /* Create the .got section to hold the global offset table. */
5195 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
5198 register asection
*s
;
5199 struct elf_link_hash_entry
*h
;
5200 struct bfd_link_hash_entry
*bh
;
5201 struct mips_elf_link_hash_table
*htab
;
5203 htab
= mips_elf_hash_table (info
);
5204 BFD_ASSERT (htab
!= NULL
);
5206 /* This function may be called more than once. */
5207 if (htab
->root
.sgot
)
5210 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5211 | SEC_LINKER_CREATED
);
5213 /* We have to use an alignment of 2**4 here because this is hardcoded
5214 in the function stub generation and in the linker script. */
5215 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
5217 || !bfd_set_section_alignment (s
, 4))
5219 htab
->root
.sgot
= s
;
5221 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5222 linker script because we don't want to define the symbol if we
5223 are not creating a global offset table. */
5225 if (! (_bfd_generic_link_add_one_symbol
5226 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5227 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
5230 h
= (struct elf_link_hash_entry
*) bh
;
5233 h
->type
= STT_OBJECT
;
5234 h
->other
= (h
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
5235 elf_hash_table (info
)->hgot
= h
;
5237 if (bfd_link_pic (info
)
5238 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
5241 htab
->got_info
= mips_elf_create_got_info (abfd
);
5242 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
5243 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5245 /* We also need a .got.plt section when generating PLTs. */
5246 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt",
5247 SEC_ALLOC
| SEC_LOAD
5250 | SEC_LINKER_CREATED
);
5253 htab
->root
.sgotplt
= s
;
5258 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
5259 __GOTT_INDEX__ symbols. These symbols are only special for
5260 shared objects; they are not used in executables. */
5263 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
5265 return (mips_elf_hash_table (info
)->root
.target_os
== is_vxworks
5266 && bfd_link_pic (info
)
5267 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
5268 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
5271 /* Return TRUE if a relocation of type R_TYPE from INPUT_BFD might
5272 require an la25 stub. See also mips_elf_local_pic_function_p,
5273 which determines whether the destination function ever requires a
5277 mips_elf_relocation_needs_la25_stub (bfd
*input_bfd
, int r_type
,
5278 bfd_boolean target_is_16_bit_code_p
)
5280 /* We specifically ignore branches and jumps from EF_PIC objects,
5281 where the onus is on the compiler or programmer to perform any
5282 necessary initialization of $25. Sometimes such initialization
5283 is unnecessary; for example, -mno-shared functions do not use
5284 the incoming value of $25, and may therefore be called directly. */
5285 if (PIC_OBJECT_P (input_bfd
))
5292 case R_MIPS_PC21_S2
:
5293 case R_MIPS_PC26_S2
:
5294 case R_MICROMIPS_26_S1
:
5295 case R_MICROMIPS_PC7_S1
:
5296 case R_MICROMIPS_PC10_S1
:
5297 case R_MICROMIPS_PC16_S1
:
5298 case R_MICROMIPS_PC23_S2
:
5302 return !target_is_16_bit_code_p
;
5309 /* Obtain the field relocated by RELOCATION. */
5312 mips_elf_obtain_contents (reloc_howto_type
*howto
,
5313 const Elf_Internal_Rela
*relocation
,
5314 bfd
*input_bfd
, bfd_byte
*contents
)
5317 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5318 unsigned int size
= bfd_get_reloc_size (howto
);
5320 /* Obtain the bytes. */
5322 x
= bfd_get (8 * size
, input_bfd
, location
);
5327 /* Store the field relocated by RELOCATION. */
5330 mips_elf_store_contents (reloc_howto_type
*howto
,
5331 const Elf_Internal_Rela
*relocation
,
5332 bfd
*input_bfd
, bfd_byte
*contents
, bfd_vma x
)
5334 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5335 unsigned int size
= bfd_get_reloc_size (howto
);
5337 /* Put the value into the output. */
5339 bfd_put (8 * size
, input_bfd
, x
, location
);
5342 /* Try to patch a load from GOT instruction in CONTENTS pointed to by
5343 RELOCATION described by HOWTO, with a move of 0 to the load target
5344 register, returning TRUE if that is successful and FALSE otherwise.
5345 If DOIT is FALSE, then only determine it patching is possible and
5346 return status without actually changing CONTENTS.
5350 mips_elf_nullify_got_load (bfd
*input_bfd
, bfd_byte
*contents
,
5351 const Elf_Internal_Rela
*relocation
,
5352 reloc_howto_type
*howto
, bfd_boolean doit
)
5354 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5355 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5356 bfd_boolean nullified
= TRUE
;
5359 _bfd_mips_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
5361 /* Obtain the current value. */
5362 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
5364 /* Note that in the unshuffled MIPS16 encoding RX is at bits [21:19]
5365 while RY is at bits [18:16] of the combined 32-bit instruction word. */
5366 if (mips16_reloc_p (r_type
)
5367 && (((x
>> 22) & 0x3ff) == 0x3d3 /* LW */
5368 || ((x
>> 22) & 0x3ff) == 0x3c7)) /* LD */
5369 x
= (0x3cd << 22) | (x
& (7 << 16)) << 3; /* LI */
5370 else if (micromips_reloc_p (r_type
)
5371 && ((x
>> 26) & 0x37) == 0x37) /* LW/LD */
5372 x
= (0xc << 26) | (x
& (0x1f << 21)); /* ADDIU */
5373 else if (((x
>> 26) & 0x3f) == 0x23 /* LW */
5374 || ((x
>> 26) & 0x3f) == 0x37) /* LD */
5375 x
= (0x9 << 26) | (x
& (0x1f << 16)); /* ADDIU */
5379 /* Put the value into the output. */
5380 if (doit
&& nullified
)
5381 mips_elf_store_contents (howto
, relocation
, input_bfd
, contents
, x
);
5383 _bfd_mips_elf_reloc_shuffle (input_bfd
, r_type
, FALSE
, location
);
5388 /* Calculate the value produced by the RELOCATION (which comes from
5389 the INPUT_BFD). The ADDEND is the addend to use for this
5390 RELOCATION; RELOCATION->R_ADDEND is ignored.
5392 The result of the relocation calculation is stored in VALUEP.
5393 On exit, set *CROSS_MODE_JUMP_P to true if the relocation field
5394 is a MIPS16 or microMIPS jump to standard MIPS code, or vice versa.
5396 This function returns bfd_reloc_continue if the caller need take no
5397 further action regarding this relocation, bfd_reloc_notsupported if
5398 something goes dramatically wrong, bfd_reloc_overflow if an
5399 overflow occurs, and bfd_reloc_ok to indicate success. */
5401 static bfd_reloc_status_type
5402 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
5403 asection
*input_section
, bfd_byte
*contents
,
5404 struct bfd_link_info
*info
,
5405 const Elf_Internal_Rela
*relocation
,
5406 bfd_vma addend
, reloc_howto_type
*howto
,
5407 Elf_Internal_Sym
*local_syms
,
5408 asection
**local_sections
, bfd_vma
*valuep
,
5410 bfd_boolean
*cross_mode_jump_p
,
5411 bfd_boolean save_addend
)
5413 /* The eventual value we will return. */
5415 /* The address of the symbol against which the relocation is
5418 /* The final GP value to be used for the relocatable, executable, or
5419 shared object file being produced. */
5421 /* The place (section offset or address) of the storage unit being
5424 /* The value of GP used to create the relocatable object. */
5426 /* The offset into the global offset table at which the address of
5427 the relocation entry symbol, adjusted by the addend, resides
5428 during execution. */
5429 bfd_vma g
= MINUS_ONE
;
5430 /* The section in which the symbol referenced by the relocation is
5432 asection
*sec
= NULL
;
5433 struct mips_elf_link_hash_entry
*h
= NULL
;
5434 /* TRUE if the symbol referred to by this relocation is a local
5436 bfd_boolean local_p
, was_local_p
;
5437 /* TRUE if the symbol referred to by this relocation is a section
5439 bfd_boolean section_p
= FALSE
;
5440 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
5441 bfd_boolean gp_disp_p
= FALSE
;
5442 /* TRUE if the symbol referred to by this relocation is
5443 "__gnu_local_gp". */
5444 bfd_boolean gnu_local_gp_p
= FALSE
;
5445 Elf_Internal_Shdr
*symtab_hdr
;
5447 unsigned long r_symndx
;
5449 /* TRUE if overflow occurred during the calculation of the
5450 relocation value. */
5451 bfd_boolean overflowed_p
;
5452 /* TRUE if this relocation refers to a MIPS16 function. */
5453 bfd_boolean target_is_16_bit_code_p
= FALSE
;
5454 bfd_boolean target_is_micromips_code_p
= FALSE
;
5455 struct mips_elf_link_hash_table
*htab
;
5457 bfd_boolean resolved_to_zero
;
5459 dynobj
= elf_hash_table (info
)->dynobj
;
5460 htab
= mips_elf_hash_table (info
);
5461 BFD_ASSERT (htab
!= NULL
);
5463 /* Parse the relocation. */
5464 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
5465 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5466 p
= (input_section
->output_section
->vma
5467 + input_section
->output_offset
5468 + relocation
->r_offset
);
5470 /* Assume that there will be no overflow. */
5471 overflowed_p
= FALSE
;
5473 /* Figure out whether or not the symbol is local, and get the offset
5474 used in the array of hash table entries. */
5475 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5476 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
5478 was_local_p
= local_p
;
5479 if (! elf_bad_symtab (input_bfd
))
5480 extsymoff
= symtab_hdr
->sh_info
;
5483 /* The symbol table does not follow the rule that local symbols
5484 must come before globals. */
5488 /* Figure out the value of the symbol. */
5491 bfd_boolean micromips_p
= MICROMIPS_P (abfd
);
5492 Elf_Internal_Sym
*sym
;
5494 sym
= local_syms
+ r_symndx
;
5495 sec
= local_sections
[r_symndx
];
5497 section_p
= ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
;
5499 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5500 if (!section_p
|| (sec
->flags
& SEC_MERGE
))
5501 symbol
+= sym
->st_value
;
5502 if ((sec
->flags
& SEC_MERGE
) && section_p
)
5504 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
5506 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
5509 /* MIPS16/microMIPS text labels should be treated as odd. */
5510 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
5513 /* Record the name of this symbol, for our caller. */
5514 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
5515 symtab_hdr
->sh_link
,
5517 if (*namep
== NULL
|| **namep
== '\0')
5518 *namep
= bfd_section_name (sec
);
5520 /* For relocations against a section symbol and ones against no
5521 symbol (absolute relocations) infer the ISA mode from the addend. */
5522 if (section_p
|| r_symndx
== STN_UNDEF
)
5524 target_is_16_bit_code_p
= (addend
& 1) && !micromips_p
;
5525 target_is_micromips_code_p
= (addend
& 1) && micromips_p
;
5527 /* For relocations against an absolute symbol infer the ISA mode
5528 from the value of the symbol plus addend. */
5529 else if (bfd_is_abs_section (sec
))
5531 target_is_16_bit_code_p
= ((symbol
+ addend
) & 1) && !micromips_p
;
5532 target_is_micromips_code_p
= ((symbol
+ addend
) & 1) && micromips_p
;
5534 /* Otherwise just use the regular symbol annotation available. */
5537 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
5538 target_is_micromips_code_p
= ELF_ST_IS_MICROMIPS (sym
->st_other
);
5543 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
5545 /* For global symbols we look up the symbol in the hash-table. */
5546 h
= ((struct mips_elf_link_hash_entry
*)
5547 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
5548 /* Find the real hash-table entry for this symbol. */
5549 while (h
->root
.root
.type
== bfd_link_hash_indirect
5550 || h
->root
.root
.type
== bfd_link_hash_warning
)
5551 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5553 /* Record the name of this symbol, for our caller. */
5554 *namep
= h
->root
.root
.root
.string
;
5556 /* See if this is the special _gp_disp symbol. Note that such a
5557 symbol must always be a global symbol. */
5558 if (strcmp (*namep
, "_gp_disp") == 0
5559 && ! NEWABI_P (input_bfd
))
5561 /* Relocations against _gp_disp are permitted only with
5562 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
5563 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
5564 return bfd_reloc_notsupported
;
5568 /* See if this is the special _gp symbol. Note that such a
5569 symbol must always be a global symbol. */
5570 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
5571 gnu_local_gp_p
= TRUE
;
5574 /* If this symbol is defined, calculate its address. Note that
5575 _gp_disp is a magic symbol, always implicitly defined by the
5576 linker, so it's inappropriate to check to see whether or not
5578 else if ((h
->root
.root
.type
== bfd_link_hash_defined
5579 || h
->root
.root
.type
== bfd_link_hash_defweak
)
5580 && h
->root
.root
.u
.def
.section
)
5582 sec
= h
->root
.root
.u
.def
.section
;
5583 if (sec
->output_section
)
5584 symbol
= (h
->root
.root
.u
.def
.value
5585 + sec
->output_section
->vma
5586 + sec
->output_offset
);
5588 symbol
= h
->root
.root
.u
.def
.value
;
5590 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
5591 /* We allow relocations against undefined weak symbols, giving
5592 it the value zero, so that you can undefined weak functions
5593 and check to see if they exist by looking at their
5596 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
5597 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5599 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
5600 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
5602 /* If this is a dynamic link, we should have created a
5603 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
5604 in _bfd_mips_elf_create_dynamic_sections.
5605 Otherwise, we should define the symbol with a value of 0.
5606 FIXME: It should probably get into the symbol table
5608 BFD_ASSERT (! bfd_link_pic (info
));
5609 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
5612 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
5614 /* This is an optional symbol - an Irix specific extension to the
5615 ELF spec. Ignore it for now.
5616 XXX - FIXME - there is more to the spec for OPTIONAL symbols
5617 than simply ignoring them, but we do not handle this for now.
5618 For information see the "64-bit ELF Object File Specification"
5619 which is available from here:
5620 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
5625 bfd_boolean reject_undefined
5626 = (info
->unresolved_syms_in_objects
== RM_DIAGNOSE
5627 && !info
->warn_unresolved_syms
)
5628 || ELF_ST_VISIBILITY (h
->root
.other
) != STV_DEFAULT
;
5630 info
->callbacks
->undefined_symbol
5631 (info
, h
->root
.root
.root
.string
, input_bfd
,
5632 input_section
, relocation
->r_offset
, reject_undefined
);
5634 if (reject_undefined
)
5635 return bfd_reloc_undefined
;
5640 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
5641 target_is_micromips_code_p
= ELF_ST_IS_MICROMIPS (h
->root
.other
);
5644 /* If this is a reference to a 16-bit function with a stub, we need
5645 to redirect the relocation to the stub unless:
5647 (a) the relocation is for a MIPS16 JAL;
5649 (b) the relocation is for a MIPS16 PIC call, and there are no
5650 non-MIPS16 uses of the GOT slot; or
5652 (c) the section allows direct references to MIPS16 functions. */
5653 if (r_type
!= R_MIPS16_26
5654 && !bfd_link_relocatable (info
)
5656 && h
->fn_stub
!= NULL
5657 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
5659 && mips_elf_tdata (input_bfd
)->local_stubs
!= NULL
5660 && mips_elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5661 && !section_allows_mips16_refs_p (input_section
))
5663 /* This is a 32- or 64-bit call to a 16-bit function. We should
5664 have already noticed that we were going to need the
5668 sec
= mips_elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5673 BFD_ASSERT (h
->need_fn_stub
);
5676 /* If a LA25 header for the stub itself exists, point to the
5677 prepended LUI/ADDIU sequence. */
5678 sec
= h
->la25_stub
->stub_section
;
5679 value
= h
->la25_stub
->offset
;
5688 symbol
= sec
->output_section
->vma
+ sec
->output_offset
+ value
;
5689 /* The target is 16-bit, but the stub isn't. */
5690 target_is_16_bit_code_p
= FALSE
;
5692 /* If this is a MIPS16 call with a stub, that is made through the PLT or
5693 to a standard MIPS function, we need to redirect the call to the stub.
5694 Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
5695 indirect calls should use an indirect stub instead. */
5696 else if (r_type
== R_MIPS16_26
&& !bfd_link_relocatable (info
)
5697 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
5699 && mips_elf_tdata (input_bfd
)->local_call_stubs
!= NULL
5700 && mips_elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
5701 && ((h
!= NULL
&& h
->use_plt_entry
) || !target_is_16_bit_code_p
))
5704 sec
= mips_elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
5707 /* If both call_stub and call_fp_stub are defined, we can figure
5708 out which one to use by checking which one appears in the input
5710 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
5715 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5717 if (CALL_FP_STUB_P (bfd_section_name (o
)))
5719 sec
= h
->call_fp_stub
;
5726 else if (h
->call_stub
!= NULL
)
5729 sec
= h
->call_fp_stub
;
5732 BFD_ASSERT (sec
->size
> 0);
5733 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5735 /* If this is a direct call to a PIC function, redirect to the
5737 else if (h
!= NULL
&& h
->la25_stub
5738 && mips_elf_relocation_needs_la25_stub (input_bfd
, r_type
,
5739 target_is_16_bit_code_p
))
5741 symbol
= (h
->la25_stub
->stub_section
->output_section
->vma
5742 + h
->la25_stub
->stub_section
->output_offset
5743 + h
->la25_stub
->offset
);
5744 if (ELF_ST_IS_MICROMIPS (h
->root
.other
))
5747 /* For direct MIPS16 and microMIPS calls make sure the compressed PLT
5748 entry is used if a standard PLT entry has also been made. In this
5749 case the symbol will have been set by mips_elf_set_plt_sym_value
5750 to point to the standard PLT entry, so redirect to the compressed
5752 else if ((mips16_branch_reloc_p (r_type
)
5753 || micromips_branch_reloc_p (r_type
))
5754 && !bfd_link_relocatable (info
)
5757 && h
->root
.plt
.plist
->comp_offset
!= MINUS_ONE
5758 && h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
)
5760 bfd_boolean micromips_p
= MICROMIPS_P (abfd
);
5762 sec
= htab
->root
.splt
;
5763 symbol
= (sec
->output_section
->vma
5764 + sec
->output_offset
5765 + htab
->plt_header_size
5766 + htab
->plt_mips_offset
5767 + h
->root
.plt
.plist
->comp_offset
5770 target_is_16_bit_code_p
= !micromips_p
;
5771 target_is_micromips_code_p
= micromips_p
;
5774 /* Make sure MIPS16 and microMIPS are not used together. */
5775 if ((mips16_branch_reloc_p (r_type
) && target_is_micromips_code_p
)
5776 || (micromips_branch_reloc_p (r_type
) && target_is_16_bit_code_p
))
5779 (_("MIPS16 and microMIPS functions cannot call each other"));
5780 return bfd_reloc_notsupported
;
5783 /* Calls from 16-bit code to 32-bit code and vice versa require the
5784 mode change. However, we can ignore calls to undefined weak symbols,
5785 which should never be executed at runtime. This exception is important
5786 because the assembly writer may have "known" that any definition of the
5787 symbol would be 16-bit code, and that direct jumps were therefore
5789 *cross_mode_jump_p
= (!bfd_link_relocatable (info
)
5790 && !(h
&& h
->root
.root
.type
== bfd_link_hash_undefweak
)
5791 && ((mips16_branch_reloc_p (r_type
)
5792 && !target_is_16_bit_code_p
)
5793 || (micromips_branch_reloc_p (r_type
)
5794 && !target_is_micromips_code_p
)
5795 || ((branch_reloc_p (r_type
)
5796 || r_type
== R_MIPS_JALR
)
5797 && (target_is_16_bit_code_p
5798 || target_is_micromips_code_p
))));
5800 resolved_to_zero
= (h
!= NULL
5801 && UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->root
));
5805 case R_MIPS16_CALL16
:
5806 case R_MIPS16_GOT16
:
5809 case R_MIPS_GOT_PAGE
:
5810 case R_MIPS_GOT_DISP
:
5811 case R_MIPS_GOT_LO16
:
5812 case R_MIPS_CALL_LO16
:
5813 case R_MICROMIPS_CALL16
:
5814 case R_MICROMIPS_GOT16
:
5815 case R_MICROMIPS_GOT_PAGE
:
5816 case R_MICROMIPS_GOT_DISP
:
5817 case R_MICROMIPS_GOT_LO16
:
5818 case R_MICROMIPS_CALL_LO16
:
5819 if (resolved_to_zero
5820 && !bfd_link_relocatable (info
)
5821 && mips_elf_nullify_got_load (input_bfd
, contents
,
5822 relocation
, howto
, TRUE
))
5823 return bfd_reloc_continue
;
5826 case R_MIPS_GOT_HI16
:
5827 case R_MIPS_CALL_HI16
:
5828 case R_MICROMIPS_GOT_HI16
:
5829 case R_MICROMIPS_CALL_HI16
:
5830 if (resolved_to_zero
5831 && htab
->use_absolute_zero
5832 && bfd_link_pic (info
))
5834 /* Redirect to the special `__gnu_absolute_zero' symbol. */
5835 h
= mips_elf_link_hash_lookup (htab
, "__gnu_absolute_zero",
5836 FALSE
, FALSE
, FALSE
);
5837 BFD_ASSERT (h
!= NULL
);
5842 local_p
= (h
== NULL
|| mips_use_local_got_p (info
, h
));
5844 gp0
= _bfd_get_gp_value (input_bfd
);
5845 gp
= _bfd_get_gp_value (abfd
);
5847 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
5852 /* Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
5853 to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
5854 corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST. */
5855 if (got_page_reloc_p (r_type
) && !local_p
)
5857 r_type
= (micromips_reloc_p (r_type
)
5858 ? R_MICROMIPS_GOT_DISP
: R_MIPS_GOT_DISP
);
5862 /* If we haven't already determined the GOT offset, and we're going
5863 to need it, get it now. */
5866 case R_MIPS16_CALL16
:
5867 case R_MIPS16_GOT16
:
5870 case R_MIPS_GOT_DISP
:
5871 case R_MIPS_GOT_HI16
:
5872 case R_MIPS_CALL_HI16
:
5873 case R_MIPS_GOT_LO16
:
5874 case R_MIPS_CALL_LO16
:
5875 case R_MICROMIPS_CALL16
:
5876 case R_MICROMIPS_GOT16
:
5877 case R_MICROMIPS_GOT_DISP
:
5878 case R_MICROMIPS_GOT_HI16
:
5879 case R_MICROMIPS_CALL_HI16
:
5880 case R_MICROMIPS_GOT_LO16
:
5881 case R_MICROMIPS_CALL_LO16
:
5883 case R_MIPS_TLS_GOTTPREL
:
5884 case R_MIPS_TLS_LDM
:
5885 case R_MIPS16_TLS_GD
:
5886 case R_MIPS16_TLS_GOTTPREL
:
5887 case R_MIPS16_TLS_LDM
:
5888 case R_MICROMIPS_TLS_GD
:
5889 case R_MICROMIPS_TLS_GOTTPREL
:
5890 case R_MICROMIPS_TLS_LDM
:
5891 /* Find the index into the GOT where this value is located. */
5892 if (tls_ldm_reloc_p (r_type
))
5894 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5895 0, 0, NULL
, r_type
);
5897 return bfd_reloc_outofrange
;
5901 /* On VxWorks, CALL relocations should refer to the .got.plt
5902 entry, which is initialized to point at the PLT stub. */
5903 if (htab
->root
.target_os
== is_vxworks
5904 && (call_hi16_reloc_p (r_type
)
5905 || call_lo16_reloc_p (r_type
)
5906 || call16_reloc_p (r_type
)))
5908 BFD_ASSERT (addend
== 0);
5909 BFD_ASSERT (h
->root
.needs_plt
);
5910 g
= mips_elf_gotplt_index (info
, &h
->root
);
5914 BFD_ASSERT (addend
== 0);
5915 g
= mips_elf_global_got_index (abfd
, info
, input_bfd
,
5917 if (!TLS_RELOC_P (r_type
)
5918 && !elf_hash_table (info
)->dynamic_sections_created
)
5919 /* This is a static link. We must initialize the GOT entry. */
5920 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->root
.sgot
->contents
+ g
);
5923 else if (htab
->root
.target_os
!= is_vxworks
5924 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
5925 /* The calculation below does not involve "g". */
5929 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5930 symbol
+ addend
, r_symndx
, h
, r_type
);
5932 return bfd_reloc_outofrange
;
5935 /* Convert GOT indices to actual offsets. */
5936 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
5940 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
5941 symbols are resolved by the loader. Add them to .rela.dyn. */
5942 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
5944 Elf_Internal_Rela outrel
;
5948 s
= mips_elf_rel_dyn_section (info
, FALSE
);
5949 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5951 outrel
.r_offset
= (input_section
->output_section
->vma
5952 + input_section
->output_offset
5953 + relocation
->r_offset
);
5954 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
5955 outrel
.r_addend
= addend
;
5956 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
5958 /* If we've written this relocation for a readonly section,
5959 we need to set DF_TEXTREL again, so that we do not delete the
5961 if (MIPS_ELF_READONLY_SECTION (input_section
))
5962 info
->flags
|= DF_TEXTREL
;
5965 return bfd_reloc_ok
;
5968 /* Figure out what kind of relocation is being performed. */
5972 return bfd_reloc_continue
;
5975 if (howto
->partial_inplace
)
5976 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
5977 value
= symbol
+ addend
;
5978 overflowed_p
= mips_elf_overflow_p (value
, 16);
5984 if ((bfd_link_pic (info
)
5985 || (htab
->root
.dynamic_sections_created
5987 && h
->root
.def_dynamic
5988 && !h
->root
.def_regular
5989 && !h
->has_static_relocs
))
5990 && r_symndx
!= STN_UNDEF
5992 || h
->root
.root
.type
!= bfd_link_hash_undefweak
5993 || (ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
5994 && !resolved_to_zero
))
5995 && (input_section
->flags
& SEC_ALLOC
) != 0)
5997 /* If we're creating a shared library, then we can't know
5998 where the symbol will end up. So, we create a relocation
5999 record in the output, and leave the job up to the dynamic
6000 linker. We must do the same for executable references to
6001 shared library symbols, unless we've decided to use copy
6002 relocs or PLTs instead. */
6004 if (!mips_elf_create_dynamic_relocation (abfd
,
6012 return bfd_reloc_undefined
;
6016 if (r_type
!= R_MIPS_REL32
)
6017 value
= symbol
+ addend
;
6021 value
&= howto
->dst_mask
;
6025 value
= symbol
+ addend
- p
;
6026 value
&= howto
->dst_mask
;
6030 /* The calculation for R_MIPS16_26 is just the same as for an
6031 R_MIPS_26. It's only the storage of the relocated field into
6032 the output file that's different. That's handled in
6033 mips_elf_perform_relocation. So, we just fall through to the
6034 R_MIPS_26 case here. */
6036 case R_MICROMIPS_26_S1
:
6040 /* Shift is 2, unusually, for microMIPS JALX. */
6041 shift
= (!*cross_mode_jump_p
&& r_type
== R_MICROMIPS_26_S1
) ? 1 : 2;
6043 if (howto
->partial_inplace
&& !section_p
)
6044 value
= _bfd_mips_elf_sign_extend (addend
, 26 + shift
);
6049 /* Make sure the target of a jump is suitably aligned. Bit 0 must
6050 be the correct ISA mode selector except for weak undefined
6052 if ((was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6053 && (*cross_mode_jump_p
6054 ? (value
& 3) != (r_type
== R_MIPS_26
)
6055 : (value
& ((1 << shift
) - 1)) != (r_type
!= R_MIPS_26
)))
6056 return bfd_reloc_outofrange
;
6059 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6060 overflowed_p
= (value
>> 26) != ((p
+ 4) >> (26 + shift
));
6061 value
&= howto
->dst_mask
;
6065 case R_MIPS_TLS_DTPREL_HI16
:
6066 case R_MIPS16_TLS_DTPREL_HI16
:
6067 case R_MICROMIPS_TLS_DTPREL_HI16
:
6068 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
6072 case R_MIPS_TLS_DTPREL_LO16
:
6073 case R_MIPS_TLS_DTPREL32
:
6074 case R_MIPS_TLS_DTPREL64
:
6075 case R_MIPS16_TLS_DTPREL_LO16
:
6076 case R_MICROMIPS_TLS_DTPREL_LO16
:
6077 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
6080 case R_MIPS_TLS_TPREL_HI16
:
6081 case R_MIPS16_TLS_TPREL_HI16
:
6082 case R_MICROMIPS_TLS_TPREL_HI16
:
6083 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
6087 case R_MIPS_TLS_TPREL_LO16
:
6088 case R_MIPS_TLS_TPREL32
:
6089 case R_MIPS_TLS_TPREL64
:
6090 case R_MIPS16_TLS_TPREL_LO16
:
6091 case R_MICROMIPS_TLS_TPREL_LO16
:
6092 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
6097 case R_MICROMIPS_HI16
:
6100 value
= mips_elf_high (addend
+ symbol
);
6101 value
&= howto
->dst_mask
;
6105 /* For MIPS16 ABI code we generate this sequence
6106 0: li $v0,%hi(_gp_disp)
6107 4: addiupc $v1,%lo(_gp_disp)
6111 So the offsets of hi and lo relocs are the same, but the
6112 base $pc is that used by the ADDIUPC instruction at $t9 + 4.
6113 ADDIUPC clears the low two bits of the instruction address,
6114 so the base is ($t9 + 4) & ~3. */
6115 if (r_type
== R_MIPS16_HI16
)
6116 value
= mips_elf_high (addend
+ gp
- ((p
+ 4) & ~(bfd_vma
) 0x3));
6117 /* The microMIPS .cpload sequence uses the same assembly
6118 instructions as the traditional psABI version, but the
6119 incoming $t9 has the low bit set. */
6120 else if (r_type
== R_MICROMIPS_HI16
)
6121 value
= mips_elf_high (addend
+ gp
- p
- 1);
6123 value
= mips_elf_high (addend
+ gp
- p
);
6129 case R_MICROMIPS_LO16
:
6130 case R_MICROMIPS_HI0_LO16
:
6132 value
= (symbol
+ addend
) & howto
->dst_mask
;
6135 /* See the comment for R_MIPS16_HI16 above for the reason
6136 for this conditional. */
6137 if (r_type
== R_MIPS16_LO16
)
6138 value
= addend
+ gp
- (p
& ~(bfd_vma
) 0x3);
6139 else if (r_type
== R_MICROMIPS_LO16
6140 || r_type
== R_MICROMIPS_HI0_LO16
)
6141 value
= addend
+ gp
- p
+ 3;
6143 value
= addend
+ gp
- p
+ 4;
6144 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
6145 for overflow. But, on, say, IRIX5, relocations against
6146 _gp_disp are normally generated from the .cpload
6147 pseudo-op. It generates code that normally looks like
6150 lui $gp,%hi(_gp_disp)
6151 addiu $gp,$gp,%lo(_gp_disp)
6154 Here $t9 holds the address of the function being called,
6155 as required by the MIPS ELF ABI. The R_MIPS_LO16
6156 relocation can easily overflow in this situation, but the
6157 R_MIPS_HI16 relocation will handle the overflow.
6158 Therefore, we consider this a bug in the MIPS ABI, and do
6159 not check for overflow here. */
6163 case R_MIPS_LITERAL
:
6164 case R_MICROMIPS_LITERAL
:
6165 /* Because we don't merge literal sections, we can handle this
6166 just like R_MIPS_GPREL16. In the long run, we should merge
6167 shared literals, and then we will need to additional work
6172 case R_MIPS16_GPREL
:
6173 /* The R_MIPS16_GPREL performs the same calculation as
6174 R_MIPS_GPREL16, but stores the relocated bits in a different
6175 order. We don't need to do anything special here; the
6176 differences are handled in mips_elf_perform_relocation. */
6177 case R_MIPS_GPREL16
:
6178 case R_MICROMIPS_GPREL7_S2
:
6179 case R_MICROMIPS_GPREL16
:
6180 /* Only sign-extend the addend if it was extracted from the
6181 instruction. If the addend was separate, leave it alone,
6182 otherwise we may lose significant bits. */
6183 if (howto
->partial_inplace
)
6184 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
6185 value
= symbol
+ addend
- gp
;
6186 /* If the symbol was local, any earlier relocatable links will
6187 have adjusted its addend with the gp offset, so compensate
6188 for that now. Don't do it for symbols forced local in this
6189 link, though, since they won't have had the gp offset applied
6193 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6194 overflowed_p
= mips_elf_overflow_p (value
, 16);
6197 case R_MIPS16_GOT16
:
6198 case R_MIPS16_CALL16
:
6201 case R_MICROMIPS_GOT16
:
6202 case R_MICROMIPS_CALL16
:
6203 /* VxWorks does not have separate local and global semantics for
6204 R_MIPS*_GOT16; every relocation evaluates to "G". */
6205 if (htab
->root
.target_os
!= is_vxworks
&& local_p
)
6207 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
6208 symbol
+ addend
, !was_local_p
);
6209 if (value
== MINUS_ONE
)
6210 return bfd_reloc_outofrange
;
6212 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
6213 overflowed_p
= mips_elf_overflow_p (value
, 16);
6220 case R_MIPS_TLS_GOTTPREL
:
6221 case R_MIPS_TLS_LDM
:
6222 case R_MIPS_GOT_DISP
:
6223 case R_MIPS16_TLS_GD
:
6224 case R_MIPS16_TLS_GOTTPREL
:
6225 case R_MIPS16_TLS_LDM
:
6226 case R_MICROMIPS_TLS_GD
:
6227 case R_MICROMIPS_TLS_GOTTPREL
:
6228 case R_MICROMIPS_TLS_LDM
:
6229 case R_MICROMIPS_GOT_DISP
:
6231 overflowed_p
= mips_elf_overflow_p (value
, 16);
6234 case R_MIPS_GPREL32
:
6235 value
= (addend
+ symbol
+ gp0
- gp
);
6237 value
&= howto
->dst_mask
;
6241 case R_MIPS_GNU_REL16_S2
:
6242 if (howto
->partial_inplace
)
6243 addend
= _bfd_mips_elf_sign_extend (addend
, 18);
6245 /* No need to exclude weak undefined symbols here as they resolve
6246 to 0 and never set `*cross_mode_jump_p', so this alignment check
6247 will never trigger for them. */
6248 if (*cross_mode_jump_p
6249 ? ((symbol
+ addend
) & 3) != 1
6250 : ((symbol
+ addend
) & 3) != 0)
6251 return bfd_reloc_outofrange
;
6253 value
= symbol
+ addend
- p
;
6254 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6255 overflowed_p
= mips_elf_overflow_p (value
, 18);
6256 value
>>= howto
->rightshift
;
6257 value
&= howto
->dst_mask
;
6260 case R_MIPS16_PC16_S1
:
6261 if (howto
->partial_inplace
)
6262 addend
= _bfd_mips_elf_sign_extend (addend
, 17);
6264 if ((was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6265 && (*cross_mode_jump_p
6266 ? ((symbol
+ addend
) & 3) != 0
6267 : ((symbol
+ addend
) & 1) == 0))
6268 return bfd_reloc_outofrange
;
6270 value
= symbol
+ addend
- p
;
6271 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6272 overflowed_p
= mips_elf_overflow_p (value
, 17);
6273 value
>>= howto
->rightshift
;
6274 value
&= howto
->dst_mask
;
6277 case R_MIPS_PC21_S2
:
6278 if (howto
->partial_inplace
)
6279 addend
= _bfd_mips_elf_sign_extend (addend
, 23);
6281 if ((symbol
+ addend
) & 3)
6282 return bfd_reloc_outofrange
;
6284 value
= symbol
+ addend
- p
;
6285 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6286 overflowed_p
= mips_elf_overflow_p (value
, 23);
6287 value
>>= howto
->rightshift
;
6288 value
&= howto
->dst_mask
;
6291 case R_MIPS_PC26_S2
:
6292 if (howto
->partial_inplace
)
6293 addend
= _bfd_mips_elf_sign_extend (addend
, 28);
6295 if ((symbol
+ addend
) & 3)
6296 return bfd_reloc_outofrange
;
6298 value
= symbol
+ addend
- p
;
6299 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6300 overflowed_p
= mips_elf_overflow_p (value
, 28);
6301 value
>>= howto
->rightshift
;
6302 value
&= howto
->dst_mask
;
6305 case R_MIPS_PC18_S3
:
6306 if (howto
->partial_inplace
)
6307 addend
= _bfd_mips_elf_sign_extend (addend
, 21);
6309 if ((symbol
+ addend
) & 7)
6310 return bfd_reloc_outofrange
;
6312 value
= symbol
+ addend
- ((p
| 7) ^ 7);
6313 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6314 overflowed_p
= mips_elf_overflow_p (value
, 21);
6315 value
>>= howto
->rightshift
;
6316 value
&= howto
->dst_mask
;
6319 case R_MIPS_PC19_S2
:
6320 if (howto
->partial_inplace
)
6321 addend
= _bfd_mips_elf_sign_extend (addend
, 21);
6323 if ((symbol
+ addend
) & 3)
6324 return bfd_reloc_outofrange
;
6326 value
= symbol
+ addend
- p
;
6327 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6328 overflowed_p
= mips_elf_overflow_p (value
, 21);
6329 value
>>= howto
->rightshift
;
6330 value
&= howto
->dst_mask
;
6334 value
= mips_elf_high (symbol
+ addend
- p
);
6335 value
&= howto
->dst_mask
;
6339 if (howto
->partial_inplace
)
6340 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
6341 value
= symbol
+ addend
- p
;
6342 value
&= howto
->dst_mask
;
6345 case R_MICROMIPS_PC7_S1
:
6346 if (howto
->partial_inplace
)
6347 addend
= _bfd_mips_elf_sign_extend (addend
, 8);
6349 if ((was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6350 && (*cross_mode_jump_p
6351 ? ((symbol
+ addend
+ 2) & 3) != 0
6352 : ((symbol
+ addend
+ 2) & 1) == 0))
6353 return bfd_reloc_outofrange
;
6355 value
= symbol
+ addend
- p
;
6356 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6357 overflowed_p
= mips_elf_overflow_p (value
, 8);
6358 value
>>= howto
->rightshift
;
6359 value
&= howto
->dst_mask
;
6362 case R_MICROMIPS_PC10_S1
:
6363 if (howto
->partial_inplace
)
6364 addend
= _bfd_mips_elf_sign_extend (addend
, 11);
6366 if ((was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6367 && (*cross_mode_jump_p
6368 ? ((symbol
+ addend
+ 2) & 3) != 0
6369 : ((symbol
+ addend
+ 2) & 1) == 0))
6370 return bfd_reloc_outofrange
;
6372 value
= symbol
+ addend
- p
;
6373 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6374 overflowed_p
= mips_elf_overflow_p (value
, 11);
6375 value
>>= howto
->rightshift
;
6376 value
&= howto
->dst_mask
;
6379 case R_MICROMIPS_PC16_S1
:
6380 if (howto
->partial_inplace
)
6381 addend
= _bfd_mips_elf_sign_extend (addend
, 17);
6383 if ((was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6384 && (*cross_mode_jump_p
6385 ? ((symbol
+ addend
) & 3) != 0
6386 : ((symbol
+ addend
) & 1) == 0))
6387 return bfd_reloc_outofrange
;
6389 value
= symbol
+ addend
- p
;
6390 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6391 overflowed_p
= mips_elf_overflow_p (value
, 17);
6392 value
>>= howto
->rightshift
;
6393 value
&= howto
->dst_mask
;
6396 case R_MICROMIPS_PC23_S2
:
6397 if (howto
->partial_inplace
)
6398 addend
= _bfd_mips_elf_sign_extend (addend
, 25);
6399 value
= symbol
+ addend
- ((p
| 3) ^ 3);
6400 if (was_local_p
|| h
->root
.root
.type
!= bfd_link_hash_undefweak
)
6401 overflowed_p
= mips_elf_overflow_p (value
, 25);
6402 value
>>= howto
->rightshift
;
6403 value
&= howto
->dst_mask
;
6406 case R_MIPS_GOT_HI16
:
6407 case R_MIPS_CALL_HI16
:
6408 case R_MICROMIPS_GOT_HI16
:
6409 case R_MICROMIPS_CALL_HI16
:
6410 /* We're allowed to handle these two relocations identically.
6411 The dynamic linker is allowed to handle the CALL relocations
6412 differently by creating a lazy evaluation stub. */
6414 value
= mips_elf_high (value
);
6415 value
&= howto
->dst_mask
;
6418 case R_MIPS_GOT_LO16
:
6419 case R_MIPS_CALL_LO16
:
6420 case R_MICROMIPS_GOT_LO16
:
6421 case R_MICROMIPS_CALL_LO16
:
6422 value
= g
& howto
->dst_mask
;
6425 case R_MIPS_GOT_PAGE
:
6426 case R_MICROMIPS_GOT_PAGE
:
6427 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
6428 if (value
== MINUS_ONE
)
6429 return bfd_reloc_outofrange
;
6430 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
6431 overflowed_p
= mips_elf_overflow_p (value
, 16);
6434 case R_MIPS_GOT_OFST
:
6435 case R_MICROMIPS_GOT_OFST
:
6437 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
6440 overflowed_p
= mips_elf_overflow_p (value
, 16);
6444 case R_MICROMIPS_SUB
:
6445 value
= symbol
- addend
;
6446 value
&= howto
->dst_mask
;
6450 case R_MICROMIPS_HIGHER
:
6451 value
= mips_elf_higher (addend
+ symbol
);
6452 value
&= howto
->dst_mask
;
6455 case R_MIPS_HIGHEST
:
6456 case R_MICROMIPS_HIGHEST
:
6457 value
= mips_elf_highest (addend
+ symbol
);
6458 value
&= howto
->dst_mask
;
6461 case R_MIPS_SCN_DISP
:
6462 case R_MICROMIPS_SCN_DISP
:
6463 value
= symbol
+ addend
- sec
->output_offset
;
6464 value
&= howto
->dst_mask
;
6468 case R_MICROMIPS_JALR
:
6469 /* This relocation is only a hint. In some cases, we optimize
6470 it into a bal instruction. But we don't try to optimize
6471 when the symbol does not resolve locally. */
6472 if (h
!= NULL
&& !SYMBOL_CALLS_LOCAL (info
, &h
->root
))
6473 return bfd_reloc_continue
;
6474 /* We can't optimize cross-mode jumps either. */
6475 if (*cross_mode_jump_p
)
6476 return bfd_reloc_continue
;
6477 value
= symbol
+ addend
;
6478 /* Neither we can non-instruction-aligned targets. */
6479 if (r_type
== R_MIPS_JALR
? (value
& 3) != 0 : (value
& 1) == 0)
6480 return bfd_reloc_continue
;
6484 case R_MIPS_GNU_VTINHERIT
:
6485 case R_MIPS_GNU_VTENTRY
:
6486 /* We don't do anything with these at present. */
6487 return bfd_reloc_continue
;
6490 /* An unrecognized relocation type. */
6491 return bfd_reloc_notsupported
;
6494 /* Store the VALUE for our caller. */
6496 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
6499 /* It has been determined that the result of the RELOCATION is the
6500 VALUE. Use HOWTO to place VALUE into the output file at the
6501 appropriate position. The SECTION is the section to which the
6503 CROSS_MODE_JUMP_P is true if the relocation field
6504 is a MIPS16 or microMIPS jump to standard MIPS code, or vice versa.
6506 Returns FALSE if anything goes wrong. */
6509 mips_elf_perform_relocation (struct bfd_link_info
*info
,
6510 reloc_howto_type
*howto
,
6511 const Elf_Internal_Rela
*relocation
,
6512 bfd_vma value
, bfd
*input_bfd
,
6513 asection
*input_section
, bfd_byte
*contents
,
6514 bfd_boolean cross_mode_jump_p
)
6518 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
6520 /* Figure out where the relocation is occurring. */
6521 location
= contents
+ relocation
->r_offset
;
6523 _bfd_mips_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
6525 /* Obtain the current value. */
6526 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
6528 /* Clear the field we are setting. */
6529 x
&= ~howto
->dst_mask
;
6531 /* Set the field. */
6532 x
|= (value
& howto
->dst_mask
);
6534 /* Detect incorrect JALX usage. If required, turn JAL or BAL into JALX. */
6535 if (!cross_mode_jump_p
&& jal_reloc_p (r_type
))
6537 bfd_vma opcode
= x
>> 26;
6539 if (r_type
== R_MIPS16_26
? opcode
== 0x7
6540 : r_type
== R_MICROMIPS_26_S1
? opcode
== 0x3c
6543 info
->callbacks
->einfo
6544 (_("%X%H: unsupported JALX to the same ISA mode\n"),
6545 input_bfd
, input_section
, relocation
->r_offset
);
6549 if (cross_mode_jump_p
&& jal_reloc_p (r_type
))
6552 bfd_vma opcode
= x
>> 26;
6553 bfd_vma jalx_opcode
;
6555 /* Check to see if the opcode is already JAL or JALX. */
6556 if (r_type
== R_MIPS16_26
)
6558 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
6561 else if (r_type
== R_MICROMIPS_26_S1
)
6563 ok
= ((opcode
== 0x3d) || (opcode
== 0x3c));
6568 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
6572 /* If the opcode is not JAL or JALX, there's a problem. We cannot
6573 convert J or JALS to JALX. */
6576 info
->callbacks
->einfo
6577 (_("%X%H: unsupported jump between ISA modes; "
6578 "consider recompiling with interlinking enabled\n"),
6579 input_bfd
, input_section
, relocation
->r_offset
);
6583 /* Make this the JALX opcode. */
6584 x
= (x
& ~(0x3fu
<< 26)) | (jalx_opcode
<< 26);
6586 else if (cross_mode_jump_p
&& b_reloc_p (r_type
))
6588 bfd_boolean ok
= FALSE
;
6589 bfd_vma opcode
= x
>> 16;
6590 bfd_vma jalx_opcode
= 0;
6591 bfd_vma sign_bit
= 0;
6595 if (r_type
== R_MICROMIPS_PC16_S1
)
6597 ok
= opcode
== 0x4060;
6602 else if (r_type
== R_MIPS_PC16
|| r_type
== R_MIPS_GNU_REL16_S2
)
6604 ok
= opcode
== 0x411;
6610 if (ok
&& !bfd_link_pic (info
))
6612 addr
= (input_section
->output_section
->vma
6613 + input_section
->output_offset
6614 + relocation
->r_offset
6617 + (((value
& ((sign_bit
<< 1) - 1)) ^ sign_bit
) - sign_bit
));
6619 if ((addr
>> 28) << 28 != (dest
>> 28) << 28)
6621 info
->callbacks
->einfo
6622 (_("%X%H: cannot convert branch between ISA modes "
6623 "to JALX: relocation out of range\n"),
6624 input_bfd
, input_section
, relocation
->r_offset
);
6628 /* Make this the JALX opcode. */
6629 x
= ((dest
>> 2) & 0x3ffffff) | jalx_opcode
<< 26;
6631 else if (!mips_elf_hash_table (info
)->ignore_branch_isa
)
6633 info
->callbacks
->einfo
6634 (_("%X%H: unsupported branch between ISA modes\n"),
6635 input_bfd
, input_section
, relocation
->r_offset
);
6640 /* Try converting JAL to BAL and J(AL)R to B(AL), if the target is in
6642 if (!bfd_link_relocatable (info
)
6643 && !cross_mode_jump_p
6644 && ((JAL_TO_BAL_P (input_bfd
)
6645 && r_type
== R_MIPS_26
6646 && (x
>> 26) == 0x3) /* jal addr */
6647 || (JALR_TO_BAL_P (input_bfd
)
6648 && r_type
== R_MIPS_JALR
6649 && x
== 0x0320f809) /* jalr t9 */
6650 || (JR_TO_B_P (input_bfd
)
6651 && r_type
== R_MIPS_JALR
6652 && (x
& ~1) == 0x03200008))) /* jr t9 / jalr zero, t9 */
6658 addr
= (input_section
->output_section
->vma
6659 + input_section
->output_offset
6660 + relocation
->r_offset
6662 if (r_type
== R_MIPS_26
)
6663 dest
= (value
<< 2) | ((addr
>> 28) << 28);
6667 if (off
<= 0x1ffff && off
>= -0x20000)
6669 if ((x
& ~1) == 0x03200008) /* jr t9 / jalr zero, t9 */
6670 x
= 0x10000000 | (((bfd_vma
) off
>> 2) & 0xffff); /* b addr */
6672 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
6676 /* Put the value into the output. */
6677 mips_elf_store_contents (howto
, relocation
, input_bfd
, contents
, x
);
6679 _bfd_mips_elf_reloc_shuffle (input_bfd
, r_type
, !bfd_link_relocatable (info
),
6685 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
6686 is the original relocation, which is now being transformed into a
6687 dynamic relocation. The ADDENDP is adjusted if necessary; the
6688 caller should store the result in place of the original addend. */
6691 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
6692 struct bfd_link_info
*info
,
6693 const Elf_Internal_Rela
*rel
,
6694 struct mips_elf_link_hash_entry
*h
,
6695 asection
*sec
, bfd_vma symbol
,
6696 bfd_vma
*addendp
, asection
*input_section
)
6698 Elf_Internal_Rela outrel
[3];
6703 bfd_boolean defined_p
;
6704 struct mips_elf_link_hash_table
*htab
;
6706 htab
= mips_elf_hash_table (info
);
6707 BFD_ASSERT (htab
!= NULL
);
6709 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
6710 dynobj
= elf_hash_table (info
)->dynobj
;
6711 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
6712 BFD_ASSERT (sreloc
!= NULL
);
6713 BFD_ASSERT (sreloc
->contents
!= NULL
);
6714 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
6717 outrel
[0].r_offset
=
6718 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
6719 if (ABI_64_P (output_bfd
))
6721 outrel
[1].r_offset
=
6722 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
6723 outrel
[2].r_offset
=
6724 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
6727 if (outrel
[0].r_offset
== MINUS_ONE
)
6728 /* The relocation field has been deleted. */
6731 if (outrel
[0].r_offset
== MINUS_TWO
)
6733 /* The relocation field has been converted into a relative value of
6734 some sort. Functions like _bfd_elf_write_section_eh_frame expect
6735 the field to be fully relocated, so add in the symbol's value. */
6740 /* We must now calculate the dynamic symbol table index to use
6741 in the relocation. */
6742 if (h
!= NULL
&& ! SYMBOL_REFERENCES_LOCAL (info
, &h
->root
))
6744 BFD_ASSERT (htab
->root
.target_os
== is_vxworks
6745 || h
->global_got_area
!= GGA_NONE
);
6746 indx
= h
->root
.dynindx
;
6747 if (SGI_COMPAT (output_bfd
))
6748 defined_p
= h
->root
.def_regular
;
6750 /* ??? glibc's ld.so just adds the final GOT entry to the
6751 relocation field. It therefore treats relocs against
6752 defined symbols in the same way as relocs against
6753 undefined symbols. */
6758 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
6760 else if (sec
== NULL
|| sec
->owner
== NULL
)
6762 bfd_set_error (bfd_error_bad_value
);
6767 indx
= elf_section_data (sec
->output_section
)->dynindx
;
6770 asection
*osec
= htab
->root
.text_index_section
;
6771 indx
= elf_section_data (osec
)->dynindx
;
6777 /* Instead of generating a relocation using the section
6778 symbol, we may as well make it a fully relative
6779 relocation. We want to avoid generating relocations to
6780 local symbols because we used to generate them
6781 incorrectly, without adding the original symbol value,
6782 which is mandated by the ABI for section symbols. In
6783 order to give dynamic loaders and applications time to
6784 phase out the incorrect use, we refrain from emitting
6785 section-relative relocations. It's not like they're
6786 useful, after all. This should be a bit more efficient
6788 /* ??? Although this behavior is compatible with glibc's ld.so,
6789 the ABI says that relocations against STN_UNDEF should have
6790 a symbol value of 0. Irix rld honors this, so relocations
6791 against STN_UNDEF have no effect. */
6792 if (!SGI_COMPAT (output_bfd
))
6797 /* If the relocation was previously an absolute relocation and
6798 this symbol will not be referred to by the relocation, we must
6799 adjust it by the value we give it in the dynamic symbol table.
6800 Otherwise leave the job up to the dynamic linker. */
6801 if (defined_p
&& r_type
!= R_MIPS_REL32
)
6804 if (htab
->root
.target_os
== is_vxworks
)
6805 /* VxWorks uses non-relative relocations for this. */
6806 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
6808 /* The relocation is always an REL32 relocation because we don't
6809 know where the shared library will wind up at load-time. */
6810 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
6813 /* For strict adherence to the ABI specification, we should
6814 generate a R_MIPS_64 relocation record by itself before the
6815 _REL32/_64 record as well, such that the addend is read in as
6816 a 64-bit value (REL32 is a 32-bit relocation, after all).
6817 However, since none of the existing ELF64 MIPS dynamic
6818 loaders seems to care, we don't waste space with these
6819 artificial relocations. If this turns out to not be true,
6820 mips_elf_allocate_dynamic_relocation() should be tweaked so
6821 as to make room for a pair of dynamic relocations per
6822 invocation if ABI_64_P, and here we should generate an
6823 additional relocation record with R_MIPS_64 by itself for a
6824 NULL symbol before this relocation record. */
6825 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
6826 ABI_64_P (output_bfd
)
6829 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
6831 /* Adjust the output offset of the relocation to reference the
6832 correct location in the output file. */
6833 outrel
[0].r_offset
+= (input_section
->output_section
->vma
6834 + input_section
->output_offset
);
6835 outrel
[1].r_offset
+= (input_section
->output_section
->vma
6836 + input_section
->output_offset
);
6837 outrel
[2].r_offset
+= (input_section
->output_section
->vma
6838 + input_section
->output_offset
);
6840 /* Put the relocation back out. We have to use the special
6841 relocation outputter in the 64-bit case since the 64-bit
6842 relocation format is non-standard. */
6843 if (ABI_64_P (output_bfd
))
6845 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
6846 (output_bfd
, &outrel
[0],
6848 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
6850 else if (htab
->root
.target_os
== is_vxworks
)
6852 /* VxWorks uses RELA rather than REL dynamic relocations. */
6853 outrel
[0].r_addend
= *addendp
;
6854 bfd_elf32_swap_reloca_out
6855 (output_bfd
, &outrel
[0],
6857 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
6860 bfd_elf32_swap_reloc_out
6861 (output_bfd
, &outrel
[0],
6862 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
6864 /* We've now added another relocation. */
6865 ++sreloc
->reloc_count
;
6867 /* Make sure the output section is writable. The dynamic linker
6868 will be writing to it. */
6869 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
6872 /* On IRIX5, make an entry of compact relocation info. */
6873 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
6875 asection
*scpt
= bfd_get_linker_section (dynobj
, ".compact_rel");
6880 Elf32_crinfo cptrel
;
6882 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
6883 cptrel
.vaddr
= (rel
->r_offset
6884 + input_section
->output_section
->vma
6885 + input_section
->output_offset
);
6886 if (r_type
== R_MIPS_REL32
)
6887 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
6889 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
6890 mips_elf_set_cr_dist2to (cptrel
, 0);
6891 cptrel
.konst
= *addendp
;
6893 cr
= (scpt
->contents
6894 + sizeof (Elf32_External_compact_rel
));
6895 mips_elf_set_cr_relvaddr (cptrel
, 0);
6896 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
6897 ((Elf32_External_crinfo
*) cr
6898 + scpt
->reloc_count
));
6899 ++scpt
->reloc_count
;
6903 /* If we've written this relocation for a readonly section,
6904 we need to set DF_TEXTREL again, so that we do not delete the
6906 if (MIPS_ELF_READONLY_SECTION (input_section
))
6907 info
->flags
|= DF_TEXTREL
;
6912 /* Return the MACH for a MIPS e_flags value. */
6915 _bfd_elf_mips_mach (flagword flags
)
6917 switch (flags
& EF_MIPS_MACH
)
6919 case E_MIPS_MACH_3900
:
6920 return bfd_mach_mips3900
;
6922 case E_MIPS_MACH_4010
:
6923 return bfd_mach_mips4010
;
6925 case E_MIPS_MACH_4100
:
6926 return bfd_mach_mips4100
;
6928 case E_MIPS_MACH_4111
:
6929 return bfd_mach_mips4111
;
6931 case E_MIPS_MACH_4120
:
6932 return bfd_mach_mips4120
;
6934 case E_MIPS_MACH_4650
:
6935 return bfd_mach_mips4650
;
6937 case E_MIPS_MACH_5400
:
6938 return bfd_mach_mips5400
;
6940 case E_MIPS_MACH_5500
:
6941 return bfd_mach_mips5500
;
6943 case E_MIPS_MACH_5900
:
6944 return bfd_mach_mips5900
;
6946 case E_MIPS_MACH_9000
:
6947 return bfd_mach_mips9000
;
6949 case E_MIPS_MACH_SB1
:
6950 return bfd_mach_mips_sb1
;
6952 case E_MIPS_MACH_LS2E
:
6953 return bfd_mach_mips_loongson_2e
;
6955 case E_MIPS_MACH_LS2F
:
6956 return bfd_mach_mips_loongson_2f
;
6958 case E_MIPS_MACH_GS464
:
6959 return bfd_mach_mips_gs464
;
6961 case E_MIPS_MACH_GS464E
:
6962 return bfd_mach_mips_gs464e
;
6964 case E_MIPS_MACH_GS264E
:
6965 return bfd_mach_mips_gs264e
;
6967 case E_MIPS_MACH_OCTEON3
:
6968 return bfd_mach_mips_octeon3
;
6970 case E_MIPS_MACH_OCTEON2
:
6971 return bfd_mach_mips_octeon2
;
6973 case E_MIPS_MACH_OCTEON
:
6974 return bfd_mach_mips_octeon
;
6976 case E_MIPS_MACH_XLR
:
6977 return bfd_mach_mips_xlr
;
6979 case E_MIPS_MACH_IAMR2
:
6980 return bfd_mach_mips_interaptiv_mr2
;
6983 switch (flags
& EF_MIPS_ARCH
)
6987 return bfd_mach_mips3000
;
6990 return bfd_mach_mips6000
;
6993 return bfd_mach_mips4000
;
6996 return bfd_mach_mips8000
;
6999 return bfd_mach_mips5
;
7001 case E_MIPS_ARCH_32
:
7002 return bfd_mach_mipsisa32
;
7004 case E_MIPS_ARCH_64
:
7005 return bfd_mach_mipsisa64
;
7007 case E_MIPS_ARCH_32R2
:
7008 return bfd_mach_mipsisa32r2
;
7010 case E_MIPS_ARCH_64R2
:
7011 return bfd_mach_mipsisa64r2
;
7013 case E_MIPS_ARCH_32R6
:
7014 return bfd_mach_mipsisa32r6
;
7016 case E_MIPS_ARCH_64R6
:
7017 return bfd_mach_mipsisa64r6
;
7024 /* Return printable name for ABI. */
7026 static INLINE
char *
7027 elf_mips_abi_name (bfd
*abfd
)
7031 flags
= elf_elfheader (abfd
)->e_flags
;
7032 switch (flags
& EF_MIPS_ABI
)
7035 if (ABI_N32_P (abfd
))
7037 else if (ABI_64_P (abfd
))
7041 case E_MIPS_ABI_O32
:
7043 case E_MIPS_ABI_O64
:
7045 case E_MIPS_ABI_EABI32
:
7047 case E_MIPS_ABI_EABI64
:
7050 return "unknown abi";
7054 /* MIPS ELF uses two common sections. One is the usual one, and the
7055 other is for small objects. All the small objects are kept
7056 together, and then referenced via the gp pointer, which yields
7057 faster assembler code. This is what we use for the small common
7058 section. This approach is copied from ecoff.c. */
7059 static asection mips_elf_scom_section
;
7060 static asymbol mips_elf_scom_symbol
;
7061 static asymbol
*mips_elf_scom_symbol_ptr
;
7063 /* MIPS ELF also uses an acommon section, which represents an
7064 allocated common symbol which may be overridden by a
7065 definition in a shared library. */
7066 static asection mips_elf_acom_section
;
7067 static asymbol mips_elf_acom_symbol
;
7068 static asymbol
*mips_elf_acom_symbol_ptr
;
7070 /* This is used for both the 32-bit and the 64-bit ABI. */
7073 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
7075 elf_symbol_type
*elfsym
;
7077 /* Handle the special MIPS section numbers that a symbol may use. */
7078 elfsym
= (elf_symbol_type
*) asym
;
7079 switch (elfsym
->internal_elf_sym
.st_shndx
)
7081 case SHN_MIPS_ACOMMON
:
7082 /* This section is used in a dynamically linked executable file.
7083 It is an allocated common section. The dynamic linker can
7084 either resolve these symbols to something in a shared
7085 library, or it can just leave them here. For our purposes,
7086 we can consider these symbols to be in a new section. */
7087 if (mips_elf_acom_section
.name
== NULL
)
7089 /* Initialize the acommon section. */
7090 mips_elf_acom_section
.name
= ".acommon";
7091 mips_elf_acom_section
.flags
= SEC_ALLOC
;
7092 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
7093 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
7094 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
7095 mips_elf_acom_symbol
.name
= ".acommon";
7096 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
7097 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
7098 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
7100 asym
->section
= &mips_elf_acom_section
;
7104 /* Common symbols less than the GP size are automatically
7105 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
7106 if (asym
->value
> elf_gp_size (abfd
)
7107 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
7108 || IRIX_COMPAT (abfd
) == ict_irix6
)
7111 case SHN_MIPS_SCOMMON
:
7112 if (mips_elf_scom_section
.name
== NULL
)
7114 /* Initialize the small common section. */
7115 mips_elf_scom_section
.name
= ".scommon";
7116 mips_elf_scom_section
.flags
= SEC_IS_COMMON
| SEC_SMALL_DATA
;
7117 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
7118 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
7119 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
7120 mips_elf_scom_symbol
.name
= ".scommon";
7121 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
7122 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
7123 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
7125 asym
->section
= &mips_elf_scom_section
;
7126 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
7129 case SHN_MIPS_SUNDEFINED
:
7130 asym
->section
= bfd_und_section_ptr
;
7135 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
7137 if (section
!= NULL
)
7139 asym
->section
= section
;
7140 /* MIPS_TEXT is a bit special, the address is not an offset
7141 to the base of the .text section. So subtract the section
7142 base address to make it an offset. */
7143 asym
->value
-= section
->vma
;
7150 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
7152 if (section
!= NULL
)
7154 asym
->section
= section
;
7155 /* MIPS_DATA is a bit special, the address is not an offset
7156 to the base of the .data section. So subtract the section
7157 base address to make it an offset. */
7158 asym
->value
-= section
->vma
;
7164 /* If this is an odd-valued function symbol, assume it's a MIPS16
7165 or microMIPS one. */
7166 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
7167 && (asym
->value
& 1) != 0)
7170 if (MICROMIPS_P (abfd
))
7171 elfsym
->internal_elf_sym
.st_other
7172 = ELF_ST_SET_MICROMIPS (elfsym
->internal_elf_sym
.st_other
);
7174 elfsym
->internal_elf_sym
.st_other
7175 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
7179 /* Implement elf_backend_eh_frame_address_size. This differs from
7180 the default in the way it handles EABI64.
7182 EABI64 was originally specified as an LP64 ABI, and that is what
7183 -mabi=eabi normally gives on a 64-bit target. However, gcc has
7184 historically accepted the combination of -mabi=eabi and -mlong32,
7185 and this ILP32 variation has become semi-official over time.
7186 Both forms use elf32 and have pointer-sized FDE addresses.
7188 If an EABI object was generated by GCC 4.0 or above, it will have
7189 an empty .gcc_compiled_longXX section, where XX is the size of longs
7190 in bits. Unfortunately, ILP32 objects generated by earlier compilers
7191 have no special marking to distinguish them from LP64 objects.
7193 We don't want users of the official LP64 ABI to be punished for the
7194 existence of the ILP32 variant, but at the same time, we don't want
7195 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
7196 We therefore take the following approach:
7198 - If ABFD contains a .gcc_compiled_longXX section, use it to
7199 determine the pointer size.
7201 - Otherwise check the type of the first relocation. Assume that
7202 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
7206 The second check is enough to detect LP64 objects generated by pre-4.0
7207 compilers because, in the kind of output generated by those compilers,
7208 the first relocation will be associated with either a CIE personality
7209 routine or an FDE start address. Furthermore, the compilers never
7210 used a special (non-pointer) encoding for this ABI.
7212 Checking the relocation type should also be safe because there is no
7213 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
7217 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, const asection
*sec
)
7219 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
7221 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
7223 bfd_boolean long32_p
, long64_p
;
7225 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
7226 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
7227 if (long32_p
&& long64_p
)
7234 if (sec
->reloc_count
> 0
7235 && elf_section_data (sec
)->relocs
!= NULL
7236 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
7245 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
7246 relocations against two unnamed section symbols to resolve to the
7247 same address. For example, if we have code like:
7249 lw $4,%got_disp(.data)($gp)
7250 lw $25,%got_disp(.text)($gp)
7253 then the linker will resolve both relocations to .data and the program
7254 will jump there rather than to .text.
7256 We can work around this problem by giving names to local section symbols.
7257 This is also what the MIPSpro tools do. */
7260 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
7262 return elf_elfheader (abfd
)->e_type
== ET_REL
&& SGI_COMPAT (abfd
);
7265 /* Work over a section just before writing it out. This routine is
7266 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
7267 sections that need the SHF_MIPS_GPREL flag by name; there has to be
7271 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
7273 if (hdr
->sh_type
== SHT_MIPS_REGINFO
7274 && hdr
->sh_size
> 0)
7278 BFD_ASSERT (hdr
->contents
== NULL
);
7280 if (hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
7283 (_("%pB: incorrect `.reginfo' section size; "
7284 "expected %" PRIu64
", got %" PRIu64
),
7285 abfd
, (uint64_t) sizeof (Elf32_External_RegInfo
),
7286 (uint64_t) hdr
->sh_size
);
7287 bfd_set_error (bfd_error_bad_value
);
7292 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
7295 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
7296 if (bfd_bwrite (buf
, 4, abfd
) != 4)
7300 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
7301 && hdr
->bfd_section
!= NULL
7302 && mips_elf_section_data (hdr
->bfd_section
) != NULL
7303 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
7305 bfd_byte
*contents
, *l
, *lend
;
7307 /* We stored the section contents in the tdata field in the
7308 set_section_contents routine. We save the section contents
7309 so that we don't have to read them again.
7310 At this point we know that elf_gp is set, so we can look
7311 through the section contents to see if there is an
7312 ODK_REGINFO structure. */
7314 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
7316 lend
= contents
+ hdr
->sh_size
;
7317 while (l
+ sizeof (Elf_External_Options
) <= lend
)
7319 Elf_Internal_Options intopt
;
7321 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
7323 if (intopt
.size
< sizeof (Elf_External_Options
))
7326 /* xgettext:c-format */
7327 (_("%pB: warning: bad `%s' option size %u smaller than"
7329 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
7332 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
7339 + sizeof (Elf_External_Options
)
7340 + (sizeof (Elf64_External_RegInfo
) - 8)),
7343 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
7344 if (bfd_bwrite (buf
, 8, abfd
) != 8)
7347 else if (intopt
.kind
== ODK_REGINFO
)
7354 + sizeof (Elf_External_Options
)
7355 + (sizeof (Elf32_External_RegInfo
) - 4)),
7358 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
7359 if (bfd_bwrite (buf
, 4, abfd
) != 4)
7366 if (hdr
->bfd_section
!= NULL
)
7368 const char *name
= bfd_section_name (hdr
->bfd_section
);
7370 /* .sbss is not handled specially here because the GNU/Linux
7371 prelinker can convert .sbss from NOBITS to PROGBITS and
7372 changing it back to NOBITS breaks the binary. The entry in
7373 _bfd_mips_elf_special_sections will ensure the correct flags
7374 are set on .sbss if BFD creates it without reading it from an
7375 input file, and without special handling here the flags set
7376 on it in an input file will be followed. */
7377 if (strcmp (name
, ".sdata") == 0
7378 || strcmp (name
, ".lit8") == 0
7379 || strcmp (name
, ".lit4") == 0)
7380 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
7381 else if (strcmp (name
, ".srdata") == 0)
7382 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
7383 else if (strcmp (name
, ".compact_rel") == 0)
7385 else if (strcmp (name
, ".rtproc") == 0)
7387 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
7389 unsigned int adjust
;
7391 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
7393 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
7401 /* Handle a MIPS specific section when reading an object file. This
7402 is called when elfcode.h finds a section with an unknown type.
7403 This routine supports both the 32-bit and 64-bit ELF ABI. */
7406 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
7407 Elf_Internal_Shdr
*hdr
,
7413 /* There ought to be a place to keep ELF backend specific flags, but
7414 at the moment there isn't one. We just keep track of the
7415 sections by their name, instead. Fortunately, the ABI gives
7416 suggested names for all the MIPS specific sections, so we will
7417 probably get away with this. */
7418 switch (hdr
->sh_type
)
7420 case SHT_MIPS_LIBLIST
:
7421 if (strcmp (name
, ".liblist") != 0)
7425 if (strcmp (name
, ".msym") != 0)
7428 case SHT_MIPS_CONFLICT
:
7429 if (strcmp (name
, ".conflict") != 0)
7432 case SHT_MIPS_GPTAB
:
7433 if (! CONST_STRNEQ (name
, ".gptab."))
7436 case SHT_MIPS_UCODE
:
7437 if (strcmp (name
, ".ucode") != 0)
7440 case SHT_MIPS_DEBUG
:
7441 if (strcmp (name
, ".mdebug") != 0)
7443 flags
= SEC_DEBUGGING
;
7445 case SHT_MIPS_REGINFO
:
7446 if (strcmp (name
, ".reginfo") != 0
7447 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
7449 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
7451 case SHT_MIPS_IFACE
:
7452 if (strcmp (name
, ".MIPS.interfaces") != 0)
7455 case SHT_MIPS_CONTENT
:
7456 if (! CONST_STRNEQ (name
, ".MIPS.content"))
7459 case SHT_MIPS_OPTIONS
:
7460 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
7463 case SHT_MIPS_ABIFLAGS
:
7464 if (!MIPS_ELF_ABIFLAGS_SECTION_NAME_P (name
))
7466 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
7468 case SHT_MIPS_DWARF
:
7469 if (! CONST_STRNEQ (name
, ".debug_")
7470 && ! CONST_STRNEQ (name
, ".zdebug_"))
7473 case SHT_MIPS_SYMBOL_LIB
:
7474 if (strcmp (name
, ".MIPS.symlib") != 0)
7477 case SHT_MIPS_EVENTS
:
7478 if (! CONST_STRNEQ (name
, ".MIPS.events")
7479 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
7482 case SHT_MIPS_XHASH
:
7483 if (strcmp (name
, ".MIPS.xhash") != 0)
7489 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7492 if (hdr
->sh_flags
& SHF_MIPS_GPREL
)
7493 flags
|= SEC_SMALL_DATA
;
7497 if (!bfd_set_section_flags (hdr
->bfd_section
,
7498 (bfd_section_flags (hdr
->bfd_section
)
7503 if (hdr
->sh_type
== SHT_MIPS_ABIFLAGS
)
7505 Elf_External_ABIFlags_v0 ext
;
7507 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
7508 &ext
, 0, sizeof ext
))
7510 bfd_mips_elf_swap_abiflags_v0_in (abfd
, &ext
,
7511 &mips_elf_tdata (abfd
)->abiflags
);
7512 if (mips_elf_tdata (abfd
)->abiflags
.version
!= 0)
7514 mips_elf_tdata (abfd
)->abiflags_valid
= TRUE
;
7517 /* FIXME: We should record sh_info for a .gptab section. */
7519 /* For a .reginfo section, set the gp value in the tdata information
7520 from the contents of this section. We need the gp value while
7521 processing relocs, so we just get it now. The .reginfo section
7522 is not used in the 64-bit MIPS ELF ABI. */
7523 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
7525 Elf32_External_RegInfo ext
;
7528 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
7529 &ext
, 0, sizeof ext
))
7531 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
7532 elf_gp (abfd
) = s
.ri_gp_value
;
7535 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
7536 set the gp value based on what we find. We may see both
7537 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
7538 they should agree. */
7539 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
7541 bfd_byte
*contents
, *l
, *lend
;
7543 contents
= bfd_malloc (hdr
->sh_size
);
7544 if (contents
== NULL
)
7546 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
7553 lend
= contents
+ hdr
->sh_size
;
7554 while (l
+ sizeof (Elf_External_Options
) <= lend
)
7556 Elf_Internal_Options intopt
;
7558 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
7560 if (intopt
.size
< sizeof (Elf_External_Options
))
7563 /* xgettext:c-format */
7564 (_("%pB: warning: bad `%s' option size %u smaller than"
7566 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
7569 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
7571 Elf64_Internal_RegInfo intreg
;
7573 bfd_mips_elf64_swap_reginfo_in
7575 ((Elf64_External_RegInfo
*)
7576 (l
+ sizeof (Elf_External_Options
))),
7578 elf_gp (abfd
) = intreg
.ri_gp_value
;
7580 else if (intopt
.kind
== ODK_REGINFO
)
7582 Elf32_RegInfo intreg
;
7584 bfd_mips_elf32_swap_reginfo_in
7586 ((Elf32_External_RegInfo
*)
7587 (l
+ sizeof (Elf_External_Options
))),
7589 elf_gp (abfd
) = intreg
.ri_gp_value
;
7599 /* Set the correct type for a MIPS ELF section. We do this by the
7600 section name, which is a hack, but ought to work. This routine is
7601 used by both the 32-bit and the 64-bit ABI. */
7604 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
7606 const char *name
= bfd_section_name (sec
);
7608 if (strcmp (name
, ".liblist") == 0)
7610 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
7611 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
7612 /* The sh_link field is set in final_write_processing. */
7614 else if (strcmp (name
, ".conflict") == 0)
7615 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
7616 else if (CONST_STRNEQ (name
, ".gptab."))
7618 hdr
->sh_type
= SHT_MIPS_GPTAB
;
7619 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
7620 /* The sh_info field is set in final_write_processing. */
7622 else if (strcmp (name
, ".ucode") == 0)
7623 hdr
->sh_type
= SHT_MIPS_UCODE
;
7624 else if (strcmp (name
, ".mdebug") == 0)
7626 hdr
->sh_type
= SHT_MIPS_DEBUG
;
7627 /* In a shared object on IRIX 5.3, the .mdebug section has an
7628 entsize of 0. FIXME: Does this matter? */
7629 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
7630 hdr
->sh_entsize
= 0;
7632 hdr
->sh_entsize
= 1;
7634 else if (strcmp (name
, ".reginfo") == 0)
7636 hdr
->sh_type
= SHT_MIPS_REGINFO
;
7637 /* In a shared object on IRIX 5.3, the .reginfo section has an
7638 entsize of 0x18. FIXME: Does this matter? */
7639 if (SGI_COMPAT (abfd
))
7641 if ((abfd
->flags
& DYNAMIC
) != 0)
7642 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
7644 hdr
->sh_entsize
= 1;
7647 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
7649 else if (SGI_COMPAT (abfd
)
7650 && (strcmp (name
, ".hash") == 0
7651 || strcmp (name
, ".dynamic") == 0
7652 || strcmp (name
, ".dynstr") == 0))
7654 if (SGI_COMPAT (abfd
))
7655 hdr
->sh_entsize
= 0;
7657 /* This isn't how the IRIX6 linker behaves. */
7658 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7661 else if (strcmp (name
, ".got") == 0
7662 || strcmp (name
, ".srdata") == 0
7663 || strcmp (name
, ".sdata") == 0
7664 || strcmp (name
, ".sbss") == 0
7665 || strcmp (name
, ".lit4") == 0
7666 || strcmp (name
, ".lit8") == 0)
7667 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
7668 else if (strcmp (name
, ".MIPS.interfaces") == 0)
7670 hdr
->sh_type
= SHT_MIPS_IFACE
;
7671 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7673 else if (CONST_STRNEQ (name
, ".MIPS.content"))
7675 hdr
->sh_type
= SHT_MIPS_CONTENT
;
7676 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7677 /* The sh_info field is set in final_write_processing. */
7679 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
7681 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
7682 hdr
->sh_entsize
= 1;
7683 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7685 else if (CONST_STRNEQ (name
, ".MIPS.abiflags"))
7687 hdr
->sh_type
= SHT_MIPS_ABIFLAGS
;
7688 hdr
->sh_entsize
= sizeof (Elf_External_ABIFlags_v0
);
7690 else if (CONST_STRNEQ (name
, ".debug_")
7691 || CONST_STRNEQ (name
, ".zdebug_"))
7693 hdr
->sh_type
= SHT_MIPS_DWARF
;
7695 /* Irix facilities such as libexc expect a single .debug_frame
7696 per executable, the system ones have NOSTRIP set and the linker
7697 doesn't merge sections with different flags so ... */
7698 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
7699 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7701 else if (strcmp (name
, ".MIPS.symlib") == 0)
7703 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
7704 /* The sh_link and sh_info fields are set in
7705 final_write_processing. */
7707 else if (CONST_STRNEQ (name
, ".MIPS.events")
7708 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
7710 hdr
->sh_type
= SHT_MIPS_EVENTS
;
7711 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7712 /* The sh_link field is set in final_write_processing. */
7714 else if (strcmp (name
, ".msym") == 0)
7716 hdr
->sh_type
= SHT_MIPS_MSYM
;
7717 hdr
->sh_flags
|= SHF_ALLOC
;
7718 hdr
->sh_entsize
= 8;
7720 else if (strcmp (name
, ".MIPS.xhash") == 0)
7722 hdr
->sh_type
= SHT_MIPS_XHASH
;
7723 hdr
->sh_flags
|= SHF_ALLOC
;
7724 hdr
->sh_entsize
= get_elf_backend_data(abfd
)->s
->arch_size
== 64 ? 0 : 4;
7727 /* The generic elf_fake_sections will set up REL_HDR using the default
7728 kind of relocations. We used to set up a second header for the
7729 non-default kind of relocations here, but only NewABI would use
7730 these, and the IRIX ld doesn't like resulting empty RELA sections.
7731 Thus we create those header only on demand now. */
7736 /* Given a BFD section, try to locate the corresponding ELF section
7737 index. This is used by both the 32-bit and the 64-bit ABI.
7738 Actually, it's not clear to me that the 64-bit ABI supports these,
7739 but for non-PIC objects we will certainly want support for at least
7740 the .scommon section. */
7743 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
7744 asection
*sec
, int *retval
)
7746 if (strcmp (bfd_section_name (sec
), ".scommon") == 0)
7748 *retval
= SHN_MIPS_SCOMMON
;
7751 if (strcmp (bfd_section_name (sec
), ".acommon") == 0)
7753 *retval
= SHN_MIPS_ACOMMON
;
7759 /* Hook called by the linker routine which adds symbols from an object
7760 file. We must handle the special MIPS section numbers here. */
7763 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
7764 Elf_Internal_Sym
*sym
, const char **namep
,
7765 flagword
*flagsp ATTRIBUTE_UNUSED
,
7766 asection
**secp
, bfd_vma
*valp
)
7768 if (SGI_COMPAT (abfd
)
7769 && (abfd
->flags
& DYNAMIC
) != 0
7770 && strcmp (*namep
, "_rld_new_interface") == 0)
7772 /* Skip IRIX5 rld entry name. */
7777 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
7778 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
7779 by setting a DT_NEEDED for the shared object. Since _gp_disp is
7780 a magic symbol resolved by the linker, we ignore this bogus definition
7781 of _gp_disp. New ABI objects do not suffer from this problem so this
7782 is not done for them. */
7784 && (sym
->st_shndx
== SHN_ABS
)
7785 && (strcmp (*namep
, "_gp_disp") == 0))
7791 switch (sym
->st_shndx
)
7794 /* Common symbols less than the GP size are automatically
7795 treated as SHN_MIPS_SCOMMON symbols. */
7796 if (sym
->st_size
> elf_gp_size (abfd
)
7797 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
7798 || IRIX_COMPAT (abfd
) == ict_irix6
)
7801 case SHN_MIPS_SCOMMON
:
7802 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
7803 (*secp
)->flags
|= SEC_IS_COMMON
| SEC_SMALL_DATA
;
7804 *valp
= sym
->st_size
;
7808 /* This section is used in a shared object. */
7809 if (mips_elf_tdata (abfd
)->elf_text_section
== NULL
)
7811 asymbol
*elf_text_symbol
;
7812 asection
*elf_text_section
;
7813 size_t amt
= sizeof (asection
);
7815 elf_text_section
= bfd_zalloc (abfd
, amt
);
7816 if (elf_text_section
== NULL
)
7819 amt
= sizeof (asymbol
);
7820 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
7821 if (elf_text_symbol
== NULL
)
7824 /* Initialize the section. */
7826 mips_elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
7827 mips_elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
7829 elf_text_section
->symbol
= elf_text_symbol
;
7830 elf_text_section
->symbol_ptr_ptr
= &mips_elf_tdata (abfd
)->elf_text_symbol
;
7832 elf_text_section
->name
= ".text";
7833 elf_text_section
->flags
= SEC_NO_FLAGS
;
7834 elf_text_section
->output_section
= NULL
;
7835 elf_text_section
->owner
= abfd
;
7836 elf_text_symbol
->name
= ".text";
7837 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
7838 elf_text_symbol
->section
= elf_text_section
;
7840 /* This code used to do *secp = bfd_und_section_ptr if
7841 bfd_link_pic (info). I don't know why, and that doesn't make sense,
7842 so I took it out. */
7843 *secp
= mips_elf_tdata (abfd
)->elf_text_section
;
7846 case SHN_MIPS_ACOMMON
:
7847 /* Fall through. XXX Can we treat this as allocated data? */
7849 /* This section is used in a shared object. */
7850 if (mips_elf_tdata (abfd
)->elf_data_section
== NULL
)
7852 asymbol
*elf_data_symbol
;
7853 asection
*elf_data_section
;
7854 size_t amt
= sizeof (asection
);
7856 elf_data_section
= bfd_zalloc (abfd
, amt
);
7857 if (elf_data_section
== NULL
)
7860 amt
= sizeof (asymbol
);
7861 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
7862 if (elf_data_symbol
== NULL
)
7865 /* Initialize the section. */
7867 mips_elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
7868 mips_elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
7870 elf_data_section
->symbol
= elf_data_symbol
;
7871 elf_data_section
->symbol_ptr_ptr
= &mips_elf_tdata (abfd
)->elf_data_symbol
;
7873 elf_data_section
->name
= ".data";
7874 elf_data_section
->flags
= SEC_NO_FLAGS
;
7875 elf_data_section
->output_section
= NULL
;
7876 elf_data_section
->owner
= abfd
;
7877 elf_data_symbol
->name
= ".data";
7878 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
7879 elf_data_symbol
->section
= elf_data_section
;
7881 /* This code used to do *secp = bfd_und_section_ptr if
7882 bfd_link_pic (info). I don't know why, and that doesn't make sense,
7883 so I took it out. */
7884 *secp
= mips_elf_tdata (abfd
)->elf_data_section
;
7887 case SHN_MIPS_SUNDEFINED
:
7888 *secp
= bfd_und_section_ptr
;
7892 if (SGI_COMPAT (abfd
)
7893 && ! bfd_link_pic (info
)
7894 && info
->output_bfd
->xvec
== abfd
->xvec
7895 && strcmp (*namep
, "__rld_obj_head") == 0)
7897 struct elf_link_hash_entry
*h
;
7898 struct bfd_link_hash_entry
*bh
;
7900 /* Mark __rld_obj_head as dynamic. */
7902 if (! (_bfd_generic_link_add_one_symbol
7903 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
7904 get_elf_backend_data (abfd
)->collect
, &bh
)))
7907 h
= (struct elf_link_hash_entry
*) bh
;
7910 h
->type
= STT_OBJECT
;
7912 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7915 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
7916 mips_elf_hash_table (info
)->rld_symbol
= h
;
7919 /* If this is a mips16 text symbol, add 1 to the value to make it
7920 odd. This will cause something like .word SYM to come up with
7921 the right value when it is loaded into the PC. */
7922 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
7928 /* This hook function is called before the linker writes out a global
7929 symbol. We mark symbols as small common if appropriate. This is
7930 also where we undo the increment of the value for a mips16 symbol. */
7933 _bfd_mips_elf_link_output_symbol_hook
7934 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7935 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
7936 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
7938 /* If we see a common symbol, which implies a relocatable link, then
7939 if a symbol was small common in an input file, mark it as small
7940 common in the output file. */
7941 if (sym
->st_shndx
== SHN_COMMON
7942 && strcmp (input_sec
->name
, ".scommon") == 0)
7943 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
7945 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
7946 sym
->st_value
&= ~1;
7951 /* Functions for the dynamic linker. */
7953 /* Create dynamic sections when linking against a dynamic object. */
7956 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
7958 struct elf_link_hash_entry
*h
;
7959 struct bfd_link_hash_entry
*bh
;
7961 register asection
*s
;
7962 const char * const *namep
;
7963 struct mips_elf_link_hash_table
*htab
;
7965 htab
= mips_elf_hash_table (info
);
7966 BFD_ASSERT (htab
!= NULL
);
7968 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7969 | SEC_LINKER_CREATED
| SEC_READONLY
);
7971 /* The psABI requires a read-only .dynamic section, but the VxWorks
7973 if (htab
->root
.target_os
!= is_vxworks
)
7975 s
= bfd_get_linker_section (abfd
, ".dynamic");
7978 if (!bfd_set_section_flags (s
, flags
))
7983 /* We need to create .got section. */
7984 if (!mips_elf_create_got_section (abfd
, info
))
7987 if (! mips_elf_rel_dyn_section (info
, TRUE
))
7990 /* Create .stub section. */
7991 s
= bfd_make_section_anyway_with_flags (abfd
,
7992 MIPS_ELF_STUB_SECTION_NAME (abfd
),
7995 || !bfd_set_section_alignment (s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7999 if (!mips_elf_hash_table (info
)->use_rld_obj_head
8000 && bfd_link_executable (info
)
8001 && bfd_get_linker_section (abfd
, ".rld_map") == NULL
)
8003 s
= bfd_make_section_anyway_with_flags (abfd
, ".rld_map",
8004 flags
&~ (flagword
) SEC_READONLY
);
8006 || !bfd_set_section_alignment (s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
8010 /* Create .MIPS.xhash section. */
8011 if (info
->emit_gnu_hash
)
8012 s
= bfd_make_section_anyway_with_flags (abfd
, ".MIPS.xhash",
8013 flags
| SEC_READONLY
);
8015 /* On IRIX5, we adjust add some additional symbols and change the
8016 alignments of several sections. There is no ABI documentation
8017 indicating that this is necessary on IRIX6, nor any evidence that
8018 the linker takes such action. */
8019 if (IRIX_COMPAT (abfd
) == ict_irix5
)
8021 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
8024 if (! (_bfd_generic_link_add_one_symbol
8025 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
8026 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
8029 h
= (struct elf_link_hash_entry
*) bh
;
8033 h
->type
= STT_SECTION
;
8035 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8039 /* We need to create a .compact_rel section. */
8040 if (SGI_COMPAT (abfd
))
8042 if (!mips_elf_create_compact_rel_section (abfd
, info
))
8046 /* Change alignments of some sections. */
8047 s
= bfd_get_linker_section (abfd
, ".hash");
8049 bfd_set_section_alignment (s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
8051 s
= bfd_get_linker_section (abfd
, ".dynsym");
8053 bfd_set_section_alignment (s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
8055 s
= bfd_get_linker_section (abfd
, ".dynstr");
8057 bfd_set_section_alignment (s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
8060 s
= bfd_get_section_by_name (abfd
, ".reginfo");
8062 bfd_set_section_alignment (s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
8064 s
= bfd_get_linker_section (abfd
, ".dynamic");
8066 bfd_set_section_alignment (s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
8069 if (bfd_link_executable (info
))
8073 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
8075 if (!(_bfd_generic_link_add_one_symbol
8076 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
8077 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
8080 h
= (struct elf_link_hash_entry
*) bh
;
8083 h
->type
= STT_SECTION
;
8085 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8088 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
8090 /* __rld_map is a four byte word located in the .data section
8091 and is filled in by the rtld to contain a pointer to
8092 the _r_debug structure. Its symbol value will be set in
8093 _bfd_mips_elf_finish_dynamic_symbol. */
8094 s
= bfd_get_linker_section (abfd
, ".rld_map");
8095 BFD_ASSERT (s
!= NULL
);
8097 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
8099 if (!(_bfd_generic_link_add_one_symbol
8100 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
8101 get_elf_backend_data (abfd
)->collect
, &bh
)))
8104 h
= (struct elf_link_hash_entry
*) bh
;
8107 h
->type
= STT_OBJECT
;
8109 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8111 mips_elf_hash_table (info
)->rld_symbol
= h
;
8115 /* Create the .plt, .rel(a).plt, .dynbss and .rel(a).bss sections.
8116 Also, on VxWorks, create the _PROCEDURE_LINKAGE_TABLE_ symbol. */
8117 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
8120 /* Do the usual VxWorks handling. */
8121 if (htab
->root
.target_os
== is_vxworks
8122 && !elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
8128 /* Return true if relocation REL against section SEC is a REL rather than
8129 RELA relocation. RELOCS is the first relocation in the section and
8130 ABFD is the bfd that contains SEC. */
8133 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
8134 const Elf_Internal_Rela
*relocs
,
8135 const Elf_Internal_Rela
*rel
)
8137 Elf_Internal_Shdr
*rel_hdr
;
8138 const struct elf_backend_data
*bed
;
8140 /* To determine which flavor of relocation this is, we depend on the
8141 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
8142 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
8143 if (rel_hdr
== NULL
)
8145 bed
= get_elf_backend_data (abfd
);
8146 return ((size_t) (rel
- relocs
)
8147 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
8150 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
8151 HOWTO is the relocation's howto and CONTENTS points to the contents
8152 of the section that REL is against. */
8155 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
8156 reloc_howto_type
*howto
, bfd_byte
*contents
)
8159 unsigned int r_type
;
8163 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
8164 location
= contents
+ rel
->r_offset
;
8166 /* Get the addend, which is stored in the input file. */
8167 _bfd_mips_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
8168 bytes
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
8169 _bfd_mips_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
8171 addend
= bytes
& howto
->src_mask
;
8173 /* Shift is 2, unusually, for microMIPS JALX. Adjust the addend
8175 if (r_type
== R_MICROMIPS_26_S1
&& (bytes
>> 26) == 0x3c)
8181 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
8182 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
8183 and update *ADDEND with the final addend. Return true on success
8184 or false if the LO16 could not be found. RELEND is the exclusive
8185 upper bound on the relocations for REL's section. */
8188 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
8189 const Elf_Internal_Rela
*rel
,
8190 const Elf_Internal_Rela
*relend
,
8191 bfd_byte
*contents
, bfd_vma
*addend
)
8193 unsigned int r_type
, lo16_type
;
8194 const Elf_Internal_Rela
*lo16_relocation
;
8195 reloc_howto_type
*lo16_howto
;
8198 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
8199 if (mips16_reloc_p (r_type
))
8200 lo16_type
= R_MIPS16_LO16
;
8201 else if (micromips_reloc_p (r_type
))
8202 lo16_type
= R_MICROMIPS_LO16
;
8203 else if (r_type
== R_MIPS_PCHI16
)
8204 lo16_type
= R_MIPS_PCLO16
;
8206 lo16_type
= R_MIPS_LO16
;
8208 /* The combined value is the sum of the HI16 addend, left-shifted by
8209 sixteen bits, and the LO16 addend, sign extended. (Usually, the
8210 code does a `lui' of the HI16 value, and then an `addiu' of the
8213 Scan ahead to find a matching LO16 relocation.
8215 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
8216 be immediately following. However, for the IRIX6 ABI, the next
8217 relocation may be a composed relocation consisting of several
8218 relocations for the same address. In that case, the R_MIPS_LO16
8219 relocation may occur as one of these. We permit a similar
8220 extension in general, as that is useful for GCC.
8222 In some cases GCC dead code elimination removes the LO16 but keeps
8223 the corresponding HI16. This is strictly speaking a violation of
8224 the ABI but not immediately harmful. */
8225 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
8226 if (lo16_relocation
== NULL
)
8229 /* Obtain the addend kept there. */
8230 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
8231 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
8233 l
<<= lo16_howto
->rightshift
;
8234 l
= _bfd_mips_elf_sign_extend (l
, 16);
8241 /* Try to read the contents of section SEC in bfd ABFD. Return true and
8242 store the contents in *CONTENTS on success. Assume that *CONTENTS
8243 already holds the contents if it is nonull on entry. */
8246 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
8251 /* Get cached copy if it exists. */
8252 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
8254 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
8258 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
8261 /* Make a new PLT record to keep internal data. */
8263 static struct plt_entry
*
8264 mips_elf_make_plt_record (bfd
*abfd
)
8266 struct plt_entry
*entry
;
8268 entry
= bfd_zalloc (abfd
, sizeof (*entry
));
8272 entry
->stub_offset
= MINUS_ONE
;
8273 entry
->mips_offset
= MINUS_ONE
;
8274 entry
->comp_offset
= MINUS_ONE
;
8275 entry
->gotplt_index
= MINUS_ONE
;
8279 /* Define the special `__gnu_absolute_zero' symbol. We only need this
8280 for PIC code, as otherwise there is no load-time relocation involved
8281 and local GOT entries whose value is zero at static link time will
8282 retain their value at load time. */
8285 mips_elf_define_absolute_zero (bfd
*abfd
, struct bfd_link_info
*info
,
8286 struct mips_elf_link_hash_table
*htab
,
8287 unsigned int r_type
)
8291 struct elf_link_hash_entry
*eh
;
8292 struct bfd_link_hash_entry
*bh
;
8296 BFD_ASSERT (!htab
->use_absolute_zero
);
8297 BFD_ASSERT (bfd_link_pic (info
));
8300 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, "__gnu_absolute_zero",
8301 BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
8302 NULL
, FALSE
, FALSE
, &hzero
.bh
))
8305 BFD_ASSERT (hzero
.bh
!= NULL
);
8307 hzero
.eh
->type
= STT_NOTYPE
;
8308 hzero
.eh
->other
= STV_PROTECTED
;
8309 hzero
.eh
->def_regular
= 1;
8310 hzero
.eh
->non_elf
= 0;
8312 if (!mips_elf_record_global_got_symbol (hzero
.eh
, abfd
, info
, TRUE
, r_type
))
8315 htab
->use_absolute_zero
= TRUE
;
8320 /* Look through the relocs for a section during the first phase, and
8321 allocate space in the global offset table and record the need for
8322 standard MIPS and compressed procedure linkage table entries. */
8325 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
8326 asection
*sec
, const Elf_Internal_Rela
*relocs
)
8330 Elf_Internal_Shdr
*symtab_hdr
;
8331 struct elf_link_hash_entry
**sym_hashes
;
8333 const Elf_Internal_Rela
*rel
;
8334 const Elf_Internal_Rela
*rel_end
;
8336 const struct elf_backend_data
*bed
;
8337 struct mips_elf_link_hash_table
*htab
;
8340 reloc_howto_type
*howto
;
8342 if (bfd_link_relocatable (info
))
8345 htab
= mips_elf_hash_table (info
);
8346 BFD_ASSERT (htab
!= NULL
);
8348 dynobj
= elf_hash_table (info
)->dynobj
;
8349 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8350 sym_hashes
= elf_sym_hashes (abfd
);
8351 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
8353 bed
= get_elf_backend_data (abfd
);
8354 rel_end
= relocs
+ sec
->reloc_count
;
8356 /* Check for the mips16 stub sections. */
8358 name
= bfd_section_name (sec
);
8359 if (FN_STUB_P (name
))
8361 unsigned long r_symndx
;
8363 /* Look at the relocation information to figure out which symbol
8366 r_symndx
= mips16_stub_symndx (bed
, sec
, relocs
, rel_end
);
8370 /* xgettext:c-format */
8371 (_("%pB: warning: cannot determine the target function for"
8372 " stub section `%s'"),
8374 bfd_set_error (bfd_error_bad_value
);
8378 if (r_symndx
< extsymoff
8379 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
8383 /* This stub is for a local symbol. This stub will only be
8384 needed if there is some relocation in this BFD, other
8385 than a 16 bit function call, which refers to this symbol. */
8386 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
8388 Elf_Internal_Rela
*sec_relocs
;
8389 const Elf_Internal_Rela
*r
, *rend
;
8391 /* We can ignore stub sections when looking for relocs. */
8392 if ((o
->flags
& SEC_RELOC
) == 0
8393 || o
->reloc_count
== 0
8394 || section_allows_mips16_refs_p (o
))
8398 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
8400 if (sec_relocs
== NULL
)
8403 rend
= sec_relocs
+ o
->reloc_count
;
8404 for (r
= sec_relocs
; r
< rend
; r
++)
8405 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
8406 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
8409 if (elf_section_data (o
)->relocs
!= sec_relocs
)
8418 /* There is no non-call reloc for this stub, so we do
8419 not need it. Since this function is called before
8420 the linker maps input sections to output sections, we
8421 can easily discard it by setting the SEC_EXCLUDE
8423 sec
->flags
|= SEC_EXCLUDE
;
8427 /* Record this stub in an array of local symbol stubs for
8429 if (mips_elf_tdata (abfd
)->local_stubs
== NULL
)
8431 unsigned long symcount
;
8435 if (elf_bad_symtab (abfd
))
8436 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
8438 symcount
= symtab_hdr
->sh_info
;
8439 amt
= symcount
* sizeof (asection
*);
8440 n
= bfd_zalloc (abfd
, amt
);
8443 mips_elf_tdata (abfd
)->local_stubs
= n
;
8446 sec
->flags
|= SEC_KEEP
;
8447 mips_elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
8449 /* We don't need to set mips16_stubs_seen in this case.
8450 That flag is used to see whether we need to look through
8451 the global symbol table for stubs. We don't need to set
8452 it here, because we just have a local stub. */
8456 struct mips_elf_link_hash_entry
*h
;
8458 h
= ((struct mips_elf_link_hash_entry
*)
8459 sym_hashes
[r_symndx
- extsymoff
]);
8461 while (h
->root
.root
.type
== bfd_link_hash_indirect
8462 || h
->root
.root
.type
== bfd_link_hash_warning
)
8463 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
8465 /* H is the symbol this stub is for. */
8467 /* If we already have an appropriate stub for this function, we
8468 don't need another one, so we can discard this one. Since
8469 this function is called before the linker maps input sections
8470 to output sections, we can easily discard it by setting the
8471 SEC_EXCLUDE flag. */
8472 if (h
->fn_stub
!= NULL
)
8474 sec
->flags
|= SEC_EXCLUDE
;
8478 sec
->flags
|= SEC_KEEP
;
8480 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
8483 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
8485 unsigned long r_symndx
;
8486 struct mips_elf_link_hash_entry
*h
;
8489 /* Look at the relocation information to figure out which symbol
8492 r_symndx
= mips16_stub_symndx (bed
, sec
, relocs
, rel_end
);
8496 /* xgettext:c-format */
8497 (_("%pB: warning: cannot determine the target function for"
8498 " stub section `%s'"),
8500 bfd_set_error (bfd_error_bad_value
);
8504 if (r_symndx
< extsymoff
8505 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
8509 /* This stub is for a local symbol. This stub will only be
8510 needed if there is some relocation (R_MIPS16_26) in this BFD
8511 that refers to this symbol. */
8512 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
8514 Elf_Internal_Rela
*sec_relocs
;
8515 const Elf_Internal_Rela
*r
, *rend
;
8517 /* We can ignore stub sections when looking for relocs. */
8518 if ((o
->flags
& SEC_RELOC
) == 0
8519 || o
->reloc_count
== 0
8520 || section_allows_mips16_refs_p (o
))
8524 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
8526 if (sec_relocs
== NULL
)
8529 rend
= sec_relocs
+ o
->reloc_count
;
8530 for (r
= sec_relocs
; r
< rend
; r
++)
8531 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
8532 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
8535 if (elf_section_data (o
)->relocs
!= sec_relocs
)
8544 /* There is no non-call reloc for this stub, so we do
8545 not need it. Since this function is called before
8546 the linker maps input sections to output sections, we
8547 can easily discard it by setting the SEC_EXCLUDE
8549 sec
->flags
|= SEC_EXCLUDE
;
8553 /* Record this stub in an array of local symbol call_stubs for
8555 if (mips_elf_tdata (abfd
)->local_call_stubs
== NULL
)
8557 unsigned long symcount
;
8561 if (elf_bad_symtab (abfd
))
8562 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
8564 symcount
= symtab_hdr
->sh_info
;
8565 amt
= symcount
* sizeof (asection
*);
8566 n
= bfd_zalloc (abfd
, amt
);
8569 mips_elf_tdata (abfd
)->local_call_stubs
= n
;
8572 sec
->flags
|= SEC_KEEP
;
8573 mips_elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
8575 /* We don't need to set mips16_stubs_seen in this case.
8576 That flag is used to see whether we need to look through
8577 the global symbol table for stubs. We don't need to set
8578 it here, because we just have a local stub. */
8582 h
= ((struct mips_elf_link_hash_entry
*)
8583 sym_hashes
[r_symndx
- extsymoff
]);
8585 /* H is the symbol this stub is for. */
8587 if (CALL_FP_STUB_P (name
))
8588 loc
= &h
->call_fp_stub
;
8590 loc
= &h
->call_stub
;
8592 /* If we already have an appropriate stub for this function, we
8593 don't need another one, so we can discard this one. Since
8594 this function is called before the linker maps input sections
8595 to output sections, we can easily discard it by setting the
8596 SEC_EXCLUDE flag. */
8599 sec
->flags
|= SEC_EXCLUDE
;
8603 sec
->flags
|= SEC_KEEP
;
8605 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
8611 for (rel
= relocs
; rel
< rel_end
; ++rel
)
8613 unsigned long r_symndx
;
8614 unsigned int r_type
;
8615 struct elf_link_hash_entry
*h
;
8616 bfd_boolean can_make_dynamic_p
;
8617 bfd_boolean call_reloc_p
;
8618 bfd_boolean constrain_symbol_p
;
8620 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
8621 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
8623 if (r_symndx
< extsymoff
)
8625 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
8628 /* xgettext:c-format */
8629 (_("%pB: malformed reloc detected for section %s"),
8631 bfd_set_error (bfd_error_bad_value
);
8636 h
= sym_hashes
[r_symndx
- extsymoff
];
8639 while (h
->root
.type
== bfd_link_hash_indirect
8640 || h
->root
.type
== bfd_link_hash_warning
)
8641 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8645 /* Set CAN_MAKE_DYNAMIC_P to true if we can convert this
8646 relocation into a dynamic one. */
8647 can_make_dynamic_p
= FALSE
;
8649 /* Set CALL_RELOC_P to true if the relocation is for a call,
8650 and if pointer equality therefore doesn't matter. */
8651 call_reloc_p
= FALSE
;
8653 /* Set CONSTRAIN_SYMBOL_P if we need to take the relocation
8654 into account when deciding how to define the symbol. */
8655 constrain_symbol_p
= TRUE
;
8660 case R_MIPS_CALL_HI16
:
8661 case R_MIPS_CALL_LO16
:
8662 case R_MIPS16_CALL16
:
8663 case R_MICROMIPS_CALL16
:
8664 case R_MICROMIPS_CALL_HI16
:
8665 case R_MICROMIPS_CALL_LO16
:
8666 call_reloc_p
= TRUE
;
8670 case R_MIPS_GOT_LO16
:
8671 case R_MIPS_GOT_PAGE
:
8672 case R_MIPS_GOT_DISP
:
8673 case R_MIPS16_GOT16
:
8674 case R_MICROMIPS_GOT16
:
8675 case R_MICROMIPS_GOT_LO16
:
8676 case R_MICROMIPS_GOT_PAGE
:
8677 case R_MICROMIPS_GOT_DISP
:
8678 /* If we have a symbol that will resolve to zero at static link
8679 time and it is used by a GOT relocation applied to code we
8680 cannot relax to an immediate zero load, then we will be using
8681 the special `__gnu_absolute_zero' symbol whose value is zero
8682 at dynamic load time. We ignore HI16-type GOT relocations at
8683 this stage, because their handling will depend entirely on
8684 the corresponding LO16-type GOT relocation. */
8685 if (!call_hi16_reloc_p (r_type
)
8687 && bfd_link_pic (info
)
8688 && !htab
->use_absolute_zero
8689 && UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8691 bfd_boolean rel_reloc
;
8693 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
8696 rel_reloc
= mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
);
8697 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, !rel_reloc
);
8699 if (!mips_elf_nullify_got_load (abfd
, contents
, rel
, howto
,
8701 if (!mips_elf_define_absolute_zero (abfd
, info
, htab
, r_type
))
8706 case R_MIPS_GOT_HI16
:
8707 case R_MIPS_GOT_OFST
:
8708 case R_MIPS_TLS_GOTTPREL
:
8710 case R_MIPS_TLS_LDM
:
8711 case R_MIPS16_TLS_GOTTPREL
:
8712 case R_MIPS16_TLS_GD
:
8713 case R_MIPS16_TLS_LDM
:
8714 case R_MICROMIPS_GOT_HI16
:
8715 case R_MICROMIPS_GOT_OFST
:
8716 case R_MICROMIPS_TLS_GOTTPREL
:
8717 case R_MICROMIPS_TLS_GD
:
8718 case R_MICROMIPS_TLS_LDM
:
8720 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
8721 if (!mips_elf_create_got_section (dynobj
, info
))
8723 if (htab
->root
.target_os
== is_vxworks
8724 && !bfd_link_pic (info
))
8727 /* xgettext:c-format */
8728 (_("%pB: GOT reloc at %#" PRIx64
" not expected in executables"),
8729 abfd
, (uint64_t) rel
->r_offset
);
8730 bfd_set_error (bfd_error_bad_value
);
8733 can_make_dynamic_p
= TRUE
;
8738 case R_MICROMIPS_JALR
:
8739 /* These relocations have empty fields and are purely there to
8740 provide link information. The symbol value doesn't matter. */
8741 constrain_symbol_p
= FALSE
;
8744 case R_MIPS_GPREL16
:
8745 case R_MIPS_GPREL32
:
8746 case R_MIPS16_GPREL
:
8747 case R_MICROMIPS_GPREL16
:
8748 /* GP-relative relocations always resolve to a definition in a
8749 regular input file, ignoring the one-definition rule. This is
8750 important for the GP setup sequence in NewABI code, which
8751 always resolves to a local function even if other relocations
8752 against the symbol wouldn't. */
8753 constrain_symbol_p
= FALSE
;
8759 /* In VxWorks executables, references to external symbols
8760 must be handled using copy relocs or PLT entries; it is not
8761 possible to convert this relocation into a dynamic one.
8763 For executables that use PLTs and copy-relocs, we have a
8764 choice between converting the relocation into a dynamic
8765 one or using copy relocations or PLT entries. It is
8766 usually better to do the former, unless the relocation is
8767 against a read-only section. */
8768 if ((bfd_link_pic (info
)
8770 && htab
->root
.target_os
!= is_vxworks
8771 && strcmp (h
->root
.root
.string
, "__gnu_local_gp") != 0
8772 && !(!info
->nocopyreloc
8773 && !PIC_OBJECT_P (abfd
)
8774 && MIPS_ELF_READONLY_SECTION (sec
))))
8775 && (sec
->flags
& SEC_ALLOC
) != 0)
8777 can_make_dynamic_p
= TRUE
;
8779 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
8785 case R_MIPS_PC21_S2
:
8786 case R_MIPS_PC26_S2
:
8788 case R_MIPS16_PC16_S1
:
8789 case R_MICROMIPS_26_S1
:
8790 case R_MICROMIPS_PC7_S1
:
8791 case R_MICROMIPS_PC10_S1
:
8792 case R_MICROMIPS_PC16_S1
:
8793 case R_MICROMIPS_PC23_S2
:
8794 call_reloc_p
= TRUE
;
8800 if (constrain_symbol_p
)
8802 if (!can_make_dynamic_p
)
8803 ((struct mips_elf_link_hash_entry
*) h
)->has_static_relocs
= 1;
8806 h
->pointer_equality_needed
= 1;
8808 /* We must not create a stub for a symbol that has
8809 relocations related to taking the function's address.
8810 This doesn't apply to VxWorks, where CALL relocs refer
8811 to a .got.plt entry instead of a normal .got entry. */
8812 if (htab
->root
.target_os
!= is_vxworks
8813 && (!can_make_dynamic_p
|| !call_reloc_p
))
8814 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
8817 /* Relocations against the special VxWorks __GOTT_BASE__ and
8818 __GOTT_INDEX__ symbols must be left to the loader. Allocate
8819 room for them in .rela.dyn. */
8820 if (is_gott_symbol (info
, h
))
8824 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
8828 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
8829 if (MIPS_ELF_READONLY_SECTION (sec
))
8830 /* We tell the dynamic linker that there are
8831 relocations against the text segment. */
8832 info
->flags
|= DF_TEXTREL
;
8835 else if (call_lo16_reloc_p (r_type
)
8836 || got_lo16_reloc_p (r_type
)
8837 || got_disp_reloc_p (r_type
)
8838 || (got16_reloc_p (r_type
)
8839 && htab
->root
.target_os
== is_vxworks
))
8841 /* We may need a local GOT entry for this relocation. We
8842 don't count R_MIPS_GOT_PAGE because we can estimate the
8843 maximum number of pages needed by looking at the size of
8844 the segment. Similar comments apply to R_MIPS*_GOT16 and
8845 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
8846 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
8847 R_MIPS_CALL_HI16 because these are always followed by an
8848 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
8849 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
8850 rel
->r_addend
, info
, r_type
))
8855 && mips_elf_relocation_needs_la25_stub (abfd
, r_type
,
8856 ELF_ST_IS_MIPS16 (h
->other
)))
8857 ((struct mips_elf_link_hash_entry
*) h
)->has_nonpic_branches
= TRUE
;
8862 case R_MIPS16_CALL16
:
8863 case R_MICROMIPS_CALL16
:
8867 /* xgettext:c-format */
8868 (_("%pB: CALL16 reloc at %#" PRIx64
" not against global symbol"),
8869 abfd
, (uint64_t) rel
->r_offset
);
8870 bfd_set_error (bfd_error_bad_value
);
8875 case R_MIPS_CALL_HI16
:
8876 case R_MIPS_CALL_LO16
:
8877 case R_MICROMIPS_CALL_HI16
:
8878 case R_MICROMIPS_CALL_LO16
:
8881 /* Make sure there is room in the regular GOT to hold the
8882 function's address. We may eliminate it in favour of
8883 a .got.plt entry later; see mips_elf_count_got_symbols. */
8884 if (!mips_elf_record_global_got_symbol (h
, abfd
, info
, TRUE
,
8888 /* We need a stub, not a plt entry for the undefined
8889 function. But we record it as if it needs plt. See
8890 _bfd_elf_adjust_dynamic_symbol. */
8896 case R_MIPS_GOT_PAGE
:
8897 case R_MICROMIPS_GOT_PAGE
:
8898 case R_MIPS16_GOT16
:
8900 case R_MIPS_GOT_HI16
:
8901 case R_MIPS_GOT_LO16
:
8902 case R_MICROMIPS_GOT16
:
8903 case R_MICROMIPS_GOT_HI16
:
8904 case R_MICROMIPS_GOT_LO16
:
8905 if (!h
|| got_page_reloc_p (r_type
))
8907 /* This relocation needs (or may need, if h != NULL) a
8908 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
8909 know for sure until we know whether the symbol is
8911 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
8913 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
8915 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
8916 addend
= mips_elf_read_rel_addend (abfd
, rel
,
8918 if (got16_reloc_p (r_type
))
8919 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
8922 addend
<<= howto
->rightshift
;
8925 addend
= rel
->r_addend
;
8926 if (!mips_elf_record_got_page_ref (info
, abfd
, r_symndx
,
8932 struct mips_elf_link_hash_entry
*hmips
=
8933 (struct mips_elf_link_hash_entry
*) h
;
8935 /* This symbol is definitely not overridable. */
8936 if (hmips
->root
.def_regular
8937 && ! (bfd_link_pic (info
) && ! info
->symbolic
8938 && ! hmips
->root
.forced_local
))
8942 /* If this is a global, overridable symbol, GOT_PAGE will
8943 decay to GOT_DISP, so we'll need a GOT entry for it. */
8946 case R_MIPS_GOT_DISP
:
8947 case R_MICROMIPS_GOT_DISP
:
8948 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
,
8953 case R_MIPS_TLS_GOTTPREL
:
8954 case R_MIPS16_TLS_GOTTPREL
:
8955 case R_MICROMIPS_TLS_GOTTPREL
:
8956 if (bfd_link_pic (info
))
8957 info
->flags
|= DF_STATIC_TLS
;
8960 case R_MIPS_TLS_LDM
:
8961 case R_MIPS16_TLS_LDM
:
8962 case R_MICROMIPS_TLS_LDM
:
8963 if (tls_ldm_reloc_p (r_type
))
8965 r_symndx
= STN_UNDEF
;
8971 case R_MIPS16_TLS_GD
:
8972 case R_MICROMIPS_TLS_GD
:
8973 /* This symbol requires a global offset table entry, or two
8974 for TLS GD relocations. */
8977 if (!mips_elf_record_global_got_symbol (h
, abfd
, info
,
8983 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
8993 /* In VxWorks executables, references to external symbols
8994 are handled using copy relocs or PLT stubs, so there's
8995 no need to add a .rela.dyn entry for this relocation. */
8996 if (can_make_dynamic_p
)
9000 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
9004 if (bfd_link_pic (info
) && h
== NULL
)
9006 /* When creating a shared object, we must copy these
9007 reloc types into the output file as R_MIPS_REL32
9008 relocs. Make room for this reloc in .rel(a).dyn. */
9009 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
9010 if (MIPS_ELF_READONLY_SECTION (sec
))
9011 /* We tell the dynamic linker that there are
9012 relocations against the text segment. */
9013 info
->flags
|= DF_TEXTREL
;
9017 struct mips_elf_link_hash_entry
*hmips
;
9019 /* For a shared object, we must copy this relocation
9020 unless the symbol turns out to be undefined and
9021 weak with non-default visibility, in which case
9022 it will be left as zero.
9024 We could elide R_MIPS_REL32 for locally binding symbols
9025 in shared libraries, but do not yet do so.
9027 For an executable, we only need to copy this
9028 reloc if the symbol is defined in a dynamic
9030 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9031 ++hmips
->possibly_dynamic_relocs
;
9032 if (MIPS_ELF_READONLY_SECTION (sec
))
9033 /* We need it to tell the dynamic linker if there
9034 are relocations against the text segment. */
9035 hmips
->readonly_reloc
= TRUE
;
9039 if (SGI_COMPAT (abfd
))
9040 mips_elf_hash_table (info
)->compact_rel_size
+=
9041 sizeof (Elf32_External_crinfo
);
9045 case R_MIPS_GPREL16
:
9046 case R_MIPS_LITERAL
:
9047 case R_MIPS_GPREL32
:
9048 case R_MICROMIPS_26_S1
:
9049 case R_MICROMIPS_GPREL16
:
9050 case R_MICROMIPS_LITERAL
:
9051 case R_MICROMIPS_GPREL7_S2
:
9052 if (SGI_COMPAT (abfd
))
9053 mips_elf_hash_table (info
)->compact_rel_size
+=
9054 sizeof (Elf32_External_crinfo
);
9057 /* This relocation describes the C++ object vtable hierarchy.
9058 Reconstruct it for later use during GC. */
9059 case R_MIPS_GNU_VTINHERIT
:
9060 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
9064 /* This relocation describes which C++ vtable entries are actually
9065 used. Record for later use during GC. */
9066 case R_MIPS_GNU_VTENTRY
:
9067 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
9075 /* Record the need for a PLT entry. At this point we don't know
9076 yet if we are going to create a PLT in the first place, but
9077 we only record whether the relocation requires a standard MIPS
9078 or a compressed code entry anyway. If we don't make a PLT after
9079 all, then we'll just ignore these arrangements. Likewise if
9080 a PLT entry is not created because the symbol is satisfied
9083 && (branch_reloc_p (r_type
)
9084 || mips16_branch_reloc_p (r_type
)
9085 || micromips_branch_reloc_p (r_type
))
9086 && !SYMBOL_CALLS_LOCAL (info
, h
))
9088 if (h
->plt
.plist
== NULL
)
9089 h
->plt
.plist
= mips_elf_make_plt_record (abfd
);
9090 if (h
->plt
.plist
== NULL
)
9093 if (branch_reloc_p (r_type
))
9094 h
->plt
.plist
->need_mips
= TRUE
;
9096 h
->plt
.plist
->need_comp
= TRUE
;
9099 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
9100 if there is one. We only need to handle global symbols here;
9101 we decide whether to keep or delete stubs for local symbols
9102 when processing the stub's relocations. */
9104 && !mips16_call_reloc_p (r_type
)
9105 && !section_allows_mips16_refs_p (sec
))
9107 struct mips_elf_link_hash_entry
*mh
;
9109 mh
= (struct mips_elf_link_hash_entry
*) h
;
9110 mh
->need_fn_stub
= TRUE
;
9113 /* Refuse some position-dependent relocations when creating a
9114 shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
9115 not PIC, but we can create dynamic relocations and the result
9116 will be fine. Also do not refuse R_MIPS_LO16, which can be
9117 combined with R_MIPS_GOT16. */
9118 if (bfd_link_pic (info
))
9122 case R_MIPS_TLS_TPREL_HI16
:
9123 case R_MIPS16_TLS_TPREL_HI16
:
9124 case R_MICROMIPS_TLS_TPREL_HI16
:
9125 case R_MIPS_TLS_TPREL_LO16
:
9126 case R_MIPS16_TLS_TPREL_LO16
:
9127 case R_MICROMIPS_TLS_TPREL_LO16
:
9128 /* These are okay in PIE, but not in a shared library. */
9129 if (bfd_link_executable (info
))
9137 case R_MIPS_HIGHEST
:
9138 case R_MICROMIPS_HI16
:
9139 case R_MICROMIPS_HIGHER
:
9140 case R_MICROMIPS_HIGHEST
:
9141 /* Don't refuse a high part relocation if it's against
9142 no symbol (e.g. part of a compound relocation). */
9143 if (r_symndx
== STN_UNDEF
)
9146 /* Likewise an absolute symbol. */
9147 if (h
!= NULL
&& bfd_is_abs_symbol (&h
->root
))
9150 /* R_MIPS_HI16 against _gp_disp is used for $gp setup,
9151 and has a special meaning. */
9152 if (!NEWABI_P (abfd
) && h
!= NULL
9153 && strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
9156 /* Likewise __GOTT_BASE__ and __GOTT_INDEX__ on VxWorks. */
9157 if (is_gott_symbol (info
, h
))
9164 case R_MICROMIPS_26_S1
:
9165 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, NEWABI_P (abfd
));
9166 /* An error for unsupported relocations is raised as part
9167 of the above search, so we can skip the following. */
9169 info
->callbacks
->einfo
9170 /* xgettext:c-format */
9171 (_("%X%H: relocation %s against `%s' cannot be used"
9172 " when making a shared object; recompile with -fPIC\n"),
9173 abfd
, sec
, rel
->r_offset
, howto
->name
,
9174 (h
) ? h
->root
.root
.string
: "a local symbol");
9185 /* Allocate space for global sym dynamic relocs. */
9188 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9190 struct bfd_link_info
*info
= inf
;
9192 struct mips_elf_link_hash_entry
*hmips
;
9193 struct mips_elf_link_hash_table
*htab
;
9195 htab
= mips_elf_hash_table (info
);
9196 BFD_ASSERT (htab
!= NULL
);
9198 dynobj
= elf_hash_table (info
)->dynobj
;
9199 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9201 /* VxWorks executables are handled elsewhere; we only need to
9202 allocate relocations in shared objects. */
9203 if (htab
->root
.target_os
== is_vxworks
&& !bfd_link_pic (info
))
9206 /* Ignore indirect symbols. All relocations against such symbols
9207 will be redirected to the target symbol. */
9208 if (h
->root
.type
== bfd_link_hash_indirect
)
9211 /* If this symbol is defined in a dynamic object, or we are creating
9212 a shared library, we will need to copy any R_MIPS_32 or
9213 R_MIPS_REL32 relocs against it into the output file. */
9214 if (! bfd_link_relocatable (info
)
9215 && hmips
->possibly_dynamic_relocs
!= 0
9216 && (h
->root
.type
== bfd_link_hash_defweak
9217 || (!h
->def_regular
&& !ELF_COMMON_DEF_P (h
))
9218 || bfd_link_pic (info
)))
9220 bfd_boolean do_copy
= TRUE
;
9222 if (h
->root
.type
== bfd_link_hash_undefweak
)
9224 /* Do not copy relocations for undefined weak symbols that
9225 we are not going to export. */
9226 if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9229 /* Make sure undefined weak symbols are output as a dynamic
9231 else if (h
->dynindx
== -1 && !h
->forced_local
)
9233 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9240 /* Even though we don't directly need a GOT entry for this symbol,
9241 the SVR4 psABI requires it to have a dynamic symbol table
9242 index greater that DT_MIPS_GOTSYM if there are dynamic
9243 relocations against it.
9245 VxWorks does not enforce the same mapping between the GOT
9246 and the symbol table, so the same requirement does not
9248 if (htab
->root
.target_os
!= is_vxworks
)
9250 if (hmips
->global_got_area
> GGA_RELOC_ONLY
)
9251 hmips
->global_got_area
= GGA_RELOC_ONLY
;
9252 hmips
->got_only_for_calls
= FALSE
;
9255 mips_elf_allocate_dynamic_relocations
9256 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
9257 if (hmips
->readonly_reloc
)
9258 /* We tell the dynamic linker that there are relocations
9259 against the text segment. */
9260 info
->flags
|= DF_TEXTREL
;
9267 /* Adjust a symbol defined by a dynamic object and referenced by a
9268 regular object. The current definition is in some section of the
9269 dynamic object, but we're not including those sections. We have to
9270 change the definition to something the rest of the link can
9274 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
9275 struct elf_link_hash_entry
*h
)
9278 struct mips_elf_link_hash_entry
*hmips
;
9279 struct mips_elf_link_hash_table
*htab
;
9282 htab
= mips_elf_hash_table (info
);
9283 BFD_ASSERT (htab
!= NULL
);
9285 dynobj
= elf_hash_table (info
)->dynobj
;
9286 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9288 /* Make sure we know what is going on here. */
9291 && ! h
->is_weakalias
9292 && (! h
->def_dynamic
9294 || h
->def_regular
)))
9296 if (h
->type
== STT_GNU_IFUNC
)
9297 _bfd_error_handler (_("IFUNC symbol %s in dynamic symbol table - IFUNCS are not supported"),
9298 h
->root
.root
.string
);
9300 _bfd_error_handler (_("non-dynamic symbol %s in dynamic symbol table"),
9301 h
->root
.root
.string
);
9305 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9307 /* If there are call relocations against an externally-defined symbol,
9308 see whether we can create a MIPS lazy-binding stub for it. We can
9309 only do this if all references to the function are through call
9310 relocations, and in that case, the traditional lazy-binding stubs
9311 are much more efficient than PLT entries.
9313 Traditional stubs are only available on SVR4 psABI-based systems;
9314 VxWorks always uses PLTs instead. */
9315 if (htab
->root
.target_os
!= is_vxworks
9317 && !hmips
->no_fn_stub
)
9319 if (! elf_hash_table (info
)->dynamic_sections_created
)
9322 /* If this symbol is not defined in a regular file, then set
9323 the symbol to the stub location. This is required to make
9324 function pointers compare as equal between the normal
9325 executable and the shared library. */
9327 && !bfd_is_abs_section (htab
->sstubs
->output_section
))
9329 hmips
->needs_lazy_stub
= TRUE
;
9330 htab
->lazy_stub_count
++;
9334 /* As above, VxWorks requires PLT entries for externally-defined
9335 functions that are only accessed through call relocations.
9337 Both VxWorks and non-VxWorks targets also need PLT entries if there
9338 are static-only relocations against an externally-defined function.
9339 This can technically occur for shared libraries if there are
9340 branches to the symbol, although it is unlikely that this will be
9341 used in practice due to the short ranges involved. It can occur
9342 for any relative or absolute relocation in executables; in that
9343 case, the PLT entry becomes the function's canonical address. */
9344 else if (((h
->needs_plt
&& !hmips
->no_fn_stub
)
9345 || (h
->type
== STT_FUNC
&& hmips
->has_static_relocs
))
9346 && htab
->use_plts_and_copy_relocs
9347 && !SYMBOL_CALLS_LOCAL (info
, h
)
9348 && !(ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
9349 && h
->root
.type
== bfd_link_hash_undefweak
))
9351 bfd_boolean micromips_p
= MICROMIPS_P (info
->output_bfd
);
9352 bfd_boolean newabi_p
= NEWABI_P (info
->output_bfd
);
9354 /* If this is the first symbol to need a PLT entry, then make some
9355 basic setup. Also work out PLT entry sizes. We'll need them
9356 for PLT offset calculations. */
9357 if (htab
->plt_mips_offset
+ htab
->plt_comp_offset
== 0)
9359 BFD_ASSERT (htab
->root
.sgotplt
->size
== 0);
9360 BFD_ASSERT (htab
->plt_got_index
== 0);
9362 /* If we're using the PLT additions to the psABI, each PLT
9363 entry is 16 bytes and the PLT0 entry is 32 bytes.
9364 Encourage better cache usage by aligning. We do this
9365 lazily to avoid pessimizing traditional objects. */
9366 if (htab
->root
.target_os
!= is_vxworks
9367 && !bfd_set_section_alignment (htab
->root
.splt
, 5))
9370 /* Make sure that .got.plt is word-aligned. We do this lazily
9371 for the same reason as above. */
9372 if (!bfd_set_section_alignment (htab
->root
.sgotplt
,
9373 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
9376 /* On non-VxWorks targets, the first two entries in .got.plt
9378 if (htab
->root
.target_os
!= is_vxworks
)
9380 += (get_elf_backend_data (dynobj
)->got_header_size
9381 / MIPS_ELF_GOT_SIZE (dynobj
));
9383 /* On VxWorks, also allocate room for the header's
9384 .rela.plt.unloaded entries. */
9385 if (htab
->root
.target_os
== is_vxworks
9386 && !bfd_link_pic (info
))
9387 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
9389 /* Now work out the sizes of individual PLT entries. */
9390 if (htab
->root
.target_os
== is_vxworks
9391 && bfd_link_pic (info
))
9392 htab
->plt_mips_entry_size
9393 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
9394 else if (htab
->root
.target_os
== is_vxworks
)
9395 htab
->plt_mips_entry_size
9396 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
9398 htab
->plt_mips_entry_size
9399 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
9400 else if (!micromips_p
)
9402 htab
->plt_mips_entry_size
9403 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
9404 htab
->plt_comp_entry_size
9405 = 2 * ARRAY_SIZE (mips16_o32_exec_plt_entry
);
9407 else if (htab
->insn32
)
9409 htab
->plt_mips_entry_size
9410 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
9411 htab
->plt_comp_entry_size
9412 = 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt_entry
);
9416 htab
->plt_mips_entry_size
9417 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
9418 htab
->plt_comp_entry_size
9419 = 2 * ARRAY_SIZE (micromips_o32_exec_plt_entry
);
9423 if (h
->plt
.plist
== NULL
)
9424 h
->plt
.plist
= mips_elf_make_plt_record (dynobj
);
9425 if (h
->plt
.plist
== NULL
)
9428 /* There are no defined MIPS16 or microMIPS PLT entries for VxWorks,
9429 n32 or n64, so always use a standard entry there.
9431 If the symbol has a MIPS16 call stub and gets a PLT entry, then
9432 all MIPS16 calls will go via that stub, and there is no benefit
9433 to having a MIPS16 entry. And in the case of call_stub a
9434 standard entry actually has to be used as the stub ends with a J
9437 || htab
->root
.target_os
== is_vxworks
9439 || hmips
->call_fp_stub
)
9441 h
->plt
.plist
->need_mips
= TRUE
;
9442 h
->plt
.plist
->need_comp
= FALSE
;
9445 /* Otherwise, if there are no direct calls to the function, we
9446 have a free choice of whether to use standard or compressed
9447 entries. Prefer microMIPS entries if the object is known to
9448 contain microMIPS code, so that it becomes possible to create
9449 pure microMIPS binaries. Prefer standard entries otherwise,
9450 because MIPS16 ones are no smaller and are usually slower. */
9451 if (!h
->plt
.plist
->need_mips
&& !h
->plt
.plist
->need_comp
)
9454 h
->plt
.plist
->need_comp
= TRUE
;
9456 h
->plt
.plist
->need_mips
= TRUE
;
9459 if (h
->plt
.plist
->need_mips
)
9461 h
->plt
.plist
->mips_offset
= htab
->plt_mips_offset
;
9462 htab
->plt_mips_offset
+= htab
->plt_mips_entry_size
;
9464 if (h
->plt
.plist
->need_comp
)
9466 h
->plt
.plist
->comp_offset
= htab
->plt_comp_offset
;
9467 htab
->plt_comp_offset
+= htab
->plt_comp_entry_size
;
9470 /* Reserve the corresponding .got.plt entry now too. */
9471 h
->plt
.plist
->gotplt_index
= htab
->plt_got_index
++;
9473 /* If the output file has no definition of the symbol, set the
9474 symbol's value to the address of the stub. */
9475 if (!bfd_link_pic (info
) && !h
->def_regular
)
9476 hmips
->use_plt_entry
= TRUE
;
9478 /* Make room for the R_MIPS_JUMP_SLOT relocation. */
9479 htab
->root
.srelplt
->size
+= (htab
->root
.target_os
== is_vxworks
9480 ? MIPS_ELF_RELA_SIZE (dynobj
)
9481 : MIPS_ELF_REL_SIZE (dynobj
));
9483 /* Make room for the .rela.plt.unloaded relocations. */
9484 if (htab
->root
.target_os
== is_vxworks
&& !bfd_link_pic (info
))
9485 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
9487 /* All relocations against this symbol that could have been made
9488 dynamic will now refer to the PLT entry instead. */
9489 hmips
->possibly_dynamic_relocs
= 0;
9494 /* If this is a weak symbol, and there is a real definition, the
9495 processor independent code will have arranged for us to see the
9496 real definition first, and we can just use the same value. */
9497 if (h
->is_weakalias
)
9499 struct elf_link_hash_entry
*def
= weakdef (h
);
9500 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
9501 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
9502 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
9506 /* Otherwise, there is nothing further to do for symbols defined
9507 in regular objects. */
9511 /* There's also nothing more to do if we'll convert all relocations
9512 against this symbol into dynamic relocations. */
9513 if (!hmips
->has_static_relocs
)
9516 /* We're now relying on copy relocations. Complain if we have
9517 some that we can't convert. */
9518 if (!htab
->use_plts_and_copy_relocs
|| bfd_link_pic (info
))
9520 _bfd_error_handler (_("non-dynamic relocations refer to "
9521 "dynamic symbol %s"),
9522 h
->root
.root
.string
);
9523 bfd_set_error (bfd_error_bad_value
);
9527 /* We must allocate the symbol in our .dynbss section, which will
9528 become part of the .bss section of the executable. There will be
9529 an entry for this symbol in the .dynsym section. The dynamic
9530 object will contain position independent code, so all references
9531 from the dynamic object to this symbol will go through the global
9532 offset table. The dynamic linker will use the .dynsym entry to
9533 determine the address it must put in the global offset table, so
9534 both the dynamic object and the regular object will refer to the
9535 same memory location for the variable. */
9537 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
9539 s
= htab
->root
.sdynrelro
;
9540 srel
= htab
->root
.sreldynrelro
;
9544 s
= htab
->root
.sdynbss
;
9545 srel
= htab
->root
.srelbss
;
9547 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
9549 if (htab
->root
.target_os
== is_vxworks
)
9550 srel
->size
+= sizeof (Elf32_External_Rela
);
9552 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
9556 /* All relocations against this symbol that could have been made
9557 dynamic will now refer to the local copy instead. */
9558 hmips
->possibly_dynamic_relocs
= 0;
9560 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
9563 /* This function is called after all the input files have been read,
9564 and the input sections have been assigned to output sections. We
9565 check for any mips16 stub sections that we can discard. */
9568 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
9569 struct bfd_link_info
*info
)
9572 struct mips_elf_link_hash_table
*htab
;
9573 struct mips_htab_traverse_info hti
;
9575 htab
= mips_elf_hash_table (info
);
9576 BFD_ASSERT (htab
!= NULL
);
9578 /* The .reginfo section has a fixed size. */
9579 sect
= bfd_get_section_by_name (output_bfd
, ".reginfo");
9582 bfd_set_section_size (sect
, sizeof (Elf32_External_RegInfo
));
9583 sect
->flags
|= SEC_FIXED_SIZE
| SEC_HAS_CONTENTS
;
9586 /* The .MIPS.abiflags section has a fixed size. */
9587 sect
= bfd_get_section_by_name (output_bfd
, ".MIPS.abiflags");
9590 bfd_set_section_size (sect
, sizeof (Elf_External_ABIFlags_v0
));
9591 sect
->flags
|= SEC_FIXED_SIZE
| SEC_HAS_CONTENTS
;
9595 hti
.output_bfd
= output_bfd
;
9597 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
9598 mips_elf_check_symbols
, &hti
);
9605 /* If the link uses a GOT, lay it out and work out its size. */
9608 mips_elf_lay_out_got (bfd
*output_bfd
, struct bfd_link_info
*info
)
9612 struct mips_got_info
*g
;
9613 bfd_size_type loadable_size
= 0;
9614 bfd_size_type page_gotno
;
9616 struct mips_elf_traverse_got_arg tga
;
9617 struct mips_elf_link_hash_table
*htab
;
9619 htab
= mips_elf_hash_table (info
);
9620 BFD_ASSERT (htab
!= NULL
);
9622 s
= htab
->root
.sgot
;
9626 dynobj
= elf_hash_table (info
)->dynobj
;
9629 /* Allocate room for the reserved entries. VxWorks always reserves
9630 3 entries; other objects only reserve 2 entries. */
9631 BFD_ASSERT (g
->assigned_low_gotno
== 0);
9632 if (htab
->root
.target_os
== is_vxworks
)
9633 htab
->reserved_gotno
= 3;
9635 htab
->reserved_gotno
= 2;
9636 g
->local_gotno
+= htab
->reserved_gotno
;
9637 g
->assigned_low_gotno
= htab
->reserved_gotno
;
9639 /* Decide which symbols need to go in the global part of the GOT and
9640 count the number of reloc-only GOT symbols. */
9641 mips_elf_link_hash_traverse (htab
, mips_elf_count_got_symbols
, info
);
9643 if (!mips_elf_resolve_final_got_entries (info
, g
))
9646 /* Calculate the total loadable size of the output. That
9647 will give us the maximum number of GOT_PAGE entries
9649 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link
.next
)
9651 asection
*subsection
;
9653 for (subsection
= ibfd
->sections
;
9655 subsection
= subsection
->next
)
9657 if ((subsection
->flags
& SEC_ALLOC
) == 0)
9659 loadable_size
+= ((subsection
->size
+ 0xf)
9660 &~ (bfd_size_type
) 0xf);
9664 if (htab
->root
.target_os
== is_vxworks
)
9665 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
9666 relocations against local symbols evaluate to "G", and the EABI does
9667 not include R_MIPS_GOT_PAGE. */
9670 /* Assume there are two loadable segments consisting of contiguous
9671 sections. Is 5 enough? */
9672 page_gotno
= (loadable_size
>> 16) + 5;
9674 /* Choose the smaller of the two page estimates; both are intended to be
9676 if (page_gotno
> g
->page_gotno
)
9677 page_gotno
= g
->page_gotno
;
9679 g
->local_gotno
+= page_gotno
;
9680 g
->assigned_high_gotno
= g
->local_gotno
- 1;
9682 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
9683 s
->size
+= g
->global_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
9684 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
9686 /* VxWorks does not support multiple GOTs. It initializes $gp to
9687 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
9689 if (htab
->root
.target_os
!= is_vxworks
9690 && s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
9692 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
9697 /* Record that all bfds use G. This also has the effect of freeing
9698 the per-bfd GOTs, which we no longer need. */
9699 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link
.next
)
9700 if (mips_elf_bfd_got (ibfd
, FALSE
))
9701 mips_elf_replace_bfd_got (ibfd
, g
);
9702 mips_elf_replace_bfd_got (output_bfd
, g
);
9704 /* Set up TLS entries. */
9705 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
9708 tga
.value
= MIPS_ELF_GOT_SIZE (output_bfd
);
9709 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, &tga
);
9712 BFD_ASSERT (g
->tls_assigned_gotno
9713 == g
->global_gotno
+ g
->local_gotno
+ g
->tls_gotno
);
9715 /* Each VxWorks GOT entry needs an explicit relocation. */
9716 if (htab
->root
.target_os
== is_vxworks
&& bfd_link_pic (info
))
9717 g
->relocs
+= g
->global_gotno
+ g
->local_gotno
- htab
->reserved_gotno
;
9719 /* Allocate room for the TLS relocations. */
9721 mips_elf_allocate_dynamic_relocations (dynobj
, info
, g
->relocs
);
9727 /* Estimate the size of the .MIPS.stubs section. */
9730 mips_elf_estimate_stub_size (bfd
*output_bfd
, struct bfd_link_info
*info
)
9732 struct mips_elf_link_hash_table
*htab
;
9733 bfd_size_type dynsymcount
;
9735 htab
= mips_elf_hash_table (info
);
9736 BFD_ASSERT (htab
!= NULL
);
9738 if (htab
->lazy_stub_count
== 0)
9741 /* IRIX rld assumes that a function stub isn't at the end of the .text
9742 section, so add a dummy entry to the end. */
9743 htab
->lazy_stub_count
++;
9745 /* Get a worst-case estimate of the number of dynamic symbols needed.
9746 At this point, dynsymcount does not account for section symbols
9747 and count_section_dynsyms may overestimate the number that will
9749 dynsymcount
= (elf_hash_table (info
)->dynsymcount
9750 + count_section_dynsyms (output_bfd
, info
));
9752 /* Determine the size of one stub entry. There's no disadvantage
9753 from using microMIPS code here, so for the sake of pure-microMIPS
9754 binaries we prefer it whenever there's any microMIPS code in
9755 output produced at all. This has a benefit of stubs being
9756 shorter by 4 bytes each too, unless in the insn32 mode. */
9757 if (!MICROMIPS_P (output_bfd
))
9758 htab
->function_stub_size
= (dynsymcount
> 0x10000
9759 ? MIPS_FUNCTION_STUB_BIG_SIZE
9760 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
9761 else if (htab
->insn32
)
9762 htab
->function_stub_size
= (dynsymcount
> 0x10000
9763 ? MICROMIPS_INSN32_FUNCTION_STUB_BIG_SIZE
9764 : MICROMIPS_INSN32_FUNCTION_STUB_NORMAL_SIZE
);
9766 htab
->function_stub_size
= (dynsymcount
> 0x10000
9767 ? MICROMIPS_FUNCTION_STUB_BIG_SIZE
9768 : MICROMIPS_FUNCTION_STUB_NORMAL_SIZE
);
9770 htab
->sstubs
->size
= htab
->lazy_stub_count
* htab
->function_stub_size
;
9773 /* A mips_elf_link_hash_traverse callback for which DATA points to a
9774 mips_htab_traverse_info. If H needs a traditional MIPS lazy-binding
9775 stub, allocate an entry in the stubs section. */
9778 mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry
*h
, void *data
)
9780 struct mips_htab_traverse_info
*hti
= data
;
9781 struct mips_elf_link_hash_table
*htab
;
9782 struct bfd_link_info
*info
;
9786 output_bfd
= hti
->output_bfd
;
9787 htab
= mips_elf_hash_table (info
);
9788 BFD_ASSERT (htab
!= NULL
);
9790 if (h
->needs_lazy_stub
)
9792 bfd_boolean micromips_p
= MICROMIPS_P (output_bfd
);
9793 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
9794 bfd_vma isa_bit
= micromips_p
;
9796 BFD_ASSERT (htab
->root
.dynobj
!= NULL
);
9797 if (h
->root
.plt
.plist
== NULL
)
9798 h
->root
.plt
.plist
= mips_elf_make_plt_record (htab
->sstubs
->owner
);
9799 if (h
->root
.plt
.plist
== NULL
)
9804 h
->root
.root
.u
.def
.section
= htab
->sstubs
;
9805 h
->root
.root
.u
.def
.value
= htab
->sstubs
->size
+ isa_bit
;
9806 h
->root
.plt
.plist
->stub_offset
= htab
->sstubs
->size
;
9807 h
->root
.other
= other
;
9808 htab
->sstubs
->size
+= htab
->function_stub_size
;
9813 /* Allocate offsets in the stubs section to each symbol that needs one.
9814 Set the final size of the .MIPS.stub section. */
9817 mips_elf_lay_out_lazy_stubs (struct bfd_link_info
*info
)
9819 bfd
*output_bfd
= info
->output_bfd
;
9820 bfd_boolean micromips_p
= MICROMIPS_P (output_bfd
);
9821 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
9822 bfd_vma isa_bit
= micromips_p
;
9823 struct mips_elf_link_hash_table
*htab
;
9824 struct mips_htab_traverse_info hti
;
9825 struct elf_link_hash_entry
*h
;
9828 htab
= mips_elf_hash_table (info
);
9829 BFD_ASSERT (htab
!= NULL
);
9831 if (htab
->lazy_stub_count
== 0)
9834 htab
->sstubs
->size
= 0;
9836 hti
.output_bfd
= output_bfd
;
9838 mips_elf_link_hash_traverse (htab
, mips_elf_allocate_lazy_stub
, &hti
);
9841 htab
->sstubs
->size
+= htab
->function_stub_size
;
9842 BFD_ASSERT (htab
->sstubs
->size
9843 == htab
->lazy_stub_count
* htab
->function_stub_size
);
9845 dynobj
= elf_hash_table (info
)->dynobj
;
9846 BFD_ASSERT (dynobj
!= NULL
);
9847 h
= _bfd_elf_define_linkage_sym (dynobj
, info
, htab
->sstubs
, "_MIPS_STUBS_");
9850 h
->root
.u
.def
.value
= isa_bit
;
9857 /* A mips_elf_link_hash_traverse callback for which DATA points to a
9858 bfd_link_info. If H uses the address of a PLT entry as the value
9859 of the symbol, then set the entry in the symbol table now. Prefer
9860 a standard MIPS PLT entry. */
9863 mips_elf_set_plt_sym_value (struct mips_elf_link_hash_entry
*h
, void *data
)
9865 struct bfd_link_info
*info
= data
;
9866 bfd_boolean micromips_p
= MICROMIPS_P (info
->output_bfd
);
9867 struct mips_elf_link_hash_table
*htab
;
9872 htab
= mips_elf_hash_table (info
);
9873 BFD_ASSERT (htab
!= NULL
);
9875 if (h
->use_plt_entry
)
9877 BFD_ASSERT (h
->root
.plt
.plist
!= NULL
);
9878 BFD_ASSERT (h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
9879 || h
->root
.plt
.plist
->comp_offset
!= MINUS_ONE
);
9881 val
= htab
->plt_header_size
;
9882 if (h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
)
9885 val
+= h
->root
.plt
.plist
->mips_offset
;
9891 val
+= htab
->plt_mips_offset
+ h
->root
.plt
.plist
->comp_offset
;
9892 other
= micromips_p
? STO_MICROMIPS
: STO_MIPS16
;
9895 /* For VxWorks, point at the PLT load stub rather than the lazy
9896 resolution stub; this stub will become the canonical function
9898 if (htab
->root
.target_os
== is_vxworks
)
9901 h
->root
.root
.u
.def
.section
= htab
->root
.splt
;
9902 h
->root
.root
.u
.def
.value
= val
;
9903 h
->root
.other
= other
;
9909 /* Set the sizes of the dynamic sections. */
9912 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
9913 struct bfd_link_info
*info
)
9916 asection
*s
, *sreldyn
;
9917 bfd_boolean reltext
;
9918 struct mips_elf_link_hash_table
*htab
;
9920 htab
= mips_elf_hash_table (info
);
9921 BFD_ASSERT (htab
!= NULL
);
9922 dynobj
= elf_hash_table (info
)->dynobj
;
9923 BFD_ASSERT (dynobj
!= NULL
);
9925 if (elf_hash_table (info
)->dynamic_sections_created
)
9927 /* Set the contents of the .interp section to the interpreter. */
9928 if (bfd_link_executable (info
) && !info
->nointerp
)
9930 s
= bfd_get_linker_section (dynobj
, ".interp");
9931 BFD_ASSERT (s
!= NULL
);
9933 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
9935 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
9938 /* Figure out the size of the PLT header if we know that we
9939 are using it. For the sake of cache alignment always use
9940 a standard header whenever any standard entries are present
9941 even if microMIPS entries are present as well. This also
9942 lets the microMIPS header rely on the value of $v0 only set
9943 by microMIPS entries, for a small size reduction.
9945 Set symbol table entry values for symbols that use the
9946 address of their PLT entry now that we can calculate it.
9948 Also create the _PROCEDURE_LINKAGE_TABLE_ symbol if we
9949 haven't already in _bfd_elf_create_dynamic_sections. */
9950 if (htab
->root
.splt
&& htab
->plt_mips_offset
+ htab
->plt_comp_offset
!= 0)
9952 bfd_boolean micromips_p
= (MICROMIPS_P (output_bfd
)
9953 && !htab
->plt_mips_offset
);
9954 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
9955 bfd_vma isa_bit
= micromips_p
;
9956 struct elf_link_hash_entry
*h
;
9959 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9960 BFD_ASSERT (htab
->root
.sgotplt
->size
== 0);
9961 BFD_ASSERT (htab
->root
.splt
->size
== 0);
9963 if (htab
->root
.target_os
== is_vxworks
&& bfd_link_pic (info
))
9964 size
= 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
9965 else if (htab
->root
.target_os
== is_vxworks
)
9966 size
= 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
9967 else if (ABI_64_P (output_bfd
))
9968 size
= 4 * ARRAY_SIZE (mips_n64_exec_plt0_entry
);
9969 else if (ABI_N32_P (output_bfd
))
9970 size
= 4 * ARRAY_SIZE (mips_n32_exec_plt0_entry
);
9971 else if (!micromips_p
)
9972 size
= 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
);
9973 else if (htab
->insn32
)
9974 size
= 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt0_entry
);
9976 size
= 2 * ARRAY_SIZE (micromips_o32_exec_plt0_entry
);
9978 htab
->plt_header_is_comp
= micromips_p
;
9979 htab
->plt_header_size
= size
;
9980 htab
->root
.splt
->size
= (size
9981 + htab
->plt_mips_offset
9982 + htab
->plt_comp_offset
);
9983 htab
->root
.sgotplt
->size
= (htab
->plt_got_index
9984 * MIPS_ELF_GOT_SIZE (dynobj
));
9986 mips_elf_link_hash_traverse (htab
, mips_elf_set_plt_sym_value
, info
);
9988 if (htab
->root
.hplt
== NULL
)
9990 h
= _bfd_elf_define_linkage_sym (dynobj
, info
, htab
->root
.splt
,
9991 "_PROCEDURE_LINKAGE_TABLE_");
9992 htab
->root
.hplt
= h
;
9997 h
= htab
->root
.hplt
;
9998 h
->root
.u
.def
.value
= isa_bit
;
10000 h
->type
= STT_FUNC
;
10004 /* Allocate space for global sym dynamic relocs. */
10005 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, info
);
10007 mips_elf_estimate_stub_size (output_bfd
, info
);
10009 if (!mips_elf_lay_out_got (output_bfd
, info
))
10012 mips_elf_lay_out_lazy_stubs (info
);
10014 /* The check_relocs and adjust_dynamic_symbol entry points have
10015 determined the sizes of the various dynamic sections. Allocate
10016 memory for them. */
10018 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10022 /* It's OK to base decisions on the section name, because none
10023 of the dynobj section names depend upon the input files. */
10024 name
= bfd_section_name (s
);
10026 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10029 if (CONST_STRNEQ (name
, ".rel"))
10033 const char *outname
;
10036 /* If this relocation section applies to a read only
10037 section, then we probably need a DT_TEXTREL entry.
10038 If the relocation section is .rel(a).dyn, we always
10039 assert a DT_TEXTREL entry rather than testing whether
10040 there exists a relocation to a read only section or
10042 outname
= bfd_section_name (s
->output_section
);
10043 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
10044 if ((target
!= NULL
10045 && (target
->flags
& SEC_READONLY
) != 0
10046 && (target
->flags
& SEC_ALLOC
) != 0)
10047 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
10050 /* We use the reloc_count field as a counter if we need
10051 to copy relocs into the output file. */
10052 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
10053 s
->reloc_count
= 0;
10055 /* If combreloc is enabled, elf_link_sort_relocs() will
10056 sort relocations, but in a different way than we do,
10057 and before we're done creating relocations. Also, it
10058 will move them around between input sections'
10059 relocation's contents, so our sorting would be
10060 broken, so don't let it run. */
10061 info
->combreloc
= 0;
10064 else if (bfd_link_executable (info
)
10065 && ! mips_elf_hash_table (info
)->use_rld_obj_head
10066 && CONST_STRNEQ (name
, ".rld_map"))
10068 /* We add a room for __rld_map. It will be filled in by the
10069 rtld to contain a pointer to the _r_debug structure. */
10070 s
->size
+= MIPS_ELF_RLD_MAP_SIZE (output_bfd
);
10072 else if (SGI_COMPAT (output_bfd
)
10073 && CONST_STRNEQ (name
, ".compact_rel"))
10074 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
10075 else if (s
== htab
->root
.splt
)
10077 /* If the last PLT entry has a branch delay slot, allocate
10078 room for an extra nop to fill the delay slot. This is
10079 for CPUs without load interlocking. */
10080 if (! LOAD_INTERLOCKS_P (output_bfd
)
10081 && htab
->root
.target_os
!= is_vxworks
10085 else if (! CONST_STRNEQ (name
, ".init")
10086 && s
!= htab
->root
.sgot
10087 && s
!= htab
->root
.sgotplt
10088 && s
!= htab
->sstubs
10089 && s
!= htab
->root
.sdynbss
10090 && s
!= htab
->root
.sdynrelro
)
10092 /* It's not one of our sections, so don't allocate space. */
10098 s
->flags
|= SEC_EXCLUDE
;
10102 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10105 /* Allocate memory for the section contents. */
10106 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10107 if (s
->contents
== NULL
)
10109 bfd_set_error (bfd_error_no_memory
);
10114 if (elf_hash_table (info
)->dynamic_sections_created
)
10116 /* Add some entries to the .dynamic section. We fill in the
10117 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
10118 must add the entries now so that we get the correct size for
10119 the .dynamic section. */
10121 /* SGI object has the equivalence of DT_DEBUG in the
10122 DT_MIPS_RLD_MAP entry. This must come first because glibc
10123 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and some tools
10124 may only look at the first one they see. */
10125 if (!bfd_link_pic (info
)
10126 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
10129 if (bfd_link_executable (info
)
10130 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP_REL
, 0))
10133 /* The DT_DEBUG entry may be filled in by the dynamic linker and
10134 used by the debugger. */
10135 if (bfd_link_executable (info
)
10136 && !SGI_COMPAT (output_bfd
)
10137 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
10141 && (SGI_COMPAT (output_bfd
)
10142 || htab
->root
.target_os
== is_vxworks
))
10143 info
->flags
|= DF_TEXTREL
;
10145 if ((info
->flags
& DF_TEXTREL
) != 0)
10147 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
10150 /* Clear the DF_TEXTREL flag. It will be set again if we
10151 write out an actual text relocation; we may not, because
10152 at this point we do not know whether e.g. any .eh_frame
10153 absolute relocations have been converted to PC-relative. */
10154 info
->flags
&= ~DF_TEXTREL
;
10157 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
10160 sreldyn
= mips_elf_rel_dyn_section (info
, FALSE
);
10161 if (htab
->root
.target_os
== is_vxworks
)
10163 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
10164 use any of the DT_MIPS_* tags. */
10165 if (sreldyn
&& sreldyn
->size
> 0)
10167 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
10170 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
10173 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
10179 if (sreldyn
&& sreldyn
->size
> 0
10180 && !bfd_is_abs_section (sreldyn
->output_section
))
10182 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
10185 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
10188 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
10192 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
10195 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
10198 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
10201 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
10204 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
10207 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
10210 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
10213 if (info
->emit_gnu_hash
10214 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_XHASH
, 0))
10217 if (IRIX_COMPAT (dynobj
) == ict_irix5
10218 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
10221 if (IRIX_COMPAT (dynobj
) == ict_irix6
10222 && (bfd_get_section_by_name
10223 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
10224 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
10227 if (htab
->root
.splt
->size
> 0)
10229 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
10232 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
10235 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
10238 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_PLTGOT
, 0))
10241 if (htab
->root
.target_os
== is_vxworks
10242 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
10249 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
10250 Adjust its R_ADDEND field so that it is correct for the output file.
10251 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
10252 and sections respectively; both use symbol indexes. */
10255 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
10256 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
10257 asection
**local_sections
, Elf_Internal_Rela
*rel
)
10259 unsigned int r_type
, r_symndx
;
10260 Elf_Internal_Sym
*sym
;
10263 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
))
10265 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
10266 if (gprel16_reloc_p (r_type
)
10267 || r_type
== R_MIPS_GPREL32
10268 || literal_reloc_p (r_type
))
10270 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
10271 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
10274 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
10275 sym
= local_syms
+ r_symndx
;
10277 /* Adjust REL's addend to account for section merging. */
10278 if (!bfd_link_relocatable (info
))
10280 sec
= local_sections
[r_symndx
];
10281 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
10284 /* This would normally be done by the rela_normal code in elflink.c. */
10285 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
10286 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
10290 /* Handle relocations against symbols from removed linkonce sections,
10291 or sections discarded by a linker script. We use this wrapper around
10292 RELOC_AGAINST_DISCARDED_SECTION to handle triplets of compound relocs
10293 on 64-bit ELF targets. In this case for any relocation handled, which
10294 always be the first in a triplet, the remaining two have to be processed
10295 together with the first, even if they are R_MIPS_NONE. It is the symbol
10296 index referred by the first reloc that applies to all the three and the
10297 remaining two never refer to an object symbol. And it is the final
10298 relocation (the last non-null one) that determines the output field of
10299 the whole relocation so retrieve the corresponding howto structure for
10300 the relocatable field to be cleared by RELOC_AGAINST_DISCARDED_SECTION.
10302 Note that RELOC_AGAINST_DISCARDED_SECTION is a macro that uses "continue"
10303 and therefore requires to be pasted in a loop. It also defines a block
10304 and does not protect any of its arguments, hence the extra brackets. */
10307 mips_reloc_against_discarded_section (bfd
*output_bfd
,
10308 struct bfd_link_info
*info
,
10309 bfd
*input_bfd
, asection
*input_section
,
10310 Elf_Internal_Rela
**rel
,
10311 const Elf_Internal_Rela
**relend
,
10312 bfd_boolean rel_reloc
,
10313 reloc_howto_type
*howto
,
10314 bfd_byte
*contents
)
10316 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
10317 int count
= bed
->s
->int_rels_per_ext_rel
;
10318 unsigned int r_type
;
10321 for (i
= count
- 1; i
> 0; i
--)
10323 r_type
= ELF_R_TYPE (output_bfd
, (*rel
)[i
].r_info
);
10324 if (r_type
!= R_MIPS_NONE
)
10326 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
, !rel_reloc
);
10332 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
10333 (*rel
), count
, (*relend
),
10334 howto
, i
, contents
);
10339 /* Relocate a MIPS ELF section. */
10342 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
10343 bfd
*input_bfd
, asection
*input_section
,
10344 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
10345 Elf_Internal_Sym
*local_syms
,
10346 asection
**local_sections
)
10348 Elf_Internal_Rela
*rel
;
10349 const Elf_Internal_Rela
*relend
;
10350 bfd_vma addend
= 0;
10351 bfd_boolean use_saved_addend_p
= FALSE
;
10353 relend
= relocs
+ input_section
->reloc_count
;
10354 for (rel
= relocs
; rel
< relend
; ++rel
)
10358 reloc_howto_type
*howto
;
10359 bfd_boolean cross_mode_jump_p
= FALSE
;
10360 /* TRUE if the relocation is a RELA relocation, rather than a
10362 bfd_boolean rela_relocation_p
= TRUE
;
10363 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
10365 unsigned long r_symndx
;
10367 Elf_Internal_Shdr
*symtab_hdr
;
10368 struct elf_link_hash_entry
*h
;
10369 bfd_boolean rel_reloc
;
10371 rel_reloc
= (NEWABI_P (input_bfd
)
10372 && mips_elf_rel_relocation_p (input_bfd
, input_section
,
10374 /* Find the relocation howto for this relocation. */
10375 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
, !rel_reloc
);
10377 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
10378 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
10379 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
))
10381 sec
= local_sections
[r_symndx
];
10386 unsigned long extsymoff
;
10389 if (!elf_bad_symtab (input_bfd
))
10390 extsymoff
= symtab_hdr
->sh_info
;
10391 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
10392 while (h
->root
.type
== bfd_link_hash_indirect
10393 || h
->root
.type
== bfd_link_hash_warning
)
10394 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10397 if (h
->root
.type
== bfd_link_hash_defined
10398 || h
->root
.type
== bfd_link_hash_defweak
)
10399 sec
= h
->root
.u
.def
.section
;
10402 if (sec
!= NULL
&& discarded_section (sec
))
10404 mips_reloc_against_discarded_section (output_bfd
, info
, input_bfd
,
10405 input_section
, &rel
, &relend
,
10406 rel_reloc
, howto
, contents
);
10410 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
10412 /* Some 32-bit code uses R_MIPS_64. In particular, people use
10413 64-bit code, but make sure all their addresses are in the
10414 lowermost or uppermost 32-bit section of the 64-bit address
10415 space. Thus, when they use an R_MIPS_64 they mean what is
10416 usually meant by R_MIPS_32, with the exception that the
10417 stored value is sign-extended to 64 bits. */
10418 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
10420 /* On big-endian systems, we need to lie about the position
10422 if (bfd_big_endian (input_bfd
))
10423 rel
->r_offset
+= 4;
10426 if (!use_saved_addend_p
)
10428 /* If these relocations were originally of the REL variety,
10429 we must pull the addend out of the field that will be
10430 relocated. Otherwise, we simply use the contents of the
10431 RELA relocation. */
10432 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
10435 rela_relocation_p
= FALSE
;
10436 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
10438 if (hi16_reloc_p (r_type
)
10439 || (got16_reloc_p (r_type
)
10440 && mips_elf_local_relocation_p (input_bfd
, rel
,
10443 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
10444 contents
, &addend
))
10447 name
= h
->root
.root
.string
;
10449 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
10450 local_syms
+ r_symndx
,
10453 /* xgettext:c-format */
10454 (_("%pB: can't find matching LO16 reloc against `%s'"
10455 " for %s at %#" PRIx64
" in section `%pA'"),
10457 howto
->name
, (uint64_t) rel
->r_offset
, input_section
);
10461 addend
<<= howto
->rightshift
;
10464 addend
= rel
->r_addend
;
10465 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
10466 local_syms
, local_sections
, rel
);
10469 if (bfd_link_relocatable (info
))
10471 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
10472 && bfd_big_endian (input_bfd
))
10473 rel
->r_offset
-= 4;
10475 if (!rela_relocation_p
&& rel
->r_addend
)
10477 addend
+= rel
->r_addend
;
10478 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
10479 addend
= mips_elf_high (addend
);
10480 else if (r_type
== R_MIPS_HIGHER
)
10481 addend
= mips_elf_higher (addend
);
10482 else if (r_type
== R_MIPS_HIGHEST
)
10483 addend
= mips_elf_highest (addend
);
10485 addend
>>= howto
->rightshift
;
10487 /* We use the source mask, rather than the destination
10488 mask because the place to which we are writing will be
10489 source of the addend in the final link. */
10490 addend
&= howto
->src_mask
;
10492 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
10493 /* See the comment above about using R_MIPS_64 in the 32-bit
10494 ABI. Here, we need to update the addend. It would be
10495 possible to get away with just using the R_MIPS_32 reloc
10496 but for endianness. */
10502 if (addend
& ((bfd_vma
) 1 << 31))
10504 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
10511 /* If we don't know that we have a 64-bit type,
10512 do two separate stores. */
10513 if (bfd_big_endian (input_bfd
))
10515 /* Store the sign-bits (which are most significant)
10517 low_bits
= sign_bits
;
10518 high_bits
= addend
;
10523 high_bits
= sign_bits
;
10525 bfd_put_32 (input_bfd
, low_bits
,
10526 contents
+ rel
->r_offset
);
10527 bfd_put_32 (input_bfd
, high_bits
,
10528 contents
+ rel
->r_offset
+ 4);
10532 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
10533 input_bfd
, input_section
,
10538 /* Go on to the next relocation. */
10542 /* In the N32 and 64-bit ABIs there may be multiple consecutive
10543 relocations for the same offset. In that case we are
10544 supposed to treat the output of each relocation as the addend
10546 if (rel
+ 1 < relend
10547 && rel
->r_offset
== rel
[1].r_offset
10548 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
10549 use_saved_addend_p
= TRUE
;
10551 use_saved_addend_p
= FALSE
;
10553 /* Figure out what value we are supposed to relocate. */
10554 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
10555 input_section
, contents
,
10556 info
, rel
, addend
, howto
,
10557 local_syms
, local_sections
,
10558 &value
, &name
, &cross_mode_jump_p
,
10559 use_saved_addend_p
))
10561 case bfd_reloc_continue
:
10562 /* There's nothing to do. */
10565 case bfd_reloc_undefined
:
10566 /* mips_elf_calculate_relocation already called the
10567 undefined_symbol callback. There's no real point in
10568 trying to perform the relocation at this point, so we
10569 just skip ahead to the next relocation. */
10572 case bfd_reloc_notsupported
:
10573 msg
= _("internal error: unsupported relocation error");
10574 info
->callbacks
->warning
10575 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
10578 case bfd_reloc_overflow
:
10579 if (use_saved_addend_p
)
10580 /* Ignore overflow until we reach the last relocation for
10581 a given location. */
10585 struct mips_elf_link_hash_table
*htab
;
10587 htab
= mips_elf_hash_table (info
);
10588 BFD_ASSERT (htab
!= NULL
);
10589 BFD_ASSERT (name
!= NULL
);
10590 if (!htab
->small_data_overflow_reported
10591 && (gprel16_reloc_p (howto
->type
)
10592 || literal_reloc_p (howto
->type
)))
10594 msg
= _("small-data section exceeds 64KB;"
10595 " lower small-data size limit (see option -G)");
10597 htab
->small_data_overflow_reported
= TRUE
;
10598 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
10600 (*info
->callbacks
->reloc_overflow
)
10601 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
10602 input_bfd
, input_section
, rel
->r_offset
);
10609 case bfd_reloc_outofrange
:
10611 if (jal_reloc_p (howto
->type
))
10612 msg
= (cross_mode_jump_p
10613 ? _("cannot convert a jump to JALX "
10614 "for a non-word-aligned address")
10615 : (howto
->type
== R_MIPS16_26
10616 ? _("jump to a non-word-aligned address")
10617 : _("jump to a non-instruction-aligned address")));
10618 else if (b_reloc_p (howto
->type
))
10619 msg
= (cross_mode_jump_p
10620 ? _("cannot convert a branch to JALX "
10621 "for a non-word-aligned address")
10622 : _("branch to a non-instruction-aligned address"));
10623 else if (aligned_pcrel_reloc_p (howto
->type
))
10624 msg
= _("PC-relative load from unaligned address");
10627 info
->callbacks
->einfo
10628 ("%X%H: %s\n", input_bfd
, input_section
, rel
->r_offset
, msg
);
10631 /* Fall through. */
10638 /* If we've got another relocation for the address, keep going
10639 until we reach the last one. */
10640 if (use_saved_addend_p
)
10646 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
10647 /* See the comment above about using R_MIPS_64 in the 32-bit
10648 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
10649 that calculated the right value. Now, however, we
10650 sign-extend the 32-bit result to 64-bits, and store it as a
10651 64-bit value. We are especially generous here in that we
10652 go to extreme lengths to support this usage on systems with
10653 only a 32-bit VMA. */
10659 if (value
& ((bfd_vma
) 1 << 31))
10661 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
10668 /* If we don't know that we have a 64-bit type,
10669 do two separate stores. */
10670 if (bfd_big_endian (input_bfd
))
10672 /* Undo what we did above. */
10673 rel
->r_offset
-= 4;
10674 /* Store the sign-bits (which are most significant)
10676 low_bits
= sign_bits
;
10682 high_bits
= sign_bits
;
10684 bfd_put_32 (input_bfd
, low_bits
,
10685 contents
+ rel
->r_offset
);
10686 bfd_put_32 (input_bfd
, high_bits
,
10687 contents
+ rel
->r_offset
+ 4);
10691 /* Actually perform the relocation. */
10692 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
10693 input_bfd
, input_section
,
10694 contents
, cross_mode_jump_p
))
10701 /* A function that iterates over each entry in la25_stubs and fills
10702 in the code for each one. DATA points to a mips_htab_traverse_info. */
10705 mips_elf_create_la25_stub (void **slot
, void *data
)
10707 struct mips_htab_traverse_info
*hti
;
10708 struct mips_elf_link_hash_table
*htab
;
10709 struct mips_elf_la25_stub
*stub
;
10712 bfd_vma offset
, target
, target_high
, target_low
;
10714 bfd_signed_vma pcrel_offset
= 0;
10716 stub
= (struct mips_elf_la25_stub
*) *slot
;
10717 hti
= (struct mips_htab_traverse_info
*) data
;
10718 htab
= mips_elf_hash_table (hti
->info
);
10719 BFD_ASSERT (htab
!= NULL
);
10721 /* Create the section contents, if we haven't already. */
10722 s
= stub
->stub_section
;
10726 loc
= bfd_malloc (s
->size
);
10735 /* Work out where in the section this stub should go. */
10736 offset
= stub
->offset
;
10738 /* We add 8 here to account for the LUI/ADDIU instructions
10739 before the branch instruction. This cannot be moved down to
10740 where pcrel_offset is calculated as 's' is updated in
10741 mips_elf_get_la25_target. */
10742 branch_pc
= s
->output_section
->vma
+ s
->output_offset
+ offset
+ 8;
10744 /* Work out the target address. */
10745 target
= mips_elf_get_la25_target (stub
, &s
);
10746 target
+= s
->output_section
->vma
+ s
->output_offset
;
10748 target_high
= ((target
+ 0x8000) >> 16) & 0xffff;
10749 target_low
= (target
& 0xffff);
10751 /* Calculate the PC of the compact branch instruction (for the case where
10752 compact branches are used for either microMIPSR6 or MIPSR6 with
10753 compact branches. Add 4-bytes to account for BC using the PC of the
10754 next instruction as the base. */
10755 pcrel_offset
= target
- (branch_pc
+ 4);
10757 if (stub
->stub_section
!= htab
->strampoline
)
10759 /* This is a simple LUI/ADDIU stub. Zero out the beginning
10760 of the section and write the two instructions at the end. */
10761 memset (loc
, 0, offset
);
10763 if (ELF_ST_IS_MICROMIPS (stub
->h
->root
.other
))
10765 bfd_put_micromips_32 (hti
->output_bfd
,
10766 LA25_LUI_MICROMIPS (target_high
),
10768 bfd_put_micromips_32 (hti
->output_bfd
,
10769 LA25_ADDIU_MICROMIPS (target_low
),
10774 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
10775 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 4);
10780 /* This is trampoline. */
10782 if (ELF_ST_IS_MICROMIPS (stub
->h
->root
.other
))
10784 bfd_put_micromips_32 (hti
->output_bfd
,
10785 LA25_LUI_MICROMIPS (target_high
), loc
);
10786 bfd_put_micromips_32 (hti
->output_bfd
,
10787 LA25_J_MICROMIPS (target
), loc
+ 4);
10788 bfd_put_micromips_32 (hti
->output_bfd
,
10789 LA25_ADDIU_MICROMIPS (target_low
), loc
+ 8);
10790 bfd_put_32 (hti
->output_bfd
, 0, loc
+ 12);
10794 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
10795 if (MIPSR6_P (hti
->output_bfd
) && htab
->compact_branches
)
10797 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 4);
10798 bfd_put_32 (hti
->output_bfd
, LA25_BC (pcrel_offset
), loc
+ 8);
10802 bfd_put_32 (hti
->output_bfd
, LA25_J (target
), loc
+ 4);
10803 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 8);
10805 bfd_put_32 (hti
->output_bfd
, 0, loc
+ 12);
10811 /* If NAME is one of the special IRIX6 symbols defined by the linker,
10812 adjust it appropriately now. */
10815 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
10816 const char *name
, Elf_Internal_Sym
*sym
)
10818 /* The linker script takes care of providing names and values for
10819 these, but we must place them into the right sections. */
10820 static const char* const text_section_symbols
[] = {
10823 "__dso_displacement",
10825 "__program_header_table",
10829 static const char* const data_section_symbols
[] = {
10837 const char* const *p
;
10840 for (i
= 0; i
< 2; ++i
)
10841 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
10844 if (strcmp (*p
, name
) == 0)
10846 /* All of these symbols are given type STT_SECTION by the
10848 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
10849 sym
->st_other
= STO_PROTECTED
;
10851 /* The IRIX linker puts these symbols in special sections. */
10853 sym
->st_shndx
= SHN_MIPS_TEXT
;
10855 sym
->st_shndx
= SHN_MIPS_DATA
;
10861 /* Finish up dynamic symbol handling. We set the contents of various
10862 dynamic sections here. */
10865 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
10866 struct bfd_link_info
*info
,
10867 struct elf_link_hash_entry
*h
,
10868 Elf_Internal_Sym
*sym
)
10872 struct mips_got_info
*g
, *gg
;
10875 struct mips_elf_link_hash_table
*htab
;
10876 struct mips_elf_link_hash_entry
*hmips
;
10878 htab
= mips_elf_hash_table (info
);
10879 BFD_ASSERT (htab
!= NULL
);
10880 dynobj
= elf_hash_table (info
)->dynobj
;
10881 hmips
= (struct mips_elf_link_hash_entry
*) h
;
10883 BFD_ASSERT (htab
->root
.target_os
!= is_vxworks
);
10885 if (h
->plt
.plist
!= NULL
10886 && (h
->plt
.plist
->mips_offset
!= MINUS_ONE
10887 || h
->plt
.plist
->comp_offset
!= MINUS_ONE
))
10889 /* We've decided to create a PLT entry for this symbol. */
10891 bfd_vma header_address
, got_address
;
10892 bfd_vma got_address_high
, got_address_low
, load
;
10896 got_index
= h
->plt
.plist
->gotplt_index
;
10898 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10899 BFD_ASSERT (h
->dynindx
!= -1);
10900 BFD_ASSERT (htab
->root
.splt
!= NULL
);
10901 BFD_ASSERT (got_index
!= MINUS_ONE
);
10902 BFD_ASSERT (!h
->def_regular
);
10904 /* Calculate the address of the PLT header. */
10905 isa_bit
= htab
->plt_header_is_comp
;
10906 header_address
= (htab
->root
.splt
->output_section
->vma
10907 + htab
->root
.splt
->output_offset
+ isa_bit
);
10909 /* Calculate the address of the .got.plt entry. */
10910 got_address
= (htab
->root
.sgotplt
->output_section
->vma
10911 + htab
->root
.sgotplt
->output_offset
10912 + got_index
* MIPS_ELF_GOT_SIZE (dynobj
));
10914 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
10915 got_address_low
= got_address
& 0xffff;
10917 /* The PLT sequence is not safe for N64 if .got.plt entry's address
10918 cannot be loaded in two instructions. */
10919 if (ABI_64_P (output_bfd
)
10920 && ((got_address
+ 0x80008000) & ~(bfd_vma
) 0xffffffff) != 0)
10923 /* xgettext:c-format */
10924 (_("%pB: `%pA' entry VMA of %#" PRIx64
" outside the 32-bit range "
10925 "supported; consider using `-Ttext-segment=...'"),
10927 htab
->root
.sgotplt
->output_section
,
10928 (int64_t) got_address
);
10929 bfd_set_error (bfd_error_no_error
);
10933 /* Initially point the .got.plt entry at the PLT header. */
10934 loc
= (htab
->root
.sgotplt
->contents
10935 + got_index
* MIPS_ELF_GOT_SIZE (dynobj
));
10936 if (ABI_64_P (output_bfd
))
10937 bfd_put_64 (output_bfd
, header_address
, loc
);
10939 bfd_put_32 (output_bfd
, header_address
, loc
);
10941 /* Now handle the PLT itself. First the standard entry (the order
10942 does not matter, we just have to pick one). */
10943 if (h
->plt
.plist
->mips_offset
!= MINUS_ONE
)
10945 const bfd_vma
*plt_entry
;
10946 bfd_vma plt_offset
;
10948 plt_offset
= htab
->plt_header_size
+ h
->plt
.plist
->mips_offset
;
10950 BFD_ASSERT (plt_offset
<= htab
->root
.splt
->size
);
10952 /* Find out where the .plt entry should go. */
10953 loc
= htab
->root
.splt
->contents
+ plt_offset
;
10955 /* Pick the load opcode. */
10956 load
= MIPS_ELF_LOAD_WORD (output_bfd
);
10958 /* Fill in the PLT entry itself. */
10960 if (MIPSR6_P (output_bfd
))
10961 plt_entry
= htab
->compact_branches
? mipsr6_exec_plt_entry_compact
10962 : mipsr6_exec_plt_entry
;
10964 plt_entry
= mips_exec_plt_entry
;
10965 bfd_put_32 (output_bfd
, plt_entry
[0] | got_address_high
, loc
);
10966 bfd_put_32 (output_bfd
, plt_entry
[1] | got_address_low
| load
,
10969 if (! LOAD_INTERLOCKS_P (output_bfd
)
10970 || (MIPSR6_P (output_bfd
) && htab
->compact_branches
))
10972 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
, loc
+ 8);
10973 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
10977 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 8);
10978 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
,
10983 /* Now the compressed entry. They come after any standard ones. */
10984 if (h
->plt
.plist
->comp_offset
!= MINUS_ONE
)
10986 bfd_vma plt_offset
;
10988 plt_offset
= (htab
->plt_header_size
+ htab
->plt_mips_offset
10989 + h
->plt
.plist
->comp_offset
);
10991 BFD_ASSERT (plt_offset
<= htab
->root
.splt
->size
);
10993 /* Find out where the .plt entry should go. */
10994 loc
= htab
->root
.splt
->contents
+ plt_offset
;
10996 /* Fill in the PLT entry itself. */
10997 if (!MICROMIPS_P (output_bfd
))
10999 const bfd_vma
*plt_entry
= mips16_o32_exec_plt_entry
;
11001 bfd_put_16 (output_bfd
, plt_entry
[0], loc
);
11002 bfd_put_16 (output_bfd
, plt_entry
[1], loc
+ 2);
11003 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
11004 bfd_put_16 (output_bfd
, plt_entry
[3], loc
+ 6);
11005 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
11006 bfd_put_16 (output_bfd
, plt_entry
[5], loc
+ 10);
11007 bfd_put_32 (output_bfd
, got_address
, loc
+ 12);
11009 else if (htab
->insn32
)
11011 const bfd_vma
*plt_entry
= micromips_insn32_o32_exec_plt_entry
;
11013 bfd_put_16 (output_bfd
, plt_entry
[0], loc
);
11014 bfd_put_16 (output_bfd
, got_address_high
, loc
+ 2);
11015 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
11016 bfd_put_16 (output_bfd
, got_address_low
, loc
+ 6);
11017 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
11018 bfd_put_16 (output_bfd
, plt_entry
[5], loc
+ 10);
11019 bfd_put_16 (output_bfd
, plt_entry
[6], loc
+ 12);
11020 bfd_put_16 (output_bfd
, got_address_low
, loc
+ 14);
11024 const bfd_vma
*plt_entry
= micromips_o32_exec_plt_entry
;
11025 bfd_signed_vma gotpc_offset
;
11026 bfd_vma loc_address
;
11028 BFD_ASSERT (got_address
% 4 == 0);
11030 loc_address
= (htab
->root
.splt
->output_section
->vma
11031 + htab
->root
.splt
->output_offset
+ plt_offset
);
11032 gotpc_offset
= got_address
- ((loc_address
| 3) ^ 3);
11034 /* ADDIUPC has a span of +/-16MB, check we're in range. */
11035 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
11038 /* xgettext:c-format */
11039 (_("%pB: `%pA' offset of %" PRId64
" from `%pA' "
11040 "beyond the range of ADDIUPC"),
11042 htab
->root
.sgotplt
->output_section
,
11043 (int64_t) gotpc_offset
,
11044 htab
->root
.splt
->output_section
);
11045 bfd_set_error (bfd_error_no_error
);
11048 bfd_put_16 (output_bfd
,
11049 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f), loc
);
11050 bfd_put_16 (output_bfd
, (gotpc_offset
>> 2) & 0xffff, loc
+ 2);
11051 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
11052 bfd_put_16 (output_bfd
, plt_entry
[3], loc
+ 6);
11053 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
11054 bfd_put_16 (output_bfd
, plt_entry
[5], loc
+ 10);
11058 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
11059 mips_elf_output_dynamic_relocation (output_bfd
, htab
->root
.srelplt
,
11060 got_index
- 2, h
->dynindx
,
11061 R_MIPS_JUMP_SLOT
, got_address
);
11063 /* We distinguish between PLT entries and lazy-binding stubs by
11064 giving the former an st_other value of STO_MIPS_PLT. Set the
11065 flag and leave the value if there are any relocations in the
11066 binary where pointer equality matters. */
11067 sym
->st_shndx
= SHN_UNDEF
;
11068 if (h
->pointer_equality_needed
)
11069 sym
->st_other
= ELF_ST_SET_MIPS_PLT (sym
->st_other
);
11077 if (h
->plt
.plist
!= NULL
&& h
->plt
.plist
->stub_offset
!= MINUS_ONE
)
11079 /* We've decided to create a lazy-binding stub. */
11080 bfd_boolean micromips_p
= MICROMIPS_P (output_bfd
);
11081 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
11082 bfd_vma stub_size
= htab
->function_stub_size
;
11083 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
11084 bfd_vma isa_bit
= micromips_p
;
11085 bfd_vma stub_big_size
;
11088 stub_big_size
= MIPS_FUNCTION_STUB_BIG_SIZE
;
11089 else if (htab
->insn32
)
11090 stub_big_size
= MICROMIPS_INSN32_FUNCTION_STUB_BIG_SIZE
;
11092 stub_big_size
= MICROMIPS_FUNCTION_STUB_BIG_SIZE
;
11094 /* This symbol has a stub. Set it up. */
11096 BFD_ASSERT (h
->dynindx
!= -1);
11098 BFD_ASSERT (stub_size
== stub_big_size
|| h
->dynindx
<= 0xffff);
11100 /* Values up to 2^31 - 1 are allowed. Larger values would cause
11101 sign extension at runtime in the stub, resulting in a negative
11103 if (h
->dynindx
& ~0x7fffffff)
11106 /* Fill the stub. */
11110 bfd_put_micromips_32 (output_bfd
, STUB_LW_MICROMIPS (output_bfd
),
11115 bfd_put_micromips_32 (output_bfd
,
11116 STUB_MOVE32_MICROMIPS
, stub
+ idx
);
11121 bfd_put_16 (output_bfd
, STUB_MOVE_MICROMIPS
, stub
+ idx
);
11124 if (stub_size
== stub_big_size
)
11126 long dynindx_hi
= (h
->dynindx
>> 16) & 0x7fff;
11128 bfd_put_micromips_32 (output_bfd
,
11129 STUB_LUI_MICROMIPS (dynindx_hi
),
11135 bfd_put_micromips_32 (output_bfd
, STUB_JALR32_MICROMIPS
,
11141 bfd_put_16 (output_bfd
, STUB_JALR_MICROMIPS
, stub
+ idx
);
11145 /* If a large stub is not required and sign extension is not a
11146 problem, then use legacy code in the stub. */
11147 if (stub_size
== stub_big_size
)
11148 bfd_put_micromips_32 (output_bfd
,
11149 STUB_ORI_MICROMIPS (h
->dynindx
& 0xffff),
11151 else if (h
->dynindx
& ~0x7fff)
11152 bfd_put_micromips_32 (output_bfd
,
11153 STUB_LI16U_MICROMIPS (h
->dynindx
& 0xffff),
11156 bfd_put_micromips_32 (output_bfd
,
11157 STUB_LI16S_MICROMIPS (output_bfd
,
11164 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
11166 bfd_put_32 (output_bfd
, STUB_MOVE
, stub
+ idx
);
11168 if (stub_size
== stub_big_size
)
11170 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
11175 if (!(MIPSR6_P (output_bfd
) && htab
->compact_branches
))
11177 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
11181 /* If a large stub is not required and sign extension is not a
11182 problem, then use legacy code in the stub. */
11183 if (stub_size
== stub_big_size
)
11184 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff),
11186 else if (h
->dynindx
& ~0x7fff)
11187 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff),
11190 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
11194 if (MIPSR6_P (output_bfd
) && htab
->compact_branches
)
11195 bfd_put_32 (output_bfd
, STUB_JALRC
, stub
+ idx
);
11198 BFD_ASSERT (h
->plt
.plist
->stub_offset
<= htab
->sstubs
->size
);
11199 memcpy (htab
->sstubs
->contents
+ h
->plt
.plist
->stub_offset
,
11202 /* Mark the symbol as undefined. stub_offset != -1 occurs
11203 only for the referenced symbol. */
11204 sym
->st_shndx
= SHN_UNDEF
;
11206 /* The run-time linker uses the st_value field of the symbol
11207 to reset the global offset table entry for this external
11208 to its stub address when unlinking a shared object. */
11209 sym
->st_value
= (htab
->sstubs
->output_section
->vma
11210 + htab
->sstubs
->output_offset
11211 + h
->plt
.plist
->stub_offset
11213 sym
->st_other
= other
;
11216 /* If we have a MIPS16 function with a stub, the dynamic symbol must
11217 refer to the stub, since only the stub uses the standard calling
11219 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
11221 BFD_ASSERT (hmips
->need_fn_stub
);
11222 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
11223 + hmips
->fn_stub
->output_offset
);
11224 sym
->st_size
= hmips
->fn_stub
->size
;
11225 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
11228 BFD_ASSERT (h
->dynindx
!= -1
11229 || h
->forced_local
);
11231 sgot
= htab
->root
.sgot
;
11232 g
= htab
->got_info
;
11233 BFD_ASSERT (g
!= NULL
);
11235 /* Run through the global symbol table, creating GOT entries for all
11236 the symbols that need them. */
11237 if (hmips
->global_got_area
!= GGA_NONE
)
11242 value
= sym
->st_value
;
11243 offset
= mips_elf_primary_global_got_index (output_bfd
, info
, h
);
11244 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
11247 if (hmips
->global_got_area
!= GGA_NONE
&& g
->next
)
11249 struct mips_got_entry e
, *p
;
11255 e
.abfd
= output_bfd
;
11258 e
.tls_type
= GOT_TLS_NONE
;
11260 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
11263 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
11266 offset
= p
->gotidx
;
11267 BFD_ASSERT (offset
> 0 && offset
< htab
->root
.sgot
->size
);
11268 if (bfd_link_pic (info
)
11269 || (elf_hash_table (info
)->dynamic_sections_created
11271 && p
->d
.h
->root
.def_dynamic
11272 && !p
->d
.h
->root
.def_regular
))
11274 /* Create an R_MIPS_REL32 relocation for this entry. Due to
11275 the various compatibility problems, it's easier to mock
11276 up an R_MIPS_32 or R_MIPS_64 relocation and leave
11277 mips_elf_create_dynamic_relocation to calculate the
11278 appropriate addend. */
11279 Elf_Internal_Rela rel
[3];
11281 memset (rel
, 0, sizeof (rel
));
11282 if (ABI_64_P (output_bfd
))
11283 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
11285 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
11286 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
11289 if (! (mips_elf_create_dynamic_relocation
11290 (output_bfd
, info
, rel
,
11291 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
11295 entry
= sym
->st_value
;
11296 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
11301 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
11302 name
= h
->root
.root
.string
;
11303 if (h
== elf_hash_table (info
)->hdynamic
11304 || h
== elf_hash_table (info
)->hgot
)
11305 sym
->st_shndx
= SHN_ABS
;
11306 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
11307 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
11309 sym
->st_shndx
= SHN_ABS
;
11310 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
11313 else if (SGI_COMPAT (output_bfd
))
11315 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
11316 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
11318 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
11319 sym
->st_other
= STO_PROTECTED
;
11321 sym
->st_shndx
= SHN_MIPS_DATA
;
11323 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
11325 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
11326 sym
->st_other
= STO_PROTECTED
;
11327 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
11328 sym
->st_shndx
= SHN_ABS
;
11330 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
11332 if (h
->type
== STT_FUNC
)
11333 sym
->st_shndx
= SHN_MIPS_TEXT
;
11334 else if (h
->type
== STT_OBJECT
)
11335 sym
->st_shndx
= SHN_MIPS_DATA
;
11339 /* Emit a copy reloc, if needed. */
11345 BFD_ASSERT (h
->dynindx
!= -1);
11346 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11348 s
= mips_elf_rel_dyn_section (info
, FALSE
);
11349 symval
= (h
->root
.u
.def
.section
->output_section
->vma
11350 + h
->root
.u
.def
.section
->output_offset
11351 + h
->root
.u
.def
.value
);
11352 mips_elf_output_dynamic_relocation (output_bfd
, s
, s
->reloc_count
++,
11353 h
->dynindx
, R_MIPS_COPY
, symval
);
11356 /* Handle the IRIX6-specific symbols. */
11357 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
11358 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
11360 /* Keep dynamic compressed symbols odd. This allows the dynamic linker
11361 to treat compressed symbols like any other. */
11362 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
11364 BFD_ASSERT (sym
->st_value
& 1);
11365 sym
->st_other
-= STO_MIPS16
;
11367 else if (ELF_ST_IS_MICROMIPS (sym
->st_other
))
11369 BFD_ASSERT (sym
->st_value
& 1);
11370 sym
->st_other
-= STO_MICROMIPS
;
11376 /* Likewise, for VxWorks. */
11379 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
11380 struct bfd_link_info
*info
,
11381 struct elf_link_hash_entry
*h
,
11382 Elf_Internal_Sym
*sym
)
11386 struct mips_got_info
*g
;
11387 struct mips_elf_link_hash_table
*htab
;
11388 struct mips_elf_link_hash_entry
*hmips
;
11390 htab
= mips_elf_hash_table (info
);
11391 BFD_ASSERT (htab
!= NULL
);
11392 dynobj
= elf_hash_table (info
)->dynobj
;
11393 hmips
= (struct mips_elf_link_hash_entry
*) h
;
11395 if (h
->plt
.plist
!= NULL
&& h
->plt
.plist
->mips_offset
!= MINUS_ONE
)
11398 bfd_vma plt_address
, got_address
, got_offset
, branch_offset
;
11399 Elf_Internal_Rela rel
;
11400 static const bfd_vma
*plt_entry
;
11401 bfd_vma gotplt_index
;
11402 bfd_vma plt_offset
;
11404 plt_offset
= htab
->plt_header_size
+ h
->plt
.plist
->mips_offset
;
11405 gotplt_index
= h
->plt
.plist
->gotplt_index
;
11407 BFD_ASSERT (h
->dynindx
!= -1);
11408 BFD_ASSERT (htab
->root
.splt
!= NULL
);
11409 BFD_ASSERT (gotplt_index
!= MINUS_ONE
);
11410 BFD_ASSERT (plt_offset
<= htab
->root
.splt
->size
);
11412 /* Calculate the address of the .plt entry. */
11413 plt_address
= (htab
->root
.splt
->output_section
->vma
11414 + htab
->root
.splt
->output_offset
11417 /* Calculate the address of the .got.plt entry. */
11418 got_address
= (htab
->root
.sgotplt
->output_section
->vma
11419 + htab
->root
.sgotplt
->output_offset
11420 + gotplt_index
* MIPS_ELF_GOT_SIZE (output_bfd
));
11422 /* Calculate the offset of the .got.plt entry from
11423 _GLOBAL_OFFSET_TABLE_. */
11424 got_offset
= mips_elf_gotplt_index (info
, h
);
11426 /* Calculate the offset for the branch at the start of the PLT
11427 entry. The branch jumps to the beginning of .plt. */
11428 branch_offset
= -(plt_offset
/ 4 + 1) & 0xffff;
11430 /* Fill in the initial value of the .got.plt entry. */
11431 bfd_put_32 (output_bfd
, plt_address
,
11432 (htab
->root
.sgotplt
->contents
11433 + gotplt_index
* MIPS_ELF_GOT_SIZE (output_bfd
)));
11435 /* Find out where the .plt entry should go. */
11436 loc
= htab
->root
.splt
->contents
+ plt_offset
;
11438 if (bfd_link_pic (info
))
11440 plt_entry
= mips_vxworks_shared_plt_entry
;
11441 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
11442 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_index
, loc
+ 4);
11446 bfd_vma got_address_high
, got_address_low
;
11448 plt_entry
= mips_vxworks_exec_plt_entry
;
11449 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
11450 got_address_low
= got_address
& 0xffff;
11452 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
11453 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_index
, loc
+ 4);
11454 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
11455 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
11456 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
11457 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
11458 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
11459 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
11461 loc
= (htab
->srelplt2
->contents
11462 + (gotplt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
11464 /* Emit a relocation for the .got.plt entry. */
11465 rel
.r_offset
= got_address
;
11466 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
11467 rel
.r_addend
= plt_offset
;
11468 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11470 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
11471 loc
+= sizeof (Elf32_External_Rela
);
11472 rel
.r_offset
= plt_address
+ 8;
11473 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
11474 rel
.r_addend
= got_offset
;
11475 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11477 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
11478 loc
+= sizeof (Elf32_External_Rela
);
11480 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
11481 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11484 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
11485 loc
= (htab
->root
.srelplt
->contents
11486 + gotplt_index
* sizeof (Elf32_External_Rela
));
11487 rel
.r_offset
= got_address
;
11488 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
11490 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11492 if (!h
->def_regular
)
11493 sym
->st_shndx
= SHN_UNDEF
;
11496 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
11498 sgot
= htab
->root
.sgot
;
11499 g
= htab
->got_info
;
11500 BFD_ASSERT (g
!= NULL
);
11502 /* See if this symbol has an entry in the GOT. */
11503 if (hmips
->global_got_area
!= GGA_NONE
)
11506 Elf_Internal_Rela outrel
;
11510 /* Install the symbol value in the GOT. */
11511 offset
= mips_elf_primary_global_got_index (output_bfd
, info
, h
);
11512 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
11514 /* Add a dynamic relocation for it. */
11515 s
= mips_elf_rel_dyn_section (info
, FALSE
);
11516 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
11517 outrel
.r_offset
= (sgot
->output_section
->vma
11518 + sgot
->output_offset
11520 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
11521 outrel
.r_addend
= 0;
11522 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
11525 /* Emit a copy reloc, if needed. */
11528 Elf_Internal_Rela rel
;
11532 BFD_ASSERT (h
->dynindx
!= -1);
11534 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
11535 + h
->root
.u
.def
.section
->output_offset
11536 + h
->root
.u
.def
.value
);
11537 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
11539 if (h
->root
.u
.def
.section
== htab
->root
.sdynrelro
)
11540 srel
= htab
->root
.sreldynrelro
;
11542 srel
= htab
->root
.srelbss
;
11543 loc
= srel
->contents
+ srel
->reloc_count
* sizeof (Elf32_External_Rela
);
11544 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11545 ++srel
->reloc_count
;
11548 /* If this is a mips16/microMIPS symbol, force the value to be even. */
11549 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
11550 sym
->st_value
&= ~1;
11555 /* Write out a plt0 entry to the beginning of .plt. */
11558 mips_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
11561 bfd_vma gotplt_value
, gotplt_value_high
, gotplt_value_low
;
11562 static const bfd_vma
*plt_entry
;
11563 struct mips_elf_link_hash_table
*htab
;
11565 htab
= mips_elf_hash_table (info
);
11566 BFD_ASSERT (htab
!= NULL
);
11568 if (ABI_64_P (output_bfd
))
11569 plt_entry
= (htab
->compact_branches
11570 ? mipsr6_n64_exec_plt0_entry_compact
11571 : mips_n64_exec_plt0_entry
);
11572 else if (ABI_N32_P (output_bfd
))
11573 plt_entry
= (htab
->compact_branches
11574 ? mipsr6_n32_exec_plt0_entry_compact
11575 : mips_n32_exec_plt0_entry
);
11576 else if (!htab
->plt_header_is_comp
)
11577 plt_entry
= (htab
->compact_branches
11578 ? mipsr6_o32_exec_plt0_entry_compact
11579 : mips_o32_exec_plt0_entry
);
11580 else if (htab
->insn32
)
11581 plt_entry
= micromips_insn32_o32_exec_plt0_entry
;
11583 plt_entry
= micromips_o32_exec_plt0_entry
;
11585 /* Calculate the value of .got.plt. */
11586 gotplt_value
= (htab
->root
.sgotplt
->output_section
->vma
11587 + htab
->root
.sgotplt
->output_offset
);
11588 gotplt_value_high
= ((gotplt_value
+ 0x8000) >> 16) & 0xffff;
11589 gotplt_value_low
= gotplt_value
& 0xffff;
11591 /* The PLT sequence is not safe for N64 if .got.plt's address can
11592 not be loaded in two instructions. */
11593 if (ABI_64_P (output_bfd
)
11594 && ((gotplt_value
+ 0x80008000) & ~(bfd_vma
) 0xffffffff) != 0)
11597 /* xgettext:c-format */
11598 (_("%pB: `%pA' start VMA of %#" PRIx64
" outside the 32-bit range "
11599 "supported; consider using `-Ttext-segment=...'"),
11601 htab
->root
.sgotplt
->output_section
,
11602 (int64_t) gotplt_value
);
11603 bfd_set_error (bfd_error_no_error
);
11607 /* Install the PLT header. */
11608 loc
= htab
->root
.splt
->contents
;
11609 if (plt_entry
== micromips_o32_exec_plt0_entry
)
11611 bfd_vma gotpc_offset
;
11612 bfd_vma loc_address
;
11615 BFD_ASSERT (gotplt_value
% 4 == 0);
11617 loc_address
= (htab
->root
.splt
->output_section
->vma
11618 + htab
->root
.splt
->output_offset
);
11619 gotpc_offset
= gotplt_value
- ((loc_address
| 3) ^ 3);
11621 /* ADDIUPC has a span of +/-16MB, check we're in range. */
11622 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
11625 /* xgettext:c-format */
11626 (_("%pB: `%pA' offset of %" PRId64
" from `%pA' "
11627 "beyond the range of ADDIUPC"),
11629 htab
->root
.sgotplt
->output_section
,
11630 (int64_t) gotpc_offset
,
11631 htab
->root
.splt
->output_section
);
11632 bfd_set_error (bfd_error_no_error
);
11635 bfd_put_16 (output_bfd
,
11636 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f), loc
);
11637 bfd_put_16 (output_bfd
, (gotpc_offset
>> 2) & 0xffff, loc
+ 2);
11638 for (i
= 2; i
< ARRAY_SIZE (micromips_o32_exec_plt0_entry
); i
++)
11639 bfd_put_16 (output_bfd
, plt_entry
[i
], loc
+ (i
* 2));
11641 else if (plt_entry
== micromips_insn32_o32_exec_plt0_entry
)
11645 bfd_put_16 (output_bfd
, plt_entry
[0], loc
);
11646 bfd_put_16 (output_bfd
, gotplt_value_high
, loc
+ 2);
11647 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
11648 bfd_put_16 (output_bfd
, gotplt_value_low
, loc
+ 6);
11649 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
11650 bfd_put_16 (output_bfd
, gotplt_value_low
, loc
+ 10);
11651 for (i
= 6; i
< ARRAY_SIZE (micromips_insn32_o32_exec_plt0_entry
); i
++)
11652 bfd_put_16 (output_bfd
, plt_entry
[i
], loc
+ (i
* 2));
11656 bfd_put_32 (output_bfd
, plt_entry
[0] | gotplt_value_high
, loc
);
11657 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_value_low
, loc
+ 4);
11658 bfd_put_32 (output_bfd
, plt_entry
[2] | gotplt_value_low
, loc
+ 8);
11659 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
11660 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
11661 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
11662 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
11663 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
11669 /* Install the PLT header for a VxWorks executable and finalize the
11670 contents of .rela.plt.unloaded. */
11673 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
11675 Elf_Internal_Rela rela
;
11677 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
11678 static const bfd_vma
*plt_entry
;
11679 struct mips_elf_link_hash_table
*htab
;
11681 htab
= mips_elf_hash_table (info
);
11682 BFD_ASSERT (htab
!= NULL
);
11684 plt_entry
= mips_vxworks_exec_plt0_entry
;
11686 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
11687 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
11688 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
11689 + htab
->root
.hgot
->root
.u
.def
.value
);
11691 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
11692 got_value_low
= got_value
& 0xffff;
11694 /* Calculate the address of the PLT header. */
11695 plt_address
= (htab
->root
.splt
->output_section
->vma
11696 + htab
->root
.splt
->output_offset
);
11698 /* Install the PLT header. */
11699 loc
= htab
->root
.splt
->contents
;
11700 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
11701 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
11702 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
11703 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
11704 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
11705 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
11707 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
11708 loc
= htab
->srelplt2
->contents
;
11709 rela
.r_offset
= plt_address
;
11710 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
11712 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
11713 loc
+= sizeof (Elf32_External_Rela
);
11715 /* Output the relocation for the following addiu of
11716 %lo(_GLOBAL_OFFSET_TABLE_). */
11717 rela
.r_offset
+= 4;
11718 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
11719 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
11720 loc
+= sizeof (Elf32_External_Rela
);
11722 /* Fix up the remaining relocations. They may have the wrong
11723 symbol index for _G_O_T_ or _P_L_T_ depending on the order
11724 in which symbols were output. */
11725 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
11727 Elf_Internal_Rela rel
;
11729 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
11730 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
11731 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11732 loc
+= sizeof (Elf32_External_Rela
);
11734 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
11735 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
11736 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11737 loc
+= sizeof (Elf32_External_Rela
);
11739 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
11740 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
11741 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11742 loc
+= sizeof (Elf32_External_Rela
);
11746 /* Install the PLT header for a VxWorks shared library. */
11749 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
11752 struct mips_elf_link_hash_table
*htab
;
11754 htab
= mips_elf_hash_table (info
);
11755 BFD_ASSERT (htab
!= NULL
);
11757 /* We just need to copy the entry byte-by-byte. */
11758 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
11759 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
11760 htab
->root
.splt
->contents
+ i
* 4);
11763 /* Finish up the dynamic sections. */
11766 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
11767 struct bfd_link_info
*info
)
11772 struct mips_got_info
*gg
, *g
;
11773 struct mips_elf_link_hash_table
*htab
;
11775 htab
= mips_elf_hash_table (info
);
11776 BFD_ASSERT (htab
!= NULL
);
11778 dynobj
= elf_hash_table (info
)->dynobj
;
11780 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
11782 sgot
= htab
->root
.sgot
;
11783 gg
= htab
->got_info
;
11785 if (elf_hash_table (info
)->dynamic_sections_created
)
11788 int dyn_to_skip
= 0, dyn_skipped
= 0;
11790 BFD_ASSERT (sdyn
!= NULL
);
11791 BFD_ASSERT (gg
!= NULL
);
11793 g
= mips_elf_bfd_got (output_bfd
, FALSE
);
11794 BFD_ASSERT (g
!= NULL
);
11796 for (b
= sdyn
->contents
;
11797 b
< sdyn
->contents
+ sdyn
->size
;
11798 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
11800 Elf_Internal_Dyn dyn
;
11804 bfd_boolean swap_out_p
;
11806 /* Read in the current dynamic entry. */
11807 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
11809 /* Assume that we're going to modify it and write it out. */
11815 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
11819 BFD_ASSERT (htab
->root
.target_os
== is_vxworks
);
11820 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
11824 /* Rewrite DT_STRSZ. */
11826 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
11830 s
= htab
->root
.sgot
;
11831 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11834 case DT_MIPS_PLTGOT
:
11835 s
= htab
->root
.sgotplt
;
11836 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11839 case DT_MIPS_RLD_VERSION
:
11840 dyn
.d_un
.d_val
= 1; /* XXX */
11843 case DT_MIPS_FLAGS
:
11844 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
11847 case DT_MIPS_TIME_STAMP
:
11851 dyn
.d_un
.d_val
= t
;
11855 case DT_MIPS_ICHECKSUM
:
11857 swap_out_p
= FALSE
;
11860 case DT_MIPS_IVERSION
:
11862 swap_out_p
= FALSE
;
11865 case DT_MIPS_BASE_ADDRESS
:
11866 s
= output_bfd
->sections
;
11867 BFD_ASSERT (s
!= NULL
);
11868 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
11871 case DT_MIPS_LOCAL_GOTNO
:
11872 dyn
.d_un
.d_val
= g
->local_gotno
;
11875 case DT_MIPS_UNREFEXTNO
:
11876 /* The index into the dynamic symbol table which is the
11877 entry of the first external symbol that is not
11878 referenced within the same object. */
11879 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
11882 case DT_MIPS_GOTSYM
:
11883 if (htab
->global_gotsym
)
11885 dyn
.d_un
.d_val
= htab
->global_gotsym
->dynindx
;
11888 /* In case if we don't have global got symbols we default
11889 to setting DT_MIPS_GOTSYM to the same value as
11890 DT_MIPS_SYMTABNO. */
11891 /* Fall through. */
11893 case DT_MIPS_SYMTABNO
:
11895 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
11896 s
= bfd_get_linker_section (dynobj
, name
);
11899 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
11901 dyn
.d_un
.d_val
= 0;
11904 case DT_MIPS_HIPAGENO
:
11905 dyn
.d_un
.d_val
= g
->local_gotno
- htab
->reserved_gotno
;
11908 case DT_MIPS_RLD_MAP
:
11910 struct elf_link_hash_entry
*h
;
11911 h
= mips_elf_hash_table (info
)->rld_symbol
;
11914 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
11915 swap_out_p
= FALSE
;
11918 s
= h
->root
.u
.def
.section
;
11920 /* The MIPS_RLD_MAP tag stores the absolute address of the
11922 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
11923 + h
->root
.u
.def
.value
);
11927 case DT_MIPS_RLD_MAP_REL
:
11929 struct elf_link_hash_entry
*h
;
11930 bfd_vma dt_addr
, rld_addr
;
11931 h
= mips_elf_hash_table (info
)->rld_symbol
;
11934 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
11935 swap_out_p
= FALSE
;
11938 s
= h
->root
.u
.def
.section
;
11940 /* The MIPS_RLD_MAP_REL tag stores the offset to the debug
11941 pointer, relative to the address of the tag. */
11942 dt_addr
= (sdyn
->output_section
->vma
+ sdyn
->output_offset
11943 + (b
- sdyn
->contents
));
11944 rld_addr
= (s
->output_section
->vma
+ s
->output_offset
11945 + h
->root
.u
.def
.value
);
11946 dyn
.d_un
.d_ptr
= rld_addr
- dt_addr
;
11950 case DT_MIPS_OPTIONS
:
11951 s
= (bfd_get_section_by_name
11952 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
11953 dyn
.d_un
.d_ptr
= s
->vma
;
11957 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11958 if (htab
->root
.target_os
== is_vxworks
)
11959 dyn
.d_un
.d_val
= DT_RELA
;
11961 dyn
.d_un
.d_val
= DT_REL
;
11965 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11966 dyn
.d_un
.d_val
= htab
->root
.srelplt
->size
;
11970 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11971 dyn
.d_un
.d_ptr
= (htab
->root
.srelplt
->output_section
->vma
11972 + htab
->root
.srelplt
->output_offset
);
11976 /* If we didn't need any text relocations after all, delete
11977 the dynamic tag. */
11978 if (!(info
->flags
& DF_TEXTREL
))
11980 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
11981 swap_out_p
= FALSE
;
11986 /* If we didn't need any text relocations after all, clear
11987 DF_TEXTREL from DT_FLAGS. */
11988 if (!(info
->flags
& DF_TEXTREL
))
11989 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
11991 swap_out_p
= FALSE
;
11994 case DT_MIPS_XHASH
:
11995 name
= ".MIPS.xhash";
11996 s
= bfd_get_linker_section (dynobj
, name
);
11997 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
12001 swap_out_p
= FALSE
;
12002 if (htab
->root
.target_os
== is_vxworks
12003 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
12008 if (swap_out_p
|| dyn_skipped
)
12009 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
12010 (dynobj
, &dyn
, b
- dyn_skipped
);
12014 dyn_skipped
+= dyn_to_skip
;
12019 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
12020 if (dyn_skipped
> 0)
12021 memset (b
- dyn_skipped
, 0, dyn_skipped
);
12024 if (sgot
!= NULL
&& sgot
->size
> 0
12025 && !bfd_is_abs_section (sgot
->output_section
))
12027 if (htab
->root
.target_os
== is_vxworks
)
12029 /* The first entry of the global offset table points to the
12030 ".dynamic" section. The second is initialized by the
12031 loader and contains the shared library identifier.
12032 The third is also initialized by the loader and points
12033 to the lazy resolution stub. */
12034 MIPS_ELF_PUT_WORD (output_bfd
,
12035 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
12037 MIPS_ELF_PUT_WORD (output_bfd
, 0,
12038 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
12039 MIPS_ELF_PUT_WORD (output_bfd
, 0,
12041 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
12045 /* The first entry of the global offset table will be filled at
12046 runtime. The second entry will be used by some runtime loaders.
12047 This isn't the case of IRIX rld. */
12048 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
12049 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
12050 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
12053 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
12054 = MIPS_ELF_GOT_SIZE (output_bfd
);
12057 /* Generate dynamic relocations for the non-primary gots. */
12058 if (gg
!= NULL
&& gg
->next
)
12060 Elf_Internal_Rela rel
[3];
12061 bfd_vma addend
= 0;
12063 memset (rel
, 0, sizeof (rel
));
12064 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
12066 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
12068 bfd_vma got_index
= g
->next
->local_gotno
+ g
->next
->global_gotno
12069 + g
->next
->tls_gotno
;
12071 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
12072 + got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
12073 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
12075 + got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
12077 if (! bfd_link_pic (info
))
12080 for (; got_index
< g
->local_gotno
; got_index
++)
12082 if (got_index
>= g
->assigned_low_gotno
12083 && got_index
<= g
->assigned_high_gotno
)
12086 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
12087 = got_index
* MIPS_ELF_GOT_SIZE (output_bfd
);
12088 if (!(mips_elf_create_dynamic_relocation
12089 (output_bfd
, info
, rel
, NULL
,
12090 bfd_abs_section_ptr
,
12091 0, &addend
, sgot
)))
12093 BFD_ASSERT (addend
== 0);
12098 /* The generation of dynamic relocations for the non-primary gots
12099 adds more dynamic relocations. We cannot count them until
12102 if (elf_hash_table (info
)->dynamic_sections_created
)
12105 bfd_boolean swap_out_p
;
12107 BFD_ASSERT (sdyn
!= NULL
);
12109 for (b
= sdyn
->contents
;
12110 b
< sdyn
->contents
+ sdyn
->size
;
12111 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
12113 Elf_Internal_Dyn dyn
;
12116 /* Read in the current dynamic entry. */
12117 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
12119 /* Assume that we're going to modify it and write it out. */
12125 /* Reduce DT_RELSZ to account for any relocations we
12126 decided not to make. This is for the n64 irix rld,
12127 which doesn't seem to apply any relocations if there
12128 are trailing null entries. */
12129 s
= mips_elf_rel_dyn_section (info
, FALSE
);
12130 dyn
.d_un
.d_val
= (s
->reloc_count
12131 * (ABI_64_P (output_bfd
)
12132 ? sizeof (Elf64_Mips_External_Rel
)
12133 : sizeof (Elf32_External_Rel
)));
12134 /* Adjust the section size too. Tools like the prelinker
12135 can reasonably expect the values to the same. */
12136 BFD_ASSERT (!bfd_is_abs_section (s
->output_section
));
12137 elf_section_data (s
->output_section
)->this_hdr
.sh_size
12142 swap_out_p
= FALSE
;
12147 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
12154 Elf32_compact_rel cpt
;
12156 if (SGI_COMPAT (output_bfd
))
12158 /* Write .compact_rel section out. */
12159 s
= bfd_get_linker_section (dynobj
, ".compact_rel");
12163 cpt
.num
= s
->reloc_count
;
12165 cpt
.offset
= (s
->output_section
->filepos
12166 + sizeof (Elf32_External_compact_rel
));
12169 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
12170 ((Elf32_External_compact_rel
*)
12173 /* Clean up a dummy stub function entry in .text. */
12174 if (htab
->sstubs
!= NULL
)
12176 file_ptr dummy_offset
;
12178 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
12179 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
12180 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
12181 htab
->function_stub_size
);
12186 /* The psABI says that the dynamic relocations must be sorted in
12187 increasing order of r_symndx. The VxWorks EABI doesn't require
12188 this, and because the code below handles REL rather than RELA
12189 relocations, using it for VxWorks would be outright harmful. */
12190 if (htab
->root
.target_os
!= is_vxworks
)
12192 s
= mips_elf_rel_dyn_section (info
, FALSE
);
12194 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
12196 reldyn_sorting_bfd
= output_bfd
;
12198 if (ABI_64_P (output_bfd
))
12199 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
12200 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
12201 sort_dynamic_relocs_64
);
12203 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
12204 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
12205 sort_dynamic_relocs
);
12210 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
12212 if (htab
->root
.target_os
== is_vxworks
)
12214 if (bfd_link_pic (info
))
12215 mips_vxworks_finish_shared_plt (output_bfd
, info
);
12217 mips_vxworks_finish_exec_plt (output_bfd
, info
);
12221 BFD_ASSERT (!bfd_link_pic (info
));
12222 if (!mips_finish_exec_plt (output_bfd
, info
))
12230 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
12233 mips_set_isa_flags (bfd
*abfd
)
12237 switch (bfd_get_mach (abfd
))
12240 if (ABI_N32_P (abfd
) || ABI_64_P (abfd
))
12241 val
= E_MIPS_ARCH_3
;
12243 val
= E_MIPS_ARCH_1
;
12246 case bfd_mach_mips3000
:
12247 val
= E_MIPS_ARCH_1
;
12250 case bfd_mach_mips3900
:
12251 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
12254 case bfd_mach_mips6000
:
12255 val
= E_MIPS_ARCH_2
;
12258 case bfd_mach_mips4010
:
12259 val
= E_MIPS_ARCH_2
| E_MIPS_MACH_4010
;
12262 case bfd_mach_mips4000
:
12263 case bfd_mach_mips4300
:
12264 case bfd_mach_mips4400
:
12265 case bfd_mach_mips4600
:
12266 val
= E_MIPS_ARCH_3
;
12269 case bfd_mach_mips4100
:
12270 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
12273 case bfd_mach_mips4111
:
12274 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
12277 case bfd_mach_mips4120
:
12278 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
12281 case bfd_mach_mips4650
:
12282 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
12285 case bfd_mach_mips5400
:
12286 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
12289 case bfd_mach_mips5500
:
12290 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
12293 case bfd_mach_mips5900
:
12294 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5900
;
12297 case bfd_mach_mips9000
:
12298 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
12301 case bfd_mach_mips5000
:
12302 case bfd_mach_mips7000
:
12303 case bfd_mach_mips8000
:
12304 case bfd_mach_mips10000
:
12305 case bfd_mach_mips12000
:
12306 case bfd_mach_mips14000
:
12307 case bfd_mach_mips16000
:
12308 val
= E_MIPS_ARCH_4
;
12311 case bfd_mach_mips5
:
12312 val
= E_MIPS_ARCH_5
;
12315 case bfd_mach_mips_loongson_2e
:
12316 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
12319 case bfd_mach_mips_loongson_2f
:
12320 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
12323 case bfd_mach_mips_sb1
:
12324 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
12327 case bfd_mach_mips_gs464
:
12328 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_GS464
;
12331 case bfd_mach_mips_gs464e
:
12332 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_GS464E
;
12335 case bfd_mach_mips_gs264e
:
12336 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_GS264E
;
12339 case bfd_mach_mips_octeon
:
12340 case bfd_mach_mips_octeonp
:
12341 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
12344 case bfd_mach_mips_octeon3
:
12345 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON3
;
12348 case bfd_mach_mips_xlr
:
12349 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_XLR
;
12352 case bfd_mach_mips_octeon2
:
12353 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON2
;
12356 case bfd_mach_mipsisa32
:
12357 val
= E_MIPS_ARCH_32
;
12360 case bfd_mach_mipsisa64
:
12361 val
= E_MIPS_ARCH_64
;
12364 case bfd_mach_mipsisa32r2
:
12365 case bfd_mach_mipsisa32r3
:
12366 case bfd_mach_mipsisa32r5
:
12367 val
= E_MIPS_ARCH_32R2
;
12370 case bfd_mach_mips_interaptiv_mr2
:
12371 val
= E_MIPS_ARCH_32R2
| E_MIPS_MACH_IAMR2
;
12374 case bfd_mach_mipsisa64r2
:
12375 case bfd_mach_mipsisa64r3
:
12376 case bfd_mach_mipsisa64r5
:
12377 val
= E_MIPS_ARCH_64R2
;
12380 case bfd_mach_mipsisa32r6
:
12381 val
= E_MIPS_ARCH_32R6
;
12384 case bfd_mach_mipsisa64r6
:
12385 val
= E_MIPS_ARCH_64R6
;
12388 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
12389 elf_elfheader (abfd
)->e_flags
|= val
;
12394 /* Whether to sort relocs output by ld -r or ld --emit-relocs, by r_offset.
12395 Don't do so for code sections. We want to keep ordering of HI16/LO16
12396 as is. On the other hand, elf-eh-frame.c processing requires .eh_frame
12397 relocs to be sorted. */
12400 _bfd_mips_elf_sort_relocs_p (asection
*sec
)
12402 return (sec
->flags
& SEC_CODE
) == 0;
12406 /* The final processing done just before writing out a MIPS ELF object
12407 file. This gets the MIPS architecture right based on the machine
12408 number. This is used by both the 32-bit and the 64-bit ABI. */
12411 _bfd_mips_final_write_processing (bfd
*abfd
)
12414 Elf_Internal_Shdr
**hdrpp
;
12418 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
12419 is nonzero. This is for compatibility with old objects, which used
12420 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
12421 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
12422 mips_set_isa_flags (abfd
);
12424 /* Set the sh_info field for .gptab sections and other appropriate
12425 info for each special section. */
12426 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
12427 i
< elf_numsections (abfd
);
12430 switch ((*hdrpp
)->sh_type
)
12432 case SHT_MIPS_MSYM
:
12433 case SHT_MIPS_LIBLIST
:
12434 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
12436 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
12439 case SHT_MIPS_GPTAB
:
12440 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
12441 name
= bfd_section_name ((*hdrpp
)->bfd_section
);
12442 BFD_ASSERT (name
!= NULL
12443 && CONST_STRNEQ (name
, ".gptab."));
12444 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
12445 BFD_ASSERT (sec
!= NULL
);
12446 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
12449 case SHT_MIPS_CONTENT
:
12450 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
12451 name
= bfd_section_name ((*hdrpp
)->bfd_section
);
12452 BFD_ASSERT (name
!= NULL
12453 && CONST_STRNEQ (name
, ".MIPS.content"));
12454 sec
= bfd_get_section_by_name (abfd
,
12455 name
+ sizeof ".MIPS.content" - 1);
12456 BFD_ASSERT (sec
!= NULL
);
12457 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
12460 case SHT_MIPS_SYMBOL_LIB
:
12461 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
12463 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
12464 sec
= bfd_get_section_by_name (abfd
, ".liblist");
12466 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
12469 case SHT_MIPS_EVENTS
:
12470 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
12471 name
= bfd_section_name ((*hdrpp
)->bfd_section
);
12472 BFD_ASSERT (name
!= NULL
);
12473 if (CONST_STRNEQ (name
, ".MIPS.events"))
12474 sec
= bfd_get_section_by_name (abfd
,
12475 name
+ sizeof ".MIPS.events" - 1);
12478 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
12479 sec
= bfd_get_section_by_name (abfd
,
12481 + sizeof ".MIPS.post_rel" - 1));
12483 BFD_ASSERT (sec
!= NULL
);
12484 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
12487 case SHT_MIPS_XHASH
:
12488 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
12490 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
12496 _bfd_mips_elf_final_write_processing (bfd
*abfd
)
12498 _bfd_mips_final_write_processing (abfd
);
12499 return _bfd_elf_final_write_processing (abfd
);
12502 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
12506 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
12507 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
12512 /* See if we need a PT_MIPS_REGINFO segment. */
12513 s
= bfd_get_section_by_name (abfd
, ".reginfo");
12514 if (s
&& (s
->flags
& SEC_LOAD
))
12517 /* See if we need a PT_MIPS_ABIFLAGS segment. */
12518 if (bfd_get_section_by_name (abfd
, ".MIPS.abiflags"))
12521 /* See if we need a PT_MIPS_OPTIONS segment. */
12522 if (IRIX_COMPAT (abfd
) == ict_irix6
12523 && bfd_get_section_by_name (abfd
,
12524 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
12527 /* See if we need a PT_MIPS_RTPROC segment. */
12528 if (IRIX_COMPAT (abfd
) == ict_irix5
12529 && bfd_get_section_by_name (abfd
, ".dynamic")
12530 && bfd_get_section_by_name (abfd
, ".mdebug"))
12533 /* Allocate a PT_NULL header in dynamic objects. See
12534 _bfd_mips_elf_modify_segment_map for details. */
12535 if (!SGI_COMPAT (abfd
)
12536 && bfd_get_section_by_name (abfd
, ".dynamic"))
12542 /* Modify the segment map for an IRIX5 executable. */
12545 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
12546 struct bfd_link_info
*info
)
12549 struct elf_segment_map
*m
, **pm
;
12552 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
12554 s
= bfd_get_section_by_name (abfd
, ".reginfo");
12555 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
12557 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
12558 if (m
->p_type
== PT_MIPS_REGINFO
)
12563 m
= bfd_zalloc (abfd
, amt
);
12567 m
->p_type
= PT_MIPS_REGINFO
;
12569 m
->sections
[0] = s
;
12571 /* We want to put it after the PHDR and INTERP segments. */
12572 pm
= &elf_seg_map (abfd
);
12574 && ((*pm
)->p_type
== PT_PHDR
12575 || (*pm
)->p_type
== PT_INTERP
))
12583 /* If there is a .MIPS.abiflags section, we need a PT_MIPS_ABIFLAGS
12585 s
= bfd_get_section_by_name (abfd
, ".MIPS.abiflags");
12586 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
12588 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
12589 if (m
->p_type
== PT_MIPS_ABIFLAGS
)
12594 m
= bfd_zalloc (abfd
, amt
);
12598 m
->p_type
= PT_MIPS_ABIFLAGS
;
12600 m
->sections
[0] = s
;
12602 /* We want to put it after the PHDR and INTERP segments. */
12603 pm
= &elf_seg_map (abfd
);
12605 && ((*pm
)->p_type
== PT_PHDR
12606 || (*pm
)->p_type
== PT_INTERP
))
12614 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
12615 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
12616 PT_MIPS_OPTIONS segment immediately following the program header
12618 if (NEWABI_P (abfd
)
12619 /* On non-IRIX6 new abi, we'll have already created a segment
12620 for this section, so don't create another. I'm not sure this
12621 is not also the case for IRIX 6, but I can't test it right
12623 && IRIX_COMPAT (abfd
) == ict_irix6
)
12625 for (s
= abfd
->sections
; s
; s
= s
->next
)
12626 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
12631 struct elf_segment_map
*options_segment
;
12633 pm
= &elf_seg_map (abfd
);
12635 && ((*pm
)->p_type
== PT_PHDR
12636 || (*pm
)->p_type
== PT_INTERP
))
12639 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
12641 amt
= sizeof (struct elf_segment_map
);
12642 options_segment
= bfd_zalloc (abfd
, amt
);
12643 options_segment
->next
= *pm
;
12644 options_segment
->p_type
= PT_MIPS_OPTIONS
;
12645 options_segment
->p_flags
= PF_R
;
12646 options_segment
->p_flags_valid
= TRUE
;
12647 options_segment
->count
= 1;
12648 options_segment
->sections
[0] = s
;
12649 *pm
= options_segment
;
12655 if (IRIX_COMPAT (abfd
) == ict_irix5
)
12657 /* If there are .dynamic and .mdebug sections, we make a room
12658 for the RTPROC header. FIXME: Rewrite without section names. */
12659 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
12660 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
12661 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
12663 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
12664 if (m
->p_type
== PT_MIPS_RTPROC
)
12669 m
= bfd_zalloc (abfd
, amt
);
12673 m
->p_type
= PT_MIPS_RTPROC
;
12675 s
= bfd_get_section_by_name (abfd
, ".rtproc");
12680 m
->p_flags_valid
= 1;
12685 m
->sections
[0] = s
;
12688 /* We want to put it after the DYNAMIC segment. */
12689 pm
= &elf_seg_map (abfd
);
12690 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
12700 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
12701 .dynstr, .dynsym, and .hash sections, and everything in
12703 for (pm
= &elf_seg_map (abfd
); *pm
!= NULL
;
12705 if ((*pm
)->p_type
== PT_DYNAMIC
)
12708 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
12709 glibc's dynamic linker has traditionally derived the number of
12710 tags from the p_filesz field, and sometimes allocates stack
12711 arrays of that size. An overly-big PT_DYNAMIC segment can
12712 be actively harmful in such cases. Making PT_DYNAMIC contain
12713 other sections can also make life hard for the prelinker,
12714 which might move one of the other sections to a different
12715 PT_LOAD segment. */
12716 if (SGI_COMPAT (abfd
)
12719 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
12721 static const char *sec_names
[] =
12723 ".dynamic", ".dynstr", ".dynsym", ".hash"
12727 struct elf_segment_map
*n
;
12729 low
= ~(bfd_vma
) 0;
12731 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
12733 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
12734 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
12741 if (high
< s
->vma
+ sz
)
12742 high
= s
->vma
+ sz
;
12747 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
12748 if ((s
->flags
& SEC_LOAD
) != 0
12750 && s
->vma
+ s
->size
<= high
)
12753 amt
= sizeof *n
- sizeof (asection
*) + c
* sizeof (asection
*);
12754 n
= bfd_zalloc (abfd
, amt
);
12761 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
12763 if ((s
->flags
& SEC_LOAD
) != 0
12765 && s
->vma
+ s
->size
<= high
)
12767 n
->sections
[i
] = s
;
12776 /* Allocate a spare program header in dynamic objects so that tools
12777 like the prelinker can add an extra PT_LOAD entry.
12779 If the prelinker needs to make room for a new PT_LOAD entry, its
12780 standard procedure is to move the first (read-only) sections into
12781 the new (writable) segment. However, the MIPS ABI requires
12782 .dynamic to be in a read-only segment, and the section will often
12783 start within sizeof (ElfNN_Phdr) bytes of the last program header.
12785 Although the prelinker could in principle move .dynamic to a
12786 writable segment, it seems better to allocate a spare program
12787 header instead, and avoid the need to move any sections.
12788 There is a long tradition of allocating spare dynamic tags,
12789 so allocating a spare program header seems like a natural
12792 If INFO is NULL, we may be copying an already prelinked binary
12793 with objcopy or strip, so do not add this header. */
12795 && !SGI_COMPAT (abfd
)
12796 && bfd_get_section_by_name (abfd
, ".dynamic"))
12798 for (pm
= &elf_seg_map (abfd
); *pm
!= NULL
; pm
= &(*pm
)->next
)
12799 if ((*pm
)->p_type
== PT_NULL
)
12803 m
= bfd_zalloc (abfd
, sizeof (*m
));
12807 m
->p_type
= PT_NULL
;
12815 /* Return the section that should be marked against GC for a given
12819 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
12820 struct bfd_link_info
*info
,
12821 Elf_Internal_Rela
*rel
,
12822 struct elf_link_hash_entry
*h
,
12823 Elf_Internal_Sym
*sym
)
12825 /* ??? Do mips16 stub sections need to be handled special? */
12828 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
12830 case R_MIPS_GNU_VTINHERIT
:
12831 case R_MIPS_GNU_VTENTRY
:
12835 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
12838 /* Prevent .MIPS.abiflags from being discarded with --gc-sections. */
12841 _bfd_mips_elf_gc_mark_extra_sections (struct bfd_link_info
*info
,
12842 elf_gc_mark_hook_fn gc_mark_hook
)
12846 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
12848 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
12852 if (! is_mips_elf (sub
))
12855 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
12857 && MIPS_ELF_ABIFLAGS_SECTION_NAME_P (bfd_section_name (o
)))
12859 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
12867 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
12868 hiding the old indirect symbol. Process additional relocation
12869 information. Also called for weakdefs, in which case we just let
12870 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
12873 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
12874 struct elf_link_hash_entry
*dir
,
12875 struct elf_link_hash_entry
*ind
)
12877 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
12879 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
12881 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
12882 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
12883 /* Any absolute non-dynamic relocations against an indirect or weak
12884 definition will be against the target symbol. */
12885 if (indmips
->has_static_relocs
)
12886 dirmips
->has_static_relocs
= TRUE
;
12888 if (ind
->root
.type
!= bfd_link_hash_indirect
)
12891 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
12892 if (indmips
->readonly_reloc
)
12893 dirmips
->readonly_reloc
= TRUE
;
12894 if (indmips
->no_fn_stub
)
12895 dirmips
->no_fn_stub
= TRUE
;
12896 if (indmips
->fn_stub
)
12898 dirmips
->fn_stub
= indmips
->fn_stub
;
12899 indmips
->fn_stub
= NULL
;
12901 if (indmips
->need_fn_stub
)
12903 dirmips
->need_fn_stub
= TRUE
;
12904 indmips
->need_fn_stub
= FALSE
;
12906 if (indmips
->call_stub
)
12908 dirmips
->call_stub
= indmips
->call_stub
;
12909 indmips
->call_stub
= NULL
;
12911 if (indmips
->call_fp_stub
)
12913 dirmips
->call_fp_stub
= indmips
->call_fp_stub
;
12914 indmips
->call_fp_stub
= NULL
;
12916 if (indmips
->global_got_area
< dirmips
->global_got_area
)
12917 dirmips
->global_got_area
= indmips
->global_got_area
;
12918 if (indmips
->global_got_area
< GGA_NONE
)
12919 indmips
->global_got_area
= GGA_NONE
;
12920 if (indmips
->has_nonpic_branches
)
12921 dirmips
->has_nonpic_branches
= TRUE
;
12924 /* Take care of the special `__gnu_absolute_zero' symbol and ignore attempts
12925 to hide it. It has to remain global (it will also be protected) so as to
12926 be assigned a global GOT entry, which will then remain unchanged at load
12930 _bfd_mips_elf_hide_symbol (struct bfd_link_info
*info
,
12931 struct elf_link_hash_entry
*entry
,
12932 bfd_boolean force_local
)
12934 struct mips_elf_link_hash_table
*htab
;
12936 htab
= mips_elf_hash_table (info
);
12937 BFD_ASSERT (htab
!= NULL
);
12938 if (htab
->use_absolute_zero
12939 && strcmp (entry
->root
.root
.string
, "__gnu_absolute_zero") == 0)
12942 _bfd_elf_link_hash_hide_symbol (info
, entry
, force_local
);
12945 #define PDR_SIZE 32
12948 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
12949 struct bfd_link_info
*info
)
12952 bfd_boolean ret
= FALSE
;
12953 unsigned char *tdata
;
12956 o
= bfd_get_section_by_name (abfd
, ".pdr");
12961 if (o
->size
% PDR_SIZE
!= 0)
12963 if (o
->output_section
!= NULL
12964 && bfd_is_abs_section (o
->output_section
))
12967 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
12971 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
12972 info
->keep_memory
);
12979 cookie
->rel
= cookie
->rels
;
12980 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
12982 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
12984 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
12993 mips_elf_section_data (o
)->u
.tdata
= tdata
;
12994 if (o
->rawsize
== 0)
12995 o
->rawsize
= o
->size
;
12996 o
->size
-= skip
* PDR_SIZE
;
13002 if (! info
->keep_memory
)
13003 free (cookie
->rels
);
13009 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
13011 if (strcmp (sec
->name
, ".pdr") == 0)
13017 _bfd_mips_elf_write_section (bfd
*output_bfd
,
13018 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
13019 asection
*sec
, bfd_byte
*contents
)
13021 bfd_byte
*to
, *from
, *end
;
13024 if (strcmp (sec
->name
, ".pdr") != 0)
13027 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
13031 end
= contents
+ sec
->size
;
13032 for (from
= contents
, i
= 0;
13034 from
+= PDR_SIZE
, i
++)
13036 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
13039 memcpy (to
, from
, PDR_SIZE
);
13042 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
13043 sec
->output_offset
, sec
->size
);
13047 /* microMIPS code retains local labels for linker relaxation. Omit them
13048 from output by default for clarity. */
13051 _bfd_mips_elf_is_target_special_symbol (bfd
*abfd
, asymbol
*sym
)
13053 return _bfd_elf_is_local_label_name (abfd
, sym
->name
);
13056 /* MIPS ELF uses a special find_nearest_line routine in order the
13057 handle the ECOFF debugging information. */
13059 struct mips_elf_find_line
13061 struct ecoff_debug_info d
;
13062 struct ecoff_find_line i
;
13066 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asymbol
**symbols
,
13067 asection
*section
, bfd_vma offset
,
13068 const char **filename_ptr
,
13069 const char **functionname_ptr
,
13070 unsigned int *line_ptr
,
13071 unsigned int *discriminator_ptr
)
13075 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
13076 filename_ptr
, functionname_ptr
,
13077 line_ptr
, discriminator_ptr
,
13078 dwarf_debug_sections
,
13079 &elf_tdata (abfd
)->dwarf2_find_line_info
)
13083 if (_bfd_dwarf1_find_nearest_line (abfd
, symbols
, section
, offset
,
13084 filename_ptr
, functionname_ptr
,
13087 if (!*functionname_ptr
)
13088 _bfd_elf_find_function (abfd
, symbols
, section
, offset
,
13089 *filename_ptr
? NULL
: filename_ptr
,
13094 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
13097 flagword origflags
;
13098 struct mips_elf_find_line
*fi
;
13099 const struct ecoff_debug_swap
* const swap
=
13100 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
13102 /* If we are called during a link, mips_elf_final_link may have
13103 cleared the SEC_HAS_CONTENTS field. We force it back on here
13104 if appropriate (which it normally will be). */
13105 origflags
= msec
->flags
;
13106 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
13107 msec
->flags
|= SEC_HAS_CONTENTS
;
13109 fi
= mips_elf_tdata (abfd
)->find_line_info
;
13112 bfd_size_type external_fdr_size
;
13115 struct fdr
*fdr_ptr
;
13116 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
13118 fi
= bfd_zalloc (abfd
, amt
);
13121 msec
->flags
= origflags
;
13125 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
13127 msec
->flags
= origflags
;
13131 /* Swap in the FDR information. */
13132 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
13133 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
13134 if (fi
->d
.fdr
== NULL
)
13136 msec
->flags
= origflags
;
13139 external_fdr_size
= swap
->external_fdr_size
;
13140 fdr_ptr
= fi
->d
.fdr
;
13141 fraw_src
= (char *) fi
->d
.external_fdr
;
13142 fraw_end
= (fraw_src
13143 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
13144 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
13145 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
13147 mips_elf_tdata (abfd
)->find_line_info
= fi
;
13149 /* Note that we don't bother to ever free this information.
13150 find_nearest_line is either called all the time, as in
13151 objdump -l, so the information should be saved, or it is
13152 rarely called, as in ld error messages, so the memory
13153 wasted is unimportant. Still, it would probably be a
13154 good idea for free_cached_info to throw it away. */
13157 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
13158 &fi
->i
, filename_ptr
, functionname_ptr
,
13161 msec
->flags
= origflags
;
13165 msec
->flags
= origflags
;
13168 /* Fall back on the generic ELF find_nearest_line routine. */
13170 return _bfd_elf_find_nearest_line (abfd
, symbols
, section
, offset
,
13171 filename_ptr
, functionname_ptr
,
13172 line_ptr
, discriminator_ptr
);
13176 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
13177 const char **filename_ptr
,
13178 const char **functionname_ptr
,
13179 unsigned int *line_ptr
)
13182 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
13183 functionname_ptr
, line_ptr
,
13184 & elf_tdata (abfd
)->dwarf2_find_line_info
);
13189 /* When are writing out the .options or .MIPS.options section,
13190 remember the bytes we are writing out, so that we can install the
13191 GP value in the section_processing routine. */
13194 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
13195 const void *location
,
13196 file_ptr offset
, bfd_size_type count
)
13198 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
13202 if (elf_section_data (section
) == NULL
)
13204 size_t amt
= sizeof (struct bfd_elf_section_data
);
13205 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
13206 if (elf_section_data (section
) == NULL
)
13209 c
= mips_elf_section_data (section
)->u
.tdata
;
13212 c
= bfd_zalloc (abfd
, section
->size
);
13215 mips_elf_section_data (section
)->u
.tdata
= c
;
13218 memcpy (c
+ offset
, location
, count
);
13221 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
13225 /* This is almost identical to bfd_generic_get_... except that some
13226 MIPS relocations need to be handled specially. Sigh. */
13229 _bfd_elf_mips_get_relocated_section_contents
13231 struct bfd_link_info
*link_info
,
13232 struct bfd_link_order
*link_order
,
13234 bfd_boolean relocatable
,
13237 /* Get enough memory to hold the stuff */
13238 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
13239 asection
*input_section
= link_order
->u
.indirect
.section
;
13242 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
13243 arelent
**reloc_vector
= NULL
;
13246 if (reloc_size
< 0)
13249 reloc_vector
= bfd_malloc (reloc_size
);
13250 if (reloc_vector
== NULL
&& reloc_size
!= 0)
13253 /* read in the section */
13254 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
13255 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
13258 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
13262 if (reloc_count
< 0)
13265 if (reloc_count
> 0)
13270 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
13273 struct bfd_hash_entry
*h
;
13274 struct bfd_link_hash_entry
*lh
;
13275 /* Skip all this stuff if we aren't mixing formats. */
13276 if (abfd
&& input_bfd
13277 && abfd
->xvec
== input_bfd
->xvec
)
13281 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
13282 lh
= (struct bfd_link_hash_entry
*) h
;
13289 case bfd_link_hash_undefined
:
13290 case bfd_link_hash_undefweak
:
13291 case bfd_link_hash_common
:
13294 case bfd_link_hash_defined
:
13295 case bfd_link_hash_defweak
:
13297 gp
= lh
->u
.def
.value
;
13299 case bfd_link_hash_indirect
:
13300 case bfd_link_hash_warning
:
13302 /* @@FIXME ignoring warning for now */
13304 case bfd_link_hash_new
:
13313 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
13315 char *error_message
= NULL
;
13316 bfd_reloc_status_type r
;
13318 /* Specific to MIPS: Deal with relocation types that require
13319 knowing the gp of the output bfd. */
13320 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
13322 /* If we've managed to find the gp and have a special
13323 function for the relocation then go ahead, else default
13324 to the generic handling. */
13326 && (*parent
)->howto
->special_function
13327 == _bfd_mips_elf32_gprel16_reloc
)
13328 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
13329 input_section
, relocatable
,
13332 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
13334 relocatable
? abfd
: NULL
,
13339 asection
*os
= input_section
->output_section
;
13341 /* A partial link, so keep the relocs */
13342 os
->orelocation
[os
->reloc_count
] = *parent
;
13346 if (r
!= bfd_reloc_ok
)
13350 case bfd_reloc_undefined
:
13351 (*link_info
->callbacks
->undefined_symbol
)
13352 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
13353 input_bfd
, input_section
, (*parent
)->address
, TRUE
);
13355 case bfd_reloc_dangerous
:
13356 BFD_ASSERT (error_message
!= NULL
);
13357 (*link_info
->callbacks
->reloc_dangerous
)
13358 (link_info
, error_message
,
13359 input_bfd
, input_section
, (*parent
)->address
);
13361 case bfd_reloc_overflow
:
13362 (*link_info
->callbacks
->reloc_overflow
)
13364 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
13365 (*parent
)->howto
->name
, (*parent
)->addend
,
13366 input_bfd
, input_section
, (*parent
)->address
);
13368 case bfd_reloc_outofrange
:
13377 free (reloc_vector
);
13381 free (reloc_vector
);
13386 mips_elf_relax_delete_bytes (bfd
*abfd
,
13387 asection
*sec
, bfd_vma addr
, int count
)
13389 Elf_Internal_Shdr
*symtab_hdr
;
13390 unsigned int sec_shndx
;
13391 bfd_byte
*contents
;
13392 Elf_Internal_Rela
*irel
, *irelend
;
13393 Elf_Internal_Sym
*isym
;
13394 Elf_Internal_Sym
*isymend
;
13395 struct elf_link_hash_entry
**sym_hashes
;
13396 struct elf_link_hash_entry
**end_hashes
;
13397 struct elf_link_hash_entry
**start_hashes
;
13398 unsigned int symcount
;
13400 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
13401 contents
= elf_section_data (sec
)->this_hdr
.contents
;
13403 irel
= elf_section_data (sec
)->relocs
;
13404 irelend
= irel
+ sec
->reloc_count
;
13406 /* Actually delete the bytes. */
13407 memmove (contents
+ addr
, contents
+ addr
+ count
,
13408 (size_t) (sec
->size
- addr
- count
));
13409 sec
->size
-= count
;
13411 /* Adjust all the relocs. */
13412 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
13414 /* Get the new reloc address. */
13415 if (irel
->r_offset
> addr
)
13416 irel
->r_offset
-= count
;
13419 BFD_ASSERT (addr
% 2 == 0);
13420 BFD_ASSERT (count
% 2 == 0);
13422 /* Adjust the local symbols defined in this section. */
13423 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
13424 isym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
13425 for (isymend
= isym
+ symtab_hdr
->sh_info
; isym
< isymend
; isym
++)
13426 if (isym
->st_shndx
== sec_shndx
&& isym
->st_value
> addr
)
13427 isym
->st_value
-= count
;
13429 /* Now adjust the global symbols defined in this section. */
13430 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
13431 - symtab_hdr
->sh_info
);
13432 sym_hashes
= start_hashes
= elf_sym_hashes (abfd
);
13433 end_hashes
= sym_hashes
+ symcount
;
13435 for (; sym_hashes
< end_hashes
; sym_hashes
++)
13437 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
13439 if ((sym_hash
->root
.type
== bfd_link_hash_defined
13440 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
13441 && sym_hash
->root
.u
.def
.section
== sec
)
13443 bfd_vma value
= sym_hash
->root
.u
.def
.value
;
13445 if (ELF_ST_IS_MICROMIPS (sym_hash
->other
))
13446 value
&= MINUS_TWO
;
13448 sym_hash
->root
.u
.def
.value
-= count
;
13456 /* Opcodes needed for microMIPS relaxation as found in
13457 opcodes/micromips-opc.c. */
13459 struct opcode_descriptor
{
13460 unsigned long match
;
13461 unsigned long mask
;
13464 /* The $ra register aka $31. */
13468 /* 32-bit instruction format register fields. */
13470 #define OP32_SREG(opcode) (((opcode) >> 16) & 0x1f)
13471 #define OP32_TREG(opcode) (((opcode) >> 21) & 0x1f)
13473 /* Check if a 5-bit register index can be abbreviated to 3 bits. */
13475 #define OP16_VALID_REG(r) \
13476 ((2 <= (r) && (r) <= 7) || (16 <= (r) && (r) <= 17))
13479 /* 32-bit and 16-bit branches. */
13481 static const struct opcode_descriptor b_insns_32
[] = {
13482 { /* "b", "p", */ 0x40400000, 0xffff0000 }, /* bgez 0 */
13483 { /* "b", "p", */ 0x94000000, 0xffff0000 }, /* beq 0, 0 */
13484 { 0, 0 } /* End marker for find_match(). */
13487 static const struct opcode_descriptor bc_insn_32
=
13488 { /* "bc(1|2)(ft)", "N,p", */ 0x42800000, 0xfec30000 };
13490 static const struct opcode_descriptor bz_insn_32
=
13491 { /* "b(g|l)(e|t)z", "s,p", */ 0x40000000, 0xff200000 };
13493 static const struct opcode_descriptor bzal_insn_32
=
13494 { /* "b(ge|lt)zal", "s,p", */ 0x40200000, 0xffa00000 };
13496 static const struct opcode_descriptor beq_insn_32
=
13497 { /* "b(eq|ne)", "s,t,p", */ 0x94000000, 0xdc000000 };
13499 static const struct opcode_descriptor b_insn_16
=
13500 { /* "b", "mD", */ 0xcc00, 0xfc00 };
13502 static const struct opcode_descriptor bz_insn_16
=
13503 { /* "b(eq|ne)z", "md,mE", */ 0x8c00, 0xdc00 };
13506 /* 32-bit and 16-bit branch EQ and NE zero. */
13508 /* NOTE: All opcode tables have BEQ/BNE in the same order: first the
13509 eq and second the ne. This convention is used when replacing a
13510 32-bit BEQ/BNE with the 16-bit version. */
13512 #define BZC32_REG_FIELD(r) (((r) & 0x1f) << 16)
13514 static const struct opcode_descriptor bz_rs_insns_32
[] = {
13515 { /* "beqz", "s,p", */ 0x94000000, 0xffe00000 },
13516 { /* "bnez", "s,p", */ 0xb4000000, 0xffe00000 },
13517 { 0, 0 } /* End marker for find_match(). */
13520 static const struct opcode_descriptor bz_rt_insns_32
[] = {
13521 { /* "beqz", "t,p", */ 0x94000000, 0xfc01f000 },
13522 { /* "bnez", "t,p", */ 0xb4000000, 0xfc01f000 },
13523 { 0, 0 } /* End marker for find_match(). */
13526 static const struct opcode_descriptor bzc_insns_32
[] = {
13527 { /* "beqzc", "s,p", */ 0x40e00000, 0xffe00000 },
13528 { /* "bnezc", "s,p", */ 0x40a00000, 0xffe00000 },
13529 { 0, 0 } /* End marker for find_match(). */
13532 static const struct opcode_descriptor bz_insns_16
[] = {
13533 { /* "beqz", "md,mE", */ 0x8c00, 0xfc00 },
13534 { /* "bnez", "md,mE", */ 0xac00, 0xfc00 },
13535 { 0, 0 } /* End marker for find_match(). */
13538 /* Switch between a 5-bit register index and its 3-bit shorthand. */
13540 #define BZ16_REG(opcode) ((((((opcode) >> 7) & 7) + 0x1e) & 0xf) + 2)
13541 #define BZ16_REG_FIELD(r) (((r) & 7) << 7)
13544 /* 32-bit instructions with a delay slot. */
13546 static const struct opcode_descriptor jal_insn_32_bd16
=
13547 { /* "jals", "a", */ 0x74000000, 0xfc000000 };
13549 static const struct opcode_descriptor jal_insn_32_bd32
=
13550 { /* "jal", "a", */ 0xf4000000, 0xfc000000 };
13552 static const struct opcode_descriptor jal_x_insn_32_bd32
=
13553 { /* "jal[x]", "a", */ 0xf0000000, 0xf8000000 };
13555 static const struct opcode_descriptor j_insn_32
=
13556 { /* "j", "a", */ 0xd4000000, 0xfc000000 };
13558 static const struct opcode_descriptor jalr_insn_32
=
13559 { /* "jalr[.hb]", "t,s", */ 0x00000f3c, 0xfc00efff };
13561 /* This table can be compacted, because no opcode replacement is made. */
13563 static const struct opcode_descriptor ds_insns_32_bd16
[] = {
13564 { /* "jals", "a", */ 0x74000000, 0xfc000000 },
13566 { /* "jalrs[.hb]", "t,s", */ 0x00004f3c, 0xfc00efff },
13567 { /* "b(ge|lt)zals", "s,p", */ 0x42200000, 0xffa00000 },
13569 { /* "b(g|l)(e|t)z", "s,p", */ 0x40000000, 0xff200000 },
13570 { /* "b(eq|ne)", "s,t,p", */ 0x94000000, 0xdc000000 },
13571 { /* "j", "a", */ 0xd4000000, 0xfc000000 },
13572 { 0, 0 } /* End marker for find_match(). */
13575 /* This table can be compacted, because no opcode replacement is made. */
13577 static const struct opcode_descriptor ds_insns_32_bd32
[] = {
13578 { /* "jal[x]", "a", */ 0xf0000000, 0xf8000000 },
13580 { /* "jalr[.hb]", "t,s", */ 0x00000f3c, 0xfc00efff },
13581 { /* "b(ge|lt)zal", "s,p", */ 0x40200000, 0xffa00000 },
13582 { 0, 0 } /* End marker for find_match(). */
13586 /* 16-bit instructions with a delay slot. */
13588 static const struct opcode_descriptor jalr_insn_16_bd16
=
13589 { /* "jalrs", "my,mj", */ 0x45e0, 0xffe0 };
13591 static const struct opcode_descriptor jalr_insn_16_bd32
=
13592 { /* "jalr", "my,mj", */ 0x45c0, 0xffe0 };
13594 static const struct opcode_descriptor jr_insn_16
=
13595 { /* "jr", "mj", */ 0x4580, 0xffe0 };
13597 #define JR16_REG(opcode) ((opcode) & 0x1f)
13599 /* This table can be compacted, because no opcode replacement is made. */
13601 static const struct opcode_descriptor ds_insns_16_bd16
[] = {
13602 { /* "jalrs", "my,mj", */ 0x45e0, 0xffe0 },
13604 { /* "b", "mD", */ 0xcc00, 0xfc00 },
13605 { /* "b(eq|ne)z", "md,mE", */ 0x8c00, 0xdc00 },
13606 { /* "jr", "mj", */ 0x4580, 0xffe0 },
13607 { 0, 0 } /* End marker for find_match(). */
13611 /* LUI instruction. */
13613 static const struct opcode_descriptor lui_insn
=
13614 { /* "lui", "s,u", */ 0x41a00000, 0xffe00000 };
13617 /* ADDIU instruction. */
13619 static const struct opcode_descriptor addiu_insn
=
13620 { /* "addiu", "t,r,j", */ 0x30000000, 0xfc000000 };
13622 static const struct opcode_descriptor addiupc_insn
=
13623 { /* "addiu", "mb,$pc,mQ", */ 0x78000000, 0xfc000000 };
13625 #define ADDIUPC_REG_FIELD(r) \
13626 (((2 <= (r) && (r) <= 7) ? (r) : ((r) - 16)) << 23)
13629 /* Relaxable instructions in a JAL delay slot: MOVE. */
13631 /* The 16-bit move has rd in 9:5 and rs in 4:0. The 32-bit moves
13632 (ADDU, OR) have rd in 15:11 and rs in 10:16. */
13633 #define MOVE32_RD(opcode) (((opcode) >> 11) & 0x1f)
13634 #define MOVE32_RS(opcode) (((opcode) >> 16) & 0x1f)
13636 #define MOVE16_RD_FIELD(r) (((r) & 0x1f) << 5)
13637 #define MOVE16_RS_FIELD(r) (((r) & 0x1f) )
13639 static const struct opcode_descriptor move_insns_32
[] = {
13640 { /* "move", "d,s", */ 0x00000290, 0xffe007ff }, /* or d,s,$0 */
13641 { /* "move", "d,s", */ 0x00000150, 0xffe007ff }, /* addu d,s,$0 */
13642 { 0, 0 } /* End marker for find_match(). */
13645 static const struct opcode_descriptor move_insn_16
=
13646 { /* "move", "mp,mj", */ 0x0c00, 0xfc00 };
13649 /* NOP instructions. */
13651 static const struct opcode_descriptor nop_insn_32
=
13652 { /* "nop", "", */ 0x00000000, 0xffffffff };
13654 static const struct opcode_descriptor nop_insn_16
=
13655 { /* "nop", "", */ 0x0c00, 0xffff };
13658 /* Instruction match support. */
13660 #define MATCH(opcode, insn) ((opcode & insn.mask) == insn.match)
13663 find_match (unsigned long opcode
, const struct opcode_descriptor insn
[])
13665 unsigned long indx
;
13667 for (indx
= 0; insn
[indx
].mask
!= 0; indx
++)
13668 if (MATCH (opcode
, insn
[indx
]))
13675 /* Branch and delay slot decoding support. */
13677 /* If PTR points to what *might* be a 16-bit branch or jump, then
13678 return the minimum length of its delay slot, otherwise return 0.
13679 Non-zero results are not definitive as we might be checking against
13680 the second half of another instruction. */
13683 check_br16_dslot (bfd
*abfd
, bfd_byte
*ptr
)
13685 unsigned long opcode
;
13688 opcode
= bfd_get_16 (abfd
, ptr
);
13689 if (MATCH (opcode
, jalr_insn_16_bd32
) != 0)
13690 /* 16-bit branch/jump with a 32-bit delay slot. */
13692 else if (MATCH (opcode
, jalr_insn_16_bd16
) != 0
13693 || find_match (opcode
, ds_insns_16_bd16
) >= 0)
13694 /* 16-bit branch/jump with a 16-bit delay slot. */
13697 /* No delay slot. */
13703 /* If PTR points to what *might* be a 32-bit branch or jump, then
13704 return the minimum length of its delay slot, otherwise return 0.
13705 Non-zero results are not definitive as we might be checking against
13706 the second half of another instruction. */
13709 check_br32_dslot (bfd
*abfd
, bfd_byte
*ptr
)
13711 unsigned long opcode
;
13714 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
13715 if (find_match (opcode
, ds_insns_32_bd32
) >= 0)
13716 /* 32-bit branch/jump with a 32-bit delay slot. */
13718 else if (find_match (opcode
, ds_insns_32_bd16
) >= 0)
13719 /* 32-bit branch/jump with a 16-bit delay slot. */
13722 /* No delay slot. */
13728 /* If PTR points to a 16-bit branch or jump with a 32-bit delay slot
13729 that doesn't fiddle with REG, then return TRUE, otherwise FALSE. */
13732 check_br16 (bfd
*abfd
, bfd_byte
*ptr
, unsigned long reg
)
13734 unsigned long opcode
;
13736 opcode
= bfd_get_16 (abfd
, ptr
);
13737 if (MATCH (opcode
, b_insn_16
)
13739 || (MATCH (opcode
, jr_insn_16
) && reg
!= JR16_REG (opcode
))
13741 || (MATCH (opcode
, bz_insn_16
) && reg
!= BZ16_REG (opcode
))
13742 /* BEQZ16, BNEZ16 */
13743 || (MATCH (opcode
, jalr_insn_16_bd32
)
13745 && reg
!= JR16_REG (opcode
) && reg
!= RA
))
13751 /* If PTR points to a 32-bit branch or jump that doesn't fiddle with REG,
13752 then return TRUE, otherwise FALSE. */
13755 check_br32 (bfd
*abfd
, bfd_byte
*ptr
, unsigned long reg
)
13757 unsigned long opcode
;
13759 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
13760 if (MATCH (opcode
, j_insn_32
)
13762 || MATCH (opcode
, bc_insn_32
)
13763 /* BC1F, BC1T, BC2F, BC2T */
13764 || (MATCH (opcode
, jal_x_insn_32_bd32
) && reg
!= RA
)
13766 || (MATCH (opcode
, bz_insn_32
) && reg
!= OP32_SREG (opcode
))
13767 /* BGEZ, BGTZ, BLEZ, BLTZ */
13768 || (MATCH (opcode
, bzal_insn_32
)
13769 /* BGEZAL, BLTZAL */
13770 && reg
!= OP32_SREG (opcode
) && reg
!= RA
)
13771 || ((MATCH (opcode
, jalr_insn_32
) || MATCH (opcode
, beq_insn_32
))
13772 /* JALR, JALR.HB, BEQ, BNE */
13773 && reg
!= OP32_SREG (opcode
) && reg
!= OP32_TREG (opcode
)))
13779 /* If the instruction encoding at PTR and relocations [INTERNAL_RELOCS,
13780 IRELEND) at OFFSET indicate that there must be a compact branch there,
13781 then return TRUE, otherwise FALSE. */
13784 check_relocated_bzc (bfd
*abfd
, const bfd_byte
*ptr
, bfd_vma offset
,
13785 const Elf_Internal_Rela
*internal_relocs
,
13786 const Elf_Internal_Rela
*irelend
)
13788 const Elf_Internal_Rela
*irel
;
13789 unsigned long opcode
;
13791 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
13792 if (find_match (opcode
, bzc_insns_32
) < 0)
13795 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13796 if (irel
->r_offset
== offset
13797 && ELF32_R_TYPE (irel
->r_info
) == R_MICROMIPS_PC16_S1
)
13803 /* Bitsize checking. */
13804 #define IS_BITSIZE(val, N) \
13805 (((((val) & ((1ULL << (N)) - 1)) ^ (1ULL << ((N) - 1))) \
13806 - (1ULL << ((N) - 1))) == (val))
13810 _bfd_mips_elf_relax_section (bfd
*abfd
, asection
*sec
,
13811 struct bfd_link_info
*link_info
,
13812 bfd_boolean
*again
)
13814 bfd_boolean insn32
= mips_elf_hash_table (link_info
)->insn32
;
13815 Elf_Internal_Shdr
*symtab_hdr
;
13816 Elf_Internal_Rela
*internal_relocs
;
13817 Elf_Internal_Rela
*irel
, *irelend
;
13818 bfd_byte
*contents
= NULL
;
13819 Elf_Internal_Sym
*isymbuf
= NULL
;
13821 /* Assume nothing changes. */
13824 /* We don't have to do anything for a relocatable link, if
13825 this section does not have relocs, or if this is not a
13828 if (bfd_link_relocatable (link_info
)
13829 || (sec
->flags
& SEC_RELOC
) == 0
13830 || sec
->reloc_count
== 0
13831 || (sec
->flags
& SEC_CODE
) == 0)
13834 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
13836 /* Get a copy of the native relocations. */
13837 internal_relocs
= (_bfd_elf_link_read_relocs
13838 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
13839 link_info
->keep_memory
));
13840 if (internal_relocs
== NULL
)
13843 /* Walk through them looking for relaxing opportunities. */
13844 irelend
= internal_relocs
+ sec
->reloc_count
;
13845 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13847 unsigned long r_symndx
= ELF32_R_SYM (irel
->r_info
);
13848 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
13849 bfd_boolean target_is_micromips_code_p
;
13850 unsigned long opcode
;
13856 /* The number of bytes to delete for relaxation and from where
13857 to delete these bytes starting at irel->r_offset. */
13861 /* If this isn't something that can be relaxed, then ignore
13863 if (r_type
!= R_MICROMIPS_HI16
13864 && r_type
!= R_MICROMIPS_PC16_S1
13865 && r_type
!= R_MICROMIPS_26_S1
)
13868 /* Get the section contents if we haven't done so already. */
13869 if (contents
== NULL
)
13871 /* Get cached copy if it exists. */
13872 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
13873 contents
= elf_section_data (sec
)->this_hdr
.contents
;
13874 /* Go get them off disk. */
13875 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
13878 ptr
= contents
+ irel
->r_offset
;
13880 /* Read this BFD's local symbols if we haven't done so already. */
13881 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
13883 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
13884 if (isymbuf
== NULL
)
13885 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
13886 symtab_hdr
->sh_info
, 0,
13888 if (isymbuf
== NULL
)
13892 /* Get the value of the symbol referred to by the reloc. */
13893 if (r_symndx
< symtab_hdr
->sh_info
)
13895 /* A local symbol. */
13896 Elf_Internal_Sym
*isym
;
13899 isym
= isymbuf
+ r_symndx
;
13900 if (isym
->st_shndx
== SHN_UNDEF
)
13901 sym_sec
= bfd_und_section_ptr
;
13902 else if (isym
->st_shndx
== SHN_ABS
)
13903 sym_sec
= bfd_abs_section_ptr
;
13904 else if (isym
->st_shndx
== SHN_COMMON
)
13905 sym_sec
= bfd_com_section_ptr
;
13907 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
13908 symval
= (isym
->st_value
13909 + sym_sec
->output_section
->vma
13910 + sym_sec
->output_offset
);
13911 target_is_micromips_code_p
= ELF_ST_IS_MICROMIPS (isym
->st_other
);
13915 unsigned long indx
;
13916 struct elf_link_hash_entry
*h
;
13918 /* An external symbol. */
13919 indx
= r_symndx
- symtab_hdr
->sh_info
;
13920 h
= elf_sym_hashes (abfd
)[indx
];
13921 BFD_ASSERT (h
!= NULL
);
13923 if (h
->root
.type
!= bfd_link_hash_defined
13924 && h
->root
.type
!= bfd_link_hash_defweak
)
13925 /* This appears to be a reference to an undefined
13926 symbol. Just ignore it -- it will be caught by the
13927 regular reloc processing. */
13930 symval
= (h
->root
.u
.def
.value
13931 + h
->root
.u
.def
.section
->output_section
->vma
13932 + h
->root
.u
.def
.section
->output_offset
);
13933 target_is_micromips_code_p
= (!h
->needs_plt
13934 && ELF_ST_IS_MICROMIPS (h
->other
));
13938 /* For simplicity of coding, we are going to modify the
13939 section contents, the section relocs, and the BFD symbol
13940 table. We must tell the rest of the code not to free up this
13941 information. It would be possible to instead create a table
13942 of changes which have to be made, as is done in coff-mips.c;
13943 that would be more work, but would require less memory when
13944 the linker is run. */
13946 /* Only 32-bit instructions relaxed. */
13947 if (irel
->r_offset
+ 4 > sec
->size
)
13950 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
13952 /* This is the pc-relative distance from the instruction the
13953 relocation is applied to, to the symbol referred. */
13955 - (sec
->output_section
->vma
+ sec
->output_offset
)
13958 /* R_MICROMIPS_HI16 / LUI relaxation to nil, performing relaxation
13959 of corresponding R_MICROMIPS_LO16 to R_MICROMIPS_HI0_LO16 or
13960 R_MICROMIPS_PC23_S2. The R_MICROMIPS_PC23_S2 condition is
13962 (symval % 4 == 0 && IS_BITSIZE (pcrval, 25))
13964 where pcrval has first to be adjusted to apply against the LO16
13965 location (we make the adjustment later on, when we have figured
13966 out the offset). */
13967 if (r_type
== R_MICROMIPS_HI16
&& MATCH (opcode
, lui_insn
))
13969 bfd_boolean bzc
= FALSE
;
13970 unsigned long nextopc
;
13974 /* Give up if the previous reloc was a HI16 against this symbol
13976 if (irel
> internal_relocs
13977 && ELF32_R_TYPE (irel
[-1].r_info
) == R_MICROMIPS_HI16
13978 && ELF32_R_SYM (irel
[-1].r_info
) == r_symndx
)
13981 /* Or if the next reloc is not a LO16 against this symbol. */
13982 if (irel
+ 1 >= irelend
13983 || ELF32_R_TYPE (irel
[1].r_info
) != R_MICROMIPS_LO16
13984 || ELF32_R_SYM (irel
[1].r_info
) != r_symndx
)
13987 /* Or if the second next reloc is a LO16 against this symbol too. */
13988 if (irel
+ 2 >= irelend
13989 && ELF32_R_TYPE (irel
[2].r_info
) == R_MICROMIPS_LO16
13990 && ELF32_R_SYM (irel
[2].r_info
) == r_symndx
)
13993 /* See if the LUI instruction *might* be in a branch delay slot.
13994 We check whether what looks like a 16-bit branch or jump is
13995 actually an immediate argument to a compact branch, and let
13996 it through if so. */
13997 if (irel
->r_offset
>= 2
13998 && check_br16_dslot (abfd
, ptr
- 2)
13999 && !(irel
->r_offset
>= 4
14000 && (bzc
= check_relocated_bzc (abfd
,
14001 ptr
- 4, irel
->r_offset
- 4,
14002 internal_relocs
, irelend
))))
14004 if (irel
->r_offset
>= 4
14006 && check_br32_dslot (abfd
, ptr
- 4))
14009 reg
= OP32_SREG (opcode
);
14011 /* We only relax adjacent instructions or ones separated with
14012 a branch or jump that has a delay slot. The branch or jump
14013 must not fiddle with the register used to hold the address.
14014 Subtract 4 for the LUI itself. */
14015 offset
= irel
[1].r_offset
- irel
[0].r_offset
;
14016 switch (offset
- 4)
14021 if (check_br16 (abfd
, ptr
+ 4, reg
))
14025 if (check_br32 (abfd
, ptr
+ 4, reg
))
14032 nextopc
= bfd_get_micromips_32 (abfd
, contents
+ irel
[1].r_offset
);
14034 /* Give up unless the same register is used with both
14036 if (OP32_SREG (nextopc
) != reg
)
14039 /* Now adjust pcrval, subtracting the offset to the LO16 reloc
14040 and rounding up to take masking of the two LSBs into account. */
14041 pcrval
= ((pcrval
- offset
+ 3) | 3) ^ 3;
14043 /* R_MICROMIPS_LO16 relaxation to R_MICROMIPS_HI0_LO16. */
14044 if (IS_BITSIZE (symval
, 16))
14046 /* Fix the relocation's type. */
14047 irel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_HI0_LO16
);
14049 /* Instructions using R_MICROMIPS_LO16 have the base or
14050 source register in bits 20:16. This register becomes $0
14051 (zero) as the result of the R_MICROMIPS_HI16 being 0. */
14052 nextopc
&= ~0x001f0000;
14053 bfd_put_16 (abfd
, (nextopc
>> 16) & 0xffff,
14054 contents
+ irel
[1].r_offset
);
14057 /* R_MICROMIPS_LO16 / ADDIU relaxation to R_MICROMIPS_PC23_S2.
14058 We add 4 to take LUI deletion into account while checking
14059 the PC-relative distance. */
14060 else if (symval
% 4 == 0
14061 && IS_BITSIZE (pcrval
+ 4, 25)
14062 && MATCH (nextopc
, addiu_insn
)
14063 && OP32_TREG (nextopc
) == OP32_SREG (nextopc
)
14064 && OP16_VALID_REG (OP32_TREG (nextopc
)))
14066 /* Fix the relocation's type. */
14067 irel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_PC23_S2
);
14069 /* Replace ADDIU with the ADDIUPC version. */
14070 nextopc
= (addiupc_insn
.match
14071 | ADDIUPC_REG_FIELD (OP32_TREG (nextopc
)));
14073 bfd_put_micromips_32 (abfd
, nextopc
,
14074 contents
+ irel
[1].r_offset
);
14077 /* Can't do anything, give up, sigh... */
14081 /* Fix the relocation's type. */
14082 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_MIPS_NONE
);
14084 /* Delete the LUI instruction: 4 bytes at irel->r_offset. */
14089 /* Compact branch relaxation -- due to the multitude of macros
14090 employed by the compiler/assembler, compact branches are not
14091 always generated. Obviously, this can/will be fixed elsewhere,
14092 but there is no drawback in double checking it here. */
14093 else if (r_type
== R_MICROMIPS_PC16_S1
14094 && irel
->r_offset
+ 5 < sec
->size
14095 && ((fndopc
= find_match (opcode
, bz_rs_insns_32
)) >= 0
14096 || (fndopc
= find_match (opcode
, bz_rt_insns_32
)) >= 0)
14098 && (delcnt
= MATCH (bfd_get_16 (abfd
, ptr
+ 4),
14099 nop_insn_16
) ? 2 : 0))
14100 || (irel
->r_offset
+ 7 < sec
->size
14101 && (delcnt
= MATCH (bfd_get_micromips_32 (abfd
,
14103 nop_insn_32
) ? 4 : 0))))
14107 reg
= OP32_SREG (opcode
) ? OP32_SREG (opcode
) : OP32_TREG (opcode
);
14109 /* Replace BEQZ/BNEZ with the compact version. */
14110 opcode
= (bzc_insns_32
[fndopc
].match
14111 | BZC32_REG_FIELD (reg
)
14112 | (opcode
& 0xffff)); /* Addend value. */
14114 bfd_put_micromips_32 (abfd
, opcode
, ptr
);
14116 /* Delete the delay slot NOP: two or four bytes from
14117 irel->offset + 4; delcnt has already been set above. */
14121 /* R_MICROMIPS_PC16_S1 relaxation to R_MICROMIPS_PC10_S1. We need
14122 to check the distance from the next instruction, so subtract 2. */
14124 && r_type
== R_MICROMIPS_PC16_S1
14125 && IS_BITSIZE (pcrval
- 2, 11)
14126 && find_match (opcode
, b_insns_32
) >= 0)
14128 /* Fix the relocation's type. */
14129 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_PC10_S1
);
14131 /* Replace the 32-bit opcode with a 16-bit opcode. */
14134 | (opcode
& 0x3ff)), /* Addend value. */
14137 /* Delete 2 bytes from irel->r_offset + 2. */
14142 /* R_MICROMIPS_PC16_S1 relaxation to R_MICROMIPS_PC7_S1. We need
14143 to check the distance from the next instruction, so subtract 2. */
14145 && r_type
== R_MICROMIPS_PC16_S1
14146 && IS_BITSIZE (pcrval
- 2, 8)
14147 && (((fndopc
= find_match (opcode
, bz_rs_insns_32
)) >= 0
14148 && OP16_VALID_REG (OP32_SREG (opcode
)))
14149 || ((fndopc
= find_match (opcode
, bz_rt_insns_32
)) >= 0
14150 && OP16_VALID_REG (OP32_TREG (opcode
)))))
14154 reg
= OP32_SREG (opcode
) ? OP32_SREG (opcode
) : OP32_TREG (opcode
);
14156 /* Fix the relocation's type. */
14157 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_PC7_S1
);
14159 /* Replace the 32-bit opcode with a 16-bit opcode. */
14161 (bz_insns_16
[fndopc
].match
14162 | BZ16_REG_FIELD (reg
)
14163 | (opcode
& 0x7f)), /* Addend value. */
14166 /* Delete 2 bytes from irel->r_offset + 2. */
14171 /* R_MICROMIPS_26_S1 -- JAL to JALS relaxation for microMIPS targets. */
14173 && r_type
== R_MICROMIPS_26_S1
14174 && target_is_micromips_code_p
14175 && irel
->r_offset
+ 7 < sec
->size
14176 && MATCH (opcode
, jal_insn_32_bd32
))
14178 unsigned long n32opc
;
14179 bfd_boolean relaxed
= FALSE
;
14181 n32opc
= bfd_get_micromips_32 (abfd
, ptr
+ 4);
14183 if (MATCH (n32opc
, nop_insn_32
))
14185 /* Replace delay slot 32-bit NOP with a 16-bit NOP. */
14186 bfd_put_16 (abfd
, nop_insn_16
.match
, ptr
+ 4);
14190 else if (find_match (n32opc
, move_insns_32
) >= 0)
14192 /* Replace delay slot 32-bit MOVE with 16-bit MOVE. */
14194 (move_insn_16
.match
14195 | MOVE16_RD_FIELD (MOVE32_RD (n32opc
))
14196 | MOVE16_RS_FIELD (MOVE32_RS (n32opc
))),
14201 /* Other 32-bit instructions relaxable to 16-bit
14202 instructions will be handled here later. */
14206 /* JAL with 32-bit delay slot that is changed to a JALS
14207 with 16-bit delay slot. */
14208 bfd_put_micromips_32 (abfd
, jal_insn_32_bd16
.match
, ptr
);
14210 /* Delete 2 bytes from irel->r_offset + 6. */
14218 /* Note that we've changed the relocs, section contents, etc. */
14219 elf_section_data (sec
)->relocs
= internal_relocs
;
14220 elf_section_data (sec
)->this_hdr
.contents
= contents
;
14221 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
14223 /* Delete bytes depending on the delcnt and deloff. */
14224 if (!mips_elf_relax_delete_bytes (abfd
, sec
,
14225 irel
->r_offset
+ deloff
, delcnt
))
14228 /* That will change things, so we should relax again.
14229 Note that this is not required, and it may be slow. */
14234 if (isymbuf
!= NULL
14235 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
14237 if (! link_info
->keep_memory
)
14241 /* Cache the symbols for elf_link_input_bfd. */
14242 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
14246 if (contents
!= NULL
14247 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
14249 if (! link_info
->keep_memory
)
14253 /* Cache the section contents for elf_link_input_bfd. */
14254 elf_section_data (sec
)->this_hdr
.contents
= contents
;
14258 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
14259 free (internal_relocs
);
14264 if (symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
14266 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
14268 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
14269 free (internal_relocs
);
14274 /* Create a MIPS ELF linker hash table. */
14276 struct bfd_link_hash_table
*
14277 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
14279 struct mips_elf_link_hash_table
*ret
;
14280 size_t amt
= sizeof (struct mips_elf_link_hash_table
);
14282 ret
= bfd_zmalloc (amt
);
14286 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
14287 mips_elf_link_hash_newfunc
,
14288 sizeof (struct mips_elf_link_hash_entry
),
14294 ret
->root
.init_plt_refcount
.plist
= NULL
;
14295 ret
->root
.init_plt_offset
.plist
= NULL
;
14297 return &ret
->root
.root
;
14300 /* Likewise, but indicate that the target is VxWorks. */
14302 struct bfd_link_hash_table
*
14303 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
14305 struct bfd_link_hash_table
*ret
;
14307 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
14310 struct mips_elf_link_hash_table
*htab
;
14312 htab
= (struct mips_elf_link_hash_table
*) ret
;
14313 htab
->use_plts_and_copy_relocs
= TRUE
;
14318 /* A function that the linker calls if we are allowed to use PLTs
14319 and copy relocs. */
14322 _bfd_mips_elf_use_plts_and_copy_relocs (struct bfd_link_info
*info
)
14324 mips_elf_hash_table (info
)->use_plts_and_copy_relocs
= TRUE
;
14327 /* A function that the linker calls to select between all or only
14328 32-bit microMIPS instructions, and between making or ignoring
14329 branch relocation checks for invalid transitions between ISA modes.
14330 Also record whether we have been configured for a GNU target. */
14333 _bfd_mips_elf_linker_flags (struct bfd_link_info
*info
, bfd_boolean insn32
,
14334 bfd_boolean ignore_branch_isa
,
14335 bfd_boolean gnu_target
)
14337 mips_elf_hash_table (info
)->insn32
= insn32
;
14338 mips_elf_hash_table (info
)->ignore_branch_isa
= ignore_branch_isa
;
14339 mips_elf_hash_table (info
)->gnu_target
= gnu_target
;
14342 /* A function that the linker calls to enable use of compact branches in
14343 linker generated code for MIPSR6. */
14346 _bfd_mips_elf_compact_branches (struct bfd_link_info
*info
, bfd_boolean on
)
14348 mips_elf_hash_table (info
)->compact_branches
= on
;
14352 /* Structure for saying that BFD machine EXTENSION extends BASE. */
14354 struct mips_mach_extension
14356 unsigned long extension
, base
;
14360 /* An array describing how BFD machines relate to one another. The entries
14361 are ordered topologically with MIPS I extensions listed last. */
14363 static const struct mips_mach_extension mips_mach_extensions
[] =
14365 /* MIPS64r2 extensions. */
14366 { bfd_mach_mips_octeon3
, bfd_mach_mips_octeon2
},
14367 { bfd_mach_mips_octeon2
, bfd_mach_mips_octeonp
},
14368 { bfd_mach_mips_octeonp
, bfd_mach_mips_octeon
},
14369 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
14370 { bfd_mach_mips_gs264e
, bfd_mach_mips_gs464e
},
14371 { bfd_mach_mips_gs464e
, bfd_mach_mips_gs464
},
14372 { bfd_mach_mips_gs464
, bfd_mach_mipsisa64r2
},
14374 /* MIPS64 extensions. */
14375 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
14376 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
14377 { bfd_mach_mips_xlr
, bfd_mach_mipsisa64
},
14379 /* MIPS V extensions. */
14380 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
14382 /* R10000 extensions. */
14383 { bfd_mach_mips12000
, bfd_mach_mips10000
},
14384 { bfd_mach_mips14000
, bfd_mach_mips10000
},
14385 { bfd_mach_mips16000
, bfd_mach_mips10000
},
14387 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
14388 vr5400 ISA, but doesn't include the multimedia stuff. It seems
14389 better to allow vr5400 and vr5500 code to be merged anyway, since
14390 many libraries will just use the core ISA. Perhaps we could add
14391 some sort of ASE flag if this ever proves a problem. */
14392 { bfd_mach_mips5500
, bfd_mach_mips5400
},
14393 { bfd_mach_mips5400
, bfd_mach_mips5000
},
14395 /* MIPS IV extensions. */
14396 { bfd_mach_mips5
, bfd_mach_mips8000
},
14397 { bfd_mach_mips10000
, bfd_mach_mips8000
},
14398 { bfd_mach_mips5000
, bfd_mach_mips8000
},
14399 { bfd_mach_mips7000
, bfd_mach_mips8000
},
14400 { bfd_mach_mips9000
, bfd_mach_mips8000
},
14402 /* VR4100 extensions. */
14403 { bfd_mach_mips4120
, bfd_mach_mips4100
},
14404 { bfd_mach_mips4111
, bfd_mach_mips4100
},
14406 /* MIPS III extensions. */
14407 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
14408 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
14409 { bfd_mach_mips8000
, bfd_mach_mips4000
},
14410 { bfd_mach_mips4650
, bfd_mach_mips4000
},
14411 { bfd_mach_mips4600
, bfd_mach_mips4000
},
14412 { bfd_mach_mips4400
, bfd_mach_mips4000
},
14413 { bfd_mach_mips4300
, bfd_mach_mips4000
},
14414 { bfd_mach_mips4100
, bfd_mach_mips4000
},
14415 { bfd_mach_mips5900
, bfd_mach_mips4000
},
14417 /* MIPS32r3 extensions. */
14418 { bfd_mach_mips_interaptiv_mr2
, bfd_mach_mipsisa32r3
},
14420 /* MIPS32r2 extensions. */
14421 { bfd_mach_mipsisa32r3
, bfd_mach_mipsisa32r2
},
14423 /* MIPS32 extensions. */
14424 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
14426 /* MIPS II extensions. */
14427 { bfd_mach_mips4000
, bfd_mach_mips6000
},
14428 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
14429 { bfd_mach_mips4010
, bfd_mach_mips6000
},
14431 /* MIPS I extensions. */
14432 { bfd_mach_mips6000
, bfd_mach_mips3000
},
14433 { bfd_mach_mips3900
, bfd_mach_mips3000
}
14436 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
14439 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
14443 if (extension
== base
)
14446 if (base
== bfd_mach_mipsisa32
14447 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
14450 if (base
== bfd_mach_mipsisa32r2
14451 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
14454 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
14455 if (extension
== mips_mach_extensions
[i
].extension
)
14457 extension
= mips_mach_extensions
[i
].base
;
14458 if (extension
== base
)
14465 /* Return the BFD mach for each .MIPS.abiflags ISA Extension. */
14467 static unsigned long
14468 bfd_mips_isa_ext_mach (unsigned int isa_ext
)
14472 case AFL_EXT_3900
: return bfd_mach_mips3900
;
14473 case AFL_EXT_4010
: return bfd_mach_mips4010
;
14474 case AFL_EXT_4100
: return bfd_mach_mips4100
;
14475 case AFL_EXT_4111
: return bfd_mach_mips4111
;
14476 case AFL_EXT_4120
: return bfd_mach_mips4120
;
14477 case AFL_EXT_4650
: return bfd_mach_mips4650
;
14478 case AFL_EXT_5400
: return bfd_mach_mips5400
;
14479 case AFL_EXT_5500
: return bfd_mach_mips5500
;
14480 case AFL_EXT_5900
: return bfd_mach_mips5900
;
14481 case AFL_EXT_10000
: return bfd_mach_mips10000
;
14482 case AFL_EXT_LOONGSON_2E
: return bfd_mach_mips_loongson_2e
;
14483 case AFL_EXT_LOONGSON_2F
: return bfd_mach_mips_loongson_2f
;
14484 case AFL_EXT_SB1
: return bfd_mach_mips_sb1
;
14485 case AFL_EXT_OCTEON
: return bfd_mach_mips_octeon
;
14486 case AFL_EXT_OCTEONP
: return bfd_mach_mips_octeonp
;
14487 case AFL_EXT_OCTEON2
: return bfd_mach_mips_octeon2
;
14488 case AFL_EXT_XLR
: return bfd_mach_mips_xlr
;
14489 default: return bfd_mach_mips3000
;
14493 /* Return the .MIPS.abiflags value representing each ISA Extension. */
14496 bfd_mips_isa_ext (bfd
*abfd
)
14498 switch (bfd_get_mach (abfd
))
14500 case bfd_mach_mips3900
: return AFL_EXT_3900
;
14501 case bfd_mach_mips4010
: return AFL_EXT_4010
;
14502 case bfd_mach_mips4100
: return AFL_EXT_4100
;
14503 case bfd_mach_mips4111
: return AFL_EXT_4111
;
14504 case bfd_mach_mips4120
: return AFL_EXT_4120
;
14505 case bfd_mach_mips4650
: return AFL_EXT_4650
;
14506 case bfd_mach_mips5400
: return AFL_EXT_5400
;
14507 case bfd_mach_mips5500
: return AFL_EXT_5500
;
14508 case bfd_mach_mips5900
: return AFL_EXT_5900
;
14509 case bfd_mach_mips10000
: return AFL_EXT_10000
;
14510 case bfd_mach_mips_loongson_2e
: return AFL_EXT_LOONGSON_2E
;
14511 case bfd_mach_mips_loongson_2f
: return AFL_EXT_LOONGSON_2F
;
14512 case bfd_mach_mips_sb1
: return AFL_EXT_SB1
;
14513 case bfd_mach_mips_octeon
: return AFL_EXT_OCTEON
;
14514 case bfd_mach_mips_octeonp
: return AFL_EXT_OCTEONP
;
14515 case bfd_mach_mips_octeon3
: return AFL_EXT_OCTEON3
;
14516 case bfd_mach_mips_octeon2
: return AFL_EXT_OCTEON2
;
14517 case bfd_mach_mips_xlr
: return AFL_EXT_XLR
;
14518 case bfd_mach_mips_interaptiv_mr2
:
14519 return AFL_EXT_INTERAPTIV_MR2
;
14524 /* Encode ISA level and revision as a single value. */
14525 #define LEVEL_REV(LEV,REV) ((LEV) << 3 | (REV))
14527 /* Decode a single value into level and revision. */
14528 #define ISA_LEVEL(LEVREV) ((LEVREV) >> 3)
14529 #define ISA_REV(LEVREV) ((LEVREV) & 0x7)
14531 /* Update the isa_level, isa_rev, isa_ext fields of abiflags. */
14534 update_mips_abiflags_isa (bfd
*abfd
, Elf_Internal_ABIFlags_v0
*abiflags
)
14537 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
14539 case E_MIPS_ARCH_1
: new_isa
= LEVEL_REV (1, 0); break;
14540 case E_MIPS_ARCH_2
: new_isa
= LEVEL_REV (2, 0); break;
14541 case E_MIPS_ARCH_3
: new_isa
= LEVEL_REV (3, 0); break;
14542 case E_MIPS_ARCH_4
: new_isa
= LEVEL_REV (4, 0); break;
14543 case E_MIPS_ARCH_5
: new_isa
= LEVEL_REV (5, 0); break;
14544 case E_MIPS_ARCH_32
: new_isa
= LEVEL_REV (32, 1); break;
14545 case E_MIPS_ARCH_32R2
: new_isa
= LEVEL_REV (32, 2); break;
14546 case E_MIPS_ARCH_32R6
: new_isa
= LEVEL_REV (32, 6); break;
14547 case E_MIPS_ARCH_64
: new_isa
= LEVEL_REV (64, 1); break;
14548 case E_MIPS_ARCH_64R2
: new_isa
= LEVEL_REV (64, 2); break;
14549 case E_MIPS_ARCH_64R6
: new_isa
= LEVEL_REV (64, 6); break;
14552 /* xgettext:c-format */
14553 (_("%pB: unknown architecture %s"),
14554 abfd
, bfd_printable_name (abfd
));
14557 if (new_isa
> LEVEL_REV (abiflags
->isa_level
, abiflags
->isa_rev
))
14559 abiflags
->isa_level
= ISA_LEVEL (new_isa
);
14560 abiflags
->isa_rev
= ISA_REV (new_isa
);
14563 /* Update the isa_ext if ABFD describes a further extension. */
14564 if (mips_mach_extends_p (bfd_mips_isa_ext_mach (abiflags
->isa_ext
),
14565 bfd_get_mach (abfd
)))
14566 abiflags
->isa_ext
= bfd_mips_isa_ext (abfd
);
14569 /* Return true if the given ELF header flags describe a 32-bit binary. */
14572 mips_32bit_flags_p (flagword flags
)
14574 return ((flags
& EF_MIPS_32BITMODE
) != 0
14575 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
14576 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
14577 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
14578 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
14579 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
14580 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
14581 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R6
);
14584 /* Infer the content of the ABI flags based on the elf header. */
14587 infer_mips_abiflags (bfd
*abfd
, Elf_Internal_ABIFlags_v0
* abiflags
)
14589 obj_attribute
*in_attr
;
14591 memset (abiflags
, 0, sizeof (Elf_Internal_ABIFlags_v0
));
14592 update_mips_abiflags_isa (abfd
, abiflags
);
14594 if (mips_32bit_flags_p (elf_elfheader (abfd
)->e_flags
))
14595 abiflags
->gpr_size
= AFL_REG_32
;
14597 abiflags
->gpr_size
= AFL_REG_64
;
14599 abiflags
->cpr1_size
= AFL_REG_NONE
;
14601 in_attr
= elf_known_obj_attributes (abfd
)[OBJ_ATTR_GNU
];
14602 abiflags
->fp_abi
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
14604 if (abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_SINGLE
14605 || abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_XX
14606 || (abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_DOUBLE
14607 && abiflags
->gpr_size
== AFL_REG_32
))
14608 abiflags
->cpr1_size
= AFL_REG_32
;
14609 else if (abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_DOUBLE
14610 || abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_64
14611 || abiflags
->fp_abi
== Val_GNU_MIPS_ABI_FP_64A
)
14612 abiflags
->cpr1_size
= AFL_REG_64
;
14614 abiflags
->cpr2_size
= AFL_REG_NONE
;
14616 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
14617 abiflags
->ases
|= AFL_ASE_MDMX
;
14618 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
14619 abiflags
->ases
|= AFL_ASE_MIPS16
;
14620 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
14621 abiflags
->ases
|= AFL_ASE_MICROMIPS
;
14623 if (abiflags
->fp_abi
!= Val_GNU_MIPS_ABI_FP_ANY
14624 && abiflags
->fp_abi
!= Val_GNU_MIPS_ABI_FP_SOFT
14625 && abiflags
->fp_abi
!= Val_GNU_MIPS_ABI_FP_64A
14626 && abiflags
->isa_level
>= 32
14627 && abiflags
->ases
!= AFL_ASE_LOONGSON_EXT
)
14628 abiflags
->flags1
|= AFL_FLAGS1_ODDSPREG
;
14631 /* We need to use a special link routine to handle the .reginfo and
14632 the .mdebug sections. We need to merge all instances of these
14633 sections together, not write them all out sequentially. */
14636 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
14639 struct bfd_link_order
*p
;
14640 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
14641 asection
*rtproc_sec
, *abiflags_sec
;
14642 Elf32_RegInfo reginfo
;
14643 struct ecoff_debug_info debug
;
14644 struct mips_htab_traverse_info hti
;
14645 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
14646 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
14647 HDRR
*symhdr
= &debug
.symbolic_header
;
14648 void *mdebug_handle
= NULL
;
14653 struct mips_elf_link_hash_table
*htab
;
14655 static const char * const secname
[] =
14657 ".text", ".init", ".fini", ".data",
14658 ".rodata", ".sdata", ".sbss", ".bss"
14660 static const int sc
[] =
14662 scText
, scInit
, scFini
, scData
,
14663 scRData
, scSData
, scSBss
, scBss
14666 htab
= mips_elf_hash_table (info
);
14667 BFD_ASSERT (htab
!= NULL
);
14669 /* Sort the dynamic symbols so that those with GOT entries come after
14671 if (!mips_elf_sort_hash_table (abfd
, info
))
14674 /* Create any scheduled LA25 stubs. */
14676 hti
.output_bfd
= abfd
;
14678 htab_traverse (htab
->la25_stubs
, mips_elf_create_la25_stub
, &hti
);
14682 /* Get a value for the GP register. */
14683 if (elf_gp (abfd
) == 0)
14685 struct bfd_link_hash_entry
*h
;
14687 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
14688 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
14689 elf_gp (abfd
) = (h
->u
.def
.value
14690 + h
->u
.def
.section
->output_section
->vma
14691 + h
->u
.def
.section
->output_offset
);
14692 else if (htab
->root
.target_os
== is_vxworks
14693 && (h
= bfd_link_hash_lookup (info
->hash
,
14694 "_GLOBAL_OFFSET_TABLE_",
14695 FALSE
, FALSE
, TRUE
))
14696 && h
->type
== bfd_link_hash_defined
)
14697 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
14698 + h
->u
.def
.section
->output_offset
14700 else if (bfd_link_relocatable (info
))
14702 bfd_vma lo
= MINUS_ONE
;
14704 /* Find the GP-relative section with the lowest offset. */
14705 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
14707 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
14710 /* And calculate GP relative to that. */
14711 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
14715 /* If the relocate_section function needs to do a reloc
14716 involving the GP value, it should make a reloc_dangerous
14717 callback to warn that GP is not defined. */
14721 /* Go through the sections and collect the .reginfo and .mdebug
14723 abiflags_sec
= NULL
;
14724 reginfo_sec
= NULL
;
14726 gptab_data_sec
= NULL
;
14727 gptab_bss_sec
= NULL
;
14728 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
14730 if (strcmp (o
->name
, ".MIPS.abiflags") == 0)
14732 /* We have found the .MIPS.abiflags section in the output file.
14733 Look through all the link_orders comprising it and remove them.
14734 The data is merged in _bfd_mips_elf_merge_private_bfd_data. */
14735 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
14737 asection
*input_section
;
14739 if (p
->type
!= bfd_indirect_link_order
)
14741 if (p
->type
== bfd_data_link_order
)
14746 input_section
= p
->u
.indirect
.section
;
14748 /* Hack: reset the SEC_HAS_CONTENTS flag so that
14749 elf_link_input_bfd ignores this section. */
14750 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
14753 /* Size has been set in _bfd_mips_elf_always_size_sections. */
14754 BFD_ASSERT(o
->size
== sizeof (Elf_External_ABIFlags_v0
));
14756 /* Skip this section later on (I don't think this currently
14757 matters, but someday it might). */
14758 o
->map_head
.link_order
= NULL
;
14763 if (strcmp (o
->name
, ".reginfo") == 0)
14765 memset (®info
, 0, sizeof reginfo
);
14767 /* We have found the .reginfo section in the output file.
14768 Look through all the link_orders comprising it and merge
14769 the information together. */
14770 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
14772 asection
*input_section
;
14774 Elf32_External_RegInfo ext
;
14778 if (p
->type
!= bfd_indirect_link_order
)
14780 if (p
->type
== bfd_data_link_order
)
14785 input_section
= p
->u
.indirect
.section
;
14786 input_bfd
= input_section
->owner
;
14788 sz
= (input_section
->size
< sizeof (ext
)
14789 ? input_section
->size
: sizeof (ext
));
14790 memset (&ext
, 0, sizeof (ext
));
14791 if (! bfd_get_section_contents (input_bfd
, input_section
,
14795 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
14797 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
14798 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
14799 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
14800 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
14801 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
14803 /* ri_gp_value is set by the function
14804 `_bfd_mips_elf_section_processing' when the section is
14805 finally written out. */
14807 /* Hack: reset the SEC_HAS_CONTENTS flag so that
14808 elf_link_input_bfd ignores this section. */
14809 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
14812 /* Size has been set in _bfd_mips_elf_always_size_sections. */
14813 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
14815 /* Skip this section later on (I don't think this currently
14816 matters, but someday it might). */
14817 o
->map_head
.link_order
= NULL
;
14822 if (strcmp (o
->name
, ".mdebug") == 0)
14824 struct extsym_info einfo
;
14827 /* We have found the .mdebug section in the output file.
14828 Look through all the link_orders comprising it and merge
14829 the information together. */
14830 symhdr
->magic
= swap
->sym_magic
;
14831 /* FIXME: What should the version stamp be? */
14832 symhdr
->vstamp
= 0;
14833 symhdr
->ilineMax
= 0;
14834 symhdr
->cbLine
= 0;
14835 symhdr
->idnMax
= 0;
14836 symhdr
->ipdMax
= 0;
14837 symhdr
->isymMax
= 0;
14838 symhdr
->ioptMax
= 0;
14839 symhdr
->iauxMax
= 0;
14840 symhdr
->issMax
= 0;
14841 symhdr
->issExtMax
= 0;
14842 symhdr
->ifdMax
= 0;
14844 symhdr
->iextMax
= 0;
14846 /* We accumulate the debugging information itself in the
14847 debug_info structure. */
14849 debug
.external_dnr
= NULL
;
14850 debug
.external_pdr
= NULL
;
14851 debug
.external_sym
= NULL
;
14852 debug
.external_opt
= NULL
;
14853 debug
.external_aux
= NULL
;
14855 debug
.ssext
= debug
.ssext_end
= NULL
;
14856 debug
.external_fdr
= NULL
;
14857 debug
.external_rfd
= NULL
;
14858 debug
.external_ext
= debug
.external_ext_end
= NULL
;
14860 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
14861 if (mdebug_handle
== NULL
)
14865 esym
.cobol_main
= 0;
14869 esym
.asym
.iss
= issNil
;
14870 esym
.asym
.st
= stLocal
;
14871 esym
.asym
.reserved
= 0;
14872 esym
.asym
.index
= indexNil
;
14874 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
14876 esym
.asym
.sc
= sc
[i
];
14877 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
14880 esym
.asym
.value
= s
->vma
;
14881 last
= s
->vma
+ s
->size
;
14884 esym
.asym
.value
= last
;
14885 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
14886 secname
[i
], &esym
))
14890 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
14892 asection
*input_section
;
14894 const struct ecoff_debug_swap
*input_swap
;
14895 struct ecoff_debug_info input_debug
;
14899 if (p
->type
!= bfd_indirect_link_order
)
14901 if (p
->type
== bfd_data_link_order
)
14906 input_section
= p
->u
.indirect
.section
;
14907 input_bfd
= input_section
->owner
;
14909 if (!is_mips_elf (input_bfd
))
14911 /* I don't know what a non MIPS ELF bfd would be
14912 doing with a .mdebug section, but I don't really
14913 want to deal with it. */
14917 input_swap
= (get_elf_backend_data (input_bfd
)
14918 ->elf_backend_ecoff_debug_swap
);
14920 BFD_ASSERT (p
->size
== input_section
->size
);
14922 /* The ECOFF linking code expects that we have already
14923 read in the debugging information and set up an
14924 ecoff_debug_info structure, so we do that now. */
14925 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
14929 if (! (bfd_ecoff_debug_accumulate
14930 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
14931 &input_debug
, input_swap
, info
)))
14934 /* Loop through the external symbols. For each one with
14935 interesting information, try to find the symbol in
14936 the linker global hash table and save the information
14937 for the output external symbols. */
14938 eraw_src
= input_debug
.external_ext
;
14939 eraw_end
= (eraw_src
14940 + (input_debug
.symbolic_header
.iextMax
14941 * input_swap
->external_ext_size
));
14943 eraw_src
< eraw_end
;
14944 eraw_src
+= input_swap
->external_ext_size
)
14948 struct mips_elf_link_hash_entry
*h
;
14950 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
14951 if (ext
.asym
.sc
== scNil
14952 || ext
.asym
.sc
== scUndefined
14953 || ext
.asym
.sc
== scSUndefined
)
14956 name
= input_debug
.ssext
+ ext
.asym
.iss
;
14957 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
14958 name
, FALSE
, FALSE
, TRUE
);
14959 if (h
== NULL
|| h
->esym
.ifd
!= -2)
14964 BFD_ASSERT (ext
.ifd
14965 < input_debug
.symbolic_header
.ifdMax
);
14966 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
14972 /* Free up the information we just read. */
14973 free (input_debug
.line
);
14974 free (input_debug
.external_dnr
);
14975 free (input_debug
.external_pdr
);
14976 free (input_debug
.external_sym
);
14977 free (input_debug
.external_opt
);
14978 free (input_debug
.external_aux
);
14979 free (input_debug
.ss
);
14980 free (input_debug
.ssext
);
14981 free (input_debug
.external_fdr
);
14982 free (input_debug
.external_rfd
);
14983 free (input_debug
.external_ext
);
14985 /* Hack: reset the SEC_HAS_CONTENTS flag so that
14986 elf_link_input_bfd ignores this section. */
14987 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
14990 if (SGI_COMPAT (abfd
) && bfd_link_pic (info
))
14992 /* Create .rtproc section. */
14993 rtproc_sec
= bfd_get_linker_section (abfd
, ".rtproc");
14994 if (rtproc_sec
== NULL
)
14996 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
14997 | SEC_LINKER_CREATED
| SEC_READONLY
);
14999 rtproc_sec
= bfd_make_section_anyway_with_flags (abfd
,
15002 if (rtproc_sec
== NULL
15003 || !bfd_set_section_alignment (rtproc_sec
, 4))
15007 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
15013 /* Build the external symbol information. */
15016 einfo
.debug
= &debug
;
15018 einfo
.failed
= FALSE
;
15019 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
15020 mips_elf_output_extsym
, &einfo
);
15024 /* Set the size of the .mdebug section. */
15025 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
15027 /* Skip this section later on (I don't think this currently
15028 matters, but someday it might). */
15029 o
->map_head
.link_order
= NULL
;
15034 if (CONST_STRNEQ (o
->name
, ".gptab."))
15036 const char *subname
;
15039 Elf32_External_gptab
*ext_tab
;
15042 /* The .gptab.sdata and .gptab.sbss sections hold
15043 information describing how the small data area would
15044 change depending upon the -G switch. These sections
15045 not used in executables files. */
15046 if (! bfd_link_relocatable (info
))
15048 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
15050 asection
*input_section
;
15052 if (p
->type
!= bfd_indirect_link_order
)
15054 if (p
->type
== bfd_data_link_order
)
15059 input_section
= p
->u
.indirect
.section
;
15061 /* Hack: reset the SEC_HAS_CONTENTS flag so that
15062 elf_link_input_bfd ignores this section. */
15063 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
15066 /* Skip this section later on (I don't think this
15067 currently matters, but someday it might). */
15068 o
->map_head
.link_order
= NULL
;
15070 /* Really remove the section. */
15071 bfd_section_list_remove (abfd
, o
);
15072 --abfd
->section_count
;
15077 /* There is one gptab for initialized data, and one for
15078 uninitialized data. */
15079 if (strcmp (o
->name
, ".gptab.sdata") == 0)
15080 gptab_data_sec
= o
;
15081 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
15086 /* xgettext:c-format */
15087 (_("%pB: illegal section name `%pA'"), abfd
, o
);
15088 bfd_set_error (bfd_error_nonrepresentable_section
);
15092 /* The linker script always combines .gptab.data and
15093 .gptab.sdata into .gptab.sdata, and likewise for
15094 .gptab.bss and .gptab.sbss. It is possible that there is
15095 no .sdata or .sbss section in the output file, in which
15096 case we must change the name of the output section. */
15097 subname
= o
->name
+ sizeof ".gptab" - 1;
15098 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
15100 if (o
== gptab_data_sec
)
15101 o
->name
= ".gptab.data";
15103 o
->name
= ".gptab.bss";
15104 subname
= o
->name
+ sizeof ".gptab" - 1;
15105 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
15108 /* Set up the first entry. */
15110 amt
= c
* sizeof (Elf32_gptab
);
15111 tab
= bfd_malloc (amt
);
15114 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
15115 tab
[0].gt_header
.gt_unused
= 0;
15117 /* Combine the input sections. */
15118 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
15120 asection
*input_section
;
15122 bfd_size_type size
;
15123 unsigned long last
;
15124 bfd_size_type gpentry
;
15126 if (p
->type
!= bfd_indirect_link_order
)
15128 if (p
->type
== bfd_data_link_order
)
15133 input_section
= p
->u
.indirect
.section
;
15134 input_bfd
= input_section
->owner
;
15136 /* Combine the gptab entries for this input section one
15137 by one. We know that the input gptab entries are
15138 sorted by ascending -G value. */
15139 size
= input_section
->size
;
15141 for (gpentry
= sizeof (Elf32_External_gptab
);
15143 gpentry
+= sizeof (Elf32_External_gptab
))
15145 Elf32_External_gptab ext_gptab
;
15146 Elf32_gptab int_gptab
;
15152 if (! (bfd_get_section_contents
15153 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
15154 sizeof (Elf32_External_gptab
))))
15160 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
15162 val
= int_gptab
.gt_entry
.gt_g_value
;
15163 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
15166 for (look
= 1; look
< c
; look
++)
15168 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
15169 tab
[look
].gt_entry
.gt_bytes
+= add
;
15171 if (tab
[look
].gt_entry
.gt_g_value
== val
)
15177 Elf32_gptab
*new_tab
;
15180 /* We need a new table entry. */
15181 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
15182 new_tab
= bfd_realloc (tab
, amt
);
15183 if (new_tab
== NULL
)
15189 tab
[c
].gt_entry
.gt_g_value
= val
;
15190 tab
[c
].gt_entry
.gt_bytes
= add
;
15192 /* Merge in the size for the next smallest -G
15193 value, since that will be implied by this new
15196 for (look
= 1; look
< c
; look
++)
15198 if (tab
[look
].gt_entry
.gt_g_value
< val
15200 || (tab
[look
].gt_entry
.gt_g_value
15201 > tab
[max
].gt_entry
.gt_g_value
)))
15205 tab
[c
].gt_entry
.gt_bytes
+=
15206 tab
[max
].gt_entry
.gt_bytes
;
15211 last
= int_gptab
.gt_entry
.gt_bytes
;
15214 /* Hack: reset the SEC_HAS_CONTENTS flag so that
15215 elf_link_input_bfd ignores this section. */
15216 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
15219 /* The table must be sorted by -G value. */
15221 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
15223 /* Swap out the table. */
15224 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
15225 ext_tab
= bfd_alloc (abfd
, amt
);
15226 if (ext_tab
== NULL
)
15232 for (j
= 0; j
< c
; j
++)
15233 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
15236 o
->size
= c
* sizeof (Elf32_External_gptab
);
15237 o
->contents
= (bfd_byte
*) ext_tab
;
15239 /* Skip this section later on (I don't think this currently
15240 matters, but someday it might). */
15241 o
->map_head
.link_order
= NULL
;
15245 /* Invoke the regular ELF backend linker to do all the work. */
15246 if (!bfd_elf_final_link (abfd
, info
))
15249 /* Now write out the computed sections. */
15251 if (abiflags_sec
!= NULL
)
15253 Elf_External_ABIFlags_v0 ext
;
15254 Elf_Internal_ABIFlags_v0
*abiflags
;
15256 abiflags
= &mips_elf_tdata (abfd
)->abiflags
;
15258 /* Set up the abiflags if no valid input sections were found. */
15259 if (!mips_elf_tdata (abfd
)->abiflags_valid
)
15261 infer_mips_abiflags (abfd
, abiflags
);
15262 mips_elf_tdata (abfd
)->abiflags_valid
= TRUE
;
15264 bfd_mips_elf_swap_abiflags_v0_out (abfd
, abiflags
, &ext
);
15265 if (! bfd_set_section_contents (abfd
, abiflags_sec
, &ext
, 0, sizeof ext
))
15269 if (reginfo_sec
!= NULL
)
15271 Elf32_External_RegInfo ext
;
15273 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
15274 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
15278 if (mdebug_sec
!= NULL
)
15280 BFD_ASSERT (abfd
->output_has_begun
);
15281 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
15283 mdebug_sec
->filepos
))
15286 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
15289 if (gptab_data_sec
!= NULL
)
15291 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
15292 gptab_data_sec
->contents
,
15293 0, gptab_data_sec
->size
))
15297 if (gptab_bss_sec
!= NULL
)
15299 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
15300 gptab_bss_sec
->contents
,
15301 0, gptab_bss_sec
->size
))
15305 if (SGI_COMPAT (abfd
))
15307 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
15308 if (rtproc_sec
!= NULL
)
15310 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
15311 rtproc_sec
->contents
,
15312 0, rtproc_sec
->size
))
15320 /* Merge object file header flags from IBFD into OBFD. Raise an error
15321 if there are conflicting settings. */
15324 mips_elf_merge_obj_e_flags (bfd
*ibfd
, struct bfd_link_info
*info
)
15326 bfd
*obfd
= info
->output_bfd
;
15327 struct mips_elf_obj_tdata
*out_tdata
= mips_elf_tdata (obfd
);
15328 flagword old_flags
;
15329 flagword new_flags
;
15332 new_flags
= elf_elfheader (ibfd
)->e_flags
;
15333 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
15334 old_flags
= elf_elfheader (obfd
)->e_flags
;
15336 /* Check flag compatibility. */
15338 new_flags
&= ~EF_MIPS_NOREORDER
;
15339 old_flags
&= ~EF_MIPS_NOREORDER
;
15341 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
15342 doesn't seem to matter. */
15343 new_flags
&= ~EF_MIPS_XGOT
;
15344 old_flags
&= ~EF_MIPS_XGOT
;
15346 /* MIPSpro generates ucode info in n64 objects. Again, we should
15347 just be able to ignore this. */
15348 new_flags
&= ~EF_MIPS_UCODE
;
15349 old_flags
&= ~EF_MIPS_UCODE
;
15351 /* DSOs should only be linked with CPIC code. */
15352 if ((ibfd
->flags
& DYNAMIC
) != 0)
15353 new_flags
|= EF_MIPS_PIC
| EF_MIPS_CPIC
;
15355 if (new_flags
== old_flags
)
15360 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
15361 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
15364 (_("%pB: warning: linking abicalls files with non-abicalls files"),
15369 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
15370 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
15371 if (! (new_flags
& EF_MIPS_PIC
))
15372 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
15374 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
15375 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
15377 /* Compare the ISAs. */
15378 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
15381 (_("%pB: linking 32-bit code with 64-bit code"),
15385 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
15387 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
15388 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
15390 /* Copy the architecture info from IBFD to OBFD. Also copy
15391 the 32-bit flag (if set) so that we continue to recognise
15392 OBFD as a 32-bit binary. */
15393 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
15394 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
15395 elf_elfheader (obfd
)->e_flags
15396 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
15398 /* Update the ABI flags isa_level, isa_rev, isa_ext fields. */
15399 update_mips_abiflags_isa (obfd
, &out_tdata
->abiflags
);
15401 /* Copy across the ABI flags if OBFD doesn't use them
15402 and if that was what caused us to treat IBFD as 32-bit. */
15403 if ((old_flags
& EF_MIPS_ABI
) == 0
15404 && mips_32bit_flags_p (new_flags
)
15405 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
15406 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
15410 /* The ISAs aren't compatible. */
15412 /* xgettext:c-format */
15413 (_("%pB: linking %s module with previous %s modules"),
15415 bfd_printable_name (ibfd
),
15416 bfd_printable_name (obfd
));
15421 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
15422 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
15424 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
15425 does set EI_CLASS differently from any 32-bit ABI. */
15426 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
15427 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
15428 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
15430 /* Only error if both are set (to different values). */
15431 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
15432 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
15433 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
15436 /* xgettext:c-format */
15437 (_("%pB: ABI mismatch: linking %s module with previous %s modules"),
15439 elf_mips_abi_name (ibfd
),
15440 elf_mips_abi_name (obfd
));
15443 new_flags
&= ~EF_MIPS_ABI
;
15444 old_flags
&= ~EF_MIPS_ABI
;
15447 /* Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
15448 and allow arbitrary mixing of the remaining ASEs (retain the union). */
15449 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
15451 int old_micro
= old_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
;
15452 int new_micro
= new_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
;
15453 int old_m16
= old_flags
& EF_MIPS_ARCH_ASE_M16
;
15454 int new_m16
= new_flags
& EF_MIPS_ARCH_ASE_M16
;
15455 int micro_mis
= old_m16
&& new_micro
;
15456 int m16_mis
= old_micro
&& new_m16
;
15458 if (m16_mis
|| micro_mis
)
15461 /* xgettext:c-format */
15462 (_("%pB: ASE mismatch: linking %s module with previous %s modules"),
15464 m16_mis
? "MIPS16" : "microMIPS",
15465 m16_mis
? "microMIPS" : "MIPS16");
15469 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
15471 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
15472 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
15475 /* Compare NaN encodings. */
15476 if ((new_flags
& EF_MIPS_NAN2008
) != (old_flags
& EF_MIPS_NAN2008
))
15478 /* xgettext:c-format */
15479 _bfd_error_handler (_("%pB: linking %s module with previous %s modules"),
15481 (new_flags
& EF_MIPS_NAN2008
15482 ? "-mnan=2008" : "-mnan=legacy"),
15483 (old_flags
& EF_MIPS_NAN2008
15484 ? "-mnan=2008" : "-mnan=legacy"));
15486 new_flags
&= ~EF_MIPS_NAN2008
;
15487 old_flags
&= ~EF_MIPS_NAN2008
;
15490 /* Compare FP64 state. */
15491 if ((new_flags
& EF_MIPS_FP64
) != (old_flags
& EF_MIPS_FP64
))
15493 /* xgettext:c-format */
15494 _bfd_error_handler (_("%pB: linking %s module with previous %s modules"),
15496 (new_flags
& EF_MIPS_FP64
15497 ? "-mfp64" : "-mfp32"),
15498 (old_flags
& EF_MIPS_FP64
15499 ? "-mfp64" : "-mfp32"));
15501 new_flags
&= ~EF_MIPS_FP64
;
15502 old_flags
&= ~EF_MIPS_FP64
;
15505 /* Warn about any other mismatches */
15506 if (new_flags
!= old_flags
)
15508 /* xgettext:c-format */
15510 (_("%pB: uses different e_flags (%#x) fields than previous modules "
15512 ibfd
, new_flags
, old_flags
);
15519 /* Merge object attributes from IBFD into OBFD. Raise an error if
15520 there are conflicting attributes. */
15522 mips_elf_merge_obj_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
15524 bfd
*obfd
= info
->output_bfd
;
15525 obj_attribute
*in_attr
;
15526 obj_attribute
*out_attr
;
15530 abi_fp_bfd
= mips_elf_tdata (obfd
)->abi_fp_bfd
;
15531 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
15532 if (!abi_fp_bfd
&& in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= Val_GNU_MIPS_ABI_FP_ANY
)
15533 mips_elf_tdata (obfd
)->abi_fp_bfd
= ibfd
;
15535 abi_msa_bfd
= mips_elf_tdata (obfd
)->abi_msa_bfd
;
15537 && in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
!= Val_GNU_MIPS_ABI_MSA_ANY
)
15538 mips_elf_tdata (obfd
)->abi_msa_bfd
= ibfd
;
15540 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
15542 /* This is the first object. Copy the attributes. */
15543 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
15545 /* Use the Tag_null value to indicate the attributes have been
15547 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
15552 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
15553 non-conflicting ones. */
15554 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
15555 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
15559 out_fp
= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
15560 in_fp
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
15561 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
15562 if (out_fp
== Val_GNU_MIPS_ABI_FP_ANY
)
15563 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_fp
;
15564 else if (out_fp
== Val_GNU_MIPS_ABI_FP_XX
15565 && (in_fp
== Val_GNU_MIPS_ABI_FP_DOUBLE
15566 || in_fp
== Val_GNU_MIPS_ABI_FP_64
15567 || in_fp
== Val_GNU_MIPS_ABI_FP_64A
))
15569 mips_elf_tdata (obfd
)->abi_fp_bfd
= ibfd
;
15570 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
15572 else if (in_fp
== Val_GNU_MIPS_ABI_FP_XX
15573 && (out_fp
== Val_GNU_MIPS_ABI_FP_DOUBLE
15574 || out_fp
== Val_GNU_MIPS_ABI_FP_64
15575 || out_fp
== Val_GNU_MIPS_ABI_FP_64A
))
15576 /* Keep the current setting. */;
15577 else if (out_fp
== Val_GNU_MIPS_ABI_FP_64A
15578 && in_fp
== Val_GNU_MIPS_ABI_FP_64
)
15580 mips_elf_tdata (obfd
)->abi_fp_bfd
= ibfd
;
15581 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
15583 else if (in_fp
== Val_GNU_MIPS_ABI_FP_64A
15584 && out_fp
== Val_GNU_MIPS_ABI_FP_64
)
15585 /* Keep the current setting. */;
15586 else if (in_fp
!= Val_GNU_MIPS_ABI_FP_ANY
)
15588 const char *out_string
, *in_string
;
15590 out_string
= _bfd_mips_fp_abi_string (out_fp
);
15591 in_string
= _bfd_mips_fp_abi_string (in_fp
);
15592 /* First warn about cases involving unrecognised ABIs. */
15593 if (!out_string
&& !in_string
)
15594 /* xgettext:c-format */
15596 (_("warning: %pB uses unknown floating point ABI %d "
15597 "(set by %pB), %pB uses unknown floating point ABI %d"),
15598 obfd
, out_fp
, abi_fp_bfd
, ibfd
, in_fp
);
15599 else if (!out_string
)
15601 /* xgettext:c-format */
15602 (_("warning: %pB uses unknown floating point ABI %d "
15603 "(set by %pB), %pB uses %s"),
15604 obfd
, out_fp
, abi_fp_bfd
, ibfd
, in_string
);
15605 else if (!in_string
)
15607 /* xgettext:c-format */
15608 (_("warning: %pB uses %s (set by %pB), "
15609 "%pB uses unknown floating point ABI %d"),
15610 obfd
, out_string
, abi_fp_bfd
, ibfd
, in_fp
);
15613 /* If one of the bfds is soft-float, the other must be
15614 hard-float. The exact choice of hard-float ABI isn't
15615 really relevant to the error message. */
15616 if (in_fp
== Val_GNU_MIPS_ABI_FP_SOFT
)
15617 out_string
= "-mhard-float";
15618 else if (out_fp
== Val_GNU_MIPS_ABI_FP_SOFT
)
15619 in_string
= "-mhard-float";
15621 /* xgettext:c-format */
15622 (_("warning: %pB uses %s (set by %pB), %pB uses %s"),
15623 obfd
, out_string
, abi_fp_bfd
, ibfd
, in_string
);
15628 /* Check for conflicting Tag_GNU_MIPS_ABI_MSA attributes and merge
15629 non-conflicting ones. */
15630 if (in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
!= out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
)
15632 out_attr
[Tag_GNU_MIPS_ABI_MSA
].type
= 1;
15633 if (out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
== Val_GNU_MIPS_ABI_MSA_ANY
)
15634 out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
= in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
;
15635 else if (in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
!= Val_GNU_MIPS_ABI_MSA_ANY
)
15636 switch (out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
)
15638 case Val_GNU_MIPS_ABI_MSA_128
:
15640 /* xgettext:c-format */
15641 (_("warning: %pB uses %s (set by %pB), "
15642 "%pB uses unknown MSA ABI %d"),
15643 obfd
, "-mmsa", abi_msa_bfd
,
15644 ibfd
, in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
);
15648 switch (in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
)
15650 case Val_GNU_MIPS_ABI_MSA_128
:
15652 /* xgettext:c-format */
15653 (_("warning: %pB uses unknown MSA ABI %d "
15654 "(set by %pB), %pB uses %s"),
15655 obfd
, out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
,
15656 abi_msa_bfd
, ibfd
, "-mmsa");
15661 /* xgettext:c-format */
15662 (_("warning: %pB uses unknown MSA ABI %d "
15663 "(set by %pB), %pB uses unknown MSA ABI %d"),
15664 obfd
, out_attr
[Tag_GNU_MIPS_ABI_MSA
].i
,
15665 abi_msa_bfd
, ibfd
, in_attr
[Tag_GNU_MIPS_ABI_MSA
].i
);
15671 /* Merge Tag_compatibility attributes and any common GNU ones. */
15672 return _bfd_elf_merge_object_attributes (ibfd
, info
);
15675 /* Merge object ABI flags from IBFD into OBFD. Raise an error if
15676 there are conflicting settings. */
15679 mips_elf_merge_obj_abiflags (bfd
*ibfd
, bfd
*obfd
)
15681 obj_attribute
*out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
15682 struct mips_elf_obj_tdata
*out_tdata
= mips_elf_tdata (obfd
);
15683 struct mips_elf_obj_tdata
*in_tdata
= mips_elf_tdata (ibfd
);
15685 /* Update the output abiflags fp_abi using the computed fp_abi. */
15686 out_tdata
->abiflags
.fp_abi
= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
15688 #define max(a, b) ((a) > (b) ? (a) : (b))
15689 /* Merge abiflags. */
15690 out_tdata
->abiflags
.isa_level
= max (out_tdata
->abiflags
.isa_level
,
15691 in_tdata
->abiflags
.isa_level
);
15692 out_tdata
->abiflags
.isa_rev
= max (out_tdata
->abiflags
.isa_rev
,
15693 in_tdata
->abiflags
.isa_rev
);
15694 out_tdata
->abiflags
.gpr_size
= max (out_tdata
->abiflags
.gpr_size
,
15695 in_tdata
->abiflags
.gpr_size
);
15696 out_tdata
->abiflags
.cpr1_size
= max (out_tdata
->abiflags
.cpr1_size
,
15697 in_tdata
->abiflags
.cpr1_size
);
15698 out_tdata
->abiflags
.cpr2_size
= max (out_tdata
->abiflags
.cpr2_size
,
15699 in_tdata
->abiflags
.cpr2_size
);
15701 out_tdata
->abiflags
.ases
|= in_tdata
->abiflags
.ases
;
15702 out_tdata
->abiflags
.flags1
|= in_tdata
->abiflags
.flags1
;
15707 /* Merge backend specific data from an object file to the output
15708 object file when linking. */
15711 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
15713 bfd
*obfd
= info
->output_bfd
;
15714 struct mips_elf_obj_tdata
*out_tdata
;
15715 struct mips_elf_obj_tdata
*in_tdata
;
15716 bfd_boolean null_input_bfd
= TRUE
;
15720 /* Check if we have the same endianness. */
15721 if (! _bfd_generic_verify_endian_match (ibfd
, info
))
15724 (_("%pB: endianness incompatible with that of the selected emulation"),
15729 if (!is_mips_elf (ibfd
) || !is_mips_elf (obfd
))
15732 in_tdata
= mips_elf_tdata (ibfd
);
15733 out_tdata
= mips_elf_tdata (obfd
);
15735 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
15738 (_("%pB: ABI is incompatible with that of the selected emulation"),
15743 /* Check to see if the input BFD actually contains any sections. If not,
15744 then it has no attributes, and its flags may not have been initialized
15745 either, but it cannot actually cause any incompatibility. */
15746 /* FIXME: This excludes any input shared library from consideration. */
15747 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
15749 /* Ignore synthetic sections and empty .text, .data and .bss sections
15750 which are automatically generated by gas. Also ignore fake
15751 (s)common sections, since merely defining a common symbol does
15752 not affect compatibility. */
15753 if ((sec
->flags
& SEC_IS_COMMON
) == 0
15754 && strcmp (sec
->name
, ".reginfo")
15755 && strcmp (sec
->name
, ".mdebug")
15757 || (strcmp (sec
->name
, ".text")
15758 && strcmp (sec
->name
, ".data")
15759 && strcmp (sec
->name
, ".bss"))))
15761 null_input_bfd
= FALSE
;
15765 if (null_input_bfd
)
15768 /* Populate abiflags using existing information. */
15769 if (in_tdata
->abiflags_valid
)
15771 obj_attribute
*in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
15772 Elf_Internal_ABIFlags_v0 in_abiflags
;
15773 Elf_Internal_ABIFlags_v0 abiflags
;
15775 /* Set up the FP ABI attribute from the abiflags if it is not already
15777 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
== Val_GNU_MIPS_ABI_FP_ANY
)
15778 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_tdata
->abiflags
.fp_abi
;
15780 infer_mips_abiflags (ibfd
, &abiflags
);
15781 in_abiflags
= in_tdata
->abiflags
;
15783 /* It is not possible to infer the correct ISA revision
15784 for R3 or R5 so drop down to R2 for the checks. */
15785 if (in_abiflags
.isa_rev
== 3 || in_abiflags
.isa_rev
== 5)
15786 in_abiflags
.isa_rev
= 2;
15788 if (LEVEL_REV (in_abiflags
.isa_level
, in_abiflags
.isa_rev
)
15789 < LEVEL_REV (abiflags
.isa_level
, abiflags
.isa_rev
))
15791 (_("%pB: warning: inconsistent ISA between e_flags and "
15792 ".MIPS.abiflags"), ibfd
);
15793 if (abiflags
.fp_abi
!= Val_GNU_MIPS_ABI_FP_ANY
15794 && in_abiflags
.fp_abi
!= abiflags
.fp_abi
)
15796 (_("%pB: warning: inconsistent FP ABI between .gnu.attributes and "
15797 ".MIPS.abiflags"), ibfd
);
15798 if ((in_abiflags
.ases
& abiflags
.ases
) != abiflags
.ases
)
15800 (_("%pB: warning: inconsistent ASEs between e_flags and "
15801 ".MIPS.abiflags"), ibfd
);
15802 /* The isa_ext is allowed to be an extension of what can be inferred
15804 if (!mips_mach_extends_p (bfd_mips_isa_ext_mach (abiflags
.isa_ext
),
15805 bfd_mips_isa_ext_mach (in_abiflags
.isa_ext
)))
15807 (_("%pB: warning: inconsistent ISA extensions between e_flags and "
15808 ".MIPS.abiflags"), ibfd
);
15809 if (in_abiflags
.flags2
!= 0)
15811 (_("%pB: warning: unexpected flag in the flags2 field of "
15812 ".MIPS.abiflags (0x%lx)"), ibfd
,
15813 in_abiflags
.flags2
);
15817 infer_mips_abiflags (ibfd
, &in_tdata
->abiflags
);
15818 in_tdata
->abiflags_valid
= TRUE
;
15821 if (!out_tdata
->abiflags_valid
)
15823 /* Copy input abiflags if output abiflags are not already valid. */
15824 out_tdata
->abiflags
= in_tdata
->abiflags
;
15825 out_tdata
->abiflags_valid
= TRUE
;
15828 if (! elf_flags_init (obfd
))
15830 elf_flags_init (obfd
) = TRUE
;
15831 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
15832 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
15833 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
15835 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
15836 && (bfd_get_arch_info (obfd
)->the_default
15837 || mips_mach_extends_p (bfd_get_mach (obfd
),
15838 bfd_get_mach (ibfd
))))
15840 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
15841 bfd_get_mach (ibfd
)))
15844 /* Update the ABI flags isa_level, isa_rev and isa_ext fields. */
15845 update_mips_abiflags_isa (obfd
, &out_tdata
->abiflags
);
15851 ok
= mips_elf_merge_obj_e_flags (ibfd
, info
);
15853 ok
= mips_elf_merge_obj_attributes (ibfd
, info
) && ok
;
15855 ok
= mips_elf_merge_obj_abiflags (ibfd
, obfd
) && ok
;
15859 bfd_set_error (bfd_error_bad_value
);
15866 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
15869 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
15871 BFD_ASSERT (!elf_flags_init (abfd
)
15872 || elf_elfheader (abfd
)->e_flags
== flags
);
15874 elf_elfheader (abfd
)->e_flags
= flags
;
15875 elf_flags_init (abfd
) = TRUE
;
15880 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
15884 default: return "";
15885 case DT_MIPS_RLD_VERSION
:
15886 return "MIPS_RLD_VERSION";
15887 case DT_MIPS_TIME_STAMP
:
15888 return "MIPS_TIME_STAMP";
15889 case DT_MIPS_ICHECKSUM
:
15890 return "MIPS_ICHECKSUM";
15891 case DT_MIPS_IVERSION
:
15892 return "MIPS_IVERSION";
15893 case DT_MIPS_FLAGS
:
15894 return "MIPS_FLAGS";
15895 case DT_MIPS_BASE_ADDRESS
:
15896 return "MIPS_BASE_ADDRESS";
15898 return "MIPS_MSYM";
15899 case DT_MIPS_CONFLICT
:
15900 return "MIPS_CONFLICT";
15901 case DT_MIPS_LIBLIST
:
15902 return "MIPS_LIBLIST";
15903 case DT_MIPS_LOCAL_GOTNO
:
15904 return "MIPS_LOCAL_GOTNO";
15905 case DT_MIPS_CONFLICTNO
:
15906 return "MIPS_CONFLICTNO";
15907 case DT_MIPS_LIBLISTNO
:
15908 return "MIPS_LIBLISTNO";
15909 case DT_MIPS_SYMTABNO
:
15910 return "MIPS_SYMTABNO";
15911 case DT_MIPS_UNREFEXTNO
:
15912 return "MIPS_UNREFEXTNO";
15913 case DT_MIPS_GOTSYM
:
15914 return "MIPS_GOTSYM";
15915 case DT_MIPS_HIPAGENO
:
15916 return "MIPS_HIPAGENO";
15917 case DT_MIPS_RLD_MAP
:
15918 return "MIPS_RLD_MAP";
15919 case DT_MIPS_RLD_MAP_REL
:
15920 return "MIPS_RLD_MAP_REL";
15921 case DT_MIPS_DELTA_CLASS
:
15922 return "MIPS_DELTA_CLASS";
15923 case DT_MIPS_DELTA_CLASS_NO
:
15924 return "MIPS_DELTA_CLASS_NO";
15925 case DT_MIPS_DELTA_INSTANCE
:
15926 return "MIPS_DELTA_INSTANCE";
15927 case DT_MIPS_DELTA_INSTANCE_NO
:
15928 return "MIPS_DELTA_INSTANCE_NO";
15929 case DT_MIPS_DELTA_RELOC
:
15930 return "MIPS_DELTA_RELOC";
15931 case DT_MIPS_DELTA_RELOC_NO
:
15932 return "MIPS_DELTA_RELOC_NO";
15933 case DT_MIPS_DELTA_SYM
:
15934 return "MIPS_DELTA_SYM";
15935 case DT_MIPS_DELTA_SYM_NO
:
15936 return "MIPS_DELTA_SYM_NO";
15937 case DT_MIPS_DELTA_CLASSSYM
:
15938 return "MIPS_DELTA_CLASSSYM";
15939 case DT_MIPS_DELTA_CLASSSYM_NO
:
15940 return "MIPS_DELTA_CLASSSYM_NO";
15941 case DT_MIPS_CXX_FLAGS
:
15942 return "MIPS_CXX_FLAGS";
15943 case DT_MIPS_PIXIE_INIT
:
15944 return "MIPS_PIXIE_INIT";
15945 case DT_MIPS_SYMBOL_LIB
:
15946 return "MIPS_SYMBOL_LIB";
15947 case DT_MIPS_LOCALPAGE_GOTIDX
:
15948 return "MIPS_LOCALPAGE_GOTIDX";
15949 case DT_MIPS_LOCAL_GOTIDX
:
15950 return "MIPS_LOCAL_GOTIDX";
15951 case DT_MIPS_HIDDEN_GOTIDX
:
15952 return "MIPS_HIDDEN_GOTIDX";
15953 case DT_MIPS_PROTECTED_GOTIDX
:
15954 return "MIPS_PROTECTED_GOT_IDX";
15955 case DT_MIPS_OPTIONS
:
15956 return "MIPS_OPTIONS";
15957 case DT_MIPS_INTERFACE
:
15958 return "MIPS_INTERFACE";
15959 case DT_MIPS_DYNSTR_ALIGN
:
15960 return "DT_MIPS_DYNSTR_ALIGN";
15961 case DT_MIPS_INTERFACE_SIZE
:
15962 return "DT_MIPS_INTERFACE_SIZE";
15963 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
15964 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
15965 case DT_MIPS_PERF_SUFFIX
:
15966 return "DT_MIPS_PERF_SUFFIX";
15967 case DT_MIPS_COMPACT_SIZE
:
15968 return "DT_MIPS_COMPACT_SIZE";
15969 case DT_MIPS_GP_VALUE
:
15970 return "DT_MIPS_GP_VALUE";
15971 case DT_MIPS_AUX_DYNAMIC
:
15972 return "DT_MIPS_AUX_DYNAMIC";
15973 case DT_MIPS_PLTGOT
:
15974 return "DT_MIPS_PLTGOT";
15975 case DT_MIPS_RWPLT
:
15976 return "DT_MIPS_RWPLT";
15977 case DT_MIPS_XHASH
:
15978 return "DT_MIPS_XHASH";
15982 /* Return the meaning of Tag_GNU_MIPS_ABI_FP value FP, or null if
15986 _bfd_mips_fp_abi_string (int fp
)
15990 /* These strings aren't translated because they're simply
15992 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
15993 return "-mdouble-float";
15995 case Val_GNU_MIPS_ABI_FP_SINGLE
:
15996 return "-msingle-float";
15998 case Val_GNU_MIPS_ABI_FP_SOFT
:
15999 return "-msoft-float";
16001 case Val_GNU_MIPS_ABI_FP_OLD_64
:
16002 return _("-mips32r2 -mfp64 (12 callee-saved)");
16004 case Val_GNU_MIPS_ABI_FP_XX
:
16007 case Val_GNU_MIPS_ABI_FP_64
:
16008 return "-mgp32 -mfp64";
16010 case Val_GNU_MIPS_ABI_FP_64A
:
16011 return "-mgp32 -mfp64 -mno-odd-spreg";
16019 print_mips_ases (FILE *file
, unsigned int mask
)
16021 if (mask
& AFL_ASE_DSP
)
16022 fputs ("\n\tDSP ASE", file
);
16023 if (mask
& AFL_ASE_DSPR2
)
16024 fputs ("\n\tDSP R2 ASE", file
);
16025 if (mask
& AFL_ASE_DSPR3
)
16026 fputs ("\n\tDSP R3 ASE", file
);
16027 if (mask
& AFL_ASE_EVA
)
16028 fputs ("\n\tEnhanced VA Scheme", file
);
16029 if (mask
& AFL_ASE_MCU
)
16030 fputs ("\n\tMCU (MicroController) ASE", file
);
16031 if (mask
& AFL_ASE_MDMX
)
16032 fputs ("\n\tMDMX ASE", file
);
16033 if (mask
& AFL_ASE_MIPS3D
)
16034 fputs ("\n\tMIPS-3D ASE", file
);
16035 if (mask
& AFL_ASE_MT
)
16036 fputs ("\n\tMT ASE", file
);
16037 if (mask
& AFL_ASE_SMARTMIPS
)
16038 fputs ("\n\tSmartMIPS ASE", file
);
16039 if (mask
& AFL_ASE_VIRT
)
16040 fputs ("\n\tVZ ASE", file
);
16041 if (mask
& AFL_ASE_MSA
)
16042 fputs ("\n\tMSA ASE", file
);
16043 if (mask
& AFL_ASE_MIPS16
)
16044 fputs ("\n\tMIPS16 ASE", file
);
16045 if (mask
& AFL_ASE_MICROMIPS
)
16046 fputs ("\n\tMICROMIPS ASE", file
);
16047 if (mask
& AFL_ASE_XPA
)
16048 fputs ("\n\tXPA ASE", file
);
16049 if (mask
& AFL_ASE_MIPS16E2
)
16050 fputs ("\n\tMIPS16e2 ASE", file
);
16051 if (mask
& AFL_ASE_CRC
)
16052 fputs ("\n\tCRC ASE", file
);
16053 if (mask
& AFL_ASE_GINV
)
16054 fputs ("\n\tGINV ASE", file
);
16055 if (mask
& AFL_ASE_LOONGSON_MMI
)
16056 fputs ("\n\tLoongson MMI ASE", file
);
16057 if (mask
& AFL_ASE_LOONGSON_CAM
)
16058 fputs ("\n\tLoongson CAM ASE", file
);
16059 if (mask
& AFL_ASE_LOONGSON_EXT
)
16060 fputs ("\n\tLoongson EXT ASE", file
);
16061 if (mask
& AFL_ASE_LOONGSON_EXT2
)
16062 fputs ("\n\tLoongson EXT2 ASE", file
);
16064 fprintf (file
, "\n\t%s", _("None"));
16065 else if ((mask
& ~AFL_ASE_MASK
) != 0)
16066 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
16070 print_mips_isa_ext (FILE *file
, unsigned int isa_ext
)
16075 fputs (_("None"), file
);
16078 fputs ("RMI XLR", file
);
16080 case AFL_EXT_OCTEON3
:
16081 fputs ("Cavium Networks Octeon3", file
);
16083 case AFL_EXT_OCTEON2
:
16084 fputs ("Cavium Networks Octeon2", file
);
16086 case AFL_EXT_OCTEONP
:
16087 fputs ("Cavium Networks OcteonP", file
);
16089 case AFL_EXT_OCTEON
:
16090 fputs ("Cavium Networks Octeon", file
);
16093 fputs ("Toshiba R5900", file
);
16096 fputs ("MIPS R4650", file
);
16099 fputs ("LSI R4010", file
);
16102 fputs ("NEC VR4100", file
);
16105 fputs ("Toshiba R3900", file
);
16107 case AFL_EXT_10000
:
16108 fputs ("MIPS R10000", file
);
16111 fputs ("Broadcom SB-1", file
);
16114 fputs ("NEC VR4111/VR4181", file
);
16117 fputs ("NEC VR4120", file
);
16120 fputs ("NEC VR5400", file
);
16123 fputs ("NEC VR5500", file
);
16125 case AFL_EXT_LOONGSON_2E
:
16126 fputs ("ST Microelectronics Loongson 2E", file
);
16128 case AFL_EXT_LOONGSON_2F
:
16129 fputs ("ST Microelectronics Loongson 2F", file
);
16131 case AFL_EXT_INTERAPTIV_MR2
:
16132 fputs ("Imagination interAptiv MR2", file
);
16135 fprintf (file
, "%s (%d)", _("Unknown"), isa_ext
);
16141 print_mips_fp_abi_value (FILE *file
, int val
)
16145 case Val_GNU_MIPS_ABI_FP_ANY
:
16146 fprintf (file
, _("Hard or soft float\n"));
16148 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
16149 fprintf (file
, _("Hard float (double precision)\n"));
16151 case Val_GNU_MIPS_ABI_FP_SINGLE
:
16152 fprintf (file
, _("Hard float (single precision)\n"));
16154 case Val_GNU_MIPS_ABI_FP_SOFT
:
16155 fprintf (file
, _("Soft float\n"));
16157 case Val_GNU_MIPS_ABI_FP_OLD_64
:
16158 fprintf (file
, _("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
16160 case Val_GNU_MIPS_ABI_FP_XX
:
16161 fprintf (file
, _("Hard float (32-bit CPU, Any FPU)\n"));
16163 case Val_GNU_MIPS_ABI_FP_64
:
16164 fprintf (file
, _("Hard float (32-bit CPU, 64-bit FPU)\n"));
16166 case Val_GNU_MIPS_ABI_FP_64A
:
16167 fprintf (file
, _("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
16170 fprintf (file
, "??? (%d)\n", val
);
16176 get_mips_reg_size (int reg_size
)
16178 return (reg_size
== AFL_REG_NONE
) ? 0
16179 : (reg_size
== AFL_REG_32
) ? 32
16180 : (reg_size
== AFL_REG_64
) ? 64
16181 : (reg_size
== AFL_REG_128
) ? 128
16186 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
16190 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
16192 /* Print normal ELF private data. */
16193 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
16195 /* xgettext:c-format */
16196 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
16198 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
16199 fprintf (file
, _(" [abi=O32]"));
16200 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
16201 fprintf (file
, _(" [abi=O64]"));
16202 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
16203 fprintf (file
, _(" [abi=EABI32]"));
16204 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
16205 fprintf (file
, _(" [abi=EABI64]"));
16206 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
16207 fprintf (file
, _(" [abi unknown]"));
16208 else if (ABI_N32_P (abfd
))
16209 fprintf (file
, _(" [abi=N32]"));
16210 else if (ABI_64_P (abfd
))
16211 fprintf (file
, _(" [abi=64]"));
16213 fprintf (file
, _(" [no abi set]"));
16215 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
16216 fprintf (file
, " [mips1]");
16217 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
16218 fprintf (file
, " [mips2]");
16219 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
16220 fprintf (file
, " [mips3]");
16221 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
16222 fprintf (file
, " [mips4]");
16223 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
16224 fprintf (file
, " [mips5]");
16225 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
16226 fprintf (file
, " [mips32]");
16227 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
16228 fprintf (file
, " [mips64]");
16229 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
16230 fprintf (file
, " [mips32r2]");
16231 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
16232 fprintf (file
, " [mips64r2]");
16233 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R6
)
16234 fprintf (file
, " [mips32r6]");
16235 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R6
)
16236 fprintf (file
, " [mips64r6]");
16238 fprintf (file
, _(" [unknown ISA]"));
16240 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
16241 fprintf (file
, " [mdmx]");
16243 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
16244 fprintf (file
, " [mips16]");
16246 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
16247 fprintf (file
, " [micromips]");
16249 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NAN2008
)
16250 fprintf (file
, " [nan2008]");
16252 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_FP64
)
16253 fprintf (file
, " [old fp64]");
16255 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
16256 fprintf (file
, " [32bitmode]");
16258 fprintf (file
, _(" [not 32bitmode]"));
16260 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
16261 fprintf (file
, " [noreorder]");
16263 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
16264 fprintf (file
, " [PIC]");
16266 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
16267 fprintf (file
, " [CPIC]");
16269 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
16270 fprintf (file
, " [XGOT]");
16272 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
16273 fprintf (file
, " [UCODE]");
16275 fputc ('\n', file
);
16277 if (mips_elf_tdata (abfd
)->abiflags_valid
)
16279 Elf_Internal_ABIFlags_v0
*abiflags
= &mips_elf_tdata (abfd
)->abiflags
;
16280 fprintf (file
, "\nMIPS ABI Flags Version: %d\n", abiflags
->version
);
16281 fprintf (file
, "\nISA: MIPS%d", abiflags
->isa_level
);
16282 if (abiflags
->isa_rev
> 1)
16283 fprintf (file
, "r%d", abiflags
->isa_rev
);
16284 fprintf (file
, "\nGPR size: %d",
16285 get_mips_reg_size (abiflags
->gpr_size
));
16286 fprintf (file
, "\nCPR1 size: %d",
16287 get_mips_reg_size (abiflags
->cpr1_size
));
16288 fprintf (file
, "\nCPR2 size: %d",
16289 get_mips_reg_size (abiflags
->cpr2_size
));
16290 fputs ("\nFP ABI: ", file
);
16291 print_mips_fp_abi_value (file
, abiflags
->fp_abi
);
16292 fputs ("ISA Extension: ", file
);
16293 print_mips_isa_ext (file
, abiflags
->isa_ext
);
16294 fputs ("\nASEs:", file
);
16295 print_mips_ases (file
, abiflags
->ases
);
16296 fprintf (file
, "\nFLAGS 1: %8.8lx", abiflags
->flags1
);
16297 fprintf (file
, "\nFLAGS 2: %8.8lx", abiflags
->flags2
);
16298 fputc ('\n', file
);
16304 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
16306 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
16307 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
16308 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
16309 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
16310 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
16311 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
16312 { STRING_COMMA_LEN (".MIPS.xhash"), 0, SHT_MIPS_XHASH
, SHF_ALLOC
},
16313 { NULL
, 0, 0, 0, 0 }
16316 /* Merge non visibility st_other attributes. Ensure that the
16317 STO_OPTIONAL flag is copied into h->other, even if this is not a
16318 definiton of the symbol. */
16320 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
16321 const Elf_Internal_Sym
*isym
,
16322 bfd_boolean definition
,
16323 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
16325 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
16327 unsigned char other
;
16329 other
= (definition
? isym
->st_other
: h
->other
);
16330 other
&= ~ELF_ST_VISIBILITY (-1);
16331 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
16335 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
16336 h
->other
|= STO_OPTIONAL
;
16339 /* Decide whether an undefined symbol is special and can be ignored.
16340 This is the case for OPTIONAL symbols on IRIX. */
16342 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
16344 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
16348 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
16350 return (sym
->st_shndx
== SHN_COMMON
16351 || sym
->st_shndx
== SHN_MIPS_ACOMMON
16352 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);
16355 /* Return address for Ith PLT stub in section PLT, for relocation REL
16356 or (bfd_vma) -1 if it should not be included. */
16359 _bfd_mips_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
16360 const arelent
*rel ATTRIBUTE_UNUSED
)
16363 + 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
)
16364 + i
* 4 * ARRAY_SIZE (mips_exec_plt_entry
));
16367 /* Build a table of synthetic symbols to represent the PLT. As with MIPS16
16368 and microMIPS PLT slots we may have a many-to-one mapping between .plt
16369 and .got.plt and also the slots may be of a different size each we walk
16370 the PLT manually fetching instructions and matching them against known
16371 patterns. To make things easier standard MIPS slots, if any, always come
16372 first. As we don't create proper ELF symbols we use the UDATA.I member
16373 of ASYMBOL to carry ISA annotation. The encoding used is the same as
16374 with the ST_OTHER member of the ELF symbol. */
16377 _bfd_mips_elf_get_synthetic_symtab (bfd
*abfd
,
16378 long symcount ATTRIBUTE_UNUSED
,
16379 asymbol
**syms ATTRIBUTE_UNUSED
,
16380 long dynsymcount
, asymbol
**dynsyms
,
16383 static const char pltname
[] = "_PROCEDURE_LINKAGE_TABLE_";
16384 static const char microsuffix
[] = "@micromipsplt";
16385 static const char m16suffix
[] = "@mips16plt";
16386 static const char mipssuffix
[] = "@plt";
16388 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
16389 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
16390 bfd_boolean micromips_p
= MICROMIPS_P (abfd
);
16391 Elf_Internal_Shdr
*hdr
;
16392 bfd_byte
*plt_data
;
16393 bfd_vma plt_offset
;
16394 unsigned int other
;
16395 bfd_vma entry_size
;
16414 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0 || dynsymcount
<= 0)
16417 relplt
= bfd_get_section_by_name (abfd
, ".rel.plt");
16418 if (relplt
== NULL
)
16421 hdr
= &elf_section_data (relplt
)->this_hdr
;
16422 if (hdr
->sh_link
!= elf_dynsymtab (abfd
) || hdr
->sh_type
!= SHT_REL
)
16425 plt
= bfd_get_section_by_name (abfd
, ".plt");
16429 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
16430 if (!(*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
16432 p
= relplt
->relocation
;
16434 /* Calculating the exact amount of space required for symbols would
16435 require two passes over the PLT, so just pessimise assuming two
16436 PLT slots per relocation. */
16437 count
= relplt
->size
/ hdr
->sh_entsize
;
16438 counti
= count
* bed
->s
->int_rels_per_ext_rel
;
16439 size
= 2 * count
* sizeof (asymbol
);
16440 size
+= count
* (sizeof (mipssuffix
) +
16441 (micromips_p
? sizeof (microsuffix
) : sizeof (m16suffix
)));
16442 for (pi
= 0; pi
< counti
; pi
+= bed
->s
->int_rels_per_ext_rel
)
16443 size
+= 2 * strlen ((*p
[pi
].sym_ptr_ptr
)->name
);
16445 /* Add the size of "_PROCEDURE_LINKAGE_TABLE_" too. */
16446 size
+= sizeof (asymbol
) + sizeof (pltname
);
16448 if (!bfd_malloc_and_get_section (abfd
, plt
, &plt_data
))
16451 if (plt
->size
< 16)
16454 s
= *ret
= bfd_malloc (size
);
16457 send
= s
+ 2 * count
+ 1;
16459 names
= (char *) send
;
16460 nend
= (char *) s
+ size
;
16463 opcode
= bfd_get_micromips_32 (abfd
, plt_data
+ 12);
16464 if (opcode
== 0x3302fffe)
16468 plt0_size
= 2 * ARRAY_SIZE (micromips_o32_exec_plt0_entry
);
16469 other
= STO_MICROMIPS
;
16471 else if (opcode
== 0x0398c1d0)
16475 plt0_size
= 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt0_entry
);
16476 other
= STO_MICROMIPS
;
16480 plt0_size
= 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
);
16485 s
->flags
= BSF_SYNTHETIC
| BSF_FUNCTION
| BSF_LOCAL
;
16489 s
->udata
.i
= other
;
16490 memcpy (names
, pltname
, sizeof (pltname
));
16491 names
+= sizeof (pltname
);
16495 for (plt_offset
= plt0_size
;
16496 plt_offset
+ 8 <= plt
->size
&& s
< send
;
16497 plt_offset
+= entry_size
)
16499 bfd_vma gotplt_addr
;
16500 const char *suffix
;
16505 opcode
= bfd_get_micromips_32 (abfd
, plt_data
+ plt_offset
+ 4);
16507 /* Check if the second word matches the expected MIPS16 instruction. */
16508 if (opcode
== 0x651aeb00)
16512 /* Truncated table??? */
16513 if (plt_offset
+ 16 > plt
->size
)
16515 gotplt_addr
= bfd_get_32 (abfd
, plt_data
+ plt_offset
+ 12);
16516 entry_size
= 2 * ARRAY_SIZE (mips16_o32_exec_plt_entry
);
16517 suffixlen
= sizeof (m16suffix
);
16518 suffix
= m16suffix
;
16519 other
= STO_MIPS16
;
16521 /* Likewise the expected microMIPS instruction (no insn32 mode). */
16522 else if (opcode
== 0xff220000)
16526 gotplt_hi
= bfd_get_16 (abfd
, plt_data
+ plt_offset
) & 0x7f;
16527 gotplt_lo
= bfd_get_16 (abfd
, plt_data
+ plt_offset
+ 2) & 0xffff;
16528 gotplt_hi
= ((gotplt_hi
^ 0x40) - 0x40) << 18;
16530 gotplt_addr
= gotplt_hi
+ gotplt_lo
;
16531 gotplt_addr
+= ((plt
->vma
+ plt_offset
) | 3) ^ 3;
16532 entry_size
= 2 * ARRAY_SIZE (micromips_o32_exec_plt_entry
);
16533 suffixlen
= sizeof (microsuffix
);
16534 suffix
= microsuffix
;
16535 other
= STO_MICROMIPS
;
16537 /* Likewise the expected microMIPS instruction (insn32 mode). */
16538 else if ((opcode
& 0xffff0000) == 0xff2f0000)
16540 gotplt_hi
= bfd_get_16 (abfd
, plt_data
+ plt_offset
+ 2) & 0xffff;
16541 gotplt_lo
= bfd_get_16 (abfd
, plt_data
+ plt_offset
+ 6) & 0xffff;
16542 gotplt_hi
= ((gotplt_hi
^ 0x8000) - 0x8000) << 16;
16543 gotplt_lo
= (gotplt_lo
^ 0x8000) - 0x8000;
16544 gotplt_addr
= gotplt_hi
+ gotplt_lo
;
16545 entry_size
= 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt_entry
);
16546 suffixlen
= sizeof (microsuffix
);
16547 suffix
= microsuffix
;
16548 other
= STO_MICROMIPS
;
16550 /* Otherwise assume standard MIPS code. */
16553 gotplt_hi
= bfd_get_32 (abfd
, plt_data
+ plt_offset
) & 0xffff;
16554 gotplt_lo
= bfd_get_32 (abfd
, plt_data
+ plt_offset
+ 4) & 0xffff;
16555 gotplt_hi
= ((gotplt_hi
^ 0x8000) - 0x8000) << 16;
16556 gotplt_lo
= (gotplt_lo
^ 0x8000) - 0x8000;
16557 gotplt_addr
= gotplt_hi
+ gotplt_lo
;
16558 entry_size
= 4 * ARRAY_SIZE (mips_exec_plt_entry
);
16559 suffixlen
= sizeof (mipssuffix
);
16560 suffix
= mipssuffix
;
16563 /* Truncated table??? */
16564 if (plt_offset
+ entry_size
> plt
->size
)
16568 i
< count
&& p
[pi
].address
!= gotplt_addr
;
16569 i
++, pi
= (pi
+ bed
->s
->int_rels_per_ext_rel
) % counti
);
16576 *s
= **p
[pi
].sym_ptr_ptr
;
16577 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
16578 we are defining a symbol, ensure one of them is set. */
16579 if ((s
->flags
& BSF_LOCAL
) == 0)
16580 s
->flags
|= BSF_GLOBAL
;
16581 s
->flags
|= BSF_SYNTHETIC
;
16583 s
->value
= plt_offset
;
16585 s
->udata
.i
= other
;
16587 len
= strlen ((*p
[pi
].sym_ptr_ptr
)->name
);
16588 namelen
= len
+ suffixlen
;
16589 if (names
+ namelen
> nend
)
16592 memcpy (names
, (*p
[pi
].sym_ptr_ptr
)->name
, len
);
16594 memcpy (names
, suffix
, suffixlen
);
16595 names
+= suffixlen
;
16598 pi
= (pi
+ bed
->s
->int_rels_per_ext_rel
) % counti
;
16607 /* Return the ABI flags associated with ABFD if available. */
16609 Elf_Internal_ABIFlags_v0
*
16610 bfd_mips_elf_get_abiflags (bfd
*abfd
)
16612 struct mips_elf_obj_tdata
*tdata
= mips_elf_tdata (abfd
);
16614 return tdata
->abiflags_valid
? &tdata
->abiflags
: NULL
;
16617 /* MIPS libc ABI versions, used with the EI_ABIVERSION ELF file header
16618 field. Taken from `libc-abis.h' generated at GNU libc build time.
16619 Using a MIPS_ prefix as other libc targets use different values. */
16622 MIPS_LIBC_ABI_DEFAULT
= 0,
16623 MIPS_LIBC_ABI_MIPS_PLT
,
16624 MIPS_LIBC_ABI_UNIQUE
,
16625 MIPS_LIBC_ABI_MIPS_O32_FP64
,
16626 MIPS_LIBC_ABI_ABSOLUTE
,
16627 MIPS_LIBC_ABI_XHASH
,
16632 _bfd_mips_init_file_header (bfd
*abfd
, struct bfd_link_info
*link_info
)
16634 struct mips_elf_link_hash_table
*htab
= NULL
;
16635 Elf_Internal_Ehdr
*i_ehdrp
;
16637 if (!_bfd_elf_init_file_header (abfd
, link_info
))
16640 i_ehdrp
= elf_elfheader (abfd
);
16643 htab
= mips_elf_hash_table (link_info
);
16644 BFD_ASSERT (htab
!= NULL
);
16648 && htab
->use_plts_and_copy_relocs
16649 && htab
->root
.target_os
!= is_vxworks
)
16650 i_ehdrp
->e_ident
[EI_ABIVERSION
] = MIPS_LIBC_ABI_MIPS_PLT
;
16652 if (mips_elf_tdata (abfd
)->abiflags
.fp_abi
== Val_GNU_MIPS_ABI_FP_64
16653 || mips_elf_tdata (abfd
)->abiflags
.fp_abi
== Val_GNU_MIPS_ABI_FP_64A
)
16654 i_ehdrp
->e_ident
[EI_ABIVERSION
] = MIPS_LIBC_ABI_MIPS_O32_FP64
;
16656 /* Mark that we need support for absolute symbols in the dynamic loader. */
16657 if (htab
!= NULL
&& htab
->use_absolute_zero
&& htab
->gnu_target
)
16658 i_ehdrp
->e_ident
[EI_ABIVERSION
] = MIPS_LIBC_ABI_ABSOLUTE
;
16660 /* Mark that we need support for .MIPS.xhash in the dynamic linker,
16661 if it is the only hash section that will be created. */
16662 if (link_info
&& link_info
->emit_gnu_hash
&& !link_info
->emit_hash
)
16663 i_ehdrp
->e_ident
[EI_ABIVERSION
] = MIPS_LIBC_ABI_XHASH
;
16668 _bfd_mips_elf_compact_eh_encoding
16669 (struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
16671 return DW_EH_PE_pcrel
| DW_EH_PE_sdata4
;
16674 /* Return the opcode for can't unwind. */
16677 _bfd_mips_elf_cant_unwind_opcode
16678 (struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
16680 return COMPACT_EH_CANT_UNWIND_OPCODE
;
16683 /* Record a position XLAT_LOC in the xlat translation table, associated with
16684 the hash entry H. The entry in the translation table will later be
16685 populated with the real symbol dynindx. */
16688 _bfd_mips_elf_record_xhash_symbol (struct elf_link_hash_entry
*h
,
16691 struct mips_elf_link_hash_entry
*hmips
;
16693 hmips
= (struct mips_elf_link_hash_entry
*) h
;
16694 hmips
->mipsxhash_loc
= xlat_loc
;