1 /* MIPS-specific support for ELF
2 Copyright 1993-2013 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
6 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
7 <mark@codesourcery.com>
8 Traditional MIPS targets support added by Koundinya.K, Dansk Data
9 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
11 This file is part of BFD, the Binary File Descriptor library.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
26 MA 02110-1301, USA. */
29 /* This file handles functionality common to the different MIPS ABI's. */
34 #include "libiberty.h"
36 #include "elfxx-mips.h"
38 #include "elf-vxworks.h"
40 /* Get the ECOFF swapping routines. */
42 #include "coff/symconst.h"
43 #include "coff/ecoff.h"
44 #include "coff/mips.h"
48 /* Types of TLS GOT entry. */
49 enum mips_got_tls_type
{
56 /* This structure is used to hold information about one GOT entry.
57 There are four types of entry:
59 (1) an absolute address
60 requires: abfd == NULL
63 (2) a SYMBOL + OFFSET address, where SYMBOL is local to an input bfd
64 requires: abfd != NULL, symndx >= 0, tls_type != GOT_TLS_LDM
65 fields: abfd, symndx, d.addend, tls_type
67 (3) a SYMBOL address, where SYMBOL is not local to an input bfd
68 requires: abfd != NULL, symndx == -1
72 requires: abfd != NULL, symndx == 0, tls_type == GOT_TLS_LDM
73 fields: none; there's only one of these per GOT. */
76 /* One input bfd that needs the GOT entry. */
78 /* The index of the symbol, as stored in the relocation r_info, if
79 we have a local symbol; -1 otherwise. */
83 /* If abfd == NULL, an address that must be stored in the got. */
85 /* If abfd != NULL && symndx != -1, the addend of the relocation
86 that should be added to the symbol value. */
88 /* If abfd != NULL && symndx == -1, the hash table entry
89 corresponding to a symbol in the GOT. The symbol's entry
90 is in the local area if h->global_got_area is GGA_NONE,
91 otherwise it is in the global area. */
92 struct mips_elf_link_hash_entry
*h
;
95 /* The TLS type of this GOT entry. An LDM GOT entry will be a local
96 symbol entry with r_symndx == 0. */
97 unsigned char tls_type
;
99 /* True if we have filled in the GOT contents for a TLS entry,
100 and created the associated relocations. */
101 unsigned char tls_initialized
;
103 /* The offset from the beginning of the .got section to the entry
104 corresponding to this symbol+addend. If it's a global symbol
105 whose offset is yet to be decided, it's going to be -1. */
109 /* This structure represents a GOT page reference from an input bfd.
110 Each instance represents a symbol + ADDEND, where the representation
111 of the symbol depends on whether it is local to the input bfd.
112 If it is, then SYMNDX >= 0, and the symbol has index SYMNDX in U.ABFD.
113 Otherwise, SYMNDX < 0 and U.H points to the symbol's hash table entry.
115 Page references with SYMNDX >= 0 always become page references
116 in the output. Page references with SYMNDX < 0 only become page
117 references if the symbol binds locally; in other cases, the page
118 reference decays to a global GOT reference. */
119 struct mips_got_page_ref
124 struct mips_elf_link_hash_entry
*h
;
130 /* This structure describes a range of addends: [MIN_ADDEND, MAX_ADDEND].
131 The structures form a non-overlapping list that is sorted by increasing
133 struct mips_got_page_range
135 struct mips_got_page_range
*next
;
136 bfd_signed_vma min_addend
;
137 bfd_signed_vma max_addend
;
140 /* This structure describes the range of addends that are applied to page
141 relocations against a given section. */
142 struct mips_got_page_entry
144 /* The section that these entries are based on. */
146 /* The ranges for this page entry. */
147 struct mips_got_page_range
*ranges
;
148 /* The maximum number of page entries needed for RANGES. */
152 /* This structure is used to hold .got information when linking. */
156 /* The number of global .got entries. */
157 unsigned int global_gotno
;
158 /* The number of global .got entries that are in the GGA_RELOC_ONLY area. */
159 unsigned int reloc_only_gotno
;
160 /* The number of .got slots used for TLS. */
161 unsigned int tls_gotno
;
162 /* The first unused TLS .got entry. Used only during
163 mips_elf_initialize_tls_index. */
164 unsigned int tls_assigned_gotno
;
165 /* The number of local .got entries, eventually including page entries. */
166 unsigned int local_gotno
;
167 /* The maximum number of page entries needed. */
168 unsigned int page_gotno
;
169 /* The number of relocations needed for the GOT entries. */
171 /* The number of local .got entries we have used. */
172 unsigned int assigned_gotno
;
173 /* A hash table holding members of the got. */
174 struct htab
*got_entries
;
175 /* A hash table holding mips_got_page_ref structures. */
176 struct htab
*got_page_refs
;
177 /* A hash table of mips_got_page_entry structures. */
178 struct htab
*got_page_entries
;
179 /* In multi-got links, a pointer to the next got (err, rather, most
180 of the time, it points to the previous got). */
181 struct mips_got_info
*next
;
184 /* Structure passed when merging bfds' gots. */
186 struct mips_elf_got_per_bfd_arg
188 /* The output bfd. */
190 /* The link information. */
191 struct bfd_link_info
*info
;
192 /* A pointer to the primary got, i.e., the one that's going to get
193 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
195 struct mips_got_info
*primary
;
196 /* A non-primary got we're trying to merge with other input bfd's
198 struct mips_got_info
*current
;
199 /* The maximum number of got entries that can be addressed with a
201 unsigned int max_count
;
202 /* The maximum number of page entries needed by each got. */
203 unsigned int max_pages
;
204 /* The total number of global entries which will live in the
205 primary got and be automatically relocated. This includes
206 those not referenced by the primary GOT but included in
208 unsigned int global_count
;
211 /* A structure used to pass information to htab_traverse callbacks
212 when laying out the GOT. */
214 struct mips_elf_traverse_got_arg
216 struct bfd_link_info
*info
;
217 struct mips_got_info
*g
;
221 struct _mips_elf_section_data
223 struct bfd_elf_section_data elf
;
230 #define mips_elf_section_data(sec) \
231 ((struct _mips_elf_section_data *) elf_section_data (sec))
233 #define is_mips_elf(bfd) \
234 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
235 && elf_tdata (bfd) != NULL \
236 && elf_object_id (bfd) == MIPS_ELF_DATA)
238 /* The ABI says that every symbol used by dynamic relocations must have
239 a global GOT entry. Among other things, this provides the dynamic
240 linker with a free, directly-indexed cache. The GOT can therefore
241 contain symbols that are not referenced by GOT relocations themselves
242 (in other words, it may have symbols that are not referenced by things
243 like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
245 GOT relocations are less likely to overflow if we put the associated
246 GOT entries towards the beginning. We therefore divide the global
247 GOT entries into two areas: "normal" and "reloc-only". Entries in
248 the first area can be used for both dynamic relocations and GP-relative
249 accesses, while those in the "reloc-only" area are for dynamic
252 These GGA_* ("Global GOT Area") values are organised so that lower
253 values are more general than higher values. Also, non-GGA_NONE
254 values are ordered by the position of the area in the GOT. */
256 #define GGA_RELOC_ONLY 1
259 /* Information about a non-PIC interface to a PIC function. There are
260 two ways of creating these interfaces. The first is to add:
263 addiu $25,$25,%lo(func)
265 immediately before a PIC function "func". The second is to add:
269 addiu $25,$25,%lo(func)
271 to a separate trampoline section.
273 Stubs of the first kind go in a new section immediately before the
274 target function. Stubs of the second kind go in a single section
275 pointed to by the hash table's "strampoline" field. */
276 struct mips_elf_la25_stub
{
277 /* The generated section that contains this stub. */
278 asection
*stub_section
;
280 /* The offset of the stub from the start of STUB_SECTION. */
283 /* One symbol for the original function. Its location is available
284 in H->root.root.u.def. */
285 struct mips_elf_link_hash_entry
*h
;
288 /* Macros for populating a mips_elf_la25_stub. */
290 #define LA25_LUI(VAL) (0x3c190000 | (VAL)) /* lui t9,VAL */
291 #define LA25_J(VAL) (0x08000000 | (((VAL) >> 2) & 0x3ffffff)) /* j VAL */
292 #define LA25_ADDIU(VAL) (0x27390000 | (VAL)) /* addiu t9,t9,VAL */
293 #define LA25_LUI_MICROMIPS(VAL) \
294 (0x41b90000 | (VAL)) /* lui t9,VAL */
295 #define LA25_J_MICROMIPS(VAL) \
296 (0xd4000000 | (((VAL) >> 1) & 0x3ffffff)) /* j VAL */
297 #define LA25_ADDIU_MICROMIPS(VAL) \
298 (0x33390000 | (VAL)) /* addiu t9,t9,VAL */
300 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
301 the dynamic symbols. */
303 struct mips_elf_hash_sort_data
305 /* The symbol in the global GOT with the lowest dynamic symbol table
307 struct elf_link_hash_entry
*low
;
308 /* The least dynamic symbol table index corresponding to a non-TLS
309 symbol with a GOT entry. */
310 long min_got_dynindx
;
311 /* The greatest dynamic symbol table index corresponding to a symbol
312 with a GOT entry that is not referenced (e.g., a dynamic symbol
313 with dynamic relocations pointing to it from non-primary GOTs). */
314 long max_unref_got_dynindx
;
315 /* The greatest dynamic symbol table index not corresponding to a
316 symbol without a GOT entry. */
317 long max_non_got_dynindx
;
320 /* We make up to two PLT entries if needed, one for standard MIPS code
321 and one for compressed code, either a MIPS16 or microMIPS one. We
322 keep a separate record of traditional lazy-binding stubs, for easier
327 /* Traditional SVR4 stub offset, or -1 if none. */
330 /* Standard PLT entry offset, or -1 if none. */
333 /* Compressed PLT entry offset, or -1 if none. */
336 /* The corresponding .got.plt index, or -1 if none. */
337 bfd_vma gotplt_index
;
339 /* Whether we need a standard PLT entry. */
340 unsigned int need_mips
: 1;
342 /* Whether we need a compressed PLT entry. */
343 unsigned int need_comp
: 1;
346 /* The MIPS ELF linker needs additional information for each symbol in
347 the global hash table. */
349 struct mips_elf_link_hash_entry
351 struct elf_link_hash_entry root
;
353 /* External symbol information. */
356 /* The la25 stub we have created for ths symbol, if any. */
357 struct mips_elf_la25_stub
*la25_stub
;
359 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
361 unsigned int possibly_dynamic_relocs
;
363 /* If there is a stub that 32 bit functions should use to call this
364 16 bit function, this points to the section containing the stub. */
367 /* If there is a stub that 16 bit functions should use to call this
368 32 bit function, this points to the section containing the stub. */
371 /* This is like the call_stub field, but it is used if the function
372 being called returns a floating point value. */
373 asection
*call_fp_stub
;
375 /* The highest GGA_* value that satisfies all references to this symbol. */
376 unsigned int global_got_area
: 2;
378 /* True if all GOT relocations against this symbol are for calls. This is
379 a looser condition than no_fn_stub below, because there may be other
380 non-call non-GOT relocations against the symbol. */
381 unsigned int got_only_for_calls
: 1;
383 /* True if one of the relocations described by possibly_dynamic_relocs
384 is against a readonly section. */
385 unsigned int readonly_reloc
: 1;
387 /* True if there is a relocation against this symbol that must be
388 resolved by the static linker (in other words, if the relocation
389 cannot possibly be made dynamic). */
390 unsigned int has_static_relocs
: 1;
392 /* True if we must not create a .MIPS.stubs entry for this symbol.
393 This is set, for example, if there are relocations related to
394 taking the function's address, i.e. any but R_MIPS_CALL*16 ones.
395 See "MIPS ABI Supplement, 3rd Edition", p. 4-20. */
396 unsigned int no_fn_stub
: 1;
398 /* Whether we need the fn_stub; this is true if this symbol appears
399 in any relocs other than a 16 bit call. */
400 unsigned int need_fn_stub
: 1;
402 /* True if this symbol is referenced by branch relocations from
403 any non-PIC input file. This is used to determine whether an
404 la25 stub is required. */
405 unsigned int has_nonpic_branches
: 1;
407 /* Does this symbol need a traditional MIPS lazy-binding stub
408 (as opposed to a PLT entry)? */
409 unsigned int needs_lazy_stub
: 1;
411 /* Does this symbol resolve to a PLT entry? */
412 unsigned int use_plt_entry
: 1;
415 /* MIPS ELF linker hash table. */
417 struct mips_elf_link_hash_table
419 struct elf_link_hash_table root
;
421 /* The number of .rtproc entries. */
422 bfd_size_type procedure_count
;
424 /* The size of the .compact_rel section (if SGI_COMPAT). */
425 bfd_size_type compact_rel_size
;
427 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic entry
428 is set to the address of __rld_obj_head as in IRIX5 and IRIX6. */
429 bfd_boolean use_rld_obj_head
;
431 /* The __rld_map or __rld_obj_head symbol. */
432 struct elf_link_hash_entry
*rld_symbol
;
434 /* This is set if we see any mips16 stub sections. */
435 bfd_boolean mips16_stubs_seen
;
437 /* True if we can generate copy relocs and PLTs. */
438 bfd_boolean use_plts_and_copy_relocs
;
440 /* True if we can only use 32-bit microMIPS instructions. */
443 /* True if we're generating code for VxWorks. */
444 bfd_boolean is_vxworks
;
446 /* True if we already reported the small-data section overflow. */
447 bfd_boolean small_data_overflow_reported
;
449 /* Shortcuts to some dynamic sections, or NULL if they are not
460 /* The master GOT information. */
461 struct mips_got_info
*got_info
;
463 /* The global symbol in the GOT with the lowest index in the dynamic
465 struct elf_link_hash_entry
*global_gotsym
;
467 /* The size of the PLT header in bytes. */
468 bfd_vma plt_header_size
;
470 /* The size of a standard PLT entry in bytes. */
471 bfd_vma plt_mips_entry_size
;
473 /* The size of a compressed PLT entry in bytes. */
474 bfd_vma plt_comp_entry_size
;
476 /* The offset of the next standard PLT entry to create. */
477 bfd_vma plt_mips_offset
;
479 /* The offset of the next compressed PLT entry to create. */
480 bfd_vma plt_comp_offset
;
482 /* The index of the next .got.plt entry to create. */
483 bfd_vma plt_got_index
;
485 /* The number of functions that need a lazy-binding stub. */
486 bfd_vma lazy_stub_count
;
488 /* The size of a function stub entry in bytes. */
489 bfd_vma function_stub_size
;
491 /* The number of reserved entries at the beginning of the GOT. */
492 unsigned int reserved_gotno
;
494 /* The section used for mips_elf_la25_stub trampolines.
495 See the comment above that structure for details. */
496 asection
*strampoline
;
498 /* A table of mips_elf_la25_stubs, indexed by (input_section, offset)
502 /* A function FN (NAME, IS, OS) that creates a new input section
503 called NAME and links it to output section OS. If IS is nonnull,
504 the new section should go immediately before it, otherwise it
505 should go at the (current) beginning of OS.
507 The function returns the new section on success, otherwise it
509 asection
*(*add_stub_section
) (const char *, asection
*, asection
*);
511 /* Small local sym cache. */
512 struct sym_cache sym_cache
;
514 /* Is the PLT header compressed? */
515 unsigned int plt_header_is_comp
: 1;
518 /* Get the MIPS ELF linker hash table from a link_info structure. */
520 #define mips_elf_hash_table(p) \
521 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
522 == MIPS_ELF_DATA ? ((struct mips_elf_link_hash_table *) ((p)->hash)) : NULL)
524 /* A structure used to communicate with htab_traverse callbacks. */
525 struct mips_htab_traverse_info
527 /* The usual link-wide information. */
528 struct bfd_link_info
*info
;
531 /* Starts off FALSE and is set to TRUE if the link should be aborted. */
535 /* MIPS ELF private object data. */
537 struct mips_elf_obj_tdata
539 /* Generic ELF private object data. */
540 struct elf_obj_tdata root
;
542 /* Input BFD providing Tag_GNU_MIPS_ABI_FP attribute for output. */
545 /* The GOT requirements of input bfds. */
546 struct mips_got_info
*got
;
548 /* Used by _bfd_mips_elf_find_nearest_line. The structure could be
549 included directly in this one, but there's no point to wasting
550 the memory just for the infrequently called find_nearest_line. */
551 struct mips_elf_find_line
*find_line_info
;
553 /* An array of stub sections indexed by symbol number. */
554 asection
**local_stubs
;
555 asection
**local_call_stubs
;
557 /* The Irix 5 support uses two virtual sections, which represent
558 text/data symbols defined in dynamic objects. */
559 asymbol
*elf_data_symbol
;
560 asymbol
*elf_text_symbol
;
561 asection
*elf_data_section
;
562 asection
*elf_text_section
;
565 /* Get MIPS ELF private object data from BFD's tdata. */
567 #define mips_elf_tdata(bfd) \
568 ((struct mips_elf_obj_tdata *) (bfd)->tdata.any)
570 #define TLS_RELOC_P(r_type) \
571 (r_type == R_MIPS_TLS_DTPMOD32 \
572 || r_type == R_MIPS_TLS_DTPMOD64 \
573 || r_type == R_MIPS_TLS_DTPREL32 \
574 || r_type == R_MIPS_TLS_DTPREL64 \
575 || r_type == R_MIPS_TLS_GD \
576 || r_type == R_MIPS_TLS_LDM \
577 || r_type == R_MIPS_TLS_DTPREL_HI16 \
578 || r_type == R_MIPS_TLS_DTPREL_LO16 \
579 || r_type == R_MIPS_TLS_GOTTPREL \
580 || r_type == R_MIPS_TLS_TPREL32 \
581 || r_type == R_MIPS_TLS_TPREL64 \
582 || r_type == R_MIPS_TLS_TPREL_HI16 \
583 || r_type == R_MIPS_TLS_TPREL_LO16 \
584 || r_type == R_MIPS16_TLS_GD \
585 || r_type == R_MIPS16_TLS_LDM \
586 || r_type == R_MIPS16_TLS_DTPREL_HI16 \
587 || r_type == R_MIPS16_TLS_DTPREL_LO16 \
588 || r_type == R_MIPS16_TLS_GOTTPREL \
589 || r_type == R_MIPS16_TLS_TPREL_HI16 \
590 || r_type == R_MIPS16_TLS_TPREL_LO16 \
591 || r_type == R_MICROMIPS_TLS_GD \
592 || r_type == R_MICROMIPS_TLS_LDM \
593 || r_type == R_MICROMIPS_TLS_DTPREL_HI16 \
594 || r_type == R_MICROMIPS_TLS_DTPREL_LO16 \
595 || r_type == R_MICROMIPS_TLS_GOTTPREL \
596 || r_type == R_MICROMIPS_TLS_TPREL_HI16 \
597 || r_type == R_MICROMIPS_TLS_TPREL_LO16)
599 /* Structure used to pass information to mips_elf_output_extsym. */
604 struct bfd_link_info
*info
;
605 struct ecoff_debug_info
*debug
;
606 const struct ecoff_debug_swap
*swap
;
610 /* The names of the runtime procedure table symbols used on IRIX5. */
612 static const char * const mips_elf_dynsym_rtproc_names
[] =
615 "_procedure_string_table",
616 "_procedure_table_size",
620 /* These structures are used to generate the .compact_rel section on
625 unsigned long id1
; /* Always one? */
626 unsigned long num
; /* Number of compact relocation entries. */
627 unsigned long id2
; /* Always two? */
628 unsigned long offset
; /* The file offset of the first relocation. */
629 unsigned long reserved0
; /* Zero? */
630 unsigned long reserved1
; /* Zero? */
639 bfd_byte reserved0
[4];
640 bfd_byte reserved1
[4];
641 } Elf32_External_compact_rel
;
645 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
646 unsigned int rtype
: 4; /* Relocation types. See below. */
647 unsigned int dist2to
: 8;
648 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
649 unsigned long konst
; /* KONST field. See below. */
650 unsigned long vaddr
; /* VADDR to be relocated. */
655 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
656 unsigned int rtype
: 4; /* Relocation types. See below. */
657 unsigned int dist2to
: 8;
658 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
659 unsigned long konst
; /* KONST field. See below. */
667 } Elf32_External_crinfo
;
673 } Elf32_External_crinfo2
;
675 /* These are the constants used to swap the bitfields in a crinfo. */
677 #define CRINFO_CTYPE (0x1)
678 #define CRINFO_CTYPE_SH (31)
679 #define CRINFO_RTYPE (0xf)
680 #define CRINFO_RTYPE_SH (27)
681 #define CRINFO_DIST2TO (0xff)
682 #define CRINFO_DIST2TO_SH (19)
683 #define CRINFO_RELVADDR (0x7ffff)
684 #define CRINFO_RELVADDR_SH (0)
686 /* A compact relocation info has long (3 words) or short (2 words)
687 formats. A short format doesn't have VADDR field and relvaddr
688 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
689 #define CRF_MIPS_LONG 1
690 #define CRF_MIPS_SHORT 0
692 /* There are 4 types of compact relocation at least. The value KONST
693 has different meaning for each type:
696 CT_MIPS_REL32 Address in data
697 CT_MIPS_WORD Address in word (XXX)
698 CT_MIPS_GPHI_LO GP - vaddr
699 CT_MIPS_JMPAD Address to jump
702 #define CRT_MIPS_REL32 0xa
703 #define CRT_MIPS_WORD 0xb
704 #define CRT_MIPS_GPHI_LO 0xc
705 #define CRT_MIPS_JMPAD 0xd
707 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
708 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
709 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
710 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
712 /* The structure of the runtime procedure descriptor created by the
713 loader for use by the static exception system. */
715 typedef struct runtime_pdr
{
716 bfd_vma adr
; /* Memory address of start of procedure. */
717 long regmask
; /* Save register mask. */
718 long regoffset
; /* Save register offset. */
719 long fregmask
; /* Save floating point register mask. */
720 long fregoffset
; /* Save floating point register offset. */
721 long frameoffset
; /* Frame size. */
722 short framereg
; /* Frame pointer register. */
723 short pcreg
; /* Offset or reg of return pc. */
724 long irpss
; /* Index into the runtime string table. */
726 struct exception_info
*exception_info
;/* Pointer to exception array. */
728 #define cbRPDR sizeof (RPDR)
729 #define rpdNil ((pRPDR) 0)
731 static struct mips_got_entry
*mips_elf_create_local_got_entry
732 (bfd
*, struct bfd_link_info
*, bfd
*, bfd_vma
, unsigned long,
733 struct mips_elf_link_hash_entry
*, int);
734 static bfd_boolean mips_elf_sort_hash_table_f
735 (struct mips_elf_link_hash_entry
*, void *);
736 static bfd_vma mips_elf_high
738 static bfd_boolean mips_elf_create_dynamic_relocation
739 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
740 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
741 bfd_vma
*, asection
*);
742 static bfd_vma mips_elf_adjust_gp
743 (bfd
*, struct mips_got_info
*, bfd
*);
745 /* This will be used when we sort the dynamic relocation records. */
746 static bfd
*reldyn_sorting_bfd
;
748 /* True if ABFD is for CPUs with load interlocking that include
749 non-MIPS1 CPUs and R3900. */
750 #define LOAD_INTERLOCKS_P(abfd) \
751 ( ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) != E_MIPS_ARCH_1) \
752 || ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_3900))
754 /* True if ABFD is for CPUs that are faster if JAL is converted to BAL.
755 This should be safe for all architectures. We enable this predicate
756 for RM9000 for now. */
757 #define JAL_TO_BAL_P(abfd) \
758 ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_9000)
760 /* True if ABFD is for CPUs that are faster if JALR is converted to BAL.
761 This should be safe for all architectures. We enable this predicate for
763 #define JALR_TO_BAL_P(abfd) 1
765 /* True if ABFD is for CPUs that are faster if JR is converted to B.
766 This should be safe for all architectures. We enable this predicate for
768 #define JR_TO_B_P(abfd) 1
770 /* True if ABFD is a PIC object. */
771 #define PIC_OBJECT_P(abfd) \
772 ((elf_elfheader (abfd)->e_flags & EF_MIPS_PIC) != 0)
774 /* Nonzero if ABFD is using the N32 ABI. */
775 #define ABI_N32_P(abfd) \
776 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
778 /* Nonzero if ABFD is using the N64 ABI. */
779 #define ABI_64_P(abfd) \
780 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
782 /* Nonzero if ABFD is using NewABI conventions. */
783 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
785 /* Nonzero if ABFD has microMIPS code. */
786 #define MICROMIPS_P(abfd) \
787 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) != 0)
789 /* The IRIX compatibility level we are striving for. */
790 #define IRIX_COMPAT(abfd) \
791 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
793 /* Whether we are trying to be compatible with IRIX at all. */
794 #define SGI_COMPAT(abfd) \
795 (IRIX_COMPAT (abfd) != ict_none)
797 /* The name of the options section. */
798 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
799 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
801 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
802 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
803 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
804 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
806 /* Whether the section is readonly. */
807 #define MIPS_ELF_READONLY_SECTION(sec) \
808 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
809 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
811 /* The name of the stub section. */
812 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
814 /* The size of an external REL relocation. */
815 #define MIPS_ELF_REL_SIZE(abfd) \
816 (get_elf_backend_data (abfd)->s->sizeof_rel)
818 /* The size of an external RELA relocation. */
819 #define MIPS_ELF_RELA_SIZE(abfd) \
820 (get_elf_backend_data (abfd)->s->sizeof_rela)
822 /* The size of an external dynamic table entry. */
823 #define MIPS_ELF_DYN_SIZE(abfd) \
824 (get_elf_backend_data (abfd)->s->sizeof_dyn)
826 /* The size of a GOT entry. */
827 #define MIPS_ELF_GOT_SIZE(abfd) \
828 (get_elf_backend_data (abfd)->s->arch_size / 8)
830 /* The size of the .rld_map section. */
831 #define MIPS_ELF_RLD_MAP_SIZE(abfd) \
832 (get_elf_backend_data (abfd)->s->arch_size / 8)
834 /* The size of a symbol-table entry. */
835 #define MIPS_ELF_SYM_SIZE(abfd) \
836 (get_elf_backend_data (abfd)->s->sizeof_sym)
838 /* The default alignment for sections, as a power of two. */
839 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
840 (get_elf_backend_data (abfd)->s->log_file_align)
842 /* Get word-sized data. */
843 #define MIPS_ELF_GET_WORD(abfd, ptr) \
844 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
846 /* Put out word-sized data. */
847 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
849 ? bfd_put_64 (abfd, val, ptr) \
850 : bfd_put_32 (abfd, val, ptr))
852 /* The opcode for word-sized loads (LW or LD). */
853 #define MIPS_ELF_LOAD_WORD(abfd) \
854 (ABI_64_P (abfd) ? 0xdc000000 : 0x8c000000)
856 /* Add a dynamic symbol table-entry. */
857 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
858 _bfd_elf_add_dynamic_entry (info, tag, val)
860 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
861 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
863 /* The name of the dynamic relocation section. */
864 #define MIPS_ELF_REL_DYN_NAME(INFO) \
865 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
867 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
868 from smaller values. Start with zero, widen, *then* decrement. */
869 #define MINUS_ONE (((bfd_vma)0) - 1)
870 #define MINUS_TWO (((bfd_vma)0) - 2)
872 /* The value to write into got[1] for SVR4 targets, to identify it is
873 a GNU object. The dynamic linker can then use got[1] to store the
875 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
876 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
878 /* The offset of $gp from the beginning of the .got section. */
879 #define ELF_MIPS_GP_OFFSET(INFO) \
880 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
882 /* The maximum size of the GOT for it to be addressable using 16-bit
884 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
886 /* Instructions which appear in a stub. */
887 #define STUB_LW(abfd) \
889 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
890 : 0x8f998010)) /* lw t9,0x8010(gp) */
891 #define STUB_MOVE(abfd) \
893 ? 0x03e0782d /* daddu t7,ra */ \
894 : 0x03e07821)) /* addu t7,ra */
895 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
896 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
897 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
898 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
899 #define STUB_LI16S(abfd, VAL) \
901 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
902 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
904 /* Likewise for the microMIPS ASE. */
905 #define STUB_LW_MICROMIPS(abfd) \
907 ? 0xdf3c8010 /* ld t9,0x8010(gp) */ \
908 : 0xff3c8010) /* lw t9,0x8010(gp) */
909 #define STUB_MOVE_MICROMIPS 0x0dff /* move t7,ra */
910 #define STUB_MOVE32_MICROMIPS(abfd) \
912 ? 0x581f7950 /* daddu t7,ra,zero */ \
913 : 0x001f7950) /* addu t7,ra,zero */
914 #define STUB_LUI_MICROMIPS(VAL) \
915 (0x41b80000 + (VAL)) /* lui t8,VAL */
916 #define STUB_JALR_MICROMIPS 0x45d9 /* jalr t9 */
917 #define STUB_JALR32_MICROMIPS 0x03f90f3c /* jalr ra,t9 */
918 #define STUB_ORI_MICROMIPS(VAL) \
919 (0x53180000 + (VAL)) /* ori t8,t8,VAL */
920 #define STUB_LI16U_MICROMIPS(VAL) \
921 (0x53000000 + (VAL)) /* ori t8,zero,VAL unsigned */
922 #define STUB_LI16S_MICROMIPS(abfd, VAL) \
924 ? 0x5f000000 + (VAL) /* daddiu t8,zero,VAL sign extended */ \
925 : 0x33000000 + (VAL)) /* addiu t8,zero,VAL sign extended */
927 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
928 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
929 #define MICROMIPS_FUNCTION_STUB_NORMAL_SIZE 12
930 #define MICROMIPS_FUNCTION_STUB_BIG_SIZE 16
931 #define MICROMIPS_INSN32_FUNCTION_STUB_NORMAL_SIZE 16
932 #define MICROMIPS_INSN32_FUNCTION_STUB_BIG_SIZE 20
934 /* The name of the dynamic interpreter. This is put in the .interp
937 #define ELF_DYNAMIC_INTERPRETER(abfd) \
938 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
939 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
940 : "/usr/lib/libc.so.1")
943 #define MNAME(bfd,pre,pos) \
944 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
945 #define ELF_R_SYM(bfd, i) \
946 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
947 #define ELF_R_TYPE(bfd, i) \
948 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
949 #define ELF_R_INFO(bfd, s, t) \
950 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
952 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
953 #define ELF_R_SYM(bfd, i) \
955 #define ELF_R_TYPE(bfd, i) \
957 #define ELF_R_INFO(bfd, s, t) \
958 (ELF32_R_INFO (s, t))
961 /* The mips16 compiler uses a couple of special sections to handle
962 floating point arguments.
964 Section names that look like .mips16.fn.FNNAME contain stubs that
965 copy floating point arguments from the fp regs to the gp regs and
966 then jump to FNNAME. If any 32 bit function calls FNNAME, the
967 call should be redirected to the stub instead. If no 32 bit
968 function calls FNNAME, the stub should be discarded. We need to
969 consider any reference to the function, not just a call, because
970 if the address of the function is taken we will need the stub,
971 since the address might be passed to a 32 bit function.
973 Section names that look like .mips16.call.FNNAME contain stubs
974 that copy floating point arguments from the gp regs to the fp
975 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
976 then any 16 bit function that calls FNNAME should be redirected
977 to the stub instead. If FNNAME is not a 32 bit function, the
978 stub should be discarded.
980 .mips16.call.fp.FNNAME sections are similar, but contain stubs
981 which call FNNAME and then copy the return value from the fp regs
982 to the gp regs. These stubs store the return value in $18 while
983 calling FNNAME; any function which might call one of these stubs
984 must arrange to save $18 around the call. (This case is not
985 needed for 32 bit functions that call 16 bit functions, because
986 16 bit functions always return floating point values in both
989 Note that in all cases FNNAME might be defined statically.
990 Therefore, FNNAME is not used literally. Instead, the relocation
991 information will indicate which symbol the section is for.
993 We record any stubs that we find in the symbol table. */
995 #define FN_STUB ".mips16.fn."
996 #define CALL_STUB ".mips16.call."
997 #define CALL_FP_STUB ".mips16.call.fp."
999 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
1000 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
1001 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
1003 /* The format of the first PLT entry in an O32 executable. */
1004 static const bfd_vma mips_o32_exec_plt0_entry
[] =
1006 0x3c1c0000, /* lui $28, %hi(&GOTPLT[0]) */
1007 0x8f990000, /* lw $25, %lo(&GOTPLT[0])($28) */
1008 0x279c0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
1009 0x031cc023, /* subu $24, $24, $28 */
1010 0x03e07821, /* move $15, $31 # 32-bit move (addu) */
1011 0x0018c082, /* srl $24, $24, 2 */
1012 0x0320f809, /* jalr $25 */
1013 0x2718fffe /* subu $24, $24, 2 */
1016 /* The format of the first PLT entry in an N32 executable. Different
1017 because gp ($28) is not available; we use t2 ($14) instead. */
1018 static const bfd_vma mips_n32_exec_plt0_entry
[] =
1020 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
1021 0x8dd90000, /* lw $25, %lo(&GOTPLT[0])($14) */
1022 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
1023 0x030ec023, /* subu $24, $24, $14 */
1024 0x03e07821, /* move $15, $31 # 32-bit move (addu) */
1025 0x0018c082, /* srl $24, $24, 2 */
1026 0x0320f809, /* jalr $25 */
1027 0x2718fffe /* subu $24, $24, 2 */
1030 /* The format of the first PLT entry in an N64 executable. Different
1031 from N32 because of the increased size of GOT entries. */
1032 static const bfd_vma mips_n64_exec_plt0_entry
[] =
1034 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
1035 0xddd90000, /* ld $25, %lo(&GOTPLT[0])($14) */
1036 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
1037 0x030ec023, /* subu $24, $24, $14 */
1038 0x03e0782d, /* move $15, $31 # 64-bit move (daddu) */
1039 0x0018c0c2, /* srl $24, $24, 3 */
1040 0x0320f809, /* jalr $25 */
1041 0x2718fffe /* subu $24, $24, 2 */
1044 /* The format of the microMIPS first PLT entry in an O32 executable.
1045 We rely on v0 ($2) rather than t8 ($24) to contain the address
1046 of the GOTPLT entry handled, so this stub may only be used when
1047 all the subsequent PLT entries are microMIPS code too.
1049 The trailing NOP is for alignment and correct disassembly only. */
1050 static const bfd_vma micromips_o32_exec_plt0_entry
[] =
1052 0x7980, 0x0000, /* addiupc $3, (&GOTPLT[0]) - . */
1053 0xff23, 0x0000, /* lw $25, 0($3) */
1054 0x0535, /* subu $2, $2, $3 */
1055 0x2525, /* srl $2, $2, 2 */
1056 0x3302, 0xfffe, /* subu $24, $2, 2 */
1057 0x0dff, /* move $15, $31 */
1058 0x45f9, /* jalrs $25 */
1059 0x0f83, /* move $28, $3 */
1063 /* The format of the microMIPS first PLT entry in an O32 executable
1064 in the insn32 mode. */
1065 static const bfd_vma micromips_insn32_o32_exec_plt0_entry
[] =
1067 0x41bc, 0x0000, /* lui $28, %hi(&GOTPLT[0]) */
1068 0xff3c, 0x0000, /* lw $25, %lo(&GOTPLT[0])($28) */
1069 0x339c, 0x0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
1070 0x0398, 0xc1d0, /* subu $24, $24, $28 */
1071 0x001f, 0x7950, /* move $15, $31 */
1072 0x0318, 0x1040, /* srl $24, $24, 2 */
1073 0x03f9, 0x0f3c, /* jalr $25 */
1074 0x3318, 0xfffe /* subu $24, $24, 2 */
1077 /* The format of subsequent standard PLT entries. */
1078 static const bfd_vma mips_exec_plt_entry
[] =
1080 0x3c0f0000, /* lui $15, %hi(.got.plt entry) */
1081 0x01f90000, /* l[wd] $25, %lo(.got.plt entry)($15) */
1082 0x25f80000, /* addiu $24, $15, %lo(.got.plt entry) */
1083 0x03200008 /* jr $25 */
1086 /* The format of subsequent MIPS16 o32 PLT entries. We use v0 ($2)
1087 and v1 ($3) as temporaries because t8 ($24) and t9 ($25) are not
1088 directly addressable. */
1089 static const bfd_vma mips16_o32_exec_plt_entry
[] =
1091 0xb203, /* lw $2, 12($pc) */
1092 0x9a60, /* lw $3, 0($2) */
1093 0x651a, /* move $24, $2 */
1095 0x653b, /* move $25, $3 */
1097 0x0000, 0x0000 /* .word (.got.plt entry) */
1100 /* The format of subsequent microMIPS o32 PLT entries. We use v0 ($2)
1101 as a temporary because t8 ($24) is not addressable with ADDIUPC. */
1102 static const bfd_vma micromips_o32_exec_plt_entry
[] =
1104 0x7900, 0x0000, /* addiupc $2, (.got.plt entry) - . */
1105 0xff22, 0x0000, /* lw $25, 0($2) */
1106 0x4599, /* jr $25 */
1107 0x0f02 /* move $24, $2 */
1110 /* The format of subsequent microMIPS o32 PLT entries in the insn32 mode. */
1111 static const bfd_vma micromips_insn32_o32_exec_plt_entry
[] =
1113 0x41af, 0x0000, /* lui $15, %hi(.got.plt entry) */
1114 0xff2f, 0x0000, /* lw $25, %lo(.got.plt entry)($15) */
1115 0x0019, 0x0f3c, /* jr $25 */
1116 0x330f, 0x0000 /* addiu $24, $15, %lo(.got.plt entry) */
1119 /* The format of the first PLT entry in a VxWorks executable. */
1120 static const bfd_vma mips_vxworks_exec_plt0_entry
[] =
1122 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
1123 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
1124 0x8f390008, /* lw t9, 8(t9) */
1125 0x00000000, /* nop */
1126 0x03200008, /* jr t9 */
1127 0x00000000 /* nop */
1130 /* The format of subsequent PLT entries. */
1131 static const bfd_vma mips_vxworks_exec_plt_entry
[] =
1133 0x10000000, /* b .PLT_resolver */
1134 0x24180000, /* li t8, <pltindex> */
1135 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
1136 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
1137 0x8f390000, /* lw t9, 0(t9) */
1138 0x00000000, /* nop */
1139 0x03200008, /* jr t9 */
1140 0x00000000 /* nop */
1143 /* The format of the first PLT entry in a VxWorks shared object. */
1144 static const bfd_vma mips_vxworks_shared_plt0_entry
[] =
1146 0x8f990008, /* lw t9, 8(gp) */
1147 0x00000000, /* nop */
1148 0x03200008, /* jr t9 */
1149 0x00000000, /* nop */
1150 0x00000000, /* nop */
1151 0x00000000 /* nop */
1154 /* The format of subsequent PLT entries. */
1155 static const bfd_vma mips_vxworks_shared_plt_entry
[] =
1157 0x10000000, /* b .PLT_resolver */
1158 0x24180000 /* li t8, <pltindex> */
1161 /* microMIPS 32-bit opcode helper installer. */
1164 bfd_put_micromips_32 (const bfd
*abfd
, bfd_vma opcode
, bfd_byte
*ptr
)
1166 bfd_put_16 (abfd
, (opcode
>> 16) & 0xffff, ptr
);
1167 bfd_put_16 (abfd
, opcode
& 0xffff, ptr
+ 2);
1170 /* microMIPS 32-bit opcode helper retriever. */
1173 bfd_get_micromips_32 (const bfd
*abfd
, const bfd_byte
*ptr
)
1175 return (bfd_get_16 (abfd
, ptr
) << 16) | bfd_get_16 (abfd
, ptr
+ 2);
1178 /* Look up an entry in a MIPS ELF linker hash table. */
1180 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
1181 ((struct mips_elf_link_hash_entry *) \
1182 elf_link_hash_lookup (&(table)->root, (string), (create), \
1185 /* Traverse a MIPS ELF linker hash table. */
1187 #define mips_elf_link_hash_traverse(table, func, info) \
1188 (elf_link_hash_traverse \
1190 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1193 /* Find the base offsets for thread-local storage in this object,
1194 for GD/LD and IE/LE respectively. */
1196 #define TP_OFFSET 0x7000
1197 #define DTP_OFFSET 0x8000
1200 dtprel_base (struct bfd_link_info
*info
)
1202 /* If tls_sec is NULL, we should have signalled an error already. */
1203 if (elf_hash_table (info
)->tls_sec
== NULL
)
1205 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
1209 tprel_base (struct bfd_link_info
*info
)
1211 /* If tls_sec is NULL, we should have signalled an error already. */
1212 if (elf_hash_table (info
)->tls_sec
== NULL
)
1214 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
1217 /* Create an entry in a MIPS ELF linker hash table. */
1219 static struct bfd_hash_entry
*
1220 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1221 struct bfd_hash_table
*table
, const char *string
)
1223 struct mips_elf_link_hash_entry
*ret
=
1224 (struct mips_elf_link_hash_entry
*) entry
;
1226 /* Allocate the structure if it has not already been allocated by a
1229 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
1231 return (struct bfd_hash_entry
*) ret
;
1233 /* Call the allocation method of the superclass. */
1234 ret
= ((struct mips_elf_link_hash_entry
*)
1235 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1239 /* Set local fields. */
1240 memset (&ret
->esym
, 0, sizeof (EXTR
));
1241 /* We use -2 as a marker to indicate that the information has
1242 not been set. -1 means there is no associated ifd. */
1245 ret
->possibly_dynamic_relocs
= 0;
1246 ret
->fn_stub
= NULL
;
1247 ret
->call_stub
= NULL
;
1248 ret
->call_fp_stub
= NULL
;
1249 ret
->global_got_area
= GGA_NONE
;
1250 ret
->got_only_for_calls
= TRUE
;
1251 ret
->readonly_reloc
= FALSE
;
1252 ret
->has_static_relocs
= FALSE
;
1253 ret
->no_fn_stub
= FALSE
;
1254 ret
->need_fn_stub
= FALSE
;
1255 ret
->has_nonpic_branches
= FALSE
;
1256 ret
->needs_lazy_stub
= FALSE
;
1257 ret
->use_plt_entry
= FALSE
;
1260 return (struct bfd_hash_entry
*) ret
;
1263 /* Allocate MIPS ELF private object data. */
1266 _bfd_mips_elf_mkobject (bfd
*abfd
)
1268 return bfd_elf_allocate_object (abfd
, sizeof (struct mips_elf_obj_tdata
),
1273 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1275 if (!sec
->used_by_bfd
)
1277 struct _mips_elf_section_data
*sdata
;
1278 bfd_size_type amt
= sizeof (*sdata
);
1280 sdata
= bfd_zalloc (abfd
, amt
);
1283 sec
->used_by_bfd
= sdata
;
1286 return _bfd_elf_new_section_hook (abfd
, sec
);
1289 /* Read ECOFF debugging information from a .mdebug section into a
1290 ecoff_debug_info structure. */
1293 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
1294 struct ecoff_debug_info
*debug
)
1297 const struct ecoff_debug_swap
*swap
;
1300 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1301 memset (debug
, 0, sizeof (*debug
));
1303 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
1304 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1307 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
1308 swap
->external_hdr_size
))
1311 symhdr
= &debug
->symbolic_header
;
1312 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1314 /* The symbolic header contains absolute file offsets and sizes to
1316 #define READ(ptr, offset, count, size, type) \
1317 if (symhdr->count == 0) \
1318 debug->ptr = NULL; \
1321 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
1322 debug->ptr = bfd_malloc (amt); \
1323 if (debug->ptr == NULL) \
1324 goto error_return; \
1325 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
1326 || bfd_bread (debug->ptr, amt, abfd) != amt) \
1327 goto error_return; \
1330 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1331 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
1332 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
1333 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
1334 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
1335 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1337 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1338 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1339 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
1340 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
1341 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
1349 if (ext_hdr
!= NULL
)
1351 if (debug
->line
!= NULL
)
1353 if (debug
->external_dnr
!= NULL
)
1354 free (debug
->external_dnr
);
1355 if (debug
->external_pdr
!= NULL
)
1356 free (debug
->external_pdr
);
1357 if (debug
->external_sym
!= NULL
)
1358 free (debug
->external_sym
);
1359 if (debug
->external_opt
!= NULL
)
1360 free (debug
->external_opt
);
1361 if (debug
->external_aux
!= NULL
)
1362 free (debug
->external_aux
);
1363 if (debug
->ss
!= NULL
)
1365 if (debug
->ssext
!= NULL
)
1366 free (debug
->ssext
);
1367 if (debug
->external_fdr
!= NULL
)
1368 free (debug
->external_fdr
);
1369 if (debug
->external_rfd
!= NULL
)
1370 free (debug
->external_rfd
);
1371 if (debug
->external_ext
!= NULL
)
1372 free (debug
->external_ext
);
1376 /* Swap RPDR (runtime procedure table entry) for output. */
1379 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
1381 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
1382 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
1383 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
1384 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
1385 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
1386 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
1388 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
1389 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1391 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1394 /* Create a runtime procedure table from the .mdebug section. */
1397 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1398 struct bfd_link_info
*info
, asection
*s
,
1399 struct ecoff_debug_info
*debug
)
1401 const struct ecoff_debug_swap
*swap
;
1402 HDRR
*hdr
= &debug
->symbolic_header
;
1404 struct rpdr_ext
*erp
;
1406 struct pdr_ext
*epdr
;
1407 struct sym_ext
*esym
;
1411 bfd_size_type count
;
1412 unsigned long sindex
;
1416 const char *no_name_func
= _("static procedure (no name)");
1424 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1426 sindex
= strlen (no_name_func
) + 1;
1427 count
= hdr
->ipdMax
;
1430 size
= swap
->external_pdr_size
;
1432 epdr
= bfd_malloc (size
* count
);
1436 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1439 size
= sizeof (RPDR
);
1440 rp
= rpdr
= bfd_malloc (size
* count
);
1444 size
= sizeof (char *);
1445 sv
= bfd_malloc (size
* count
);
1449 count
= hdr
->isymMax
;
1450 size
= swap
->external_sym_size
;
1451 esym
= bfd_malloc (size
* count
);
1455 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1458 count
= hdr
->issMax
;
1459 ss
= bfd_malloc (count
);
1462 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1465 count
= hdr
->ipdMax
;
1466 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1468 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1469 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1470 rp
->adr
= sym
.value
;
1471 rp
->regmask
= pdr
.regmask
;
1472 rp
->regoffset
= pdr
.regoffset
;
1473 rp
->fregmask
= pdr
.fregmask
;
1474 rp
->fregoffset
= pdr
.fregoffset
;
1475 rp
->frameoffset
= pdr
.frameoffset
;
1476 rp
->framereg
= pdr
.framereg
;
1477 rp
->pcreg
= pdr
.pcreg
;
1479 sv
[i
] = ss
+ sym
.iss
;
1480 sindex
+= strlen (sv
[i
]) + 1;
1484 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1485 size
= BFD_ALIGN (size
, 16);
1486 rtproc
= bfd_alloc (abfd
, size
);
1489 mips_elf_hash_table (info
)->procedure_count
= 0;
1493 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1496 memset (erp
, 0, sizeof (struct rpdr_ext
));
1498 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1499 strcpy (str
, no_name_func
);
1500 str
+= strlen (no_name_func
) + 1;
1501 for (i
= 0; i
< count
; i
++)
1503 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1504 strcpy (str
, sv
[i
]);
1505 str
+= strlen (sv
[i
]) + 1;
1507 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1509 /* Set the size and contents of .rtproc section. */
1511 s
->contents
= rtproc
;
1513 /* Skip this section later on (I don't think this currently
1514 matters, but someday it might). */
1515 s
->map_head
.link_order
= NULL
;
1544 /* We're going to create a stub for H. Create a symbol for the stub's
1545 value and size, to help make the disassembly easier to read. */
1548 mips_elf_create_stub_symbol (struct bfd_link_info
*info
,
1549 struct mips_elf_link_hash_entry
*h
,
1550 const char *prefix
, asection
*s
, bfd_vma value
,
1553 struct bfd_link_hash_entry
*bh
;
1554 struct elf_link_hash_entry
*elfh
;
1557 if (ELF_ST_IS_MICROMIPS (h
->root
.other
))
1560 /* Create a new symbol. */
1561 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1563 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1564 BSF_LOCAL
, s
, value
, NULL
,
1568 /* Make it a local function. */
1569 elfh
= (struct elf_link_hash_entry
*) bh
;
1570 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
1572 elfh
->forced_local
= 1;
1576 /* We're about to redefine H. Create a symbol to represent H's
1577 current value and size, to help make the disassembly easier
1581 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1582 struct mips_elf_link_hash_entry
*h
,
1585 struct bfd_link_hash_entry
*bh
;
1586 struct elf_link_hash_entry
*elfh
;
1591 /* Read the symbol's value. */
1592 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1593 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1594 s
= h
->root
.root
.u
.def
.section
;
1595 value
= h
->root
.root
.u
.def
.value
;
1597 /* Create a new symbol. */
1598 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1600 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1601 BSF_LOCAL
, s
, value
, NULL
,
1605 /* Make it local and copy the other attributes from H. */
1606 elfh
= (struct elf_link_hash_entry
*) bh
;
1607 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1608 elfh
->other
= h
->root
.other
;
1609 elfh
->size
= h
->root
.size
;
1610 elfh
->forced_local
= 1;
1614 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1615 function rather than to a hard-float stub. */
1618 section_allows_mips16_refs_p (asection
*section
)
1622 name
= bfd_get_section_name (section
->owner
, section
);
1623 return (FN_STUB_P (name
)
1624 || CALL_STUB_P (name
)
1625 || CALL_FP_STUB_P (name
)
1626 || strcmp (name
, ".pdr") == 0);
1629 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1630 stub section of some kind. Return the R_SYMNDX of the target
1631 function, or 0 if we can't decide which function that is. */
1633 static unsigned long
1634 mips16_stub_symndx (const struct elf_backend_data
*bed
,
1635 asection
*sec ATTRIBUTE_UNUSED
,
1636 const Elf_Internal_Rela
*relocs
,
1637 const Elf_Internal_Rela
*relend
)
1639 int int_rels_per_ext_rel
= bed
->s
->int_rels_per_ext_rel
;
1640 const Elf_Internal_Rela
*rel
;
1642 /* Trust the first R_MIPS_NONE relocation, if any, but not a subsequent
1643 one in a compound relocation. */
1644 for (rel
= relocs
; rel
< relend
; rel
+= int_rels_per_ext_rel
)
1645 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1646 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1648 /* Otherwise trust the first relocation, whatever its kind. This is
1649 the traditional behavior. */
1650 if (relocs
< relend
)
1651 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1656 /* Check the mips16 stubs for a particular symbol, and see if we can
1660 mips_elf_check_mips16_stubs (struct bfd_link_info
*info
,
1661 struct mips_elf_link_hash_entry
*h
)
1663 /* Dynamic symbols must use the standard call interface, in case other
1664 objects try to call them. */
1665 if (h
->fn_stub
!= NULL
1666 && h
->root
.dynindx
!= -1)
1668 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1669 h
->need_fn_stub
= TRUE
;
1672 if (h
->fn_stub
!= NULL
1673 && ! h
->need_fn_stub
)
1675 /* We don't need the fn_stub; the only references to this symbol
1676 are 16 bit calls. Clobber the size to 0 to prevent it from
1677 being included in the link. */
1678 h
->fn_stub
->size
= 0;
1679 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1680 h
->fn_stub
->reloc_count
= 0;
1681 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1684 if (h
->call_stub
!= NULL
1685 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1687 /* We don't need the call_stub; this is a 16 bit function, so
1688 calls from other 16 bit functions are OK. Clobber the size
1689 to 0 to prevent it from being included in the link. */
1690 h
->call_stub
->size
= 0;
1691 h
->call_stub
->flags
&= ~SEC_RELOC
;
1692 h
->call_stub
->reloc_count
= 0;
1693 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1696 if (h
->call_fp_stub
!= NULL
1697 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1699 /* We don't need the call_stub; this is a 16 bit function, so
1700 calls from other 16 bit functions are OK. Clobber the size
1701 to 0 to prevent it from being included in the link. */
1702 h
->call_fp_stub
->size
= 0;
1703 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1704 h
->call_fp_stub
->reloc_count
= 0;
1705 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1709 /* Hashtable callbacks for mips_elf_la25_stubs. */
1712 mips_elf_la25_stub_hash (const void *entry_
)
1714 const struct mips_elf_la25_stub
*entry
;
1716 entry
= (struct mips_elf_la25_stub
*) entry_
;
1717 return entry
->h
->root
.root
.u
.def
.section
->id
1718 + entry
->h
->root
.root
.u
.def
.value
;
1722 mips_elf_la25_stub_eq (const void *entry1_
, const void *entry2_
)
1724 const struct mips_elf_la25_stub
*entry1
, *entry2
;
1726 entry1
= (struct mips_elf_la25_stub
*) entry1_
;
1727 entry2
= (struct mips_elf_la25_stub
*) entry2_
;
1728 return ((entry1
->h
->root
.root
.u
.def
.section
1729 == entry2
->h
->root
.root
.u
.def
.section
)
1730 && (entry1
->h
->root
.root
.u
.def
.value
1731 == entry2
->h
->root
.root
.u
.def
.value
));
1734 /* Called by the linker to set up the la25 stub-creation code. FN is
1735 the linker's implementation of add_stub_function. Return true on
1739 _bfd_mips_elf_init_stubs (struct bfd_link_info
*info
,
1740 asection
*(*fn
) (const char *, asection
*,
1743 struct mips_elf_link_hash_table
*htab
;
1745 htab
= mips_elf_hash_table (info
);
1749 htab
->add_stub_section
= fn
;
1750 htab
->la25_stubs
= htab_try_create (1, mips_elf_la25_stub_hash
,
1751 mips_elf_la25_stub_eq
, NULL
);
1752 if (htab
->la25_stubs
== NULL
)
1758 /* Return true if H is a locally-defined PIC function, in the sense
1759 that it or its fn_stub might need $25 to be valid on entry.
1760 Note that MIPS16 functions set up $gp using PC-relative instructions,
1761 so they themselves never need $25 to be valid. Only non-MIPS16
1762 entry points are of interest here. */
1765 mips_elf_local_pic_function_p (struct mips_elf_link_hash_entry
*h
)
1767 return ((h
->root
.root
.type
== bfd_link_hash_defined
1768 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1769 && h
->root
.def_regular
1770 && !bfd_is_abs_section (h
->root
.root
.u
.def
.section
)
1771 && (!ELF_ST_IS_MIPS16 (h
->root
.other
)
1772 || (h
->fn_stub
&& h
->need_fn_stub
))
1773 && (PIC_OBJECT_P (h
->root
.root
.u
.def
.section
->owner
)
1774 || ELF_ST_IS_MIPS_PIC (h
->root
.other
)));
1777 /* Set *SEC to the input section that contains the target of STUB.
1778 Return the offset of the target from the start of that section. */
1781 mips_elf_get_la25_target (struct mips_elf_la25_stub
*stub
,
1784 if (ELF_ST_IS_MIPS16 (stub
->h
->root
.other
))
1786 BFD_ASSERT (stub
->h
->need_fn_stub
);
1787 *sec
= stub
->h
->fn_stub
;
1792 *sec
= stub
->h
->root
.root
.u
.def
.section
;
1793 return stub
->h
->root
.root
.u
.def
.value
;
1797 /* STUB describes an la25 stub that we have decided to implement
1798 by inserting an LUI/ADDIU pair before the target function.
1799 Create the section and redirect the function symbol to it. */
1802 mips_elf_add_la25_intro (struct mips_elf_la25_stub
*stub
,
1803 struct bfd_link_info
*info
)
1805 struct mips_elf_link_hash_table
*htab
;
1807 asection
*s
, *input_section
;
1810 htab
= mips_elf_hash_table (info
);
1814 /* Create a unique name for the new section. */
1815 name
= bfd_malloc (11 + sizeof (".text.stub."));
1818 sprintf (name
, ".text.stub.%d", (int) htab_elements (htab
->la25_stubs
));
1820 /* Create the section. */
1821 mips_elf_get_la25_target (stub
, &input_section
);
1822 s
= htab
->add_stub_section (name
, input_section
,
1823 input_section
->output_section
);
1827 /* Make sure that any padding goes before the stub. */
1828 align
= input_section
->alignment_power
;
1829 if (!bfd_set_section_alignment (s
->owner
, s
, align
))
1832 s
->size
= (1 << align
) - 8;
1834 /* Create a symbol for the stub. */
1835 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 8);
1836 stub
->stub_section
= s
;
1837 stub
->offset
= s
->size
;
1839 /* Allocate room for it. */
1844 /* STUB describes an la25 stub that we have decided to implement
1845 with a separate trampoline. Allocate room for it and redirect
1846 the function symbol to it. */
1849 mips_elf_add_la25_trampoline (struct mips_elf_la25_stub
*stub
,
1850 struct bfd_link_info
*info
)
1852 struct mips_elf_link_hash_table
*htab
;
1855 htab
= mips_elf_hash_table (info
);
1859 /* Create a trampoline section, if we haven't already. */
1860 s
= htab
->strampoline
;
1863 asection
*input_section
= stub
->h
->root
.root
.u
.def
.section
;
1864 s
= htab
->add_stub_section (".text", NULL
,
1865 input_section
->output_section
);
1866 if (s
== NULL
|| !bfd_set_section_alignment (s
->owner
, s
, 4))
1868 htab
->strampoline
= s
;
1871 /* Create a symbol for the stub. */
1872 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 16);
1873 stub
->stub_section
= s
;
1874 stub
->offset
= s
->size
;
1876 /* Allocate room for it. */
1881 /* H describes a symbol that needs an la25 stub. Make sure that an
1882 appropriate stub exists and point H at it. */
1885 mips_elf_add_la25_stub (struct bfd_link_info
*info
,
1886 struct mips_elf_link_hash_entry
*h
)
1888 struct mips_elf_link_hash_table
*htab
;
1889 struct mips_elf_la25_stub search
, *stub
;
1890 bfd_boolean use_trampoline_p
;
1895 /* Describe the stub we want. */
1896 search
.stub_section
= NULL
;
1900 /* See if we've already created an equivalent stub. */
1901 htab
= mips_elf_hash_table (info
);
1905 slot
= htab_find_slot (htab
->la25_stubs
, &search
, INSERT
);
1909 stub
= (struct mips_elf_la25_stub
*) *slot
;
1912 /* We can reuse the existing stub. */
1913 h
->la25_stub
= stub
;
1917 /* Create a permanent copy of ENTRY and add it to the hash table. */
1918 stub
= bfd_malloc (sizeof (search
));
1924 /* Prefer to use LUI/ADDIU stubs if the function is at the beginning
1925 of the section and if we would need no more than 2 nops. */
1926 value
= mips_elf_get_la25_target (stub
, &s
);
1927 use_trampoline_p
= (value
!= 0 || s
->alignment_power
> 4);
1929 h
->la25_stub
= stub
;
1930 return (use_trampoline_p
1931 ? mips_elf_add_la25_trampoline (stub
, info
)
1932 : mips_elf_add_la25_intro (stub
, info
));
1935 /* A mips_elf_link_hash_traverse callback that is called before sizing
1936 sections. DATA points to a mips_htab_traverse_info structure. */
1939 mips_elf_check_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
1941 struct mips_htab_traverse_info
*hti
;
1943 hti
= (struct mips_htab_traverse_info
*) data
;
1944 if (!hti
->info
->relocatable
)
1945 mips_elf_check_mips16_stubs (hti
->info
, h
);
1947 if (mips_elf_local_pic_function_p (h
))
1949 /* PR 12845: If H is in a section that has been garbage
1950 collected it will have its output section set to *ABS*. */
1951 if (bfd_is_abs_section (h
->root
.root
.u
.def
.section
->output_section
))
1954 /* H is a function that might need $25 to be valid on entry.
1955 If we're creating a non-PIC relocatable object, mark H as
1956 being PIC. If we're creating a non-relocatable object with
1957 non-PIC branches and jumps to H, make sure that H has an la25
1959 if (hti
->info
->relocatable
)
1961 if (!PIC_OBJECT_P (hti
->output_bfd
))
1962 h
->root
.other
= ELF_ST_SET_MIPS_PIC (h
->root
.other
);
1964 else if (h
->has_nonpic_branches
&& !mips_elf_add_la25_stub (hti
->info
, h
))
1973 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1974 Most mips16 instructions are 16 bits, but these instructions
1977 The format of these instructions is:
1979 +--------------+--------------------------------+
1980 | JALX | X| Imm 20:16 | Imm 25:21 |
1981 +--------------+--------------------------------+
1983 +-----------------------------------------------+
1985 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1986 Note that the immediate value in the first word is swapped.
1988 When producing a relocatable object file, R_MIPS16_26 is
1989 handled mostly like R_MIPS_26. In particular, the addend is
1990 stored as a straight 26-bit value in a 32-bit instruction.
1991 (gas makes life simpler for itself by never adjusting a
1992 R_MIPS16_26 reloc to be against a section, so the addend is
1993 always zero). However, the 32 bit instruction is stored as 2
1994 16-bit values, rather than a single 32-bit value. In a
1995 big-endian file, the result is the same; in a little-endian
1996 file, the two 16-bit halves of the 32 bit value are swapped.
1997 This is so that a disassembler can recognize the jal
2000 When doing a final link, R_MIPS16_26 is treated as a 32 bit
2001 instruction stored as two 16-bit values. The addend A is the
2002 contents of the targ26 field. The calculation is the same as
2003 R_MIPS_26. When storing the calculated value, reorder the
2004 immediate value as shown above, and don't forget to store the
2005 value as two 16-bit values.
2007 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
2011 +--------+----------------------+
2015 +--------+----------------------+
2018 +----------+------+-------------+
2022 +----------+--------------------+
2023 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
2024 ((sub1 << 16) | sub2)).
2026 When producing a relocatable object file, the calculation is
2027 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2028 When producing a fully linked file, the calculation is
2029 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2030 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
2032 The table below lists the other MIPS16 instruction relocations.
2033 Each one is calculated in the same way as the non-MIPS16 relocation
2034 given on the right, but using the extended MIPS16 layout of 16-bit
2037 R_MIPS16_GPREL R_MIPS_GPREL16
2038 R_MIPS16_GOT16 R_MIPS_GOT16
2039 R_MIPS16_CALL16 R_MIPS_CALL16
2040 R_MIPS16_HI16 R_MIPS_HI16
2041 R_MIPS16_LO16 R_MIPS_LO16
2043 A typical instruction will have a format like this:
2045 +--------------+--------------------------------+
2046 | EXTEND | Imm 10:5 | Imm 15:11 |
2047 +--------------+--------------------------------+
2048 | Major | rx | ry | Imm 4:0 |
2049 +--------------+--------------------------------+
2051 EXTEND is the five bit value 11110. Major is the instruction
2054 All we need to do here is shuffle the bits appropriately.
2055 As above, the two 16-bit halves must be swapped on a
2056 little-endian system. */
2058 static inline bfd_boolean
2059 mips16_reloc_p (int r_type
)
2064 case R_MIPS16_GPREL
:
2065 case R_MIPS16_GOT16
:
2066 case R_MIPS16_CALL16
:
2069 case R_MIPS16_TLS_GD
:
2070 case R_MIPS16_TLS_LDM
:
2071 case R_MIPS16_TLS_DTPREL_HI16
:
2072 case R_MIPS16_TLS_DTPREL_LO16
:
2073 case R_MIPS16_TLS_GOTTPREL
:
2074 case R_MIPS16_TLS_TPREL_HI16
:
2075 case R_MIPS16_TLS_TPREL_LO16
:
2083 /* Check if a microMIPS reloc. */
2085 static inline bfd_boolean
2086 micromips_reloc_p (unsigned int r_type
)
2088 return r_type
>= R_MICROMIPS_min
&& r_type
< R_MICROMIPS_max
;
2091 /* Similar to MIPS16, the two 16-bit halves in microMIPS must be swapped
2092 on a little-endian system. This does not apply to R_MICROMIPS_PC7_S1
2093 and R_MICROMIPS_PC10_S1 relocs that apply to 16-bit instructions. */
2095 static inline bfd_boolean
2096 micromips_reloc_shuffle_p (unsigned int r_type
)
2098 return (micromips_reloc_p (r_type
)
2099 && r_type
!= R_MICROMIPS_PC7_S1
2100 && r_type
!= R_MICROMIPS_PC10_S1
);
2103 static inline bfd_boolean
2104 got16_reloc_p (int r_type
)
2106 return (r_type
== R_MIPS_GOT16
2107 || r_type
== R_MIPS16_GOT16
2108 || r_type
== R_MICROMIPS_GOT16
);
2111 static inline bfd_boolean
2112 call16_reloc_p (int r_type
)
2114 return (r_type
== R_MIPS_CALL16
2115 || r_type
== R_MIPS16_CALL16
2116 || r_type
== R_MICROMIPS_CALL16
);
2119 static inline bfd_boolean
2120 got_disp_reloc_p (unsigned int r_type
)
2122 return r_type
== R_MIPS_GOT_DISP
|| r_type
== R_MICROMIPS_GOT_DISP
;
2125 static inline bfd_boolean
2126 got_page_reloc_p (unsigned int r_type
)
2128 return r_type
== R_MIPS_GOT_PAGE
|| r_type
== R_MICROMIPS_GOT_PAGE
;
2131 static inline bfd_boolean
2132 got_ofst_reloc_p (unsigned int r_type
)
2134 return r_type
== R_MIPS_GOT_OFST
|| r_type
== R_MICROMIPS_GOT_OFST
;
2137 static inline bfd_boolean
2138 got_hi16_reloc_p (unsigned int r_type
)
2140 return r_type
== R_MIPS_GOT_HI16
|| r_type
== R_MICROMIPS_GOT_HI16
;
2143 static inline bfd_boolean
2144 got_lo16_reloc_p (unsigned int r_type
)
2146 return r_type
== R_MIPS_GOT_LO16
|| r_type
== R_MICROMIPS_GOT_LO16
;
2149 static inline bfd_boolean
2150 call_hi16_reloc_p (unsigned int r_type
)
2152 return r_type
== R_MIPS_CALL_HI16
|| r_type
== R_MICROMIPS_CALL_HI16
;
2155 static inline bfd_boolean
2156 call_lo16_reloc_p (unsigned int r_type
)
2158 return r_type
== R_MIPS_CALL_LO16
|| r_type
== R_MICROMIPS_CALL_LO16
;
2161 static inline bfd_boolean
2162 hi16_reloc_p (int r_type
)
2164 return (r_type
== R_MIPS_HI16
2165 || r_type
== R_MIPS16_HI16
2166 || r_type
== R_MICROMIPS_HI16
);
2169 static inline bfd_boolean
2170 lo16_reloc_p (int r_type
)
2172 return (r_type
== R_MIPS_LO16
2173 || r_type
== R_MIPS16_LO16
2174 || r_type
== R_MICROMIPS_LO16
);
2177 static inline bfd_boolean
2178 mips16_call_reloc_p (int r_type
)
2180 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
2183 static inline bfd_boolean
2184 jal_reloc_p (int r_type
)
2186 return (r_type
== R_MIPS_26
2187 || r_type
== R_MIPS16_26
2188 || r_type
== R_MICROMIPS_26_S1
);
2191 static inline bfd_boolean
2192 micromips_branch_reloc_p (int r_type
)
2194 return (r_type
== R_MICROMIPS_26_S1
2195 || r_type
== R_MICROMIPS_PC16_S1
2196 || r_type
== R_MICROMIPS_PC10_S1
2197 || r_type
== R_MICROMIPS_PC7_S1
);
2200 static inline bfd_boolean
2201 tls_gd_reloc_p (unsigned int r_type
)
2203 return (r_type
== R_MIPS_TLS_GD
2204 || r_type
== R_MIPS16_TLS_GD
2205 || r_type
== R_MICROMIPS_TLS_GD
);
2208 static inline bfd_boolean
2209 tls_ldm_reloc_p (unsigned int r_type
)
2211 return (r_type
== R_MIPS_TLS_LDM
2212 || r_type
== R_MIPS16_TLS_LDM
2213 || r_type
== R_MICROMIPS_TLS_LDM
);
2216 static inline bfd_boolean
2217 tls_gottprel_reloc_p (unsigned int r_type
)
2219 return (r_type
== R_MIPS_TLS_GOTTPREL
2220 || r_type
== R_MIPS16_TLS_GOTTPREL
2221 || r_type
== R_MICROMIPS_TLS_GOTTPREL
);
2225 _bfd_mips_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
2226 bfd_boolean jal_shuffle
, bfd_byte
*data
)
2228 bfd_vma first
, second
, val
;
2230 if (!mips16_reloc_p (r_type
) && !micromips_reloc_shuffle_p (r_type
))
2233 /* Pick up the first and second halfwords of the instruction. */
2234 first
= bfd_get_16 (abfd
, data
);
2235 second
= bfd_get_16 (abfd
, data
+ 2);
2236 if (micromips_reloc_p (r_type
) || (r_type
== R_MIPS16_26
&& !jal_shuffle
))
2237 val
= first
<< 16 | second
;
2238 else if (r_type
!= R_MIPS16_26
)
2239 val
= (((first
& 0xf800) << 16) | ((second
& 0xffe0) << 11)
2240 | ((first
& 0x1f) << 11) | (first
& 0x7e0) | (second
& 0x1f));
2242 val
= (((first
& 0xfc00) << 16) | ((first
& 0x3e0) << 11)
2243 | ((first
& 0x1f) << 21) | second
);
2244 bfd_put_32 (abfd
, val
, data
);
2248 _bfd_mips_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
2249 bfd_boolean jal_shuffle
, bfd_byte
*data
)
2251 bfd_vma first
, second
, val
;
2253 if (!mips16_reloc_p (r_type
) && !micromips_reloc_shuffle_p (r_type
))
2256 val
= bfd_get_32 (abfd
, data
);
2257 if (micromips_reloc_p (r_type
) || (r_type
== R_MIPS16_26
&& !jal_shuffle
))
2259 second
= val
& 0xffff;
2262 else if (r_type
!= R_MIPS16_26
)
2264 second
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
2265 first
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
2269 second
= val
& 0xffff;
2270 first
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
2271 | ((val
>> 21) & 0x1f);
2273 bfd_put_16 (abfd
, second
, data
+ 2);
2274 bfd_put_16 (abfd
, first
, data
);
2277 bfd_reloc_status_type
2278 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
2279 arelent
*reloc_entry
, asection
*input_section
,
2280 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
2284 bfd_reloc_status_type status
;
2286 if (bfd_is_com_section (symbol
->section
))
2289 relocation
= symbol
->value
;
2291 relocation
+= symbol
->section
->output_section
->vma
;
2292 relocation
+= symbol
->section
->output_offset
;
2294 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2295 return bfd_reloc_outofrange
;
2297 /* Set val to the offset into the section or symbol. */
2298 val
= reloc_entry
->addend
;
2300 _bfd_mips_elf_sign_extend (val
, 16);
2302 /* Adjust val for the final section location and GP value. If we
2303 are producing relocatable output, we don't want to do this for
2304 an external symbol. */
2306 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2307 val
+= relocation
- gp
;
2309 if (reloc_entry
->howto
->partial_inplace
)
2311 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
2313 + reloc_entry
->address
);
2314 if (status
!= bfd_reloc_ok
)
2318 reloc_entry
->addend
= val
;
2321 reloc_entry
->address
+= input_section
->output_offset
;
2323 return bfd_reloc_ok
;
2326 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
2327 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
2328 that contains the relocation field and DATA points to the start of
2333 struct mips_hi16
*next
;
2335 asection
*input_section
;
2339 /* FIXME: This should not be a static variable. */
2341 static struct mips_hi16
*mips_hi16_list
;
2343 /* A howto special_function for REL *HI16 relocations. We can only
2344 calculate the correct value once we've seen the partnering
2345 *LO16 relocation, so just save the information for later.
2347 The ABI requires that the *LO16 immediately follow the *HI16.
2348 However, as a GNU extension, we permit an arbitrary number of
2349 *HI16s to be associated with a single *LO16. This significantly
2350 simplies the relocation handling in gcc. */
2352 bfd_reloc_status_type
2353 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2354 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
2355 asection
*input_section
, bfd
*output_bfd
,
2356 char **error_message ATTRIBUTE_UNUSED
)
2358 struct mips_hi16
*n
;
2360 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2361 return bfd_reloc_outofrange
;
2363 n
= bfd_malloc (sizeof *n
);
2365 return bfd_reloc_outofrange
;
2367 n
->next
= mips_hi16_list
;
2369 n
->input_section
= input_section
;
2370 n
->rel
= *reloc_entry
;
2373 if (output_bfd
!= NULL
)
2374 reloc_entry
->address
+= input_section
->output_offset
;
2376 return bfd_reloc_ok
;
2379 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
2380 like any other 16-bit relocation when applied to global symbols, but is
2381 treated in the same as R_MIPS_HI16 when applied to local symbols. */
2383 bfd_reloc_status_type
2384 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2385 void *data
, asection
*input_section
,
2386 bfd
*output_bfd
, char **error_message
)
2388 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
2389 || bfd_is_und_section (bfd_get_section (symbol
))
2390 || bfd_is_com_section (bfd_get_section (symbol
)))
2391 /* The relocation is against a global symbol. */
2392 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2393 input_section
, output_bfd
,
2396 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
2397 input_section
, output_bfd
, error_message
);
2400 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
2401 is a straightforward 16 bit inplace relocation, but we must deal with
2402 any partnering high-part relocations as well. */
2404 bfd_reloc_status_type
2405 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2406 void *data
, asection
*input_section
,
2407 bfd
*output_bfd
, char **error_message
)
2410 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2412 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2413 return bfd_reloc_outofrange
;
2415 _bfd_mips_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2417 vallo
= bfd_get_32 (abfd
, location
);
2418 _bfd_mips_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2421 while (mips_hi16_list
!= NULL
)
2423 bfd_reloc_status_type ret
;
2424 struct mips_hi16
*hi
;
2426 hi
= mips_hi16_list
;
2428 /* R_MIPS*_GOT16 relocations are something of a special case. We
2429 want to install the addend in the same way as for a R_MIPS*_HI16
2430 relocation (with a rightshift of 16). However, since GOT16
2431 relocations can also be used with global symbols, their howto
2432 has a rightshift of 0. */
2433 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
2434 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
2435 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
2436 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
2437 else if (hi
->rel
.howto
->type
== R_MICROMIPS_GOT16
)
2438 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MICROMIPS_HI16
, FALSE
);
2440 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
2441 carry or borrow will induce a change of +1 or -1 in the high part. */
2442 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
2444 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
2445 hi
->input_section
, output_bfd
,
2447 if (ret
!= bfd_reloc_ok
)
2450 mips_hi16_list
= hi
->next
;
2454 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2455 input_section
, output_bfd
,
2459 /* A generic howto special_function. This calculates and installs the
2460 relocation itself, thus avoiding the oft-discussed problems in
2461 bfd_perform_relocation and bfd_install_relocation. */
2463 bfd_reloc_status_type
2464 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2465 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
2466 asection
*input_section
, bfd
*output_bfd
,
2467 char **error_message ATTRIBUTE_UNUSED
)
2470 bfd_reloc_status_type status
;
2471 bfd_boolean relocatable
;
2473 relocatable
= (output_bfd
!= NULL
);
2475 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2476 return bfd_reloc_outofrange
;
2478 /* Build up the field adjustment in VAL. */
2480 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2482 /* Either we're calculating the final field value or we have a
2483 relocation against a section symbol. Add in the section's
2484 offset or address. */
2485 val
+= symbol
->section
->output_section
->vma
;
2486 val
+= symbol
->section
->output_offset
;
2491 /* We're calculating the final field value. Add in the symbol's value
2492 and, if pc-relative, subtract the address of the field itself. */
2493 val
+= symbol
->value
;
2494 if (reloc_entry
->howto
->pc_relative
)
2496 val
-= input_section
->output_section
->vma
;
2497 val
-= input_section
->output_offset
;
2498 val
-= reloc_entry
->address
;
2502 /* VAL is now the final adjustment. If we're keeping this relocation
2503 in the output file, and if the relocation uses a separate addend,
2504 we just need to add VAL to that addend. Otherwise we need to add
2505 VAL to the relocation field itself. */
2506 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
2507 reloc_entry
->addend
+= val
;
2510 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2512 /* Add in the separate addend, if any. */
2513 val
+= reloc_entry
->addend
;
2515 /* Add VAL to the relocation field. */
2516 _bfd_mips_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2518 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
2520 _bfd_mips_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2523 if (status
!= bfd_reloc_ok
)
2528 reloc_entry
->address
+= input_section
->output_offset
;
2530 return bfd_reloc_ok
;
2533 /* Swap an entry in a .gptab section. Note that these routines rely
2534 on the equivalence of the two elements of the union. */
2537 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
2540 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2541 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2545 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
2546 Elf32_External_gptab
*ex
)
2548 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
2549 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
2553 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
2554 Elf32_External_compact_rel
*ex
)
2556 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
2557 H_PUT_32 (abfd
, in
->num
, ex
->num
);
2558 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
2559 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
2560 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
2561 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
2565 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
2566 Elf32_External_crinfo
*ex
)
2570 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2571 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2572 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2573 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2574 H_PUT_32 (abfd
, l
, ex
->info
);
2575 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
2576 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
2579 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2580 routines swap this structure in and out. They are used outside of
2581 BFD, so they are globally visible. */
2584 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
2587 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2588 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2589 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2590 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2591 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2592 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
2596 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
2597 Elf32_External_RegInfo
*ex
)
2599 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2600 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2601 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2602 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2603 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2604 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2607 /* In the 64 bit ABI, the .MIPS.options section holds register
2608 information in an Elf64_Reginfo structure. These routines swap
2609 them in and out. They are globally visible because they are used
2610 outside of BFD. These routines are here so that gas can call them
2611 without worrying about whether the 64 bit ABI has been included. */
2614 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
2615 Elf64_Internal_RegInfo
*in
)
2617 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2618 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
2619 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2620 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2621 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2622 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2623 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
2627 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
2628 Elf64_External_RegInfo
*ex
)
2630 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2631 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
2632 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2633 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2634 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2635 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2636 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2639 /* Swap in an options header. */
2642 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
2643 Elf_Internal_Options
*in
)
2645 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
2646 in
->size
= H_GET_8 (abfd
, ex
->size
);
2647 in
->section
= H_GET_16 (abfd
, ex
->section
);
2648 in
->info
= H_GET_32 (abfd
, ex
->info
);
2651 /* Swap out an options header. */
2654 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
2655 Elf_External_Options
*ex
)
2657 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
2658 H_PUT_8 (abfd
, in
->size
, ex
->size
);
2659 H_PUT_16 (abfd
, in
->section
, ex
->section
);
2660 H_PUT_32 (abfd
, in
->info
, ex
->info
);
2663 /* This function is called via qsort() to sort the dynamic relocation
2664 entries by increasing r_symndx value. */
2667 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
2669 Elf_Internal_Rela int_reloc1
;
2670 Elf_Internal_Rela int_reloc2
;
2673 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
2674 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
2676 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
2680 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
2682 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
2687 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
2690 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
2691 const void *arg2 ATTRIBUTE_UNUSED
)
2694 Elf_Internal_Rela int_reloc1
[3];
2695 Elf_Internal_Rela int_reloc2
[3];
2697 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2698 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
2699 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2700 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
2702 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
2704 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
2707 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
2709 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
2718 /* This routine is used to write out ECOFF debugging external symbol
2719 information. It is called via mips_elf_link_hash_traverse. The
2720 ECOFF external symbol information must match the ELF external
2721 symbol information. Unfortunately, at this point we don't know
2722 whether a symbol is required by reloc information, so the two
2723 tables may wind up being different. We must sort out the external
2724 symbol information before we can set the final size of the .mdebug
2725 section, and we must set the size of the .mdebug section before we
2726 can relocate any sections, and we can't know which symbols are
2727 required by relocation until we relocate the sections.
2728 Fortunately, it is relatively unlikely that any symbol will be
2729 stripped but required by a reloc. In particular, it can not happen
2730 when generating a final executable. */
2733 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
2735 struct extsym_info
*einfo
= data
;
2737 asection
*sec
, *output_section
;
2739 if (h
->root
.indx
== -2)
2741 else if ((h
->root
.def_dynamic
2742 || h
->root
.ref_dynamic
2743 || h
->root
.type
== bfd_link_hash_new
)
2744 && !h
->root
.def_regular
2745 && !h
->root
.ref_regular
)
2747 else if (einfo
->info
->strip
== strip_all
2748 || (einfo
->info
->strip
== strip_some
2749 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2750 h
->root
.root
.root
.string
,
2751 FALSE
, FALSE
) == NULL
))
2759 if (h
->esym
.ifd
== -2)
2762 h
->esym
.cobol_main
= 0;
2763 h
->esym
.weakext
= 0;
2764 h
->esym
.reserved
= 0;
2765 h
->esym
.ifd
= ifdNil
;
2766 h
->esym
.asym
.value
= 0;
2767 h
->esym
.asym
.st
= stGlobal
;
2769 if (h
->root
.root
.type
== bfd_link_hash_undefined
2770 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
2774 /* Use undefined class. Also, set class and type for some
2776 name
= h
->root
.root
.root
.string
;
2777 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2778 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2780 h
->esym
.asym
.sc
= scData
;
2781 h
->esym
.asym
.st
= stLabel
;
2782 h
->esym
.asym
.value
= 0;
2784 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2786 h
->esym
.asym
.sc
= scAbs
;
2787 h
->esym
.asym
.st
= stLabel
;
2788 h
->esym
.asym
.value
=
2789 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2791 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
2793 h
->esym
.asym
.sc
= scAbs
;
2794 h
->esym
.asym
.st
= stLabel
;
2795 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2798 h
->esym
.asym
.sc
= scUndefined
;
2800 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2801 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2802 h
->esym
.asym
.sc
= scAbs
;
2807 sec
= h
->root
.root
.u
.def
.section
;
2808 output_section
= sec
->output_section
;
2810 /* When making a shared library and symbol h is the one from
2811 the another shared library, OUTPUT_SECTION may be null. */
2812 if (output_section
== NULL
)
2813 h
->esym
.asym
.sc
= scUndefined
;
2816 name
= bfd_section_name (output_section
->owner
, output_section
);
2818 if (strcmp (name
, ".text") == 0)
2819 h
->esym
.asym
.sc
= scText
;
2820 else if (strcmp (name
, ".data") == 0)
2821 h
->esym
.asym
.sc
= scData
;
2822 else if (strcmp (name
, ".sdata") == 0)
2823 h
->esym
.asym
.sc
= scSData
;
2824 else if (strcmp (name
, ".rodata") == 0
2825 || strcmp (name
, ".rdata") == 0)
2826 h
->esym
.asym
.sc
= scRData
;
2827 else if (strcmp (name
, ".bss") == 0)
2828 h
->esym
.asym
.sc
= scBss
;
2829 else if (strcmp (name
, ".sbss") == 0)
2830 h
->esym
.asym
.sc
= scSBss
;
2831 else if (strcmp (name
, ".init") == 0)
2832 h
->esym
.asym
.sc
= scInit
;
2833 else if (strcmp (name
, ".fini") == 0)
2834 h
->esym
.asym
.sc
= scFini
;
2836 h
->esym
.asym
.sc
= scAbs
;
2840 h
->esym
.asym
.reserved
= 0;
2841 h
->esym
.asym
.index
= indexNil
;
2844 if (h
->root
.root
.type
== bfd_link_hash_common
)
2845 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2846 else if (h
->root
.root
.type
== bfd_link_hash_defined
2847 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2849 if (h
->esym
.asym
.sc
== scCommon
)
2850 h
->esym
.asym
.sc
= scBss
;
2851 else if (h
->esym
.asym
.sc
== scSCommon
)
2852 h
->esym
.asym
.sc
= scSBss
;
2854 sec
= h
->root
.root
.u
.def
.section
;
2855 output_section
= sec
->output_section
;
2856 if (output_section
!= NULL
)
2857 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2858 + sec
->output_offset
2859 + output_section
->vma
);
2861 h
->esym
.asym
.value
= 0;
2865 struct mips_elf_link_hash_entry
*hd
= h
;
2867 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
2868 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2870 if (hd
->needs_lazy_stub
)
2872 BFD_ASSERT (hd
->root
.plt
.plist
!= NULL
);
2873 BFD_ASSERT (hd
->root
.plt
.plist
->stub_offset
!= MINUS_ONE
);
2874 /* Set type and value for a symbol with a function stub. */
2875 h
->esym
.asym
.st
= stProc
;
2876 sec
= hd
->root
.root
.u
.def
.section
;
2878 h
->esym
.asym
.value
= 0;
2881 output_section
= sec
->output_section
;
2882 if (output_section
!= NULL
)
2883 h
->esym
.asym
.value
= (hd
->root
.plt
.plist
->stub_offset
2884 + sec
->output_offset
2885 + output_section
->vma
);
2887 h
->esym
.asym
.value
= 0;
2892 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2893 h
->root
.root
.root
.string
,
2896 einfo
->failed
= TRUE
;
2903 /* A comparison routine used to sort .gptab entries. */
2906 gptab_compare (const void *p1
, const void *p2
)
2908 const Elf32_gptab
*a1
= p1
;
2909 const Elf32_gptab
*a2
= p2
;
2911 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
2914 /* Functions to manage the got entry hash table. */
2916 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
2919 static INLINE hashval_t
2920 mips_elf_hash_bfd_vma (bfd_vma addr
)
2923 return addr
+ (addr
>> 32);
2930 mips_elf_got_entry_hash (const void *entry_
)
2932 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2934 return (entry
->symndx
2935 + ((entry
->tls_type
== GOT_TLS_LDM
) << 18)
2936 + (entry
->tls_type
== GOT_TLS_LDM
? 0
2937 : !entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
2938 : entry
->symndx
>= 0 ? (entry
->abfd
->id
2939 + mips_elf_hash_bfd_vma (entry
->d
.addend
))
2940 : entry
->d
.h
->root
.root
.root
.hash
));
2944 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
2946 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2947 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2949 return (e1
->symndx
== e2
->symndx
2950 && e1
->tls_type
== e2
->tls_type
2951 && (e1
->tls_type
== GOT_TLS_LDM
? TRUE
2952 : !e1
->abfd
? !e2
->abfd
&& e1
->d
.address
== e2
->d
.address
2953 : e1
->symndx
>= 0 ? (e1
->abfd
== e2
->abfd
2954 && e1
->d
.addend
== e2
->d
.addend
)
2955 : e2
->abfd
&& e1
->d
.h
== e2
->d
.h
));
2959 mips_got_page_ref_hash (const void *ref_
)
2961 const struct mips_got_page_ref
*ref
;
2963 ref
= (const struct mips_got_page_ref
*) ref_
;
2964 return ((ref
->symndx
>= 0
2965 ? (hashval_t
) (ref
->u
.abfd
->id
+ ref
->symndx
)
2966 : ref
->u
.h
->root
.root
.root
.hash
)
2967 + mips_elf_hash_bfd_vma (ref
->addend
));
2971 mips_got_page_ref_eq (const void *ref1_
, const void *ref2_
)
2973 const struct mips_got_page_ref
*ref1
, *ref2
;
2975 ref1
= (const struct mips_got_page_ref
*) ref1_
;
2976 ref2
= (const struct mips_got_page_ref
*) ref2_
;
2977 return (ref1
->symndx
== ref2
->symndx
2978 && (ref1
->symndx
< 0
2979 ? ref1
->u
.h
== ref2
->u
.h
2980 : ref1
->u
.abfd
== ref2
->u
.abfd
)
2981 && ref1
->addend
== ref2
->addend
);
2985 mips_got_page_entry_hash (const void *entry_
)
2987 const struct mips_got_page_entry
*entry
;
2989 entry
= (const struct mips_got_page_entry
*) entry_
;
2990 return entry
->sec
->id
;
2994 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
2996 const struct mips_got_page_entry
*entry1
, *entry2
;
2998 entry1
= (const struct mips_got_page_entry
*) entry1_
;
2999 entry2
= (const struct mips_got_page_entry
*) entry2_
;
3000 return entry1
->sec
== entry2
->sec
;
3003 /* Create and return a new mips_got_info structure. */
3005 static struct mips_got_info
*
3006 mips_elf_create_got_info (bfd
*abfd
)
3008 struct mips_got_info
*g
;
3010 g
= bfd_zalloc (abfd
, sizeof (struct mips_got_info
));
3014 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
3015 mips_elf_got_entry_eq
, NULL
);
3016 if (g
->got_entries
== NULL
)
3019 g
->got_page_refs
= htab_try_create (1, mips_got_page_ref_hash
,
3020 mips_got_page_ref_eq
, NULL
);
3021 if (g
->got_page_refs
== NULL
)
3027 /* Return the GOT info for input bfd ABFD, trying to create a new one if
3028 CREATE_P and if ABFD doesn't already have a GOT. */
3030 static struct mips_got_info
*
3031 mips_elf_bfd_got (bfd
*abfd
, bfd_boolean create_p
)
3033 struct mips_elf_obj_tdata
*tdata
;
3035 if (!is_mips_elf (abfd
))
3038 tdata
= mips_elf_tdata (abfd
);
3039 if (!tdata
->got
&& create_p
)
3040 tdata
->got
= mips_elf_create_got_info (abfd
);
3044 /* Record that ABFD should use output GOT G. */
3047 mips_elf_replace_bfd_got (bfd
*abfd
, struct mips_got_info
*g
)
3049 struct mips_elf_obj_tdata
*tdata
;
3051 BFD_ASSERT (is_mips_elf (abfd
));
3052 tdata
= mips_elf_tdata (abfd
);
3055 /* The GOT structure itself and the hash table entries are
3056 allocated to a bfd, but the hash tables aren't. */
3057 htab_delete (tdata
->got
->got_entries
);
3058 htab_delete (tdata
->got
->got_page_refs
);
3059 if (tdata
->got
->got_page_entries
)
3060 htab_delete (tdata
->got
->got_page_entries
);
3065 /* Return the dynamic relocation section. If it doesn't exist, try to
3066 create a new it if CREATE_P, otherwise return NULL. Also return NULL
3067 if creation fails. */
3070 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
3076 dname
= MIPS_ELF_REL_DYN_NAME (info
);
3077 dynobj
= elf_hash_table (info
)->dynobj
;
3078 sreloc
= bfd_get_linker_section (dynobj
, dname
);
3079 if (sreloc
== NULL
&& create_p
)
3081 sreloc
= bfd_make_section_anyway_with_flags (dynobj
, dname
,
3086 | SEC_LINKER_CREATED
3089 || ! bfd_set_section_alignment (dynobj
, sreloc
,
3090 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
3096 /* Return the GOT_TLS_* type required by relocation type R_TYPE. */
3099 mips_elf_reloc_tls_type (unsigned int r_type
)
3101 if (tls_gd_reloc_p (r_type
))
3104 if (tls_ldm_reloc_p (r_type
))
3107 if (tls_gottprel_reloc_p (r_type
))
3110 return GOT_TLS_NONE
;
3113 /* Return the number of GOT slots needed for GOT TLS type TYPE. */
3116 mips_tls_got_entries (unsigned int type
)
3133 /* Count the number of relocations needed for a TLS GOT entry, with
3134 access types from TLS_TYPE, and symbol H (or a local symbol if H
3138 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
3139 struct elf_link_hash_entry
*h
)
3142 bfd_boolean need_relocs
= FALSE
;
3143 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
3145 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3146 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
3149 if ((info
->shared
|| indx
!= 0)
3151 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3152 || h
->root
.type
!= bfd_link_hash_undefweak
))
3161 return indx
!= 0 ? 2 : 1;
3167 return info
->shared
? 1 : 0;
3174 /* Add the number of GOT entries and TLS relocations required by ENTRY
3178 mips_elf_count_got_entry (struct bfd_link_info
*info
,
3179 struct mips_got_info
*g
,
3180 struct mips_got_entry
*entry
)
3182 if (entry
->tls_type
)
3184 g
->tls_gotno
+= mips_tls_got_entries (entry
->tls_type
);
3185 g
->relocs
+= mips_tls_got_relocs (info
, entry
->tls_type
,
3187 ? &entry
->d
.h
->root
: NULL
);
3189 else if (entry
->symndx
>= 0 || entry
->d
.h
->global_got_area
== GGA_NONE
)
3190 g
->local_gotno
+= 1;
3192 g
->global_gotno
+= 1;
3195 /* Output a simple dynamic relocation into SRELOC. */
3198 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
3200 unsigned long reloc_index
,
3205 Elf_Internal_Rela rel
[3];
3207 memset (rel
, 0, sizeof (rel
));
3209 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
3210 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
3212 if (ABI_64_P (output_bfd
))
3214 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
3215 (output_bfd
, &rel
[0],
3217 + reloc_index
* sizeof (Elf64_Mips_External_Rel
)));
3220 bfd_elf32_swap_reloc_out
3221 (output_bfd
, &rel
[0],
3223 + reloc_index
* sizeof (Elf32_External_Rel
)));
3226 /* Initialize a set of TLS GOT entries for one symbol. */
3229 mips_elf_initialize_tls_slots (bfd
*abfd
, struct bfd_link_info
*info
,
3230 struct mips_got_entry
*entry
,
3231 struct mips_elf_link_hash_entry
*h
,
3234 struct mips_elf_link_hash_table
*htab
;
3236 asection
*sreloc
, *sgot
;
3237 bfd_vma got_offset
, got_offset2
;
3238 bfd_boolean need_relocs
= FALSE
;
3240 htab
= mips_elf_hash_table (info
);
3249 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
3251 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
3252 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
3253 indx
= h
->root
.dynindx
;
3256 if (entry
->tls_initialized
)
3259 if ((info
->shared
|| indx
!= 0)
3261 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
3262 || h
->root
.type
!= bfd_link_hash_undefweak
))
3265 /* MINUS_ONE means the symbol is not defined in this object. It may not
3266 be defined at all; assume that the value doesn't matter in that
3267 case. Otherwise complain if we would use the value. */
3268 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
3269 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
3271 /* Emit necessary relocations. */
3272 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
3273 got_offset
= entry
->gotidx
;
3275 switch (entry
->tls_type
)
3278 /* General Dynamic. */
3279 got_offset2
= got_offset
+ MIPS_ELF_GOT_SIZE (abfd
);
3283 mips_elf_output_dynamic_relocation
3284 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3285 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
3286 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
3289 mips_elf_output_dynamic_relocation
3290 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3291 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
3292 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset2
);
3294 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
3295 sgot
->contents
+ got_offset2
);
3299 MIPS_ELF_PUT_WORD (abfd
, 1,
3300 sgot
->contents
+ got_offset
);
3301 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
3302 sgot
->contents
+ got_offset2
);
3307 /* Initial Exec model. */
3311 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
3312 sgot
->contents
+ got_offset
);
3314 MIPS_ELF_PUT_WORD (abfd
, 0,
3315 sgot
->contents
+ got_offset
);
3317 mips_elf_output_dynamic_relocation
3318 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3319 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
3320 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
3323 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
3324 sgot
->contents
+ got_offset
);
3328 /* The initial offset is zero, and the LD offsets will include the
3329 bias by DTP_OFFSET. */
3330 MIPS_ELF_PUT_WORD (abfd
, 0,
3331 sgot
->contents
+ got_offset
3332 + MIPS_ELF_GOT_SIZE (abfd
));
3335 MIPS_ELF_PUT_WORD (abfd
, 1,
3336 sgot
->contents
+ got_offset
);
3338 mips_elf_output_dynamic_relocation
3339 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
3340 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
3341 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
3348 entry
->tls_initialized
= TRUE
;
3351 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
3352 for global symbol H. .got.plt comes before the GOT, so the offset
3353 will be negative. */
3356 mips_elf_gotplt_index (struct bfd_link_info
*info
,
3357 struct elf_link_hash_entry
*h
)
3359 bfd_vma got_address
, got_value
;
3360 struct mips_elf_link_hash_table
*htab
;
3362 htab
= mips_elf_hash_table (info
);
3363 BFD_ASSERT (htab
!= NULL
);
3365 BFD_ASSERT (h
->plt
.plist
!= NULL
);
3366 BFD_ASSERT (h
->plt
.plist
->gotplt_index
!= MINUS_ONE
);
3368 /* Calculate the address of the associated .got.plt entry. */
3369 got_address
= (htab
->sgotplt
->output_section
->vma
3370 + htab
->sgotplt
->output_offset
3371 + (h
->plt
.plist
->gotplt_index
3372 * MIPS_ELF_GOT_SIZE (info
->output_bfd
)));
3374 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
3375 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
3376 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
3377 + htab
->root
.hgot
->root
.u
.def
.value
);
3379 return got_address
- got_value
;
3382 /* Return the GOT offset for address VALUE. If there is not yet a GOT
3383 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
3384 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
3385 offset can be found. */
3388 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3389 bfd_vma value
, unsigned long r_symndx
,
3390 struct mips_elf_link_hash_entry
*h
, int r_type
)
3392 struct mips_elf_link_hash_table
*htab
;
3393 struct mips_got_entry
*entry
;
3395 htab
= mips_elf_hash_table (info
);
3396 BFD_ASSERT (htab
!= NULL
);
3398 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
3399 r_symndx
, h
, r_type
);
3403 if (entry
->tls_type
)
3404 mips_elf_initialize_tls_slots (abfd
, info
, entry
, h
, value
);
3405 return entry
->gotidx
;
3408 /* Return the GOT index of global symbol H in the primary GOT. */
3411 mips_elf_primary_global_got_index (bfd
*obfd
, struct bfd_link_info
*info
,
3412 struct elf_link_hash_entry
*h
)
3414 struct mips_elf_link_hash_table
*htab
;
3415 long global_got_dynindx
;
3416 struct mips_got_info
*g
;
3419 htab
= mips_elf_hash_table (info
);
3420 BFD_ASSERT (htab
!= NULL
);
3422 global_got_dynindx
= 0;
3423 if (htab
->global_gotsym
!= NULL
)
3424 global_got_dynindx
= htab
->global_gotsym
->dynindx
;
3426 /* Once we determine the global GOT entry with the lowest dynamic
3427 symbol table index, we must put all dynamic symbols with greater
3428 indices into the primary GOT. That makes it easy to calculate the
3430 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
3431 g
= mips_elf_bfd_got (obfd
, FALSE
);
3432 got_index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
3433 * MIPS_ELF_GOT_SIZE (obfd
));
3434 BFD_ASSERT (got_index
< htab
->sgot
->size
);
3439 /* Return the GOT index for the global symbol indicated by H, which is
3440 referenced by a relocation of type R_TYPE in IBFD. */
3443 mips_elf_global_got_index (bfd
*obfd
, struct bfd_link_info
*info
, bfd
*ibfd
,
3444 struct elf_link_hash_entry
*h
, int r_type
)
3446 struct mips_elf_link_hash_table
*htab
;
3447 struct mips_got_info
*g
;
3448 struct mips_got_entry lookup
, *entry
;
3451 htab
= mips_elf_hash_table (info
);
3452 BFD_ASSERT (htab
!= NULL
);
3454 g
= mips_elf_bfd_got (ibfd
, FALSE
);
3457 lookup
.tls_type
= mips_elf_reloc_tls_type (r_type
);
3458 if (!lookup
.tls_type
&& g
== mips_elf_bfd_got (obfd
, FALSE
))
3459 return mips_elf_primary_global_got_index (obfd
, info
, h
);
3463 lookup
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3464 entry
= htab_find (g
->got_entries
, &lookup
);
3467 gotidx
= entry
->gotidx
;
3468 BFD_ASSERT (gotidx
> 0 && gotidx
< htab
->sgot
->size
);
3470 if (lookup
.tls_type
)
3472 bfd_vma value
= MINUS_ONE
;
3474 if ((h
->root
.type
== bfd_link_hash_defined
3475 || h
->root
.type
== bfd_link_hash_defweak
)
3476 && h
->root
.u
.def
.section
->output_section
)
3477 value
= (h
->root
.u
.def
.value
3478 + h
->root
.u
.def
.section
->output_offset
3479 + h
->root
.u
.def
.section
->output_section
->vma
);
3481 mips_elf_initialize_tls_slots (obfd
, info
, entry
, lookup
.d
.h
, value
);
3486 /* Find a GOT page entry that points to within 32KB of VALUE. These
3487 entries are supposed to be placed at small offsets in the GOT, i.e.,
3488 within 32KB of GP. Return the index of the GOT entry, or -1 if no
3489 entry could be created. If OFFSETP is nonnull, use it to return the
3490 offset of the GOT entry from VALUE. */
3493 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3494 bfd_vma value
, bfd_vma
*offsetp
)
3496 bfd_vma page
, got_index
;
3497 struct mips_got_entry
*entry
;
3499 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
3500 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
3501 NULL
, R_MIPS_GOT_PAGE
);
3506 got_index
= entry
->gotidx
;
3509 *offsetp
= value
- entry
->d
.address
;
3514 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
3515 EXTERNAL is true if the relocation was originally against a global
3516 symbol that binds locally. */
3519 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3520 bfd_vma value
, bfd_boolean external
)
3522 struct mips_got_entry
*entry
;
3524 /* GOT16 relocations against local symbols are followed by a LO16
3525 relocation; those against global symbols are not. Thus if the
3526 symbol was originally local, the GOT16 relocation should load the
3527 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
3529 value
= mips_elf_high (value
) << 16;
3531 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
3532 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
3533 same in all cases. */
3534 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
3535 NULL
, R_MIPS_GOT16
);
3537 return entry
->gotidx
;
3542 /* Returns the offset for the entry at the INDEXth position
3546 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
3547 bfd
*input_bfd
, bfd_vma got_index
)
3549 struct mips_elf_link_hash_table
*htab
;
3553 htab
= mips_elf_hash_table (info
);
3554 BFD_ASSERT (htab
!= NULL
);
3557 gp
= _bfd_get_gp_value (output_bfd
)
3558 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
3560 return sgot
->output_section
->vma
+ sgot
->output_offset
+ got_index
- gp
;
3563 /* Create and return a local GOT entry for VALUE, which was calculated
3564 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
3565 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
3568 static struct mips_got_entry
*
3569 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3570 bfd
*ibfd
, bfd_vma value
,
3571 unsigned long r_symndx
,
3572 struct mips_elf_link_hash_entry
*h
,
3575 struct mips_got_entry lookup
, *entry
;
3577 struct mips_got_info
*g
;
3578 struct mips_elf_link_hash_table
*htab
;
3581 htab
= mips_elf_hash_table (info
);
3582 BFD_ASSERT (htab
!= NULL
);
3584 g
= mips_elf_bfd_got (ibfd
, FALSE
);
3587 g
= mips_elf_bfd_got (abfd
, FALSE
);
3588 BFD_ASSERT (g
!= NULL
);
3591 /* This function shouldn't be called for symbols that live in the global
3593 BFD_ASSERT (h
== NULL
|| h
->global_got_area
== GGA_NONE
);
3595 lookup
.tls_type
= mips_elf_reloc_tls_type (r_type
);
3596 if (lookup
.tls_type
)
3599 if (tls_ldm_reloc_p (r_type
))
3602 lookup
.d
.addend
= 0;
3606 lookup
.symndx
= r_symndx
;
3607 lookup
.d
.addend
= 0;
3615 entry
= (struct mips_got_entry
*) htab_find (g
->got_entries
, &lookup
);
3618 gotidx
= entry
->gotidx
;
3619 BFD_ASSERT (gotidx
> 0 && gotidx
< htab
->sgot
->size
);
3626 lookup
.d
.address
= value
;
3627 loc
= htab_find_slot (g
->got_entries
, &lookup
, INSERT
);
3631 entry
= (struct mips_got_entry
*) *loc
;
3635 if (g
->assigned_gotno
>= g
->local_gotno
)
3637 /* We didn't allocate enough space in the GOT. */
3638 (*_bfd_error_handler
)
3639 (_("not enough GOT space for local GOT entries"));
3640 bfd_set_error (bfd_error_bad_value
);
3644 entry
= (struct mips_got_entry
*) bfd_alloc (abfd
, sizeof (*entry
));
3648 lookup
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
3652 MIPS_ELF_PUT_WORD (abfd
, value
, htab
->sgot
->contents
+ entry
->gotidx
);
3654 /* These GOT entries need a dynamic relocation on VxWorks. */
3655 if (htab
->is_vxworks
)
3657 Elf_Internal_Rela outrel
;
3660 bfd_vma got_address
;
3662 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3663 got_address
= (htab
->sgot
->output_section
->vma
3664 + htab
->sgot
->output_offset
3667 rloc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
3668 outrel
.r_offset
= got_address
;
3669 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
3670 outrel
.r_addend
= value
;
3671 bfd_elf32_swap_reloca_out (abfd
, &outrel
, rloc
);
3677 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
3678 The number might be exact or a worst-case estimate, depending on how
3679 much information is available to elf_backend_omit_section_dynsym at
3680 the current linking stage. */
3682 static bfd_size_type
3683 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
3685 bfd_size_type count
;
3688 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
3691 const struct elf_backend_data
*bed
;
3693 bed
= get_elf_backend_data (output_bfd
);
3694 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
3695 if ((p
->flags
& SEC_EXCLUDE
) == 0
3696 && (p
->flags
& SEC_ALLOC
) != 0
3697 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
3703 /* Sort the dynamic symbol table so that symbols that need GOT entries
3704 appear towards the end. */
3707 mips_elf_sort_hash_table (bfd
*abfd
, struct bfd_link_info
*info
)
3709 struct mips_elf_link_hash_table
*htab
;
3710 struct mips_elf_hash_sort_data hsd
;
3711 struct mips_got_info
*g
;
3713 if (elf_hash_table (info
)->dynsymcount
== 0)
3716 htab
= mips_elf_hash_table (info
);
3717 BFD_ASSERT (htab
!= NULL
);
3724 hsd
.max_unref_got_dynindx
3725 = hsd
.min_got_dynindx
3726 = (elf_hash_table (info
)->dynsymcount
- g
->reloc_only_gotno
);
3727 hsd
.max_non_got_dynindx
= count_section_dynsyms (abfd
, info
) + 1;
3728 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
3729 elf_hash_table (info
)),
3730 mips_elf_sort_hash_table_f
,
3733 /* There should have been enough room in the symbol table to
3734 accommodate both the GOT and non-GOT symbols. */
3735 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
3736 BFD_ASSERT ((unsigned long) hsd
.max_unref_got_dynindx
3737 == elf_hash_table (info
)->dynsymcount
);
3738 BFD_ASSERT (elf_hash_table (info
)->dynsymcount
- hsd
.min_got_dynindx
3739 == g
->global_gotno
);
3741 /* Now we know which dynamic symbol has the lowest dynamic symbol
3742 table index in the GOT. */
3743 htab
->global_gotsym
= hsd
.low
;
3748 /* If H needs a GOT entry, assign it the highest available dynamic
3749 index. Otherwise, assign it the lowest available dynamic
3753 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
3755 struct mips_elf_hash_sort_data
*hsd
= data
;
3757 /* Symbols without dynamic symbol table entries aren't interesting
3759 if (h
->root
.dynindx
== -1)
3762 switch (h
->global_got_area
)
3765 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
3769 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
3770 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3773 case GGA_RELOC_ONLY
:
3774 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
3775 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3776 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
3783 /* Record that input bfd ABFD requires a GOT entry like *LOOKUP
3784 (which is owned by the caller and shouldn't be added to the
3785 hash table directly). */
3788 mips_elf_record_got_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3789 struct mips_got_entry
*lookup
)
3791 struct mips_elf_link_hash_table
*htab
;
3792 struct mips_got_entry
*entry
;
3793 struct mips_got_info
*g
;
3794 void **loc
, **bfd_loc
;
3796 /* Make sure there's a slot for this entry in the master GOT. */
3797 htab
= mips_elf_hash_table (info
);
3799 loc
= htab_find_slot (g
->got_entries
, lookup
, INSERT
);
3803 /* Populate the entry if it isn't already. */
3804 entry
= (struct mips_got_entry
*) *loc
;
3807 entry
= (struct mips_got_entry
*) bfd_alloc (abfd
, sizeof (*entry
));
3811 lookup
->tls_initialized
= FALSE
;
3812 lookup
->gotidx
= -1;
3817 /* Reuse the same GOT entry for the BFD's GOT. */
3818 g
= mips_elf_bfd_got (abfd
, TRUE
);
3822 bfd_loc
= htab_find_slot (g
->got_entries
, lookup
, INSERT
);
3831 /* ABFD has a GOT relocation of type R_TYPE against H. Reserve a GOT
3832 entry for it. FOR_CALL is true if the caller is only interested in
3833 using the GOT entry for calls. */
3836 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
3837 bfd
*abfd
, struct bfd_link_info
*info
,
3838 bfd_boolean for_call
, int r_type
)
3840 struct mips_elf_link_hash_table
*htab
;
3841 struct mips_elf_link_hash_entry
*hmips
;
3842 struct mips_got_entry entry
;
3843 unsigned char tls_type
;
3845 htab
= mips_elf_hash_table (info
);
3846 BFD_ASSERT (htab
!= NULL
);
3848 hmips
= (struct mips_elf_link_hash_entry
*) h
;
3850 hmips
->got_only_for_calls
= FALSE
;
3852 /* A global symbol in the GOT must also be in the dynamic symbol
3854 if (h
->dynindx
== -1)
3856 switch (ELF_ST_VISIBILITY (h
->other
))
3860 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
3863 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3867 tls_type
= mips_elf_reloc_tls_type (r_type
);
3868 if (tls_type
== GOT_TLS_NONE
&& hmips
->global_got_area
> GGA_NORMAL
)
3869 hmips
->global_got_area
= GGA_NORMAL
;
3873 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3874 entry
.tls_type
= tls_type
;
3875 return mips_elf_record_got_entry (info
, abfd
, &entry
);
3878 /* ABFD has a GOT relocation of type R_TYPE against symbol SYMNDX + ADDEND,
3879 where SYMNDX is a local symbol. Reserve a GOT entry for it. */
3882 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
3883 struct bfd_link_info
*info
, int r_type
)
3885 struct mips_elf_link_hash_table
*htab
;
3886 struct mips_got_info
*g
;
3887 struct mips_got_entry entry
;
3889 htab
= mips_elf_hash_table (info
);
3890 BFD_ASSERT (htab
!= NULL
);
3893 BFD_ASSERT (g
!= NULL
);
3896 entry
.symndx
= symndx
;
3897 entry
.d
.addend
= addend
;
3898 entry
.tls_type
= mips_elf_reloc_tls_type (r_type
);
3899 return mips_elf_record_got_entry (info
, abfd
, &entry
);
3902 /* Record that ABFD has a page relocation against SYMNDX + ADDEND.
3903 H is the symbol's hash table entry, or null if SYMNDX is local
3907 mips_elf_record_got_page_ref (struct bfd_link_info
*info
, bfd
*abfd
,
3908 long symndx
, struct elf_link_hash_entry
*h
,
3909 bfd_signed_vma addend
)
3911 struct mips_elf_link_hash_table
*htab
;
3912 struct mips_got_info
*g1
, *g2
;
3913 struct mips_got_page_ref lookup
, *entry
;
3914 void **loc
, **bfd_loc
;
3916 htab
= mips_elf_hash_table (info
);
3917 BFD_ASSERT (htab
!= NULL
);
3919 g1
= htab
->got_info
;
3920 BFD_ASSERT (g1
!= NULL
);
3925 lookup
.u
.h
= (struct mips_elf_link_hash_entry
*) h
;
3929 lookup
.symndx
= symndx
;
3930 lookup
.u
.abfd
= abfd
;
3932 lookup
.addend
= addend
;
3933 loc
= htab_find_slot (g1
->got_page_refs
, &lookup
, INSERT
);
3937 entry
= (struct mips_got_page_ref
*) *loc
;
3940 entry
= bfd_alloc (abfd
, sizeof (*entry
));
3948 /* Add the same entry to the BFD's GOT. */
3949 g2
= mips_elf_bfd_got (abfd
, TRUE
);
3953 bfd_loc
= htab_find_slot (g2
->got_page_refs
, &lookup
, INSERT
);
3963 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
3966 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
3970 struct mips_elf_link_hash_table
*htab
;
3972 htab
= mips_elf_hash_table (info
);
3973 BFD_ASSERT (htab
!= NULL
);
3975 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3976 BFD_ASSERT (s
!= NULL
);
3978 if (htab
->is_vxworks
)
3979 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
3984 /* Make room for a null element. */
3985 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
3988 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
3992 /* A htab_traverse callback for GOT entries, with DATA pointing to a
3993 mips_elf_traverse_got_arg structure. Count the number of GOT
3994 entries and TLS relocs. Set DATA->value to true if we need
3995 to resolve indirect or warning symbols and then recreate the GOT. */
3998 mips_elf_check_recreate_got (void **entryp
, void *data
)
4000 struct mips_got_entry
*entry
;
4001 struct mips_elf_traverse_got_arg
*arg
;
4003 entry
= (struct mips_got_entry
*) *entryp
;
4004 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4005 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
4007 struct mips_elf_link_hash_entry
*h
;
4010 if (h
->root
.root
.type
== bfd_link_hash_indirect
4011 || h
->root
.root
.type
== bfd_link_hash_warning
)
4017 mips_elf_count_got_entry (arg
->info
, arg
->g
, entry
);
4021 /* A htab_traverse callback for GOT entries, with DATA pointing to a
4022 mips_elf_traverse_got_arg structure. Add all entries to DATA->g,
4023 converting entries for indirect and warning symbols into entries
4024 for the target symbol. Set DATA->g to null on error. */
4027 mips_elf_recreate_got (void **entryp
, void *data
)
4029 struct mips_got_entry new_entry
, *entry
;
4030 struct mips_elf_traverse_got_arg
*arg
;
4033 entry
= (struct mips_got_entry
*) *entryp
;
4034 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4035 if (entry
->abfd
!= NULL
4036 && entry
->symndx
== -1
4037 && (entry
->d
.h
->root
.root
.type
== bfd_link_hash_indirect
4038 || entry
->d
.h
->root
.root
.type
== bfd_link_hash_warning
))
4040 struct mips_elf_link_hash_entry
*h
;
4047 BFD_ASSERT (h
->global_got_area
== GGA_NONE
);
4048 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4050 while (h
->root
.root
.type
== bfd_link_hash_indirect
4051 || h
->root
.root
.type
== bfd_link_hash_warning
);
4054 slot
= htab_find_slot (arg
->g
->got_entries
, entry
, INSERT
);
4062 if (entry
== &new_entry
)
4064 entry
= bfd_alloc (entry
->abfd
, sizeof (*entry
));
4073 mips_elf_count_got_entry (arg
->info
, arg
->g
, entry
);
4078 /* Return the maximum number of GOT page entries required for RANGE. */
4081 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
4083 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
4086 /* Record that G requires a page entry that can reach SEC + ADDEND. */
4089 mips_elf_record_got_page_entry (struct mips_got_info
*g
,
4090 asection
*sec
, bfd_signed_vma addend
)
4092 struct mips_got_page_entry lookup
, *entry
;
4093 struct mips_got_page_range
**range_ptr
, *range
;
4094 bfd_vma old_pages
, new_pages
;
4097 /* Find the mips_got_page_entry hash table entry for this section. */
4099 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
4103 /* Create a mips_got_page_entry if this is the first time we've
4104 seen the section. */
4105 entry
= (struct mips_got_page_entry
*) *loc
;
4108 entry
= bfd_zalloc (sec
->owner
, sizeof (*entry
));
4116 /* Skip over ranges whose maximum extent cannot share a page entry
4118 range_ptr
= &entry
->ranges
;
4119 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
4120 range_ptr
= &(*range_ptr
)->next
;
4122 /* If we scanned to the end of the list, or found a range whose
4123 minimum extent cannot share a page entry with ADDEND, create
4124 a new singleton range. */
4126 if (!range
|| addend
< range
->min_addend
- 0xffff)
4128 range
= bfd_zalloc (sec
->owner
, sizeof (*range
));
4132 range
->next
= *range_ptr
;
4133 range
->min_addend
= addend
;
4134 range
->max_addend
= addend
;
4142 /* Remember how many pages the old range contributed. */
4143 old_pages
= mips_elf_pages_for_range (range
);
4145 /* Update the ranges. */
4146 if (addend
< range
->min_addend
)
4147 range
->min_addend
= addend
;
4148 else if (addend
> range
->max_addend
)
4150 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
4152 old_pages
+= mips_elf_pages_for_range (range
->next
);
4153 range
->max_addend
= range
->next
->max_addend
;
4154 range
->next
= range
->next
->next
;
4157 range
->max_addend
= addend
;
4160 /* Record any change in the total estimate. */
4161 new_pages
= mips_elf_pages_for_range (range
);
4162 if (old_pages
!= new_pages
)
4164 entry
->num_pages
+= new_pages
- old_pages
;
4165 g
->page_gotno
+= new_pages
- old_pages
;
4171 /* A htab_traverse callback for which *REFP points to a mips_got_page_ref
4172 and for which DATA points to a mips_elf_traverse_got_arg. Work out
4173 whether the page reference described by *REFP needs a GOT page entry,
4174 and record that entry in DATA->g if so. Set DATA->g to null on failure. */
4177 mips_elf_resolve_got_page_ref (void **refp
, void *data
)
4179 struct mips_got_page_ref
*ref
;
4180 struct mips_elf_traverse_got_arg
*arg
;
4181 struct mips_elf_link_hash_table
*htab
;
4185 ref
= (struct mips_got_page_ref
*) *refp
;
4186 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4187 htab
= mips_elf_hash_table (arg
->info
);
4189 if (ref
->symndx
< 0)
4191 struct mips_elf_link_hash_entry
*h
;
4193 /* Global GOT_PAGEs decay to GOT_DISP and so don't need page entries. */
4195 if (!SYMBOL_REFERENCES_LOCAL (arg
->info
, &h
->root
))
4198 /* Ignore undefined symbols; we'll issue an error later if
4200 if (!((h
->root
.root
.type
== bfd_link_hash_defined
4201 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4202 && h
->root
.root
.u
.def
.section
))
4205 sec
= h
->root
.root
.u
.def
.section
;
4206 addend
= h
->root
.root
.u
.def
.value
+ ref
->addend
;
4210 Elf_Internal_Sym
*isym
;
4212 /* Read in the symbol. */
4213 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ref
->u
.abfd
,
4221 /* Get the associated input section. */
4222 sec
= bfd_section_from_elf_index (ref
->u
.abfd
, isym
->st_shndx
);
4229 /* If this is a mergable section, work out the section and offset
4230 of the merged data. For section symbols, the addend specifies
4231 of the offset _of_ the first byte in the data, otherwise it
4232 specifies the offset _from_ the first byte. */
4233 if (sec
->flags
& SEC_MERGE
)
4237 secinfo
= elf_section_data (sec
)->sec_info
;
4238 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
4239 addend
= _bfd_merged_section_offset (ref
->u
.abfd
, &sec
, secinfo
,
4240 isym
->st_value
+ ref
->addend
);
4242 addend
= _bfd_merged_section_offset (ref
->u
.abfd
, &sec
, secinfo
,
4243 isym
->st_value
) + ref
->addend
;
4246 addend
= isym
->st_value
+ ref
->addend
;
4248 if (!mips_elf_record_got_page_entry (arg
->g
, sec
, addend
))
4256 /* If any entries in G->got_entries are for indirect or warning symbols,
4257 replace them with entries for the target symbol. Convert g->got_page_refs
4258 into got_page_entry structures and estimate the number of page entries
4259 that they require. */
4262 mips_elf_resolve_final_got_entries (struct bfd_link_info
*info
,
4263 struct mips_got_info
*g
)
4265 struct mips_elf_traverse_got_arg tga
;
4266 struct mips_got_info oldg
;
4273 htab_traverse (g
->got_entries
, mips_elf_check_recreate_got
, &tga
);
4277 g
->got_entries
= htab_create (htab_size (oldg
.got_entries
),
4278 mips_elf_got_entry_hash
,
4279 mips_elf_got_entry_eq
, NULL
);
4280 if (!g
->got_entries
)
4283 htab_traverse (oldg
.got_entries
, mips_elf_recreate_got
, &tga
);
4287 htab_delete (oldg
.got_entries
);
4290 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4291 mips_got_page_entry_eq
, NULL
);
4292 if (g
->got_page_entries
== NULL
)
4297 htab_traverse (g
->got_page_refs
, mips_elf_resolve_got_page_ref
, &tga
);
4302 /* A mips_elf_link_hash_traverse callback for which DATA points to the
4303 link_info structure. Decide whether the hash entry needs an entry in
4304 the global part of the primary GOT, setting global_got_area accordingly.
4305 Count the number of global symbols that are in the primary GOT only
4306 because they have relocations against them (reloc_only_gotno). */
4309 mips_elf_count_got_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
4311 struct bfd_link_info
*info
;
4312 struct mips_elf_link_hash_table
*htab
;
4313 struct mips_got_info
*g
;
4315 info
= (struct bfd_link_info
*) data
;
4316 htab
= mips_elf_hash_table (info
);
4318 if (h
->global_got_area
!= GGA_NONE
)
4320 /* Make a final decision about whether the symbol belongs in the
4321 local or global GOT. Symbols that bind locally can (and in the
4322 case of forced-local symbols, must) live in the local GOT.
4323 Those that are aren't in the dynamic symbol table must also
4324 live in the local GOT.
4326 Note that the former condition does not always imply the
4327 latter: symbols do not bind locally if they are completely
4328 undefined. We'll report undefined symbols later if appropriate. */
4329 if (h
->root
.dynindx
== -1
4330 || (h
->got_only_for_calls
4331 ? SYMBOL_CALLS_LOCAL (info
, &h
->root
)
4332 : SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
4333 /* The symbol belongs in the local GOT. We no longer need this
4334 entry if it was only used for relocations; those relocations
4335 will be against the null or section symbol instead of H. */
4336 h
->global_got_area
= GGA_NONE
;
4337 else if (htab
->is_vxworks
4338 && h
->got_only_for_calls
4339 && h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
)
4340 /* On VxWorks, calls can refer directly to the .got.plt entry;
4341 they don't need entries in the regular GOT. .got.plt entries
4342 will be allocated by _bfd_mips_elf_adjust_dynamic_symbol. */
4343 h
->global_got_area
= GGA_NONE
;
4344 else if (h
->global_got_area
== GGA_RELOC_ONLY
)
4346 g
->reloc_only_gotno
++;
4353 /* A htab_traverse callback for GOT entries. Add each one to the GOT
4354 given in mips_elf_traverse_got_arg DATA. Clear DATA->G on error. */
4357 mips_elf_add_got_entry (void **entryp
, void *data
)
4359 struct mips_got_entry
*entry
;
4360 struct mips_elf_traverse_got_arg
*arg
;
4363 entry
= (struct mips_got_entry
*) *entryp
;
4364 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4365 slot
= htab_find_slot (arg
->g
->got_entries
, entry
, INSERT
);
4374 mips_elf_count_got_entry (arg
->info
, arg
->g
, entry
);
4379 /* A htab_traverse callback for GOT page entries. Add each one to the GOT
4380 given in mips_elf_traverse_got_arg DATA. Clear DATA->G on error. */
4383 mips_elf_add_got_page_entry (void **entryp
, void *data
)
4385 struct mips_got_page_entry
*entry
;
4386 struct mips_elf_traverse_got_arg
*arg
;
4389 entry
= (struct mips_got_page_entry
*) *entryp
;
4390 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4391 slot
= htab_find_slot (arg
->g
->got_page_entries
, entry
, INSERT
);
4400 arg
->g
->page_gotno
+= entry
->num_pages
;
4405 /* Consider merging FROM, which is ABFD's GOT, into TO. Return -1 if
4406 this would lead to overflow, 1 if they were merged successfully,
4407 and 0 if a merge failed due to lack of memory. (These values are chosen
4408 so that nonnegative return values can be returned by a htab_traverse
4412 mips_elf_merge_got_with (bfd
*abfd
, struct mips_got_info
*from
,
4413 struct mips_got_info
*to
,
4414 struct mips_elf_got_per_bfd_arg
*arg
)
4416 struct mips_elf_traverse_got_arg tga
;
4417 unsigned int estimate
;
4419 /* Work out how many page entries we would need for the combined GOT. */
4420 estimate
= arg
->max_pages
;
4421 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
4422 estimate
= from
->page_gotno
+ to
->page_gotno
;
4424 /* And conservatively estimate how many local and TLS entries
4426 estimate
+= from
->local_gotno
+ to
->local_gotno
;
4427 estimate
+= from
->tls_gotno
+ to
->tls_gotno
;
4429 /* If we're merging with the primary got, any TLS relocations will
4430 come after the full set of global entries. Otherwise estimate those
4431 conservatively as well. */
4432 if (to
== arg
->primary
&& from
->tls_gotno
+ to
->tls_gotno
)
4433 estimate
+= arg
->global_count
;
4435 estimate
+= from
->global_gotno
+ to
->global_gotno
;
4437 /* Bail out if the combined GOT might be too big. */
4438 if (estimate
> arg
->max_count
)
4441 /* Transfer the bfd's got information from FROM to TO. */
4442 tga
.info
= arg
->info
;
4444 htab_traverse (from
->got_entries
, mips_elf_add_got_entry
, &tga
);
4448 htab_traverse (from
->got_page_entries
, mips_elf_add_got_page_entry
, &tga
);
4452 mips_elf_replace_bfd_got (abfd
, to
);
4456 /* Attempt to merge GOT G, which belongs to ABFD. Try to use as much
4457 as possible of the primary got, since it doesn't require explicit
4458 dynamic relocations, but don't use bfds that would reference global
4459 symbols out of the addressable range. Failing the primary got,
4460 attempt to merge with the current got, or finish the current got
4461 and then make make the new got current. */
4464 mips_elf_merge_got (bfd
*abfd
, struct mips_got_info
*g
,
4465 struct mips_elf_got_per_bfd_arg
*arg
)
4467 unsigned int estimate
;
4470 if (!mips_elf_resolve_final_got_entries (arg
->info
, g
))
4473 /* Work out the number of page, local and TLS entries. */
4474 estimate
= arg
->max_pages
;
4475 if (estimate
> g
->page_gotno
)
4476 estimate
= g
->page_gotno
;
4477 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
4479 /* We place TLS GOT entries after both locals and globals. The globals
4480 for the primary GOT may overflow the normal GOT size limit, so be
4481 sure not to merge a GOT which requires TLS with the primary GOT in that
4482 case. This doesn't affect non-primary GOTs. */
4483 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
4485 if (estimate
<= arg
->max_count
)
4487 /* If we don't have a primary GOT, use it as
4488 a starting point for the primary GOT. */
4495 /* Try merging with the primary GOT. */
4496 result
= mips_elf_merge_got_with (abfd
, g
, arg
->primary
, arg
);
4501 /* If we can merge with the last-created got, do it. */
4504 result
= mips_elf_merge_got_with (abfd
, g
, arg
->current
, arg
);
4509 /* Well, we couldn't merge, so create a new GOT. Don't check if it
4510 fits; if it turns out that it doesn't, we'll get relocation
4511 overflows anyway. */
4512 g
->next
= arg
->current
;
4518 /* ENTRYP is a hash table entry for a mips_got_entry. Set its gotidx
4519 to GOTIDX, duplicating the entry if it has already been assigned
4520 an index in a different GOT. */
4523 mips_elf_set_gotidx (void **entryp
, long gotidx
)
4525 struct mips_got_entry
*entry
;
4527 entry
= (struct mips_got_entry
*) *entryp
;
4528 if (entry
->gotidx
> 0)
4530 struct mips_got_entry
*new_entry
;
4532 new_entry
= bfd_alloc (entry
->abfd
, sizeof (*entry
));
4536 *new_entry
= *entry
;
4537 *entryp
= new_entry
;
4540 entry
->gotidx
= gotidx
;
4544 /* Set the TLS GOT index for the GOT entry in ENTRYP. DATA points to a
4545 mips_elf_traverse_got_arg in which DATA->value is the size of one
4546 GOT entry. Set DATA->g to null on failure. */
4549 mips_elf_initialize_tls_index (void **entryp
, void *data
)
4551 struct mips_got_entry
*entry
;
4552 struct mips_elf_traverse_got_arg
*arg
;
4554 /* We're only interested in TLS symbols. */
4555 entry
= (struct mips_got_entry
*) *entryp
;
4556 if (entry
->tls_type
== GOT_TLS_NONE
)
4559 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4560 if (!mips_elf_set_gotidx (entryp
, arg
->value
* arg
->g
->tls_assigned_gotno
))
4566 /* Account for the entries we've just allocated. */
4567 arg
->g
->tls_assigned_gotno
+= mips_tls_got_entries (entry
->tls_type
);
4571 /* A htab_traverse callback for GOT entries, where DATA points to a
4572 mips_elf_traverse_got_arg. Set the global_got_area of each global
4573 symbol to DATA->value. */
4576 mips_elf_set_global_got_area (void **entryp
, void *data
)
4578 struct mips_got_entry
*entry
;
4579 struct mips_elf_traverse_got_arg
*arg
;
4581 entry
= (struct mips_got_entry
*) *entryp
;
4582 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4583 if (entry
->abfd
!= NULL
4584 && entry
->symndx
== -1
4585 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
4586 entry
->d
.h
->global_got_area
= arg
->value
;
4590 /* A htab_traverse callback for secondary GOT entries, where DATA points
4591 to a mips_elf_traverse_got_arg. Assign GOT indices to global entries
4592 and record the number of relocations they require. DATA->value is
4593 the size of one GOT entry. Set DATA->g to null on failure. */
4596 mips_elf_set_global_gotidx (void **entryp
, void *data
)
4598 struct mips_got_entry
*entry
;
4599 struct mips_elf_traverse_got_arg
*arg
;
4601 entry
= (struct mips_got_entry
*) *entryp
;
4602 arg
= (struct mips_elf_traverse_got_arg
*) data
;
4603 if (entry
->abfd
!= NULL
4604 && entry
->symndx
== -1
4605 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
4607 if (!mips_elf_set_gotidx (entryp
, arg
->value
* arg
->g
->assigned_gotno
))
4612 arg
->g
->assigned_gotno
+= 1;
4614 if (arg
->info
->shared
4615 || (elf_hash_table (arg
->info
)->dynamic_sections_created
4616 && entry
->d
.h
->root
.def_dynamic
4617 && !entry
->d
.h
->root
.def_regular
))
4618 arg
->g
->relocs
+= 1;
4624 /* A htab_traverse callback for GOT entries for which DATA is the
4625 bfd_link_info. Forbid any global symbols from having traditional
4626 lazy-binding stubs. */
4629 mips_elf_forbid_lazy_stubs (void **entryp
, void *data
)
4631 struct bfd_link_info
*info
;
4632 struct mips_elf_link_hash_table
*htab
;
4633 struct mips_got_entry
*entry
;
4635 entry
= (struct mips_got_entry
*) *entryp
;
4636 info
= (struct bfd_link_info
*) data
;
4637 htab
= mips_elf_hash_table (info
);
4638 BFD_ASSERT (htab
!= NULL
);
4640 if (entry
->abfd
!= NULL
4641 && entry
->symndx
== -1
4642 && entry
->d
.h
->needs_lazy_stub
)
4644 entry
->d
.h
->needs_lazy_stub
= FALSE
;
4645 htab
->lazy_stub_count
--;
4651 /* Return the offset of an input bfd IBFD's GOT from the beginning of
4654 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
4659 g
= mips_elf_bfd_got (ibfd
, FALSE
);
4663 BFD_ASSERT (g
->next
);
4667 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
4668 * MIPS_ELF_GOT_SIZE (abfd
);
4671 /* Turn a single GOT that is too big for 16-bit addressing into
4672 a sequence of GOTs, each one 16-bit addressable. */
4675 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
4676 asection
*got
, bfd_size_type pages
)
4678 struct mips_elf_link_hash_table
*htab
;
4679 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
4680 struct mips_elf_traverse_got_arg tga
;
4681 struct mips_got_info
*g
, *gg
;
4682 unsigned int assign
, needed_relocs
;
4685 dynobj
= elf_hash_table (info
)->dynobj
;
4686 htab
= mips_elf_hash_table (info
);
4687 BFD_ASSERT (htab
!= NULL
);
4691 got_per_bfd_arg
.obfd
= abfd
;
4692 got_per_bfd_arg
.info
= info
;
4693 got_per_bfd_arg
.current
= NULL
;
4694 got_per_bfd_arg
.primary
= NULL
;
4695 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
4696 / MIPS_ELF_GOT_SIZE (abfd
))
4697 - htab
->reserved_gotno
);
4698 got_per_bfd_arg
.max_pages
= pages
;
4699 /* The number of globals that will be included in the primary GOT.
4700 See the calls to mips_elf_set_global_got_area below for more
4702 got_per_bfd_arg
.global_count
= g
->global_gotno
;
4704 /* Try to merge the GOTs of input bfds together, as long as they
4705 don't seem to exceed the maximum GOT size, choosing one of them
4706 to be the primary GOT. */
4707 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
4709 gg
= mips_elf_bfd_got (ibfd
, FALSE
);
4710 if (gg
&& !mips_elf_merge_got (ibfd
, gg
, &got_per_bfd_arg
))
4714 /* If we do not find any suitable primary GOT, create an empty one. */
4715 if (got_per_bfd_arg
.primary
== NULL
)
4716 g
->next
= mips_elf_create_got_info (abfd
);
4718 g
->next
= got_per_bfd_arg
.primary
;
4719 g
->next
->next
= got_per_bfd_arg
.current
;
4721 /* GG is now the master GOT, and G is the primary GOT. */
4725 /* Map the output bfd to the primary got. That's what we're going
4726 to use for bfds that use GOT16 or GOT_PAGE relocations that we
4727 didn't mark in check_relocs, and we want a quick way to find it.
4728 We can't just use gg->next because we're going to reverse the
4730 mips_elf_replace_bfd_got (abfd
, g
);
4732 /* Every symbol that is referenced in a dynamic relocation must be
4733 present in the primary GOT, so arrange for them to appear after
4734 those that are actually referenced. */
4735 gg
->reloc_only_gotno
= gg
->global_gotno
- g
->global_gotno
;
4736 g
->global_gotno
= gg
->global_gotno
;
4739 tga
.value
= GGA_RELOC_ONLY
;
4740 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_area
, &tga
);
4741 tga
.value
= GGA_NORMAL
;
4742 htab_traverse (g
->got_entries
, mips_elf_set_global_got_area
, &tga
);
4744 /* Now go through the GOTs assigning them offset ranges.
4745 [assigned_gotno, local_gotno[ will be set to the range of local
4746 entries in each GOT. We can then compute the end of a GOT by
4747 adding local_gotno to global_gotno. We reverse the list and make
4748 it circular since then we'll be able to quickly compute the
4749 beginning of a GOT, by computing the end of its predecessor. To
4750 avoid special cases for the primary GOT, while still preserving
4751 assertions that are valid for both single- and multi-got links,
4752 we arrange for the main got struct to have the right number of
4753 global entries, but set its local_gotno such that the initial
4754 offset of the primary GOT is zero. Remember that the primary GOT
4755 will become the last item in the circular linked list, so it
4756 points back to the master GOT. */
4757 gg
->local_gotno
= -g
->global_gotno
;
4758 gg
->global_gotno
= g
->global_gotno
;
4765 struct mips_got_info
*gn
;
4767 assign
+= htab
->reserved_gotno
;
4768 g
->assigned_gotno
= assign
;
4769 g
->local_gotno
+= assign
;
4770 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
4771 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
4773 /* Take g out of the direct list, and push it onto the reversed
4774 list that gg points to. g->next is guaranteed to be nonnull after
4775 this operation, as required by mips_elf_initialize_tls_index. */
4780 /* Set up any TLS entries. We always place the TLS entries after
4781 all non-TLS entries. */
4782 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
4784 tga
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4785 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, &tga
);
4788 BFD_ASSERT (g
->tls_assigned_gotno
== assign
);
4790 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
4793 /* Forbid global symbols in every non-primary GOT from having
4794 lazy-binding stubs. */
4796 htab_traverse (g
->got_entries
, mips_elf_forbid_lazy_stubs
, info
);
4800 got
->size
= assign
* MIPS_ELF_GOT_SIZE (abfd
);
4803 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
4805 unsigned int save_assign
;
4807 /* Assign offsets to global GOT entries and count how many
4808 relocations they need. */
4809 save_assign
= g
->assigned_gotno
;
4810 g
->assigned_gotno
= g
->local_gotno
;
4812 tga
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4814 htab_traverse (g
->got_entries
, mips_elf_set_global_gotidx
, &tga
);
4817 BFD_ASSERT (g
->assigned_gotno
== g
->local_gotno
+ g
->global_gotno
);
4818 g
->assigned_gotno
= save_assign
;
4822 g
->relocs
+= g
->local_gotno
- g
->assigned_gotno
;
4823 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
4824 + g
->next
->global_gotno
4825 + g
->next
->tls_gotno
4826 + htab
->reserved_gotno
);
4828 needed_relocs
+= g
->relocs
;
4830 needed_relocs
+= g
->relocs
;
4833 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
4840 /* Returns the first relocation of type r_type found, beginning with
4841 RELOCATION. RELEND is one-past-the-end of the relocation table. */
4843 static const Elf_Internal_Rela
*
4844 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
4845 const Elf_Internal_Rela
*relocation
,
4846 const Elf_Internal_Rela
*relend
)
4848 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
4850 while (relocation
< relend
)
4852 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
4853 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
4859 /* We didn't find it. */
4863 /* Return whether an input relocation is against a local symbol. */
4866 mips_elf_local_relocation_p (bfd
*input_bfd
,
4867 const Elf_Internal_Rela
*relocation
,
4868 asection
**local_sections
)
4870 unsigned long r_symndx
;
4871 Elf_Internal_Shdr
*symtab_hdr
;
4874 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4875 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4876 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
4878 if (r_symndx
< extsymoff
)
4880 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
4886 /* Sign-extend VALUE, which has the indicated number of BITS. */
4889 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
4891 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
4892 /* VALUE is negative. */
4893 value
|= ((bfd_vma
) - 1) << bits
;
4898 /* Return non-zero if the indicated VALUE has overflowed the maximum
4899 range expressible by a signed number with the indicated number of
4903 mips_elf_overflow_p (bfd_vma value
, int bits
)
4905 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
4907 if (svalue
> (1 << (bits
- 1)) - 1)
4908 /* The value is too big. */
4910 else if (svalue
< -(1 << (bits
- 1)))
4911 /* The value is too small. */
4918 /* Calculate the %high function. */
4921 mips_elf_high (bfd_vma value
)
4923 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
4926 /* Calculate the %higher function. */
4929 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
4932 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
4939 /* Calculate the %highest function. */
4942 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
4945 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
4952 /* Create the .compact_rel section. */
4955 mips_elf_create_compact_rel_section
4956 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4959 register asection
*s
;
4961 if (bfd_get_linker_section (abfd
, ".compact_rel") == NULL
)
4963 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
4966 s
= bfd_make_section_anyway_with_flags (abfd
, ".compact_rel", flags
);
4968 || ! bfd_set_section_alignment (abfd
, s
,
4969 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4972 s
->size
= sizeof (Elf32_External_compact_rel
);
4978 /* Create the .got section to hold the global offset table. */
4981 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4984 register asection
*s
;
4985 struct elf_link_hash_entry
*h
;
4986 struct bfd_link_hash_entry
*bh
;
4987 struct mips_elf_link_hash_table
*htab
;
4989 htab
= mips_elf_hash_table (info
);
4990 BFD_ASSERT (htab
!= NULL
);
4992 /* This function may be called more than once. */
4996 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4997 | SEC_LINKER_CREATED
);
4999 /* We have to use an alignment of 2**4 here because this is hardcoded
5000 in the function stub generation and in the linker script. */
5001 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
5003 || ! bfd_set_section_alignment (abfd
, s
, 4))
5007 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
5008 linker script because we don't want to define the symbol if we
5009 are not creating a global offset table. */
5011 if (! (_bfd_generic_link_add_one_symbol
5012 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
5013 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
5016 h
= (struct elf_link_hash_entry
*) bh
;
5019 h
->type
= STT_OBJECT
;
5020 h
->other
= (h
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
5021 elf_hash_table (info
)->hgot
= h
;
5024 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
5027 htab
->got_info
= mips_elf_create_got_info (abfd
);
5028 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
5029 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5031 /* We also need a .got.plt section when generating PLTs. */
5032 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt",
5033 SEC_ALLOC
| SEC_LOAD
5036 | SEC_LINKER_CREATED
);
5044 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
5045 __GOTT_INDEX__ symbols. These symbols are only special for
5046 shared objects; they are not used in executables. */
5049 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
5051 return (mips_elf_hash_table (info
)->is_vxworks
5053 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
5054 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
5057 /* Return TRUE if a relocation of type R_TYPE from INPUT_BFD might
5058 require an la25 stub. See also mips_elf_local_pic_function_p,
5059 which determines whether the destination function ever requires a
5063 mips_elf_relocation_needs_la25_stub (bfd
*input_bfd
, int r_type
,
5064 bfd_boolean target_is_16_bit_code_p
)
5066 /* We specifically ignore branches and jumps from EF_PIC objects,
5067 where the onus is on the compiler or programmer to perform any
5068 necessary initialization of $25. Sometimes such initialization
5069 is unnecessary; for example, -mno-shared functions do not use
5070 the incoming value of $25, and may therefore be called directly. */
5071 if (PIC_OBJECT_P (input_bfd
))
5078 case R_MICROMIPS_26_S1
:
5079 case R_MICROMIPS_PC7_S1
:
5080 case R_MICROMIPS_PC10_S1
:
5081 case R_MICROMIPS_PC16_S1
:
5082 case R_MICROMIPS_PC23_S2
:
5086 return !target_is_16_bit_code_p
;
5093 /* Calculate the value produced by the RELOCATION (which comes from
5094 the INPUT_BFD). The ADDEND is the addend to use for this
5095 RELOCATION; RELOCATION->R_ADDEND is ignored.
5097 The result of the relocation calculation is stored in VALUEP.
5098 On exit, set *CROSS_MODE_JUMP_P to true if the relocation field
5099 is a MIPS16 or microMIPS jump to standard MIPS code, or vice versa.
5101 This function returns bfd_reloc_continue if the caller need take no
5102 further action regarding this relocation, bfd_reloc_notsupported if
5103 something goes dramatically wrong, bfd_reloc_overflow if an
5104 overflow occurs, and bfd_reloc_ok to indicate success. */
5106 static bfd_reloc_status_type
5107 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
5108 asection
*input_section
,
5109 struct bfd_link_info
*info
,
5110 const Elf_Internal_Rela
*relocation
,
5111 bfd_vma addend
, reloc_howto_type
*howto
,
5112 Elf_Internal_Sym
*local_syms
,
5113 asection
**local_sections
, bfd_vma
*valuep
,
5115 bfd_boolean
*cross_mode_jump_p
,
5116 bfd_boolean save_addend
)
5118 /* The eventual value we will return. */
5120 /* The address of the symbol against which the relocation is
5123 /* The final GP value to be used for the relocatable, executable, or
5124 shared object file being produced. */
5126 /* The place (section offset or address) of the storage unit being
5129 /* The value of GP used to create the relocatable object. */
5131 /* The offset into the global offset table at which the address of
5132 the relocation entry symbol, adjusted by the addend, resides
5133 during execution. */
5134 bfd_vma g
= MINUS_ONE
;
5135 /* The section in which the symbol referenced by the relocation is
5137 asection
*sec
= NULL
;
5138 struct mips_elf_link_hash_entry
*h
= NULL
;
5139 /* TRUE if the symbol referred to by this relocation is a local
5141 bfd_boolean local_p
, was_local_p
;
5142 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
5143 bfd_boolean gp_disp_p
= FALSE
;
5144 /* TRUE if the symbol referred to by this relocation is
5145 "__gnu_local_gp". */
5146 bfd_boolean gnu_local_gp_p
= FALSE
;
5147 Elf_Internal_Shdr
*symtab_hdr
;
5149 unsigned long r_symndx
;
5151 /* TRUE if overflow occurred during the calculation of the
5152 relocation value. */
5153 bfd_boolean overflowed_p
;
5154 /* TRUE if this relocation refers to a MIPS16 function. */
5155 bfd_boolean target_is_16_bit_code_p
= FALSE
;
5156 bfd_boolean target_is_micromips_code_p
= FALSE
;
5157 struct mips_elf_link_hash_table
*htab
;
5160 dynobj
= elf_hash_table (info
)->dynobj
;
5161 htab
= mips_elf_hash_table (info
);
5162 BFD_ASSERT (htab
!= NULL
);
5164 /* Parse the relocation. */
5165 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
5166 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5167 p
= (input_section
->output_section
->vma
5168 + input_section
->output_offset
5169 + relocation
->r_offset
);
5171 /* Assume that there will be no overflow. */
5172 overflowed_p
= FALSE
;
5174 /* Figure out whether or not the symbol is local, and get the offset
5175 used in the array of hash table entries. */
5176 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5177 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
5179 was_local_p
= local_p
;
5180 if (! elf_bad_symtab (input_bfd
))
5181 extsymoff
= symtab_hdr
->sh_info
;
5184 /* The symbol table does not follow the rule that local symbols
5185 must come before globals. */
5189 /* Figure out the value of the symbol. */
5192 Elf_Internal_Sym
*sym
;
5194 sym
= local_syms
+ r_symndx
;
5195 sec
= local_sections
[r_symndx
];
5197 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5198 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
5199 || (sec
->flags
& SEC_MERGE
))
5200 symbol
+= sym
->st_value
;
5201 if ((sec
->flags
& SEC_MERGE
)
5202 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
5204 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
5206 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
5209 /* MIPS16/microMIPS text labels should be treated as odd. */
5210 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
5213 /* Record the name of this symbol, for our caller. */
5214 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
5215 symtab_hdr
->sh_link
,
5218 *namep
= bfd_section_name (input_bfd
, sec
);
5220 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
5221 target_is_micromips_code_p
= ELF_ST_IS_MICROMIPS (sym
->st_other
);
5225 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
5227 /* For global symbols we look up the symbol in the hash-table. */
5228 h
= ((struct mips_elf_link_hash_entry
*)
5229 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
5230 /* Find the real hash-table entry for this symbol. */
5231 while (h
->root
.root
.type
== bfd_link_hash_indirect
5232 || h
->root
.root
.type
== bfd_link_hash_warning
)
5233 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5235 /* Record the name of this symbol, for our caller. */
5236 *namep
= h
->root
.root
.root
.string
;
5238 /* See if this is the special _gp_disp symbol. Note that such a
5239 symbol must always be a global symbol. */
5240 if (strcmp (*namep
, "_gp_disp") == 0
5241 && ! NEWABI_P (input_bfd
))
5243 /* Relocations against _gp_disp are permitted only with
5244 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
5245 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
5246 return bfd_reloc_notsupported
;
5250 /* See if this is the special _gp symbol. Note that such a
5251 symbol must always be a global symbol. */
5252 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
5253 gnu_local_gp_p
= TRUE
;
5256 /* If this symbol is defined, calculate its address. Note that
5257 _gp_disp is a magic symbol, always implicitly defined by the
5258 linker, so it's inappropriate to check to see whether or not
5260 else if ((h
->root
.root
.type
== bfd_link_hash_defined
5261 || h
->root
.root
.type
== bfd_link_hash_defweak
)
5262 && h
->root
.root
.u
.def
.section
)
5264 sec
= h
->root
.root
.u
.def
.section
;
5265 if (sec
->output_section
)
5266 symbol
= (h
->root
.root
.u
.def
.value
5267 + sec
->output_section
->vma
5268 + sec
->output_offset
);
5270 symbol
= h
->root
.root
.u
.def
.value
;
5272 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
5273 /* We allow relocations against undefined weak symbols, giving
5274 it the value zero, so that you can undefined weak functions
5275 and check to see if they exist by looking at their
5278 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
5279 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5281 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
5282 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
5284 /* If this is a dynamic link, we should have created a
5285 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
5286 in in _bfd_mips_elf_create_dynamic_sections.
5287 Otherwise, we should define the symbol with a value of 0.
5288 FIXME: It should probably get into the symbol table
5290 BFD_ASSERT (! info
->shared
);
5291 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
5294 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
5296 /* This is an optional symbol - an Irix specific extension to the
5297 ELF spec. Ignore it for now.
5298 XXX - FIXME - there is more to the spec for OPTIONAL symbols
5299 than simply ignoring them, but we do not handle this for now.
5300 For information see the "64-bit ELF Object File Specification"
5301 which is available from here:
5302 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
5305 else if ((*info
->callbacks
->undefined_symbol
)
5306 (info
, h
->root
.root
.root
.string
, input_bfd
,
5307 input_section
, relocation
->r_offset
,
5308 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
5309 || ELF_ST_VISIBILITY (h
->root
.other
)))
5311 return bfd_reloc_undefined
;
5315 return bfd_reloc_notsupported
;
5318 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
5319 target_is_micromips_code_p
= ELF_ST_IS_MICROMIPS (h
->root
.other
);
5322 /* If this is a reference to a 16-bit function with a stub, we need
5323 to redirect the relocation to the stub unless:
5325 (a) the relocation is for a MIPS16 JAL;
5327 (b) the relocation is for a MIPS16 PIC call, and there are no
5328 non-MIPS16 uses of the GOT slot; or
5330 (c) the section allows direct references to MIPS16 functions. */
5331 if (r_type
!= R_MIPS16_26
5332 && !info
->relocatable
5334 && h
->fn_stub
!= NULL
5335 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
5337 && mips_elf_tdata (input_bfd
)->local_stubs
!= NULL
5338 && mips_elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5339 && !section_allows_mips16_refs_p (input_section
))
5341 /* This is a 32- or 64-bit call to a 16-bit function. We should
5342 have already noticed that we were going to need the
5346 sec
= mips_elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5351 BFD_ASSERT (h
->need_fn_stub
);
5354 /* If a LA25 header for the stub itself exists, point to the
5355 prepended LUI/ADDIU sequence. */
5356 sec
= h
->la25_stub
->stub_section
;
5357 value
= h
->la25_stub
->offset
;
5366 symbol
= sec
->output_section
->vma
+ sec
->output_offset
+ value
;
5367 /* The target is 16-bit, but the stub isn't. */
5368 target_is_16_bit_code_p
= FALSE
;
5370 /* If this is a MIPS16 call with a stub, that is made through the PLT or
5371 to a standard MIPS function, we need to redirect the call to the stub.
5372 Note that we specifically exclude R_MIPS16_CALL16 from this behavior;
5373 indirect calls should use an indirect stub instead. */
5374 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
5375 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
5377 && mips_elf_tdata (input_bfd
)->local_call_stubs
!= NULL
5378 && mips_elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
5379 && ((h
!= NULL
&& h
->use_plt_entry
) || !target_is_16_bit_code_p
))
5382 sec
= mips_elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
5385 /* If both call_stub and call_fp_stub are defined, we can figure
5386 out which one to use by checking which one appears in the input
5388 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
5393 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5395 if (CALL_FP_STUB_P (bfd_get_section_name (input_bfd
, o
)))
5397 sec
= h
->call_fp_stub
;
5404 else if (h
->call_stub
!= NULL
)
5407 sec
= h
->call_fp_stub
;
5410 BFD_ASSERT (sec
->size
> 0);
5411 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5413 /* If this is a direct call to a PIC function, redirect to the
5415 else if (h
!= NULL
&& h
->la25_stub
5416 && mips_elf_relocation_needs_la25_stub (input_bfd
, r_type
,
5417 target_is_16_bit_code_p
))
5418 symbol
= (h
->la25_stub
->stub_section
->output_section
->vma
5419 + h
->la25_stub
->stub_section
->output_offset
5420 + h
->la25_stub
->offset
);
5421 /* For direct MIPS16 and microMIPS calls make sure the compressed PLT
5422 entry is used if a standard PLT entry has also been made. In this
5423 case the symbol will have been set by mips_elf_set_plt_sym_value
5424 to point to the standard PLT entry, so redirect to the compressed
5426 else if ((r_type
== R_MIPS16_26
|| r_type
== R_MICROMIPS_26_S1
)
5427 && !info
->relocatable
5430 && h
->root
.plt
.plist
->comp_offset
!= MINUS_ONE
5431 && h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
)
5433 bfd_boolean micromips_p
= MICROMIPS_P (abfd
);
5436 symbol
= (sec
->output_section
->vma
5437 + sec
->output_offset
5438 + htab
->plt_header_size
5439 + htab
->plt_mips_offset
5440 + h
->root
.plt
.plist
->comp_offset
5443 target_is_16_bit_code_p
= !micromips_p
;
5444 target_is_micromips_code_p
= micromips_p
;
5447 /* Make sure MIPS16 and microMIPS are not used together. */
5448 if ((r_type
== R_MIPS16_26
&& target_is_micromips_code_p
)
5449 || (micromips_branch_reloc_p (r_type
) && target_is_16_bit_code_p
))
5451 (*_bfd_error_handler
)
5452 (_("MIPS16 and microMIPS functions cannot call each other"));
5453 return bfd_reloc_notsupported
;
5456 /* Calls from 16-bit code to 32-bit code and vice versa require the
5457 mode change. However, we can ignore calls to undefined weak symbols,
5458 which should never be executed at runtime. This exception is important
5459 because the assembly writer may have "known" that any definition of the
5460 symbol would be 16-bit code, and that direct jumps were therefore
5462 *cross_mode_jump_p
= (!info
->relocatable
5463 && !(h
&& h
->root
.root
.type
== bfd_link_hash_undefweak
)
5464 && ((r_type
== R_MIPS16_26
&& !target_is_16_bit_code_p
)
5465 || (r_type
== R_MICROMIPS_26_S1
5466 && !target_is_micromips_code_p
)
5467 || ((r_type
== R_MIPS_26
|| r_type
== R_MIPS_JALR
)
5468 && (target_is_16_bit_code_p
5469 || target_is_micromips_code_p
))));
5471 local_p
= (h
== NULL
5472 || (h
->got_only_for_calls
5473 ? SYMBOL_CALLS_LOCAL (info
, &h
->root
)
5474 : SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)));
5476 gp0
= _bfd_get_gp_value (input_bfd
);
5477 gp
= _bfd_get_gp_value (abfd
);
5479 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
5484 /* Global R_MIPS_GOT_PAGE/R_MICROMIPS_GOT_PAGE relocations are equivalent
5485 to R_MIPS_GOT_DISP/R_MICROMIPS_GOT_DISP. The addend is applied by the
5486 corresponding R_MIPS_GOT_OFST/R_MICROMIPS_GOT_OFST. */
5487 if (got_page_reloc_p (r_type
) && !local_p
)
5489 r_type
= (micromips_reloc_p (r_type
)
5490 ? R_MICROMIPS_GOT_DISP
: R_MIPS_GOT_DISP
);
5494 /* If we haven't already determined the GOT offset, and we're going
5495 to need it, get it now. */
5498 case R_MIPS16_CALL16
:
5499 case R_MIPS16_GOT16
:
5502 case R_MIPS_GOT_DISP
:
5503 case R_MIPS_GOT_HI16
:
5504 case R_MIPS_CALL_HI16
:
5505 case R_MIPS_GOT_LO16
:
5506 case R_MIPS_CALL_LO16
:
5507 case R_MICROMIPS_CALL16
:
5508 case R_MICROMIPS_GOT16
:
5509 case R_MICROMIPS_GOT_DISP
:
5510 case R_MICROMIPS_GOT_HI16
:
5511 case R_MICROMIPS_CALL_HI16
:
5512 case R_MICROMIPS_GOT_LO16
:
5513 case R_MICROMIPS_CALL_LO16
:
5515 case R_MIPS_TLS_GOTTPREL
:
5516 case R_MIPS_TLS_LDM
:
5517 case R_MIPS16_TLS_GD
:
5518 case R_MIPS16_TLS_GOTTPREL
:
5519 case R_MIPS16_TLS_LDM
:
5520 case R_MICROMIPS_TLS_GD
:
5521 case R_MICROMIPS_TLS_GOTTPREL
:
5522 case R_MICROMIPS_TLS_LDM
:
5523 /* Find the index into the GOT where this value is located. */
5524 if (tls_ldm_reloc_p (r_type
))
5526 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5527 0, 0, NULL
, r_type
);
5529 return bfd_reloc_outofrange
;
5533 /* On VxWorks, CALL relocations should refer to the .got.plt
5534 entry, which is initialized to point at the PLT stub. */
5535 if (htab
->is_vxworks
5536 && (call_hi16_reloc_p (r_type
)
5537 || call_lo16_reloc_p (r_type
)
5538 || call16_reloc_p (r_type
)))
5540 BFD_ASSERT (addend
== 0);
5541 BFD_ASSERT (h
->root
.needs_plt
);
5542 g
= mips_elf_gotplt_index (info
, &h
->root
);
5546 BFD_ASSERT (addend
== 0);
5547 g
= mips_elf_global_got_index (abfd
, info
, input_bfd
,
5549 if (!TLS_RELOC_P (r_type
)
5550 && !elf_hash_table (info
)->dynamic_sections_created
)
5551 /* This is a static link. We must initialize the GOT entry. */
5552 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->sgot
->contents
+ g
);
5555 else if (!htab
->is_vxworks
5556 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
5557 /* The calculation below does not involve "g". */
5561 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5562 symbol
+ addend
, r_symndx
, h
, r_type
);
5564 return bfd_reloc_outofrange
;
5567 /* Convert GOT indices to actual offsets. */
5568 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
5572 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
5573 symbols are resolved by the loader. Add them to .rela.dyn. */
5574 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
5576 Elf_Internal_Rela outrel
;
5580 s
= mips_elf_rel_dyn_section (info
, FALSE
);
5581 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5583 outrel
.r_offset
= (input_section
->output_section
->vma
5584 + input_section
->output_offset
5585 + relocation
->r_offset
);
5586 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
5587 outrel
.r_addend
= addend
;
5588 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
5590 /* If we've written this relocation for a readonly section,
5591 we need to set DF_TEXTREL again, so that we do not delete the
5593 if (MIPS_ELF_READONLY_SECTION (input_section
))
5594 info
->flags
|= DF_TEXTREL
;
5597 return bfd_reloc_ok
;
5600 /* Figure out what kind of relocation is being performed. */
5604 return bfd_reloc_continue
;
5607 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
5608 overflowed_p
= mips_elf_overflow_p (value
, 16);
5615 || (htab
->root
.dynamic_sections_created
5617 && h
->root
.def_dynamic
5618 && !h
->root
.def_regular
5619 && !h
->has_static_relocs
))
5620 && r_symndx
!= STN_UNDEF
5622 || h
->root
.root
.type
!= bfd_link_hash_undefweak
5623 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5624 && (input_section
->flags
& SEC_ALLOC
) != 0)
5626 /* If we're creating a shared library, then we can't know
5627 where the symbol will end up. So, we create a relocation
5628 record in the output, and leave the job up to the dynamic
5629 linker. We must do the same for executable references to
5630 shared library symbols, unless we've decided to use copy
5631 relocs or PLTs instead. */
5633 if (!mips_elf_create_dynamic_relocation (abfd
,
5641 return bfd_reloc_undefined
;
5645 if (r_type
!= R_MIPS_REL32
)
5646 value
= symbol
+ addend
;
5650 value
&= howto
->dst_mask
;
5654 value
= symbol
+ addend
- p
;
5655 value
&= howto
->dst_mask
;
5659 /* The calculation for R_MIPS16_26 is just the same as for an
5660 R_MIPS_26. It's only the storage of the relocated field into
5661 the output file that's different. That's handled in
5662 mips_elf_perform_relocation. So, we just fall through to the
5663 R_MIPS_26 case here. */
5665 case R_MICROMIPS_26_S1
:
5669 /* Make sure the target of JALX is word-aligned. Bit 0 must be
5670 the correct ISA mode selector and bit 1 must be 0. */
5671 if (*cross_mode_jump_p
&& (symbol
& 3) != (r_type
== R_MIPS_26
))
5672 return bfd_reloc_outofrange
;
5674 /* Shift is 2, unusually, for microMIPS JALX. */
5675 shift
= (!*cross_mode_jump_p
&& r_type
== R_MICROMIPS_26_S1
) ? 1 : 2;
5678 value
= addend
| ((p
+ 4) & (0xfc000000 << shift
));
5680 value
= _bfd_mips_elf_sign_extend (addend
, 26 + shift
);
5681 value
= (value
+ symbol
) >> shift
;
5682 if (!was_local_p
&& h
->root
.root
.type
!= bfd_link_hash_undefweak
)
5683 overflowed_p
= (value
>> 26) != ((p
+ 4) >> (26 + shift
));
5684 value
&= howto
->dst_mask
;
5688 case R_MIPS_TLS_DTPREL_HI16
:
5689 case R_MIPS16_TLS_DTPREL_HI16
:
5690 case R_MICROMIPS_TLS_DTPREL_HI16
:
5691 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
5695 case R_MIPS_TLS_DTPREL_LO16
:
5696 case R_MIPS_TLS_DTPREL32
:
5697 case R_MIPS_TLS_DTPREL64
:
5698 case R_MIPS16_TLS_DTPREL_LO16
:
5699 case R_MICROMIPS_TLS_DTPREL_LO16
:
5700 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
5703 case R_MIPS_TLS_TPREL_HI16
:
5704 case R_MIPS16_TLS_TPREL_HI16
:
5705 case R_MICROMIPS_TLS_TPREL_HI16
:
5706 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
5710 case R_MIPS_TLS_TPREL_LO16
:
5711 case R_MIPS_TLS_TPREL32
:
5712 case R_MIPS_TLS_TPREL64
:
5713 case R_MIPS16_TLS_TPREL_LO16
:
5714 case R_MICROMIPS_TLS_TPREL_LO16
:
5715 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
5720 case R_MICROMIPS_HI16
:
5723 value
= mips_elf_high (addend
+ symbol
);
5724 value
&= howto
->dst_mask
;
5728 /* For MIPS16 ABI code we generate this sequence
5729 0: li $v0,%hi(_gp_disp)
5730 4: addiupc $v1,%lo(_gp_disp)
5734 So the offsets of hi and lo relocs are the same, but the
5735 base $pc is that used by the ADDIUPC instruction at $t9 + 4.
5736 ADDIUPC clears the low two bits of the instruction address,
5737 so the base is ($t9 + 4) & ~3. */
5738 if (r_type
== R_MIPS16_HI16
)
5739 value
= mips_elf_high (addend
+ gp
- ((p
+ 4) & ~(bfd_vma
) 0x3));
5740 /* The microMIPS .cpload sequence uses the same assembly
5741 instructions as the traditional psABI version, but the
5742 incoming $t9 has the low bit set. */
5743 else if (r_type
== R_MICROMIPS_HI16
)
5744 value
= mips_elf_high (addend
+ gp
- p
- 1);
5746 value
= mips_elf_high (addend
+ gp
- p
);
5747 overflowed_p
= mips_elf_overflow_p (value
, 16);
5753 case R_MICROMIPS_LO16
:
5754 case R_MICROMIPS_HI0_LO16
:
5756 value
= (symbol
+ addend
) & howto
->dst_mask
;
5759 /* See the comment for R_MIPS16_HI16 above for the reason
5760 for this conditional. */
5761 if (r_type
== R_MIPS16_LO16
)
5762 value
= addend
+ gp
- (p
& ~(bfd_vma
) 0x3);
5763 else if (r_type
== R_MICROMIPS_LO16
5764 || r_type
== R_MICROMIPS_HI0_LO16
)
5765 value
= addend
+ gp
- p
+ 3;
5767 value
= addend
+ gp
- p
+ 4;
5768 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
5769 for overflow. But, on, say, IRIX5, relocations against
5770 _gp_disp are normally generated from the .cpload
5771 pseudo-op. It generates code that normally looks like
5774 lui $gp,%hi(_gp_disp)
5775 addiu $gp,$gp,%lo(_gp_disp)
5778 Here $t9 holds the address of the function being called,
5779 as required by the MIPS ELF ABI. The R_MIPS_LO16
5780 relocation can easily overflow in this situation, but the
5781 R_MIPS_HI16 relocation will handle the overflow.
5782 Therefore, we consider this a bug in the MIPS ABI, and do
5783 not check for overflow here. */
5787 case R_MIPS_LITERAL
:
5788 case R_MICROMIPS_LITERAL
:
5789 /* Because we don't merge literal sections, we can handle this
5790 just like R_MIPS_GPREL16. In the long run, we should merge
5791 shared literals, and then we will need to additional work
5796 case R_MIPS16_GPREL
:
5797 /* The R_MIPS16_GPREL performs the same calculation as
5798 R_MIPS_GPREL16, but stores the relocated bits in a different
5799 order. We don't need to do anything special here; the
5800 differences are handled in mips_elf_perform_relocation. */
5801 case R_MIPS_GPREL16
:
5802 case R_MICROMIPS_GPREL7_S2
:
5803 case R_MICROMIPS_GPREL16
:
5804 /* Only sign-extend the addend if it was extracted from the
5805 instruction. If the addend was separate, leave it alone,
5806 otherwise we may lose significant bits. */
5807 if (howto
->partial_inplace
)
5808 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
5809 value
= symbol
+ addend
- gp
;
5810 /* If the symbol was local, any earlier relocatable links will
5811 have adjusted its addend with the gp offset, so compensate
5812 for that now. Don't do it for symbols forced local in this
5813 link, though, since they won't have had the gp offset applied
5817 overflowed_p
= mips_elf_overflow_p (value
, 16);
5820 case R_MIPS16_GOT16
:
5821 case R_MIPS16_CALL16
:
5824 case R_MICROMIPS_GOT16
:
5825 case R_MICROMIPS_CALL16
:
5826 /* VxWorks does not have separate local and global semantics for
5827 R_MIPS*_GOT16; every relocation evaluates to "G". */
5828 if (!htab
->is_vxworks
&& local_p
)
5830 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
5831 symbol
+ addend
, !was_local_p
);
5832 if (value
== MINUS_ONE
)
5833 return bfd_reloc_outofrange
;
5835 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5836 overflowed_p
= mips_elf_overflow_p (value
, 16);
5843 case R_MIPS_TLS_GOTTPREL
:
5844 case R_MIPS_TLS_LDM
:
5845 case R_MIPS_GOT_DISP
:
5846 case R_MIPS16_TLS_GD
:
5847 case R_MIPS16_TLS_GOTTPREL
:
5848 case R_MIPS16_TLS_LDM
:
5849 case R_MICROMIPS_TLS_GD
:
5850 case R_MICROMIPS_TLS_GOTTPREL
:
5851 case R_MICROMIPS_TLS_LDM
:
5852 case R_MICROMIPS_GOT_DISP
:
5854 overflowed_p
= mips_elf_overflow_p (value
, 16);
5857 case R_MIPS_GPREL32
:
5858 value
= (addend
+ symbol
+ gp0
- gp
);
5860 value
&= howto
->dst_mask
;
5864 case R_MIPS_GNU_REL16_S2
:
5865 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
5866 overflowed_p
= mips_elf_overflow_p (value
, 18);
5867 value
>>= howto
->rightshift
;
5868 value
&= howto
->dst_mask
;
5871 case R_MICROMIPS_PC7_S1
:
5872 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 8) - p
;
5873 overflowed_p
= mips_elf_overflow_p (value
, 8);
5874 value
>>= howto
->rightshift
;
5875 value
&= howto
->dst_mask
;
5878 case R_MICROMIPS_PC10_S1
:
5879 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 11) - p
;
5880 overflowed_p
= mips_elf_overflow_p (value
, 11);
5881 value
>>= howto
->rightshift
;
5882 value
&= howto
->dst_mask
;
5885 case R_MICROMIPS_PC16_S1
:
5886 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 17) - p
;
5887 overflowed_p
= mips_elf_overflow_p (value
, 17);
5888 value
>>= howto
->rightshift
;
5889 value
&= howto
->dst_mask
;
5892 case R_MICROMIPS_PC23_S2
:
5893 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 25) - ((p
| 3) ^ 3);
5894 overflowed_p
= mips_elf_overflow_p (value
, 25);
5895 value
>>= howto
->rightshift
;
5896 value
&= howto
->dst_mask
;
5899 case R_MIPS_GOT_HI16
:
5900 case R_MIPS_CALL_HI16
:
5901 case R_MICROMIPS_GOT_HI16
:
5902 case R_MICROMIPS_CALL_HI16
:
5903 /* We're allowed to handle these two relocations identically.
5904 The dynamic linker is allowed to handle the CALL relocations
5905 differently by creating a lazy evaluation stub. */
5907 value
= mips_elf_high (value
);
5908 value
&= howto
->dst_mask
;
5911 case R_MIPS_GOT_LO16
:
5912 case R_MIPS_CALL_LO16
:
5913 case R_MICROMIPS_GOT_LO16
:
5914 case R_MICROMIPS_CALL_LO16
:
5915 value
= g
& howto
->dst_mask
;
5918 case R_MIPS_GOT_PAGE
:
5919 case R_MICROMIPS_GOT_PAGE
:
5920 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
5921 if (value
== MINUS_ONE
)
5922 return bfd_reloc_outofrange
;
5923 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5924 overflowed_p
= mips_elf_overflow_p (value
, 16);
5927 case R_MIPS_GOT_OFST
:
5928 case R_MICROMIPS_GOT_OFST
:
5930 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
5933 overflowed_p
= mips_elf_overflow_p (value
, 16);
5937 case R_MICROMIPS_SUB
:
5938 value
= symbol
- addend
;
5939 value
&= howto
->dst_mask
;
5943 case R_MICROMIPS_HIGHER
:
5944 value
= mips_elf_higher (addend
+ symbol
);
5945 value
&= howto
->dst_mask
;
5948 case R_MIPS_HIGHEST
:
5949 case R_MICROMIPS_HIGHEST
:
5950 value
= mips_elf_highest (addend
+ symbol
);
5951 value
&= howto
->dst_mask
;
5954 case R_MIPS_SCN_DISP
:
5955 case R_MICROMIPS_SCN_DISP
:
5956 value
= symbol
+ addend
- sec
->output_offset
;
5957 value
&= howto
->dst_mask
;
5961 case R_MICROMIPS_JALR
:
5962 /* This relocation is only a hint. In some cases, we optimize
5963 it into a bal instruction. But we don't try to optimize
5964 when the symbol does not resolve locally. */
5965 if (h
!= NULL
&& !SYMBOL_CALLS_LOCAL (info
, &h
->root
))
5966 return bfd_reloc_continue
;
5967 value
= symbol
+ addend
;
5971 case R_MIPS_GNU_VTINHERIT
:
5972 case R_MIPS_GNU_VTENTRY
:
5973 /* We don't do anything with these at present. */
5974 return bfd_reloc_continue
;
5977 /* An unrecognized relocation type. */
5978 return bfd_reloc_notsupported
;
5981 /* Store the VALUE for our caller. */
5983 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
5986 /* Obtain the field relocated by RELOCATION. */
5989 mips_elf_obtain_contents (reloc_howto_type
*howto
,
5990 const Elf_Internal_Rela
*relocation
,
5991 bfd
*input_bfd
, bfd_byte
*contents
)
5994 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5996 /* Obtain the bytes. */
5997 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
6002 /* It has been determined that the result of the RELOCATION is the
6003 VALUE. Use HOWTO to place VALUE into the output file at the
6004 appropriate position. The SECTION is the section to which the
6006 CROSS_MODE_JUMP_P is true if the relocation field
6007 is a MIPS16 or microMIPS jump to standard MIPS code, or vice versa.
6009 Returns FALSE if anything goes wrong. */
6012 mips_elf_perform_relocation (struct bfd_link_info
*info
,
6013 reloc_howto_type
*howto
,
6014 const Elf_Internal_Rela
*relocation
,
6015 bfd_vma value
, bfd
*input_bfd
,
6016 asection
*input_section
, bfd_byte
*contents
,
6017 bfd_boolean cross_mode_jump_p
)
6021 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
6023 /* Figure out where the relocation is occurring. */
6024 location
= contents
+ relocation
->r_offset
;
6026 _bfd_mips_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
6028 /* Obtain the current value. */
6029 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
6031 /* Clear the field we are setting. */
6032 x
&= ~howto
->dst_mask
;
6034 /* Set the field. */
6035 x
|= (value
& howto
->dst_mask
);
6037 /* If required, turn JAL into JALX. */
6038 if (cross_mode_jump_p
&& jal_reloc_p (r_type
))
6041 bfd_vma opcode
= x
>> 26;
6042 bfd_vma jalx_opcode
;
6044 /* Check to see if the opcode is already JAL or JALX. */
6045 if (r_type
== R_MIPS16_26
)
6047 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
6050 else if (r_type
== R_MICROMIPS_26_S1
)
6052 ok
= ((opcode
== 0x3d) || (opcode
== 0x3c));
6057 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
6061 /* If the opcode is not JAL or JALX, there's a problem. We cannot
6062 convert J or JALS to JALX. */
6065 (*_bfd_error_handler
)
6066 (_("%B: %A+0x%lx: Unsupported jump between ISA modes; consider recompiling with interlinking enabled."),
6069 (unsigned long) relocation
->r_offset
);
6070 bfd_set_error (bfd_error_bad_value
);
6074 /* Make this the JALX opcode. */
6075 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
6078 /* Try converting JAL to BAL and J(AL)R to B(AL), if the target is in
6080 if (!info
->relocatable
6081 && !cross_mode_jump_p
6082 && ((JAL_TO_BAL_P (input_bfd
)
6083 && r_type
== R_MIPS_26
6084 && (x
>> 26) == 0x3) /* jal addr */
6085 || (JALR_TO_BAL_P (input_bfd
)
6086 && r_type
== R_MIPS_JALR
6087 && x
== 0x0320f809) /* jalr t9 */
6088 || (JR_TO_B_P (input_bfd
)
6089 && r_type
== R_MIPS_JALR
6090 && x
== 0x03200008))) /* jr t9 */
6096 addr
= (input_section
->output_section
->vma
6097 + input_section
->output_offset
6098 + relocation
->r_offset
6100 if (r_type
== R_MIPS_26
)
6101 dest
= (value
<< 2) | ((addr
>> 28) << 28);
6105 if (off
<= 0x1ffff && off
>= -0x20000)
6107 if (x
== 0x03200008) /* jr t9 */
6108 x
= 0x10000000 | (((bfd_vma
) off
>> 2) & 0xffff); /* b addr */
6110 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
6114 /* Put the value into the output. */
6115 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
6117 _bfd_mips_elf_reloc_shuffle (input_bfd
, r_type
, !info
->relocatable
,
6123 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
6124 is the original relocation, which is now being transformed into a
6125 dynamic relocation. The ADDENDP is adjusted if necessary; the
6126 caller should store the result in place of the original addend. */
6129 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
6130 struct bfd_link_info
*info
,
6131 const Elf_Internal_Rela
*rel
,
6132 struct mips_elf_link_hash_entry
*h
,
6133 asection
*sec
, bfd_vma symbol
,
6134 bfd_vma
*addendp
, asection
*input_section
)
6136 Elf_Internal_Rela outrel
[3];
6141 bfd_boolean defined_p
;
6142 struct mips_elf_link_hash_table
*htab
;
6144 htab
= mips_elf_hash_table (info
);
6145 BFD_ASSERT (htab
!= NULL
);
6147 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
6148 dynobj
= elf_hash_table (info
)->dynobj
;
6149 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
6150 BFD_ASSERT (sreloc
!= NULL
);
6151 BFD_ASSERT (sreloc
->contents
!= NULL
);
6152 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
6155 outrel
[0].r_offset
=
6156 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
6157 if (ABI_64_P (output_bfd
))
6159 outrel
[1].r_offset
=
6160 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
6161 outrel
[2].r_offset
=
6162 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
6165 if (outrel
[0].r_offset
== MINUS_ONE
)
6166 /* The relocation field has been deleted. */
6169 if (outrel
[0].r_offset
== MINUS_TWO
)
6171 /* The relocation field has been converted into a relative value of
6172 some sort. Functions like _bfd_elf_write_section_eh_frame expect
6173 the field to be fully relocated, so add in the symbol's value. */
6178 /* We must now calculate the dynamic symbol table index to use
6179 in the relocation. */
6180 if (h
!= NULL
&& ! SYMBOL_REFERENCES_LOCAL (info
, &h
->root
))
6182 BFD_ASSERT (htab
->is_vxworks
|| h
->global_got_area
!= GGA_NONE
);
6183 indx
= h
->root
.dynindx
;
6184 if (SGI_COMPAT (output_bfd
))
6185 defined_p
= h
->root
.def_regular
;
6187 /* ??? glibc's ld.so just adds the final GOT entry to the
6188 relocation field. It therefore treats relocs against
6189 defined symbols in the same way as relocs against
6190 undefined symbols. */
6195 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
6197 else if (sec
== NULL
|| sec
->owner
== NULL
)
6199 bfd_set_error (bfd_error_bad_value
);
6204 indx
= elf_section_data (sec
->output_section
)->dynindx
;
6207 asection
*osec
= htab
->root
.text_index_section
;
6208 indx
= elf_section_data (osec
)->dynindx
;
6214 /* Instead of generating a relocation using the section
6215 symbol, we may as well make it a fully relative
6216 relocation. We want to avoid generating relocations to
6217 local symbols because we used to generate them
6218 incorrectly, without adding the original symbol value,
6219 which is mandated by the ABI for section symbols. In
6220 order to give dynamic loaders and applications time to
6221 phase out the incorrect use, we refrain from emitting
6222 section-relative relocations. It's not like they're
6223 useful, after all. This should be a bit more efficient
6225 /* ??? Although this behavior is compatible with glibc's ld.so,
6226 the ABI says that relocations against STN_UNDEF should have
6227 a symbol value of 0. Irix rld honors this, so relocations
6228 against STN_UNDEF have no effect. */
6229 if (!SGI_COMPAT (output_bfd
))
6234 /* If the relocation was previously an absolute relocation and
6235 this symbol will not be referred to by the relocation, we must
6236 adjust it by the value we give it in the dynamic symbol table.
6237 Otherwise leave the job up to the dynamic linker. */
6238 if (defined_p
&& r_type
!= R_MIPS_REL32
)
6241 if (htab
->is_vxworks
)
6242 /* VxWorks uses non-relative relocations for this. */
6243 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
6245 /* The relocation is always an REL32 relocation because we don't
6246 know where the shared library will wind up at load-time. */
6247 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
6250 /* For strict adherence to the ABI specification, we should
6251 generate a R_MIPS_64 relocation record by itself before the
6252 _REL32/_64 record as well, such that the addend is read in as
6253 a 64-bit value (REL32 is a 32-bit relocation, after all).
6254 However, since none of the existing ELF64 MIPS dynamic
6255 loaders seems to care, we don't waste space with these
6256 artificial relocations. If this turns out to not be true,
6257 mips_elf_allocate_dynamic_relocation() should be tweaked so
6258 as to make room for a pair of dynamic relocations per
6259 invocation if ABI_64_P, and here we should generate an
6260 additional relocation record with R_MIPS_64 by itself for a
6261 NULL symbol before this relocation record. */
6262 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
6263 ABI_64_P (output_bfd
)
6266 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
6268 /* Adjust the output offset of the relocation to reference the
6269 correct location in the output file. */
6270 outrel
[0].r_offset
+= (input_section
->output_section
->vma
6271 + input_section
->output_offset
);
6272 outrel
[1].r_offset
+= (input_section
->output_section
->vma
6273 + input_section
->output_offset
);
6274 outrel
[2].r_offset
+= (input_section
->output_section
->vma
6275 + input_section
->output_offset
);
6277 /* Put the relocation back out. We have to use the special
6278 relocation outputter in the 64-bit case since the 64-bit
6279 relocation format is non-standard. */
6280 if (ABI_64_P (output_bfd
))
6282 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
6283 (output_bfd
, &outrel
[0],
6285 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
6287 else if (htab
->is_vxworks
)
6289 /* VxWorks uses RELA rather than REL dynamic relocations. */
6290 outrel
[0].r_addend
= *addendp
;
6291 bfd_elf32_swap_reloca_out
6292 (output_bfd
, &outrel
[0],
6294 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
6297 bfd_elf32_swap_reloc_out
6298 (output_bfd
, &outrel
[0],
6299 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
6301 /* We've now added another relocation. */
6302 ++sreloc
->reloc_count
;
6304 /* Make sure the output section is writable. The dynamic linker
6305 will be writing to it. */
6306 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
6309 /* On IRIX5, make an entry of compact relocation info. */
6310 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
6312 asection
*scpt
= bfd_get_linker_section (dynobj
, ".compact_rel");
6317 Elf32_crinfo cptrel
;
6319 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
6320 cptrel
.vaddr
= (rel
->r_offset
6321 + input_section
->output_section
->vma
6322 + input_section
->output_offset
);
6323 if (r_type
== R_MIPS_REL32
)
6324 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
6326 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
6327 mips_elf_set_cr_dist2to (cptrel
, 0);
6328 cptrel
.konst
= *addendp
;
6330 cr
= (scpt
->contents
6331 + sizeof (Elf32_External_compact_rel
));
6332 mips_elf_set_cr_relvaddr (cptrel
, 0);
6333 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
6334 ((Elf32_External_crinfo
*) cr
6335 + scpt
->reloc_count
));
6336 ++scpt
->reloc_count
;
6340 /* If we've written this relocation for a readonly section,
6341 we need to set DF_TEXTREL again, so that we do not delete the
6343 if (MIPS_ELF_READONLY_SECTION (input_section
))
6344 info
->flags
|= DF_TEXTREL
;
6349 /* Return the MACH for a MIPS e_flags value. */
6352 _bfd_elf_mips_mach (flagword flags
)
6354 switch (flags
& EF_MIPS_MACH
)
6356 case E_MIPS_MACH_3900
:
6357 return bfd_mach_mips3900
;
6359 case E_MIPS_MACH_4010
:
6360 return bfd_mach_mips4010
;
6362 case E_MIPS_MACH_4100
:
6363 return bfd_mach_mips4100
;
6365 case E_MIPS_MACH_4111
:
6366 return bfd_mach_mips4111
;
6368 case E_MIPS_MACH_4120
:
6369 return bfd_mach_mips4120
;
6371 case E_MIPS_MACH_4650
:
6372 return bfd_mach_mips4650
;
6374 case E_MIPS_MACH_5400
:
6375 return bfd_mach_mips5400
;
6377 case E_MIPS_MACH_5500
:
6378 return bfd_mach_mips5500
;
6380 case E_MIPS_MACH_5900
:
6381 return bfd_mach_mips5900
;
6383 case E_MIPS_MACH_9000
:
6384 return bfd_mach_mips9000
;
6386 case E_MIPS_MACH_SB1
:
6387 return bfd_mach_mips_sb1
;
6389 case E_MIPS_MACH_LS2E
:
6390 return bfd_mach_mips_loongson_2e
;
6392 case E_MIPS_MACH_LS2F
:
6393 return bfd_mach_mips_loongson_2f
;
6395 case E_MIPS_MACH_LS3A
:
6396 return bfd_mach_mips_loongson_3a
;
6398 case E_MIPS_MACH_OCTEON2
:
6399 return bfd_mach_mips_octeon2
;
6401 case E_MIPS_MACH_OCTEON
:
6402 return bfd_mach_mips_octeon
;
6404 case E_MIPS_MACH_XLR
:
6405 return bfd_mach_mips_xlr
;
6408 switch (flags
& EF_MIPS_ARCH
)
6412 return bfd_mach_mips3000
;
6415 return bfd_mach_mips6000
;
6418 return bfd_mach_mips4000
;
6421 return bfd_mach_mips8000
;
6424 return bfd_mach_mips5
;
6426 case E_MIPS_ARCH_32
:
6427 return bfd_mach_mipsisa32
;
6429 case E_MIPS_ARCH_64
:
6430 return bfd_mach_mipsisa64
;
6432 case E_MIPS_ARCH_32R2
:
6433 return bfd_mach_mipsisa32r2
;
6435 case E_MIPS_ARCH_64R2
:
6436 return bfd_mach_mipsisa64r2
;
6443 /* Return printable name for ABI. */
6445 static INLINE
char *
6446 elf_mips_abi_name (bfd
*abfd
)
6450 flags
= elf_elfheader (abfd
)->e_flags
;
6451 switch (flags
& EF_MIPS_ABI
)
6454 if (ABI_N32_P (abfd
))
6456 else if (ABI_64_P (abfd
))
6460 case E_MIPS_ABI_O32
:
6462 case E_MIPS_ABI_O64
:
6464 case E_MIPS_ABI_EABI32
:
6466 case E_MIPS_ABI_EABI64
:
6469 return "unknown abi";
6473 /* MIPS ELF uses two common sections. One is the usual one, and the
6474 other is for small objects. All the small objects are kept
6475 together, and then referenced via the gp pointer, which yields
6476 faster assembler code. This is what we use for the small common
6477 section. This approach is copied from ecoff.c. */
6478 static asection mips_elf_scom_section
;
6479 static asymbol mips_elf_scom_symbol
;
6480 static asymbol
*mips_elf_scom_symbol_ptr
;
6482 /* MIPS ELF also uses an acommon section, which represents an
6483 allocated common symbol which may be overridden by a
6484 definition in a shared library. */
6485 static asection mips_elf_acom_section
;
6486 static asymbol mips_elf_acom_symbol
;
6487 static asymbol
*mips_elf_acom_symbol_ptr
;
6489 /* This is used for both the 32-bit and the 64-bit ABI. */
6492 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
6494 elf_symbol_type
*elfsym
;
6496 /* Handle the special MIPS section numbers that a symbol may use. */
6497 elfsym
= (elf_symbol_type
*) asym
;
6498 switch (elfsym
->internal_elf_sym
.st_shndx
)
6500 case SHN_MIPS_ACOMMON
:
6501 /* This section is used in a dynamically linked executable file.
6502 It is an allocated common section. The dynamic linker can
6503 either resolve these symbols to something in a shared
6504 library, or it can just leave them here. For our purposes,
6505 we can consider these symbols to be in a new section. */
6506 if (mips_elf_acom_section
.name
== NULL
)
6508 /* Initialize the acommon section. */
6509 mips_elf_acom_section
.name
= ".acommon";
6510 mips_elf_acom_section
.flags
= SEC_ALLOC
;
6511 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
6512 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
6513 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
6514 mips_elf_acom_symbol
.name
= ".acommon";
6515 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
6516 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
6517 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
6519 asym
->section
= &mips_elf_acom_section
;
6523 /* Common symbols less than the GP size are automatically
6524 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
6525 if (asym
->value
> elf_gp_size (abfd
)
6526 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
6527 || IRIX_COMPAT (abfd
) == ict_irix6
)
6530 case SHN_MIPS_SCOMMON
:
6531 if (mips_elf_scom_section
.name
== NULL
)
6533 /* Initialize the small common section. */
6534 mips_elf_scom_section
.name
= ".scommon";
6535 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
6536 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
6537 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
6538 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
6539 mips_elf_scom_symbol
.name
= ".scommon";
6540 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
6541 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
6542 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
6544 asym
->section
= &mips_elf_scom_section
;
6545 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6548 case SHN_MIPS_SUNDEFINED
:
6549 asym
->section
= bfd_und_section_ptr
;
6554 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
6556 if (section
!= NULL
)
6558 asym
->section
= section
;
6559 /* MIPS_TEXT is a bit special, the address is not an offset
6560 to the base of the .text section. So substract the section
6561 base address to make it an offset. */
6562 asym
->value
-= section
->vma
;
6569 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
6571 if (section
!= NULL
)
6573 asym
->section
= section
;
6574 /* MIPS_DATA is a bit special, the address is not an offset
6575 to the base of the .data section. So substract the section
6576 base address to make it an offset. */
6577 asym
->value
-= section
->vma
;
6583 /* If this is an odd-valued function symbol, assume it's a MIPS16
6584 or microMIPS one. */
6585 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
6586 && (asym
->value
& 1) != 0)
6589 if (MICROMIPS_P (abfd
))
6590 elfsym
->internal_elf_sym
.st_other
6591 = ELF_ST_SET_MICROMIPS (elfsym
->internal_elf_sym
.st_other
);
6593 elfsym
->internal_elf_sym
.st_other
6594 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
6598 /* Implement elf_backend_eh_frame_address_size. This differs from
6599 the default in the way it handles EABI64.
6601 EABI64 was originally specified as an LP64 ABI, and that is what
6602 -mabi=eabi normally gives on a 64-bit target. However, gcc has
6603 historically accepted the combination of -mabi=eabi and -mlong32,
6604 and this ILP32 variation has become semi-official over time.
6605 Both forms use elf32 and have pointer-sized FDE addresses.
6607 If an EABI object was generated by GCC 4.0 or above, it will have
6608 an empty .gcc_compiled_longXX section, where XX is the size of longs
6609 in bits. Unfortunately, ILP32 objects generated by earlier compilers
6610 have no special marking to distinguish them from LP64 objects.
6612 We don't want users of the official LP64 ABI to be punished for the
6613 existence of the ILP32 variant, but at the same time, we don't want
6614 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
6615 We therefore take the following approach:
6617 - If ABFD contains a .gcc_compiled_longXX section, use it to
6618 determine the pointer size.
6620 - Otherwise check the type of the first relocation. Assume that
6621 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
6625 The second check is enough to detect LP64 objects generated by pre-4.0
6626 compilers because, in the kind of output generated by those compilers,
6627 the first relocation will be associated with either a CIE personality
6628 routine or an FDE start address. Furthermore, the compilers never
6629 used a special (non-pointer) encoding for this ABI.
6631 Checking the relocation type should also be safe because there is no
6632 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
6636 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
6638 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
6640 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
6642 bfd_boolean long32_p
, long64_p
;
6644 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
6645 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
6646 if (long32_p
&& long64_p
)
6653 if (sec
->reloc_count
> 0
6654 && elf_section_data (sec
)->relocs
!= NULL
6655 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
6664 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
6665 relocations against two unnamed section symbols to resolve to the
6666 same address. For example, if we have code like:
6668 lw $4,%got_disp(.data)($gp)
6669 lw $25,%got_disp(.text)($gp)
6672 then the linker will resolve both relocations to .data and the program
6673 will jump there rather than to .text.
6675 We can work around this problem by giving names to local section symbols.
6676 This is also what the MIPSpro tools do. */
6679 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
6681 return SGI_COMPAT (abfd
);
6684 /* Work over a section just before writing it out. This routine is
6685 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
6686 sections that need the SHF_MIPS_GPREL flag by name; there has to be
6690 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
6692 if (hdr
->sh_type
== SHT_MIPS_REGINFO
6693 && hdr
->sh_size
> 0)
6697 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
6698 BFD_ASSERT (hdr
->contents
== NULL
);
6701 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
6704 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
6705 if (bfd_bwrite (buf
, 4, abfd
) != 4)
6709 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
6710 && hdr
->bfd_section
!= NULL
6711 && mips_elf_section_data (hdr
->bfd_section
) != NULL
6712 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
6714 bfd_byte
*contents
, *l
, *lend
;
6716 /* We stored the section contents in the tdata field in the
6717 set_section_contents routine. We save the section contents
6718 so that we don't have to read them again.
6719 At this point we know that elf_gp is set, so we can look
6720 through the section contents to see if there is an
6721 ODK_REGINFO structure. */
6723 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
6725 lend
= contents
+ hdr
->sh_size
;
6726 while (l
+ sizeof (Elf_External_Options
) <= lend
)
6728 Elf_Internal_Options intopt
;
6730 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
6732 if (intopt
.size
< sizeof (Elf_External_Options
))
6734 (*_bfd_error_handler
)
6735 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
6736 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6739 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6746 + sizeof (Elf_External_Options
)
6747 + (sizeof (Elf64_External_RegInfo
) - 8)),
6750 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
6751 if (bfd_bwrite (buf
, 8, abfd
) != 8)
6754 else if (intopt
.kind
== ODK_REGINFO
)
6761 + sizeof (Elf_External_Options
)
6762 + (sizeof (Elf32_External_RegInfo
) - 4)),
6765 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
6766 if (bfd_bwrite (buf
, 4, abfd
) != 4)
6773 if (hdr
->bfd_section
!= NULL
)
6775 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
6777 /* .sbss is not handled specially here because the GNU/Linux
6778 prelinker can convert .sbss from NOBITS to PROGBITS and
6779 changing it back to NOBITS breaks the binary. The entry in
6780 _bfd_mips_elf_special_sections will ensure the correct flags
6781 are set on .sbss if BFD creates it without reading it from an
6782 input file, and without special handling here the flags set
6783 on it in an input file will be followed. */
6784 if (strcmp (name
, ".sdata") == 0
6785 || strcmp (name
, ".lit8") == 0
6786 || strcmp (name
, ".lit4") == 0)
6788 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
6789 hdr
->sh_type
= SHT_PROGBITS
;
6791 else if (strcmp (name
, ".srdata") == 0)
6793 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
6794 hdr
->sh_type
= SHT_PROGBITS
;
6796 else if (strcmp (name
, ".compact_rel") == 0)
6799 hdr
->sh_type
= SHT_PROGBITS
;
6801 else if (strcmp (name
, ".rtproc") == 0)
6803 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
6805 unsigned int adjust
;
6807 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
6809 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
6817 /* Handle a MIPS specific section when reading an object file. This
6818 is called when elfcode.h finds a section with an unknown type.
6819 This routine supports both the 32-bit and 64-bit ELF ABI.
6821 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
6825 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
6826 Elf_Internal_Shdr
*hdr
,
6832 /* There ought to be a place to keep ELF backend specific flags, but
6833 at the moment there isn't one. We just keep track of the
6834 sections by their name, instead. Fortunately, the ABI gives
6835 suggested names for all the MIPS specific sections, so we will
6836 probably get away with this. */
6837 switch (hdr
->sh_type
)
6839 case SHT_MIPS_LIBLIST
:
6840 if (strcmp (name
, ".liblist") != 0)
6844 if (strcmp (name
, ".msym") != 0)
6847 case SHT_MIPS_CONFLICT
:
6848 if (strcmp (name
, ".conflict") != 0)
6851 case SHT_MIPS_GPTAB
:
6852 if (! CONST_STRNEQ (name
, ".gptab."))
6855 case SHT_MIPS_UCODE
:
6856 if (strcmp (name
, ".ucode") != 0)
6859 case SHT_MIPS_DEBUG
:
6860 if (strcmp (name
, ".mdebug") != 0)
6862 flags
= SEC_DEBUGGING
;
6864 case SHT_MIPS_REGINFO
:
6865 if (strcmp (name
, ".reginfo") != 0
6866 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
6868 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
6870 case SHT_MIPS_IFACE
:
6871 if (strcmp (name
, ".MIPS.interfaces") != 0)
6874 case SHT_MIPS_CONTENT
:
6875 if (! CONST_STRNEQ (name
, ".MIPS.content"))
6878 case SHT_MIPS_OPTIONS
:
6879 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6882 case SHT_MIPS_DWARF
:
6883 if (! CONST_STRNEQ (name
, ".debug_")
6884 && ! CONST_STRNEQ (name
, ".zdebug_"))
6887 case SHT_MIPS_SYMBOL_LIB
:
6888 if (strcmp (name
, ".MIPS.symlib") != 0)
6891 case SHT_MIPS_EVENTS
:
6892 if (! CONST_STRNEQ (name
, ".MIPS.events")
6893 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
6900 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6905 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
6906 (bfd_get_section_flags (abfd
,
6912 /* FIXME: We should record sh_info for a .gptab section. */
6914 /* For a .reginfo section, set the gp value in the tdata information
6915 from the contents of this section. We need the gp value while
6916 processing relocs, so we just get it now. The .reginfo section
6917 is not used in the 64-bit MIPS ELF ABI. */
6918 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
6920 Elf32_External_RegInfo ext
;
6923 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
6924 &ext
, 0, sizeof ext
))
6926 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
6927 elf_gp (abfd
) = s
.ri_gp_value
;
6930 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
6931 set the gp value based on what we find. We may see both
6932 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
6933 they should agree. */
6934 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
6936 bfd_byte
*contents
, *l
, *lend
;
6938 contents
= bfd_malloc (hdr
->sh_size
);
6939 if (contents
== NULL
)
6941 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
6948 lend
= contents
+ hdr
->sh_size
;
6949 while (l
+ sizeof (Elf_External_Options
) <= lend
)
6951 Elf_Internal_Options intopt
;
6953 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
6955 if (intopt
.size
< sizeof (Elf_External_Options
))
6957 (*_bfd_error_handler
)
6958 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
6959 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6962 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6964 Elf64_Internal_RegInfo intreg
;
6966 bfd_mips_elf64_swap_reginfo_in
6968 ((Elf64_External_RegInfo
*)
6969 (l
+ sizeof (Elf_External_Options
))),
6971 elf_gp (abfd
) = intreg
.ri_gp_value
;
6973 else if (intopt
.kind
== ODK_REGINFO
)
6975 Elf32_RegInfo intreg
;
6977 bfd_mips_elf32_swap_reginfo_in
6979 ((Elf32_External_RegInfo
*)
6980 (l
+ sizeof (Elf_External_Options
))),
6982 elf_gp (abfd
) = intreg
.ri_gp_value
;
6992 /* Set the correct type for a MIPS ELF section. We do this by the
6993 section name, which is a hack, but ought to work. This routine is
6994 used by both the 32-bit and the 64-bit ABI. */
6997 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
6999 const char *name
= bfd_get_section_name (abfd
, sec
);
7001 if (strcmp (name
, ".liblist") == 0)
7003 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
7004 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
7005 /* The sh_link field is set in final_write_processing. */
7007 else if (strcmp (name
, ".conflict") == 0)
7008 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
7009 else if (CONST_STRNEQ (name
, ".gptab."))
7011 hdr
->sh_type
= SHT_MIPS_GPTAB
;
7012 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
7013 /* The sh_info field is set in final_write_processing. */
7015 else if (strcmp (name
, ".ucode") == 0)
7016 hdr
->sh_type
= SHT_MIPS_UCODE
;
7017 else if (strcmp (name
, ".mdebug") == 0)
7019 hdr
->sh_type
= SHT_MIPS_DEBUG
;
7020 /* In a shared object on IRIX 5.3, the .mdebug section has an
7021 entsize of 0. FIXME: Does this matter? */
7022 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
7023 hdr
->sh_entsize
= 0;
7025 hdr
->sh_entsize
= 1;
7027 else if (strcmp (name
, ".reginfo") == 0)
7029 hdr
->sh_type
= SHT_MIPS_REGINFO
;
7030 /* In a shared object on IRIX 5.3, the .reginfo section has an
7031 entsize of 0x18. FIXME: Does this matter? */
7032 if (SGI_COMPAT (abfd
))
7034 if ((abfd
->flags
& DYNAMIC
) != 0)
7035 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
7037 hdr
->sh_entsize
= 1;
7040 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
7042 else if (SGI_COMPAT (abfd
)
7043 && (strcmp (name
, ".hash") == 0
7044 || strcmp (name
, ".dynamic") == 0
7045 || strcmp (name
, ".dynstr") == 0))
7047 if (SGI_COMPAT (abfd
))
7048 hdr
->sh_entsize
= 0;
7050 /* This isn't how the IRIX6 linker behaves. */
7051 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
7054 else if (strcmp (name
, ".got") == 0
7055 || strcmp (name
, ".srdata") == 0
7056 || strcmp (name
, ".sdata") == 0
7057 || strcmp (name
, ".sbss") == 0
7058 || strcmp (name
, ".lit4") == 0
7059 || strcmp (name
, ".lit8") == 0)
7060 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
7061 else if (strcmp (name
, ".MIPS.interfaces") == 0)
7063 hdr
->sh_type
= SHT_MIPS_IFACE
;
7064 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7066 else if (CONST_STRNEQ (name
, ".MIPS.content"))
7068 hdr
->sh_type
= SHT_MIPS_CONTENT
;
7069 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7070 /* The sh_info field is set in final_write_processing. */
7072 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
7074 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
7075 hdr
->sh_entsize
= 1;
7076 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7078 else if (CONST_STRNEQ (name
, ".debug_")
7079 || CONST_STRNEQ (name
, ".zdebug_"))
7081 hdr
->sh_type
= SHT_MIPS_DWARF
;
7083 /* Irix facilities such as libexc expect a single .debug_frame
7084 per executable, the system ones have NOSTRIP set and the linker
7085 doesn't merge sections with different flags so ... */
7086 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
7087 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7089 else if (strcmp (name
, ".MIPS.symlib") == 0)
7091 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
7092 /* The sh_link and sh_info fields are set in
7093 final_write_processing. */
7095 else if (CONST_STRNEQ (name
, ".MIPS.events")
7096 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
7098 hdr
->sh_type
= SHT_MIPS_EVENTS
;
7099 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
7100 /* The sh_link field is set in final_write_processing. */
7102 else if (strcmp (name
, ".msym") == 0)
7104 hdr
->sh_type
= SHT_MIPS_MSYM
;
7105 hdr
->sh_flags
|= SHF_ALLOC
;
7106 hdr
->sh_entsize
= 8;
7109 /* The generic elf_fake_sections will set up REL_HDR using the default
7110 kind of relocations. We used to set up a second header for the
7111 non-default kind of relocations here, but only NewABI would use
7112 these, and the IRIX ld doesn't like resulting empty RELA sections.
7113 Thus we create those header only on demand now. */
7118 /* Given a BFD section, try to locate the corresponding ELF section
7119 index. This is used by both the 32-bit and the 64-bit ABI.
7120 Actually, it's not clear to me that the 64-bit ABI supports these,
7121 but for non-PIC objects we will certainly want support for at least
7122 the .scommon section. */
7125 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
7126 asection
*sec
, int *retval
)
7128 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
7130 *retval
= SHN_MIPS_SCOMMON
;
7133 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
7135 *retval
= SHN_MIPS_ACOMMON
;
7141 /* Hook called by the linker routine which adds symbols from an object
7142 file. We must handle the special MIPS section numbers here. */
7145 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
7146 Elf_Internal_Sym
*sym
, const char **namep
,
7147 flagword
*flagsp ATTRIBUTE_UNUSED
,
7148 asection
**secp
, bfd_vma
*valp
)
7150 if (SGI_COMPAT (abfd
)
7151 && (abfd
->flags
& DYNAMIC
) != 0
7152 && strcmp (*namep
, "_rld_new_interface") == 0)
7154 /* Skip IRIX5 rld entry name. */
7159 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
7160 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
7161 by setting a DT_NEEDED for the shared object. Since _gp_disp is
7162 a magic symbol resolved by the linker, we ignore this bogus definition
7163 of _gp_disp. New ABI objects do not suffer from this problem so this
7164 is not done for them. */
7166 && (sym
->st_shndx
== SHN_ABS
)
7167 && (strcmp (*namep
, "_gp_disp") == 0))
7173 switch (sym
->st_shndx
)
7176 /* Common symbols less than the GP size are automatically
7177 treated as SHN_MIPS_SCOMMON symbols. */
7178 if (sym
->st_size
> elf_gp_size (abfd
)
7179 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
7180 || IRIX_COMPAT (abfd
) == ict_irix6
)
7183 case SHN_MIPS_SCOMMON
:
7184 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
7185 (*secp
)->flags
|= SEC_IS_COMMON
;
7186 *valp
= sym
->st_size
;
7190 /* This section is used in a shared object. */
7191 if (mips_elf_tdata (abfd
)->elf_text_section
== NULL
)
7193 asymbol
*elf_text_symbol
;
7194 asection
*elf_text_section
;
7195 bfd_size_type amt
= sizeof (asection
);
7197 elf_text_section
= bfd_zalloc (abfd
, amt
);
7198 if (elf_text_section
== NULL
)
7201 amt
= sizeof (asymbol
);
7202 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
7203 if (elf_text_symbol
== NULL
)
7206 /* Initialize the section. */
7208 mips_elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
7209 mips_elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
7211 elf_text_section
->symbol
= elf_text_symbol
;
7212 elf_text_section
->symbol_ptr_ptr
= &mips_elf_tdata (abfd
)->elf_text_symbol
;
7214 elf_text_section
->name
= ".text";
7215 elf_text_section
->flags
= SEC_NO_FLAGS
;
7216 elf_text_section
->output_section
= NULL
;
7217 elf_text_section
->owner
= abfd
;
7218 elf_text_symbol
->name
= ".text";
7219 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
7220 elf_text_symbol
->section
= elf_text_section
;
7222 /* This code used to do *secp = bfd_und_section_ptr if
7223 info->shared. I don't know why, and that doesn't make sense,
7224 so I took it out. */
7225 *secp
= mips_elf_tdata (abfd
)->elf_text_section
;
7228 case SHN_MIPS_ACOMMON
:
7229 /* Fall through. XXX Can we treat this as allocated data? */
7231 /* This section is used in a shared object. */
7232 if (mips_elf_tdata (abfd
)->elf_data_section
== NULL
)
7234 asymbol
*elf_data_symbol
;
7235 asection
*elf_data_section
;
7236 bfd_size_type amt
= sizeof (asection
);
7238 elf_data_section
= bfd_zalloc (abfd
, amt
);
7239 if (elf_data_section
== NULL
)
7242 amt
= sizeof (asymbol
);
7243 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
7244 if (elf_data_symbol
== NULL
)
7247 /* Initialize the section. */
7249 mips_elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
7250 mips_elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
7252 elf_data_section
->symbol
= elf_data_symbol
;
7253 elf_data_section
->symbol_ptr_ptr
= &mips_elf_tdata (abfd
)->elf_data_symbol
;
7255 elf_data_section
->name
= ".data";
7256 elf_data_section
->flags
= SEC_NO_FLAGS
;
7257 elf_data_section
->output_section
= NULL
;
7258 elf_data_section
->owner
= abfd
;
7259 elf_data_symbol
->name
= ".data";
7260 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
7261 elf_data_symbol
->section
= elf_data_section
;
7263 /* This code used to do *secp = bfd_und_section_ptr if
7264 info->shared. I don't know why, and that doesn't make sense,
7265 so I took it out. */
7266 *secp
= mips_elf_tdata (abfd
)->elf_data_section
;
7269 case SHN_MIPS_SUNDEFINED
:
7270 *secp
= bfd_und_section_ptr
;
7274 if (SGI_COMPAT (abfd
)
7276 && info
->output_bfd
->xvec
== abfd
->xvec
7277 && strcmp (*namep
, "__rld_obj_head") == 0)
7279 struct elf_link_hash_entry
*h
;
7280 struct bfd_link_hash_entry
*bh
;
7282 /* Mark __rld_obj_head as dynamic. */
7284 if (! (_bfd_generic_link_add_one_symbol
7285 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
7286 get_elf_backend_data (abfd
)->collect
, &bh
)))
7289 h
= (struct elf_link_hash_entry
*) bh
;
7292 h
->type
= STT_OBJECT
;
7294 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7297 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
7298 mips_elf_hash_table (info
)->rld_symbol
= h
;
7301 /* If this is a mips16 text symbol, add 1 to the value to make it
7302 odd. This will cause something like .word SYM to come up with
7303 the right value when it is loaded into the PC. */
7304 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
7310 /* This hook function is called before the linker writes out a global
7311 symbol. We mark symbols as small common if appropriate. This is
7312 also where we undo the increment of the value for a mips16 symbol. */
7315 _bfd_mips_elf_link_output_symbol_hook
7316 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7317 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
7318 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
7320 /* If we see a common symbol, which implies a relocatable link, then
7321 if a symbol was small common in an input file, mark it as small
7322 common in the output file. */
7323 if (sym
->st_shndx
== SHN_COMMON
7324 && strcmp (input_sec
->name
, ".scommon") == 0)
7325 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
7327 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
7328 sym
->st_value
&= ~1;
7333 /* Functions for the dynamic linker. */
7335 /* Create dynamic sections when linking against a dynamic object. */
7338 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
7340 struct elf_link_hash_entry
*h
;
7341 struct bfd_link_hash_entry
*bh
;
7343 register asection
*s
;
7344 const char * const *namep
;
7345 struct mips_elf_link_hash_table
*htab
;
7347 htab
= mips_elf_hash_table (info
);
7348 BFD_ASSERT (htab
!= NULL
);
7350 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7351 | SEC_LINKER_CREATED
| SEC_READONLY
);
7353 /* The psABI requires a read-only .dynamic section, but the VxWorks
7355 if (!htab
->is_vxworks
)
7357 s
= bfd_get_linker_section (abfd
, ".dynamic");
7360 if (! bfd_set_section_flags (abfd
, s
, flags
))
7365 /* We need to create .got section. */
7366 if (!mips_elf_create_got_section (abfd
, info
))
7369 if (! mips_elf_rel_dyn_section (info
, TRUE
))
7372 /* Create .stub section. */
7373 s
= bfd_make_section_anyway_with_flags (abfd
,
7374 MIPS_ELF_STUB_SECTION_NAME (abfd
),
7377 || ! bfd_set_section_alignment (abfd
, s
,
7378 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7382 if (!mips_elf_hash_table (info
)->use_rld_obj_head
7384 && bfd_get_linker_section (abfd
, ".rld_map") == NULL
)
7386 s
= bfd_make_section_anyway_with_flags (abfd
, ".rld_map",
7387 flags
&~ (flagword
) SEC_READONLY
);
7389 || ! bfd_set_section_alignment (abfd
, s
,
7390 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
7394 /* On IRIX5, we adjust add some additional symbols and change the
7395 alignments of several sections. There is no ABI documentation
7396 indicating that this is necessary on IRIX6, nor any evidence that
7397 the linker takes such action. */
7398 if (IRIX_COMPAT (abfd
) == ict_irix5
)
7400 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
7403 if (! (_bfd_generic_link_add_one_symbol
7404 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
7405 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
7408 h
= (struct elf_link_hash_entry
*) bh
;
7411 h
->type
= STT_SECTION
;
7413 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7417 /* We need to create a .compact_rel section. */
7418 if (SGI_COMPAT (abfd
))
7420 if (!mips_elf_create_compact_rel_section (abfd
, info
))
7424 /* Change alignments of some sections. */
7425 s
= bfd_get_linker_section (abfd
, ".hash");
7427 (void) bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7429 s
= bfd_get_linker_section (abfd
, ".dynsym");
7431 (void) bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7433 s
= bfd_get_linker_section (abfd
, ".dynstr");
7435 (void) bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7438 s
= bfd_get_section_by_name (abfd
, ".reginfo");
7440 (void) bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7442 s
= bfd_get_linker_section (abfd
, ".dynamic");
7444 (void) bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7451 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
7453 if (!(_bfd_generic_link_add_one_symbol
7454 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
7455 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
7458 h
= (struct elf_link_hash_entry
*) bh
;
7461 h
->type
= STT_SECTION
;
7463 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7466 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
7468 /* __rld_map is a four byte word located in the .data section
7469 and is filled in by the rtld to contain a pointer to
7470 the _r_debug structure. Its symbol value will be set in
7471 _bfd_mips_elf_finish_dynamic_symbol. */
7472 s
= bfd_get_linker_section (abfd
, ".rld_map");
7473 BFD_ASSERT (s
!= NULL
);
7475 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
7477 if (!(_bfd_generic_link_add_one_symbol
7478 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
7479 get_elf_backend_data (abfd
)->collect
, &bh
)))
7482 h
= (struct elf_link_hash_entry
*) bh
;
7485 h
->type
= STT_OBJECT
;
7487 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7489 mips_elf_hash_table (info
)->rld_symbol
= h
;
7493 /* Create the .plt, .rel(a).plt, .dynbss and .rel(a).bss sections.
7494 Also, on VxWorks, create the _PROCEDURE_LINKAGE_TABLE_ symbol. */
7495 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
7498 /* Cache the sections created above. */
7499 htab
->splt
= bfd_get_linker_section (abfd
, ".plt");
7500 htab
->sdynbss
= bfd_get_linker_section (abfd
, ".dynbss");
7501 if (htab
->is_vxworks
)
7503 htab
->srelbss
= bfd_get_linker_section (abfd
, ".rela.bss");
7504 htab
->srelplt
= bfd_get_linker_section (abfd
, ".rela.plt");
7507 htab
->srelplt
= bfd_get_linker_section (abfd
, ".rel.plt");
7509 || (htab
->is_vxworks
&& !htab
->srelbss
&& !info
->shared
)
7514 /* Do the usual VxWorks handling. */
7515 if (htab
->is_vxworks
7516 && !elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
7522 /* Return true if relocation REL against section SEC is a REL rather than
7523 RELA relocation. RELOCS is the first relocation in the section and
7524 ABFD is the bfd that contains SEC. */
7527 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
7528 const Elf_Internal_Rela
*relocs
,
7529 const Elf_Internal_Rela
*rel
)
7531 Elf_Internal_Shdr
*rel_hdr
;
7532 const struct elf_backend_data
*bed
;
7534 /* To determine which flavor of relocation this is, we depend on the
7535 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
7536 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
7537 if (rel_hdr
== NULL
)
7539 bed
= get_elf_backend_data (abfd
);
7540 return ((size_t) (rel
- relocs
)
7541 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
7544 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
7545 HOWTO is the relocation's howto and CONTENTS points to the contents
7546 of the section that REL is against. */
7549 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
7550 reloc_howto_type
*howto
, bfd_byte
*contents
)
7553 unsigned int r_type
;
7556 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7557 location
= contents
+ rel
->r_offset
;
7559 /* Get the addend, which is stored in the input file. */
7560 _bfd_mips_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
7561 addend
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
7562 _bfd_mips_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
7564 return addend
& howto
->src_mask
;
7567 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
7568 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
7569 and update *ADDEND with the final addend. Return true on success
7570 or false if the LO16 could not be found. RELEND is the exclusive
7571 upper bound on the relocations for REL's section. */
7574 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
7575 const Elf_Internal_Rela
*rel
,
7576 const Elf_Internal_Rela
*relend
,
7577 bfd_byte
*contents
, bfd_vma
*addend
)
7579 unsigned int r_type
, lo16_type
;
7580 const Elf_Internal_Rela
*lo16_relocation
;
7581 reloc_howto_type
*lo16_howto
;
7584 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7585 if (mips16_reloc_p (r_type
))
7586 lo16_type
= R_MIPS16_LO16
;
7587 else if (micromips_reloc_p (r_type
))
7588 lo16_type
= R_MICROMIPS_LO16
;
7590 lo16_type
= R_MIPS_LO16
;
7592 /* The combined value is the sum of the HI16 addend, left-shifted by
7593 sixteen bits, and the LO16 addend, sign extended. (Usually, the
7594 code does a `lui' of the HI16 value, and then an `addiu' of the
7597 Scan ahead to find a matching LO16 relocation.
7599 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
7600 be immediately following. However, for the IRIX6 ABI, the next
7601 relocation may be a composed relocation consisting of several
7602 relocations for the same address. In that case, the R_MIPS_LO16
7603 relocation may occur as one of these. We permit a similar
7604 extension in general, as that is useful for GCC.
7606 In some cases GCC dead code elimination removes the LO16 but keeps
7607 the corresponding HI16. This is strictly speaking a violation of
7608 the ABI but not immediately harmful. */
7609 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
7610 if (lo16_relocation
== NULL
)
7613 /* Obtain the addend kept there. */
7614 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
7615 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
7617 l
<<= lo16_howto
->rightshift
;
7618 l
= _bfd_mips_elf_sign_extend (l
, 16);
7625 /* Try to read the contents of section SEC in bfd ABFD. Return true and
7626 store the contents in *CONTENTS on success. Assume that *CONTENTS
7627 already holds the contents if it is nonull on entry. */
7630 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
7635 /* Get cached copy if it exists. */
7636 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
7638 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
7642 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
7645 /* Make a new PLT record to keep internal data. */
7647 static struct plt_entry
*
7648 mips_elf_make_plt_record (bfd
*abfd
)
7650 struct plt_entry
*entry
;
7652 entry
= bfd_zalloc (abfd
, sizeof (*entry
));
7656 entry
->stub_offset
= MINUS_ONE
;
7657 entry
->mips_offset
= MINUS_ONE
;
7658 entry
->comp_offset
= MINUS_ONE
;
7659 entry
->gotplt_index
= MINUS_ONE
;
7663 /* Look through the relocs for a section during the first phase, and
7664 allocate space in the global offset table and record the need for
7665 standard MIPS and compressed procedure linkage table entries. */
7668 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7669 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7673 Elf_Internal_Shdr
*symtab_hdr
;
7674 struct elf_link_hash_entry
**sym_hashes
;
7676 const Elf_Internal_Rela
*rel
;
7677 const Elf_Internal_Rela
*rel_end
;
7679 const struct elf_backend_data
*bed
;
7680 struct mips_elf_link_hash_table
*htab
;
7683 reloc_howto_type
*howto
;
7685 if (info
->relocatable
)
7688 htab
= mips_elf_hash_table (info
);
7689 BFD_ASSERT (htab
!= NULL
);
7691 dynobj
= elf_hash_table (info
)->dynobj
;
7692 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7693 sym_hashes
= elf_sym_hashes (abfd
);
7694 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7696 bed
= get_elf_backend_data (abfd
);
7697 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7699 /* Check for the mips16 stub sections. */
7701 name
= bfd_get_section_name (abfd
, sec
);
7702 if (FN_STUB_P (name
))
7704 unsigned long r_symndx
;
7706 /* Look at the relocation information to figure out which symbol
7709 r_symndx
= mips16_stub_symndx (bed
, sec
, relocs
, rel_end
);
7712 (*_bfd_error_handler
)
7713 (_("%B: Warning: cannot determine the target function for"
7714 " stub section `%s'"),
7716 bfd_set_error (bfd_error_bad_value
);
7720 if (r_symndx
< extsymoff
7721 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7725 /* This stub is for a local symbol. This stub will only be
7726 needed if there is some relocation in this BFD, other
7727 than a 16 bit function call, which refers to this symbol. */
7728 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7730 Elf_Internal_Rela
*sec_relocs
;
7731 const Elf_Internal_Rela
*r
, *rend
;
7733 /* We can ignore stub sections when looking for relocs. */
7734 if ((o
->flags
& SEC_RELOC
) == 0
7735 || o
->reloc_count
== 0
7736 || section_allows_mips16_refs_p (o
))
7740 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7742 if (sec_relocs
== NULL
)
7745 rend
= sec_relocs
+ o
->reloc_count
;
7746 for (r
= sec_relocs
; r
< rend
; r
++)
7747 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
7748 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
7751 if (elf_section_data (o
)->relocs
!= sec_relocs
)
7760 /* There is no non-call reloc for this stub, so we do
7761 not need it. Since this function is called before
7762 the linker maps input sections to output sections, we
7763 can easily discard it by setting the SEC_EXCLUDE
7765 sec
->flags
|= SEC_EXCLUDE
;
7769 /* Record this stub in an array of local symbol stubs for
7771 if (mips_elf_tdata (abfd
)->local_stubs
== NULL
)
7773 unsigned long symcount
;
7777 if (elf_bad_symtab (abfd
))
7778 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
7780 symcount
= symtab_hdr
->sh_info
;
7781 amt
= symcount
* sizeof (asection
*);
7782 n
= bfd_zalloc (abfd
, amt
);
7785 mips_elf_tdata (abfd
)->local_stubs
= n
;
7788 sec
->flags
|= SEC_KEEP
;
7789 mips_elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
7791 /* We don't need to set mips16_stubs_seen in this case.
7792 That flag is used to see whether we need to look through
7793 the global symbol table for stubs. We don't need to set
7794 it here, because we just have a local stub. */
7798 struct mips_elf_link_hash_entry
*h
;
7800 h
= ((struct mips_elf_link_hash_entry
*)
7801 sym_hashes
[r_symndx
- extsymoff
]);
7803 while (h
->root
.root
.type
== bfd_link_hash_indirect
7804 || h
->root
.root
.type
== bfd_link_hash_warning
)
7805 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7807 /* H is the symbol this stub is for. */
7809 /* If we already have an appropriate stub for this function, we
7810 don't need another one, so we can discard this one. Since
7811 this function is called before the linker maps input sections
7812 to output sections, we can easily discard it by setting the
7813 SEC_EXCLUDE flag. */
7814 if (h
->fn_stub
!= NULL
)
7816 sec
->flags
|= SEC_EXCLUDE
;
7820 sec
->flags
|= SEC_KEEP
;
7822 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
7825 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
7827 unsigned long r_symndx
;
7828 struct mips_elf_link_hash_entry
*h
;
7831 /* Look at the relocation information to figure out which symbol
7834 r_symndx
= mips16_stub_symndx (bed
, sec
, relocs
, rel_end
);
7837 (*_bfd_error_handler
)
7838 (_("%B: Warning: cannot determine the target function for"
7839 " stub section `%s'"),
7841 bfd_set_error (bfd_error_bad_value
);
7845 if (r_symndx
< extsymoff
7846 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7850 /* This stub is for a local symbol. This stub will only be
7851 needed if there is some relocation (R_MIPS16_26) in this BFD
7852 that refers to this symbol. */
7853 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7855 Elf_Internal_Rela
*sec_relocs
;
7856 const Elf_Internal_Rela
*r
, *rend
;
7858 /* We can ignore stub sections when looking for relocs. */
7859 if ((o
->flags
& SEC_RELOC
) == 0
7860 || o
->reloc_count
== 0
7861 || section_allows_mips16_refs_p (o
))
7865 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7867 if (sec_relocs
== NULL
)
7870 rend
= sec_relocs
+ o
->reloc_count
;
7871 for (r
= sec_relocs
; r
< rend
; r
++)
7872 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
7873 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
7876 if (elf_section_data (o
)->relocs
!= sec_relocs
)
7885 /* There is no non-call reloc for this stub, so we do
7886 not need it. Since this function is called before
7887 the linker maps input sections to output sections, we
7888 can easily discard it by setting the SEC_EXCLUDE
7890 sec
->flags
|= SEC_EXCLUDE
;
7894 /* Record this stub in an array of local symbol call_stubs for
7896 if (mips_elf_tdata (abfd
)->local_call_stubs
== NULL
)
7898 unsigned long symcount
;
7902 if (elf_bad_symtab (abfd
))
7903 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
7905 symcount
= symtab_hdr
->sh_info
;
7906 amt
= symcount
* sizeof (asection
*);
7907 n
= bfd_zalloc (abfd
, amt
);
7910 mips_elf_tdata (abfd
)->local_call_stubs
= n
;
7913 sec
->flags
|= SEC_KEEP
;
7914 mips_elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
7916 /* We don't need to set mips16_stubs_seen in this case.
7917 That flag is used to see whether we need to look through
7918 the global symbol table for stubs. We don't need to set
7919 it here, because we just have a local stub. */
7923 h
= ((struct mips_elf_link_hash_entry
*)
7924 sym_hashes
[r_symndx
- extsymoff
]);
7926 /* H is the symbol this stub is for. */
7928 if (CALL_FP_STUB_P (name
))
7929 loc
= &h
->call_fp_stub
;
7931 loc
= &h
->call_stub
;
7933 /* If we already have an appropriate stub for this function, we
7934 don't need another one, so we can discard this one. Since
7935 this function is called before the linker maps input sections
7936 to output sections, we can easily discard it by setting the
7937 SEC_EXCLUDE flag. */
7940 sec
->flags
|= SEC_EXCLUDE
;
7944 sec
->flags
|= SEC_KEEP
;
7946 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
7952 for (rel
= relocs
; rel
< rel_end
; ++rel
)
7954 unsigned long r_symndx
;
7955 unsigned int r_type
;
7956 struct elf_link_hash_entry
*h
;
7957 bfd_boolean can_make_dynamic_p
;
7959 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
7960 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7962 if (r_symndx
< extsymoff
)
7964 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
7966 (*_bfd_error_handler
)
7967 (_("%B: Malformed reloc detected for section %s"),
7969 bfd_set_error (bfd_error_bad_value
);
7974 h
= sym_hashes
[r_symndx
- extsymoff
];
7977 while (h
->root
.type
== bfd_link_hash_indirect
7978 || h
->root
.type
== bfd_link_hash_warning
)
7979 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7981 /* PR15323, ref flags aren't set for references in the
7983 h
->root
.non_ir_ref
= 1;
7987 /* Set CAN_MAKE_DYNAMIC_P to true if we can convert this
7988 relocation into a dynamic one. */
7989 can_make_dynamic_p
= FALSE
;
7994 case R_MIPS_CALL_HI16
:
7995 case R_MIPS_CALL_LO16
:
7996 case R_MIPS_GOT_HI16
:
7997 case R_MIPS_GOT_LO16
:
7998 case R_MIPS_GOT_PAGE
:
7999 case R_MIPS_GOT_OFST
:
8000 case R_MIPS_GOT_DISP
:
8001 case R_MIPS_TLS_GOTTPREL
:
8003 case R_MIPS_TLS_LDM
:
8004 case R_MIPS16_GOT16
:
8005 case R_MIPS16_CALL16
:
8006 case R_MIPS16_TLS_GOTTPREL
:
8007 case R_MIPS16_TLS_GD
:
8008 case R_MIPS16_TLS_LDM
:
8009 case R_MICROMIPS_GOT16
:
8010 case R_MICROMIPS_CALL16
:
8011 case R_MICROMIPS_CALL_HI16
:
8012 case R_MICROMIPS_CALL_LO16
:
8013 case R_MICROMIPS_GOT_HI16
:
8014 case R_MICROMIPS_GOT_LO16
:
8015 case R_MICROMIPS_GOT_PAGE
:
8016 case R_MICROMIPS_GOT_OFST
:
8017 case R_MICROMIPS_GOT_DISP
:
8018 case R_MICROMIPS_TLS_GOTTPREL
:
8019 case R_MICROMIPS_TLS_GD
:
8020 case R_MICROMIPS_TLS_LDM
:
8022 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
8023 if (!mips_elf_create_got_section (dynobj
, info
))
8025 if (htab
->is_vxworks
&& !info
->shared
)
8027 (*_bfd_error_handler
)
8028 (_("%B: GOT reloc at 0x%lx not expected in executables"),
8029 abfd
, (unsigned long) rel
->r_offset
);
8030 bfd_set_error (bfd_error_bad_value
);
8035 /* This is just a hint; it can safely be ignored. Don't set
8036 has_static_relocs for the corresponding symbol. */
8038 case R_MICROMIPS_JALR
:
8044 /* In VxWorks executables, references to external symbols
8045 must be handled using copy relocs or PLT entries; it is not
8046 possible to convert this relocation into a dynamic one.
8048 For executables that use PLTs and copy-relocs, we have a
8049 choice between converting the relocation into a dynamic
8050 one or using copy relocations or PLT entries. It is
8051 usually better to do the former, unless the relocation is
8052 against a read-only section. */
8055 && !htab
->is_vxworks
8056 && strcmp (h
->root
.root
.string
, "__gnu_local_gp") != 0
8057 && !(!info
->nocopyreloc
8058 && !PIC_OBJECT_P (abfd
)
8059 && MIPS_ELF_READONLY_SECTION (sec
))))
8060 && (sec
->flags
& SEC_ALLOC
) != 0)
8062 can_make_dynamic_p
= TRUE
;
8064 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
8067 /* For sections that are not SEC_ALLOC a copy reloc would be
8068 output if possible (implying questionable semantics for
8069 read-only data objects) or otherwise the final link would
8070 fail as ld.so will not process them and could not therefore
8071 handle any outstanding dynamic relocations.
8073 For such sections that are also SEC_DEBUGGING, we can avoid
8074 these problems by simply ignoring any relocs as these
8075 sections have a predefined use and we know it is safe to do
8078 This is needed in cases such as a global symbol definition
8079 in a shared library causing a common symbol from an object
8080 file to be converted to an undefined reference. If that
8081 happens, then all the relocations against this symbol from
8082 SEC_DEBUGGING sections in the object file will resolve to
8084 if ((sec
->flags
& SEC_DEBUGGING
) != 0)
8089 /* Most static relocations require pointer equality, except
8092 h
->pointer_equality_needed
= TRUE
;
8098 case R_MICROMIPS_26_S1
:
8099 case R_MICROMIPS_PC7_S1
:
8100 case R_MICROMIPS_PC10_S1
:
8101 case R_MICROMIPS_PC16_S1
:
8102 case R_MICROMIPS_PC23_S2
:
8104 ((struct mips_elf_link_hash_entry
*) h
)->has_static_relocs
= TRUE
;
8110 /* Relocations against the special VxWorks __GOTT_BASE__ and
8111 __GOTT_INDEX__ symbols must be left to the loader. Allocate
8112 room for them in .rela.dyn. */
8113 if (is_gott_symbol (info
, h
))
8117 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
8121 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
8122 if (MIPS_ELF_READONLY_SECTION (sec
))
8123 /* We tell the dynamic linker that there are
8124 relocations against the text segment. */
8125 info
->flags
|= DF_TEXTREL
;
8128 else if (call_lo16_reloc_p (r_type
)
8129 || got_lo16_reloc_p (r_type
)
8130 || got_disp_reloc_p (r_type
)
8131 || (got16_reloc_p (r_type
) && htab
->is_vxworks
))
8133 /* We may need a local GOT entry for this relocation. We
8134 don't count R_MIPS_GOT_PAGE because we can estimate the
8135 maximum number of pages needed by looking at the size of
8136 the segment. Similar comments apply to R_MIPS*_GOT16 and
8137 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
8138 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
8139 R_MIPS_CALL_HI16 because these are always followed by an
8140 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
8141 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
8142 rel
->r_addend
, info
, r_type
))
8147 && mips_elf_relocation_needs_la25_stub (abfd
, r_type
,
8148 ELF_ST_IS_MIPS16 (h
->other
)))
8149 ((struct mips_elf_link_hash_entry
*) h
)->has_nonpic_branches
= TRUE
;
8154 case R_MIPS16_CALL16
:
8155 case R_MICROMIPS_CALL16
:
8158 (*_bfd_error_handler
)
8159 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
8160 abfd
, (unsigned long) rel
->r_offset
);
8161 bfd_set_error (bfd_error_bad_value
);
8166 case R_MIPS_CALL_HI16
:
8167 case R_MIPS_CALL_LO16
:
8168 case R_MICROMIPS_CALL_HI16
:
8169 case R_MICROMIPS_CALL_LO16
:
8172 /* Make sure there is room in the regular GOT to hold the
8173 function's address. We may eliminate it in favour of
8174 a .got.plt entry later; see mips_elf_count_got_symbols. */
8175 if (!mips_elf_record_global_got_symbol (h
, abfd
, info
, TRUE
,
8179 /* We need a stub, not a plt entry for the undefined
8180 function. But we record it as if it needs plt. See
8181 _bfd_elf_adjust_dynamic_symbol. */
8187 case R_MIPS_GOT_PAGE
:
8188 case R_MICROMIPS_GOT_PAGE
:
8189 case R_MIPS16_GOT16
:
8191 case R_MIPS_GOT_HI16
:
8192 case R_MIPS_GOT_LO16
:
8193 case R_MICROMIPS_GOT16
:
8194 case R_MICROMIPS_GOT_HI16
:
8195 case R_MICROMIPS_GOT_LO16
:
8196 if (!h
|| got_page_reloc_p (r_type
))
8198 /* This relocation needs (or may need, if h != NULL) a
8199 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
8200 know for sure until we know whether the symbol is
8202 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
8204 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
8206 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
8207 addend
= mips_elf_read_rel_addend (abfd
, rel
,
8209 if (got16_reloc_p (r_type
))
8210 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
8213 addend
<<= howto
->rightshift
;
8216 addend
= rel
->r_addend
;
8217 if (!mips_elf_record_got_page_ref (info
, abfd
, r_symndx
,
8223 struct mips_elf_link_hash_entry
*hmips
=
8224 (struct mips_elf_link_hash_entry
*) h
;
8226 /* This symbol is definitely not overridable. */
8227 if (hmips
->root
.def_regular
8228 && ! (info
->shared
&& ! info
->symbolic
8229 && ! hmips
->root
.forced_local
))
8233 /* If this is a global, overridable symbol, GOT_PAGE will
8234 decay to GOT_DISP, so we'll need a GOT entry for it. */
8237 case R_MIPS_GOT_DISP
:
8238 case R_MICROMIPS_GOT_DISP
:
8239 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
,
8244 case R_MIPS_TLS_GOTTPREL
:
8245 case R_MIPS16_TLS_GOTTPREL
:
8246 case R_MICROMIPS_TLS_GOTTPREL
:
8248 info
->flags
|= DF_STATIC_TLS
;
8251 case R_MIPS_TLS_LDM
:
8252 case R_MIPS16_TLS_LDM
:
8253 case R_MICROMIPS_TLS_LDM
:
8254 if (tls_ldm_reloc_p (r_type
))
8256 r_symndx
= STN_UNDEF
;
8262 case R_MIPS16_TLS_GD
:
8263 case R_MICROMIPS_TLS_GD
:
8264 /* This symbol requires a global offset table entry, or two
8265 for TLS GD relocations. */
8268 if (!mips_elf_record_global_got_symbol (h
, abfd
, info
,
8274 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
8284 /* In VxWorks executables, references to external symbols
8285 are handled using copy relocs or PLT stubs, so there's
8286 no need to add a .rela.dyn entry for this relocation. */
8287 if (can_make_dynamic_p
)
8291 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
8295 if (info
->shared
&& h
== NULL
)
8297 /* When creating a shared object, we must copy these
8298 reloc types into the output file as R_MIPS_REL32
8299 relocs. Make room for this reloc in .rel(a).dyn. */
8300 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
8301 if (MIPS_ELF_READONLY_SECTION (sec
))
8302 /* We tell the dynamic linker that there are
8303 relocations against the text segment. */
8304 info
->flags
|= DF_TEXTREL
;
8308 struct mips_elf_link_hash_entry
*hmips
;
8310 /* For a shared object, we must copy this relocation
8311 unless the symbol turns out to be undefined and
8312 weak with non-default visibility, in which case
8313 it will be left as zero.
8315 We could elide R_MIPS_REL32 for locally binding symbols
8316 in shared libraries, but do not yet do so.
8318 For an executable, we only need to copy this
8319 reloc if the symbol is defined in a dynamic
8321 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8322 ++hmips
->possibly_dynamic_relocs
;
8323 if (MIPS_ELF_READONLY_SECTION (sec
))
8324 /* We need it to tell the dynamic linker if there
8325 are relocations against the text segment. */
8326 hmips
->readonly_reloc
= TRUE
;
8330 if (SGI_COMPAT (abfd
))
8331 mips_elf_hash_table (info
)->compact_rel_size
+=
8332 sizeof (Elf32_External_crinfo
);
8336 case R_MIPS_GPREL16
:
8337 case R_MIPS_LITERAL
:
8338 case R_MIPS_GPREL32
:
8339 case R_MICROMIPS_26_S1
:
8340 case R_MICROMIPS_GPREL16
:
8341 case R_MICROMIPS_LITERAL
:
8342 case R_MICROMIPS_GPREL7_S2
:
8343 if (SGI_COMPAT (abfd
))
8344 mips_elf_hash_table (info
)->compact_rel_size
+=
8345 sizeof (Elf32_External_crinfo
);
8348 /* This relocation describes the C++ object vtable hierarchy.
8349 Reconstruct it for later use during GC. */
8350 case R_MIPS_GNU_VTINHERIT
:
8351 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
8355 /* This relocation describes which C++ vtable entries are actually
8356 used. Record for later use during GC. */
8357 case R_MIPS_GNU_VTENTRY
:
8358 BFD_ASSERT (h
!= NULL
);
8360 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
8368 /* Record the need for a PLT entry. At this point we don't know
8369 yet if we are going to create a PLT in the first place, but
8370 we only record whether the relocation requires a standard MIPS
8371 or a compressed code entry anyway. If we don't make a PLT after
8372 all, then we'll just ignore these arrangements. Likewise if
8373 a PLT entry is not created because the symbol is satisfied
8376 && jal_reloc_p (r_type
)
8377 && !SYMBOL_CALLS_LOCAL (info
, h
))
8379 if (h
->plt
.plist
== NULL
)
8380 h
->plt
.plist
= mips_elf_make_plt_record (abfd
);
8381 if (h
->plt
.plist
== NULL
)
8384 if (r_type
== R_MIPS_26
)
8385 h
->plt
.plist
->need_mips
= TRUE
;
8387 h
->plt
.plist
->need_comp
= TRUE
;
8390 /* We must not create a stub for a symbol that has relocations
8391 related to taking the function's address. This doesn't apply to
8392 VxWorks, where CALL relocs refer to a .got.plt entry instead of
8393 a normal .got entry. */
8394 if (!htab
->is_vxworks
&& h
!= NULL
)
8398 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
8400 case R_MIPS16_CALL16
:
8402 case R_MIPS_CALL_HI16
:
8403 case R_MIPS_CALL_LO16
:
8405 case R_MICROMIPS_CALL16
:
8406 case R_MICROMIPS_CALL_HI16
:
8407 case R_MICROMIPS_CALL_LO16
:
8408 case R_MICROMIPS_JALR
:
8412 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
8413 if there is one. We only need to handle global symbols here;
8414 we decide whether to keep or delete stubs for local symbols
8415 when processing the stub's relocations. */
8417 && !mips16_call_reloc_p (r_type
)
8418 && !section_allows_mips16_refs_p (sec
))
8420 struct mips_elf_link_hash_entry
*mh
;
8422 mh
= (struct mips_elf_link_hash_entry
*) h
;
8423 mh
->need_fn_stub
= TRUE
;
8426 /* Refuse some position-dependent relocations when creating a
8427 shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
8428 not PIC, but we can create dynamic relocations and the result
8429 will be fine. Also do not refuse R_MIPS_LO16, which can be
8430 combined with R_MIPS_GOT16. */
8438 case R_MIPS_HIGHEST
:
8439 case R_MICROMIPS_HI16
:
8440 case R_MICROMIPS_HIGHER
:
8441 case R_MICROMIPS_HIGHEST
:
8442 /* Don't refuse a high part relocation if it's against
8443 no symbol (e.g. part of a compound relocation). */
8444 if (r_symndx
== STN_UNDEF
)
8447 /* R_MIPS_HI16 against _gp_disp is used for $gp setup,
8448 and has a special meaning. */
8449 if (!NEWABI_P (abfd
) && h
!= NULL
8450 && strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
8453 /* Likewise __GOTT_BASE__ and __GOTT_INDEX__ on VxWorks. */
8454 if (is_gott_symbol (info
, h
))
8461 case R_MICROMIPS_26_S1
:
8462 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
8463 (*_bfd_error_handler
)
8464 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
8466 (h
) ? h
->root
.root
.string
: "a local symbol");
8467 bfd_set_error (bfd_error_bad_value
);
8479 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
8480 struct bfd_link_info
*link_info
,
8483 Elf_Internal_Rela
*internal_relocs
;
8484 Elf_Internal_Rela
*irel
, *irelend
;
8485 Elf_Internal_Shdr
*symtab_hdr
;
8486 bfd_byte
*contents
= NULL
;
8488 bfd_boolean changed_contents
= FALSE
;
8489 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
8490 Elf_Internal_Sym
*isymbuf
= NULL
;
8492 /* We are not currently changing any sizes, so only one pass. */
8495 if (link_info
->relocatable
)
8498 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
8499 link_info
->keep_memory
);
8500 if (internal_relocs
== NULL
)
8503 irelend
= internal_relocs
+ sec
->reloc_count
8504 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
8505 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8506 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
8508 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
8511 bfd_signed_vma sym_offset
;
8512 unsigned int r_type
;
8513 unsigned long r_symndx
;
8515 unsigned long instruction
;
8517 /* Turn jalr into bgezal, and jr into beq, if they're marked
8518 with a JALR relocation, that indicate where they jump to.
8519 This saves some pipeline bubbles. */
8520 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
8521 if (r_type
!= R_MIPS_JALR
)
8524 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
8525 /* Compute the address of the jump target. */
8526 if (r_symndx
>= extsymoff
)
8528 struct mips_elf_link_hash_entry
*h
8529 = ((struct mips_elf_link_hash_entry
*)
8530 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
8532 while (h
->root
.root
.type
== bfd_link_hash_indirect
8533 || h
->root
.root
.type
== bfd_link_hash_warning
)
8534 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
8536 /* If a symbol is undefined, or if it may be overridden,
8538 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
8539 || h
->root
.root
.type
== bfd_link_hash_defweak
)
8540 && h
->root
.root
.u
.def
.section
)
8541 || (link_info
->shared
&& ! link_info
->symbolic
8542 && !h
->root
.forced_local
))
8545 sym_sec
= h
->root
.root
.u
.def
.section
;
8546 if (sym_sec
->output_section
)
8547 symval
= (h
->root
.root
.u
.def
.value
8548 + sym_sec
->output_section
->vma
8549 + sym_sec
->output_offset
);
8551 symval
= h
->root
.root
.u
.def
.value
;
8555 Elf_Internal_Sym
*isym
;
8557 /* Read this BFD's symbols if we haven't done so already. */
8558 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
8560 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
8561 if (isymbuf
== NULL
)
8562 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
8563 symtab_hdr
->sh_info
, 0,
8565 if (isymbuf
== NULL
)
8569 isym
= isymbuf
+ r_symndx
;
8570 if (isym
->st_shndx
== SHN_UNDEF
)
8572 else if (isym
->st_shndx
== SHN_ABS
)
8573 sym_sec
= bfd_abs_section_ptr
;
8574 else if (isym
->st_shndx
== SHN_COMMON
)
8575 sym_sec
= bfd_com_section_ptr
;
8578 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
8579 symval
= isym
->st_value
8580 + sym_sec
->output_section
->vma
8581 + sym_sec
->output_offset
;
8584 /* Compute branch offset, from delay slot of the jump to the
8586 sym_offset
= (symval
+ irel
->r_addend
)
8587 - (sec_start
+ irel
->r_offset
+ 4);
8589 /* Branch offset must be properly aligned. */
8590 if ((sym_offset
& 3) != 0)
8595 /* Check that it's in range. */
8596 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
8599 /* Get the section contents if we haven't done so already. */
8600 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
8603 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
8605 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
8606 if ((instruction
& 0xfc1fffff) == 0x0000f809)
8607 instruction
= 0x04110000;
8608 /* If it was jr <reg>, turn it into b <target>. */
8609 else if ((instruction
& 0xfc1fffff) == 0x00000008)
8610 instruction
= 0x10000000;
8614 instruction
|= (sym_offset
& 0xffff);
8615 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
8616 changed_contents
= TRUE
;
8619 if (contents
!= NULL
8620 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8622 if (!changed_contents
&& !link_info
->keep_memory
)
8626 /* Cache the section contents for elf_link_input_bfd. */
8627 elf_section_data (sec
)->this_hdr
.contents
= contents
;
8633 if (contents
!= NULL
8634 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8639 /* Allocate space for global sym dynamic relocs. */
8642 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8644 struct bfd_link_info
*info
= inf
;
8646 struct mips_elf_link_hash_entry
*hmips
;
8647 struct mips_elf_link_hash_table
*htab
;
8649 htab
= mips_elf_hash_table (info
);
8650 BFD_ASSERT (htab
!= NULL
);
8652 dynobj
= elf_hash_table (info
)->dynobj
;
8653 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8655 /* VxWorks executables are handled elsewhere; we only need to
8656 allocate relocations in shared objects. */
8657 if (htab
->is_vxworks
&& !info
->shared
)
8660 /* Ignore indirect symbols. All relocations against such symbols
8661 will be redirected to the target symbol. */
8662 if (h
->root
.type
== bfd_link_hash_indirect
)
8665 /* If this symbol is defined in a dynamic object, or we are creating
8666 a shared library, we will need to copy any R_MIPS_32 or
8667 R_MIPS_REL32 relocs against it into the output file. */
8668 if (! info
->relocatable
8669 && hmips
->possibly_dynamic_relocs
!= 0
8670 && (h
->root
.type
== bfd_link_hash_defweak
8671 || (!h
->def_regular
&& !ELF_COMMON_DEF_P (h
))
8674 bfd_boolean do_copy
= TRUE
;
8676 if (h
->root
.type
== bfd_link_hash_undefweak
)
8678 /* Do not copy relocations for undefined weak symbols with
8679 non-default visibility. */
8680 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8683 /* Make sure undefined weak symbols are output as a dynamic
8685 else if (h
->dynindx
== -1 && !h
->forced_local
)
8687 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8694 /* Even though we don't directly need a GOT entry for this symbol,
8695 the SVR4 psABI requires it to have a dynamic symbol table
8696 index greater that DT_MIPS_GOTSYM if there are dynamic
8697 relocations against it.
8699 VxWorks does not enforce the same mapping between the GOT
8700 and the symbol table, so the same requirement does not
8702 if (!htab
->is_vxworks
)
8704 if (hmips
->global_got_area
> GGA_RELOC_ONLY
)
8705 hmips
->global_got_area
= GGA_RELOC_ONLY
;
8706 hmips
->got_only_for_calls
= FALSE
;
8709 mips_elf_allocate_dynamic_relocations
8710 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
8711 if (hmips
->readonly_reloc
)
8712 /* We tell the dynamic linker that there are relocations
8713 against the text segment. */
8714 info
->flags
|= DF_TEXTREL
;
8721 /* Adjust a symbol defined by a dynamic object and referenced by a
8722 regular object. The current definition is in some section of the
8723 dynamic object, but we're not including those sections. We have to
8724 change the definition to something the rest of the link can
8728 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
8729 struct elf_link_hash_entry
*h
)
8732 struct mips_elf_link_hash_entry
*hmips
;
8733 struct mips_elf_link_hash_table
*htab
;
8735 htab
= mips_elf_hash_table (info
);
8736 BFD_ASSERT (htab
!= NULL
);
8738 dynobj
= elf_hash_table (info
)->dynobj
;
8739 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8741 /* Make sure we know what is going on here. */
8742 BFD_ASSERT (dynobj
!= NULL
8744 || h
->u
.weakdef
!= NULL
8747 && !h
->def_regular
)));
8749 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8751 /* If there are call relocations against an externally-defined symbol,
8752 see whether we can create a MIPS lazy-binding stub for it. We can
8753 only do this if all references to the function are through call
8754 relocations, and in that case, the traditional lazy-binding stubs
8755 are much more efficient than PLT entries.
8757 Traditional stubs are only available on SVR4 psABI-based systems;
8758 VxWorks always uses PLTs instead. */
8759 if (!htab
->is_vxworks
&& h
->needs_plt
&& !hmips
->no_fn_stub
)
8761 if (! elf_hash_table (info
)->dynamic_sections_created
)
8764 /* If this symbol is not defined in a regular file, then set
8765 the symbol to the stub location. This is required to make
8766 function pointers compare as equal between the normal
8767 executable and the shared library. */
8768 if (!h
->def_regular
)
8770 hmips
->needs_lazy_stub
= TRUE
;
8771 htab
->lazy_stub_count
++;
8775 /* As above, VxWorks requires PLT entries for externally-defined
8776 functions that are only accessed through call relocations.
8778 Both VxWorks and non-VxWorks targets also need PLT entries if there
8779 are static-only relocations against an externally-defined function.
8780 This can technically occur for shared libraries if there are
8781 branches to the symbol, although it is unlikely that this will be
8782 used in practice due to the short ranges involved. It can occur
8783 for any relative or absolute relocation in executables; in that
8784 case, the PLT entry becomes the function's canonical address. */
8785 else if (((h
->needs_plt
&& !hmips
->no_fn_stub
)
8786 || (h
->type
== STT_FUNC
&& hmips
->has_static_relocs
))
8787 && htab
->use_plts_and_copy_relocs
8788 && !SYMBOL_CALLS_LOCAL (info
, h
)
8789 && !(ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
8790 && h
->root
.type
== bfd_link_hash_undefweak
))
8792 bfd_boolean micromips_p
= MICROMIPS_P (info
->output_bfd
);
8793 bfd_boolean newabi_p
= NEWABI_P (info
->output_bfd
);
8795 /* If this is the first symbol to need a PLT entry, then make some
8796 basic setup. Also work out PLT entry sizes. We'll need them
8797 for PLT offset calculations. */
8798 if (htab
->plt_mips_offset
+ htab
->plt_comp_offset
== 0)
8800 BFD_ASSERT (htab
->sgotplt
->size
== 0);
8801 BFD_ASSERT (htab
->plt_got_index
== 0);
8803 /* If we're using the PLT additions to the psABI, each PLT
8804 entry is 16 bytes and the PLT0 entry is 32 bytes.
8805 Encourage better cache usage by aligning. We do this
8806 lazily to avoid pessimizing traditional objects. */
8807 if (!htab
->is_vxworks
8808 && !bfd_set_section_alignment (dynobj
, htab
->splt
, 5))
8811 /* Make sure that .got.plt is word-aligned. We do this lazily
8812 for the same reason as above. */
8813 if (!bfd_set_section_alignment (dynobj
, htab
->sgotplt
,
8814 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
8817 /* On non-VxWorks targets, the first two entries in .got.plt
8819 if (!htab
->is_vxworks
)
8821 += (get_elf_backend_data (dynobj
)->got_header_size
8822 / MIPS_ELF_GOT_SIZE (dynobj
));
8824 /* On VxWorks, also allocate room for the header's
8825 .rela.plt.unloaded entries. */
8826 if (htab
->is_vxworks
&& !info
->shared
)
8827 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
8829 /* Now work out the sizes of individual PLT entries. */
8830 if (htab
->is_vxworks
&& info
->shared
)
8831 htab
->plt_mips_entry_size
8832 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
8833 else if (htab
->is_vxworks
)
8834 htab
->plt_mips_entry_size
8835 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
8837 htab
->plt_mips_entry_size
8838 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
8839 else if (!micromips_p
)
8841 htab
->plt_mips_entry_size
8842 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
8843 htab
->plt_comp_entry_size
8844 = 2 * ARRAY_SIZE (mips16_o32_exec_plt_entry
);
8846 else if (htab
->insn32
)
8848 htab
->plt_mips_entry_size
8849 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
8850 htab
->plt_comp_entry_size
8851 = 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt_entry
);
8855 htab
->plt_mips_entry_size
8856 = 4 * ARRAY_SIZE (mips_exec_plt_entry
);
8857 htab
->plt_comp_entry_size
8858 = 2 * ARRAY_SIZE (micromips_o32_exec_plt_entry
);
8862 if (h
->plt
.plist
== NULL
)
8863 h
->plt
.plist
= mips_elf_make_plt_record (dynobj
);
8864 if (h
->plt
.plist
== NULL
)
8867 /* There are no defined MIPS16 or microMIPS PLT entries for VxWorks,
8868 n32 or n64, so always use a standard entry there.
8870 If the symbol has a MIPS16 call stub and gets a PLT entry, then
8871 all MIPS16 calls will go via that stub, and there is no benefit
8872 to having a MIPS16 entry. And in the case of call_stub a
8873 standard entry actually has to be used as the stub ends with a J
8878 || hmips
->call_fp_stub
)
8880 h
->plt
.plist
->need_mips
= TRUE
;
8881 h
->plt
.plist
->need_comp
= FALSE
;
8884 /* Otherwise, if there are no direct calls to the function, we
8885 have a free choice of whether to use standard or compressed
8886 entries. Prefer microMIPS entries if the object is known to
8887 contain microMIPS code, so that it becomes possible to create
8888 pure microMIPS binaries. Prefer standard entries otherwise,
8889 because MIPS16 ones are no smaller and are usually slower. */
8890 if (!h
->plt
.plist
->need_mips
&& !h
->plt
.plist
->need_comp
)
8893 h
->plt
.plist
->need_comp
= TRUE
;
8895 h
->plt
.plist
->need_mips
= TRUE
;
8898 if (h
->plt
.plist
->need_mips
)
8900 h
->plt
.plist
->mips_offset
= htab
->plt_mips_offset
;
8901 htab
->plt_mips_offset
+= htab
->plt_mips_entry_size
;
8903 if (h
->plt
.plist
->need_comp
)
8905 h
->plt
.plist
->comp_offset
= htab
->plt_comp_offset
;
8906 htab
->plt_comp_offset
+= htab
->plt_comp_entry_size
;
8909 /* Reserve the corresponding .got.plt entry now too. */
8910 h
->plt
.plist
->gotplt_index
= htab
->plt_got_index
++;
8912 /* If the output file has no definition of the symbol, set the
8913 symbol's value to the address of the stub. */
8914 if (!info
->shared
&& !h
->def_regular
)
8915 hmips
->use_plt_entry
= TRUE
;
8917 /* Make room for the R_MIPS_JUMP_SLOT relocation. */
8918 htab
->srelplt
->size
+= (htab
->is_vxworks
8919 ? MIPS_ELF_RELA_SIZE (dynobj
)
8920 : MIPS_ELF_REL_SIZE (dynobj
));
8922 /* Make room for the .rela.plt.unloaded relocations. */
8923 if (htab
->is_vxworks
&& !info
->shared
)
8924 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
8926 /* All relocations against this symbol that could have been made
8927 dynamic will now refer to the PLT entry instead. */
8928 hmips
->possibly_dynamic_relocs
= 0;
8933 /* If this is a weak symbol, and there is a real definition, the
8934 processor independent code will have arranged for us to see the
8935 real definition first, and we can just use the same value. */
8936 if (h
->u
.weakdef
!= NULL
)
8938 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
8939 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
8940 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
8941 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
8945 /* Otherwise, there is nothing further to do for symbols defined
8946 in regular objects. */
8950 /* There's also nothing more to do if we'll convert all relocations
8951 against this symbol into dynamic relocations. */
8952 if (!hmips
->has_static_relocs
)
8955 /* We're now relying on copy relocations. Complain if we have
8956 some that we can't convert. */
8957 if (!htab
->use_plts_and_copy_relocs
|| info
->shared
)
8959 (*_bfd_error_handler
) (_("non-dynamic relocations refer to "
8960 "dynamic symbol %s"),
8961 h
->root
.root
.string
);
8962 bfd_set_error (bfd_error_bad_value
);
8966 /* We must allocate the symbol in our .dynbss section, which will
8967 become part of the .bss section of the executable. There will be
8968 an entry for this symbol in the .dynsym section. The dynamic
8969 object will contain position independent code, so all references
8970 from the dynamic object to this symbol will go through the global
8971 offset table. The dynamic linker will use the .dynsym entry to
8972 determine the address it must put in the global offset table, so
8973 both the dynamic object and the regular object will refer to the
8974 same memory location for the variable. */
8976 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
8978 if (htab
->is_vxworks
)
8979 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
8981 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
8985 /* All relocations against this symbol that could have been made
8986 dynamic will now refer to the local copy instead. */
8987 hmips
->possibly_dynamic_relocs
= 0;
8989 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
8992 /* This function is called after all the input files have been read,
8993 and the input sections have been assigned to output sections. We
8994 check for any mips16 stub sections that we can discard. */
8997 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
8998 struct bfd_link_info
*info
)
9001 struct mips_elf_link_hash_table
*htab
;
9002 struct mips_htab_traverse_info hti
;
9004 htab
= mips_elf_hash_table (info
);
9005 BFD_ASSERT (htab
!= NULL
);
9007 /* The .reginfo section has a fixed size. */
9008 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
9010 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
9013 hti
.output_bfd
= output_bfd
;
9015 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
9016 mips_elf_check_symbols
, &hti
);
9023 /* If the link uses a GOT, lay it out and work out its size. */
9026 mips_elf_lay_out_got (bfd
*output_bfd
, struct bfd_link_info
*info
)
9030 struct mips_got_info
*g
;
9031 bfd_size_type loadable_size
= 0;
9032 bfd_size_type page_gotno
;
9034 struct mips_elf_traverse_got_arg tga
;
9035 struct mips_elf_link_hash_table
*htab
;
9037 htab
= mips_elf_hash_table (info
);
9038 BFD_ASSERT (htab
!= NULL
);
9044 dynobj
= elf_hash_table (info
)->dynobj
;
9047 /* Allocate room for the reserved entries. VxWorks always reserves
9048 3 entries; other objects only reserve 2 entries. */
9049 BFD_ASSERT (g
->assigned_gotno
== 0);
9050 if (htab
->is_vxworks
)
9051 htab
->reserved_gotno
= 3;
9053 htab
->reserved_gotno
= 2;
9054 g
->local_gotno
+= htab
->reserved_gotno
;
9055 g
->assigned_gotno
= htab
->reserved_gotno
;
9057 /* Decide which symbols need to go in the global part of the GOT and
9058 count the number of reloc-only GOT symbols. */
9059 mips_elf_link_hash_traverse (htab
, mips_elf_count_got_symbols
, info
);
9061 if (!mips_elf_resolve_final_got_entries (info
, g
))
9064 /* Calculate the total loadable size of the output. That
9065 will give us the maximum number of GOT_PAGE entries
9067 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
9069 asection
*subsection
;
9071 for (subsection
= ibfd
->sections
;
9073 subsection
= subsection
->next
)
9075 if ((subsection
->flags
& SEC_ALLOC
) == 0)
9077 loadable_size
+= ((subsection
->size
+ 0xf)
9078 &~ (bfd_size_type
) 0xf);
9082 if (htab
->is_vxworks
)
9083 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
9084 relocations against local symbols evaluate to "G", and the EABI does
9085 not include R_MIPS_GOT_PAGE. */
9088 /* Assume there are two loadable segments consisting of contiguous
9089 sections. Is 5 enough? */
9090 page_gotno
= (loadable_size
>> 16) + 5;
9092 /* Choose the smaller of the two page estimates; both are intended to be
9094 if (page_gotno
> g
->page_gotno
)
9095 page_gotno
= g
->page_gotno
;
9097 g
->local_gotno
+= page_gotno
;
9099 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
9100 s
->size
+= g
->global_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
9101 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
9103 /* VxWorks does not support multiple GOTs. It initializes $gp to
9104 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
9106 if (!htab
->is_vxworks
&& s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
9108 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
9113 /* Record that all bfds use G. This also has the effect of freeing
9114 the per-bfd GOTs, which we no longer need. */
9115 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
9116 if (mips_elf_bfd_got (ibfd
, FALSE
))
9117 mips_elf_replace_bfd_got (ibfd
, g
);
9118 mips_elf_replace_bfd_got (output_bfd
, g
);
9120 /* Set up TLS entries. */
9121 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
9124 tga
.value
= MIPS_ELF_GOT_SIZE (output_bfd
);
9125 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, &tga
);
9128 BFD_ASSERT (g
->tls_assigned_gotno
9129 == g
->global_gotno
+ g
->local_gotno
+ g
->tls_gotno
);
9131 /* Each VxWorks GOT entry needs an explicit relocation. */
9132 if (htab
->is_vxworks
&& info
->shared
)
9133 g
->relocs
+= g
->global_gotno
+ g
->local_gotno
- htab
->reserved_gotno
;
9135 /* Allocate room for the TLS relocations. */
9137 mips_elf_allocate_dynamic_relocations (dynobj
, info
, g
->relocs
);
9143 /* Estimate the size of the .MIPS.stubs section. */
9146 mips_elf_estimate_stub_size (bfd
*output_bfd
, struct bfd_link_info
*info
)
9148 struct mips_elf_link_hash_table
*htab
;
9149 bfd_size_type dynsymcount
;
9151 htab
= mips_elf_hash_table (info
);
9152 BFD_ASSERT (htab
!= NULL
);
9154 if (htab
->lazy_stub_count
== 0)
9157 /* IRIX rld assumes that a function stub isn't at the end of the .text
9158 section, so add a dummy entry to the end. */
9159 htab
->lazy_stub_count
++;
9161 /* Get a worst-case estimate of the number of dynamic symbols needed.
9162 At this point, dynsymcount does not account for section symbols
9163 and count_section_dynsyms may overestimate the number that will
9165 dynsymcount
= (elf_hash_table (info
)->dynsymcount
9166 + count_section_dynsyms (output_bfd
, info
));
9168 /* Determine the size of one stub entry. There's no disadvantage
9169 from using microMIPS code here, so for the sake of pure-microMIPS
9170 binaries we prefer it whenever there's any microMIPS code in
9171 output produced at all. This has a benefit of stubs being
9172 shorter by 4 bytes each too, unless in the insn32 mode. */
9173 if (!MICROMIPS_P (output_bfd
))
9174 htab
->function_stub_size
= (dynsymcount
> 0x10000
9175 ? MIPS_FUNCTION_STUB_BIG_SIZE
9176 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
9177 else if (htab
->insn32
)
9178 htab
->function_stub_size
= (dynsymcount
> 0x10000
9179 ? MICROMIPS_INSN32_FUNCTION_STUB_BIG_SIZE
9180 : MICROMIPS_INSN32_FUNCTION_STUB_NORMAL_SIZE
);
9182 htab
->function_stub_size
= (dynsymcount
> 0x10000
9183 ? MICROMIPS_FUNCTION_STUB_BIG_SIZE
9184 : MICROMIPS_FUNCTION_STUB_NORMAL_SIZE
);
9186 htab
->sstubs
->size
= htab
->lazy_stub_count
* htab
->function_stub_size
;
9189 /* A mips_elf_link_hash_traverse callback for which DATA points to a
9190 mips_htab_traverse_info. If H needs a traditional MIPS lazy-binding
9191 stub, allocate an entry in the stubs section. */
9194 mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry
*h
, void *data
)
9196 struct mips_htab_traverse_info
*hti
= data
;
9197 struct mips_elf_link_hash_table
*htab
;
9198 struct bfd_link_info
*info
;
9202 output_bfd
= hti
->output_bfd
;
9203 htab
= mips_elf_hash_table (info
);
9204 BFD_ASSERT (htab
!= NULL
);
9206 if (h
->needs_lazy_stub
)
9208 bfd_boolean micromips_p
= MICROMIPS_P (output_bfd
);
9209 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
9210 bfd_vma isa_bit
= micromips_p
;
9212 BFD_ASSERT (htab
->root
.dynobj
!= NULL
);
9213 if (h
->root
.plt
.plist
== NULL
)
9214 h
->root
.plt
.plist
= mips_elf_make_plt_record (htab
->sstubs
->owner
);
9215 if (h
->root
.plt
.plist
== NULL
)
9220 h
->root
.root
.u
.def
.section
= htab
->sstubs
;
9221 h
->root
.root
.u
.def
.value
= htab
->sstubs
->size
+ isa_bit
;
9222 h
->root
.plt
.plist
->stub_offset
= htab
->sstubs
->size
;
9223 h
->root
.other
= other
;
9224 htab
->sstubs
->size
+= htab
->function_stub_size
;
9229 /* Allocate offsets in the stubs section to each symbol that needs one.
9230 Set the final size of the .MIPS.stub section. */
9233 mips_elf_lay_out_lazy_stubs (struct bfd_link_info
*info
)
9235 bfd
*output_bfd
= info
->output_bfd
;
9236 bfd_boolean micromips_p
= MICROMIPS_P (output_bfd
);
9237 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
9238 bfd_vma isa_bit
= micromips_p
;
9239 struct mips_elf_link_hash_table
*htab
;
9240 struct mips_htab_traverse_info hti
;
9241 struct elf_link_hash_entry
*h
;
9244 htab
= mips_elf_hash_table (info
);
9245 BFD_ASSERT (htab
!= NULL
);
9247 if (htab
->lazy_stub_count
== 0)
9250 htab
->sstubs
->size
= 0;
9252 hti
.output_bfd
= output_bfd
;
9254 mips_elf_link_hash_traverse (htab
, mips_elf_allocate_lazy_stub
, &hti
);
9257 htab
->sstubs
->size
+= htab
->function_stub_size
;
9258 BFD_ASSERT (htab
->sstubs
->size
9259 == htab
->lazy_stub_count
* htab
->function_stub_size
);
9261 dynobj
= elf_hash_table (info
)->dynobj
;
9262 BFD_ASSERT (dynobj
!= NULL
);
9263 h
= _bfd_elf_define_linkage_sym (dynobj
, info
, htab
->sstubs
, "_MIPS_STUBS_");
9266 h
->root
.u
.def
.value
= isa_bit
;
9273 /* A mips_elf_link_hash_traverse callback for which DATA points to a
9274 bfd_link_info. If H uses the address of a PLT entry as the value
9275 of the symbol, then set the entry in the symbol table now. Prefer
9276 a standard MIPS PLT entry. */
9279 mips_elf_set_plt_sym_value (struct mips_elf_link_hash_entry
*h
, void *data
)
9281 struct bfd_link_info
*info
= data
;
9282 bfd_boolean micromips_p
= MICROMIPS_P (info
->output_bfd
);
9283 struct mips_elf_link_hash_table
*htab
;
9288 htab
= mips_elf_hash_table (info
);
9289 BFD_ASSERT (htab
!= NULL
);
9291 if (h
->use_plt_entry
)
9293 BFD_ASSERT (h
->root
.plt
.plist
!= NULL
);
9294 BFD_ASSERT (h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
9295 || h
->root
.plt
.plist
->comp_offset
!= MINUS_ONE
);
9297 val
= htab
->plt_header_size
;
9298 if (h
->root
.plt
.plist
->mips_offset
!= MINUS_ONE
)
9301 val
+= h
->root
.plt
.plist
->mips_offset
;
9307 val
+= htab
->plt_mips_offset
+ h
->root
.plt
.plist
->comp_offset
;
9308 other
= micromips_p
? STO_MICROMIPS
: STO_MIPS16
;
9311 /* For VxWorks, point at the PLT load stub rather than the lazy
9312 resolution stub; this stub will become the canonical function
9314 if (htab
->is_vxworks
)
9317 h
->root
.root
.u
.def
.section
= htab
->splt
;
9318 h
->root
.root
.u
.def
.value
= val
;
9319 h
->root
.other
= other
;
9325 /* Set the sizes of the dynamic sections. */
9328 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
9329 struct bfd_link_info
*info
)
9332 asection
*s
, *sreldyn
;
9333 bfd_boolean reltext
;
9334 struct mips_elf_link_hash_table
*htab
;
9336 htab
= mips_elf_hash_table (info
);
9337 BFD_ASSERT (htab
!= NULL
);
9338 dynobj
= elf_hash_table (info
)->dynobj
;
9339 BFD_ASSERT (dynobj
!= NULL
);
9341 if (elf_hash_table (info
)->dynamic_sections_created
)
9343 /* Set the contents of the .interp section to the interpreter. */
9344 if (info
->executable
)
9346 s
= bfd_get_linker_section (dynobj
, ".interp");
9347 BFD_ASSERT (s
!= NULL
);
9349 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
9351 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
9354 /* Figure out the size of the PLT header if we know that we
9355 are using it. For the sake of cache alignment always use
9356 a standard header whenever any standard entries are present
9357 even if microMIPS entries are present as well. This also
9358 lets the microMIPS header rely on the value of $v0 only set
9359 by microMIPS entries, for a small size reduction.
9361 Set symbol table entry values for symbols that use the
9362 address of their PLT entry now that we can calculate it.
9364 Also create the _PROCEDURE_LINKAGE_TABLE_ symbol if we
9365 haven't already in _bfd_elf_create_dynamic_sections. */
9366 if (htab
->splt
&& htab
->plt_mips_offset
+ htab
->plt_comp_offset
!= 0)
9368 bfd_boolean micromips_p
= (MICROMIPS_P (output_bfd
)
9369 && !htab
->plt_mips_offset
);
9370 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
9371 bfd_vma isa_bit
= micromips_p
;
9372 struct elf_link_hash_entry
*h
;
9375 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9376 BFD_ASSERT (htab
->sgotplt
->size
== 0);
9377 BFD_ASSERT (htab
->splt
->size
== 0);
9379 if (htab
->is_vxworks
&& info
->shared
)
9380 size
= 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
9381 else if (htab
->is_vxworks
)
9382 size
= 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
9383 else if (ABI_64_P (output_bfd
))
9384 size
= 4 * ARRAY_SIZE (mips_n64_exec_plt0_entry
);
9385 else if (ABI_N32_P (output_bfd
))
9386 size
= 4 * ARRAY_SIZE (mips_n32_exec_plt0_entry
);
9387 else if (!micromips_p
)
9388 size
= 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
);
9389 else if (htab
->insn32
)
9390 size
= 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt0_entry
);
9392 size
= 2 * ARRAY_SIZE (micromips_o32_exec_plt0_entry
);
9394 htab
->plt_header_is_comp
= micromips_p
;
9395 htab
->plt_header_size
= size
;
9396 htab
->splt
->size
= (size
9397 + htab
->plt_mips_offset
9398 + htab
->plt_comp_offset
);
9399 htab
->sgotplt
->size
= (htab
->plt_got_index
9400 * MIPS_ELF_GOT_SIZE (dynobj
));
9402 mips_elf_link_hash_traverse (htab
, mips_elf_set_plt_sym_value
, info
);
9404 if (htab
->root
.hplt
== NULL
)
9406 h
= _bfd_elf_define_linkage_sym (dynobj
, info
, htab
->splt
,
9407 "_PROCEDURE_LINKAGE_TABLE_");
9408 htab
->root
.hplt
= h
;
9413 h
= htab
->root
.hplt
;
9414 h
->root
.u
.def
.value
= isa_bit
;
9420 /* Allocate space for global sym dynamic relocs. */
9421 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, info
);
9423 mips_elf_estimate_stub_size (output_bfd
, info
);
9425 if (!mips_elf_lay_out_got (output_bfd
, info
))
9428 mips_elf_lay_out_lazy_stubs (info
);
9430 /* The check_relocs and adjust_dynamic_symbol entry points have
9431 determined the sizes of the various dynamic sections. Allocate
9434 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9438 /* It's OK to base decisions on the section name, because none
9439 of the dynobj section names depend upon the input files. */
9440 name
= bfd_get_section_name (dynobj
, s
);
9442 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9445 if (CONST_STRNEQ (name
, ".rel"))
9449 const char *outname
;
9452 /* If this relocation section applies to a read only
9453 section, then we probably need a DT_TEXTREL entry.
9454 If the relocation section is .rel(a).dyn, we always
9455 assert a DT_TEXTREL entry rather than testing whether
9456 there exists a relocation to a read only section or
9458 outname
= bfd_get_section_name (output_bfd
,
9460 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
9462 && (target
->flags
& SEC_READONLY
) != 0
9463 && (target
->flags
& SEC_ALLOC
) != 0)
9464 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
9467 /* We use the reloc_count field as a counter if we need
9468 to copy relocs into the output file. */
9469 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
9472 /* If combreloc is enabled, elf_link_sort_relocs() will
9473 sort relocations, but in a different way than we do,
9474 and before we're done creating relocations. Also, it
9475 will move them around between input sections'
9476 relocation's contents, so our sorting would be
9477 broken, so don't let it run. */
9478 info
->combreloc
= 0;
9481 else if (! info
->shared
9482 && ! mips_elf_hash_table (info
)->use_rld_obj_head
9483 && CONST_STRNEQ (name
, ".rld_map"))
9485 /* We add a room for __rld_map. It will be filled in by the
9486 rtld to contain a pointer to the _r_debug structure. */
9487 s
->size
+= MIPS_ELF_RLD_MAP_SIZE (output_bfd
);
9489 else if (SGI_COMPAT (output_bfd
)
9490 && CONST_STRNEQ (name
, ".compact_rel"))
9491 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
9492 else if (s
== htab
->splt
)
9494 /* If the last PLT entry has a branch delay slot, allocate
9495 room for an extra nop to fill the delay slot. This is
9496 for CPUs without load interlocking. */
9497 if (! LOAD_INTERLOCKS_P (output_bfd
)
9498 && ! htab
->is_vxworks
&& s
->size
> 0)
9501 else if (! CONST_STRNEQ (name
, ".init")
9503 && s
!= htab
->sgotplt
9504 && s
!= htab
->sstubs
9505 && s
!= htab
->sdynbss
)
9507 /* It's not one of our sections, so don't allocate space. */
9513 s
->flags
|= SEC_EXCLUDE
;
9517 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9520 /* Allocate memory for the section contents. */
9521 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
9522 if (s
->contents
== NULL
)
9524 bfd_set_error (bfd_error_no_memory
);
9529 if (elf_hash_table (info
)->dynamic_sections_created
)
9531 /* Add some entries to the .dynamic section. We fill in the
9532 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
9533 must add the entries now so that we get the correct size for
9534 the .dynamic section. */
9536 /* SGI object has the equivalence of DT_DEBUG in the
9537 DT_MIPS_RLD_MAP entry. This must come first because glibc
9538 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and some tools
9539 may only look at the first one they see. */
9541 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
9544 /* The DT_DEBUG entry may be filled in by the dynamic linker and
9545 used by the debugger. */
9546 if (info
->executable
9547 && !SGI_COMPAT (output_bfd
)
9548 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
9551 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
9552 info
->flags
|= DF_TEXTREL
;
9554 if ((info
->flags
& DF_TEXTREL
) != 0)
9556 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
9559 /* Clear the DF_TEXTREL flag. It will be set again if we
9560 write out an actual text relocation; we may not, because
9561 at this point we do not know whether e.g. any .eh_frame
9562 absolute relocations have been converted to PC-relative. */
9563 info
->flags
&= ~DF_TEXTREL
;
9566 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
9569 sreldyn
= mips_elf_rel_dyn_section (info
, FALSE
);
9570 if (htab
->is_vxworks
)
9572 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
9573 use any of the DT_MIPS_* tags. */
9574 if (sreldyn
&& sreldyn
->size
> 0)
9576 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
9579 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
9582 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
9588 if (sreldyn
&& sreldyn
->size
> 0)
9590 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
9593 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
9596 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
9600 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
9603 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
9606 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
9609 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
9612 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
9615 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
9618 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
9621 if (IRIX_COMPAT (dynobj
) == ict_irix5
9622 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
9625 if (IRIX_COMPAT (dynobj
) == ict_irix6
9626 && (bfd_get_section_by_name
9627 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
9628 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
9631 if (htab
->splt
->size
> 0)
9633 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
9636 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
9639 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
9642 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_PLTGOT
, 0))
9645 if (htab
->is_vxworks
9646 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
9653 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
9654 Adjust its R_ADDEND field so that it is correct for the output file.
9655 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
9656 and sections respectively; both use symbol indexes. */
9659 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
9660 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
9661 asection
**local_sections
, Elf_Internal_Rela
*rel
)
9663 unsigned int r_type
, r_symndx
;
9664 Elf_Internal_Sym
*sym
;
9667 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
))
9669 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
9670 if (gprel16_reloc_p (r_type
)
9671 || r_type
== R_MIPS_GPREL32
9672 || literal_reloc_p (r_type
))
9674 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
9675 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
9678 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
9679 sym
= local_syms
+ r_symndx
;
9681 /* Adjust REL's addend to account for section merging. */
9682 if (!info
->relocatable
)
9684 sec
= local_sections
[r_symndx
];
9685 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
9688 /* This would normally be done by the rela_normal code in elflink.c. */
9689 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
9690 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
9694 /* Handle relocations against symbols from removed linkonce sections,
9695 or sections discarded by a linker script. We use this wrapper around
9696 RELOC_AGAINST_DISCARDED_SECTION to handle triplets of compound relocs
9697 on 64-bit ELF targets. In this case for any relocation handled, which
9698 always be the first in a triplet, the remaining two have to be processed
9699 together with the first, even if they are R_MIPS_NONE. It is the symbol
9700 index referred by the first reloc that applies to all the three and the
9701 remaining two never refer to an object symbol. And it is the final
9702 relocation (the last non-null one) that determines the output field of
9703 the whole relocation so retrieve the corresponding howto structure for
9704 the relocatable field to be cleared by RELOC_AGAINST_DISCARDED_SECTION.
9706 Note that RELOC_AGAINST_DISCARDED_SECTION is a macro that uses "continue"
9707 and therefore requires to be pasted in a loop. It also defines a block
9708 and does not protect any of its arguments, hence the extra brackets. */
9711 mips_reloc_against_discarded_section (bfd
*output_bfd
,
9712 struct bfd_link_info
*info
,
9713 bfd
*input_bfd
, asection
*input_section
,
9714 Elf_Internal_Rela
**rel
,
9715 const Elf_Internal_Rela
**relend
,
9716 bfd_boolean rel_reloc
,
9717 reloc_howto_type
*howto
,
9720 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
9721 int count
= bed
->s
->int_rels_per_ext_rel
;
9722 unsigned int r_type
;
9725 for (i
= count
- 1; i
> 0; i
--)
9727 r_type
= ELF_R_TYPE (output_bfd
, (*rel
)[i
].r_info
);
9728 if (r_type
!= R_MIPS_NONE
)
9730 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
, !rel_reloc
);
9736 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
9737 (*rel
), count
, (*relend
),
9738 howto
, i
, contents
);
9743 /* Relocate a MIPS ELF section. */
9746 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
9747 bfd
*input_bfd
, asection
*input_section
,
9748 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
9749 Elf_Internal_Sym
*local_syms
,
9750 asection
**local_sections
)
9752 Elf_Internal_Rela
*rel
;
9753 const Elf_Internal_Rela
*relend
;
9755 bfd_boolean use_saved_addend_p
= FALSE
;
9756 const struct elf_backend_data
*bed
;
9758 bed
= get_elf_backend_data (output_bfd
);
9759 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
9760 for (rel
= relocs
; rel
< relend
; ++rel
)
9764 reloc_howto_type
*howto
;
9765 bfd_boolean cross_mode_jump_p
= FALSE
;
9766 /* TRUE if the relocation is a RELA relocation, rather than a
9768 bfd_boolean rela_relocation_p
= TRUE
;
9769 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
9771 unsigned long r_symndx
;
9773 Elf_Internal_Shdr
*symtab_hdr
;
9774 struct elf_link_hash_entry
*h
;
9775 bfd_boolean rel_reloc
;
9777 rel_reloc
= (NEWABI_P (input_bfd
)
9778 && mips_elf_rel_relocation_p (input_bfd
, input_section
,
9780 /* Find the relocation howto for this relocation. */
9781 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
, !rel_reloc
);
9783 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
9784 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
9785 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
))
9787 sec
= local_sections
[r_symndx
];
9792 unsigned long extsymoff
;
9795 if (!elf_bad_symtab (input_bfd
))
9796 extsymoff
= symtab_hdr
->sh_info
;
9797 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
9798 while (h
->root
.type
== bfd_link_hash_indirect
9799 || h
->root
.type
== bfd_link_hash_warning
)
9800 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9803 if (h
->root
.type
== bfd_link_hash_defined
9804 || h
->root
.type
== bfd_link_hash_defweak
)
9805 sec
= h
->root
.u
.def
.section
;
9808 if (sec
!= NULL
&& discarded_section (sec
))
9810 mips_reloc_against_discarded_section (output_bfd
, info
, input_bfd
,
9811 input_section
, &rel
, &relend
,
9812 rel_reloc
, howto
, contents
);
9816 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
9818 /* Some 32-bit code uses R_MIPS_64. In particular, people use
9819 64-bit code, but make sure all their addresses are in the
9820 lowermost or uppermost 32-bit section of the 64-bit address
9821 space. Thus, when they use an R_MIPS_64 they mean what is
9822 usually meant by R_MIPS_32, with the exception that the
9823 stored value is sign-extended to 64 bits. */
9824 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
9826 /* On big-endian systems, we need to lie about the position
9828 if (bfd_big_endian (input_bfd
))
9832 if (!use_saved_addend_p
)
9834 /* If these relocations were originally of the REL variety,
9835 we must pull the addend out of the field that will be
9836 relocated. Otherwise, we simply use the contents of the
9838 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
9841 rela_relocation_p
= FALSE
;
9842 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
9844 if (hi16_reloc_p (r_type
)
9845 || (got16_reloc_p (r_type
)
9846 && mips_elf_local_relocation_p (input_bfd
, rel
,
9849 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
9853 name
= h
->root
.root
.string
;
9855 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
9856 local_syms
+ r_symndx
,
9858 (*_bfd_error_handler
)
9859 (_("%B: Can't find matching LO16 reloc against `%s' for %s at 0x%lx in section `%A'"),
9860 input_bfd
, input_section
, name
, howto
->name
,
9865 addend
<<= howto
->rightshift
;
9868 addend
= rel
->r_addend
;
9869 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
9870 local_syms
, local_sections
, rel
);
9873 if (info
->relocatable
)
9875 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
9876 && bfd_big_endian (input_bfd
))
9879 if (!rela_relocation_p
&& rel
->r_addend
)
9881 addend
+= rel
->r_addend
;
9882 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
9883 addend
= mips_elf_high (addend
);
9884 else if (r_type
== R_MIPS_HIGHER
)
9885 addend
= mips_elf_higher (addend
);
9886 else if (r_type
== R_MIPS_HIGHEST
)
9887 addend
= mips_elf_highest (addend
);
9889 addend
>>= howto
->rightshift
;
9891 /* We use the source mask, rather than the destination
9892 mask because the place to which we are writing will be
9893 source of the addend in the final link. */
9894 addend
&= howto
->src_mask
;
9896 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
9897 /* See the comment above about using R_MIPS_64 in the 32-bit
9898 ABI. Here, we need to update the addend. It would be
9899 possible to get away with just using the R_MIPS_32 reloc
9900 but for endianness. */
9906 if (addend
& ((bfd_vma
) 1 << 31))
9908 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
9915 /* If we don't know that we have a 64-bit type,
9916 do two separate stores. */
9917 if (bfd_big_endian (input_bfd
))
9919 /* Store the sign-bits (which are most significant)
9921 low_bits
= sign_bits
;
9927 high_bits
= sign_bits
;
9929 bfd_put_32 (input_bfd
, low_bits
,
9930 contents
+ rel
->r_offset
);
9931 bfd_put_32 (input_bfd
, high_bits
,
9932 contents
+ rel
->r_offset
+ 4);
9936 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
9937 input_bfd
, input_section
,
9942 /* Go on to the next relocation. */
9946 /* In the N32 and 64-bit ABIs there may be multiple consecutive
9947 relocations for the same offset. In that case we are
9948 supposed to treat the output of each relocation as the addend
9950 if (rel
+ 1 < relend
9951 && rel
->r_offset
== rel
[1].r_offset
9952 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
9953 use_saved_addend_p
= TRUE
;
9955 use_saved_addend_p
= FALSE
;
9957 /* Figure out what value we are supposed to relocate. */
9958 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
9959 input_section
, info
, rel
,
9960 addend
, howto
, local_syms
,
9961 local_sections
, &value
,
9962 &name
, &cross_mode_jump_p
,
9963 use_saved_addend_p
))
9965 case bfd_reloc_continue
:
9966 /* There's nothing to do. */
9969 case bfd_reloc_undefined
:
9970 /* mips_elf_calculate_relocation already called the
9971 undefined_symbol callback. There's no real point in
9972 trying to perform the relocation at this point, so we
9973 just skip ahead to the next relocation. */
9976 case bfd_reloc_notsupported
:
9977 msg
= _("internal error: unsupported relocation error");
9978 info
->callbacks
->warning
9979 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
9982 case bfd_reloc_overflow
:
9983 if (use_saved_addend_p
)
9984 /* Ignore overflow until we reach the last relocation for
9985 a given location. */
9989 struct mips_elf_link_hash_table
*htab
;
9991 htab
= mips_elf_hash_table (info
);
9992 BFD_ASSERT (htab
!= NULL
);
9993 BFD_ASSERT (name
!= NULL
);
9994 if (!htab
->small_data_overflow_reported
9995 && (gprel16_reloc_p (howto
->type
)
9996 || literal_reloc_p (howto
->type
)))
9998 msg
= _("small-data section exceeds 64KB;"
9999 " lower small-data size limit (see option -G)");
10001 htab
->small_data_overflow_reported
= TRUE
;
10002 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
10004 if (! ((*info
->callbacks
->reloc_overflow
)
10005 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
10006 input_bfd
, input_section
, rel
->r_offset
)))
10014 case bfd_reloc_outofrange
:
10015 if (jal_reloc_p (howto
->type
))
10017 msg
= _("JALX to a non-word-aligned address");
10018 info
->callbacks
->warning
10019 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
10022 /* Fall through. */
10029 /* If we've got another relocation for the address, keep going
10030 until we reach the last one. */
10031 if (use_saved_addend_p
)
10037 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
10038 /* See the comment above about using R_MIPS_64 in the 32-bit
10039 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
10040 that calculated the right value. Now, however, we
10041 sign-extend the 32-bit result to 64-bits, and store it as a
10042 64-bit value. We are especially generous here in that we
10043 go to extreme lengths to support this usage on systems with
10044 only a 32-bit VMA. */
10050 if (value
& ((bfd_vma
) 1 << 31))
10052 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
10059 /* If we don't know that we have a 64-bit type,
10060 do two separate stores. */
10061 if (bfd_big_endian (input_bfd
))
10063 /* Undo what we did above. */
10064 rel
->r_offset
-= 4;
10065 /* Store the sign-bits (which are most significant)
10067 low_bits
= sign_bits
;
10073 high_bits
= sign_bits
;
10075 bfd_put_32 (input_bfd
, low_bits
,
10076 contents
+ rel
->r_offset
);
10077 bfd_put_32 (input_bfd
, high_bits
,
10078 contents
+ rel
->r_offset
+ 4);
10082 /* Actually perform the relocation. */
10083 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
10084 input_bfd
, input_section
,
10085 contents
, cross_mode_jump_p
))
10092 /* A function that iterates over each entry in la25_stubs and fills
10093 in the code for each one. DATA points to a mips_htab_traverse_info. */
10096 mips_elf_create_la25_stub (void **slot
, void *data
)
10098 struct mips_htab_traverse_info
*hti
;
10099 struct mips_elf_link_hash_table
*htab
;
10100 struct mips_elf_la25_stub
*stub
;
10103 bfd_vma offset
, target
, target_high
, target_low
;
10105 stub
= (struct mips_elf_la25_stub
*) *slot
;
10106 hti
= (struct mips_htab_traverse_info
*) data
;
10107 htab
= mips_elf_hash_table (hti
->info
);
10108 BFD_ASSERT (htab
!= NULL
);
10110 /* Create the section contents, if we haven't already. */
10111 s
= stub
->stub_section
;
10115 loc
= bfd_malloc (s
->size
);
10124 /* Work out where in the section this stub should go. */
10125 offset
= stub
->offset
;
10127 /* Work out the target address. */
10128 target
= mips_elf_get_la25_target (stub
, &s
);
10129 target
+= s
->output_section
->vma
+ s
->output_offset
;
10131 target_high
= ((target
+ 0x8000) >> 16) & 0xffff;
10132 target_low
= (target
& 0xffff);
10134 if (stub
->stub_section
!= htab
->strampoline
)
10136 /* This is a simple LUI/ADDIU stub. Zero out the beginning
10137 of the section and write the two instructions at the end. */
10138 memset (loc
, 0, offset
);
10140 if (ELF_ST_IS_MICROMIPS (stub
->h
->root
.other
))
10142 bfd_put_micromips_32 (hti
->output_bfd
,
10143 LA25_LUI_MICROMIPS (target_high
),
10145 bfd_put_micromips_32 (hti
->output_bfd
,
10146 LA25_ADDIU_MICROMIPS (target_low
),
10151 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
10152 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 4);
10157 /* This is trampoline. */
10159 if (ELF_ST_IS_MICROMIPS (stub
->h
->root
.other
))
10161 bfd_put_micromips_32 (hti
->output_bfd
,
10162 LA25_LUI_MICROMIPS (target_high
), loc
);
10163 bfd_put_micromips_32 (hti
->output_bfd
,
10164 LA25_J_MICROMIPS (target
), loc
+ 4);
10165 bfd_put_micromips_32 (hti
->output_bfd
,
10166 LA25_ADDIU_MICROMIPS (target_low
), loc
+ 8);
10167 bfd_put_32 (hti
->output_bfd
, 0, loc
+ 12);
10171 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
10172 bfd_put_32 (hti
->output_bfd
, LA25_J (target
), loc
+ 4);
10173 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 8);
10174 bfd_put_32 (hti
->output_bfd
, 0, loc
+ 12);
10180 /* If NAME is one of the special IRIX6 symbols defined by the linker,
10181 adjust it appropriately now. */
10184 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
10185 const char *name
, Elf_Internal_Sym
*sym
)
10187 /* The linker script takes care of providing names and values for
10188 these, but we must place them into the right sections. */
10189 static const char* const text_section_symbols
[] = {
10192 "__dso_displacement",
10194 "__program_header_table",
10198 static const char* const data_section_symbols
[] = {
10206 const char* const *p
;
10209 for (i
= 0; i
< 2; ++i
)
10210 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
10213 if (strcmp (*p
, name
) == 0)
10215 /* All of these symbols are given type STT_SECTION by the
10217 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
10218 sym
->st_other
= STO_PROTECTED
;
10220 /* The IRIX linker puts these symbols in special sections. */
10222 sym
->st_shndx
= SHN_MIPS_TEXT
;
10224 sym
->st_shndx
= SHN_MIPS_DATA
;
10230 /* Finish up dynamic symbol handling. We set the contents of various
10231 dynamic sections here. */
10234 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
10235 struct bfd_link_info
*info
,
10236 struct elf_link_hash_entry
*h
,
10237 Elf_Internal_Sym
*sym
)
10241 struct mips_got_info
*g
, *gg
;
10244 struct mips_elf_link_hash_table
*htab
;
10245 struct mips_elf_link_hash_entry
*hmips
;
10247 htab
= mips_elf_hash_table (info
);
10248 BFD_ASSERT (htab
!= NULL
);
10249 dynobj
= elf_hash_table (info
)->dynobj
;
10250 hmips
= (struct mips_elf_link_hash_entry
*) h
;
10252 BFD_ASSERT (!htab
->is_vxworks
);
10254 if (h
->plt
.plist
!= NULL
10255 && (h
->plt
.plist
->mips_offset
!= MINUS_ONE
10256 || h
->plt
.plist
->comp_offset
!= MINUS_ONE
))
10258 /* We've decided to create a PLT entry for this symbol. */
10260 bfd_vma header_address
, got_address
;
10261 bfd_vma got_address_high
, got_address_low
, load
;
10265 got_index
= h
->plt
.plist
->gotplt_index
;
10267 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10268 BFD_ASSERT (h
->dynindx
!= -1);
10269 BFD_ASSERT (htab
->splt
!= NULL
);
10270 BFD_ASSERT (got_index
!= MINUS_ONE
);
10271 BFD_ASSERT (!h
->def_regular
);
10273 /* Calculate the address of the PLT header. */
10274 isa_bit
= htab
->plt_header_is_comp
;
10275 header_address
= (htab
->splt
->output_section
->vma
10276 + htab
->splt
->output_offset
+ isa_bit
);
10278 /* Calculate the address of the .got.plt entry. */
10279 got_address
= (htab
->sgotplt
->output_section
->vma
10280 + htab
->sgotplt
->output_offset
10281 + got_index
* MIPS_ELF_GOT_SIZE (dynobj
));
10283 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
10284 got_address_low
= got_address
& 0xffff;
10286 /* Initially point the .got.plt entry at the PLT header. */
10287 loc
= (htab
->sgotplt
->contents
+ got_index
* MIPS_ELF_GOT_SIZE (dynobj
));
10288 if (ABI_64_P (output_bfd
))
10289 bfd_put_64 (output_bfd
, header_address
, loc
);
10291 bfd_put_32 (output_bfd
, header_address
, loc
);
10293 /* Now handle the PLT itself. First the standard entry (the order
10294 does not matter, we just have to pick one). */
10295 if (h
->plt
.plist
->mips_offset
!= MINUS_ONE
)
10297 const bfd_vma
*plt_entry
;
10298 bfd_vma plt_offset
;
10300 plt_offset
= htab
->plt_header_size
+ h
->plt
.plist
->mips_offset
;
10302 BFD_ASSERT (plt_offset
<= htab
->splt
->size
);
10304 /* Find out where the .plt entry should go. */
10305 loc
= htab
->splt
->contents
+ plt_offset
;
10307 /* Pick the load opcode. */
10308 load
= MIPS_ELF_LOAD_WORD (output_bfd
);
10310 /* Fill in the PLT entry itself. */
10311 plt_entry
= mips_exec_plt_entry
;
10312 bfd_put_32 (output_bfd
, plt_entry
[0] | got_address_high
, loc
);
10313 bfd_put_32 (output_bfd
, plt_entry
[1] | got_address_low
| load
,
10316 if (! LOAD_INTERLOCKS_P (output_bfd
))
10318 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
, loc
+ 8);
10319 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
10323 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 8);
10324 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
,
10329 /* Now the compressed entry. They come after any standard ones. */
10330 if (h
->plt
.plist
->comp_offset
!= MINUS_ONE
)
10332 bfd_vma plt_offset
;
10334 plt_offset
= (htab
->plt_header_size
+ htab
->plt_mips_offset
10335 + h
->plt
.plist
->comp_offset
);
10337 BFD_ASSERT (plt_offset
<= htab
->splt
->size
);
10339 /* Find out where the .plt entry should go. */
10340 loc
= htab
->splt
->contents
+ plt_offset
;
10342 /* Fill in the PLT entry itself. */
10343 if (!MICROMIPS_P (output_bfd
))
10345 const bfd_vma
*plt_entry
= mips16_o32_exec_plt_entry
;
10347 bfd_put_16 (output_bfd
, plt_entry
[0], loc
);
10348 bfd_put_16 (output_bfd
, plt_entry
[1], loc
+ 2);
10349 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
10350 bfd_put_16 (output_bfd
, plt_entry
[3], loc
+ 6);
10351 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
10352 bfd_put_16 (output_bfd
, plt_entry
[5], loc
+ 10);
10353 bfd_put_32 (output_bfd
, got_address
, loc
+ 12);
10355 else if (htab
->insn32
)
10357 const bfd_vma
*plt_entry
= micromips_insn32_o32_exec_plt_entry
;
10359 bfd_put_16 (output_bfd
, plt_entry
[0], loc
);
10360 bfd_put_16 (output_bfd
, got_address_high
, loc
+ 2);
10361 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
10362 bfd_put_16 (output_bfd
, got_address_low
, loc
+ 6);
10363 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
10364 bfd_put_16 (output_bfd
, plt_entry
[5], loc
+ 10);
10365 bfd_put_16 (output_bfd
, plt_entry
[6], loc
+ 12);
10366 bfd_put_16 (output_bfd
, got_address_low
, loc
+ 14);
10370 const bfd_vma
*plt_entry
= micromips_o32_exec_plt_entry
;
10371 bfd_signed_vma gotpc_offset
;
10372 bfd_vma loc_address
;
10374 BFD_ASSERT (got_address
% 4 == 0);
10376 loc_address
= (htab
->splt
->output_section
->vma
10377 + htab
->splt
->output_offset
+ plt_offset
);
10378 gotpc_offset
= got_address
- ((loc_address
| 3) ^ 3);
10380 /* ADDIUPC has a span of +/-16MB, check we're in range. */
10381 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
10383 (*_bfd_error_handler
)
10384 (_("%B: `%A' offset of %ld from `%A' "
10385 "beyond the range of ADDIUPC"),
10387 htab
->sgotplt
->output_section
,
10388 htab
->splt
->output_section
,
10389 (long) gotpc_offset
);
10390 bfd_set_error (bfd_error_no_error
);
10393 bfd_put_16 (output_bfd
,
10394 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f), loc
);
10395 bfd_put_16 (output_bfd
, (gotpc_offset
>> 2) & 0xffff, loc
+ 2);
10396 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
10397 bfd_put_16 (output_bfd
, plt_entry
[3], loc
+ 6);
10398 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
10399 bfd_put_16 (output_bfd
, plt_entry
[5], loc
+ 10);
10403 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
10404 mips_elf_output_dynamic_relocation (output_bfd
, htab
->srelplt
,
10405 got_index
- 2, h
->dynindx
,
10406 R_MIPS_JUMP_SLOT
, got_address
);
10408 /* We distinguish between PLT entries and lazy-binding stubs by
10409 giving the former an st_other value of STO_MIPS_PLT. Set the
10410 flag and leave the value if there are any relocations in the
10411 binary where pointer equality matters. */
10412 sym
->st_shndx
= SHN_UNDEF
;
10413 if (h
->pointer_equality_needed
)
10414 sym
->st_other
= ELF_ST_SET_MIPS_PLT (sym
->st_other
);
10422 if (h
->plt
.plist
!= NULL
&& h
->plt
.plist
->stub_offset
!= MINUS_ONE
)
10424 /* We've decided to create a lazy-binding stub. */
10425 bfd_boolean micromips_p
= MICROMIPS_P (output_bfd
);
10426 unsigned int other
= micromips_p
? STO_MICROMIPS
: 0;
10427 bfd_vma stub_size
= htab
->function_stub_size
;
10428 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
10429 bfd_vma isa_bit
= micromips_p
;
10430 bfd_vma stub_big_size
;
10433 stub_big_size
= MIPS_FUNCTION_STUB_BIG_SIZE
;
10434 else if (htab
->insn32
)
10435 stub_big_size
= MICROMIPS_INSN32_FUNCTION_STUB_BIG_SIZE
;
10437 stub_big_size
= MICROMIPS_FUNCTION_STUB_BIG_SIZE
;
10439 /* This symbol has a stub. Set it up. */
10441 BFD_ASSERT (h
->dynindx
!= -1);
10443 BFD_ASSERT (stub_size
== stub_big_size
|| h
->dynindx
<= 0xffff);
10445 /* Values up to 2^31 - 1 are allowed. Larger values would cause
10446 sign extension at runtime in the stub, resulting in a negative
10448 if (h
->dynindx
& ~0x7fffffff)
10451 /* Fill the stub. */
10455 bfd_put_micromips_32 (output_bfd
, STUB_LW_MICROMIPS (output_bfd
),
10460 bfd_put_micromips_32 (output_bfd
,
10461 STUB_MOVE32_MICROMIPS (output_bfd
),
10467 bfd_put_16 (output_bfd
, STUB_MOVE_MICROMIPS
, stub
+ idx
);
10470 if (stub_size
== stub_big_size
)
10472 long dynindx_hi
= (h
->dynindx
>> 16) & 0x7fff;
10474 bfd_put_micromips_32 (output_bfd
,
10475 STUB_LUI_MICROMIPS (dynindx_hi
),
10481 bfd_put_micromips_32 (output_bfd
, STUB_JALR32_MICROMIPS
,
10487 bfd_put_16 (output_bfd
, STUB_JALR_MICROMIPS
, stub
+ idx
);
10491 /* If a large stub is not required and sign extension is not a
10492 problem, then use legacy code in the stub. */
10493 if (stub_size
== stub_big_size
)
10494 bfd_put_micromips_32 (output_bfd
,
10495 STUB_ORI_MICROMIPS (h
->dynindx
& 0xffff),
10497 else if (h
->dynindx
& ~0x7fff)
10498 bfd_put_micromips_32 (output_bfd
,
10499 STUB_LI16U_MICROMIPS (h
->dynindx
& 0xffff),
10502 bfd_put_micromips_32 (output_bfd
,
10503 STUB_LI16S_MICROMIPS (output_bfd
,
10510 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
10512 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ idx
);
10514 if (stub_size
== stub_big_size
)
10516 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
10520 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
10523 /* If a large stub is not required and sign extension is not a
10524 problem, then use legacy code in the stub. */
10525 if (stub_size
== stub_big_size
)
10526 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff),
10528 else if (h
->dynindx
& ~0x7fff)
10529 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff),
10532 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
10536 BFD_ASSERT (h
->plt
.plist
->stub_offset
<= htab
->sstubs
->size
);
10537 memcpy (htab
->sstubs
->contents
+ h
->plt
.plist
->stub_offset
,
10540 /* Mark the symbol as undefined. stub_offset != -1 occurs
10541 only for the referenced symbol. */
10542 sym
->st_shndx
= SHN_UNDEF
;
10544 /* The run-time linker uses the st_value field of the symbol
10545 to reset the global offset table entry for this external
10546 to its stub address when unlinking a shared object. */
10547 sym
->st_value
= (htab
->sstubs
->output_section
->vma
10548 + htab
->sstubs
->output_offset
10549 + h
->plt
.plist
->stub_offset
10551 sym
->st_other
= other
;
10554 /* If we have a MIPS16 function with a stub, the dynamic symbol must
10555 refer to the stub, since only the stub uses the standard calling
10557 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
10559 BFD_ASSERT (hmips
->need_fn_stub
);
10560 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
10561 + hmips
->fn_stub
->output_offset
);
10562 sym
->st_size
= hmips
->fn_stub
->size
;
10563 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
10566 BFD_ASSERT (h
->dynindx
!= -1
10567 || h
->forced_local
);
10570 g
= htab
->got_info
;
10571 BFD_ASSERT (g
!= NULL
);
10573 /* Run through the global symbol table, creating GOT entries for all
10574 the symbols that need them. */
10575 if (hmips
->global_got_area
!= GGA_NONE
)
10580 value
= sym
->st_value
;
10581 offset
= mips_elf_primary_global_got_index (output_bfd
, info
, h
);
10582 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
10585 if (hmips
->global_got_area
!= GGA_NONE
&& g
->next
)
10587 struct mips_got_entry e
, *p
;
10593 e
.abfd
= output_bfd
;
10596 e
.tls_type
= GOT_TLS_NONE
;
10598 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
10601 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
10604 offset
= p
->gotidx
;
10605 BFD_ASSERT (offset
> 0 && offset
< htab
->sgot
->size
);
10607 || (elf_hash_table (info
)->dynamic_sections_created
10609 && p
->d
.h
->root
.def_dynamic
10610 && !p
->d
.h
->root
.def_regular
))
10612 /* Create an R_MIPS_REL32 relocation for this entry. Due to
10613 the various compatibility problems, it's easier to mock
10614 up an R_MIPS_32 or R_MIPS_64 relocation and leave
10615 mips_elf_create_dynamic_relocation to calculate the
10616 appropriate addend. */
10617 Elf_Internal_Rela rel
[3];
10619 memset (rel
, 0, sizeof (rel
));
10620 if (ABI_64_P (output_bfd
))
10621 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
10623 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
10624 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
10627 if (! (mips_elf_create_dynamic_relocation
10628 (output_bfd
, info
, rel
,
10629 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
10633 entry
= sym
->st_value
;
10634 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
10639 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
10640 name
= h
->root
.root
.string
;
10641 if (h
== elf_hash_table (info
)->hdynamic
10642 || h
== elf_hash_table (info
)->hgot
)
10643 sym
->st_shndx
= SHN_ABS
;
10644 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
10645 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
10647 sym
->st_shndx
= SHN_ABS
;
10648 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
10651 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
10653 sym
->st_shndx
= SHN_ABS
;
10654 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
10655 sym
->st_value
= elf_gp (output_bfd
);
10657 else if (SGI_COMPAT (output_bfd
))
10659 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
10660 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
10662 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
10663 sym
->st_other
= STO_PROTECTED
;
10665 sym
->st_shndx
= SHN_MIPS_DATA
;
10667 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
10669 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
10670 sym
->st_other
= STO_PROTECTED
;
10671 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
10672 sym
->st_shndx
= SHN_ABS
;
10674 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
10676 if (h
->type
== STT_FUNC
)
10677 sym
->st_shndx
= SHN_MIPS_TEXT
;
10678 else if (h
->type
== STT_OBJECT
)
10679 sym
->st_shndx
= SHN_MIPS_DATA
;
10683 /* Emit a copy reloc, if needed. */
10689 BFD_ASSERT (h
->dynindx
!= -1);
10690 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10692 s
= mips_elf_rel_dyn_section (info
, FALSE
);
10693 symval
= (h
->root
.u
.def
.section
->output_section
->vma
10694 + h
->root
.u
.def
.section
->output_offset
10695 + h
->root
.u
.def
.value
);
10696 mips_elf_output_dynamic_relocation (output_bfd
, s
, s
->reloc_count
++,
10697 h
->dynindx
, R_MIPS_COPY
, symval
);
10700 /* Handle the IRIX6-specific symbols. */
10701 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
10702 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
10704 /* Keep dynamic compressed symbols odd. This allows the dynamic linker
10705 to treat compressed symbols like any other. */
10706 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
10708 BFD_ASSERT (sym
->st_value
& 1);
10709 sym
->st_other
-= STO_MIPS16
;
10711 else if (ELF_ST_IS_MICROMIPS (sym
->st_other
))
10713 BFD_ASSERT (sym
->st_value
& 1);
10714 sym
->st_other
-= STO_MICROMIPS
;
10720 /* Likewise, for VxWorks. */
10723 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
10724 struct bfd_link_info
*info
,
10725 struct elf_link_hash_entry
*h
,
10726 Elf_Internal_Sym
*sym
)
10730 struct mips_got_info
*g
;
10731 struct mips_elf_link_hash_table
*htab
;
10732 struct mips_elf_link_hash_entry
*hmips
;
10734 htab
= mips_elf_hash_table (info
);
10735 BFD_ASSERT (htab
!= NULL
);
10736 dynobj
= elf_hash_table (info
)->dynobj
;
10737 hmips
= (struct mips_elf_link_hash_entry
*) h
;
10739 if (h
->plt
.plist
!= NULL
&& h
->plt
.plist
->mips_offset
!= MINUS_ONE
)
10742 bfd_vma plt_address
, got_address
, got_offset
, branch_offset
;
10743 Elf_Internal_Rela rel
;
10744 static const bfd_vma
*plt_entry
;
10745 bfd_vma gotplt_index
;
10746 bfd_vma plt_offset
;
10748 plt_offset
= htab
->plt_header_size
+ h
->plt
.plist
->mips_offset
;
10749 gotplt_index
= h
->plt
.plist
->gotplt_index
;
10751 BFD_ASSERT (h
->dynindx
!= -1);
10752 BFD_ASSERT (htab
->splt
!= NULL
);
10753 BFD_ASSERT (gotplt_index
!= MINUS_ONE
);
10754 BFD_ASSERT (plt_offset
<= htab
->splt
->size
);
10756 /* Calculate the address of the .plt entry. */
10757 plt_address
= (htab
->splt
->output_section
->vma
10758 + htab
->splt
->output_offset
10761 /* Calculate the address of the .got.plt entry. */
10762 got_address
= (htab
->sgotplt
->output_section
->vma
10763 + htab
->sgotplt
->output_offset
10764 + gotplt_index
* MIPS_ELF_GOT_SIZE (output_bfd
));
10766 /* Calculate the offset of the .got.plt entry from
10767 _GLOBAL_OFFSET_TABLE_. */
10768 got_offset
= mips_elf_gotplt_index (info
, h
);
10770 /* Calculate the offset for the branch at the start of the PLT
10771 entry. The branch jumps to the beginning of .plt. */
10772 branch_offset
= -(plt_offset
/ 4 + 1) & 0xffff;
10774 /* Fill in the initial value of the .got.plt entry. */
10775 bfd_put_32 (output_bfd
, plt_address
,
10776 (htab
->sgotplt
->contents
10777 + gotplt_index
* MIPS_ELF_GOT_SIZE (output_bfd
)));
10779 /* Find out where the .plt entry should go. */
10780 loc
= htab
->splt
->contents
+ plt_offset
;
10784 plt_entry
= mips_vxworks_shared_plt_entry
;
10785 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
10786 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_index
, loc
+ 4);
10790 bfd_vma got_address_high
, got_address_low
;
10792 plt_entry
= mips_vxworks_exec_plt_entry
;
10793 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
10794 got_address_low
= got_address
& 0xffff;
10796 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
10797 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_index
, loc
+ 4);
10798 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
10799 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
10800 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
10801 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
10802 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
10803 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
10805 loc
= (htab
->srelplt2
->contents
10806 + (gotplt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
10808 /* Emit a relocation for the .got.plt entry. */
10809 rel
.r_offset
= got_address
;
10810 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
10811 rel
.r_addend
= plt_offset
;
10812 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
10814 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
10815 loc
+= sizeof (Elf32_External_Rela
);
10816 rel
.r_offset
= plt_address
+ 8;
10817 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
10818 rel
.r_addend
= got_offset
;
10819 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
10821 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
10822 loc
+= sizeof (Elf32_External_Rela
);
10824 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
10825 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
10828 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
10829 loc
= (htab
->srelplt
->contents
10830 + gotplt_index
* sizeof (Elf32_External_Rela
));
10831 rel
.r_offset
= got_address
;
10832 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
10834 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
10836 if (!h
->def_regular
)
10837 sym
->st_shndx
= SHN_UNDEF
;
10840 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
10843 g
= htab
->got_info
;
10844 BFD_ASSERT (g
!= NULL
);
10846 /* See if this symbol has an entry in the GOT. */
10847 if (hmips
->global_got_area
!= GGA_NONE
)
10850 Elf_Internal_Rela outrel
;
10854 /* Install the symbol value in the GOT. */
10855 offset
= mips_elf_primary_global_got_index (output_bfd
, info
, h
);
10856 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
10858 /* Add a dynamic relocation for it. */
10859 s
= mips_elf_rel_dyn_section (info
, FALSE
);
10860 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
10861 outrel
.r_offset
= (sgot
->output_section
->vma
10862 + sgot
->output_offset
10864 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
10865 outrel
.r_addend
= 0;
10866 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
10869 /* Emit a copy reloc, if needed. */
10872 Elf_Internal_Rela rel
;
10874 BFD_ASSERT (h
->dynindx
!= -1);
10876 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
10877 + h
->root
.u
.def
.section
->output_offset
10878 + h
->root
.u
.def
.value
);
10879 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
10881 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
10882 htab
->srelbss
->contents
10883 + (htab
->srelbss
->reloc_count
10884 * sizeof (Elf32_External_Rela
)));
10885 ++htab
->srelbss
->reloc_count
;
10888 /* If this is a mips16/microMIPS symbol, force the value to be even. */
10889 if (ELF_ST_IS_COMPRESSED (sym
->st_other
))
10890 sym
->st_value
&= ~1;
10895 /* Write out a plt0 entry to the beginning of .plt. */
10898 mips_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
10901 bfd_vma gotplt_value
, gotplt_value_high
, gotplt_value_low
;
10902 static const bfd_vma
*plt_entry
;
10903 struct mips_elf_link_hash_table
*htab
;
10905 htab
= mips_elf_hash_table (info
);
10906 BFD_ASSERT (htab
!= NULL
);
10908 if (ABI_64_P (output_bfd
))
10909 plt_entry
= mips_n64_exec_plt0_entry
;
10910 else if (ABI_N32_P (output_bfd
))
10911 plt_entry
= mips_n32_exec_plt0_entry
;
10912 else if (!htab
->plt_header_is_comp
)
10913 plt_entry
= mips_o32_exec_plt0_entry
;
10914 else if (htab
->insn32
)
10915 plt_entry
= micromips_insn32_o32_exec_plt0_entry
;
10917 plt_entry
= micromips_o32_exec_plt0_entry
;
10919 /* Calculate the value of .got.plt. */
10920 gotplt_value
= (htab
->sgotplt
->output_section
->vma
10921 + htab
->sgotplt
->output_offset
);
10922 gotplt_value_high
= ((gotplt_value
+ 0x8000) >> 16) & 0xffff;
10923 gotplt_value_low
= gotplt_value
& 0xffff;
10925 /* The PLT sequence is not safe for N64 if .got.plt's address can
10926 not be loaded in two instructions. */
10927 BFD_ASSERT ((gotplt_value
& ~(bfd_vma
) 0x7fffffff) == 0
10928 || ~(gotplt_value
| 0x7fffffff) == 0);
10930 /* Install the PLT header. */
10931 loc
= htab
->splt
->contents
;
10932 if (plt_entry
== micromips_o32_exec_plt0_entry
)
10934 bfd_vma gotpc_offset
;
10935 bfd_vma loc_address
;
10938 BFD_ASSERT (gotplt_value
% 4 == 0);
10940 loc_address
= (htab
->splt
->output_section
->vma
10941 + htab
->splt
->output_offset
);
10942 gotpc_offset
= gotplt_value
- ((loc_address
| 3) ^ 3);
10944 /* ADDIUPC has a span of +/-16MB, check we're in range. */
10945 if (gotpc_offset
+ 0x1000000 >= 0x2000000)
10947 (*_bfd_error_handler
)
10948 (_("%B: `%A' offset of %ld from `%A' beyond the range of ADDIUPC"),
10950 htab
->sgotplt
->output_section
,
10951 htab
->splt
->output_section
,
10952 (long) gotpc_offset
);
10953 bfd_set_error (bfd_error_no_error
);
10956 bfd_put_16 (output_bfd
,
10957 plt_entry
[0] | ((gotpc_offset
>> 18) & 0x7f), loc
);
10958 bfd_put_16 (output_bfd
, (gotpc_offset
>> 2) & 0xffff, loc
+ 2);
10959 for (i
= 2; i
< ARRAY_SIZE (micromips_o32_exec_plt0_entry
); i
++)
10960 bfd_put_16 (output_bfd
, plt_entry
[i
], loc
+ (i
* 2));
10962 else if (plt_entry
== micromips_insn32_o32_exec_plt0_entry
)
10966 bfd_put_16 (output_bfd
, plt_entry
[0], loc
);
10967 bfd_put_16 (output_bfd
, gotplt_value_high
, loc
+ 2);
10968 bfd_put_16 (output_bfd
, plt_entry
[2], loc
+ 4);
10969 bfd_put_16 (output_bfd
, gotplt_value_low
, loc
+ 6);
10970 bfd_put_16 (output_bfd
, plt_entry
[4], loc
+ 8);
10971 bfd_put_16 (output_bfd
, gotplt_value_low
, loc
+ 10);
10972 for (i
= 6; i
< ARRAY_SIZE (micromips_insn32_o32_exec_plt0_entry
); i
++)
10973 bfd_put_16 (output_bfd
, plt_entry
[i
], loc
+ (i
* 2));
10977 bfd_put_32 (output_bfd
, plt_entry
[0] | gotplt_value_high
, loc
);
10978 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_value_low
, loc
+ 4);
10979 bfd_put_32 (output_bfd
, plt_entry
[2] | gotplt_value_low
, loc
+ 8);
10980 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
10981 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
10982 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
10983 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
10984 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
10990 /* Install the PLT header for a VxWorks executable and finalize the
10991 contents of .rela.plt.unloaded. */
10994 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
10996 Elf_Internal_Rela rela
;
10998 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
10999 static const bfd_vma
*plt_entry
;
11000 struct mips_elf_link_hash_table
*htab
;
11002 htab
= mips_elf_hash_table (info
);
11003 BFD_ASSERT (htab
!= NULL
);
11005 plt_entry
= mips_vxworks_exec_plt0_entry
;
11007 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
11008 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
11009 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
11010 + htab
->root
.hgot
->root
.u
.def
.value
);
11012 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
11013 got_value_low
= got_value
& 0xffff;
11015 /* Calculate the address of the PLT header. */
11016 plt_address
= htab
->splt
->output_section
->vma
+ htab
->splt
->output_offset
;
11018 /* Install the PLT header. */
11019 loc
= htab
->splt
->contents
;
11020 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
11021 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
11022 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
11023 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
11024 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
11025 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
11027 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
11028 loc
= htab
->srelplt2
->contents
;
11029 rela
.r_offset
= plt_address
;
11030 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
11032 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
11033 loc
+= sizeof (Elf32_External_Rela
);
11035 /* Output the relocation for the following addiu of
11036 %lo(_GLOBAL_OFFSET_TABLE_). */
11037 rela
.r_offset
+= 4;
11038 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
11039 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
11040 loc
+= sizeof (Elf32_External_Rela
);
11042 /* Fix up the remaining relocations. They may have the wrong
11043 symbol index for _G_O_T_ or _P_L_T_ depending on the order
11044 in which symbols were output. */
11045 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
11047 Elf_Internal_Rela rel
;
11049 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
11050 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
11051 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11052 loc
+= sizeof (Elf32_External_Rela
);
11054 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
11055 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
11056 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11057 loc
+= sizeof (Elf32_External_Rela
);
11059 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
11060 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
11061 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
11062 loc
+= sizeof (Elf32_External_Rela
);
11066 /* Install the PLT header for a VxWorks shared library. */
11069 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
11072 struct mips_elf_link_hash_table
*htab
;
11074 htab
= mips_elf_hash_table (info
);
11075 BFD_ASSERT (htab
!= NULL
);
11077 /* We just need to copy the entry byte-by-byte. */
11078 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
11079 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
11080 htab
->splt
->contents
+ i
* 4);
11083 /* Finish up the dynamic sections. */
11086 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
11087 struct bfd_link_info
*info
)
11092 struct mips_got_info
*gg
, *g
;
11093 struct mips_elf_link_hash_table
*htab
;
11095 htab
= mips_elf_hash_table (info
);
11096 BFD_ASSERT (htab
!= NULL
);
11098 dynobj
= elf_hash_table (info
)->dynobj
;
11100 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
11103 gg
= htab
->got_info
;
11105 if (elf_hash_table (info
)->dynamic_sections_created
)
11108 int dyn_to_skip
= 0, dyn_skipped
= 0;
11110 BFD_ASSERT (sdyn
!= NULL
);
11111 BFD_ASSERT (gg
!= NULL
);
11113 g
= mips_elf_bfd_got (output_bfd
, FALSE
);
11114 BFD_ASSERT (g
!= NULL
);
11116 for (b
= sdyn
->contents
;
11117 b
< sdyn
->contents
+ sdyn
->size
;
11118 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
11120 Elf_Internal_Dyn dyn
;
11124 bfd_boolean swap_out_p
;
11126 /* Read in the current dynamic entry. */
11127 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
11129 /* Assume that we're going to modify it and write it out. */
11135 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
11139 BFD_ASSERT (htab
->is_vxworks
);
11140 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
11144 /* Rewrite DT_STRSZ. */
11146 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
11151 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11154 case DT_MIPS_PLTGOT
:
11156 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11159 case DT_MIPS_RLD_VERSION
:
11160 dyn
.d_un
.d_val
= 1; /* XXX */
11163 case DT_MIPS_FLAGS
:
11164 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
11167 case DT_MIPS_TIME_STAMP
:
11171 dyn
.d_un
.d_val
= t
;
11175 case DT_MIPS_ICHECKSUM
:
11177 swap_out_p
= FALSE
;
11180 case DT_MIPS_IVERSION
:
11182 swap_out_p
= FALSE
;
11185 case DT_MIPS_BASE_ADDRESS
:
11186 s
= output_bfd
->sections
;
11187 BFD_ASSERT (s
!= NULL
);
11188 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
11191 case DT_MIPS_LOCAL_GOTNO
:
11192 dyn
.d_un
.d_val
= g
->local_gotno
;
11195 case DT_MIPS_UNREFEXTNO
:
11196 /* The index into the dynamic symbol table which is the
11197 entry of the first external symbol that is not
11198 referenced within the same object. */
11199 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
11202 case DT_MIPS_GOTSYM
:
11203 if (htab
->global_gotsym
)
11205 dyn
.d_un
.d_val
= htab
->global_gotsym
->dynindx
;
11208 /* In case if we don't have global got symbols we default
11209 to setting DT_MIPS_GOTSYM to the same value as
11210 DT_MIPS_SYMTABNO, so we just fall through. */
11212 case DT_MIPS_SYMTABNO
:
11214 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
11215 s
= bfd_get_section_by_name (output_bfd
, name
);
11216 BFD_ASSERT (s
!= NULL
);
11218 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
11221 case DT_MIPS_HIPAGENO
:
11222 dyn
.d_un
.d_val
= g
->local_gotno
- htab
->reserved_gotno
;
11225 case DT_MIPS_RLD_MAP
:
11227 struct elf_link_hash_entry
*h
;
11228 h
= mips_elf_hash_table (info
)->rld_symbol
;
11231 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
11232 swap_out_p
= FALSE
;
11235 s
= h
->root
.u
.def
.section
;
11236 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
11237 + h
->root
.u
.def
.value
);
11241 case DT_MIPS_OPTIONS
:
11242 s
= (bfd_get_section_by_name
11243 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
11244 dyn
.d_un
.d_ptr
= s
->vma
;
11248 BFD_ASSERT (htab
->is_vxworks
);
11249 /* The count does not include the JUMP_SLOT relocations. */
11251 dyn
.d_un
.d_val
-= htab
->srelplt
->size
;
11255 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11256 if (htab
->is_vxworks
)
11257 dyn
.d_un
.d_val
= DT_RELA
;
11259 dyn
.d_un
.d_val
= DT_REL
;
11263 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11264 dyn
.d_un
.d_val
= htab
->srelplt
->size
;
11268 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
11269 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
11270 + htab
->srelplt
->output_offset
);
11274 /* If we didn't need any text relocations after all, delete
11275 the dynamic tag. */
11276 if (!(info
->flags
& DF_TEXTREL
))
11278 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
11279 swap_out_p
= FALSE
;
11284 /* If we didn't need any text relocations after all, clear
11285 DF_TEXTREL from DT_FLAGS. */
11286 if (!(info
->flags
& DF_TEXTREL
))
11287 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
11289 swap_out_p
= FALSE
;
11293 swap_out_p
= FALSE
;
11294 if (htab
->is_vxworks
11295 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
11300 if (swap_out_p
|| dyn_skipped
)
11301 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
11302 (dynobj
, &dyn
, b
- dyn_skipped
);
11306 dyn_skipped
+= dyn_to_skip
;
11311 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
11312 if (dyn_skipped
> 0)
11313 memset (b
- dyn_skipped
, 0, dyn_skipped
);
11316 if (sgot
!= NULL
&& sgot
->size
> 0
11317 && !bfd_is_abs_section (sgot
->output_section
))
11319 if (htab
->is_vxworks
)
11321 /* The first entry of the global offset table points to the
11322 ".dynamic" section. The second is initialized by the
11323 loader and contains the shared library identifier.
11324 The third is also initialized by the loader and points
11325 to the lazy resolution stub. */
11326 MIPS_ELF_PUT_WORD (output_bfd
,
11327 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
11329 MIPS_ELF_PUT_WORD (output_bfd
, 0,
11330 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
11331 MIPS_ELF_PUT_WORD (output_bfd
, 0,
11333 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
11337 /* The first entry of the global offset table will be filled at
11338 runtime. The second entry will be used by some runtime loaders.
11339 This isn't the case of IRIX rld. */
11340 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
11341 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
11342 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
11345 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
11346 = MIPS_ELF_GOT_SIZE (output_bfd
);
11349 /* Generate dynamic relocations for the non-primary gots. */
11350 if (gg
!= NULL
&& gg
->next
)
11352 Elf_Internal_Rela rel
[3];
11353 bfd_vma addend
= 0;
11355 memset (rel
, 0, sizeof (rel
));
11356 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
11358 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
11360 bfd_vma got_index
= g
->next
->local_gotno
+ g
->next
->global_gotno
11361 + g
->next
->tls_gotno
;
11363 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
11364 + got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
11365 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
11367 + got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
11369 if (! info
->shared
)
11372 while (got_index
< g
->assigned_gotno
)
11374 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
11375 = got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
11376 if (!(mips_elf_create_dynamic_relocation
11377 (output_bfd
, info
, rel
, NULL
,
11378 bfd_abs_section_ptr
,
11379 0, &addend
, sgot
)))
11381 BFD_ASSERT (addend
== 0);
11386 /* The generation of dynamic relocations for the non-primary gots
11387 adds more dynamic relocations. We cannot count them until
11390 if (elf_hash_table (info
)->dynamic_sections_created
)
11393 bfd_boolean swap_out_p
;
11395 BFD_ASSERT (sdyn
!= NULL
);
11397 for (b
= sdyn
->contents
;
11398 b
< sdyn
->contents
+ sdyn
->size
;
11399 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
11401 Elf_Internal_Dyn dyn
;
11404 /* Read in the current dynamic entry. */
11405 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
11407 /* Assume that we're going to modify it and write it out. */
11413 /* Reduce DT_RELSZ to account for any relocations we
11414 decided not to make. This is for the n64 irix rld,
11415 which doesn't seem to apply any relocations if there
11416 are trailing null entries. */
11417 s
= mips_elf_rel_dyn_section (info
, FALSE
);
11418 dyn
.d_un
.d_val
= (s
->reloc_count
11419 * (ABI_64_P (output_bfd
)
11420 ? sizeof (Elf64_Mips_External_Rel
)
11421 : sizeof (Elf32_External_Rel
)));
11422 /* Adjust the section size too. Tools like the prelinker
11423 can reasonably expect the values to the same. */
11424 elf_section_data (s
->output_section
)->this_hdr
.sh_size
11429 swap_out_p
= FALSE
;
11434 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
11441 Elf32_compact_rel cpt
;
11443 if (SGI_COMPAT (output_bfd
))
11445 /* Write .compact_rel section out. */
11446 s
= bfd_get_linker_section (dynobj
, ".compact_rel");
11450 cpt
.num
= s
->reloc_count
;
11452 cpt
.offset
= (s
->output_section
->filepos
11453 + sizeof (Elf32_External_compact_rel
));
11456 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
11457 ((Elf32_External_compact_rel
*)
11460 /* Clean up a dummy stub function entry in .text. */
11461 if (htab
->sstubs
!= NULL
)
11463 file_ptr dummy_offset
;
11465 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
11466 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
11467 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
11468 htab
->function_stub_size
);
11473 /* The psABI says that the dynamic relocations must be sorted in
11474 increasing order of r_symndx. The VxWorks EABI doesn't require
11475 this, and because the code below handles REL rather than RELA
11476 relocations, using it for VxWorks would be outright harmful. */
11477 if (!htab
->is_vxworks
)
11479 s
= mips_elf_rel_dyn_section (info
, FALSE
);
11481 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
11483 reldyn_sorting_bfd
= output_bfd
;
11485 if (ABI_64_P (output_bfd
))
11486 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
11487 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
11488 sort_dynamic_relocs_64
);
11490 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
11491 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
11492 sort_dynamic_relocs
);
11497 if (htab
->splt
&& htab
->splt
->size
> 0)
11499 if (htab
->is_vxworks
)
11502 mips_vxworks_finish_shared_plt (output_bfd
, info
);
11504 mips_vxworks_finish_exec_plt (output_bfd
, info
);
11508 BFD_ASSERT (!info
->shared
);
11509 if (!mips_finish_exec_plt (output_bfd
, info
))
11517 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
11520 mips_set_isa_flags (bfd
*abfd
)
11524 switch (bfd_get_mach (abfd
))
11527 case bfd_mach_mips3000
:
11528 val
= E_MIPS_ARCH_1
;
11531 case bfd_mach_mips3900
:
11532 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
11535 case bfd_mach_mips6000
:
11536 val
= E_MIPS_ARCH_2
;
11539 case bfd_mach_mips4000
:
11540 case bfd_mach_mips4300
:
11541 case bfd_mach_mips4400
:
11542 case bfd_mach_mips4600
:
11543 val
= E_MIPS_ARCH_3
;
11546 case bfd_mach_mips4010
:
11547 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
11550 case bfd_mach_mips4100
:
11551 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
11554 case bfd_mach_mips4111
:
11555 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
11558 case bfd_mach_mips4120
:
11559 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
11562 case bfd_mach_mips4650
:
11563 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
11566 case bfd_mach_mips5400
:
11567 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
11570 case bfd_mach_mips5500
:
11571 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
11574 case bfd_mach_mips5900
:
11575 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_5900
;
11578 case bfd_mach_mips9000
:
11579 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
11582 case bfd_mach_mips5000
:
11583 case bfd_mach_mips7000
:
11584 case bfd_mach_mips8000
:
11585 case bfd_mach_mips10000
:
11586 case bfd_mach_mips12000
:
11587 case bfd_mach_mips14000
:
11588 case bfd_mach_mips16000
:
11589 val
= E_MIPS_ARCH_4
;
11592 case bfd_mach_mips5
:
11593 val
= E_MIPS_ARCH_5
;
11596 case bfd_mach_mips_loongson_2e
:
11597 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
11600 case bfd_mach_mips_loongson_2f
:
11601 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
11604 case bfd_mach_mips_sb1
:
11605 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
11608 case bfd_mach_mips_loongson_3a
:
11609 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_LS3A
;
11612 case bfd_mach_mips_octeon
:
11613 case bfd_mach_mips_octeonp
:
11614 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
11617 case bfd_mach_mips_xlr
:
11618 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_XLR
;
11621 case bfd_mach_mips_octeon2
:
11622 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON2
;
11625 case bfd_mach_mipsisa32
:
11626 val
= E_MIPS_ARCH_32
;
11629 case bfd_mach_mipsisa64
:
11630 val
= E_MIPS_ARCH_64
;
11633 case bfd_mach_mipsisa32r2
:
11634 val
= E_MIPS_ARCH_32R2
;
11637 case bfd_mach_mipsisa64r2
:
11638 val
= E_MIPS_ARCH_64R2
;
11641 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
11642 elf_elfheader (abfd
)->e_flags
|= val
;
11647 /* The final processing done just before writing out a MIPS ELF object
11648 file. This gets the MIPS architecture right based on the machine
11649 number. This is used by both the 32-bit and the 64-bit ABI. */
11652 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
11653 bfd_boolean linker ATTRIBUTE_UNUSED
)
11656 Elf_Internal_Shdr
**hdrpp
;
11660 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
11661 is nonzero. This is for compatibility with old objects, which used
11662 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
11663 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
11664 mips_set_isa_flags (abfd
);
11666 /* Set the sh_info field for .gptab sections and other appropriate
11667 info for each special section. */
11668 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
11669 i
< elf_numsections (abfd
);
11672 switch ((*hdrpp
)->sh_type
)
11674 case SHT_MIPS_MSYM
:
11675 case SHT_MIPS_LIBLIST
:
11676 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
11678 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
11681 case SHT_MIPS_GPTAB
:
11682 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
11683 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
11684 BFD_ASSERT (name
!= NULL
11685 && CONST_STRNEQ (name
, ".gptab."));
11686 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
11687 BFD_ASSERT (sec
!= NULL
);
11688 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
11691 case SHT_MIPS_CONTENT
:
11692 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
11693 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
11694 BFD_ASSERT (name
!= NULL
11695 && CONST_STRNEQ (name
, ".MIPS.content"));
11696 sec
= bfd_get_section_by_name (abfd
,
11697 name
+ sizeof ".MIPS.content" - 1);
11698 BFD_ASSERT (sec
!= NULL
);
11699 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
11702 case SHT_MIPS_SYMBOL_LIB
:
11703 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
11705 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
11706 sec
= bfd_get_section_by_name (abfd
, ".liblist");
11708 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
11711 case SHT_MIPS_EVENTS
:
11712 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
11713 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
11714 BFD_ASSERT (name
!= NULL
);
11715 if (CONST_STRNEQ (name
, ".MIPS.events"))
11716 sec
= bfd_get_section_by_name (abfd
,
11717 name
+ sizeof ".MIPS.events" - 1);
11720 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
11721 sec
= bfd_get_section_by_name (abfd
,
11723 + sizeof ".MIPS.post_rel" - 1));
11725 BFD_ASSERT (sec
!= NULL
);
11726 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
11733 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
11737 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
11738 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
11743 /* See if we need a PT_MIPS_REGINFO segment. */
11744 s
= bfd_get_section_by_name (abfd
, ".reginfo");
11745 if (s
&& (s
->flags
& SEC_LOAD
))
11748 /* See if we need a PT_MIPS_OPTIONS segment. */
11749 if (IRIX_COMPAT (abfd
) == ict_irix6
11750 && bfd_get_section_by_name (abfd
,
11751 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
11754 /* See if we need a PT_MIPS_RTPROC segment. */
11755 if (IRIX_COMPAT (abfd
) == ict_irix5
11756 && bfd_get_section_by_name (abfd
, ".dynamic")
11757 && bfd_get_section_by_name (abfd
, ".mdebug"))
11760 /* Allocate a PT_NULL header in dynamic objects. See
11761 _bfd_mips_elf_modify_segment_map for details. */
11762 if (!SGI_COMPAT (abfd
)
11763 && bfd_get_section_by_name (abfd
, ".dynamic"))
11769 /* Modify the segment map for an IRIX5 executable. */
11772 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
11773 struct bfd_link_info
*info
)
11776 struct elf_segment_map
*m
, **pm
;
11779 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
11781 s
= bfd_get_section_by_name (abfd
, ".reginfo");
11782 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
11784 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
11785 if (m
->p_type
== PT_MIPS_REGINFO
)
11790 m
= bfd_zalloc (abfd
, amt
);
11794 m
->p_type
= PT_MIPS_REGINFO
;
11796 m
->sections
[0] = s
;
11798 /* We want to put it after the PHDR and INTERP segments. */
11799 pm
= &elf_seg_map (abfd
);
11801 && ((*pm
)->p_type
== PT_PHDR
11802 || (*pm
)->p_type
== PT_INTERP
))
11810 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
11811 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
11812 PT_MIPS_OPTIONS segment immediately following the program header
11814 if (NEWABI_P (abfd
)
11815 /* On non-IRIX6 new abi, we'll have already created a segment
11816 for this section, so don't create another. I'm not sure this
11817 is not also the case for IRIX 6, but I can't test it right
11819 && IRIX_COMPAT (abfd
) == ict_irix6
)
11821 for (s
= abfd
->sections
; s
; s
= s
->next
)
11822 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
11827 struct elf_segment_map
*options_segment
;
11829 pm
= &elf_seg_map (abfd
);
11831 && ((*pm
)->p_type
== PT_PHDR
11832 || (*pm
)->p_type
== PT_INTERP
))
11835 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
11837 amt
= sizeof (struct elf_segment_map
);
11838 options_segment
= bfd_zalloc (abfd
, amt
);
11839 options_segment
->next
= *pm
;
11840 options_segment
->p_type
= PT_MIPS_OPTIONS
;
11841 options_segment
->p_flags
= PF_R
;
11842 options_segment
->p_flags_valid
= TRUE
;
11843 options_segment
->count
= 1;
11844 options_segment
->sections
[0] = s
;
11845 *pm
= options_segment
;
11851 if (IRIX_COMPAT (abfd
) == ict_irix5
)
11853 /* If there are .dynamic and .mdebug sections, we make a room
11854 for the RTPROC header. FIXME: Rewrite without section names. */
11855 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
11856 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
11857 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
11859 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
11860 if (m
->p_type
== PT_MIPS_RTPROC
)
11865 m
= bfd_zalloc (abfd
, amt
);
11869 m
->p_type
= PT_MIPS_RTPROC
;
11871 s
= bfd_get_section_by_name (abfd
, ".rtproc");
11876 m
->p_flags_valid
= 1;
11881 m
->sections
[0] = s
;
11884 /* We want to put it after the DYNAMIC segment. */
11885 pm
= &elf_seg_map (abfd
);
11886 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
11896 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
11897 .dynstr, .dynsym, and .hash sections, and everything in
11899 for (pm
= &elf_seg_map (abfd
); *pm
!= NULL
;
11901 if ((*pm
)->p_type
== PT_DYNAMIC
)
11904 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
11906 /* For a normal mips executable the permissions for the PT_DYNAMIC
11907 segment are read, write and execute. We do that here since
11908 the code in elf.c sets only the read permission. This matters
11909 sometimes for the dynamic linker. */
11910 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
11912 m
->p_flags
= PF_R
| PF_W
| PF_X
;
11913 m
->p_flags_valid
= 1;
11916 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
11917 glibc's dynamic linker has traditionally derived the number of
11918 tags from the p_filesz field, and sometimes allocates stack
11919 arrays of that size. An overly-big PT_DYNAMIC segment can
11920 be actively harmful in such cases. Making PT_DYNAMIC contain
11921 other sections can also make life hard for the prelinker,
11922 which might move one of the other sections to a different
11923 PT_LOAD segment. */
11924 if (SGI_COMPAT (abfd
)
11927 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
11929 static const char *sec_names
[] =
11931 ".dynamic", ".dynstr", ".dynsym", ".hash"
11935 struct elf_segment_map
*n
;
11937 low
= ~(bfd_vma
) 0;
11939 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
11941 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
11942 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
11949 if (high
< s
->vma
+ sz
)
11950 high
= s
->vma
+ sz
;
11955 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
11956 if ((s
->flags
& SEC_LOAD
) != 0
11958 && s
->vma
+ s
->size
<= high
)
11961 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
11962 n
= bfd_zalloc (abfd
, amt
);
11969 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
11971 if ((s
->flags
& SEC_LOAD
) != 0
11973 && s
->vma
+ s
->size
<= high
)
11975 n
->sections
[i
] = s
;
11984 /* Allocate a spare program header in dynamic objects so that tools
11985 like the prelinker can add an extra PT_LOAD entry.
11987 If the prelinker needs to make room for a new PT_LOAD entry, its
11988 standard procedure is to move the first (read-only) sections into
11989 the new (writable) segment. However, the MIPS ABI requires
11990 .dynamic to be in a read-only segment, and the section will often
11991 start within sizeof (ElfNN_Phdr) bytes of the last program header.
11993 Although the prelinker could in principle move .dynamic to a
11994 writable segment, it seems better to allocate a spare program
11995 header instead, and avoid the need to move any sections.
11996 There is a long tradition of allocating spare dynamic tags,
11997 so allocating a spare program header seems like a natural
12000 If INFO is NULL, we may be copying an already prelinked binary
12001 with objcopy or strip, so do not add this header. */
12003 && !SGI_COMPAT (abfd
)
12004 && bfd_get_section_by_name (abfd
, ".dynamic"))
12006 for (pm
= &elf_seg_map (abfd
); *pm
!= NULL
; pm
= &(*pm
)->next
)
12007 if ((*pm
)->p_type
== PT_NULL
)
12011 m
= bfd_zalloc (abfd
, sizeof (*m
));
12015 m
->p_type
= PT_NULL
;
12023 /* Return the section that should be marked against GC for a given
12027 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
12028 struct bfd_link_info
*info
,
12029 Elf_Internal_Rela
*rel
,
12030 struct elf_link_hash_entry
*h
,
12031 Elf_Internal_Sym
*sym
)
12033 /* ??? Do mips16 stub sections need to be handled special? */
12036 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
12038 case R_MIPS_GNU_VTINHERIT
:
12039 case R_MIPS_GNU_VTENTRY
:
12043 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
12046 /* Update the got entry reference counts for the section being removed. */
12049 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
12050 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
12051 asection
*sec ATTRIBUTE_UNUSED
,
12052 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
12055 Elf_Internal_Shdr
*symtab_hdr
;
12056 struct elf_link_hash_entry
**sym_hashes
;
12057 bfd_signed_vma
*local_got_refcounts
;
12058 const Elf_Internal_Rela
*rel
, *relend
;
12059 unsigned long r_symndx
;
12060 struct elf_link_hash_entry
*h
;
12062 if (info
->relocatable
)
12065 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
12066 sym_hashes
= elf_sym_hashes (abfd
);
12067 local_got_refcounts
= elf_local_got_refcounts (abfd
);
12069 relend
= relocs
+ sec
->reloc_count
;
12070 for (rel
= relocs
; rel
< relend
; rel
++)
12071 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
12073 case R_MIPS16_GOT16
:
12074 case R_MIPS16_CALL16
:
12076 case R_MIPS_CALL16
:
12077 case R_MIPS_CALL_HI16
:
12078 case R_MIPS_CALL_LO16
:
12079 case R_MIPS_GOT_HI16
:
12080 case R_MIPS_GOT_LO16
:
12081 case R_MIPS_GOT_DISP
:
12082 case R_MIPS_GOT_PAGE
:
12083 case R_MIPS_GOT_OFST
:
12084 case R_MICROMIPS_GOT16
:
12085 case R_MICROMIPS_CALL16
:
12086 case R_MICROMIPS_CALL_HI16
:
12087 case R_MICROMIPS_CALL_LO16
:
12088 case R_MICROMIPS_GOT_HI16
:
12089 case R_MICROMIPS_GOT_LO16
:
12090 case R_MICROMIPS_GOT_DISP
:
12091 case R_MICROMIPS_GOT_PAGE
:
12092 case R_MICROMIPS_GOT_OFST
:
12093 /* ??? It would seem that the existing MIPS code does no sort
12094 of reference counting or whatnot on its GOT and PLT entries,
12095 so it is not possible to garbage collect them at this time. */
12106 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
12107 hiding the old indirect symbol. Process additional relocation
12108 information. Also called for weakdefs, in which case we just let
12109 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
12112 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
12113 struct elf_link_hash_entry
*dir
,
12114 struct elf_link_hash_entry
*ind
)
12116 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
12118 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
12120 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
12121 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
12122 /* Any absolute non-dynamic relocations against an indirect or weak
12123 definition will be against the target symbol. */
12124 if (indmips
->has_static_relocs
)
12125 dirmips
->has_static_relocs
= TRUE
;
12127 if (ind
->root
.type
!= bfd_link_hash_indirect
)
12130 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
12131 if (indmips
->readonly_reloc
)
12132 dirmips
->readonly_reloc
= TRUE
;
12133 if (indmips
->no_fn_stub
)
12134 dirmips
->no_fn_stub
= TRUE
;
12135 if (indmips
->fn_stub
)
12137 dirmips
->fn_stub
= indmips
->fn_stub
;
12138 indmips
->fn_stub
= NULL
;
12140 if (indmips
->need_fn_stub
)
12142 dirmips
->need_fn_stub
= TRUE
;
12143 indmips
->need_fn_stub
= FALSE
;
12145 if (indmips
->call_stub
)
12147 dirmips
->call_stub
= indmips
->call_stub
;
12148 indmips
->call_stub
= NULL
;
12150 if (indmips
->call_fp_stub
)
12152 dirmips
->call_fp_stub
= indmips
->call_fp_stub
;
12153 indmips
->call_fp_stub
= NULL
;
12155 if (indmips
->global_got_area
< dirmips
->global_got_area
)
12156 dirmips
->global_got_area
= indmips
->global_got_area
;
12157 if (indmips
->global_got_area
< GGA_NONE
)
12158 indmips
->global_got_area
= GGA_NONE
;
12159 if (indmips
->has_nonpic_branches
)
12160 dirmips
->has_nonpic_branches
= TRUE
;
12163 #define PDR_SIZE 32
12166 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
12167 struct bfd_link_info
*info
)
12170 bfd_boolean ret
= FALSE
;
12171 unsigned char *tdata
;
12174 o
= bfd_get_section_by_name (abfd
, ".pdr");
12179 if (o
->size
% PDR_SIZE
!= 0)
12181 if (o
->output_section
!= NULL
12182 && bfd_is_abs_section (o
->output_section
))
12185 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
12189 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
12190 info
->keep_memory
);
12197 cookie
->rel
= cookie
->rels
;
12198 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
12200 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
12202 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
12211 mips_elf_section_data (o
)->u
.tdata
= tdata
;
12212 o
->size
-= skip
* PDR_SIZE
;
12218 if (! info
->keep_memory
)
12219 free (cookie
->rels
);
12225 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
12227 if (strcmp (sec
->name
, ".pdr") == 0)
12233 _bfd_mips_elf_write_section (bfd
*output_bfd
,
12234 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
12235 asection
*sec
, bfd_byte
*contents
)
12237 bfd_byte
*to
, *from
, *end
;
12240 if (strcmp (sec
->name
, ".pdr") != 0)
12243 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
12247 end
= contents
+ sec
->size
;
12248 for (from
= contents
, i
= 0;
12250 from
+= PDR_SIZE
, i
++)
12252 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
12255 memcpy (to
, from
, PDR_SIZE
);
12258 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
12259 sec
->output_offset
, sec
->size
);
12263 /* microMIPS code retains local labels for linker relaxation. Omit them
12264 from output by default for clarity. */
12267 _bfd_mips_elf_is_target_special_symbol (bfd
*abfd
, asymbol
*sym
)
12269 return _bfd_elf_is_local_label_name (abfd
, sym
->name
);
12272 /* MIPS ELF uses a special find_nearest_line routine in order the
12273 handle the ECOFF debugging information. */
12275 struct mips_elf_find_line
12277 struct ecoff_debug_info d
;
12278 struct ecoff_find_line i
;
12282 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
12283 asymbol
**symbols
, bfd_vma offset
,
12284 const char **filename_ptr
,
12285 const char **functionname_ptr
,
12286 unsigned int *line_ptr
)
12290 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
12291 filename_ptr
, functionname_ptr
,
12295 if (_bfd_dwarf2_find_nearest_line (abfd
, dwarf_debug_sections
,
12296 section
, symbols
, offset
,
12297 filename_ptr
, functionname_ptr
,
12298 line_ptr
, NULL
, ABI_64_P (abfd
) ? 8 : 0,
12299 &elf_tdata (abfd
)->dwarf2_find_line_info
))
12302 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
12305 flagword origflags
;
12306 struct mips_elf_find_line
*fi
;
12307 const struct ecoff_debug_swap
* const swap
=
12308 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
12310 /* If we are called during a link, mips_elf_final_link may have
12311 cleared the SEC_HAS_CONTENTS field. We force it back on here
12312 if appropriate (which it normally will be). */
12313 origflags
= msec
->flags
;
12314 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
12315 msec
->flags
|= SEC_HAS_CONTENTS
;
12317 fi
= mips_elf_tdata (abfd
)->find_line_info
;
12320 bfd_size_type external_fdr_size
;
12323 struct fdr
*fdr_ptr
;
12324 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
12326 fi
= bfd_zalloc (abfd
, amt
);
12329 msec
->flags
= origflags
;
12333 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
12335 msec
->flags
= origflags
;
12339 /* Swap in the FDR information. */
12340 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
12341 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
12342 if (fi
->d
.fdr
== NULL
)
12344 msec
->flags
= origflags
;
12347 external_fdr_size
= swap
->external_fdr_size
;
12348 fdr_ptr
= fi
->d
.fdr
;
12349 fraw_src
= (char *) fi
->d
.external_fdr
;
12350 fraw_end
= (fraw_src
12351 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
12352 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
12353 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
12355 mips_elf_tdata (abfd
)->find_line_info
= fi
;
12357 /* Note that we don't bother to ever free this information.
12358 find_nearest_line is either called all the time, as in
12359 objdump -l, so the information should be saved, or it is
12360 rarely called, as in ld error messages, so the memory
12361 wasted is unimportant. Still, it would probably be a
12362 good idea for free_cached_info to throw it away. */
12365 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
12366 &fi
->i
, filename_ptr
, functionname_ptr
,
12369 msec
->flags
= origflags
;
12373 msec
->flags
= origflags
;
12376 /* Fall back on the generic ELF find_nearest_line routine. */
12378 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
12379 filename_ptr
, functionname_ptr
,
12384 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
12385 const char **filename_ptr
,
12386 const char **functionname_ptr
,
12387 unsigned int *line_ptr
)
12390 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
12391 functionname_ptr
, line_ptr
,
12392 & elf_tdata (abfd
)->dwarf2_find_line_info
);
12397 /* When are writing out the .options or .MIPS.options section,
12398 remember the bytes we are writing out, so that we can install the
12399 GP value in the section_processing routine. */
12402 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
12403 const void *location
,
12404 file_ptr offset
, bfd_size_type count
)
12406 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
12410 if (elf_section_data (section
) == NULL
)
12412 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
12413 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
12414 if (elf_section_data (section
) == NULL
)
12417 c
= mips_elf_section_data (section
)->u
.tdata
;
12420 c
= bfd_zalloc (abfd
, section
->size
);
12423 mips_elf_section_data (section
)->u
.tdata
= c
;
12426 memcpy (c
+ offset
, location
, count
);
12429 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
12433 /* This is almost identical to bfd_generic_get_... except that some
12434 MIPS relocations need to be handled specially. Sigh. */
12437 _bfd_elf_mips_get_relocated_section_contents
12439 struct bfd_link_info
*link_info
,
12440 struct bfd_link_order
*link_order
,
12442 bfd_boolean relocatable
,
12445 /* Get enough memory to hold the stuff */
12446 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
12447 asection
*input_section
= link_order
->u
.indirect
.section
;
12450 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
12451 arelent
**reloc_vector
= NULL
;
12454 if (reloc_size
< 0)
12457 reloc_vector
= bfd_malloc (reloc_size
);
12458 if (reloc_vector
== NULL
&& reloc_size
!= 0)
12461 /* read in the section */
12462 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
12463 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
12466 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
12470 if (reloc_count
< 0)
12473 if (reloc_count
> 0)
12478 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
12481 struct bfd_hash_entry
*h
;
12482 struct bfd_link_hash_entry
*lh
;
12483 /* Skip all this stuff if we aren't mixing formats. */
12484 if (abfd
&& input_bfd
12485 && abfd
->xvec
== input_bfd
->xvec
)
12489 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
12490 lh
= (struct bfd_link_hash_entry
*) h
;
12497 case bfd_link_hash_undefined
:
12498 case bfd_link_hash_undefweak
:
12499 case bfd_link_hash_common
:
12502 case bfd_link_hash_defined
:
12503 case bfd_link_hash_defweak
:
12505 gp
= lh
->u
.def
.value
;
12507 case bfd_link_hash_indirect
:
12508 case bfd_link_hash_warning
:
12510 /* @@FIXME ignoring warning for now */
12512 case bfd_link_hash_new
:
12521 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
12523 char *error_message
= NULL
;
12524 bfd_reloc_status_type r
;
12526 /* Specific to MIPS: Deal with relocation types that require
12527 knowing the gp of the output bfd. */
12528 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
12530 /* If we've managed to find the gp and have a special
12531 function for the relocation then go ahead, else default
12532 to the generic handling. */
12534 && (*parent
)->howto
->special_function
12535 == _bfd_mips_elf32_gprel16_reloc
)
12536 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
12537 input_section
, relocatable
,
12540 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
12542 relocatable
? abfd
: NULL
,
12547 asection
*os
= input_section
->output_section
;
12549 /* A partial link, so keep the relocs */
12550 os
->orelocation
[os
->reloc_count
] = *parent
;
12554 if (r
!= bfd_reloc_ok
)
12558 case bfd_reloc_undefined
:
12559 if (!((*link_info
->callbacks
->undefined_symbol
)
12560 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
12561 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
12564 case bfd_reloc_dangerous
:
12565 BFD_ASSERT (error_message
!= NULL
);
12566 if (!((*link_info
->callbacks
->reloc_dangerous
)
12567 (link_info
, error_message
, input_bfd
, input_section
,
12568 (*parent
)->address
)))
12571 case bfd_reloc_overflow
:
12572 if (!((*link_info
->callbacks
->reloc_overflow
)
12574 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
12575 (*parent
)->howto
->name
, (*parent
)->addend
,
12576 input_bfd
, input_section
, (*parent
)->address
)))
12579 case bfd_reloc_outofrange
:
12588 if (reloc_vector
!= NULL
)
12589 free (reloc_vector
);
12593 if (reloc_vector
!= NULL
)
12594 free (reloc_vector
);
12599 mips_elf_relax_delete_bytes (bfd
*abfd
,
12600 asection
*sec
, bfd_vma addr
, int count
)
12602 Elf_Internal_Shdr
*symtab_hdr
;
12603 unsigned int sec_shndx
;
12604 bfd_byte
*contents
;
12605 Elf_Internal_Rela
*irel
, *irelend
;
12606 Elf_Internal_Sym
*isym
;
12607 Elf_Internal_Sym
*isymend
;
12608 struct elf_link_hash_entry
**sym_hashes
;
12609 struct elf_link_hash_entry
**end_hashes
;
12610 struct elf_link_hash_entry
**start_hashes
;
12611 unsigned int symcount
;
12613 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
12614 contents
= elf_section_data (sec
)->this_hdr
.contents
;
12616 irel
= elf_section_data (sec
)->relocs
;
12617 irelend
= irel
+ sec
->reloc_count
;
12619 /* Actually delete the bytes. */
12620 memmove (contents
+ addr
, contents
+ addr
+ count
,
12621 (size_t) (sec
->size
- addr
- count
));
12622 sec
->size
-= count
;
12624 /* Adjust all the relocs. */
12625 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
12627 /* Get the new reloc address. */
12628 if (irel
->r_offset
> addr
)
12629 irel
->r_offset
-= count
;
12632 BFD_ASSERT (addr
% 2 == 0);
12633 BFD_ASSERT (count
% 2 == 0);
12635 /* Adjust the local symbols defined in this section. */
12636 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
12637 isym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
12638 for (isymend
= isym
+ symtab_hdr
->sh_info
; isym
< isymend
; isym
++)
12639 if (isym
->st_shndx
== sec_shndx
&& isym
->st_value
> addr
)
12640 isym
->st_value
-= count
;
12642 /* Now adjust the global symbols defined in this section. */
12643 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
12644 - symtab_hdr
->sh_info
);
12645 sym_hashes
= start_hashes
= elf_sym_hashes (abfd
);
12646 end_hashes
= sym_hashes
+ symcount
;
12648 for (; sym_hashes
< end_hashes
; sym_hashes
++)
12650 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
12652 if ((sym_hash
->root
.type
== bfd_link_hash_defined
12653 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
12654 && sym_hash
->root
.u
.def
.section
== sec
)
12656 bfd_vma value
= sym_hash
->root
.u
.def
.value
;
12658 if (ELF_ST_IS_MICROMIPS (sym_hash
->other
))
12659 value
&= MINUS_TWO
;
12661 sym_hash
->root
.u
.def
.value
-= count
;
12669 /* Opcodes needed for microMIPS relaxation as found in
12670 opcodes/micromips-opc.c. */
12672 struct opcode_descriptor
{
12673 unsigned long match
;
12674 unsigned long mask
;
12677 /* The $ra register aka $31. */
12681 /* 32-bit instruction format register fields. */
12683 #define OP32_SREG(opcode) (((opcode) >> 16) & 0x1f)
12684 #define OP32_TREG(opcode) (((opcode) >> 21) & 0x1f)
12686 /* Check if a 5-bit register index can be abbreviated to 3 bits. */
12688 #define OP16_VALID_REG(r) \
12689 ((2 <= (r) && (r) <= 7) || (16 <= (r) && (r) <= 17))
12692 /* 32-bit and 16-bit branches. */
12694 static const struct opcode_descriptor b_insns_32
[] = {
12695 { /* "b", "p", */ 0x40400000, 0xffff0000 }, /* bgez 0 */
12696 { /* "b", "p", */ 0x94000000, 0xffff0000 }, /* beq 0, 0 */
12697 { 0, 0 } /* End marker for find_match(). */
12700 static const struct opcode_descriptor bc_insn_32
=
12701 { /* "bc(1|2)(ft)", "N,p", */ 0x42800000, 0xfec30000 };
12703 static const struct opcode_descriptor bz_insn_32
=
12704 { /* "b(g|l)(e|t)z", "s,p", */ 0x40000000, 0xff200000 };
12706 static const struct opcode_descriptor bzal_insn_32
=
12707 { /* "b(ge|lt)zal", "s,p", */ 0x40200000, 0xffa00000 };
12709 static const struct opcode_descriptor beq_insn_32
=
12710 { /* "b(eq|ne)", "s,t,p", */ 0x94000000, 0xdc000000 };
12712 static const struct opcode_descriptor b_insn_16
=
12713 { /* "b", "mD", */ 0xcc00, 0xfc00 };
12715 static const struct opcode_descriptor bz_insn_16
=
12716 { /* "b(eq|ne)z", "md,mE", */ 0x8c00, 0xdc00 };
12719 /* 32-bit and 16-bit branch EQ and NE zero. */
12721 /* NOTE: All opcode tables have BEQ/BNE in the same order: first the
12722 eq and second the ne. This convention is used when replacing a
12723 32-bit BEQ/BNE with the 16-bit version. */
12725 #define BZC32_REG_FIELD(r) (((r) & 0x1f) << 16)
12727 static const struct opcode_descriptor bz_rs_insns_32
[] = {
12728 { /* "beqz", "s,p", */ 0x94000000, 0xffe00000 },
12729 { /* "bnez", "s,p", */ 0xb4000000, 0xffe00000 },
12730 { 0, 0 } /* End marker for find_match(). */
12733 static const struct opcode_descriptor bz_rt_insns_32
[] = {
12734 { /* "beqz", "t,p", */ 0x94000000, 0xfc01f000 },
12735 { /* "bnez", "t,p", */ 0xb4000000, 0xfc01f000 },
12736 { 0, 0 } /* End marker for find_match(). */
12739 static const struct opcode_descriptor bzc_insns_32
[] = {
12740 { /* "beqzc", "s,p", */ 0x40e00000, 0xffe00000 },
12741 { /* "bnezc", "s,p", */ 0x40a00000, 0xffe00000 },
12742 { 0, 0 } /* End marker for find_match(). */
12745 static const struct opcode_descriptor bz_insns_16
[] = {
12746 { /* "beqz", "md,mE", */ 0x8c00, 0xfc00 },
12747 { /* "bnez", "md,mE", */ 0xac00, 0xfc00 },
12748 { 0, 0 } /* End marker for find_match(). */
12751 /* Switch between a 5-bit register index and its 3-bit shorthand. */
12753 #define BZ16_REG(opcode) ((((((opcode) >> 7) & 7) + 0x1e) & 0x17) + 2)
12754 #define BZ16_REG_FIELD(r) \
12755 (((2 <= (r) && (r) <= 7) ? (r) : ((r) - 16)) << 7)
12758 /* 32-bit instructions with a delay slot. */
12760 static const struct opcode_descriptor jal_insn_32_bd16
=
12761 { /* "jals", "a", */ 0x74000000, 0xfc000000 };
12763 static const struct opcode_descriptor jal_insn_32_bd32
=
12764 { /* "jal", "a", */ 0xf4000000, 0xfc000000 };
12766 static const struct opcode_descriptor jal_x_insn_32_bd32
=
12767 { /* "jal[x]", "a", */ 0xf0000000, 0xf8000000 };
12769 static const struct opcode_descriptor j_insn_32
=
12770 { /* "j", "a", */ 0xd4000000, 0xfc000000 };
12772 static const struct opcode_descriptor jalr_insn_32
=
12773 { /* "jalr[.hb]", "t,s", */ 0x00000f3c, 0xfc00efff };
12775 /* This table can be compacted, because no opcode replacement is made. */
12777 static const struct opcode_descriptor ds_insns_32_bd16
[] = {
12778 { /* "jals", "a", */ 0x74000000, 0xfc000000 },
12780 { /* "jalrs[.hb]", "t,s", */ 0x00004f3c, 0xfc00efff },
12781 { /* "b(ge|lt)zals", "s,p", */ 0x42200000, 0xffa00000 },
12783 { /* "b(g|l)(e|t)z", "s,p", */ 0x40000000, 0xff200000 },
12784 { /* "b(eq|ne)", "s,t,p", */ 0x94000000, 0xdc000000 },
12785 { /* "j", "a", */ 0xd4000000, 0xfc000000 },
12786 { 0, 0 } /* End marker for find_match(). */
12789 /* This table can be compacted, because no opcode replacement is made. */
12791 static const struct opcode_descriptor ds_insns_32_bd32
[] = {
12792 { /* "jal[x]", "a", */ 0xf0000000, 0xf8000000 },
12794 { /* "jalr[.hb]", "t,s", */ 0x00000f3c, 0xfc00efff },
12795 { /* "b(ge|lt)zal", "s,p", */ 0x40200000, 0xffa00000 },
12796 { 0, 0 } /* End marker for find_match(). */
12800 /* 16-bit instructions with a delay slot. */
12802 static const struct opcode_descriptor jalr_insn_16_bd16
=
12803 { /* "jalrs", "my,mj", */ 0x45e0, 0xffe0 };
12805 static const struct opcode_descriptor jalr_insn_16_bd32
=
12806 { /* "jalr", "my,mj", */ 0x45c0, 0xffe0 };
12808 static const struct opcode_descriptor jr_insn_16
=
12809 { /* "jr", "mj", */ 0x4580, 0xffe0 };
12811 #define JR16_REG(opcode) ((opcode) & 0x1f)
12813 /* This table can be compacted, because no opcode replacement is made. */
12815 static const struct opcode_descriptor ds_insns_16_bd16
[] = {
12816 { /* "jalrs", "my,mj", */ 0x45e0, 0xffe0 },
12818 { /* "b", "mD", */ 0xcc00, 0xfc00 },
12819 { /* "b(eq|ne)z", "md,mE", */ 0x8c00, 0xdc00 },
12820 { /* "jr", "mj", */ 0x4580, 0xffe0 },
12821 { 0, 0 } /* End marker for find_match(). */
12825 /* LUI instruction. */
12827 static const struct opcode_descriptor lui_insn
=
12828 { /* "lui", "s,u", */ 0x41a00000, 0xffe00000 };
12831 /* ADDIU instruction. */
12833 static const struct opcode_descriptor addiu_insn
=
12834 { /* "addiu", "t,r,j", */ 0x30000000, 0xfc000000 };
12836 static const struct opcode_descriptor addiupc_insn
=
12837 { /* "addiu", "mb,$pc,mQ", */ 0x78000000, 0xfc000000 };
12839 #define ADDIUPC_REG_FIELD(r) \
12840 (((2 <= (r) && (r) <= 7) ? (r) : ((r) - 16)) << 23)
12843 /* Relaxable instructions in a JAL delay slot: MOVE. */
12845 /* The 16-bit move has rd in 9:5 and rs in 4:0. The 32-bit moves
12846 (ADDU, OR) have rd in 15:11 and rs in 10:16. */
12847 #define MOVE32_RD(opcode) (((opcode) >> 11) & 0x1f)
12848 #define MOVE32_RS(opcode) (((opcode) >> 16) & 0x1f)
12850 #define MOVE16_RD_FIELD(r) (((r) & 0x1f) << 5)
12851 #define MOVE16_RS_FIELD(r) (((r) & 0x1f) )
12853 static const struct opcode_descriptor move_insns_32
[] = {
12854 { /* "move", "d,s", */ 0x00000150, 0xffe007ff }, /* addu d,s,$0 */
12855 { /* "move", "d,s", */ 0x00000290, 0xffe007ff }, /* or d,s,$0 */
12856 { 0, 0 } /* End marker for find_match(). */
12859 static const struct opcode_descriptor move_insn_16
=
12860 { /* "move", "mp,mj", */ 0x0c00, 0xfc00 };
12863 /* NOP instructions. */
12865 static const struct opcode_descriptor nop_insn_32
=
12866 { /* "nop", "", */ 0x00000000, 0xffffffff };
12868 static const struct opcode_descriptor nop_insn_16
=
12869 { /* "nop", "", */ 0x0c00, 0xffff };
12872 /* Instruction match support. */
12874 #define MATCH(opcode, insn) ((opcode & insn.mask) == insn.match)
12877 find_match (unsigned long opcode
, const struct opcode_descriptor insn
[])
12879 unsigned long indx
;
12881 for (indx
= 0; insn
[indx
].mask
!= 0; indx
++)
12882 if (MATCH (opcode
, insn
[indx
]))
12889 /* Branch and delay slot decoding support. */
12891 /* If PTR points to what *might* be a 16-bit branch or jump, then
12892 return the minimum length of its delay slot, otherwise return 0.
12893 Non-zero results are not definitive as we might be checking against
12894 the second half of another instruction. */
12897 check_br16_dslot (bfd
*abfd
, bfd_byte
*ptr
)
12899 unsigned long opcode
;
12902 opcode
= bfd_get_16 (abfd
, ptr
);
12903 if (MATCH (opcode
, jalr_insn_16_bd32
) != 0)
12904 /* 16-bit branch/jump with a 32-bit delay slot. */
12906 else if (MATCH (opcode
, jalr_insn_16_bd16
) != 0
12907 || find_match (opcode
, ds_insns_16_bd16
) >= 0)
12908 /* 16-bit branch/jump with a 16-bit delay slot. */
12911 /* No delay slot. */
12917 /* If PTR points to what *might* be a 32-bit branch or jump, then
12918 return the minimum length of its delay slot, otherwise return 0.
12919 Non-zero results are not definitive as we might be checking against
12920 the second half of another instruction. */
12923 check_br32_dslot (bfd
*abfd
, bfd_byte
*ptr
)
12925 unsigned long opcode
;
12928 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
12929 if (find_match (opcode
, ds_insns_32_bd32
) >= 0)
12930 /* 32-bit branch/jump with a 32-bit delay slot. */
12932 else if (find_match (opcode
, ds_insns_32_bd16
) >= 0)
12933 /* 32-bit branch/jump with a 16-bit delay slot. */
12936 /* No delay slot. */
12942 /* If PTR points to a 16-bit branch or jump with a 32-bit delay slot
12943 that doesn't fiddle with REG, then return TRUE, otherwise FALSE. */
12946 check_br16 (bfd
*abfd
, bfd_byte
*ptr
, unsigned long reg
)
12948 unsigned long opcode
;
12950 opcode
= bfd_get_16 (abfd
, ptr
);
12951 if (MATCH (opcode
, b_insn_16
)
12953 || (MATCH (opcode
, jr_insn_16
) && reg
!= JR16_REG (opcode
))
12955 || (MATCH (opcode
, bz_insn_16
) && reg
!= BZ16_REG (opcode
))
12956 /* BEQZ16, BNEZ16 */
12957 || (MATCH (opcode
, jalr_insn_16_bd32
)
12959 && reg
!= JR16_REG (opcode
) && reg
!= RA
))
12965 /* If PTR points to a 32-bit branch or jump that doesn't fiddle with REG,
12966 then return TRUE, otherwise FALSE. */
12969 check_br32 (bfd
*abfd
, bfd_byte
*ptr
, unsigned long reg
)
12971 unsigned long opcode
;
12973 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
12974 if (MATCH (opcode
, j_insn_32
)
12976 || MATCH (opcode
, bc_insn_32
)
12977 /* BC1F, BC1T, BC2F, BC2T */
12978 || (MATCH (opcode
, jal_x_insn_32_bd32
) && reg
!= RA
)
12980 || (MATCH (opcode
, bz_insn_32
) && reg
!= OP32_SREG (opcode
))
12981 /* BGEZ, BGTZ, BLEZ, BLTZ */
12982 || (MATCH (opcode
, bzal_insn_32
)
12983 /* BGEZAL, BLTZAL */
12984 && reg
!= OP32_SREG (opcode
) && reg
!= RA
)
12985 || ((MATCH (opcode
, jalr_insn_32
) || MATCH (opcode
, beq_insn_32
))
12986 /* JALR, JALR.HB, BEQ, BNE */
12987 && reg
!= OP32_SREG (opcode
) && reg
!= OP32_TREG (opcode
)))
12993 /* If the instruction encoding at PTR and relocations [INTERNAL_RELOCS,
12994 IRELEND) at OFFSET indicate that there must be a compact branch there,
12995 then return TRUE, otherwise FALSE. */
12998 check_relocated_bzc (bfd
*abfd
, const bfd_byte
*ptr
, bfd_vma offset
,
12999 const Elf_Internal_Rela
*internal_relocs
,
13000 const Elf_Internal_Rela
*irelend
)
13002 const Elf_Internal_Rela
*irel
;
13003 unsigned long opcode
;
13005 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
13006 if (find_match (opcode
, bzc_insns_32
) < 0)
13009 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13010 if (irel
->r_offset
== offset
13011 && ELF32_R_TYPE (irel
->r_info
) == R_MICROMIPS_PC16_S1
)
13017 /* Bitsize checking. */
13018 #define IS_BITSIZE(val, N) \
13019 (((((val) & ((1ULL << (N)) - 1)) ^ (1ULL << ((N) - 1))) \
13020 - (1ULL << ((N) - 1))) == (val))
13024 _bfd_mips_elf_relax_section (bfd
*abfd
, asection
*sec
,
13025 struct bfd_link_info
*link_info
,
13026 bfd_boolean
*again
)
13028 bfd_boolean insn32
= mips_elf_hash_table (link_info
)->insn32
;
13029 Elf_Internal_Shdr
*symtab_hdr
;
13030 Elf_Internal_Rela
*internal_relocs
;
13031 Elf_Internal_Rela
*irel
, *irelend
;
13032 bfd_byte
*contents
= NULL
;
13033 Elf_Internal_Sym
*isymbuf
= NULL
;
13035 /* Assume nothing changes. */
13038 /* We don't have to do anything for a relocatable link, if
13039 this section does not have relocs, or if this is not a
13042 if (link_info
->relocatable
13043 || (sec
->flags
& SEC_RELOC
) == 0
13044 || sec
->reloc_count
== 0
13045 || (sec
->flags
& SEC_CODE
) == 0)
13048 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
13050 /* Get a copy of the native relocations. */
13051 internal_relocs
= (_bfd_elf_link_read_relocs
13052 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
13053 link_info
->keep_memory
));
13054 if (internal_relocs
== NULL
)
13057 /* Walk through them looking for relaxing opportunities. */
13058 irelend
= internal_relocs
+ sec
->reloc_count
;
13059 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13061 unsigned long r_symndx
= ELF32_R_SYM (irel
->r_info
);
13062 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
13063 bfd_boolean target_is_micromips_code_p
;
13064 unsigned long opcode
;
13070 /* The number of bytes to delete for relaxation and from where
13071 to delete these bytes starting at irel->r_offset. */
13075 /* If this isn't something that can be relaxed, then ignore
13077 if (r_type
!= R_MICROMIPS_HI16
13078 && r_type
!= R_MICROMIPS_PC16_S1
13079 && r_type
!= R_MICROMIPS_26_S1
)
13082 /* Get the section contents if we haven't done so already. */
13083 if (contents
== NULL
)
13085 /* Get cached copy if it exists. */
13086 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
13087 contents
= elf_section_data (sec
)->this_hdr
.contents
;
13088 /* Go get them off disk. */
13089 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
13092 ptr
= contents
+ irel
->r_offset
;
13094 /* Read this BFD's local symbols if we haven't done so already. */
13095 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
13097 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
13098 if (isymbuf
== NULL
)
13099 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
13100 symtab_hdr
->sh_info
, 0,
13102 if (isymbuf
== NULL
)
13106 /* Get the value of the symbol referred to by the reloc. */
13107 if (r_symndx
< symtab_hdr
->sh_info
)
13109 /* A local symbol. */
13110 Elf_Internal_Sym
*isym
;
13113 isym
= isymbuf
+ r_symndx
;
13114 if (isym
->st_shndx
== SHN_UNDEF
)
13115 sym_sec
= bfd_und_section_ptr
;
13116 else if (isym
->st_shndx
== SHN_ABS
)
13117 sym_sec
= bfd_abs_section_ptr
;
13118 else if (isym
->st_shndx
== SHN_COMMON
)
13119 sym_sec
= bfd_com_section_ptr
;
13121 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
13122 symval
= (isym
->st_value
13123 + sym_sec
->output_section
->vma
13124 + sym_sec
->output_offset
);
13125 target_is_micromips_code_p
= ELF_ST_IS_MICROMIPS (isym
->st_other
);
13129 unsigned long indx
;
13130 struct elf_link_hash_entry
*h
;
13132 /* An external symbol. */
13133 indx
= r_symndx
- symtab_hdr
->sh_info
;
13134 h
= elf_sym_hashes (abfd
)[indx
];
13135 BFD_ASSERT (h
!= NULL
);
13137 if (h
->root
.type
!= bfd_link_hash_defined
13138 && h
->root
.type
!= bfd_link_hash_defweak
)
13139 /* This appears to be a reference to an undefined
13140 symbol. Just ignore it -- it will be caught by the
13141 regular reloc processing. */
13144 symval
= (h
->root
.u
.def
.value
13145 + h
->root
.u
.def
.section
->output_section
->vma
13146 + h
->root
.u
.def
.section
->output_offset
);
13147 target_is_micromips_code_p
= (!h
->needs_plt
13148 && ELF_ST_IS_MICROMIPS (h
->other
));
13152 /* For simplicity of coding, we are going to modify the
13153 section contents, the section relocs, and the BFD symbol
13154 table. We must tell the rest of the code not to free up this
13155 information. It would be possible to instead create a table
13156 of changes which have to be made, as is done in coff-mips.c;
13157 that would be more work, but would require less memory when
13158 the linker is run. */
13160 /* Only 32-bit instructions relaxed. */
13161 if (irel
->r_offset
+ 4 > sec
->size
)
13164 opcode
= bfd_get_micromips_32 (abfd
, ptr
);
13166 /* This is the pc-relative distance from the instruction the
13167 relocation is applied to, to the symbol referred. */
13169 - (sec
->output_section
->vma
+ sec
->output_offset
)
13172 /* R_MICROMIPS_HI16 / LUI relaxation to nil, performing relaxation
13173 of corresponding R_MICROMIPS_LO16 to R_MICROMIPS_HI0_LO16 or
13174 R_MICROMIPS_PC23_S2. The R_MICROMIPS_PC23_S2 condition is
13176 (symval % 4 == 0 && IS_BITSIZE (pcrval, 25))
13178 where pcrval has first to be adjusted to apply against the LO16
13179 location (we make the adjustment later on, when we have figured
13180 out the offset). */
13181 if (r_type
== R_MICROMIPS_HI16
&& MATCH (opcode
, lui_insn
))
13183 bfd_boolean bzc
= FALSE
;
13184 unsigned long nextopc
;
13188 /* Give up if the previous reloc was a HI16 against this symbol
13190 if (irel
> internal_relocs
13191 && ELF32_R_TYPE (irel
[-1].r_info
) == R_MICROMIPS_HI16
13192 && ELF32_R_SYM (irel
[-1].r_info
) == r_symndx
)
13195 /* Or if the next reloc is not a LO16 against this symbol. */
13196 if (irel
+ 1 >= irelend
13197 || ELF32_R_TYPE (irel
[1].r_info
) != R_MICROMIPS_LO16
13198 || ELF32_R_SYM (irel
[1].r_info
) != r_symndx
)
13201 /* Or if the second next reloc is a LO16 against this symbol too. */
13202 if (irel
+ 2 >= irelend
13203 && ELF32_R_TYPE (irel
[2].r_info
) == R_MICROMIPS_LO16
13204 && ELF32_R_SYM (irel
[2].r_info
) == r_symndx
)
13207 /* See if the LUI instruction *might* be in a branch delay slot.
13208 We check whether what looks like a 16-bit branch or jump is
13209 actually an immediate argument to a compact branch, and let
13210 it through if so. */
13211 if (irel
->r_offset
>= 2
13212 && check_br16_dslot (abfd
, ptr
- 2)
13213 && !(irel
->r_offset
>= 4
13214 && (bzc
= check_relocated_bzc (abfd
,
13215 ptr
- 4, irel
->r_offset
- 4,
13216 internal_relocs
, irelend
))))
13218 if (irel
->r_offset
>= 4
13220 && check_br32_dslot (abfd
, ptr
- 4))
13223 reg
= OP32_SREG (opcode
);
13225 /* We only relax adjacent instructions or ones separated with
13226 a branch or jump that has a delay slot. The branch or jump
13227 must not fiddle with the register used to hold the address.
13228 Subtract 4 for the LUI itself. */
13229 offset
= irel
[1].r_offset
- irel
[0].r_offset
;
13230 switch (offset
- 4)
13235 if (check_br16 (abfd
, ptr
+ 4, reg
))
13239 if (check_br32 (abfd
, ptr
+ 4, reg
))
13246 nextopc
= bfd_get_micromips_32 (abfd
, contents
+ irel
[1].r_offset
);
13248 /* Give up unless the same register is used with both
13250 if (OP32_SREG (nextopc
) != reg
)
13253 /* Now adjust pcrval, subtracting the offset to the LO16 reloc
13254 and rounding up to take masking of the two LSBs into account. */
13255 pcrval
= ((pcrval
- offset
+ 3) | 3) ^ 3;
13257 /* R_MICROMIPS_LO16 relaxation to R_MICROMIPS_HI0_LO16. */
13258 if (IS_BITSIZE (symval
, 16))
13260 /* Fix the relocation's type. */
13261 irel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_HI0_LO16
);
13263 /* Instructions using R_MICROMIPS_LO16 have the base or
13264 source register in bits 20:16. This register becomes $0
13265 (zero) as the result of the R_MICROMIPS_HI16 being 0. */
13266 nextopc
&= ~0x001f0000;
13267 bfd_put_16 (abfd
, (nextopc
>> 16) & 0xffff,
13268 contents
+ irel
[1].r_offset
);
13271 /* R_MICROMIPS_LO16 / ADDIU relaxation to R_MICROMIPS_PC23_S2.
13272 We add 4 to take LUI deletion into account while checking
13273 the PC-relative distance. */
13274 else if (symval
% 4 == 0
13275 && IS_BITSIZE (pcrval
+ 4, 25)
13276 && MATCH (nextopc
, addiu_insn
)
13277 && OP32_TREG (nextopc
) == OP32_SREG (nextopc
)
13278 && OP16_VALID_REG (OP32_TREG (nextopc
)))
13280 /* Fix the relocation's type. */
13281 irel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_PC23_S2
);
13283 /* Replace ADDIU with the ADDIUPC version. */
13284 nextopc
= (addiupc_insn
.match
13285 | ADDIUPC_REG_FIELD (OP32_TREG (nextopc
)));
13287 bfd_put_micromips_32 (abfd
, nextopc
,
13288 contents
+ irel
[1].r_offset
);
13291 /* Can't do anything, give up, sigh... */
13295 /* Fix the relocation's type. */
13296 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_MIPS_NONE
);
13298 /* Delete the LUI instruction: 4 bytes at irel->r_offset. */
13303 /* Compact branch relaxation -- due to the multitude of macros
13304 employed by the compiler/assembler, compact branches are not
13305 always generated. Obviously, this can/will be fixed elsewhere,
13306 but there is no drawback in double checking it here. */
13307 else if (r_type
== R_MICROMIPS_PC16_S1
13308 && irel
->r_offset
+ 5 < sec
->size
13309 && ((fndopc
= find_match (opcode
, bz_rs_insns_32
)) >= 0
13310 || (fndopc
= find_match (opcode
, bz_rt_insns_32
)) >= 0)
13312 && (delcnt
= MATCH (bfd_get_16 (abfd
, ptr
+ 4),
13313 nop_insn_16
) ? 2 : 0))
13314 || (irel
->r_offset
+ 7 < sec
->size
13315 && (delcnt
= MATCH (bfd_get_micromips_32 (abfd
,
13317 nop_insn_32
) ? 4 : 0))))
13321 reg
= OP32_SREG (opcode
) ? OP32_SREG (opcode
) : OP32_TREG (opcode
);
13323 /* Replace BEQZ/BNEZ with the compact version. */
13324 opcode
= (bzc_insns_32
[fndopc
].match
13325 | BZC32_REG_FIELD (reg
)
13326 | (opcode
& 0xffff)); /* Addend value. */
13328 bfd_put_micromips_32 (abfd
, opcode
, ptr
);
13330 /* Delete the delay slot NOP: two or four bytes from
13331 irel->offset + 4; delcnt has already been set above. */
13335 /* R_MICROMIPS_PC16_S1 relaxation to R_MICROMIPS_PC10_S1. We need
13336 to check the distance from the next instruction, so subtract 2. */
13338 && r_type
== R_MICROMIPS_PC16_S1
13339 && IS_BITSIZE (pcrval
- 2, 11)
13340 && find_match (opcode
, b_insns_32
) >= 0)
13342 /* Fix the relocation's type. */
13343 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_PC10_S1
);
13345 /* Replace the 32-bit opcode with a 16-bit opcode. */
13348 | (opcode
& 0x3ff)), /* Addend value. */
13351 /* Delete 2 bytes from irel->r_offset + 2. */
13356 /* R_MICROMIPS_PC16_S1 relaxation to R_MICROMIPS_PC7_S1. We need
13357 to check the distance from the next instruction, so subtract 2. */
13359 && r_type
== R_MICROMIPS_PC16_S1
13360 && IS_BITSIZE (pcrval
- 2, 8)
13361 && (((fndopc
= find_match (opcode
, bz_rs_insns_32
)) >= 0
13362 && OP16_VALID_REG (OP32_SREG (opcode
)))
13363 || ((fndopc
= find_match (opcode
, bz_rt_insns_32
)) >= 0
13364 && OP16_VALID_REG (OP32_TREG (opcode
)))))
13368 reg
= OP32_SREG (opcode
) ? OP32_SREG (opcode
) : OP32_TREG (opcode
);
13370 /* Fix the relocation's type. */
13371 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_MICROMIPS_PC7_S1
);
13373 /* Replace the 32-bit opcode with a 16-bit opcode. */
13375 (bz_insns_16
[fndopc
].match
13376 | BZ16_REG_FIELD (reg
)
13377 | (opcode
& 0x7f)), /* Addend value. */
13380 /* Delete 2 bytes from irel->r_offset + 2. */
13385 /* R_MICROMIPS_26_S1 -- JAL to JALS relaxation for microMIPS targets. */
13387 && r_type
== R_MICROMIPS_26_S1
13388 && target_is_micromips_code_p
13389 && irel
->r_offset
+ 7 < sec
->size
13390 && MATCH (opcode
, jal_insn_32_bd32
))
13392 unsigned long n32opc
;
13393 bfd_boolean relaxed
= FALSE
;
13395 n32opc
= bfd_get_micromips_32 (abfd
, ptr
+ 4);
13397 if (MATCH (n32opc
, nop_insn_32
))
13399 /* Replace delay slot 32-bit NOP with a 16-bit NOP. */
13400 bfd_put_16 (abfd
, nop_insn_16
.match
, ptr
+ 4);
13404 else if (find_match (n32opc
, move_insns_32
) >= 0)
13406 /* Replace delay slot 32-bit MOVE with 16-bit MOVE. */
13408 (move_insn_16
.match
13409 | MOVE16_RD_FIELD (MOVE32_RD (n32opc
))
13410 | MOVE16_RS_FIELD (MOVE32_RS (n32opc
))),
13415 /* Other 32-bit instructions relaxable to 16-bit
13416 instructions will be handled here later. */
13420 /* JAL with 32-bit delay slot that is changed to a JALS
13421 with 16-bit delay slot. */
13422 bfd_put_micromips_32 (abfd
, jal_insn_32_bd16
.match
, ptr
);
13424 /* Delete 2 bytes from irel->r_offset + 6. */
13432 /* Note that we've changed the relocs, section contents, etc. */
13433 elf_section_data (sec
)->relocs
= internal_relocs
;
13434 elf_section_data (sec
)->this_hdr
.contents
= contents
;
13435 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
13437 /* Delete bytes depending on the delcnt and deloff. */
13438 if (!mips_elf_relax_delete_bytes (abfd
, sec
,
13439 irel
->r_offset
+ deloff
, delcnt
))
13442 /* That will change things, so we should relax again.
13443 Note that this is not required, and it may be slow. */
13448 if (isymbuf
!= NULL
13449 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
13451 if (! link_info
->keep_memory
)
13455 /* Cache the symbols for elf_link_input_bfd. */
13456 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
13460 if (contents
!= NULL
13461 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
13463 if (! link_info
->keep_memory
)
13467 /* Cache the section contents for elf_link_input_bfd. */
13468 elf_section_data (sec
)->this_hdr
.contents
= contents
;
13472 if (internal_relocs
!= NULL
13473 && elf_section_data (sec
)->relocs
!= internal_relocs
)
13474 free (internal_relocs
);
13479 if (isymbuf
!= NULL
13480 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
13482 if (contents
!= NULL
13483 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
13485 if (internal_relocs
!= NULL
13486 && elf_section_data (sec
)->relocs
!= internal_relocs
)
13487 free (internal_relocs
);
13492 /* Create a MIPS ELF linker hash table. */
13494 struct bfd_link_hash_table
*
13495 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
13497 struct mips_elf_link_hash_table
*ret
;
13498 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
13500 ret
= bfd_zmalloc (amt
);
13504 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
13505 mips_elf_link_hash_newfunc
,
13506 sizeof (struct mips_elf_link_hash_entry
),
13512 ret
->root
.init_plt_refcount
.plist
= NULL
;
13513 ret
->root
.init_plt_offset
.plist
= NULL
;
13515 return &ret
->root
.root
;
13518 /* Likewise, but indicate that the target is VxWorks. */
13520 struct bfd_link_hash_table
*
13521 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
13523 struct bfd_link_hash_table
*ret
;
13525 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
13528 struct mips_elf_link_hash_table
*htab
;
13530 htab
= (struct mips_elf_link_hash_table
*) ret
;
13531 htab
->use_plts_and_copy_relocs
= TRUE
;
13532 htab
->is_vxworks
= TRUE
;
13537 /* A function that the linker calls if we are allowed to use PLTs
13538 and copy relocs. */
13541 _bfd_mips_elf_use_plts_and_copy_relocs (struct bfd_link_info
*info
)
13543 mips_elf_hash_table (info
)->use_plts_and_copy_relocs
= TRUE
;
13546 /* A function that the linker calls to select between all or only
13547 32-bit microMIPS instructions. */
13550 _bfd_mips_elf_insn32 (struct bfd_link_info
*info
, bfd_boolean on
)
13552 mips_elf_hash_table (info
)->insn32
= on
;
13555 /* We need to use a special link routine to handle the .reginfo and
13556 the .mdebug sections. We need to merge all instances of these
13557 sections together, not write them all out sequentially. */
13560 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
13563 struct bfd_link_order
*p
;
13564 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
13565 asection
*rtproc_sec
;
13566 Elf32_RegInfo reginfo
;
13567 struct ecoff_debug_info debug
;
13568 struct mips_htab_traverse_info hti
;
13569 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
13570 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
13571 HDRR
*symhdr
= &debug
.symbolic_header
;
13572 void *mdebug_handle
= NULL
;
13577 struct mips_elf_link_hash_table
*htab
;
13579 static const char * const secname
[] =
13581 ".text", ".init", ".fini", ".data",
13582 ".rodata", ".sdata", ".sbss", ".bss"
13584 static const int sc
[] =
13586 scText
, scInit
, scFini
, scData
,
13587 scRData
, scSData
, scSBss
, scBss
13590 /* Sort the dynamic symbols so that those with GOT entries come after
13592 htab
= mips_elf_hash_table (info
);
13593 BFD_ASSERT (htab
!= NULL
);
13595 if (!mips_elf_sort_hash_table (abfd
, info
))
13598 /* Create any scheduled LA25 stubs. */
13600 hti
.output_bfd
= abfd
;
13602 htab_traverse (htab
->la25_stubs
, mips_elf_create_la25_stub
, &hti
);
13606 /* Get a value for the GP register. */
13607 if (elf_gp (abfd
) == 0)
13609 struct bfd_link_hash_entry
*h
;
13611 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
13612 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
13613 elf_gp (abfd
) = (h
->u
.def
.value
13614 + h
->u
.def
.section
->output_section
->vma
13615 + h
->u
.def
.section
->output_offset
);
13616 else if (htab
->is_vxworks
13617 && (h
= bfd_link_hash_lookup (info
->hash
,
13618 "_GLOBAL_OFFSET_TABLE_",
13619 FALSE
, FALSE
, TRUE
))
13620 && h
->type
== bfd_link_hash_defined
)
13621 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
13622 + h
->u
.def
.section
->output_offset
13624 else if (info
->relocatable
)
13626 bfd_vma lo
= MINUS_ONE
;
13628 /* Find the GP-relative section with the lowest offset. */
13629 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
13631 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
13634 /* And calculate GP relative to that. */
13635 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
13639 /* If the relocate_section function needs to do a reloc
13640 involving the GP value, it should make a reloc_dangerous
13641 callback to warn that GP is not defined. */
13645 /* Go through the sections and collect the .reginfo and .mdebug
13647 reginfo_sec
= NULL
;
13649 gptab_data_sec
= NULL
;
13650 gptab_bss_sec
= NULL
;
13651 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
13653 if (strcmp (o
->name
, ".reginfo") == 0)
13655 memset (®info
, 0, sizeof reginfo
);
13657 /* We have found the .reginfo section in the output file.
13658 Look through all the link_orders comprising it and merge
13659 the information together. */
13660 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
13662 asection
*input_section
;
13664 Elf32_External_RegInfo ext
;
13667 if (p
->type
!= bfd_indirect_link_order
)
13669 if (p
->type
== bfd_data_link_order
)
13674 input_section
= p
->u
.indirect
.section
;
13675 input_bfd
= input_section
->owner
;
13677 if (! bfd_get_section_contents (input_bfd
, input_section
,
13678 &ext
, 0, sizeof ext
))
13681 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
13683 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
13684 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
13685 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
13686 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
13687 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
13689 /* ri_gp_value is set by the function
13690 mips_elf32_section_processing when the section is
13691 finally written out. */
13693 /* Hack: reset the SEC_HAS_CONTENTS flag so that
13694 elf_link_input_bfd ignores this section. */
13695 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
13698 /* Size has been set in _bfd_mips_elf_always_size_sections. */
13699 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
13701 /* Skip this section later on (I don't think this currently
13702 matters, but someday it might). */
13703 o
->map_head
.link_order
= NULL
;
13708 if (strcmp (o
->name
, ".mdebug") == 0)
13710 struct extsym_info einfo
;
13713 /* We have found the .mdebug section in the output file.
13714 Look through all the link_orders comprising it and merge
13715 the information together. */
13716 symhdr
->magic
= swap
->sym_magic
;
13717 /* FIXME: What should the version stamp be? */
13718 symhdr
->vstamp
= 0;
13719 symhdr
->ilineMax
= 0;
13720 symhdr
->cbLine
= 0;
13721 symhdr
->idnMax
= 0;
13722 symhdr
->ipdMax
= 0;
13723 symhdr
->isymMax
= 0;
13724 symhdr
->ioptMax
= 0;
13725 symhdr
->iauxMax
= 0;
13726 symhdr
->issMax
= 0;
13727 symhdr
->issExtMax
= 0;
13728 symhdr
->ifdMax
= 0;
13730 symhdr
->iextMax
= 0;
13732 /* We accumulate the debugging information itself in the
13733 debug_info structure. */
13735 debug
.external_dnr
= NULL
;
13736 debug
.external_pdr
= NULL
;
13737 debug
.external_sym
= NULL
;
13738 debug
.external_opt
= NULL
;
13739 debug
.external_aux
= NULL
;
13741 debug
.ssext
= debug
.ssext_end
= NULL
;
13742 debug
.external_fdr
= NULL
;
13743 debug
.external_rfd
= NULL
;
13744 debug
.external_ext
= debug
.external_ext_end
= NULL
;
13746 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
13747 if (mdebug_handle
== NULL
)
13751 esym
.cobol_main
= 0;
13755 esym
.asym
.iss
= issNil
;
13756 esym
.asym
.st
= stLocal
;
13757 esym
.asym
.reserved
= 0;
13758 esym
.asym
.index
= indexNil
;
13760 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
13762 esym
.asym
.sc
= sc
[i
];
13763 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
13766 esym
.asym
.value
= s
->vma
;
13767 last
= s
->vma
+ s
->size
;
13770 esym
.asym
.value
= last
;
13771 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
13772 secname
[i
], &esym
))
13776 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
13778 asection
*input_section
;
13780 const struct ecoff_debug_swap
*input_swap
;
13781 struct ecoff_debug_info input_debug
;
13785 if (p
->type
!= bfd_indirect_link_order
)
13787 if (p
->type
== bfd_data_link_order
)
13792 input_section
= p
->u
.indirect
.section
;
13793 input_bfd
= input_section
->owner
;
13795 if (!is_mips_elf (input_bfd
))
13797 /* I don't know what a non MIPS ELF bfd would be
13798 doing with a .mdebug section, but I don't really
13799 want to deal with it. */
13803 input_swap
= (get_elf_backend_data (input_bfd
)
13804 ->elf_backend_ecoff_debug_swap
);
13806 BFD_ASSERT (p
->size
== input_section
->size
);
13808 /* The ECOFF linking code expects that we have already
13809 read in the debugging information and set up an
13810 ecoff_debug_info structure, so we do that now. */
13811 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
13815 if (! (bfd_ecoff_debug_accumulate
13816 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
13817 &input_debug
, input_swap
, info
)))
13820 /* Loop through the external symbols. For each one with
13821 interesting information, try to find the symbol in
13822 the linker global hash table and save the information
13823 for the output external symbols. */
13824 eraw_src
= input_debug
.external_ext
;
13825 eraw_end
= (eraw_src
13826 + (input_debug
.symbolic_header
.iextMax
13827 * input_swap
->external_ext_size
));
13829 eraw_src
< eraw_end
;
13830 eraw_src
+= input_swap
->external_ext_size
)
13834 struct mips_elf_link_hash_entry
*h
;
13836 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
13837 if (ext
.asym
.sc
== scNil
13838 || ext
.asym
.sc
== scUndefined
13839 || ext
.asym
.sc
== scSUndefined
)
13842 name
= input_debug
.ssext
+ ext
.asym
.iss
;
13843 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
13844 name
, FALSE
, FALSE
, TRUE
);
13845 if (h
== NULL
|| h
->esym
.ifd
!= -2)
13850 BFD_ASSERT (ext
.ifd
13851 < input_debug
.symbolic_header
.ifdMax
);
13852 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
13858 /* Free up the information we just read. */
13859 free (input_debug
.line
);
13860 free (input_debug
.external_dnr
);
13861 free (input_debug
.external_pdr
);
13862 free (input_debug
.external_sym
);
13863 free (input_debug
.external_opt
);
13864 free (input_debug
.external_aux
);
13865 free (input_debug
.ss
);
13866 free (input_debug
.ssext
);
13867 free (input_debug
.external_fdr
);
13868 free (input_debug
.external_rfd
);
13869 free (input_debug
.external_ext
);
13871 /* Hack: reset the SEC_HAS_CONTENTS flag so that
13872 elf_link_input_bfd ignores this section. */
13873 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
13876 if (SGI_COMPAT (abfd
) && info
->shared
)
13878 /* Create .rtproc section. */
13879 rtproc_sec
= bfd_get_linker_section (abfd
, ".rtproc");
13880 if (rtproc_sec
== NULL
)
13882 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
13883 | SEC_LINKER_CREATED
| SEC_READONLY
);
13885 rtproc_sec
= bfd_make_section_anyway_with_flags (abfd
,
13888 if (rtproc_sec
== NULL
13889 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
13893 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
13899 /* Build the external symbol information. */
13902 einfo
.debug
= &debug
;
13904 einfo
.failed
= FALSE
;
13905 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
13906 mips_elf_output_extsym
, &einfo
);
13910 /* Set the size of the .mdebug section. */
13911 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
13913 /* Skip this section later on (I don't think this currently
13914 matters, but someday it might). */
13915 o
->map_head
.link_order
= NULL
;
13920 if (CONST_STRNEQ (o
->name
, ".gptab."))
13922 const char *subname
;
13925 Elf32_External_gptab
*ext_tab
;
13928 /* The .gptab.sdata and .gptab.sbss sections hold
13929 information describing how the small data area would
13930 change depending upon the -G switch. These sections
13931 not used in executables files. */
13932 if (! info
->relocatable
)
13934 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
13936 asection
*input_section
;
13938 if (p
->type
!= bfd_indirect_link_order
)
13940 if (p
->type
== bfd_data_link_order
)
13945 input_section
= p
->u
.indirect
.section
;
13947 /* Hack: reset the SEC_HAS_CONTENTS flag so that
13948 elf_link_input_bfd ignores this section. */
13949 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
13952 /* Skip this section later on (I don't think this
13953 currently matters, but someday it might). */
13954 o
->map_head
.link_order
= NULL
;
13956 /* Really remove the section. */
13957 bfd_section_list_remove (abfd
, o
);
13958 --abfd
->section_count
;
13963 /* There is one gptab for initialized data, and one for
13964 uninitialized data. */
13965 if (strcmp (o
->name
, ".gptab.sdata") == 0)
13966 gptab_data_sec
= o
;
13967 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
13971 (*_bfd_error_handler
)
13972 (_("%s: illegal section name `%s'"),
13973 bfd_get_filename (abfd
), o
->name
);
13974 bfd_set_error (bfd_error_nonrepresentable_section
);
13978 /* The linker script always combines .gptab.data and
13979 .gptab.sdata into .gptab.sdata, and likewise for
13980 .gptab.bss and .gptab.sbss. It is possible that there is
13981 no .sdata or .sbss section in the output file, in which
13982 case we must change the name of the output section. */
13983 subname
= o
->name
+ sizeof ".gptab" - 1;
13984 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
13986 if (o
== gptab_data_sec
)
13987 o
->name
= ".gptab.data";
13989 o
->name
= ".gptab.bss";
13990 subname
= o
->name
+ sizeof ".gptab" - 1;
13991 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
13994 /* Set up the first entry. */
13996 amt
= c
* sizeof (Elf32_gptab
);
13997 tab
= bfd_malloc (amt
);
14000 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
14001 tab
[0].gt_header
.gt_unused
= 0;
14003 /* Combine the input sections. */
14004 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
14006 asection
*input_section
;
14008 bfd_size_type size
;
14009 unsigned long last
;
14010 bfd_size_type gpentry
;
14012 if (p
->type
!= bfd_indirect_link_order
)
14014 if (p
->type
== bfd_data_link_order
)
14019 input_section
= p
->u
.indirect
.section
;
14020 input_bfd
= input_section
->owner
;
14022 /* Combine the gptab entries for this input section one
14023 by one. We know that the input gptab entries are
14024 sorted by ascending -G value. */
14025 size
= input_section
->size
;
14027 for (gpentry
= sizeof (Elf32_External_gptab
);
14029 gpentry
+= sizeof (Elf32_External_gptab
))
14031 Elf32_External_gptab ext_gptab
;
14032 Elf32_gptab int_gptab
;
14038 if (! (bfd_get_section_contents
14039 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
14040 sizeof (Elf32_External_gptab
))))
14046 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
14048 val
= int_gptab
.gt_entry
.gt_g_value
;
14049 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
14052 for (look
= 1; look
< c
; look
++)
14054 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
14055 tab
[look
].gt_entry
.gt_bytes
+= add
;
14057 if (tab
[look
].gt_entry
.gt_g_value
== val
)
14063 Elf32_gptab
*new_tab
;
14066 /* We need a new table entry. */
14067 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
14068 new_tab
= bfd_realloc (tab
, amt
);
14069 if (new_tab
== NULL
)
14075 tab
[c
].gt_entry
.gt_g_value
= val
;
14076 tab
[c
].gt_entry
.gt_bytes
= add
;
14078 /* Merge in the size for the next smallest -G
14079 value, since that will be implied by this new
14082 for (look
= 1; look
< c
; look
++)
14084 if (tab
[look
].gt_entry
.gt_g_value
< val
14086 || (tab
[look
].gt_entry
.gt_g_value
14087 > tab
[max
].gt_entry
.gt_g_value
)))
14091 tab
[c
].gt_entry
.gt_bytes
+=
14092 tab
[max
].gt_entry
.gt_bytes
;
14097 last
= int_gptab
.gt_entry
.gt_bytes
;
14100 /* Hack: reset the SEC_HAS_CONTENTS flag so that
14101 elf_link_input_bfd ignores this section. */
14102 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
14105 /* The table must be sorted by -G value. */
14107 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
14109 /* Swap out the table. */
14110 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
14111 ext_tab
= bfd_alloc (abfd
, amt
);
14112 if (ext_tab
== NULL
)
14118 for (j
= 0; j
< c
; j
++)
14119 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
14122 o
->size
= c
* sizeof (Elf32_External_gptab
);
14123 o
->contents
= (bfd_byte
*) ext_tab
;
14125 /* Skip this section later on (I don't think this currently
14126 matters, but someday it might). */
14127 o
->map_head
.link_order
= NULL
;
14131 /* Invoke the regular ELF backend linker to do all the work. */
14132 if (!bfd_elf_final_link (abfd
, info
))
14135 /* Now write out the computed sections. */
14137 if (reginfo_sec
!= NULL
)
14139 Elf32_External_RegInfo ext
;
14141 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
14142 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
14146 if (mdebug_sec
!= NULL
)
14148 BFD_ASSERT (abfd
->output_has_begun
);
14149 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
14151 mdebug_sec
->filepos
))
14154 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
14157 if (gptab_data_sec
!= NULL
)
14159 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
14160 gptab_data_sec
->contents
,
14161 0, gptab_data_sec
->size
))
14165 if (gptab_bss_sec
!= NULL
)
14167 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
14168 gptab_bss_sec
->contents
,
14169 0, gptab_bss_sec
->size
))
14173 if (SGI_COMPAT (abfd
))
14175 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
14176 if (rtproc_sec
!= NULL
)
14178 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
14179 rtproc_sec
->contents
,
14180 0, rtproc_sec
->size
))
14188 /* Structure for saying that BFD machine EXTENSION extends BASE. */
14190 struct mips_mach_extension
14192 unsigned long extension
, base
;
14196 /* An array describing how BFD machines relate to one another. The entries
14197 are ordered topologically with MIPS I extensions listed last. */
14199 static const struct mips_mach_extension mips_mach_extensions
[] =
14201 /* MIPS64r2 extensions. */
14202 { bfd_mach_mips_octeon2
, bfd_mach_mips_octeonp
},
14203 { bfd_mach_mips_octeonp
, bfd_mach_mips_octeon
},
14204 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
14206 /* MIPS64 extensions. */
14207 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
14208 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
14209 { bfd_mach_mips_xlr
, bfd_mach_mipsisa64
},
14210 { bfd_mach_mips_loongson_3a
, bfd_mach_mipsisa64
},
14212 /* MIPS V extensions. */
14213 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
14215 /* R10000 extensions. */
14216 { bfd_mach_mips12000
, bfd_mach_mips10000
},
14217 { bfd_mach_mips14000
, bfd_mach_mips10000
},
14218 { bfd_mach_mips16000
, bfd_mach_mips10000
},
14220 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
14221 vr5400 ISA, but doesn't include the multimedia stuff. It seems
14222 better to allow vr5400 and vr5500 code to be merged anyway, since
14223 many libraries will just use the core ISA. Perhaps we could add
14224 some sort of ASE flag if this ever proves a problem. */
14225 { bfd_mach_mips5500
, bfd_mach_mips5400
},
14226 { bfd_mach_mips5400
, bfd_mach_mips5000
},
14228 /* MIPS IV extensions. */
14229 { bfd_mach_mips5
, bfd_mach_mips8000
},
14230 { bfd_mach_mips10000
, bfd_mach_mips8000
},
14231 { bfd_mach_mips5000
, bfd_mach_mips8000
},
14232 { bfd_mach_mips7000
, bfd_mach_mips8000
},
14233 { bfd_mach_mips9000
, bfd_mach_mips8000
},
14235 /* VR4100 extensions. */
14236 { bfd_mach_mips4120
, bfd_mach_mips4100
},
14237 { bfd_mach_mips4111
, bfd_mach_mips4100
},
14239 /* MIPS III extensions. */
14240 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
14241 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
14242 { bfd_mach_mips8000
, bfd_mach_mips4000
},
14243 { bfd_mach_mips4650
, bfd_mach_mips4000
},
14244 { bfd_mach_mips4600
, bfd_mach_mips4000
},
14245 { bfd_mach_mips4400
, bfd_mach_mips4000
},
14246 { bfd_mach_mips4300
, bfd_mach_mips4000
},
14247 { bfd_mach_mips4100
, bfd_mach_mips4000
},
14248 { bfd_mach_mips4010
, bfd_mach_mips4000
},
14249 { bfd_mach_mips5900
, bfd_mach_mips4000
},
14251 /* MIPS32 extensions. */
14252 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
14254 /* MIPS II extensions. */
14255 { bfd_mach_mips4000
, bfd_mach_mips6000
},
14256 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
14258 /* MIPS I extensions. */
14259 { bfd_mach_mips6000
, bfd_mach_mips3000
},
14260 { bfd_mach_mips3900
, bfd_mach_mips3000
}
14264 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
14267 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
14271 if (extension
== base
)
14274 if (base
== bfd_mach_mipsisa32
14275 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
14278 if (base
== bfd_mach_mipsisa32r2
14279 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
14282 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
14283 if (extension
== mips_mach_extensions
[i
].extension
)
14285 extension
= mips_mach_extensions
[i
].base
;
14286 if (extension
== base
)
14294 /* Return true if the given ELF header flags describe a 32-bit binary. */
14297 mips_32bit_flags_p (flagword flags
)
14299 return ((flags
& EF_MIPS_32BITMODE
) != 0
14300 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
14301 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
14302 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
14303 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
14304 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
14305 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
14309 /* Merge object attributes from IBFD into OBFD. Raise an error if
14310 there are conflicting attributes. */
14312 mips_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
14314 obj_attribute
*in_attr
;
14315 obj_attribute
*out_attr
;
14318 abi_fp_bfd
= mips_elf_tdata (obfd
)->abi_fp_bfd
;
14319 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
14320 if (!abi_fp_bfd
&& in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= Val_GNU_MIPS_ABI_FP_ANY
)
14321 mips_elf_tdata (obfd
)->abi_fp_bfd
= ibfd
;
14323 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
14325 /* This is the first object. Copy the attributes. */
14326 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
14328 /* Use the Tag_null value to indicate the attributes have been
14330 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
14335 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
14336 non-conflicting ones. */
14337 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
14338 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
14340 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
14341 if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
== Val_GNU_MIPS_ABI_FP_ANY
)
14342 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
14343 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= Val_GNU_MIPS_ABI_FP_ANY
)
14344 switch (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
14346 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
14347 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
14349 case Val_GNU_MIPS_ABI_FP_SINGLE
:
14351 (_("Warning: %B uses %s (set by %B), %B uses %s"),
14352 obfd
, abi_fp_bfd
, ibfd
, "-mdouble-float", "-msingle-float");
14355 case Val_GNU_MIPS_ABI_FP_SOFT
:
14357 (_("Warning: %B uses %s (set by %B), %B uses %s"),
14358 obfd
, abi_fp_bfd
, ibfd
, "-mhard-float", "-msoft-float");
14361 case Val_GNU_MIPS_ABI_FP_64
:
14363 (_("Warning: %B uses %s (set by %B), %B uses %s"),
14364 obfd
, abi_fp_bfd
, ibfd
,
14365 "-mdouble-float", "-mips32r2 -mfp64");
14370 (_("Warning: %B uses %s (set by %B), "
14371 "%B uses unknown floating point ABI %d"),
14372 obfd
, abi_fp_bfd
, ibfd
,
14373 "-mdouble-float", in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
14378 case Val_GNU_MIPS_ABI_FP_SINGLE
:
14379 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
14381 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
14383 (_("Warning: %B uses %s (set by %B), %B uses %s"),
14384 obfd
, abi_fp_bfd
, ibfd
, "-msingle-float", "-mdouble-float");
14387 case Val_GNU_MIPS_ABI_FP_SOFT
:
14389 (_("Warning: %B uses %s (set by %B), %B uses %s"),
14390 obfd
, abi_fp_bfd
, ibfd
, "-mhard-float", "-msoft-float");
14393 case Val_GNU_MIPS_ABI_FP_64
:
14395 (_("Warning: %B uses %s (set by %B), %B uses %s"),
14396 obfd
, abi_fp_bfd
, ibfd
,
14397 "-msingle-float", "-mips32r2 -mfp64");
14402 (_("Warning: %B uses %s (set by %B), "
14403 "%B uses unknown floating point ABI %d"),
14404 obfd
, abi_fp_bfd
, ibfd
,
14405 "-msingle-float", in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
14410 case Val_GNU_MIPS_ABI_FP_SOFT
:
14411 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
14413 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
14414 case Val_GNU_MIPS_ABI_FP_SINGLE
:
14415 case Val_GNU_MIPS_ABI_FP_64
:
14417 (_("Warning: %B uses %s (set by %B), %B uses %s"),
14418 obfd
, abi_fp_bfd
, ibfd
, "-msoft-float", "-mhard-float");
14423 (_("Warning: %B uses %s (set by %B), "
14424 "%B uses unknown floating point ABI %d"),
14425 obfd
, abi_fp_bfd
, ibfd
,
14426 "-msoft-float", in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
14431 case Val_GNU_MIPS_ABI_FP_64
:
14432 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
14434 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
14436 (_("Warning: %B uses %s (set by %B), %B uses %s"),
14437 obfd
, abi_fp_bfd
, ibfd
,
14438 "-mips32r2 -mfp64", "-mdouble-float");
14441 case Val_GNU_MIPS_ABI_FP_SINGLE
:
14443 (_("Warning: %B uses %s (set by %B), %B uses %s"),
14444 obfd
, abi_fp_bfd
, ibfd
,
14445 "-mips32r2 -mfp64", "-msingle-float");
14448 case Val_GNU_MIPS_ABI_FP_SOFT
:
14450 (_("Warning: %B uses %s (set by %B), %B uses %s"),
14451 obfd
, abi_fp_bfd
, ibfd
, "-mhard-float", "-msoft-float");
14456 (_("Warning: %B uses %s (set by %B), "
14457 "%B uses unknown floating point ABI %d"),
14458 obfd
, abi_fp_bfd
, ibfd
,
14459 "-mips32r2 -mfp64", in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
14465 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
14467 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
14469 (_("Warning: %B uses unknown floating point ABI %d "
14470 "(set by %B), %B uses %s"),
14471 obfd
, abi_fp_bfd
, ibfd
,
14472 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
, "-mdouble-float");
14475 case Val_GNU_MIPS_ABI_FP_SINGLE
:
14477 (_("Warning: %B uses unknown floating point ABI %d "
14478 "(set by %B), %B uses %s"),
14479 obfd
, abi_fp_bfd
, ibfd
,
14480 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
, "-msingle-float");
14483 case Val_GNU_MIPS_ABI_FP_SOFT
:
14485 (_("Warning: %B uses unknown floating point ABI %d "
14486 "(set by %B), %B uses %s"),
14487 obfd
, abi_fp_bfd
, ibfd
,
14488 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
, "-msoft-float");
14491 case Val_GNU_MIPS_ABI_FP_64
:
14493 (_("Warning: %B uses unknown floating point ABI %d "
14494 "(set by %B), %B uses %s"),
14495 obfd
, abi_fp_bfd
, ibfd
,
14496 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
, "-mips32r2 -mfp64");
14501 (_("Warning: %B uses unknown floating point ABI %d "
14502 "(set by %B), %B uses unknown floating point ABI %d"),
14503 obfd
, abi_fp_bfd
, ibfd
,
14504 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
,
14505 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
14512 /* Merge Tag_compatibility attributes and any common GNU ones. */
14513 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
14518 /* Merge backend specific data from an object file to the output
14519 object file when linking. */
14522 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
14524 flagword old_flags
;
14525 flagword new_flags
;
14527 bfd_boolean null_input_bfd
= TRUE
;
14530 /* Check if we have the same endianness. */
14531 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
14533 (*_bfd_error_handler
)
14534 (_("%B: endianness incompatible with that of the selected emulation"),
14539 if (!is_mips_elf (ibfd
) || !is_mips_elf (obfd
))
14542 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
14544 (*_bfd_error_handler
)
14545 (_("%B: ABI is incompatible with that of the selected emulation"),
14550 if (!mips_elf_merge_obj_attributes (ibfd
, obfd
))
14553 new_flags
= elf_elfheader (ibfd
)->e_flags
;
14554 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
14555 old_flags
= elf_elfheader (obfd
)->e_flags
;
14557 if (! elf_flags_init (obfd
))
14559 elf_flags_init (obfd
) = TRUE
;
14560 elf_elfheader (obfd
)->e_flags
= new_flags
;
14561 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
14562 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
14564 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
14565 && (bfd_get_arch_info (obfd
)->the_default
14566 || mips_mach_extends_p (bfd_get_mach (obfd
),
14567 bfd_get_mach (ibfd
))))
14569 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
14570 bfd_get_mach (ibfd
)))
14577 /* Check flag compatibility. */
14579 new_flags
&= ~EF_MIPS_NOREORDER
;
14580 old_flags
&= ~EF_MIPS_NOREORDER
;
14582 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
14583 doesn't seem to matter. */
14584 new_flags
&= ~EF_MIPS_XGOT
;
14585 old_flags
&= ~EF_MIPS_XGOT
;
14587 /* MIPSpro generates ucode info in n64 objects. Again, we should
14588 just be able to ignore this. */
14589 new_flags
&= ~EF_MIPS_UCODE
;
14590 old_flags
&= ~EF_MIPS_UCODE
;
14592 /* DSOs should only be linked with CPIC code. */
14593 if ((ibfd
->flags
& DYNAMIC
) != 0)
14594 new_flags
|= EF_MIPS_PIC
| EF_MIPS_CPIC
;
14596 if (new_flags
== old_flags
)
14599 /* Check to see if the input BFD actually contains any sections.
14600 If not, its flags may not have been initialised either, but it cannot
14601 actually cause any incompatibility. */
14602 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
14604 /* Ignore synthetic sections and empty .text, .data and .bss sections
14605 which are automatically generated by gas. Also ignore fake
14606 (s)common sections, since merely defining a common symbol does
14607 not affect compatibility. */
14608 if ((sec
->flags
& SEC_IS_COMMON
) == 0
14609 && strcmp (sec
->name
, ".reginfo")
14610 && strcmp (sec
->name
, ".mdebug")
14612 || (strcmp (sec
->name
, ".text")
14613 && strcmp (sec
->name
, ".data")
14614 && strcmp (sec
->name
, ".bss"))))
14616 null_input_bfd
= FALSE
;
14620 if (null_input_bfd
)
14625 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
14626 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
14628 (*_bfd_error_handler
)
14629 (_("%B: warning: linking abicalls files with non-abicalls files"),
14634 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
14635 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
14636 if (! (new_flags
& EF_MIPS_PIC
))
14637 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
14639 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
14640 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
14642 /* Compare the ISAs. */
14643 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
14645 (*_bfd_error_handler
)
14646 (_("%B: linking 32-bit code with 64-bit code"),
14650 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
14652 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
14653 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
14655 /* Copy the architecture info from IBFD to OBFD. Also copy
14656 the 32-bit flag (if set) so that we continue to recognise
14657 OBFD as a 32-bit binary. */
14658 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
14659 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
14660 elf_elfheader (obfd
)->e_flags
14661 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
14663 /* Copy across the ABI flags if OBFD doesn't use them
14664 and if that was what caused us to treat IBFD as 32-bit. */
14665 if ((old_flags
& EF_MIPS_ABI
) == 0
14666 && mips_32bit_flags_p (new_flags
)
14667 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
14668 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
14672 /* The ISAs aren't compatible. */
14673 (*_bfd_error_handler
)
14674 (_("%B: linking %s module with previous %s modules"),
14676 bfd_printable_name (ibfd
),
14677 bfd_printable_name (obfd
));
14682 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
14683 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
14685 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
14686 does set EI_CLASS differently from any 32-bit ABI. */
14687 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
14688 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
14689 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
14691 /* Only error if both are set (to different values). */
14692 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
14693 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
14694 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
14696 (*_bfd_error_handler
)
14697 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
14699 elf_mips_abi_name (ibfd
),
14700 elf_mips_abi_name (obfd
));
14703 new_flags
&= ~EF_MIPS_ABI
;
14704 old_flags
&= ~EF_MIPS_ABI
;
14707 /* Compare ASEs. Forbid linking MIPS16 and microMIPS ASE modules together
14708 and allow arbitrary mixing of the remaining ASEs (retain the union). */
14709 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
14711 int old_micro
= old_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
;
14712 int new_micro
= new_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
;
14713 int old_m16
= old_flags
& EF_MIPS_ARCH_ASE_M16
;
14714 int new_m16
= new_flags
& EF_MIPS_ARCH_ASE_M16
;
14715 int micro_mis
= old_m16
&& new_micro
;
14716 int m16_mis
= old_micro
&& new_m16
;
14718 if (m16_mis
|| micro_mis
)
14720 (*_bfd_error_handler
)
14721 (_("%B: ASE mismatch: linking %s module with previous %s modules"),
14723 m16_mis
? "MIPS16" : "microMIPS",
14724 m16_mis
? "microMIPS" : "MIPS16");
14728 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
14730 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
14731 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
14734 /* Compare NaN encodings. */
14735 if ((new_flags
& EF_MIPS_NAN2008
) != (old_flags
& EF_MIPS_NAN2008
))
14737 _bfd_error_handler (_("%B: linking %s module with previous %s modules"),
14739 (new_flags
& EF_MIPS_NAN2008
14740 ? "-mnan=2008" : "-mnan=legacy"),
14741 (old_flags
& EF_MIPS_NAN2008
14742 ? "-mnan=2008" : "-mnan=legacy"));
14744 new_flags
&= ~EF_MIPS_NAN2008
;
14745 old_flags
&= ~EF_MIPS_NAN2008
;
14748 /* Warn about any other mismatches */
14749 if (new_flags
!= old_flags
)
14751 (*_bfd_error_handler
)
14752 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
14753 ibfd
, (unsigned long) new_flags
,
14754 (unsigned long) old_flags
);
14760 bfd_set_error (bfd_error_bad_value
);
14767 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
14770 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
14772 BFD_ASSERT (!elf_flags_init (abfd
)
14773 || elf_elfheader (abfd
)->e_flags
== flags
);
14775 elf_elfheader (abfd
)->e_flags
= flags
;
14776 elf_flags_init (abfd
) = TRUE
;
14781 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
14785 default: return "";
14786 case DT_MIPS_RLD_VERSION
:
14787 return "MIPS_RLD_VERSION";
14788 case DT_MIPS_TIME_STAMP
:
14789 return "MIPS_TIME_STAMP";
14790 case DT_MIPS_ICHECKSUM
:
14791 return "MIPS_ICHECKSUM";
14792 case DT_MIPS_IVERSION
:
14793 return "MIPS_IVERSION";
14794 case DT_MIPS_FLAGS
:
14795 return "MIPS_FLAGS";
14796 case DT_MIPS_BASE_ADDRESS
:
14797 return "MIPS_BASE_ADDRESS";
14799 return "MIPS_MSYM";
14800 case DT_MIPS_CONFLICT
:
14801 return "MIPS_CONFLICT";
14802 case DT_MIPS_LIBLIST
:
14803 return "MIPS_LIBLIST";
14804 case DT_MIPS_LOCAL_GOTNO
:
14805 return "MIPS_LOCAL_GOTNO";
14806 case DT_MIPS_CONFLICTNO
:
14807 return "MIPS_CONFLICTNO";
14808 case DT_MIPS_LIBLISTNO
:
14809 return "MIPS_LIBLISTNO";
14810 case DT_MIPS_SYMTABNO
:
14811 return "MIPS_SYMTABNO";
14812 case DT_MIPS_UNREFEXTNO
:
14813 return "MIPS_UNREFEXTNO";
14814 case DT_MIPS_GOTSYM
:
14815 return "MIPS_GOTSYM";
14816 case DT_MIPS_HIPAGENO
:
14817 return "MIPS_HIPAGENO";
14818 case DT_MIPS_RLD_MAP
:
14819 return "MIPS_RLD_MAP";
14820 case DT_MIPS_DELTA_CLASS
:
14821 return "MIPS_DELTA_CLASS";
14822 case DT_MIPS_DELTA_CLASS_NO
:
14823 return "MIPS_DELTA_CLASS_NO";
14824 case DT_MIPS_DELTA_INSTANCE
:
14825 return "MIPS_DELTA_INSTANCE";
14826 case DT_MIPS_DELTA_INSTANCE_NO
:
14827 return "MIPS_DELTA_INSTANCE_NO";
14828 case DT_MIPS_DELTA_RELOC
:
14829 return "MIPS_DELTA_RELOC";
14830 case DT_MIPS_DELTA_RELOC_NO
:
14831 return "MIPS_DELTA_RELOC_NO";
14832 case DT_MIPS_DELTA_SYM
:
14833 return "MIPS_DELTA_SYM";
14834 case DT_MIPS_DELTA_SYM_NO
:
14835 return "MIPS_DELTA_SYM_NO";
14836 case DT_MIPS_DELTA_CLASSSYM
:
14837 return "MIPS_DELTA_CLASSSYM";
14838 case DT_MIPS_DELTA_CLASSSYM_NO
:
14839 return "MIPS_DELTA_CLASSSYM_NO";
14840 case DT_MIPS_CXX_FLAGS
:
14841 return "MIPS_CXX_FLAGS";
14842 case DT_MIPS_PIXIE_INIT
:
14843 return "MIPS_PIXIE_INIT";
14844 case DT_MIPS_SYMBOL_LIB
:
14845 return "MIPS_SYMBOL_LIB";
14846 case DT_MIPS_LOCALPAGE_GOTIDX
:
14847 return "MIPS_LOCALPAGE_GOTIDX";
14848 case DT_MIPS_LOCAL_GOTIDX
:
14849 return "MIPS_LOCAL_GOTIDX";
14850 case DT_MIPS_HIDDEN_GOTIDX
:
14851 return "MIPS_HIDDEN_GOTIDX";
14852 case DT_MIPS_PROTECTED_GOTIDX
:
14853 return "MIPS_PROTECTED_GOT_IDX";
14854 case DT_MIPS_OPTIONS
:
14855 return "MIPS_OPTIONS";
14856 case DT_MIPS_INTERFACE
:
14857 return "MIPS_INTERFACE";
14858 case DT_MIPS_DYNSTR_ALIGN
:
14859 return "DT_MIPS_DYNSTR_ALIGN";
14860 case DT_MIPS_INTERFACE_SIZE
:
14861 return "DT_MIPS_INTERFACE_SIZE";
14862 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
14863 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
14864 case DT_MIPS_PERF_SUFFIX
:
14865 return "DT_MIPS_PERF_SUFFIX";
14866 case DT_MIPS_COMPACT_SIZE
:
14867 return "DT_MIPS_COMPACT_SIZE";
14868 case DT_MIPS_GP_VALUE
:
14869 return "DT_MIPS_GP_VALUE";
14870 case DT_MIPS_AUX_DYNAMIC
:
14871 return "DT_MIPS_AUX_DYNAMIC";
14872 case DT_MIPS_PLTGOT
:
14873 return "DT_MIPS_PLTGOT";
14874 case DT_MIPS_RWPLT
:
14875 return "DT_MIPS_RWPLT";
14880 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
14884 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
14886 /* Print normal ELF private data. */
14887 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
14889 /* xgettext:c-format */
14890 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
14892 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
14893 fprintf (file
, _(" [abi=O32]"));
14894 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
14895 fprintf (file
, _(" [abi=O64]"));
14896 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
14897 fprintf (file
, _(" [abi=EABI32]"));
14898 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
14899 fprintf (file
, _(" [abi=EABI64]"));
14900 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
14901 fprintf (file
, _(" [abi unknown]"));
14902 else if (ABI_N32_P (abfd
))
14903 fprintf (file
, _(" [abi=N32]"));
14904 else if (ABI_64_P (abfd
))
14905 fprintf (file
, _(" [abi=64]"));
14907 fprintf (file
, _(" [no abi set]"));
14909 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
14910 fprintf (file
, " [mips1]");
14911 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
14912 fprintf (file
, " [mips2]");
14913 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
14914 fprintf (file
, " [mips3]");
14915 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
14916 fprintf (file
, " [mips4]");
14917 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
14918 fprintf (file
, " [mips5]");
14919 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
14920 fprintf (file
, " [mips32]");
14921 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
14922 fprintf (file
, " [mips64]");
14923 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
14924 fprintf (file
, " [mips32r2]");
14925 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
14926 fprintf (file
, " [mips64r2]");
14928 fprintf (file
, _(" [unknown ISA]"));
14930 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
14931 fprintf (file
, " [mdmx]");
14933 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
14934 fprintf (file
, " [mips16]");
14936 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
14937 fprintf (file
, " [micromips]");
14939 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NAN2008
)
14940 fprintf (file
, " [nan2008]");
14942 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_FP64
)
14943 fprintf (file
, " [fp64]");
14945 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
14946 fprintf (file
, " [32bitmode]");
14948 fprintf (file
, _(" [not 32bitmode]"));
14950 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
14951 fprintf (file
, " [noreorder]");
14953 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
14954 fprintf (file
, " [PIC]");
14956 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
14957 fprintf (file
, " [CPIC]");
14959 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
14960 fprintf (file
, " [XGOT]");
14962 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
14963 fprintf (file
, " [UCODE]");
14965 fputc ('\n', file
);
14970 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
14972 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
14973 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
14974 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
14975 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
14976 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
14977 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
14978 { NULL
, 0, 0, 0, 0 }
14981 /* Merge non visibility st_other attributes. Ensure that the
14982 STO_OPTIONAL flag is copied into h->other, even if this is not a
14983 definiton of the symbol. */
14985 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
14986 const Elf_Internal_Sym
*isym
,
14987 bfd_boolean definition
,
14988 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
14990 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
14992 unsigned char other
;
14994 other
= (definition
? isym
->st_other
: h
->other
);
14995 other
&= ~ELF_ST_VISIBILITY (-1);
14996 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
15000 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
15001 h
->other
|= STO_OPTIONAL
;
15004 /* Decide whether an undefined symbol is special and can be ignored.
15005 This is the case for OPTIONAL symbols on IRIX. */
15007 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
15009 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
15013 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
15015 return (sym
->st_shndx
== SHN_COMMON
15016 || sym
->st_shndx
== SHN_MIPS_ACOMMON
15017 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);
15020 /* Return address for Ith PLT stub in section PLT, for relocation REL
15021 or (bfd_vma) -1 if it should not be included. */
15024 _bfd_mips_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
15025 const arelent
*rel ATTRIBUTE_UNUSED
)
15028 + 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
)
15029 + i
* 4 * ARRAY_SIZE (mips_exec_plt_entry
));
15032 /* Build a table of synthetic symbols to represent the PLT. As with MIPS16
15033 and microMIPS PLT slots we may have a many-to-one mapping between .plt
15034 and .got.plt and also the slots may be of a different size each we walk
15035 the PLT manually fetching instructions and matching them against known
15036 patterns. To make things easier standard MIPS slots, if any, always come
15037 first. As we don't create proper ELF symbols we use the UDATA.I member
15038 of ASYMBOL to carry ISA annotation. The encoding used is the same as
15039 with the ST_OTHER member of the ELF symbol. */
15042 _bfd_mips_elf_get_synthetic_symtab (bfd
*abfd
,
15043 long symcount ATTRIBUTE_UNUSED
,
15044 asymbol
**syms ATTRIBUTE_UNUSED
,
15045 long dynsymcount
, asymbol
**dynsyms
,
15048 static const char pltname
[] = "_PROCEDURE_LINKAGE_TABLE_";
15049 static const char microsuffix
[] = "@micromipsplt";
15050 static const char m16suffix
[] = "@mips16plt";
15051 static const char mipssuffix
[] = "@plt";
15053 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
15054 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
15055 bfd_boolean micromips_p
= MICROMIPS_P (abfd
);
15056 Elf_Internal_Shdr
*hdr
;
15057 bfd_byte
*plt_data
;
15058 bfd_vma plt_offset
;
15059 unsigned int other
;
15060 bfd_vma entry_size
;
15079 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0 || dynsymcount
<= 0)
15082 relplt
= bfd_get_section_by_name (abfd
, ".rel.plt");
15083 if (relplt
== NULL
)
15086 hdr
= &elf_section_data (relplt
)->this_hdr
;
15087 if (hdr
->sh_link
!= elf_dynsymtab (abfd
) || hdr
->sh_type
!= SHT_REL
)
15090 plt
= bfd_get_section_by_name (abfd
, ".plt");
15094 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
15095 if (!(*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
15097 p
= relplt
->relocation
;
15099 /* Calculating the exact amount of space required for symbols would
15100 require two passes over the PLT, so just pessimise assuming two
15101 PLT slots per relocation. */
15102 count
= relplt
->size
/ hdr
->sh_entsize
;
15103 counti
= count
* bed
->s
->int_rels_per_ext_rel
;
15104 size
= 2 * count
* sizeof (asymbol
);
15105 size
+= count
* (sizeof (mipssuffix
) +
15106 (micromips_p
? sizeof (microsuffix
) : sizeof (m16suffix
)));
15107 for (pi
= 0; pi
< counti
; pi
+= bed
->s
->int_rels_per_ext_rel
)
15108 size
+= 2 * strlen ((*p
[pi
].sym_ptr_ptr
)->name
);
15110 /* Add the size of "_PROCEDURE_LINKAGE_TABLE_" too. */
15111 size
+= sizeof (asymbol
) + sizeof (pltname
);
15113 if (!bfd_malloc_and_get_section (abfd
, plt
, &plt_data
))
15116 if (plt
->size
< 16)
15119 s
= *ret
= bfd_malloc (size
);
15122 send
= s
+ 2 * count
+ 1;
15124 names
= (char *) send
;
15125 nend
= (char *) s
+ size
;
15128 opcode
= bfd_get_micromips_32 (abfd
, plt_data
+ 12);
15129 if (opcode
== 0x3302fffe)
15133 plt0_size
= 2 * ARRAY_SIZE (micromips_o32_exec_plt0_entry
);
15134 other
= STO_MICROMIPS
;
15136 else if (opcode
== 0x0398c1d0)
15140 plt0_size
= 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt0_entry
);
15141 other
= STO_MICROMIPS
;
15145 plt0_size
= 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
);
15150 s
->flags
= BSF_SYNTHETIC
| BSF_FUNCTION
| BSF_LOCAL
;
15154 s
->udata
.i
= other
;
15155 memcpy (names
, pltname
, sizeof (pltname
));
15156 names
+= sizeof (pltname
);
15160 for (plt_offset
= plt0_size
;
15161 plt_offset
+ 8 <= plt
->size
&& s
< send
;
15162 plt_offset
+= entry_size
)
15164 bfd_vma gotplt_addr
;
15165 const char *suffix
;
15170 opcode
= bfd_get_micromips_32 (abfd
, plt_data
+ plt_offset
+ 4);
15172 /* Check if the second word matches the expected MIPS16 instruction. */
15173 if (opcode
== 0x651aeb00)
15177 /* Truncated table??? */
15178 if (plt_offset
+ 16 > plt
->size
)
15180 gotplt_addr
= bfd_get_32 (abfd
, plt_data
+ plt_offset
+ 12);
15181 entry_size
= 2 * ARRAY_SIZE (mips16_o32_exec_plt_entry
);
15182 suffixlen
= sizeof (m16suffix
);
15183 suffix
= m16suffix
;
15184 other
= STO_MIPS16
;
15186 /* Likewise the expected microMIPS instruction (no insn32 mode). */
15187 else if (opcode
== 0xff220000)
15191 gotplt_hi
= bfd_get_16 (abfd
, plt_data
+ plt_offset
) & 0x7f;
15192 gotplt_lo
= bfd_get_16 (abfd
, plt_data
+ plt_offset
+ 2) & 0xffff;
15193 gotplt_hi
= ((gotplt_hi
^ 0x40) - 0x40) << 18;
15195 gotplt_addr
= gotplt_hi
+ gotplt_lo
;
15196 gotplt_addr
+= ((plt
->vma
+ plt_offset
) | 3) ^ 3;
15197 entry_size
= 2 * ARRAY_SIZE (micromips_o32_exec_plt_entry
);
15198 suffixlen
= sizeof (microsuffix
);
15199 suffix
= microsuffix
;
15200 other
= STO_MICROMIPS
;
15202 /* Likewise the expected microMIPS instruction (insn32 mode). */
15203 else if ((opcode
& 0xffff0000) == 0xff2f0000)
15205 gotplt_hi
= bfd_get_16 (abfd
, plt_data
+ plt_offset
+ 2) & 0xffff;
15206 gotplt_lo
= bfd_get_16 (abfd
, plt_data
+ plt_offset
+ 6) & 0xffff;
15207 gotplt_hi
= ((gotplt_hi
^ 0x8000) - 0x8000) << 16;
15208 gotplt_lo
= (gotplt_lo
^ 0x8000) - 0x8000;
15209 gotplt_addr
= gotplt_hi
+ gotplt_lo
;
15210 entry_size
= 2 * ARRAY_SIZE (micromips_insn32_o32_exec_plt_entry
);
15211 suffixlen
= sizeof (microsuffix
);
15212 suffix
= microsuffix
;
15213 other
= STO_MICROMIPS
;
15215 /* Otherwise assume standard MIPS code. */
15218 gotplt_hi
= bfd_get_32 (abfd
, plt_data
+ plt_offset
) & 0xffff;
15219 gotplt_lo
= bfd_get_32 (abfd
, plt_data
+ plt_offset
+ 4) & 0xffff;
15220 gotplt_hi
= ((gotplt_hi
^ 0x8000) - 0x8000) << 16;
15221 gotplt_lo
= (gotplt_lo
^ 0x8000) - 0x8000;
15222 gotplt_addr
= gotplt_hi
+ gotplt_lo
;
15223 entry_size
= 4 * ARRAY_SIZE (mips_exec_plt_entry
);
15224 suffixlen
= sizeof (mipssuffix
);
15225 suffix
= mipssuffix
;
15228 /* Truncated table??? */
15229 if (plt_offset
+ entry_size
> plt
->size
)
15233 i
< count
&& p
[pi
].address
!= gotplt_addr
;
15234 i
++, pi
= (pi
+ bed
->s
->int_rels_per_ext_rel
) % counti
);
15241 *s
= **p
[pi
].sym_ptr_ptr
;
15242 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
15243 we are defining a symbol, ensure one of them is set. */
15244 if ((s
->flags
& BSF_LOCAL
) == 0)
15245 s
->flags
|= BSF_GLOBAL
;
15246 s
->flags
|= BSF_SYNTHETIC
;
15248 s
->value
= plt_offset
;
15250 s
->udata
.i
= other
;
15252 len
= strlen ((*p
[pi
].sym_ptr_ptr
)->name
);
15253 namelen
= len
+ suffixlen
;
15254 if (names
+ namelen
> nend
)
15257 memcpy (names
, (*p
[pi
].sym_ptr_ptr
)->name
, len
);
15259 memcpy (names
, suffix
, suffixlen
);
15260 names
+= suffixlen
;
15263 pi
= (pi
+ bed
->s
->int_rels_per_ext_rel
) % counti
;
15273 _bfd_mips_post_process_headers (bfd
*abfd
, struct bfd_link_info
*link_info
)
15275 struct mips_elf_link_hash_table
*htab
;
15276 Elf_Internal_Ehdr
*i_ehdrp
;
15278 i_ehdrp
= elf_elfheader (abfd
);
15281 htab
= mips_elf_hash_table (link_info
);
15282 BFD_ASSERT (htab
!= NULL
);
15284 if (htab
->use_plts_and_copy_relocs
&& !htab
->is_vxworks
)
15285 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;