1 /* MIPS-specific support for ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
8 <mark@codesourcery.com>
9 Traditional MIPS targets support added by Koundinya.K, Dansk Data
10 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
12 This file is part of BFD, the Binary File Descriptor library.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
27 MA 02110-1301, USA. */
30 /* This file handles functionality common to the different MIPS ABI's. */
35 #include "libiberty.h"
37 #include "elfxx-mips.h"
39 #include "elf-vxworks.h"
41 /* Get the ECOFF swapping routines. */
43 #include "coff/symconst.h"
44 #include "coff/ecoff.h"
45 #include "coff/mips.h"
49 /* This structure is used to hold information about one GOT entry.
50 There are three types of entry:
52 (1) absolute addresses
54 (2) SYMBOL + OFFSET addresses, where SYMBOL is local to an input bfd
55 (abfd != NULL, symndx >= 0)
56 (3) global and forced-local symbols
57 (abfd != NULL, symndx == -1)
59 Type (3) entries are treated differently for different types of GOT.
60 In the "master" GOT -- i.e. the one that describes every GOT
61 reference needed in the link -- the mips_got_entry is keyed on both
62 the symbol and the input bfd that references it. If it turns out
63 that we need multiple GOTs, we can then use this information to
64 create separate GOTs for each input bfd.
66 However, we want each of these separate GOTs to have at most one
67 entry for a given symbol, so their type (3) entries are keyed only
68 on the symbol. The input bfd given by the "abfd" field is somewhat
69 arbitrary in this case.
71 This means that when there are multiple GOTs, each GOT has a unique
72 mips_got_entry for every symbol within it. We can therefore use the
73 mips_got_entry fields (tls_type and gotidx) to track the symbol's
76 However, if it turns out that we need only a single GOT, we continue
77 to use the master GOT to describe it. There may therefore be several
78 mips_got_entries for the same symbol, each with a different input bfd.
79 We want to make sure that each symbol gets a unique GOT entry, so when
80 there's a single GOT, we use the symbol's hash entry, not the
81 mips_got_entry fields, to track a symbol's GOT index. */
84 /* The input bfd in which the symbol is defined. */
86 /* The index of the symbol, as stored in the relocation r_info, if
87 we have a local symbol; -1 otherwise. */
91 /* If abfd == NULL, an address that must be stored in the got. */
93 /* If abfd != NULL && symndx != -1, the addend of the relocation
94 that should be added to the symbol value. */
96 /* If abfd != NULL && symndx == -1, the hash table entry
97 corresponding to a global symbol in the got (or, local, if
99 struct mips_elf_link_hash_entry
*h
;
102 /* The TLS types included in this GOT entry (specifically, GD and
103 IE). The GD and IE flags can be added as we encounter new
104 relocations. LDM can also be set; it will always be alone, not
105 combined with any GD or IE flags. An LDM GOT entry will be
106 a local symbol entry with r_symndx == 0. */
107 unsigned char tls_type
;
109 /* The offset from the beginning of the .got section to the entry
110 corresponding to this symbol+addend. If it's a global symbol
111 whose offset is yet to be decided, it's going to be -1. */
115 /* This structure describes a range of addends: [MIN_ADDEND, MAX_ADDEND].
116 The structures form a non-overlapping list that is sorted by increasing
118 struct mips_got_page_range
120 struct mips_got_page_range
*next
;
121 bfd_signed_vma min_addend
;
122 bfd_signed_vma max_addend
;
125 /* This structure describes the range of addends that are applied to page
126 relocations against a given symbol. */
127 struct mips_got_page_entry
129 /* The input bfd in which the symbol is defined. */
131 /* The index of the symbol, as stored in the relocation r_info. */
133 /* The ranges for this page entry. */
134 struct mips_got_page_range
*ranges
;
135 /* The maximum number of page entries needed for RANGES. */
139 /* This structure is used to hold .got information when linking. */
143 /* The global symbol in the GOT with the lowest index in the dynamic
145 struct elf_link_hash_entry
*global_gotsym
;
146 /* The number of global .got entries. */
147 unsigned int global_gotno
;
148 /* The number of global .got entries that are in the GGA_RELOC_ONLY area. */
149 unsigned int reloc_only_gotno
;
150 /* The number of .got slots used for TLS. */
151 unsigned int tls_gotno
;
152 /* The first unused TLS .got entry. Used only during
153 mips_elf_initialize_tls_index. */
154 unsigned int tls_assigned_gotno
;
155 /* The number of local .got entries, eventually including page entries. */
156 unsigned int local_gotno
;
157 /* The maximum number of page entries needed. */
158 unsigned int page_gotno
;
159 /* The number of local .got entries we have used. */
160 unsigned int assigned_gotno
;
161 /* A hash table holding members of the got. */
162 struct htab
*got_entries
;
163 /* A hash table of mips_got_page_entry structures. */
164 struct htab
*got_page_entries
;
165 /* A hash table mapping input bfds to other mips_got_info. NULL
166 unless multi-got was necessary. */
167 struct htab
*bfd2got
;
168 /* In multi-got links, a pointer to the next got (err, rather, most
169 of the time, it points to the previous got). */
170 struct mips_got_info
*next
;
171 /* This is the GOT index of the TLS LDM entry for the GOT, MINUS_ONE
172 for none, or MINUS_TWO for not yet assigned. This is needed
173 because a single-GOT link may have multiple hash table entries
174 for the LDM. It does not get initialized in multi-GOT mode. */
175 bfd_vma tls_ldm_offset
;
178 /* Map an input bfd to a got in a multi-got link. */
180 struct mips_elf_bfd2got_hash
{
182 struct mips_got_info
*g
;
185 /* Structure passed when traversing the bfd2got hash table, used to
186 create and merge bfd's gots. */
188 struct mips_elf_got_per_bfd_arg
190 /* A hashtable that maps bfds to gots. */
192 /* The output bfd. */
194 /* The link information. */
195 struct bfd_link_info
*info
;
196 /* A pointer to the primary got, i.e., the one that's going to get
197 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
199 struct mips_got_info
*primary
;
200 /* A non-primary got we're trying to merge with other input bfd's
202 struct mips_got_info
*current
;
203 /* The maximum number of got entries that can be addressed with a
205 unsigned int max_count
;
206 /* The maximum number of page entries needed by each got. */
207 unsigned int max_pages
;
208 /* The total number of global entries which will live in the
209 primary got and be automatically relocated. This includes
210 those not referenced by the primary GOT but included in
212 unsigned int global_count
;
215 /* Another structure used to pass arguments for got entries traversal. */
217 struct mips_elf_set_global_got_offset_arg
219 struct mips_got_info
*g
;
221 unsigned int needed_relocs
;
222 struct bfd_link_info
*info
;
225 /* A structure used to count TLS relocations or GOT entries, for GOT
226 entry or ELF symbol table traversal. */
228 struct mips_elf_count_tls_arg
230 struct bfd_link_info
*info
;
234 struct _mips_elf_section_data
236 struct bfd_elf_section_data elf
;
243 #define mips_elf_section_data(sec) \
244 ((struct _mips_elf_section_data *) elf_section_data (sec))
246 /* The ABI says that every symbol used by dynamic relocations must have
247 a global GOT entry. Among other things, this provides the dynamic
248 linker with a free, directly-indexed cache. The GOT can therefore
249 contain symbols that are not referenced by GOT relocations themselves
250 (in other words, it may have symbols that are not referenced by things
251 like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
253 GOT relocations are less likely to overflow if we put the associated
254 GOT entries towards the beginning. We therefore divide the global
255 GOT entries into two areas: "normal" and "reloc-only". Entries in
256 the first area can be used for both dynamic relocations and GP-relative
257 accesses, while those in the "reloc-only" area are for dynamic
260 These GGA_* ("Global GOT Area") values are organised so that lower
261 values are more general than higher values. Also, non-GGA_NONE
262 values are ordered by the position of the area in the GOT. */
264 #define GGA_RELOC_ONLY 1
267 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
268 the dynamic symbols. */
270 struct mips_elf_hash_sort_data
272 /* The symbol in the global GOT with the lowest dynamic symbol table
274 struct elf_link_hash_entry
*low
;
275 /* The least dynamic symbol table index corresponding to a non-TLS
276 symbol with a GOT entry. */
277 long min_got_dynindx
;
278 /* The greatest dynamic symbol table index corresponding to a symbol
279 with a GOT entry that is not referenced (e.g., a dynamic symbol
280 with dynamic relocations pointing to it from non-primary GOTs). */
281 long max_unref_got_dynindx
;
282 /* The greatest dynamic symbol table index not corresponding to a
283 symbol without a GOT entry. */
284 long max_non_got_dynindx
;
287 /* The MIPS ELF linker needs additional information for each symbol in
288 the global hash table. */
290 struct mips_elf_link_hash_entry
292 struct elf_link_hash_entry root
;
294 /* External symbol information. */
297 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
299 unsigned int possibly_dynamic_relocs
;
301 /* If there is a stub that 32 bit functions should use to call this
302 16 bit function, this points to the section containing the stub. */
305 /* If there is a stub that 16 bit functions should use to call this
306 32 bit function, this points to the section containing the stub. */
309 /* This is like the call_stub field, but it is used if the function
310 being called returns a floating point value. */
311 asection
*call_fp_stub
;
315 #define GOT_TLS_LDM 2
317 #define GOT_TLS_OFFSET_DONE 0x40
318 #define GOT_TLS_DONE 0x80
319 unsigned char tls_type
;
321 /* This is only used in single-GOT mode; in multi-GOT mode there
322 is one mips_got_entry per GOT entry, so the offset is stored
323 there. In single-GOT mode there may be many mips_got_entry
324 structures all referring to the same GOT slot. It might be
325 possible to use root.got.offset instead, but that field is
326 overloaded already. */
327 bfd_vma tls_got_offset
;
329 /* The highest GGA_* value that satisfies all references to this symbol. */
330 unsigned int global_got_area
: 2;
332 /* True if one of the relocations described by possibly_dynamic_relocs
333 is against a readonly section. */
334 unsigned int readonly_reloc
: 1;
336 /* True if we must not create a .MIPS.stubs entry for this symbol.
337 This is set, for example, if there are relocations related to
338 taking the function's address, i.e. any but R_MIPS_CALL*16 ones.
339 See "MIPS ABI Supplement, 3rd Edition", p. 4-20. */
340 unsigned int no_fn_stub
: 1;
342 /* Whether we need the fn_stub; this is true if this symbol appears
343 in any relocs other than a 16 bit call. */
344 unsigned int need_fn_stub
: 1;
346 /* Are we referenced by some kind of relocation? */
347 unsigned int is_relocation_target
: 1;
349 /* Are we referenced by branch relocations? */
350 unsigned int is_branch_target
: 1;
352 /* Does this symbol need a traditional MIPS lazy-binding stub
353 (as opposed to a PLT entry)? */
354 unsigned int needs_lazy_stub
: 1;
357 /* MIPS ELF linker hash table. */
359 struct mips_elf_link_hash_table
361 struct elf_link_hash_table root
;
363 /* We no longer use this. */
364 /* String section indices for the dynamic section symbols. */
365 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
367 /* The number of .rtproc entries. */
368 bfd_size_type procedure_count
;
369 /* The size of the .compact_rel section (if SGI_COMPAT). */
370 bfd_size_type compact_rel_size
;
371 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
372 entry is set to the address of __rld_obj_head as in IRIX5. */
373 bfd_boolean use_rld_obj_head
;
374 /* This is the value of the __rld_map or __rld_obj_head symbol. */
376 /* This is set if we see any mips16 stub sections. */
377 bfd_boolean mips16_stubs_seen
;
378 /* True if we're generating code for VxWorks. */
379 bfd_boolean is_vxworks
;
380 /* True if we already reported the small-data section overflow. */
381 bfd_boolean small_data_overflow_reported
;
382 /* Shortcuts to some dynamic sections, or NULL if they are not
392 /* The master GOT information. */
393 struct mips_got_info
*got_info
;
394 /* The size of the PLT header in bytes (VxWorks only). */
395 bfd_vma plt_header_size
;
396 /* The size of a PLT entry in bytes (VxWorks only). */
397 bfd_vma plt_entry_size
;
398 /* The number of functions that need a lazy-binding stub. */
399 bfd_vma lazy_stub_count
;
400 /* The size of a function stub entry in bytes. */
401 bfd_vma function_stub_size
;
404 #define TLS_RELOC_P(r_type) \
405 (r_type == R_MIPS_TLS_DTPMOD32 \
406 || r_type == R_MIPS_TLS_DTPMOD64 \
407 || r_type == R_MIPS_TLS_DTPREL32 \
408 || r_type == R_MIPS_TLS_DTPREL64 \
409 || r_type == R_MIPS_TLS_GD \
410 || r_type == R_MIPS_TLS_LDM \
411 || r_type == R_MIPS_TLS_DTPREL_HI16 \
412 || r_type == R_MIPS_TLS_DTPREL_LO16 \
413 || r_type == R_MIPS_TLS_GOTTPREL \
414 || r_type == R_MIPS_TLS_TPREL32 \
415 || r_type == R_MIPS_TLS_TPREL64 \
416 || r_type == R_MIPS_TLS_TPREL_HI16 \
417 || r_type == R_MIPS_TLS_TPREL_LO16)
419 /* Structure used to pass information to mips_elf_output_extsym. */
424 struct bfd_link_info
*info
;
425 struct ecoff_debug_info
*debug
;
426 const struct ecoff_debug_swap
*swap
;
430 /* The names of the runtime procedure table symbols used on IRIX5. */
432 static const char * const mips_elf_dynsym_rtproc_names
[] =
435 "_procedure_string_table",
436 "_procedure_table_size",
440 /* These structures are used to generate the .compact_rel section on
445 unsigned long id1
; /* Always one? */
446 unsigned long num
; /* Number of compact relocation entries. */
447 unsigned long id2
; /* Always two? */
448 unsigned long offset
; /* The file offset of the first relocation. */
449 unsigned long reserved0
; /* Zero? */
450 unsigned long reserved1
; /* Zero? */
459 bfd_byte reserved0
[4];
460 bfd_byte reserved1
[4];
461 } Elf32_External_compact_rel
;
465 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
466 unsigned int rtype
: 4; /* Relocation types. See below. */
467 unsigned int dist2to
: 8;
468 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
469 unsigned long konst
; /* KONST field. See below. */
470 unsigned long vaddr
; /* VADDR to be relocated. */
475 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
476 unsigned int rtype
: 4; /* Relocation types. See below. */
477 unsigned int dist2to
: 8;
478 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
479 unsigned long konst
; /* KONST field. See below. */
487 } Elf32_External_crinfo
;
493 } Elf32_External_crinfo2
;
495 /* These are the constants used to swap the bitfields in a crinfo. */
497 #define CRINFO_CTYPE (0x1)
498 #define CRINFO_CTYPE_SH (31)
499 #define CRINFO_RTYPE (0xf)
500 #define CRINFO_RTYPE_SH (27)
501 #define CRINFO_DIST2TO (0xff)
502 #define CRINFO_DIST2TO_SH (19)
503 #define CRINFO_RELVADDR (0x7ffff)
504 #define CRINFO_RELVADDR_SH (0)
506 /* A compact relocation info has long (3 words) or short (2 words)
507 formats. A short format doesn't have VADDR field and relvaddr
508 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
509 #define CRF_MIPS_LONG 1
510 #define CRF_MIPS_SHORT 0
512 /* There are 4 types of compact relocation at least. The value KONST
513 has different meaning for each type:
516 CT_MIPS_REL32 Address in data
517 CT_MIPS_WORD Address in word (XXX)
518 CT_MIPS_GPHI_LO GP - vaddr
519 CT_MIPS_JMPAD Address to jump
522 #define CRT_MIPS_REL32 0xa
523 #define CRT_MIPS_WORD 0xb
524 #define CRT_MIPS_GPHI_LO 0xc
525 #define CRT_MIPS_JMPAD 0xd
527 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
528 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
529 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
530 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
532 /* The structure of the runtime procedure descriptor created by the
533 loader for use by the static exception system. */
535 typedef struct runtime_pdr
{
536 bfd_vma adr
; /* Memory address of start of procedure. */
537 long regmask
; /* Save register mask. */
538 long regoffset
; /* Save register offset. */
539 long fregmask
; /* Save floating point register mask. */
540 long fregoffset
; /* Save floating point register offset. */
541 long frameoffset
; /* Frame size. */
542 short framereg
; /* Frame pointer register. */
543 short pcreg
; /* Offset or reg of return pc. */
544 long irpss
; /* Index into the runtime string table. */
546 struct exception_info
*exception_info
;/* Pointer to exception array. */
548 #define cbRPDR sizeof (RPDR)
549 #define rpdNil ((pRPDR) 0)
551 static struct mips_got_entry
*mips_elf_create_local_got_entry
552 (bfd
*, struct bfd_link_info
*, bfd
*, bfd_vma
, unsigned long,
553 struct mips_elf_link_hash_entry
*, int);
554 static bfd_boolean mips_elf_sort_hash_table_f
555 (struct mips_elf_link_hash_entry
*, void *);
556 static bfd_vma mips_elf_high
558 static bfd_boolean mips_elf_create_dynamic_relocation
559 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
560 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
561 bfd_vma
*, asection
*);
562 static hashval_t mips_elf_got_entry_hash
564 static bfd_vma mips_elf_adjust_gp
565 (bfd
*, struct mips_got_info
*, bfd
*);
566 static struct mips_got_info
*mips_elf_got_for_ibfd
567 (struct mips_got_info
*, bfd
*);
569 /* This will be used when we sort the dynamic relocation records. */
570 static bfd
*reldyn_sorting_bfd
;
572 /* Nonzero if ABFD is using the N32 ABI. */
573 #define ABI_N32_P(abfd) \
574 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
576 /* Nonzero if ABFD is using the N64 ABI. */
577 #define ABI_64_P(abfd) \
578 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
580 /* Nonzero if ABFD is using NewABI conventions. */
581 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
583 /* The IRIX compatibility level we are striving for. */
584 #define IRIX_COMPAT(abfd) \
585 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
587 /* Whether we are trying to be compatible with IRIX at all. */
588 #define SGI_COMPAT(abfd) \
589 (IRIX_COMPAT (abfd) != ict_none)
591 /* The name of the options section. */
592 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
593 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
595 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
596 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
597 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
598 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
600 /* Whether the section is readonly. */
601 #define MIPS_ELF_READONLY_SECTION(sec) \
602 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
603 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
605 /* The name of the stub section. */
606 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
608 /* The size of an external REL relocation. */
609 #define MIPS_ELF_REL_SIZE(abfd) \
610 (get_elf_backend_data (abfd)->s->sizeof_rel)
612 /* The size of an external RELA relocation. */
613 #define MIPS_ELF_RELA_SIZE(abfd) \
614 (get_elf_backend_data (abfd)->s->sizeof_rela)
616 /* The size of an external dynamic table entry. */
617 #define MIPS_ELF_DYN_SIZE(abfd) \
618 (get_elf_backend_data (abfd)->s->sizeof_dyn)
620 /* The size of a GOT entry. */
621 #define MIPS_ELF_GOT_SIZE(abfd) \
622 (get_elf_backend_data (abfd)->s->arch_size / 8)
624 /* The size of a symbol-table entry. */
625 #define MIPS_ELF_SYM_SIZE(abfd) \
626 (get_elf_backend_data (abfd)->s->sizeof_sym)
628 /* The default alignment for sections, as a power of two. */
629 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
630 (get_elf_backend_data (abfd)->s->log_file_align)
632 /* Get word-sized data. */
633 #define MIPS_ELF_GET_WORD(abfd, ptr) \
634 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
636 /* Put out word-sized data. */
637 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
639 ? bfd_put_64 (abfd, val, ptr) \
640 : bfd_put_32 (abfd, val, ptr))
642 /* Add a dynamic symbol table-entry. */
643 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
644 _bfd_elf_add_dynamic_entry (info, tag, val)
646 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
647 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
649 /* Determine whether the internal relocation of index REL_IDX is REL
650 (zero) or RELA (non-zero). The assumption is that, if there are
651 two relocation sections for this section, one of them is REL and
652 the other is RELA. If the index of the relocation we're testing is
653 in range for the first relocation section, check that the external
654 relocation size is that for RELA. It is also assumed that, if
655 rel_idx is not in range for the first section, and this first
656 section contains REL relocs, then the relocation is in the second
657 section, that is RELA. */
658 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
659 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
660 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
661 > (bfd_vma)(rel_idx)) \
662 == (elf_section_data (sec)->rel_hdr.sh_entsize \
663 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
664 : sizeof (Elf32_External_Rela))))
666 /* The name of the dynamic relocation section. */
667 #define MIPS_ELF_REL_DYN_NAME(INFO) \
668 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
670 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
671 from smaller values. Start with zero, widen, *then* decrement. */
672 #define MINUS_ONE (((bfd_vma)0) - 1)
673 #define MINUS_TWO (((bfd_vma)0) - 2)
675 /* The number of local .got entries we reserve. */
676 #define MIPS_RESERVED_GOTNO(INFO) \
677 (mips_elf_hash_table (INFO)->is_vxworks ? 3 : 2)
679 /* The value to write into got[1] for SVR4 targets, to identify it is
680 a GNU object. The dynamic linker can then use got[1] to store the
682 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
683 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
685 /* The offset of $gp from the beginning of the .got section. */
686 #define ELF_MIPS_GP_OFFSET(INFO) \
687 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
689 /* The maximum size of the GOT for it to be addressable using 16-bit
691 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
693 /* Instructions which appear in a stub. */
694 #define STUB_LW(abfd) \
696 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
697 : 0x8f998010)) /* lw t9,0x8010(gp) */
698 #define STUB_MOVE(abfd) \
700 ? 0x03e0782d /* daddu t7,ra */ \
701 : 0x03e07821)) /* addu t7,ra */
702 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
703 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
704 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
705 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
706 #define STUB_LI16S(abfd, VAL) \
708 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
709 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
711 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
712 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
714 /* The name of the dynamic interpreter. This is put in the .interp
717 #define ELF_DYNAMIC_INTERPRETER(abfd) \
718 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
719 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
720 : "/usr/lib/libc.so.1")
723 #define MNAME(bfd,pre,pos) \
724 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
725 #define ELF_R_SYM(bfd, i) \
726 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
727 #define ELF_R_TYPE(bfd, i) \
728 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
729 #define ELF_R_INFO(bfd, s, t) \
730 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
732 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
733 #define ELF_R_SYM(bfd, i) \
735 #define ELF_R_TYPE(bfd, i) \
737 #define ELF_R_INFO(bfd, s, t) \
738 (ELF32_R_INFO (s, t))
741 /* The mips16 compiler uses a couple of special sections to handle
742 floating point arguments.
744 Section names that look like .mips16.fn.FNNAME contain stubs that
745 copy floating point arguments from the fp regs to the gp regs and
746 then jump to FNNAME. If any 32 bit function calls FNNAME, the
747 call should be redirected to the stub instead. If no 32 bit
748 function calls FNNAME, the stub should be discarded. We need to
749 consider any reference to the function, not just a call, because
750 if the address of the function is taken we will need the stub,
751 since the address might be passed to a 32 bit function.
753 Section names that look like .mips16.call.FNNAME contain stubs
754 that copy floating point arguments from the gp regs to the fp
755 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
756 then any 16 bit function that calls FNNAME should be redirected
757 to the stub instead. If FNNAME is not a 32 bit function, the
758 stub should be discarded.
760 .mips16.call.fp.FNNAME sections are similar, but contain stubs
761 which call FNNAME and then copy the return value from the fp regs
762 to the gp regs. These stubs store the return value in $18 while
763 calling FNNAME; any function which might call one of these stubs
764 must arrange to save $18 around the call. (This case is not
765 needed for 32 bit functions that call 16 bit functions, because
766 16 bit functions always return floating point values in both
769 Note that in all cases FNNAME might be defined statically.
770 Therefore, FNNAME is not used literally. Instead, the relocation
771 information will indicate which symbol the section is for.
773 We record any stubs that we find in the symbol table. */
775 #define FN_STUB ".mips16.fn."
776 #define CALL_STUB ".mips16.call."
777 #define CALL_FP_STUB ".mips16.call.fp."
779 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
780 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
781 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
783 /* The format of the first PLT entry in a VxWorks executable. */
784 static const bfd_vma mips_vxworks_exec_plt0_entry
[] = {
785 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
786 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
787 0x8f390008, /* lw t9, 8(t9) */
788 0x00000000, /* nop */
789 0x03200008, /* jr t9 */
793 /* The format of subsequent PLT entries. */
794 static const bfd_vma mips_vxworks_exec_plt_entry
[] = {
795 0x10000000, /* b .PLT_resolver */
796 0x24180000, /* li t8, <pltindex> */
797 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
798 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
799 0x8f390000, /* lw t9, 0(t9) */
800 0x00000000, /* nop */
801 0x03200008, /* jr t9 */
805 /* The format of the first PLT entry in a VxWorks shared object. */
806 static const bfd_vma mips_vxworks_shared_plt0_entry
[] = {
807 0x8f990008, /* lw t9, 8(gp) */
808 0x00000000, /* nop */
809 0x03200008, /* jr t9 */
810 0x00000000, /* nop */
811 0x00000000, /* nop */
815 /* The format of subsequent PLT entries. */
816 static const bfd_vma mips_vxworks_shared_plt_entry
[] = {
817 0x10000000, /* b .PLT_resolver */
818 0x24180000 /* li t8, <pltindex> */
821 /* Look up an entry in a MIPS ELF linker hash table. */
823 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
824 ((struct mips_elf_link_hash_entry *) \
825 elf_link_hash_lookup (&(table)->root, (string), (create), \
828 /* Traverse a MIPS ELF linker hash table. */
830 #define mips_elf_link_hash_traverse(table, func, info) \
831 (elf_link_hash_traverse \
833 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
836 /* Get the MIPS ELF linker hash table from a link_info structure. */
838 #define mips_elf_hash_table(p) \
839 ((struct mips_elf_link_hash_table *) ((p)->hash))
841 /* Find the base offsets for thread-local storage in this object,
842 for GD/LD and IE/LE respectively. */
844 #define TP_OFFSET 0x7000
845 #define DTP_OFFSET 0x8000
848 dtprel_base (struct bfd_link_info
*info
)
850 /* If tls_sec is NULL, we should have signalled an error already. */
851 if (elf_hash_table (info
)->tls_sec
== NULL
)
853 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
857 tprel_base (struct bfd_link_info
*info
)
859 /* If tls_sec is NULL, we should have signalled an error already. */
860 if (elf_hash_table (info
)->tls_sec
== NULL
)
862 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
865 /* Create an entry in a MIPS ELF linker hash table. */
867 static struct bfd_hash_entry
*
868 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
869 struct bfd_hash_table
*table
, const char *string
)
871 struct mips_elf_link_hash_entry
*ret
=
872 (struct mips_elf_link_hash_entry
*) entry
;
874 /* Allocate the structure if it has not already been allocated by a
877 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
879 return (struct bfd_hash_entry
*) ret
;
881 /* Call the allocation method of the superclass. */
882 ret
= ((struct mips_elf_link_hash_entry
*)
883 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
887 /* Set local fields. */
888 memset (&ret
->esym
, 0, sizeof (EXTR
));
889 /* We use -2 as a marker to indicate that the information has
890 not been set. -1 means there is no associated ifd. */
892 ret
->possibly_dynamic_relocs
= 0;
894 ret
->call_stub
= NULL
;
895 ret
->call_fp_stub
= NULL
;
896 ret
->tls_type
= GOT_NORMAL
;
897 ret
->global_got_area
= GGA_NONE
;
898 ret
->readonly_reloc
= FALSE
;
899 ret
->no_fn_stub
= FALSE
;
900 ret
->need_fn_stub
= FALSE
;
901 ret
->is_relocation_target
= FALSE
;
902 ret
->is_branch_target
= FALSE
;
903 ret
->needs_lazy_stub
= FALSE
;
906 return (struct bfd_hash_entry
*) ret
;
910 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
912 if (!sec
->used_by_bfd
)
914 struct _mips_elf_section_data
*sdata
;
915 bfd_size_type amt
= sizeof (*sdata
);
917 sdata
= bfd_zalloc (abfd
, amt
);
920 sec
->used_by_bfd
= sdata
;
923 return _bfd_elf_new_section_hook (abfd
, sec
);
926 /* Read ECOFF debugging information from a .mdebug section into a
927 ecoff_debug_info structure. */
930 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
931 struct ecoff_debug_info
*debug
)
934 const struct ecoff_debug_swap
*swap
;
937 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
938 memset (debug
, 0, sizeof (*debug
));
940 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
941 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
944 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
945 swap
->external_hdr_size
))
948 symhdr
= &debug
->symbolic_header
;
949 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
951 /* The symbolic header contains absolute file offsets and sizes to
953 #define READ(ptr, offset, count, size, type) \
954 if (symhdr->count == 0) \
958 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
959 debug->ptr = bfd_malloc (amt); \
960 if (debug->ptr == NULL) \
962 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
963 || bfd_bread (debug->ptr, amt, abfd) != amt) \
967 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
968 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
969 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
970 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
971 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
972 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
974 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
975 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
976 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
977 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
978 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
988 if (debug
->line
!= NULL
)
990 if (debug
->external_dnr
!= NULL
)
991 free (debug
->external_dnr
);
992 if (debug
->external_pdr
!= NULL
)
993 free (debug
->external_pdr
);
994 if (debug
->external_sym
!= NULL
)
995 free (debug
->external_sym
);
996 if (debug
->external_opt
!= NULL
)
997 free (debug
->external_opt
);
998 if (debug
->external_aux
!= NULL
)
999 free (debug
->external_aux
);
1000 if (debug
->ss
!= NULL
)
1002 if (debug
->ssext
!= NULL
)
1003 free (debug
->ssext
);
1004 if (debug
->external_fdr
!= NULL
)
1005 free (debug
->external_fdr
);
1006 if (debug
->external_rfd
!= NULL
)
1007 free (debug
->external_rfd
);
1008 if (debug
->external_ext
!= NULL
)
1009 free (debug
->external_ext
);
1013 /* Swap RPDR (runtime procedure table entry) for output. */
1016 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
1018 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
1019 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
1020 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
1021 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
1022 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
1023 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
1025 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
1026 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1028 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1031 /* Create a runtime procedure table from the .mdebug section. */
1034 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1035 struct bfd_link_info
*info
, asection
*s
,
1036 struct ecoff_debug_info
*debug
)
1038 const struct ecoff_debug_swap
*swap
;
1039 HDRR
*hdr
= &debug
->symbolic_header
;
1041 struct rpdr_ext
*erp
;
1043 struct pdr_ext
*epdr
;
1044 struct sym_ext
*esym
;
1048 bfd_size_type count
;
1049 unsigned long sindex
;
1053 const char *no_name_func
= _("static procedure (no name)");
1061 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1063 sindex
= strlen (no_name_func
) + 1;
1064 count
= hdr
->ipdMax
;
1067 size
= swap
->external_pdr_size
;
1069 epdr
= bfd_malloc (size
* count
);
1073 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1076 size
= sizeof (RPDR
);
1077 rp
= rpdr
= bfd_malloc (size
* count
);
1081 size
= sizeof (char *);
1082 sv
= bfd_malloc (size
* count
);
1086 count
= hdr
->isymMax
;
1087 size
= swap
->external_sym_size
;
1088 esym
= bfd_malloc (size
* count
);
1092 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1095 count
= hdr
->issMax
;
1096 ss
= bfd_malloc (count
);
1099 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1102 count
= hdr
->ipdMax
;
1103 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1105 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1106 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1107 rp
->adr
= sym
.value
;
1108 rp
->regmask
= pdr
.regmask
;
1109 rp
->regoffset
= pdr
.regoffset
;
1110 rp
->fregmask
= pdr
.fregmask
;
1111 rp
->fregoffset
= pdr
.fregoffset
;
1112 rp
->frameoffset
= pdr
.frameoffset
;
1113 rp
->framereg
= pdr
.framereg
;
1114 rp
->pcreg
= pdr
.pcreg
;
1116 sv
[i
] = ss
+ sym
.iss
;
1117 sindex
+= strlen (sv
[i
]) + 1;
1121 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1122 size
= BFD_ALIGN (size
, 16);
1123 rtproc
= bfd_alloc (abfd
, size
);
1126 mips_elf_hash_table (info
)->procedure_count
= 0;
1130 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1133 memset (erp
, 0, sizeof (struct rpdr_ext
));
1135 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1136 strcpy (str
, no_name_func
);
1137 str
+= strlen (no_name_func
) + 1;
1138 for (i
= 0; i
< count
; i
++)
1140 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1141 strcpy (str
, sv
[i
]);
1142 str
+= strlen (sv
[i
]) + 1;
1144 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1146 /* Set the size and contents of .rtproc section. */
1148 s
->contents
= rtproc
;
1150 /* Skip this section later on (I don't think this currently
1151 matters, but someday it might). */
1152 s
->map_head
.link_order
= NULL
;
1181 /* We're about to redefine H. Create a symbol to represent H's
1182 current value and size, to help make the disassembly easier
1186 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1187 struct mips_elf_link_hash_entry
*h
,
1190 struct bfd_link_hash_entry
*bh
;
1191 struct elf_link_hash_entry
*elfh
;
1196 /* Read the symbol's value. */
1197 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1198 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1199 s
= h
->root
.root
.u
.def
.section
;
1200 value
= h
->root
.root
.u
.def
.value
;
1202 /* Create a new symbol. */
1203 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1205 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1206 BSF_LOCAL
, s
, value
, NULL
,
1210 /* Make it local and copy the other attributes from H. */
1211 elfh
= (struct elf_link_hash_entry
*) bh
;
1212 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1213 elfh
->other
= h
->root
.other
;
1214 elfh
->size
= h
->root
.size
;
1215 elfh
->forced_local
= 1;
1219 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1220 function rather than to a hard-float stub. */
1223 section_allows_mips16_refs_p (asection
*section
)
1227 name
= bfd_get_section_name (section
->owner
, section
);
1228 return (FN_STUB_P (name
)
1229 || CALL_STUB_P (name
)
1230 || CALL_FP_STUB_P (name
)
1231 || strcmp (name
, ".pdr") == 0);
1234 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1235 stub section of some kind. Return the R_SYMNDX of the target
1236 function, or 0 if we can't decide which function that is. */
1238 static unsigned long
1239 mips16_stub_symndx (asection
*sec
, const Elf_Internal_Rela
*relocs
,
1240 const Elf_Internal_Rela
*relend
)
1242 const Elf_Internal_Rela
*rel
;
1244 /* Trust the first R_MIPS_NONE relocation, if any. */
1245 for (rel
= relocs
; rel
< relend
; rel
++)
1246 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1247 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1249 /* Otherwise trust the first relocation, whatever its kind. This is
1250 the traditional behavior. */
1251 if (relocs
< relend
)
1252 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1257 /* Check the mips16 stubs for a particular symbol, and see if we can
1261 mips_elf_check_mips16_stubs (struct mips_elf_link_hash_entry
*h
, void *data
)
1263 struct bfd_link_info
*info
;
1265 info
= (struct bfd_link_info
*) data
;
1266 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1267 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1269 /* Dynamic symbols must use the standard call interface, in case other
1270 objects try to call them. */
1271 if (h
->fn_stub
!= NULL
1272 && h
->root
.dynindx
!= -1)
1274 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1275 h
->need_fn_stub
= TRUE
;
1278 if (h
->fn_stub
!= NULL
1279 && ! h
->need_fn_stub
)
1281 /* We don't need the fn_stub; the only references to this symbol
1282 are 16 bit calls. Clobber the size to 0 to prevent it from
1283 being included in the link. */
1284 h
->fn_stub
->size
= 0;
1285 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1286 h
->fn_stub
->reloc_count
= 0;
1287 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1290 if (h
->call_stub
!= NULL
1291 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1293 /* We don't need the call_stub; this is a 16 bit function, so
1294 calls from other 16 bit functions are OK. Clobber the size
1295 to 0 to prevent it from being included in the link. */
1296 h
->call_stub
->size
= 0;
1297 h
->call_stub
->flags
&= ~SEC_RELOC
;
1298 h
->call_stub
->reloc_count
= 0;
1299 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1302 if (h
->call_fp_stub
!= NULL
1303 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1305 /* We don't need the call_stub; this is a 16 bit function, so
1306 calls from other 16 bit functions are OK. Clobber the size
1307 to 0 to prevent it from being included in the link. */
1308 h
->call_fp_stub
->size
= 0;
1309 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1310 h
->call_fp_stub
->reloc_count
= 0;
1311 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1317 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1318 Most mips16 instructions are 16 bits, but these instructions
1321 The format of these instructions is:
1323 +--------------+--------------------------------+
1324 | JALX | X| Imm 20:16 | Imm 25:21 |
1325 +--------------+--------------------------------+
1327 +-----------------------------------------------+
1329 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1330 Note that the immediate value in the first word is swapped.
1332 When producing a relocatable object file, R_MIPS16_26 is
1333 handled mostly like R_MIPS_26. In particular, the addend is
1334 stored as a straight 26-bit value in a 32-bit instruction.
1335 (gas makes life simpler for itself by never adjusting a
1336 R_MIPS16_26 reloc to be against a section, so the addend is
1337 always zero). However, the 32 bit instruction is stored as 2
1338 16-bit values, rather than a single 32-bit value. In a
1339 big-endian file, the result is the same; in a little-endian
1340 file, the two 16-bit halves of the 32 bit value are swapped.
1341 This is so that a disassembler can recognize the jal
1344 When doing a final link, R_MIPS16_26 is treated as a 32 bit
1345 instruction stored as two 16-bit values. The addend A is the
1346 contents of the targ26 field. The calculation is the same as
1347 R_MIPS_26. When storing the calculated value, reorder the
1348 immediate value as shown above, and don't forget to store the
1349 value as two 16-bit values.
1351 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
1355 +--------+----------------------+
1359 +--------+----------------------+
1362 +----------+------+-------------+
1366 +----------+--------------------+
1367 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
1368 ((sub1 << 16) | sub2)).
1370 When producing a relocatable object file, the calculation is
1371 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1372 When producing a fully linked file, the calculation is
1373 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1374 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
1376 The table below lists the other MIPS16 instruction relocations.
1377 Each one is calculated in the same way as the non-MIPS16 relocation
1378 given on the right, but using the extended MIPS16 layout of 16-bit
1381 R_MIPS16_GPREL R_MIPS_GPREL16
1382 R_MIPS16_GOT16 R_MIPS_GOT16
1383 R_MIPS16_CALL16 R_MIPS_CALL16
1384 R_MIPS16_HI16 R_MIPS_HI16
1385 R_MIPS16_LO16 R_MIPS_LO16
1387 A typical instruction will have a format like this:
1389 +--------------+--------------------------------+
1390 | EXTEND | Imm 10:5 | Imm 15:11 |
1391 +--------------+--------------------------------+
1392 | Major | rx | ry | Imm 4:0 |
1393 +--------------+--------------------------------+
1395 EXTEND is the five bit value 11110. Major is the instruction
1398 All we need to do here is shuffle the bits appropriately.
1399 As above, the two 16-bit halves must be swapped on a
1400 little-endian system. */
1402 static inline bfd_boolean
1403 mips16_reloc_p (int r_type
)
1408 case R_MIPS16_GPREL
:
1409 case R_MIPS16_GOT16
:
1410 case R_MIPS16_CALL16
:
1420 static inline bfd_boolean
1421 got16_reloc_p (int r_type
)
1423 return r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS16_GOT16
;
1426 static inline bfd_boolean
1427 call16_reloc_p (int r_type
)
1429 return r_type
== R_MIPS_CALL16
|| r_type
== R_MIPS16_CALL16
;
1432 static inline bfd_boolean
1433 hi16_reloc_p (int r_type
)
1435 return r_type
== R_MIPS_HI16
|| r_type
== R_MIPS16_HI16
;
1438 static inline bfd_boolean
1439 lo16_reloc_p (int r_type
)
1441 return r_type
== R_MIPS_LO16
|| r_type
== R_MIPS16_LO16
;
1444 static inline bfd_boolean
1445 mips16_call_reloc_p (int r_type
)
1447 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
1451 _bfd_mips16_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
1452 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1454 bfd_vma extend
, insn
, val
;
1456 if (!mips16_reloc_p (r_type
))
1459 /* Pick up the mips16 extend instruction and the real instruction. */
1460 extend
= bfd_get_16 (abfd
, data
);
1461 insn
= bfd_get_16 (abfd
, data
+ 2);
1462 if (r_type
== R_MIPS16_26
)
1465 val
= ((extend
& 0xfc00) << 16) | ((extend
& 0x3e0) << 11)
1466 | ((extend
& 0x1f) << 21) | insn
;
1468 val
= extend
<< 16 | insn
;
1471 val
= ((extend
& 0xf800) << 16) | ((insn
& 0xffe0) << 11)
1472 | ((extend
& 0x1f) << 11) | (extend
& 0x7e0) | (insn
& 0x1f);
1473 bfd_put_32 (abfd
, val
, data
);
1477 _bfd_mips16_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
1478 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1480 bfd_vma extend
, insn
, val
;
1482 if (!mips16_reloc_p (r_type
))
1485 val
= bfd_get_32 (abfd
, data
);
1486 if (r_type
== R_MIPS16_26
)
1490 insn
= val
& 0xffff;
1491 extend
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
1492 | ((val
>> 21) & 0x1f);
1496 insn
= val
& 0xffff;
1502 insn
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
1503 extend
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
1505 bfd_put_16 (abfd
, insn
, data
+ 2);
1506 bfd_put_16 (abfd
, extend
, data
);
1509 bfd_reloc_status_type
1510 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1511 arelent
*reloc_entry
, asection
*input_section
,
1512 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1516 bfd_reloc_status_type status
;
1518 if (bfd_is_com_section (symbol
->section
))
1521 relocation
= symbol
->value
;
1523 relocation
+= symbol
->section
->output_section
->vma
;
1524 relocation
+= symbol
->section
->output_offset
;
1526 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1527 return bfd_reloc_outofrange
;
1529 /* Set val to the offset into the section or symbol. */
1530 val
= reloc_entry
->addend
;
1532 _bfd_mips_elf_sign_extend (val
, 16);
1534 /* Adjust val for the final section location and GP value. If we
1535 are producing relocatable output, we don't want to do this for
1536 an external symbol. */
1538 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1539 val
+= relocation
- gp
;
1541 if (reloc_entry
->howto
->partial_inplace
)
1543 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1545 + reloc_entry
->address
);
1546 if (status
!= bfd_reloc_ok
)
1550 reloc_entry
->addend
= val
;
1553 reloc_entry
->address
+= input_section
->output_offset
;
1555 return bfd_reloc_ok
;
1558 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
1559 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
1560 that contains the relocation field and DATA points to the start of
1565 struct mips_hi16
*next
;
1567 asection
*input_section
;
1571 /* FIXME: This should not be a static variable. */
1573 static struct mips_hi16
*mips_hi16_list
;
1575 /* A howto special_function for REL *HI16 relocations. We can only
1576 calculate the correct value once we've seen the partnering
1577 *LO16 relocation, so just save the information for later.
1579 The ABI requires that the *LO16 immediately follow the *HI16.
1580 However, as a GNU extension, we permit an arbitrary number of
1581 *HI16s to be associated with a single *LO16. This significantly
1582 simplies the relocation handling in gcc. */
1584 bfd_reloc_status_type
1585 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1586 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
1587 asection
*input_section
, bfd
*output_bfd
,
1588 char **error_message ATTRIBUTE_UNUSED
)
1590 struct mips_hi16
*n
;
1592 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1593 return bfd_reloc_outofrange
;
1595 n
= bfd_malloc (sizeof *n
);
1597 return bfd_reloc_outofrange
;
1599 n
->next
= mips_hi16_list
;
1601 n
->input_section
= input_section
;
1602 n
->rel
= *reloc_entry
;
1605 if (output_bfd
!= NULL
)
1606 reloc_entry
->address
+= input_section
->output_offset
;
1608 return bfd_reloc_ok
;
1611 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
1612 like any other 16-bit relocation when applied to global symbols, but is
1613 treated in the same as R_MIPS_HI16 when applied to local symbols. */
1615 bfd_reloc_status_type
1616 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1617 void *data
, asection
*input_section
,
1618 bfd
*output_bfd
, char **error_message
)
1620 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
1621 || bfd_is_und_section (bfd_get_section (symbol
))
1622 || bfd_is_com_section (bfd_get_section (symbol
)))
1623 /* The relocation is against a global symbol. */
1624 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1625 input_section
, output_bfd
,
1628 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1629 input_section
, output_bfd
, error_message
);
1632 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
1633 is a straightforward 16 bit inplace relocation, but we must deal with
1634 any partnering high-part relocations as well. */
1636 bfd_reloc_status_type
1637 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1638 void *data
, asection
*input_section
,
1639 bfd
*output_bfd
, char **error_message
)
1642 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1644 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1645 return bfd_reloc_outofrange
;
1647 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1649 vallo
= bfd_get_32 (abfd
, location
);
1650 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1653 while (mips_hi16_list
!= NULL
)
1655 bfd_reloc_status_type ret
;
1656 struct mips_hi16
*hi
;
1658 hi
= mips_hi16_list
;
1660 /* R_MIPS*_GOT16 relocations are something of a special case. We
1661 want to install the addend in the same way as for a R_MIPS*_HI16
1662 relocation (with a rightshift of 16). However, since GOT16
1663 relocations can also be used with global symbols, their howto
1664 has a rightshift of 0. */
1665 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
1666 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
1667 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
1668 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
1670 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
1671 carry or borrow will induce a change of +1 or -1 in the high part. */
1672 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
1674 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
1675 hi
->input_section
, output_bfd
,
1677 if (ret
!= bfd_reloc_ok
)
1680 mips_hi16_list
= hi
->next
;
1684 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1685 input_section
, output_bfd
,
1689 /* A generic howto special_function. This calculates and installs the
1690 relocation itself, thus avoiding the oft-discussed problems in
1691 bfd_perform_relocation and bfd_install_relocation. */
1693 bfd_reloc_status_type
1694 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1695 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
1696 asection
*input_section
, bfd
*output_bfd
,
1697 char **error_message ATTRIBUTE_UNUSED
)
1700 bfd_reloc_status_type status
;
1701 bfd_boolean relocatable
;
1703 relocatable
= (output_bfd
!= NULL
);
1705 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1706 return bfd_reloc_outofrange
;
1708 /* Build up the field adjustment in VAL. */
1710 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1712 /* Either we're calculating the final field value or we have a
1713 relocation against a section symbol. Add in the section's
1714 offset or address. */
1715 val
+= symbol
->section
->output_section
->vma
;
1716 val
+= symbol
->section
->output_offset
;
1721 /* We're calculating the final field value. Add in the symbol's value
1722 and, if pc-relative, subtract the address of the field itself. */
1723 val
+= symbol
->value
;
1724 if (reloc_entry
->howto
->pc_relative
)
1726 val
-= input_section
->output_section
->vma
;
1727 val
-= input_section
->output_offset
;
1728 val
-= reloc_entry
->address
;
1732 /* VAL is now the final adjustment. If we're keeping this relocation
1733 in the output file, and if the relocation uses a separate addend,
1734 we just need to add VAL to that addend. Otherwise we need to add
1735 VAL to the relocation field itself. */
1736 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
1737 reloc_entry
->addend
+= val
;
1740 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1742 /* Add in the separate addend, if any. */
1743 val
+= reloc_entry
->addend
;
1745 /* Add VAL to the relocation field. */
1746 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1748 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1750 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1753 if (status
!= bfd_reloc_ok
)
1758 reloc_entry
->address
+= input_section
->output_offset
;
1760 return bfd_reloc_ok
;
1763 /* Swap an entry in a .gptab section. Note that these routines rely
1764 on the equivalence of the two elements of the union. */
1767 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
1770 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1771 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1775 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
1776 Elf32_External_gptab
*ex
)
1778 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
1779 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
1783 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
1784 Elf32_External_compact_rel
*ex
)
1786 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1787 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1788 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1789 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1790 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1791 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1795 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
1796 Elf32_External_crinfo
*ex
)
1800 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1801 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1802 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1803 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1804 H_PUT_32 (abfd
, l
, ex
->info
);
1805 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1806 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1809 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1810 routines swap this structure in and out. They are used outside of
1811 BFD, so they are globally visible. */
1814 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
1817 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1818 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1819 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1820 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1821 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1822 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1826 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
1827 Elf32_External_RegInfo
*ex
)
1829 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1830 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1831 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1832 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1833 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1834 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1837 /* In the 64 bit ABI, the .MIPS.options section holds register
1838 information in an Elf64_Reginfo structure. These routines swap
1839 them in and out. They are globally visible because they are used
1840 outside of BFD. These routines are here so that gas can call them
1841 without worrying about whether the 64 bit ABI has been included. */
1844 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
1845 Elf64_Internal_RegInfo
*in
)
1847 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1848 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1849 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1850 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1851 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1852 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1853 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1857 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
1858 Elf64_External_RegInfo
*ex
)
1860 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1861 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1862 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1863 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1864 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1865 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1866 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1869 /* Swap in an options header. */
1872 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
1873 Elf_Internal_Options
*in
)
1875 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1876 in
->size
= H_GET_8 (abfd
, ex
->size
);
1877 in
->section
= H_GET_16 (abfd
, ex
->section
);
1878 in
->info
= H_GET_32 (abfd
, ex
->info
);
1881 /* Swap out an options header. */
1884 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
1885 Elf_External_Options
*ex
)
1887 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1888 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1889 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1890 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1893 /* This function is called via qsort() to sort the dynamic relocation
1894 entries by increasing r_symndx value. */
1897 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
1899 Elf_Internal_Rela int_reloc1
;
1900 Elf_Internal_Rela int_reloc2
;
1903 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1904 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1906 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
1910 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
1912 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
1917 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
1920 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
1921 const void *arg2 ATTRIBUTE_UNUSED
)
1924 Elf_Internal_Rela int_reloc1
[3];
1925 Elf_Internal_Rela int_reloc2
[3];
1927 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1928 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
1929 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1930 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
1932 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
1934 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
1937 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
1939 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
1948 /* This routine is used to write out ECOFF debugging external symbol
1949 information. It is called via mips_elf_link_hash_traverse. The
1950 ECOFF external symbol information must match the ELF external
1951 symbol information. Unfortunately, at this point we don't know
1952 whether a symbol is required by reloc information, so the two
1953 tables may wind up being different. We must sort out the external
1954 symbol information before we can set the final size of the .mdebug
1955 section, and we must set the size of the .mdebug section before we
1956 can relocate any sections, and we can't know which symbols are
1957 required by relocation until we relocate the sections.
1958 Fortunately, it is relatively unlikely that any symbol will be
1959 stripped but required by a reloc. In particular, it can not happen
1960 when generating a final executable. */
1963 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
1965 struct extsym_info
*einfo
= data
;
1967 asection
*sec
, *output_section
;
1969 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1970 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1972 if (h
->root
.indx
== -2)
1974 else if ((h
->root
.def_dynamic
1975 || h
->root
.ref_dynamic
1976 || h
->root
.type
== bfd_link_hash_new
)
1977 && !h
->root
.def_regular
1978 && !h
->root
.ref_regular
)
1980 else if (einfo
->info
->strip
== strip_all
1981 || (einfo
->info
->strip
== strip_some
1982 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1983 h
->root
.root
.root
.string
,
1984 FALSE
, FALSE
) == NULL
))
1992 if (h
->esym
.ifd
== -2)
1995 h
->esym
.cobol_main
= 0;
1996 h
->esym
.weakext
= 0;
1997 h
->esym
.reserved
= 0;
1998 h
->esym
.ifd
= ifdNil
;
1999 h
->esym
.asym
.value
= 0;
2000 h
->esym
.asym
.st
= stGlobal
;
2002 if (h
->root
.root
.type
== bfd_link_hash_undefined
2003 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
2007 /* Use undefined class. Also, set class and type for some
2009 name
= h
->root
.root
.root
.string
;
2010 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2011 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2013 h
->esym
.asym
.sc
= scData
;
2014 h
->esym
.asym
.st
= stLabel
;
2015 h
->esym
.asym
.value
= 0;
2017 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2019 h
->esym
.asym
.sc
= scAbs
;
2020 h
->esym
.asym
.st
= stLabel
;
2021 h
->esym
.asym
.value
=
2022 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2024 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
2026 h
->esym
.asym
.sc
= scAbs
;
2027 h
->esym
.asym
.st
= stLabel
;
2028 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2031 h
->esym
.asym
.sc
= scUndefined
;
2033 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2034 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2035 h
->esym
.asym
.sc
= scAbs
;
2040 sec
= h
->root
.root
.u
.def
.section
;
2041 output_section
= sec
->output_section
;
2043 /* When making a shared library and symbol h is the one from
2044 the another shared library, OUTPUT_SECTION may be null. */
2045 if (output_section
== NULL
)
2046 h
->esym
.asym
.sc
= scUndefined
;
2049 name
= bfd_section_name (output_section
->owner
, output_section
);
2051 if (strcmp (name
, ".text") == 0)
2052 h
->esym
.asym
.sc
= scText
;
2053 else if (strcmp (name
, ".data") == 0)
2054 h
->esym
.asym
.sc
= scData
;
2055 else if (strcmp (name
, ".sdata") == 0)
2056 h
->esym
.asym
.sc
= scSData
;
2057 else if (strcmp (name
, ".rodata") == 0
2058 || strcmp (name
, ".rdata") == 0)
2059 h
->esym
.asym
.sc
= scRData
;
2060 else if (strcmp (name
, ".bss") == 0)
2061 h
->esym
.asym
.sc
= scBss
;
2062 else if (strcmp (name
, ".sbss") == 0)
2063 h
->esym
.asym
.sc
= scSBss
;
2064 else if (strcmp (name
, ".init") == 0)
2065 h
->esym
.asym
.sc
= scInit
;
2066 else if (strcmp (name
, ".fini") == 0)
2067 h
->esym
.asym
.sc
= scFini
;
2069 h
->esym
.asym
.sc
= scAbs
;
2073 h
->esym
.asym
.reserved
= 0;
2074 h
->esym
.asym
.index
= indexNil
;
2077 if (h
->root
.root
.type
== bfd_link_hash_common
)
2078 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2079 else if (h
->root
.root
.type
== bfd_link_hash_defined
2080 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2082 if (h
->esym
.asym
.sc
== scCommon
)
2083 h
->esym
.asym
.sc
= scBss
;
2084 else if (h
->esym
.asym
.sc
== scSCommon
)
2085 h
->esym
.asym
.sc
= scSBss
;
2087 sec
= h
->root
.root
.u
.def
.section
;
2088 output_section
= sec
->output_section
;
2089 if (output_section
!= NULL
)
2090 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2091 + sec
->output_offset
2092 + output_section
->vma
);
2094 h
->esym
.asym
.value
= 0;
2098 struct mips_elf_link_hash_entry
*hd
= h
;
2100 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
2101 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2103 if (hd
->needs_lazy_stub
)
2105 /* Set type and value for a symbol with a function stub. */
2106 h
->esym
.asym
.st
= stProc
;
2107 sec
= hd
->root
.root
.u
.def
.section
;
2109 h
->esym
.asym
.value
= 0;
2112 output_section
= sec
->output_section
;
2113 if (output_section
!= NULL
)
2114 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
2115 + sec
->output_offset
2116 + output_section
->vma
);
2118 h
->esym
.asym
.value
= 0;
2123 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2124 h
->root
.root
.root
.string
,
2127 einfo
->failed
= TRUE
;
2134 /* A comparison routine used to sort .gptab entries. */
2137 gptab_compare (const void *p1
, const void *p2
)
2139 const Elf32_gptab
*a1
= p1
;
2140 const Elf32_gptab
*a2
= p2
;
2142 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
2145 /* Functions to manage the got entry hash table. */
2147 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
2150 static INLINE hashval_t
2151 mips_elf_hash_bfd_vma (bfd_vma addr
)
2154 return addr
+ (addr
>> 32);
2160 /* got_entries only match if they're identical, except for gotidx, so
2161 use all fields to compute the hash, and compare the appropriate
2165 mips_elf_got_entry_hash (const void *entry_
)
2167 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2169 return entry
->symndx
2170 + ((entry
->tls_type
& GOT_TLS_LDM
) << 17)
2171 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
2173 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
2174 : entry
->d
.h
->root
.root
.root
.hash
));
2178 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
2180 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2181 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2183 /* An LDM entry can only match another LDM entry. */
2184 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2187 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
2188 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
2189 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
2190 : e1
->d
.h
== e2
->d
.h
);
2193 /* multi_got_entries are still a match in the case of global objects,
2194 even if the input bfd in which they're referenced differs, so the
2195 hash computation and compare functions are adjusted
2199 mips_elf_multi_got_entry_hash (const void *entry_
)
2201 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2203 return entry
->symndx
2205 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
2206 : entry
->symndx
>= 0
2207 ? ((entry
->tls_type
& GOT_TLS_LDM
)
2208 ? (GOT_TLS_LDM
<< 17)
2210 + mips_elf_hash_bfd_vma (entry
->d
.addend
)))
2211 : entry
->d
.h
->root
.root
.root
.hash
);
2215 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
2217 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2218 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2220 /* Any two LDM entries match. */
2221 if (e1
->tls_type
& e2
->tls_type
& GOT_TLS_LDM
)
2224 /* Nothing else matches an LDM entry. */
2225 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2228 return e1
->symndx
== e2
->symndx
2229 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
2230 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
2231 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
2232 : e1
->d
.h
== e2
->d
.h
);
2236 mips_got_page_entry_hash (const void *entry_
)
2238 const struct mips_got_page_entry
*entry
;
2240 entry
= (const struct mips_got_page_entry
*) entry_
;
2241 return entry
->abfd
->id
+ entry
->symndx
;
2245 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
2247 const struct mips_got_page_entry
*entry1
, *entry2
;
2249 entry1
= (const struct mips_got_page_entry
*) entry1_
;
2250 entry2
= (const struct mips_got_page_entry
*) entry2_
;
2251 return entry1
->abfd
== entry2
->abfd
&& entry1
->symndx
== entry2
->symndx
;
2254 /* Return the dynamic relocation section. If it doesn't exist, try to
2255 create a new it if CREATE_P, otherwise return NULL. Also return NULL
2256 if creation fails. */
2259 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
2265 dname
= MIPS_ELF_REL_DYN_NAME (info
);
2266 dynobj
= elf_hash_table (info
)->dynobj
;
2267 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
2268 if (sreloc
== NULL
&& create_p
)
2270 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
2275 | SEC_LINKER_CREATED
2278 || ! bfd_set_section_alignment (dynobj
, sreloc
,
2279 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
2285 /* Count the number of relocations needed for a TLS GOT entry, with
2286 access types from TLS_TYPE, and symbol H (or a local symbol if H
2290 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
2291 struct elf_link_hash_entry
*h
)
2295 bfd_boolean need_relocs
= FALSE
;
2296 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2298 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2299 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
2302 if ((info
->shared
|| indx
!= 0)
2304 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2305 || h
->root
.type
!= bfd_link_hash_undefweak
))
2311 if (tls_type
& GOT_TLS_GD
)
2318 if (tls_type
& GOT_TLS_IE
)
2321 if ((tls_type
& GOT_TLS_LDM
) && info
->shared
)
2327 /* Count the number of TLS relocations required for the GOT entry in
2328 ARG1, if it describes a local symbol. */
2331 mips_elf_count_local_tls_relocs (void **arg1
, void *arg2
)
2333 struct mips_got_entry
*entry
= * (struct mips_got_entry
**) arg1
;
2334 struct mips_elf_count_tls_arg
*arg
= arg2
;
2336 if (entry
->abfd
!= NULL
&& entry
->symndx
!= -1)
2337 arg
->needed
+= mips_tls_got_relocs (arg
->info
, entry
->tls_type
, NULL
);
2342 /* Count the number of TLS GOT entries required for the global (or
2343 forced-local) symbol in ARG1. */
2346 mips_elf_count_global_tls_entries (void *arg1
, void *arg2
)
2348 struct mips_elf_link_hash_entry
*hm
2349 = (struct mips_elf_link_hash_entry
*) arg1
;
2350 struct mips_elf_count_tls_arg
*arg
= arg2
;
2352 if (hm
->tls_type
& GOT_TLS_GD
)
2354 if (hm
->tls_type
& GOT_TLS_IE
)
2360 /* Count the number of TLS relocations required for the global (or
2361 forced-local) symbol in ARG1. */
2364 mips_elf_count_global_tls_relocs (void *arg1
, void *arg2
)
2366 struct mips_elf_link_hash_entry
*hm
2367 = (struct mips_elf_link_hash_entry
*) arg1
;
2368 struct mips_elf_count_tls_arg
*arg
= arg2
;
2370 arg
->needed
+= mips_tls_got_relocs (arg
->info
, hm
->tls_type
, &hm
->root
);
2375 /* Output a simple dynamic relocation into SRELOC. */
2378 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
2384 Elf_Internal_Rela rel
[3];
2386 memset (rel
, 0, sizeof (rel
));
2388 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
2389 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
2391 if (ABI_64_P (output_bfd
))
2393 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2394 (output_bfd
, &rel
[0],
2396 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
2399 bfd_elf32_swap_reloc_out
2400 (output_bfd
, &rel
[0],
2402 + sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
2403 ++sreloc
->reloc_count
;
2406 /* Initialize a set of TLS GOT entries for one symbol. */
2409 mips_elf_initialize_tls_slots (bfd
*abfd
, bfd_vma got_offset
,
2410 unsigned char *tls_type_p
,
2411 struct bfd_link_info
*info
,
2412 struct mips_elf_link_hash_entry
*h
,
2415 struct mips_elf_link_hash_table
*htab
;
2417 asection
*sreloc
, *sgot
;
2418 bfd_vma offset
, offset2
;
2419 bfd_boolean need_relocs
= FALSE
;
2421 htab
= mips_elf_hash_table (info
);
2427 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2429 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
2430 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
2431 indx
= h
->root
.dynindx
;
2434 if (*tls_type_p
& GOT_TLS_DONE
)
2437 if ((info
->shared
|| indx
!= 0)
2439 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
2440 || h
->root
.type
!= bfd_link_hash_undefweak
))
2443 /* MINUS_ONE means the symbol is not defined in this object. It may not
2444 be defined at all; assume that the value doesn't matter in that
2445 case. Otherwise complain if we would use the value. */
2446 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
2447 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
2449 /* Emit necessary relocations. */
2450 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
2452 /* General Dynamic. */
2453 if (*tls_type_p
& GOT_TLS_GD
)
2455 offset
= got_offset
;
2456 offset2
= offset
+ MIPS_ELF_GOT_SIZE (abfd
);
2460 mips_elf_output_dynamic_relocation
2461 (abfd
, sreloc
, indx
,
2462 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2463 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2466 mips_elf_output_dynamic_relocation
2467 (abfd
, sreloc
, indx
,
2468 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
2469 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset2
);
2471 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2472 sgot
->contents
+ offset2
);
2476 MIPS_ELF_PUT_WORD (abfd
, 1,
2477 sgot
->contents
+ offset
);
2478 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2479 sgot
->contents
+ offset2
);
2482 got_offset
+= 2 * MIPS_ELF_GOT_SIZE (abfd
);
2485 /* Initial Exec model. */
2486 if (*tls_type_p
& GOT_TLS_IE
)
2488 offset
= got_offset
;
2493 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
2494 sgot
->contents
+ offset
);
2496 MIPS_ELF_PUT_WORD (abfd
, 0,
2497 sgot
->contents
+ offset
);
2499 mips_elf_output_dynamic_relocation
2500 (abfd
, sreloc
, indx
,
2501 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
2502 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2505 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
2506 sgot
->contents
+ offset
);
2509 if (*tls_type_p
& GOT_TLS_LDM
)
2511 /* The initial offset is zero, and the LD offsets will include the
2512 bias by DTP_OFFSET. */
2513 MIPS_ELF_PUT_WORD (abfd
, 0,
2514 sgot
->contents
+ got_offset
2515 + MIPS_ELF_GOT_SIZE (abfd
));
2518 MIPS_ELF_PUT_WORD (abfd
, 1,
2519 sgot
->contents
+ got_offset
);
2521 mips_elf_output_dynamic_relocation
2522 (abfd
, sreloc
, indx
,
2523 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2524 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
2527 *tls_type_p
|= GOT_TLS_DONE
;
2530 /* Return the GOT index to use for a relocation of type R_TYPE against
2531 a symbol accessed using TLS_TYPE models. The GOT entries for this
2532 symbol in this GOT start at GOT_INDEX. This function initializes the
2533 GOT entries and corresponding relocations. */
2536 mips_tls_got_index (bfd
*abfd
, bfd_vma got_index
, unsigned char *tls_type
,
2537 int r_type
, struct bfd_link_info
*info
,
2538 struct mips_elf_link_hash_entry
*h
, bfd_vma symbol
)
2540 BFD_ASSERT (r_type
== R_MIPS_TLS_GOTTPREL
|| r_type
== R_MIPS_TLS_GD
2541 || r_type
== R_MIPS_TLS_LDM
);
2543 mips_elf_initialize_tls_slots (abfd
, got_index
, tls_type
, info
, h
, symbol
);
2545 if (r_type
== R_MIPS_TLS_GOTTPREL
)
2547 BFD_ASSERT (*tls_type
& GOT_TLS_IE
);
2548 if (*tls_type
& GOT_TLS_GD
)
2549 return got_index
+ 2 * MIPS_ELF_GOT_SIZE (abfd
);
2554 if (r_type
== R_MIPS_TLS_GD
)
2556 BFD_ASSERT (*tls_type
& GOT_TLS_GD
);
2560 if (r_type
== R_MIPS_TLS_LDM
)
2562 BFD_ASSERT (*tls_type
& GOT_TLS_LDM
);
2569 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
2570 for global symbol H. .got.plt comes before the GOT, so the offset
2571 will be negative. */
2574 mips_elf_gotplt_index (struct bfd_link_info
*info
,
2575 struct elf_link_hash_entry
*h
)
2577 bfd_vma plt_index
, got_address
, got_value
;
2578 struct mips_elf_link_hash_table
*htab
;
2580 htab
= mips_elf_hash_table (info
);
2581 BFD_ASSERT (h
->plt
.offset
!= (bfd_vma
) -1);
2583 /* Calculate the index of the symbol's PLT entry. */
2584 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
2586 /* Calculate the address of the associated .got.plt entry. */
2587 got_address
= (htab
->sgotplt
->output_section
->vma
2588 + htab
->sgotplt
->output_offset
2591 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
2592 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
2593 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
2594 + htab
->root
.hgot
->root
.u
.def
.value
);
2596 return got_address
- got_value
;
2599 /* Return the GOT offset for address VALUE. If there is not yet a GOT
2600 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
2601 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
2602 offset can be found. */
2605 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2606 bfd_vma value
, unsigned long r_symndx
,
2607 struct mips_elf_link_hash_entry
*h
, int r_type
)
2609 struct mips_elf_link_hash_table
*htab
;
2610 struct mips_got_entry
*entry
;
2612 htab
= mips_elf_hash_table (info
);
2613 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
2614 r_symndx
, h
, r_type
);
2618 if (TLS_RELOC_P (r_type
))
2620 if (entry
->symndx
== -1 && htab
->got_info
->next
== NULL
)
2621 /* A type (3) entry in the single-GOT case. We use the symbol's
2622 hash table entry to track the index. */
2623 return mips_tls_got_index (abfd
, h
->tls_got_offset
, &h
->tls_type
,
2624 r_type
, info
, h
, value
);
2626 return mips_tls_got_index (abfd
, entry
->gotidx
, &entry
->tls_type
,
2627 r_type
, info
, h
, value
);
2630 return entry
->gotidx
;
2633 /* Returns the GOT index for the global symbol indicated by H. */
2636 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
,
2637 int r_type
, struct bfd_link_info
*info
)
2639 struct mips_elf_link_hash_table
*htab
;
2641 struct mips_got_info
*g
, *gg
;
2642 long global_got_dynindx
= 0;
2644 htab
= mips_elf_hash_table (info
);
2645 gg
= g
= htab
->got_info
;
2646 if (g
->bfd2got
&& ibfd
)
2648 struct mips_got_entry e
, *p
;
2650 BFD_ASSERT (h
->dynindx
>= 0);
2652 g
= mips_elf_got_for_ibfd (g
, ibfd
);
2653 if (g
->next
!= gg
|| TLS_RELOC_P (r_type
))
2657 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
2660 p
= htab_find (g
->got_entries
, &e
);
2662 BFD_ASSERT (p
->gotidx
> 0);
2664 if (TLS_RELOC_P (r_type
))
2666 bfd_vma value
= MINUS_ONE
;
2667 if ((h
->root
.type
== bfd_link_hash_defined
2668 || h
->root
.type
== bfd_link_hash_defweak
)
2669 && h
->root
.u
.def
.section
->output_section
)
2670 value
= (h
->root
.u
.def
.value
2671 + h
->root
.u
.def
.section
->output_offset
2672 + h
->root
.u
.def
.section
->output_section
->vma
);
2674 return mips_tls_got_index (abfd
, p
->gotidx
, &p
->tls_type
, r_type
,
2675 info
, e
.d
.h
, value
);
2682 if (gg
->global_gotsym
!= NULL
)
2683 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
2685 if (TLS_RELOC_P (r_type
))
2687 struct mips_elf_link_hash_entry
*hm
2688 = (struct mips_elf_link_hash_entry
*) h
;
2689 bfd_vma value
= MINUS_ONE
;
2691 if ((h
->root
.type
== bfd_link_hash_defined
2692 || h
->root
.type
== bfd_link_hash_defweak
)
2693 && h
->root
.u
.def
.section
->output_section
)
2694 value
= (h
->root
.u
.def
.value
2695 + h
->root
.u
.def
.section
->output_offset
2696 + h
->root
.u
.def
.section
->output_section
->vma
);
2698 index
= mips_tls_got_index (abfd
, hm
->tls_got_offset
, &hm
->tls_type
,
2699 r_type
, info
, hm
, value
);
2703 /* Once we determine the global GOT entry with the lowest dynamic
2704 symbol table index, we must put all dynamic symbols with greater
2705 indices into the GOT. That makes it easy to calculate the GOT
2707 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
2708 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
2709 * MIPS_ELF_GOT_SIZE (abfd
));
2711 BFD_ASSERT (index
< htab
->sgot
->size
);
2716 /* Find a GOT page entry that points to within 32KB of VALUE. These
2717 entries are supposed to be placed at small offsets in the GOT, i.e.,
2718 within 32KB of GP. Return the index of the GOT entry, or -1 if no
2719 entry could be created. If OFFSETP is nonnull, use it to return the
2720 offset of the GOT entry from VALUE. */
2723 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2724 bfd_vma value
, bfd_vma
*offsetp
)
2726 bfd_vma page
, index
;
2727 struct mips_got_entry
*entry
;
2729 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
2730 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
2731 NULL
, R_MIPS_GOT_PAGE
);
2736 index
= entry
->gotidx
;
2739 *offsetp
= value
- entry
->d
.address
;
2744 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
2745 EXTERNAL is true if the relocation was against a global symbol
2746 that has been forced local. */
2749 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2750 bfd_vma value
, bfd_boolean external
)
2752 struct mips_got_entry
*entry
;
2754 /* GOT16 relocations against local symbols are followed by a LO16
2755 relocation; those against global symbols are not. Thus if the
2756 symbol was originally local, the GOT16 relocation should load the
2757 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
2759 value
= mips_elf_high (value
) << 16;
2761 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
2762 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
2763 same in all cases. */
2764 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
2765 NULL
, R_MIPS_GOT16
);
2767 return entry
->gotidx
;
2772 /* Returns the offset for the entry at the INDEXth position
2776 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
2777 bfd
*input_bfd
, bfd_vma index
)
2779 struct mips_elf_link_hash_table
*htab
;
2783 htab
= mips_elf_hash_table (info
);
2785 gp
= _bfd_get_gp_value (output_bfd
)
2786 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
2788 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
2791 /* Create and return a local GOT entry for VALUE, which was calculated
2792 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
2793 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
2796 static struct mips_got_entry
*
2797 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
2798 bfd
*ibfd
, bfd_vma value
,
2799 unsigned long r_symndx
,
2800 struct mips_elf_link_hash_entry
*h
,
2803 struct mips_got_entry entry
, **loc
;
2804 struct mips_got_info
*g
;
2805 struct mips_elf_link_hash_table
*htab
;
2807 htab
= mips_elf_hash_table (info
);
2811 entry
.d
.address
= value
;
2814 g
= mips_elf_got_for_ibfd (htab
->got_info
, ibfd
);
2817 g
= mips_elf_got_for_ibfd (htab
->got_info
, abfd
);
2818 BFD_ASSERT (g
!= NULL
);
2821 /* We might have a symbol, H, if it has been forced local. Use the
2822 global entry then. It doesn't matter whether an entry is local
2823 or global for TLS, since the dynamic linker does not
2824 automatically relocate TLS GOT entries. */
2825 BFD_ASSERT (h
== NULL
|| h
->root
.forced_local
);
2826 if (TLS_RELOC_P (r_type
))
2828 struct mips_got_entry
*p
;
2831 if (r_type
== R_MIPS_TLS_LDM
)
2833 entry
.tls_type
= GOT_TLS_LDM
;
2839 entry
.symndx
= r_symndx
;
2845 p
= (struct mips_got_entry
*)
2846 htab_find (g
->got_entries
, &entry
);
2852 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
2857 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
2860 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2865 memcpy (*loc
, &entry
, sizeof entry
);
2867 if (g
->assigned_gotno
> g
->local_gotno
)
2869 (*loc
)->gotidx
= -1;
2870 /* We didn't allocate enough space in the GOT. */
2871 (*_bfd_error_handler
)
2872 (_("not enough GOT space for local GOT entries"));
2873 bfd_set_error (bfd_error_bad_value
);
2877 MIPS_ELF_PUT_WORD (abfd
, value
,
2878 (htab
->sgot
->contents
+ entry
.gotidx
));
2880 /* These GOT entries need a dynamic relocation on VxWorks. */
2881 if (htab
->is_vxworks
)
2883 Elf_Internal_Rela outrel
;
2886 bfd_vma got_address
;
2888 s
= mips_elf_rel_dyn_section (info
, FALSE
);
2889 got_address
= (htab
->sgot
->output_section
->vma
2890 + htab
->sgot
->output_offset
2893 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
2894 outrel
.r_offset
= got_address
;
2895 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
2896 outrel
.r_addend
= value
;
2897 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
2903 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
2904 The number might be exact or a worst-case estimate, depending on how
2905 much information is available to elf_backend_omit_section_dynsym at
2906 the current linking stage. */
2908 static bfd_size_type
2909 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
2911 bfd_size_type count
;
2914 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
2917 const struct elf_backend_data
*bed
;
2919 bed
= get_elf_backend_data (output_bfd
);
2920 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
2921 if ((p
->flags
& SEC_EXCLUDE
) == 0
2922 && (p
->flags
& SEC_ALLOC
) != 0
2923 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
2929 /* Sort the dynamic symbol table so that symbols that need GOT entries
2930 appear towards the end. */
2933 mips_elf_sort_hash_table (bfd
*abfd
, struct bfd_link_info
*info
)
2935 struct mips_elf_link_hash_table
*htab
;
2936 struct mips_elf_hash_sort_data hsd
;
2937 struct mips_got_info
*g
;
2939 if (elf_hash_table (info
)->dynsymcount
== 0)
2942 htab
= mips_elf_hash_table (info
);
2948 hsd
.max_unref_got_dynindx
2949 = hsd
.min_got_dynindx
2950 = (elf_hash_table (info
)->dynsymcount
- g
->reloc_only_gotno
);
2951 hsd
.max_non_got_dynindx
= count_section_dynsyms (abfd
, info
) + 1;
2952 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
2953 elf_hash_table (info
)),
2954 mips_elf_sort_hash_table_f
,
2957 /* There should have been enough room in the symbol table to
2958 accommodate both the GOT and non-GOT symbols. */
2959 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
2960 BFD_ASSERT ((unsigned long) hsd
.max_unref_got_dynindx
2961 == elf_hash_table (info
)->dynsymcount
);
2962 BFD_ASSERT (elf_hash_table (info
)->dynsymcount
- hsd
.min_got_dynindx
2963 == g
->global_gotno
);
2965 /* Now we know which dynamic symbol has the lowest dynamic symbol
2966 table index in the GOT. */
2967 g
->global_gotsym
= hsd
.low
;
2972 /* If H needs a GOT entry, assign it the highest available dynamic
2973 index. Otherwise, assign it the lowest available dynamic
2977 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
2979 struct mips_elf_hash_sort_data
*hsd
= data
;
2981 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2982 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2984 /* Symbols without dynamic symbol table entries aren't interesting
2986 if (h
->root
.dynindx
== -1)
2989 switch (h
->global_got_area
)
2992 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
2996 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
2998 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
2999 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3002 case GGA_RELOC_ONLY
:
3003 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
3005 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
3006 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3007 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
3014 /* If H is a symbol that needs a global GOT entry, but has a dynamic
3015 symbol table index lower than any we've seen to date, record it for
3019 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
3020 bfd
*abfd
, struct bfd_link_info
*info
,
3021 unsigned char tls_flag
)
3023 struct mips_elf_link_hash_table
*htab
;
3024 struct mips_elf_link_hash_entry
*hmips
;
3025 struct mips_got_entry entry
, **loc
;
3026 struct mips_got_info
*g
;
3028 htab
= mips_elf_hash_table (info
);
3029 hmips
= (struct mips_elf_link_hash_entry
*) h
;
3031 /* A global symbol in the GOT must also be in the dynamic symbol
3033 if (h
->dynindx
== -1)
3035 switch (ELF_ST_VISIBILITY (h
->other
))
3039 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
3042 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3046 /* Make sure we have a GOT to put this entry into. */
3048 BFD_ASSERT (g
!= NULL
);
3052 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3055 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3058 /* If we've already marked this entry as needing GOT space, we don't
3059 need to do it again. */
3062 (*loc
)->tls_type
|= tls_flag
;
3066 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3072 entry
.tls_type
= tls_flag
;
3074 memcpy (*loc
, &entry
, sizeof entry
);
3077 hmips
->global_got_area
= GGA_NORMAL
;
3082 /* Reserve space in G for a GOT entry containing the value of symbol
3083 SYMNDX in input bfd ABDF, plus ADDEND. */
3086 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
3087 struct bfd_link_info
*info
,
3088 unsigned char tls_flag
)
3090 struct mips_elf_link_hash_table
*htab
;
3091 struct mips_got_info
*g
;
3092 struct mips_got_entry entry
, **loc
;
3094 htab
= mips_elf_hash_table (info
);
3096 BFD_ASSERT (g
!= NULL
);
3099 entry
.symndx
= symndx
;
3100 entry
.d
.addend
= addend
;
3101 entry
.tls_type
= tls_flag
;
3102 loc
= (struct mips_got_entry
**)
3103 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
3107 if (tls_flag
== GOT_TLS_GD
&& !((*loc
)->tls_type
& GOT_TLS_GD
))
3110 (*loc
)->tls_type
|= tls_flag
;
3112 else if (tls_flag
== GOT_TLS_IE
&& !((*loc
)->tls_type
& GOT_TLS_IE
))
3115 (*loc
)->tls_type
|= tls_flag
;
3123 entry
.tls_type
= tls_flag
;
3124 if (tls_flag
== GOT_TLS_IE
)
3126 else if (tls_flag
== GOT_TLS_GD
)
3128 else if (g
->tls_ldm_offset
== MINUS_ONE
)
3130 g
->tls_ldm_offset
= MINUS_TWO
;
3136 entry
.gotidx
= g
->local_gotno
++;
3140 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3145 memcpy (*loc
, &entry
, sizeof entry
);
3150 /* Return the maximum number of GOT page entries required for RANGE. */
3153 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
3155 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
3158 /* Record that ABFD has a page relocation against symbol SYMNDX and
3159 that ADDEND is the addend for that relocation.
3161 This function creates an upper bound on the number of GOT slots
3162 required; no attempt is made to combine references to non-overridable
3163 global symbols across multiple input files. */
3166 mips_elf_record_got_page_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3167 long symndx
, bfd_signed_vma addend
)
3169 struct mips_elf_link_hash_table
*htab
;
3170 struct mips_got_info
*g
;
3171 struct mips_got_page_entry lookup
, *entry
;
3172 struct mips_got_page_range
**range_ptr
, *range
;
3173 bfd_vma old_pages
, new_pages
;
3176 htab
= mips_elf_hash_table (info
);
3178 BFD_ASSERT (g
!= NULL
);
3180 /* Find the mips_got_page_entry hash table entry for this symbol. */
3182 lookup
.symndx
= symndx
;
3183 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
3187 /* Create a mips_got_page_entry if this is the first time we've
3189 entry
= (struct mips_got_page_entry
*) *loc
;
3192 entry
= bfd_alloc (abfd
, sizeof (*entry
));
3197 entry
->symndx
= symndx
;
3198 entry
->ranges
= NULL
;
3199 entry
->num_pages
= 0;
3203 /* Skip over ranges whose maximum extent cannot share a page entry
3205 range_ptr
= &entry
->ranges
;
3206 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
3207 range_ptr
= &(*range_ptr
)->next
;
3209 /* If we scanned to the end of the list, or found a range whose
3210 minimum extent cannot share a page entry with ADDEND, create
3211 a new singleton range. */
3213 if (!range
|| addend
< range
->min_addend
- 0xffff)
3215 range
= bfd_alloc (abfd
, sizeof (*range
));
3219 range
->next
= *range_ptr
;
3220 range
->min_addend
= addend
;
3221 range
->max_addend
= addend
;
3229 /* Remember how many pages the old range contributed. */
3230 old_pages
= mips_elf_pages_for_range (range
);
3232 /* Update the ranges. */
3233 if (addend
< range
->min_addend
)
3234 range
->min_addend
= addend
;
3235 else if (addend
> range
->max_addend
)
3237 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
3239 old_pages
+= mips_elf_pages_for_range (range
->next
);
3240 range
->max_addend
= range
->next
->max_addend
;
3241 range
->next
= range
->next
->next
;
3244 range
->max_addend
= addend
;
3247 /* Record any change in the total estimate. */
3248 new_pages
= mips_elf_pages_for_range (range
);
3249 if (old_pages
!= new_pages
)
3251 entry
->num_pages
+= new_pages
- old_pages
;
3252 g
->page_gotno
+= new_pages
- old_pages
;
3258 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
3261 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
3265 struct mips_elf_link_hash_table
*htab
;
3267 htab
= mips_elf_hash_table (info
);
3268 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3269 BFD_ASSERT (s
!= NULL
);
3271 if (htab
->is_vxworks
)
3272 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
3277 /* Make room for a null element. */
3278 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
3281 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
3285 /* A htab_traverse callback for GOT entries. Set boolean *DATA to true
3286 if the GOT entry is for an indirect or warning symbol. */
3289 mips_elf_check_recreate_got (void **entryp
, void *data
)
3291 struct mips_got_entry
*entry
;
3292 bfd_boolean
*must_recreate
;
3294 entry
= (struct mips_got_entry
*) *entryp
;
3295 must_recreate
= (bfd_boolean
*) data
;
3296 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3298 struct mips_elf_link_hash_entry
*h
;
3301 if (h
->root
.root
.type
== bfd_link_hash_indirect
3302 || h
->root
.root
.type
== bfd_link_hash_warning
)
3304 *must_recreate
= TRUE
;
3311 /* A htab_traverse callback for GOT entries. Add all entries to
3312 hash table *DATA, converting entries for indirect and warning
3313 symbols into entries for the target symbol. Set *DATA to null
3317 mips_elf_recreate_got (void **entryp
, void *data
)
3320 struct mips_got_entry
*entry
;
3323 new_got
= (htab_t
*) data
;
3324 entry
= (struct mips_got_entry
*) *entryp
;
3325 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3327 struct mips_elf_link_hash_entry
*h
;
3330 while (h
->root
.root
.type
== bfd_link_hash_indirect
3331 || h
->root
.root
.type
== bfd_link_hash_warning
)
3333 BFD_ASSERT (h
->global_got_area
== GGA_NONE
);
3334 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3338 slot
= htab_find_slot (*new_got
, entry
, INSERT
);
3351 /* If any entries in G->got_entries are for indirect or warning symbols,
3352 replace them with entries for the target symbol. */
3355 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
3357 bfd_boolean must_recreate
;
3360 must_recreate
= FALSE
;
3361 htab_traverse (g
->got_entries
, mips_elf_check_recreate_got
, &must_recreate
);
3364 new_got
= htab_create (htab_size (g
->got_entries
),
3365 mips_elf_got_entry_hash
,
3366 mips_elf_got_entry_eq
, NULL
);
3367 htab_traverse (g
->got_entries
, mips_elf_recreate_got
, &new_got
);
3368 if (new_got
== NULL
)
3371 /* Each entry in g->got_entries has either been copied to new_got
3372 or freed. Now delete the hash table itself. */
3373 htab_delete (g
->got_entries
);
3374 g
->got_entries
= new_got
;
3379 /* A mips_elf_link_hash_traverse callback for which DATA points
3380 to a mips_got_info. Count the number of type (3) entries. */
3383 mips_elf_count_got_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
3385 struct mips_got_info
*g
;
3387 g
= (struct mips_got_info
*) data
;
3388 if (h
->global_got_area
!= GGA_NONE
)
3390 if (h
->root
.forced_local
|| h
->root
.dynindx
== -1)
3392 /* We no longer need this entry if it was only used for
3393 relocations; those relocations will be against the
3394 null or section symbol instead of H. */
3395 if (h
->global_got_area
!= GGA_RELOC_ONLY
)
3397 h
->global_got_area
= GGA_NONE
;
3402 if (h
->global_got_area
== GGA_RELOC_ONLY
)
3403 g
->reloc_only_gotno
++;
3409 /* Compute the hash value of the bfd in a bfd2got hash entry. */
3412 mips_elf_bfd2got_entry_hash (const void *entry_
)
3414 const struct mips_elf_bfd2got_hash
*entry
3415 = (struct mips_elf_bfd2got_hash
*)entry_
;
3417 return entry
->bfd
->id
;
3420 /* Check whether two hash entries have the same bfd. */
3423 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
3425 const struct mips_elf_bfd2got_hash
*e1
3426 = (const struct mips_elf_bfd2got_hash
*)entry1
;
3427 const struct mips_elf_bfd2got_hash
*e2
3428 = (const struct mips_elf_bfd2got_hash
*)entry2
;
3430 return e1
->bfd
== e2
->bfd
;
3433 /* In a multi-got link, determine the GOT to be used for IBFD. G must
3434 be the master GOT data. */
3436 static struct mips_got_info
*
3437 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
3439 struct mips_elf_bfd2got_hash e
, *p
;
3445 p
= htab_find (g
->bfd2got
, &e
);
3446 return p
? p
->g
: NULL
;
3449 /* Use BFD2GOT to find ABFD's got entry, creating one if none exists.
3450 Return NULL if an error occured. */
3452 static struct mips_got_info
*
3453 mips_elf_get_got_for_bfd (struct htab
*bfd2got
, bfd
*output_bfd
,
3456 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
3457 struct mips_got_info
*g
;
3460 bfdgot_entry
.bfd
= input_bfd
;
3461 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
3462 bfdgot
= (struct mips_elf_bfd2got_hash
*) *bfdgotp
;
3466 bfdgot
= ((struct mips_elf_bfd2got_hash
*)
3467 bfd_alloc (output_bfd
, sizeof (struct mips_elf_bfd2got_hash
)));
3473 g
= ((struct mips_got_info
*)
3474 bfd_alloc (output_bfd
, sizeof (struct mips_got_info
)));
3478 bfdgot
->bfd
= input_bfd
;
3481 g
->global_gotsym
= NULL
;
3482 g
->global_gotno
= 0;
3483 g
->reloc_only_gotno
= 0;
3486 g
->assigned_gotno
= -1;
3488 g
->tls_assigned_gotno
= 0;
3489 g
->tls_ldm_offset
= MINUS_ONE
;
3490 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3491 mips_elf_multi_got_entry_eq
, NULL
);
3492 if (g
->got_entries
== NULL
)
3495 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3496 mips_got_page_entry_eq
, NULL
);
3497 if (g
->got_page_entries
== NULL
)
3507 /* A htab_traverse callback for the entries in the master got.
3508 Create one separate got for each bfd that has entries in the global
3509 got, such that we can tell how many local and global entries each
3513 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
3515 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3516 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3517 struct mips_got_info
*g
;
3519 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3526 /* Insert the GOT entry in the bfd's got entry hash table. */
3527 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
3528 if (*entryp
!= NULL
)
3533 if (entry
->tls_type
)
3535 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3537 if (entry
->tls_type
& GOT_TLS_IE
)
3540 else if (entry
->symndx
>= 0 || entry
->d
.h
->root
.forced_local
)
3548 /* A htab_traverse callback for the page entries in the master got.
3549 Associate each page entry with the bfd's got. */
3552 mips_elf_make_got_pages_per_bfd (void **entryp
, void *p
)
3554 struct mips_got_page_entry
*entry
= (struct mips_got_page_entry
*) *entryp
;
3555 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*) p
;
3556 struct mips_got_info
*g
;
3558 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3565 /* Insert the GOT entry in the bfd's got entry hash table. */
3566 entryp
= htab_find_slot (g
->got_page_entries
, entry
, INSERT
);
3567 if (*entryp
!= NULL
)
3571 g
->page_gotno
+= entry
->num_pages
;
3575 /* Consider merging the got described by BFD2GOT with TO, using the
3576 information given by ARG. Return -1 if this would lead to overflow,
3577 1 if they were merged successfully, and 0 if a merge failed due to
3578 lack of memory. (These values are chosen so that nonnegative return
3579 values can be returned by a htab_traverse callback.) */
3582 mips_elf_merge_got_with (struct mips_elf_bfd2got_hash
*bfd2got
,
3583 struct mips_got_info
*to
,
3584 struct mips_elf_got_per_bfd_arg
*arg
)
3586 struct mips_got_info
*from
= bfd2got
->g
;
3587 unsigned int estimate
;
3589 /* Work out how many page entries we would need for the combined GOT. */
3590 estimate
= arg
->max_pages
;
3591 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
3592 estimate
= from
->page_gotno
+ to
->page_gotno
;
3594 /* And conservatively estimate how many local, global and TLS entries
3596 estimate
+= (from
->local_gotno
3597 + from
->global_gotno
3603 /* Bail out if the combined GOT might be too big. */
3604 if (estimate
> arg
->max_count
)
3607 /* Commit to the merge. Record that TO is now the bfd for this got. */
3610 /* Transfer the bfd's got information from FROM to TO. */
3611 htab_traverse (from
->got_entries
, mips_elf_make_got_per_bfd
, arg
);
3612 if (arg
->obfd
== NULL
)
3615 htab_traverse (from
->got_page_entries
, mips_elf_make_got_pages_per_bfd
, arg
);
3616 if (arg
->obfd
== NULL
)
3619 /* We don't have to worry about releasing memory of the actual
3620 got entries, since they're all in the master got_entries hash
3622 htab_delete (from
->got_entries
);
3623 htab_delete (from
->got_page_entries
);
3627 /* Attempt to merge gots of different input bfds. Try to use as much
3628 as possible of the primary got, since it doesn't require explicit
3629 dynamic relocations, but don't use bfds that would reference global
3630 symbols out of the addressable range. Failing the primary got,
3631 attempt to merge with the current got, or finish the current got
3632 and then make make the new got current. */
3635 mips_elf_merge_gots (void **bfd2got_
, void *p
)
3637 struct mips_elf_bfd2got_hash
*bfd2got
3638 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
3639 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3640 struct mips_got_info
*g
;
3641 unsigned int estimate
;
3646 /* Work out the number of page, local and TLS entries. */
3647 estimate
= arg
->max_pages
;
3648 if (estimate
> g
->page_gotno
)
3649 estimate
= g
->page_gotno
;
3650 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
3652 /* We place TLS GOT entries after both locals and globals. The globals
3653 for the primary GOT may overflow the normal GOT size limit, so be
3654 sure not to merge a GOT which requires TLS with the primary GOT in that
3655 case. This doesn't affect non-primary GOTs. */
3656 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
3658 if (estimate
<= arg
->max_count
)
3660 /* If we don't have a primary GOT, use it as
3661 a starting point for the primary GOT. */
3664 arg
->primary
= bfd2got
->g
;
3668 /* Try merging with the primary GOT. */
3669 result
= mips_elf_merge_got_with (bfd2got
, arg
->primary
, arg
);
3674 /* If we can merge with the last-created got, do it. */
3677 result
= mips_elf_merge_got_with (bfd2got
, arg
->current
, arg
);
3682 /* Well, we couldn't merge, so create a new GOT. Don't check if it
3683 fits; if it turns out that it doesn't, we'll get relocation
3684 overflows anyway. */
3685 g
->next
= arg
->current
;
3691 /* Set the TLS GOT index for the GOT entry in ENTRYP. ENTRYP's NEXT field
3692 is null iff there is just a single GOT. */
3695 mips_elf_initialize_tls_index (void **entryp
, void *p
)
3697 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3698 struct mips_got_info
*g
= p
;
3700 unsigned char tls_type
;
3702 /* We're only interested in TLS symbols. */
3703 if (entry
->tls_type
== 0)
3706 next_index
= MIPS_ELF_GOT_SIZE (entry
->abfd
) * (long) g
->tls_assigned_gotno
;
3708 if (entry
->symndx
== -1 && g
->next
== NULL
)
3710 /* A type (3) got entry in the single-GOT case. We use the symbol's
3711 hash table entry to track its index. */
3712 if (entry
->d
.h
->tls_type
& GOT_TLS_OFFSET_DONE
)
3714 entry
->d
.h
->tls_type
|= GOT_TLS_OFFSET_DONE
;
3715 entry
->d
.h
->tls_got_offset
= next_index
;
3716 tls_type
= entry
->d
.h
->tls_type
;
3720 if (entry
->tls_type
& GOT_TLS_LDM
)
3722 /* There are separate mips_got_entry objects for each input bfd
3723 that requires an LDM entry. Make sure that all LDM entries in
3724 a GOT resolve to the same index. */
3725 if (g
->tls_ldm_offset
!= MINUS_TWO
&& g
->tls_ldm_offset
!= MINUS_ONE
)
3727 entry
->gotidx
= g
->tls_ldm_offset
;
3730 g
->tls_ldm_offset
= next_index
;
3732 entry
->gotidx
= next_index
;
3733 tls_type
= entry
->tls_type
;
3736 /* Account for the entries we've just allocated. */
3737 if (tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3738 g
->tls_assigned_gotno
+= 2;
3739 if (tls_type
& GOT_TLS_IE
)
3740 g
->tls_assigned_gotno
+= 1;
3745 /* If passed a NULL mips_got_info in the argument, set the marker used
3746 to tell whether a global symbol needs a got entry (in the primary
3747 got) to the given VALUE.
3749 If passed a pointer G to a mips_got_info in the argument (it must
3750 not be the primary GOT), compute the offset from the beginning of
3751 the (primary) GOT section to the entry in G corresponding to the
3752 global symbol. G's assigned_gotno must contain the index of the
3753 first available global GOT entry in G. VALUE must contain the size
3754 of a GOT entry in bytes. For each global GOT entry that requires a
3755 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
3756 marked as not eligible for lazy resolution through a function
3759 mips_elf_set_global_got_offset (void **entryp
, void *p
)
3761 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3762 struct mips_elf_set_global_got_offset_arg
*arg
3763 = (struct mips_elf_set_global_got_offset_arg
*)p
;
3764 struct mips_got_info
*g
= arg
->g
;
3766 if (g
&& entry
->tls_type
!= GOT_NORMAL
)
3767 arg
->needed_relocs
+=
3768 mips_tls_got_relocs (arg
->info
, entry
->tls_type
,
3769 entry
->symndx
== -1 ? &entry
->d
.h
->root
: NULL
);
3771 if (entry
->abfd
!= NULL
3772 && entry
->symndx
== -1
3773 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
3777 BFD_ASSERT (g
->global_gotsym
== NULL
);
3779 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
3780 if (arg
->info
->shared
3781 || (elf_hash_table (arg
->info
)->dynamic_sections_created
3782 && entry
->d
.h
->root
.def_dynamic
3783 && !entry
->d
.h
->root
.def_regular
))
3784 ++arg
->needed_relocs
;
3787 entry
->d
.h
->global_got_area
= arg
->value
;
3793 /* A htab_traverse callback for GOT entries for which DATA is the
3794 bfd_link_info. Forbid any global symbols from having traditional
3795 lazy-binding stubs. */
3798 mips_elf_forbid_lazy_stubs (void **entryp
, void *data
)
3800 struct bfd_link_info
*info
;
3801 struct mips_elf_link_hash_table
*htab
;
3802 struct mips_got_entry
*entry
;
3804 entry
= (struct mips_got_entry
*) *entryp
;
3805 info
= (struct bfd_link_info
*) data
;
3806 htab
= mips_elf_hash_table (info
);
3807 if (entry
->abfd
!= NULL
3808 && entry
->symndx
== -1
3809 && entry
->d
.h
->needs_lazy_stub
)
3811 entry
->d
.h
->needs_lazy_stub
= FALSE
;
3812 htab
->lazy_stub_count
--;
3818 /* Return the offset of an input bfd IBFD's GOT from the beginning of
3821 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
3823 if (g
->bfd2got
== NULL
)
3826 g
= mips_elf_got_for_ibfd (g
, ibfd
);
3830 BFD_ASSERT (g
->next
);
3834 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
3835 * MIPS_ELF_GOT_SIZE (abfd
);
3838 /* Turn a single GOT that is too big for 16-bit addressing into
3839 a sequence of GOTs, each one 16-bit addressable. */
3842 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
3843 asection
*got
, bfd_size_type pages
)
3845 struct mips_elf_link_hash_table
*htab
;
3846 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
3847 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
3848 struct mips_got_info
*g
, *gg
;
3849 unsigned int assign
, needed_relocs
;
3852 dynobj
= elf_hash_table (info
)->dynobj
;
3853 htab
= mips_elf_hash_table (info
);
3855 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
3856 mips_elf_bfd2got_entry_eq
, NULL
);
3857 if (g
->bfd2got
== NULL
)
3860 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
3861 got_per_bfd_arg
.obfd
= abfd
;
3862 got_per_bfd_arg
.info
= info
;
3864 /* Count how many GOT entries each input bfd requires, creating a
3865 map from bfd to got info while at that. */
3866 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
3867 if (got_per_bfd_arg
.obfd
== NULL
)
3870 /* Also count how many page entries each input bfd requires. */
3871 htab_traverse (g
->got_page_entries
, mips_elf_make_got_pages_per_bfd
,
3873 if (got_per_bfd_arg
.obfd
== NULL
)
3876 got_per_bfd_arg
.current
= NULL
;
3877 got_per_bfd_arg
.primary
= NULL
;
3878 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
3879 / MIPS_ELF_GOT_SIZE (abfd
))
3880 - MIPS_RESERVED_GOTNO (info
));
3881 got_per_bfd_arg
.max_pages
= pages
;
3882 /* The number of globals that will be included in the primary GOT.
3883 See the calls to mips_elf_set_global_got_offset below for more
3885 got_per_bfd_arg
.global_count
= g
->global_gotno
;
3887 /* Try to merge the GOTs of input bfds together, as long as they
3888 don't seem to exceed the maximum GOT size, choosing one of them
3889 to be the primary GOT. */
3890 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
3891 if (got_per_bfd_arg
.obfd
== NULL
)
3894 /* If we do not find any suitable primary GOT, create an empty one. */
3895 if (got_per_bfd_arg
.primary
== NULL
)
3897 g
->next
= (struct mips_got_info
*)
3898 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
3899 if (g
->next
== NULL
)
3902 g
->next
->global_gotsym
= NULL
;
3903 g
->next
->global_gotno
= 0;
3904 g
->next
->reloc_only_gotno
= 0;
3905 g
->next
->local_gotno
= 0;
3906 g
->next
->page_gotno
= 0;
3907 g
->next
->tls_gotno
= 0;
3908 g
->next
->assigned_gotno
= 0;
3909 g
->next
->tls_assigned_gotno
= 0;
3910 g
->next
->tls_ldm_offset
= MINUS_ONE
;
3911 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3912 mips_elf_multi_got_entry_eq
,
3914 if (g
->next
->got_entries
== NULL
)
3916 g
->next
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3917 mips_got_page_entry_eq
,
3919 if (g
->next
->got_page_entries
== NULL
)
3921 g
->next
->bfd2got
= NULL
;
3924 g
->next
= got_per_bfd_arg
.primary
;
3925 g
->next
->next
= got_per_bfd_arg
.current
;
3927 /* GG is now the master GOT, and G is the primary GOT. */
3931 /* Map the output bfd to the primary got. That's what we're going
3932 to use for bfds that use GOT16 or GOT_PAGE relocations that we
3933 didn't mark in check_relocs, and we want a quick way to find it.
3934 We can't just use gg->next because we're going to reverse the
3937 struct mips_elf_bfd2got_hash
*bfdgot
;
3940 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
3941 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
3948 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
3950 BFD_ASSERT (*bfdgotp
== NULL
);
3954 /* Every symbol that is referenced in a dynamic relocation must be
3955 present in the primary GOT, so arrange for them to appear after
3956 those that are actually referenced. */
3957 gg
->reloc_only_gotno
= gg
->global_gotno
- g
->global_gotno
;
3958 g
->global_gotno
= gg
->global_gotno
;
3960 set_got_offset_arg
.g
= NULL
;
3961 set_got_offset_arg
.value
= GGA_RELOC_ONLY
;
3962 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
3963 &set_got_offset_arg
);
3964 set_got_offset_arg
.value
= GGA_NORMAL
;
3965 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
3966 &set_got_offset_arg
);
3968 /* Now go through the GOTs assigning them offset ranges.
3969 [assigned_gotno, local_gotno[ will be set to the range of local
3970 entries in each GOT. We can then compute the end of a GOT by
3971 adding local_gotno to global_gotno. We reverse the list and make
3972 it circular since then we'll be able to quickly compute the
3973 beginning of a GOT, by computing the end of its predecessor. To
3974 avoid special cases for the primary GOT, while still preserving
3975 assertions that are valid for both single- and multi-got links,
3976 we arrange for the main got struct to have the right number of
3977 global entries, but set its local_gotno such that the initial
3978 offset of the primary GOT is zero. Remember that the primary GOT
3979 will become the last item in the circular linked list, so it
3980 points back to the master GOT. */
3981 gg
->local_gotno
= -g
->global_gotno
;
3982 gg
->global_gotno
= g
->global_gotno
;
3989 struct mips_got_info
*gn
;
3991 assign
+= MIPS_RESERVED_GOTNO (info
);
3992 g
->assigned_gotno
= assign
;
3993 g
->local_gotno
+= assign
;
3994 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
3995 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
3997 /* Take g out of the direct list, and push it onto the reversed
3998 list that gg points to. g->next is guaranteed to be nonnull after
3999 this operation, as required by mips_elf_initialize_tls_index. */
4004 /* Set up any TLS entries. We always place the TLS entries after
4005 all non-TLS entries. */
4006 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
4007 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
4009 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
4012 /* Forbid global symbols in every non-primary GOT from having
4013 lazy-binding stubs. */
4015 htab_traverse (g
->got_entries
, mips_elf_forbid_lazy_stubs
, info
);
4019 got
->size
= (gg
->next
->local_gotno
4020 + gg
->next
->global_gotno
4021 + gg
->next
->tls_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
4024 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4025 set_got_offset_arg
.info
= info
;
4026 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
4028 unsigned int save_assign
;
4030 /* Assign offsets to global GOT entries. */
4031 save_assign
= g
->assigned_gotno
;
4032 g
->assigned_gotno
= g
->local_gotno
;
4033 set_got_offset_arg
.g
= g
;
4034 set_got_offset_arg
.needed_relocs
= 0;
4035 htab_traverse (g
->got_entries
,
4036 mips_elf_set_global_got_offset
,
4037 &set_got_offset_arg
);
4038 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
4039 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
<= g
->global_gotno
);
4041 g
->assigned_gotno
= save_assign
;
4044 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
4045 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
4046 + g
->next
->global_gotno
4047 + g
->next
->tls_gotno
4048 + MIPS_RESERVED_GOTNO (info
));
4053 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
4060 /* Returns the first relocation of type r_type found, beginning with
4061 RELOCATION. RELEND is one-past-the-end of the relocation table. */
4063 static const Elf_Internal_Rela
*
4064 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
4065 const Elf_Internal_Rela
*relocation
,
4066 const Elf_Internal_Rela
*relend
)
4068 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
4070 while (relocation
< relend
)
4072 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
4073 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
4079 /* We didn't find it. */
4083 /* Return whether a relocation is against a local symbol. */
4086 mips_elf_local_relocation_p (bfd
*input_bfd
,
4087 const Elf_Internal_Rela
*relocation
,
4088 asection
**local_sections
,
4089 bfd_boolean check_forced
)
4091 unsigned long r_symndx
;
4092 Elf_Internal_Shdr
*symtab_hdr
;
4093 struct mips_elf_link_hash_entry
*h
;
4096 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4097 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4098 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
4100 if (r_symndx
< extsymoff
)
4102 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
4107 /* Look up the hash table to check whether the symbol
4108 was forced local. */
4109 h
= (struct mips_elf_link_hash_entry
*)
4110 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
4111 /* Find the real hash-table entry for this symbol. */
4112 while (h
->root
.root
.type
== bfd_link_hash_indirect
4113 || h
->root
.root
.type
== bfd_link_hash_warning
)
4114 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4115 if (h
->root
.forced_local
)
4122 /* Sign-extend VALUE, which has the indicated number of BITS. */
4125 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
4127 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
4128 /* VALUE is negative. */
4129 value
|= ((bfd_vma
) - 1) << bits
;
4134 /* Return non-zero if the indicated VALUE has overflowed the maximum
4135 range expressible by a signed number with the indicated number of
4139 mips_elf_overflow_p (bfd_vma value
, int bits
)
4141 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
4143 if (svalue
> (1 << (bits
- 1)) - 1)
4144 /* The value is too big. */
4146 else if (svalue
< -(1 << (bits
- 1)))
4147 /* The value is too small. */
4154 /* Calculate the %high function. */
4157 mips_elf_high (bfd_vma value
)
4159 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
4162 /* Calculate the %higher function. */
4165 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
4168 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
4175 /* Calculate the %highest function. */
4178 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
4181 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
4188 /* Create the .compact_rel section. */
4191 mips_elf_create_compact_rel_section
4192 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4195 register asection
*s
;
4197 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4199 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
4202 s
= bfd_make_section_with_flags (abfd
, ".compact_rel", flags
);
4204 || ! bfd_set_section_alignment (abfd
, s
,
4205 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4208 s
->size
= sizeof (Elf32_External_compact_rel
);
4214 /* Create the .got section to hold the global offset table. */
4217 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4220 register asection
*s
;
4221 struct elf_link_hash_entry
*h
;
4222 struct bfd_link_hash_entry
*bh
;
4223 struct mips_got_info
*g
;
4225 struct mips_elf_link_hash_table
*htab
;
4227 htab
= mips_elf_hash_table (info
);
4229 /* This function may be called more than once. */
4233 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4234 | SEC_LINKER_CREATED
);
4236 /* We have to use an alignment of 2**4 here because this is hardcoded
4237 in the function stub generation and in the linker script. */
4238 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4240 || ! bfd_set_section_alignment (abfd
, s
, 4))
4244 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4245 linker script because we don't want to define the symbol if we
4246 are not creating a global offset table. */
4248 if (! (_bfd_generic_link_add_one_symbol
4249 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4250 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4253 h
= (struct elf_link_hash_entry
*) bh
;
4256 h
->type
= STT_OBJECT
;
4257 elf_hash_table (info
)->hgot
= h
;
4260 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4263 amt
= sizeof (struct mips_got_info
);
4264 g
= bfd_alloc (abfd
, amt
);
4267 g
->global_gotsym
= NULL
;
4268 g
->global_gotno
= 0;
4269 g
->reloc_only_gotno
= 0;
4271 g
->local_gotno
= MIPS_RESERVED_GOTNO (info
);
4273 g
->assigned_gotno
= MIPS_RESERVED_GOTNO (info
);
4276 g
->tls_ldm_offset
= MINUS_ONE
;
4277 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
4278 mips_elf_got_entry_eq
, NULL
);
4279 if (g
->got_entries
== NULL
)
4281 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4282 mips_got_page_entry_eq
, NULL
);
4283 if (g
->got_page_entries
== NULL
)
4286 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
4287 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
4289 /* VxWorks also needs a .got.plt section. */
4290 if (htab
->is_vxworks
)
4292 s
= bfd_make_section_with_flags (abfd
, ".got.plt",
4293 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4294 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4295 if (s
== NULL
|| !bfd_set_section_alignment (abfd
, s
, 4))
4303 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
4304 __GOTT_INDEX__ symbols. These symbols are only special for
4305 shared objects; they are not used in executables. */
4308 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
4310 return (mips_elf_hash_table (info
)->is_vxworks
4312 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
4313 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
4316 /* Calculate the value produced by the RELOCATION (which comes from
4317 the INPUT_BFD). The ADDEND is the addend to use for this
4318 RELOCATION; RELOCATION->R_ADDEND is ignored.
4320 The result of the relocation calculation is stored in VALUEP.
4321 REQUIRE_JALXP indicates whether or not the opcode used with this
4322 relocation must be JALX.
4324 This function returns bfd_reloc_continue if the caller need take no
4325 further action regarding this relocation, bfd_reloc_notsupported if
4326 something goes dramatically wrong, bfd_reloc_overflow if an
4327 overflow occurs, and bfd_reloc_ok to indicate success. */
4329 static bfd_reloc_status_type
4330 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
4331 asection
*input_section
,
4332 struct bfd_link_info
*info
,
4333 const Elf_Internal_Rela
*relocation
,
4334 bfd_vma addend
, reloc_howto_type
*howto
,
4335 Elf_Internal_Sym
*local_syms
,
4336 asection
**local_sections
, bfd_vma
*valuep
,
4337 const char **namep
, bfd_boolean
*require_jalxp
,
4338 bfd_boolean save_addend
)
4340 /* The eventual value we will return. */
4342 /* The address of the symbol against which the relocation is
4345 /* The final GP value to be used for the relocatable, executable, or
4346 shared object file being produced. */
4348 /* The place (section offset or address) of the storage unit being
4351 /* The value of GP used to create the relocatable object. */
4353 /* The offset into the global offset table at which the address of
4354 the relocation entry symbol, adjusted by the addend, resides
4355 during execution. */
4356 bfd_vma g
= MINUS_ONE
;
4357 /* The section in which the symbol referenced by the relocation is
4359 asection
*sec
= NULL
;
4360 struct mips_elf_link_hash_entry
*h
= NULL
;
4361 /* TRUE if the symbol referred to by this relocation is a local
4363 bfd_boolean local_p
, was_local_p
;
4364 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
4365 bfd_boolean gp_disp_p
= FALSE
;
4366 /* TRUE if the symbol referred to by this relocation is
4367 "__gnu_local_gp". */
4368 bfd_boolean gnu_local_gp_p
= FALSE
;
4369 Elf_Internal_Shdr
*symtab_hdr
;
4371 unsigned long r_symndx
;
4373 /* TRUE if overflow occurred during the calculation of the
4374 relocation value. */
4375 bfd_boolean overflowed_p
;
4376 /* TRUE if this relocation refers to a MIPS16 function. */
4377 bfd_boolean target_is_16_bit_code_p
= FALSE
;
4378 struct mips_elf_link_hash_table
*htab
;
4381 dynobj
= elf_hash_table (info
)->dynobj
;
4382 htab
= mips_elf_hash_table (info
);
4384 /* Parse the relocation. */
4385 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4386 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4387 p
= (input_section
->output_section
->vma
4388 + input_section
->output_offset
4389 + relocation
->r_offset
);
4391 /* Assume that there will be no overflow. */
4392 overflowed_p
= FALSE
;
4394 /* Figure out whether or not the symbol is local, and get the offset
4395 used in the array of hash table entries. */
4396 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4397 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4398 local_sections
, FALSE
);
4399 was_local_p
= local_p
;
4400 if (! elf_bad_symtab (input_bfd
))
4401 extsymoff
= symtab_hdr
->sh_info
;
4404 /* The symbol table does not follow the rule that local symbols
4405 must come before globals. */
4409 /* Figure out the value of the symbol. */
4412 Elf_Internal_Sym
*sym
;
4414 sym
= local_syms
+ r_symndx
;
4415 sec
= local_sections
[r_symndx
];
4417 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4418 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
4419 || (sec
->flags
& SEC_MERGE
))
4420 symbol
+= sym
->st_value
;
4421 if ((sec
->flags
& SEC_MERGE
)
4422 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4424 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
4426 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
4429 /* MIPS16 text labels should be treated as odd. */
4430 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
4433 /* Record the name of this symbol, for our caller. */
4434 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
4435 symtab_hdr
->sh_link
,
4438 *namep
= bfd_section_name (input_bfd
, sec
);
4440 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
4444 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
4446 /* For global symbols we look up the symbol in the hash-table. */
4447 h
= ((struct mips_elf_link_hash_entry
*)
4448 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
4449 /* Find the real hash-table entry for this symbol. */
4450 while (h
->root
.root
.type
== bfd_link_hash_indirect
4451 || h
->root
.root
.type
== bfd_link_hash_warning
)
4452 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4454 /* Record the name of this symbol, for our caller. */
4455 *namep
= h
->root
.root
.root
.string
;
4457 /* See if this is the special _gp_disp symbol. Note that such a
4458 symbol must always be a global symbol. */
4459 if (strcmp (*namep
, "_gp_disp") == 0
4460 && ! NEWABI_P (input_bfd
))
4462 /* Relocations against _gp_disp are permitted only with
4463 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
4464 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
4465 return bfd_reloc_notsupported
;
4469 /* See if this is the special _gp symbol. Note that such a
4470 symbol must always be a global symbol. */
4471 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
4472 gnu_local_gp_p
= TRUE
;
4475 /* If this symbol is defined, calculate its address. Note that
4476 _gp_disp is a magic symbol, always implicitly defined by the
4477 linker, so it's inappropriate to check to see whether or not
4479 else if ((h
->root
.root
.type
== bfd_link_hash_defined
4480 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4481 && h
->root
.root
.u
.def
.section
)
4483 sec
= h
->root
.root
.u
.def
.section
;
4484 if (sec
->output_section
)
4485 symbol
= (h
->root
.root
.u
.def
.value
4486 + sec
->output_section
->vma
4487 + sec
->output_offset
);
4489 symbol
= h
->root
.root
.u
.def
.value
;
4491 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
4492 /* We allow relocations against undefined weak symbols, giving
4493 it the value zero, so that you can undefined weak functions
4494 and check to see if they exist by looking at their
4497 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4498 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4500 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
4501 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
4503 /* If this is a dynamic link, we should have created a
4504 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
4505 in in _bfd_mips_elf_create_dynamic_sections.
4506 Otherwise, we should define the symbol with a value of 0.
4507 FIXME: It should probably get into the symbol table
4509 BFD_ASSERT (! info
->shared
);
4510 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
4513 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
4515 /* This is an optional symbol - an Irix specific extension to the
4516 ELF spec. Ignore it for now.
4517 XXX - FIXME - there is more to the spec for OPTIONAL symbols
4518 than simply ignoring them, but we do not handle this for now.
4519 For information see the "64-bit ELF Object File Specification"
4520 which is available from here:
4521 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
4526 if (! ((*info
->callbacks
->undefined_symbol
)
4527 (info
, h
->root
.root
.root
.string
, input_bfd
,
4528 input_section
, relocation
->r_offset
,
4529 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
4530 || ELF_ST_VISIBILITY (h
->root
.other
))))
4531 return bfd_reloc_undefined
;
4535 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
4538 /* If this is a reference to a 16-bit function with a stub, we need
4539 to redirect the relocation to the stub unless:
4541 (a) the relocation is for a MIPS16 JAL;
4543 (b) the relocation is for a MIPS16 PIC call, and there are no
4544 non-MIPS16 uses of the GOT slot; or
4546 (c) the section allows direct references to MIPS16 functions. */
4547 if (r_type
!= R_MIPS16_26
4548 && !info
->relocatable
4550 && h
->fn_stub
!= NULL
4551 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
4553 && elf_tdata (input_bfd
)->local_stubs
!= NULL
4554 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
4555 && !section_allows_mips16_refs_p (input_section
))
4557 /* This is a 32- or 64-bit call to a 16-bit function. We should
4558 have already noticed that we were going to need the
4561 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
4564 BFD_ASSERT (h
->need_fn_stub
);
4568 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4569 /* The target is 16-bit, but the stub isn't. */
4570 target_is_16_bit_code_p
= FALSE
;
4572 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
4573 need to redirect the call to the stub. Note that we specifically
4574 exclude R_MIPS16_CALL16 from this behavior; indirect calls should
4575 use an indirect stub instead. */
4576 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
4577 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
4579 && elf_tdata (input_bfd
)->local_call_stubs
!= NULL
4580 && elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
4581 && !target_is_16_bit_code_p
)
4584 sec
= elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
4587 /* If both call_stub and call_fp_stub are defined, we can figure
4588 out which one to use by checking which one appears in the input
4590 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
4595 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4597 if (CALL_FP_STUB_P (bfd_get_section_name (input_bfd
, o
)))
4599 sec
= h
->call_fp_stub
;
4606 else if (h
->call_stub
!= NULL
)
4609 sec
= h
->call_fp_stub
;
4612 BFD_ASSERT (sec
->size
> 0);
4613 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4616 /* Calls from 16-bit code to 32-bit code and vice versa require the
4617 special jalx instruction. */
4618 *require_jalxp
= (!info
->relocatable
4619 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
4620 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
4622 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4623 local_sections
, TRUE
);
4625 gp0
= _bfd_get_gp_value (input_bfd
);
4626 gp
= _bfd_get_gp_value (abfd
);
4628 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
4633 /* If we haven't already determined the GOT offset, oand we're going
4634 to need it, get it now. */
4637 case R_MIPS_GOT_PAGE
:
4638 case R_MIPS_GOT_OFST
:
4639 /* We need to decay to GOT_DISP/addend if the symbol doesn't
4641 local_p
= local_p
|| _bfd_elf_symbol_refs_local_p (&h
->root
, info
, 1);
4642 if (local_p
|| r_type
== R_MIPS_GOT_OFST
)
4646 case R_MIPS16_CALL16
:
4647 case R_MIPS16_GOT16
:
4650 case R_MIPS_GOT_DISP
:
4651 case R_MIPS_GOT_HI16
:
4652 case R_MIPS_CALL_HI16
:
4653 case R_MIPS_GOT_LO16
:
4654 case R_MIPS_CALL_LO16
:
4656 case R_MIPS_TLS_GOTTPREL
:
4657 case R_MIPS_TLS_LDM
:
4658 /* Find the index into the GOT where this value is located. */
4659 if (r_type
== R_MIPS_TLS_LDM
)
4661 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
4662 0, 0, NULL
, r_type
);
4664 return bfd_reloc_outofrange
;
4668 /* On VxWorks, CALL relocations should refer to the .got.plt
4669 entry, which is initialized to point at the PLT stub. */
4670 if (htab
->is_vxworks
4671 && (r_type
== R_MIPS_CALL_HI16
4672 || r_type
== R_MIPS_CALL_LO16
4673 || call16_reloc_p (r_type
)))
4675 BFD_ASSERT (addend
== 0);
4676 BFD_ASSERT (h
->root
.needs_plt
);
4677 g
= mips_elf_gotplt_index (info
, &h
->root
);
4681 /* GOT_PAGE may take a non-zero addend, that is ignored in a
4682 GOT_PAGE relocation that decays to GOT_DISP because the
4683 symbol turns out to be global. The addend is then added
4685 BFD_ASSERT (addend
== 0 || r_type
== R_MIPS_GOT_PAGE
);
4686 g
= mips_elf_global_got_index (dynobj
, input_bfd
,
4687 &h
->root
, r_type
, info
);
4688 if (h
->tls_type
== GOT_NORMAL
4689 && (! elf_hash_table(info
)->dynamic_sections_created
4691 && (info
->symbolic
|| h
->root
.forced_local
)
4692 && h
->root
.def_regular
)))
4693 /* This is a static link or a -Bsymbolic link. The
4694 symbol is defined locally, or was forced to be local.
4695 We must initialize this entry in the GOT. */
4696 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->sgot
->contents
+ g
);
4699 else if (!htab
->is_vxworks
4700 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
4701 /* The calculation below does not involve "g". */
4705 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
4706 symbol
+ addend
, r_symndx
, h
, r_type
);
4708 return bfd_reloc_outofrange
;
4711 /* Convert GOT indices to actual offsets. */
4712 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
4716 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
4717 symbols are resolved by the loader. Add them to .rela.dyn. */
4718 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
4720 Elf_Internal_Rela outrel
;
4724 s
= mips_elf_rel_dyn_section (info
, FALSE
);
4725 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4727 outrel
.r_offset
= (input_section
->output_section
->vma
4728 + input_section
->output_offset
4729 + relocation
->r_offset
);
4730 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
4731 outrel
.r_addend
= addend
;
4732 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
4734 /* If we've written this relocation for a readonly section,
4735 we need to set DF_TEXTREL again, so that we do not delete the
4737 if (MIPS_ELF_READONLY_SECTION (input_section
))
4738 info
->flags
|= DF_TEXTREL
;
4741 return bfd_reloc_ok
;
4744 /* Figure out what kind of relocation is being performed. */
4748 return bfd_reloc_continue
;
4751 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
4752 overflowed_p
= mips_elf_overflow_p (value
, 16);
4759 || (!htab
->is_vxworks
4760 && htab
->root
.dynamic_sections_created
4762 && h
->root
.def_dynamic
4763 && !h
->root
.def_regular
))
4766 || h
->root
.root
.type
!= bfd_link_hash_undefweak
4767 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4768 && (input_section
->flags
& SEC_ALLOC
) != 0)
4770 /* If we're creating a shared library, or this relocation is
4771 against a symbol in a shared library, then we can't know
4772 where the symbol will end up. So, we create a relocation
4773 record in the output, and leave the job up to the dynamic
4776 In VxWorks executables, references to external symbols
4777 are handled using copy relocs or PLT stubs, so there's
4778 no need to add a dynamic relocation here. */
4780 if (!mips_elf_create_dynamic_relocation (abfd
,
4788 return bfd_reloc_undefined
;
4792 if (r_type
!= R_MIPS_REL32
)
4793 value
= symbol
+ addend
;
4797 value
&= howto
->dst_mask
;
4801 value
= symbol
+ addend
- p
;
4802 value
&= howto
->dst_mask
;
4806 /* The calculation for R_MIPS16_26 is just the same as for an
4807 R_MIPS_26. It's only the storage of the relocated field into
4808 the output file that's different. That's handled in
4809 mips_elf_perform_relocation. So, we just fall through to the
4810 R_MIPS_26 case here. */
4813 value
= ((addend
| ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
4816 value
= (_bfd_mips_elf_sign_extend (addend
, 28) + symbol
) >> 2;
4817 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
)
4818 overflowed_p
= (value
>> 26) != ((p
+ 4) >> 28);
4820 value
&= howto
->dst_mask
;
4823 case R_MIPS_TLS_DTPREL_HI16
:
4824 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
4828 case R_MIPS_TLS_DTPREL_LO16
:
4829 case R_MIPS_TLS_DTPREL32
:
4830 case R_MIPS_TLS_DTPREL64
:
4831 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
4834 case R_MIPS_TLS_TPREL_HI16
:
4835 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
4839 case R_MIPS_TLS_TPREL_LO16
:
4840 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
4847 value
= mips_elf_high (addend
+ symbol
);
4848 value
&= howto
->dst_mask
;
4852 /* For MIPS16 ABI code we generate this sequence
4853 0: li $v0,%hi(_gp_disp)
4854 4: addiupc $v1,%lo(_gp_disp)
4858 So the offsets of hi and lo relocs are the same, but the
4859 $pc is four higher than $t9 would be, so reduce
4860 both reloc addends by 4. */
4861 if (r_type
== R_MIPS16_HI16
)
4862 value
= mips_elf_high (addend
+ gp
- p
- 4);
4864 value
= mips_elf_high (addend
+ gp
- p
);
4865 overflowed_p
= mips_elf_overflow_p (value
, 16);
4872 value
= (symbol
+ addend
) & howto
->dst_mask
;
4875 /* See the comment for R_MIPS16_HI16 above for the reason
4876 for this conditional. */
4877 if (r_type
== R_MIPS16_LO16
)
4878 value
= addend
+ gp
- p
;
4880 value
= addend
+ gp
- p
+ 4;
4881 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
4882 for overflow. But, on, say, IRIX5, relocations against
4883 _gp_disp are normally generated from the .cpload
4884 pseudo-op. It generates code that normally looks like
4887 lui $gp,%hi(_gp_disp)
4888 addiu $gp,$gp,%lo(_gp_disp)
4891 Here $t9 holds the address of the function being called,
4892 as required by the MIPS ELF ABI. The R_MIPS_LO16
4893 relocation can easily overflow in this situation, but the
4894 R_MIPS_HI16 relocation will handle the overflow.
4895 Therefore, we consider this a bug in the MIPS ABI, and do
4896 not check for overflow here. */
4900 case R_MIPS_LITERAL
:
4901 /* Because we don't merge literal sections, we can handle this
4902 just like R_MIPS_GPREL16. In the long run, we should merge
4903 shared literals, and then we will need to additional work
4908 case R_MIPS16_GPREL
:
4909 /* The R_MIPS16_GPREL performs the same calculation as
4910 R_MIPS_GPREL16, but stores the relocated bits in a different
4911 order. We don't need to do anything special here; the
4912 differences are handled in mips_elf_perform_relocation. */
4913 case R_MIPS_GPREL16
:
4914 /* Only sign-extend the addend if it was extracted from the
4915 instruction. If the addend was separate, leave it alone,
4916 otherwise we may lose significant bits. */
4917 if (howto
->partial_inplace
)
4918 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
4919 value
= symbol
+ addend
- gp
;
4920 /* If the symbol was local, any earlier relocatable links will
4921 have adjusted its addend with the gp offset, so compensate
4922 for that now. Don't do it for symbols forced local in this
4923 link, though, since they won't have had the gp offset applied
4927 overflowed_p
= mips_elf_overflow_p (value
, 16);
4930 case R_MIPS16_GOT16
:
4931 case R_MIPS16_CALL16
:
4934 /* VxWorks does not have separate local and global semantics for
4935 R_MIPS*_GOT16; every relocation evaluates to "G". */
4936 if (!htab
->is_vxworks
&& local_p
)
4940 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
4941 local_sections
, FALSE
);
4942 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
4943 symbol
+ addend
, forced
);
4944 if (value
== MINUS_ONE
)
4945 return bfd_reloc_outofrange
;
4947 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
4948 overflowed_p
= mips_elf_overflow_p (value
, 16);
4955 case R_MIPS_TLS_GOTTPREL
:
4956 case R_MIPS_TLS_LDM
:
4957 case R_MIPS_GOT_DISP
:
4960 overflowed_p
= mips_elf_overflow_p (value
, 16);
4963 case R_MIPS_GPREL32
:
4964 value
= (addend
+ symbol
+ gp0
- gp
);
4966 value
&= howto
->dst_mask
;
4970 case R_MIPS_GNU_REL16_S2
:
4971 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
4972 overflowed_p
= mips_elf_overflow_p (value
, 18);
4973 value
>>= howto
->rightshift
;
4974 value
&= howto
->dst_mask
;
4977 case R_MIPS_GOT_HI16
:
4978 case R_MIPS_CALL_HI16
:
4979 /* We're allowed to handle these two relocations identically.
4980 The dynamic linker is allowed to handle the CALL relocations
4981 differently by creating a lazy evaluation stub. */
4983 value
= mips_elf_high (value
);
4984 value
&= howto
->dst_mask
;
4987 case R_MIPS_GOT_LO16
:
4988 case R_MIPS_CALL_LO16
:
4989 value
= g
& howto
->dst_mask
;
4992 case R_MIPS_GOT_PAGE
:
4993 /* GOT_PAGE relocations that reference non-local symbols decay
4994 to GOT_DISP. The corresponding GOT_OFST relocation decays to
4998 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
4999 if (value
== MINUS_ONE
)
5000 return bfd_reloc_outofrange
;
5001 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5002 overflowed_p
= mips_elf_overflow_p (value
, 16);
5005 case R_MIPS_GOT_OFST
:
5007 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
5010 overflowed_p
= mips_elf_overflow_p (value
, 16);
5014 value
= symbol
- addend
;
5015 value
&= howto
->dst_mask
;
5019 value
= mips_elf_higher (addend
+ symbol
);
5020 value
&= howto
->dst_mask
;
5023 case R_MIPS_HIGHEST
:
5024 value
= mips_elf_highest (addend
+ symbol
);
5025 value
&= howto
->dst_mask
;
5028 case R_MIPS_SCN_DISP
:
5029 value
= symbol
+ addend
- sec
->output_offset
;
5030 value
&= howto
->dst_mask
;
5034 /* This relocation is only a hint. In some cases, we optimize
5035 it into a bal instruction. But we don't try to optimize
5036 branches to the PLT; that will wind up wasting time. */
5037 if (h
!= NULL
&& h
->root
.plt
.offset
!= (bfd_vma
) -1)
5038 return bfd_reloc_continue
;
5039 value
= symbol
+ addend
;
5043 case R_MIPS_GNU_VTINHERIT
:
5044 case R_MIPS_GNU_VTENTRY
:
5045 /* We don't do anything with these at present. */
5046 return bfd_reloc_continue
;
5049 /* An unrecognized relocation type. */
5050 return bfd_reloc_notsupported
;
5053 /* Store the VALUE for our caller. */
5055 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
5058 /* Obtain the field relocated by RELOCATION. */
5061 mips_elf_obtain_contents (reloc_howto_type
*howto
,
5062 const Elf_Internal_Rela
*relocation
,
5063 bfd
*input_bfd
, bfd_byte
*contents
)
5066 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5068 /* Obtain the bytes. */
5069 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
5074 /* It has been determined that the result of the RELOCATION is the
5075 VALUE. Use HOWTO to place VALUE into the output file at the
5076 appropriate position. The SECTION is the section to which the
5077 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
5078 for the relocation must be either JAL or JALX, and it is
5079 unconditionally converted to JALX.
5081 Returns FALSE if anything goes wrong. */
5084 mips_elf_perform_relocation (struct bfd_link_info
*info
,
5085 reloc_howto_type
*howto
,
5086 const Elf_Internal_Rela
*relocation
,
5087 bfd_vma value
, bfd
*input_bfd
,
5088 asection
*input_section
, bfd_byte
*contents
,
5089 bfd_boolean require_jalx
)
5093 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5095 /* Figure out where the relocation is occurring. */
5096 location
= contents
+ relocation
->r_offset
;
5098 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
5100 /* Obtain the current value. */
5101 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
5103 /* Clear the field we are setting. */
5104 x
&= ~howto
->dst_mask
;
5106 /* Set the field. */
5107 x
|= (value
& howto
->dst_mask
);
5109 /* If required, turn JAL into JALX. */
5113 bfd_vma opcode
= x
>> 26;
5114 bfd_vma jalx_opcode
;
5116 /* Check to see if the opcode is already JAL or JALX. */
5117 if (r_type
== R_MIPS16_26
)
5119 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
5124 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
5128 /* If the opcode is not JAL or JALX, there's a problem. */
5131 (*_bfd_error_handler
)
5132 (_("%B: %A+0x%lx: jump to stub routine which is not jal"),
5135 (unsigned long) relocation
->r_offset
);
5136 bfd_set_error (bfd_error_bad_value
);
5140 /* Make this the JALX opcode. */
5141 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
5144 /* On the RM9000, bal is faster than jal, because bal uses branch
5145 prediction hardware. If we are linking for the RM9000, and we
5146 see jal, and bal fits, use it instead. Note that this
5147 transformation should be safe for all architectures. */
5148 if (bfd_get_mach (input_bfd
) == bfd_mach_mips9000
5149 && !info
->relocatable
5151 && ((r_type
== R_MIPS_26
&& (x
>> 26) == 0x3) /* jal addr */
5152 || (r_type
== R_MIPS_JALR
&& x
== 0x0320f809))) /* jalr t9 */
5158 addr
= (input_section
->output_section
->vma
5159 + input_section
->output_offset
5160 + relocation
->r_offset
5162 if (r_type
== R_MIPS_26
)
5163 dest
= (value
<< 2) | ((addr
>> 28) << 28);
5167 if (off
<= 0x1ffff && off
>= -0x20000)
5168 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
5171 /* Put the value into the output. */
5172 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
5174 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, !info
->relocatable
,
5180 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5181 is the original relocation, which is now being transformed into a
5182 dynamic relocation. The ADDENDP is adjusted if necessary; the
5183 caller should store the result in place of the original addend. */
5186 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
5187 struct bfd_link_info
*info
,
5188 const Elf_Internal_Rela
*rel
,
5189 struct mips_elf_link_hash_entry
*h
,
5190 asection
*sec
, bfd_vma symbol
,
5191 bfd_vma
*addendp
, asection
*input_section
)
5193 Elf_Internal_Rela outrel
[3];
5198 bfd_boolean defined_p
;
5199 struct mips_elf_link_hash_table
*htab
;
5201 htab
= mips_elf_hash_table (info
);
5202 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5203 dynobj
= elf_hash_table (info
)->dynobj
;
5204 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
5205 BFD_ASSERT (sreloc
!= NULL
);
5206 BFD_ASSERT (sreloc
->contents
!= NULL
);
5207 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
5210 outrel
[0].r_offset
=
5211 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
5212 if (ABI_64_P (output_bfd
))
5214 outrel
[1].r_offset
=
5215 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
5216 outrel
[2].r_offset
=
5217 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
5220 if (outrel
[0].r_offset
== MINUS_ONE
)
5221 /* The relocation field has been deleted. */
5224 if (outrel
[0].r_offset
== MINUS_TWO
)
5226 /* The relocation field has been converted into a relative value of
5227 some sort. Functions like _bfd_elf_write_section_eh_frame expect
5228 the field to be fully relocated, so add in the symbol's value. */
5233 /* We must now calculate the dynamic symbol table index to use
5234 in the relocation. */
5236 && (!h
->root
.def_regular
5237 || (info
->shared
&& !info
->symbolic
&& !h
->root
.forced_local
)))
5239 indx
= h
->root
.dynindx
;
5240 if (SGI_COMPAT (output_bfd
))
5241 defined_p
= h
->root
.def_regular
;
5243 /* ??? glibc's ld.so just adds the final GOT entry to the
5244 relocation field. It therefore treats relocs against
5245 defined symbols in the same way as relocs against
5246 undefined symbols. */
5251 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5253 else if (sec
== NULL
|| sec
->owner
== NULL
)
5255 bfd_set_error (bfd_error_bad_value
);
5260 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5263 asection
*osec
= htab
->root
.text_index_section
;
5264 indx
= elf_section_data (osec
)->dynindx
;
5270 /* Instead of generating a relocation using the section
5271 symbol, we may as well make it a fully relative
5272 relocation. We want to avoid generating relocations to
5273 local symbols because we used to generate them
5274 incorrectly, without adding the original symbol value,
5275 which is mandated by the ABI for section symbols. In
5276 order to give dynamic loaders and applications time to
5277 phase out the incorrect use, we refrain from emitting
5278 section-relative relocations. It's not like they're
5279 useful, after all. This should be a bit more efficient
5281 /* ??? Although this behavior is compatible with glibc's ld.so,
5282 the ABI says that relocations against STN_UNDEF should have
5283 a symbol value of 0. Irix rld honors this, so relocations
5284 against STN_UNDEF have no effect. */
5285 if (!SGI_COMPAT (output_bfd
))
5290 /* If the relocation was previously an absolute relocation and
5291 this symbol will not be referred to by the relocation, we must
5292 adjust it by the value we give it in the dynamic symbol table.
5293 Otherwise leave the job up to the dynamic linker. */
5294 if (defined_p
&& r_type
!= R_MIPS_REL32
)
5297 if (htab
->is_vxworks
)
5298 /* VxWorks uses non-relative relocations for this. */
5299 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
5301 /* The relocation is always an REL32 relocation because we don't
5302 know where the shared library will wind up at load-time. */
5303 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
5306 /* For strict adherence to the ABI specification, we should
5307 generate a R_MIPS_64 relocation record by itself before the
5308 _REL32/_64 record as well, such that the addend is read in as
5309 a 64-bit value (REL32 is a 32-bit relocation, after all).
5310 However, since none of the existing ELF64 MIPS dynamic
5311 loaders seems to care, we don't waste space with these
5312 artificial relocations. If this turns out to not be true,
5313 mips_elf_allocate_dynamic_relocation() should be tweaked so
5314 as to make room for a pair of dynamic relocations per
5315 invocation if ABI_64_P, and here we should generate an
5316 additional relocation record with R_MIPS_64 by itself for a
5317 NULL symbol before this relocation record. */
5318 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
5319 ABI_64_P (output_bfd
)
5322 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
5324 /* Adjust the output offset of the relocation to reference the
5325 correct location in the output file. */
5326 outrel
[0].r_offset
+= (input_section
->output_section
->vma
5327 + input_section
->output_offset
);
5328 outrel
[1].r_offset
+= (input_section
->output_section
->vma
5329 + input_section
->output_offset
);
5330 outrel
[2].r_offset
+= (input_section
->output_section
->vma
5331 + input_section
->output_offset
);
5333 /* Put the relocation back out. We have to use the special
5334 relocation outputter in the 64-bit case since the 64-bit
5335 relocation format is non-standard. */
5336 if (ABI_64_P (output_bfd
))
5338 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5339 (output_bfd
, &outrel
[0],
5341 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5343 else if (htab
->is_vxworks
)
5345 /* VxWorks uses RELA rather than REL dynamic relocations. */
5346 outrel
[0].r_addend
= *addendp
;
5347 bfd_elf32_swap_reloca_out
5348 (output_bfd
, &outrel
[0],
5350 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
5353 bfd_elf32_swap_reloc_out
5354 (output_bfd
, &outrel
[0],
5355 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
5357 /* We've now added another relocation. */
5358 ++sreloc
->reloc_count
;
5360 /* Make sure the output section is writable. The dynamic linker
5361 will be writing to it. */
5362 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5365 /* On IRIX5, make an entry of compact relocation info. */
5366 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
5368 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5373 Elf32_crinfo cptrel
;
5375 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5376 cptrel
.vaddr
= (rel
->r_offset
5377 + input_section
->output_section
->vma
5378 + input_section
->output_offset
);
5379 if (r_type
== R_MIPS_REL32
)
5380 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5382 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5383 mips_elf_set_cr_dist2to (cptrel
, 0);
5384 cptrel
.konst
= *addendp
;
5386 cr
= (scpt
->contents
5387 + sizeof (Elf32_External_compact_rel
));
5388 mips_elf_set_cr_relvaddr (cptrel
, 0);
5389 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5390 ((Elf32_External_crinfo
*) cr
5391 + scpt
->reloc_count
));
5392 ++scpt
->reloc_count
;
5396 /* If we've written this relocation for a readonly section,
5397 we need to set DF_TEXTREL again, so that we do not delete the
5399 if (MIPS_ELF_READONLY_SECTION (input_section
))
5400 info
->flags
|= DF_TEXTREL
;
5405 /* Return the MACH for a MIPS e_flags value. */
5408 _bfd_elf_mips_mach (flagword flags
)
5410 switch (flags
& EF_MIPS_MACH
)
5412 case E_MIPS_MACH_3900
:
5413 return bfd_mach_mips3900
;
5415 case E_MIPS_MACH_4010
:
5416 return bfd_mach_mips4010
;
5418 case E_MIPS_MACH_4100
:
5419 return bfd_mach_mips4100
;
5421 case E_MIPS_MACH_4111
:
5422 return bfd_mach_mips4111
;
5424 case E_MIPS_MACH_4120
:
5425 return bfd_mach_mips4120
;
5427 case E_MIPS_MACH_4650
:
5428 return bfd_mach_mips4650
;
5430 case E_MIPS_MACH_5400
:
5431 return bfd_mach_mips5400
;
5433 case E_MIPS_MACH_5500
:
5434 return bfd_mach_mips5500
;
5436 case E_MIPS_MACH_9000
:
5437 return bfd_mach_mips9000
;
5439 case E_MIPS_MACH_SB1
:
5440 return bfd_mach_mips_sb1
;
5442 case E_MIPS_MACH_LS2E
:
5443 return bfd_mach_mips_loongson_2e
;
5445 case E_MIPS_MACH_LS2F
:
5446 return bfd_mach_mips_loongson_2f
;
5448 case E_MIPS_MACH_OCTEON
:
5449 return bfd_mach_mips_octeon
;
5452 switch (flags
& EF_MIPS_ARCH
)
5456 return bfd_mach_mips3000
;
5459 return bfd_mach_mips6000
;
5462 return bfd_mach_mips4000
;
5465 return bfd_mach_mips8000
;
5468 return bfd_mach_mips5
;
5470 case E_MIPS_ARCH_32
:
5471 return bfd_mach_mipsisa32
;
5473 case E_MIPS_ARCH_64
:
5474 return bfd_mach_mipsisa64
;
5476 case E_MIPS_ARCH_32R2
:
5477 return bfd_mach_mipsisa32r2
;
5479 case E_MIPS_ARCH_64R2
:
5480 return bfd_mach_mipsisa64r2
;
5487 /* Return printable name for ABI. */
5489 static INLINE
char *
5490 elf_mips_abi_name (bfd
*abfd
)
5494 flags
= elf_elfheader (abfd
)->e_flags
;
5495 switch (flags
& EF_MIPS_ABI
)
5498 if (ABI_N32_P (abfd
))
5500 else if (ABI_64_P (abfd
))
5504 case E_MIPS_ABI_O32
:
5506 case E_MIPS_ABI_O64
:
5508 case E_MIPS_ABI_EABI32
:
5510 case E_MIPS_ABI_EABI64
:
5513 return "unknown abi";
5517 /* MIPS ELF uses two common sections. One is the usual one, and the
5518 other is for small objects. All the small objects are kept
5519 together, and then referenced via the gp pointer, which yields
5520 faster assembler code. This is what we use for the small common
5521 section. This approach is copied from ecoff.c. */
5522 static asection mips_elf_scom_section
;
5523 static asymbol mips_elf_scom_symbol
;
5524 static asymbol
*mips_elf_scom_symbol_ptr
;
5526 /* MIPS ELF also uses an acommon section, which represents an
5527 allocated common symbol which may be overridden by a
5528 definition in a shared library. */
5529 static asection mips_elf_acom_section
;
5530 static asymbol mips_elf_acom_symbol
;
5531 static asymbol
*mips_elf_acom_symbol_ptr
;
5533 /* This is used for both the 32-bit and the 64-bit ABI. */
5536 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
5538 elf_symbol_type
*elfsym
;
5540 /* Handle the special MIPS section numbers that a symbol may use. */
5541 elfsym
= (elf_symbol_type
*) asym
;
5542 switch (elfsym
->internal_elf_sym
.st_shndx
)
5544 case SHN_MIPS_ACOMMON
:
5545 /* This section is used in a dynamically linked executable file.
5546 It is an allocated common section. The dynamic linker can
5547 either resolve these symbols to something in a shared
5548 library, or it can just leave them here. For our purposes,
5549 we can consider these symbols to be in a new section. */
5550 if (mips_elf_acom_section
.name
== NULL
)
5552 /* Initialize the acommon section. */
5553 mips_elf_acom_section
.name
= ".acommon";
5554 mips_elf_acom_section
.flags
= SEC_ALLOC
;
5555 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
5556 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
5557 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
5558 mips_elf_acom_symbol
.name
= ".acommon";
5559 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
5560 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
5561 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
5563 asym
->section
= &mips_elf_acom_section
;
5567 /* Common symbols less than the GP size are automatically
5568 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
5569 if (asym
->value
> elf_gp_size (abfd
)
5570 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
5571 || IRIX_COMPAT (abfd
) == ict_irix6
)
5574 case SHN_MIPS_SCOMMON
:
5575 if (mips_elf_scom_section
.name
== NULL
)
5577 /* Initialize the small common section. */
5578 mips_elf_scom_section
.name
= ".scommon";
5579 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
5580 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
5581 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
5582 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
5583 mips_elf_scom_symbol
.name
= ".scommon";
5584 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
5585 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
5586 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
5588 asym
->section
= &mips_elf_scom_section
;
5589 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
5592 case SHN_MIPS_SUNDEFINED
:
5593 asym
->section
= bfd_und_section_ptr
;
5598 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
5600 BFD_ASSERT (SGI_COMPAT (abfd
));
5601 if (section
!= NULL
)
5603 asym
->section
= section
;
5604 /* MIPS_TEXT is a bit special, the address is not an offset
5605 to the base of the .text section. So substract the section
5606 base address to make it an offset. */
5607 asym
->value
-= section
->vma
;
5614 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
5616 BFD_ASSERT (SGI_COMPAT (abfd
));
5617 if (section
!= NULL
)
5619 asym
->section
= section
;
5620 /* MIPS_DATA is a bit special, the address is not an offset
5621 to the base of the .data section. So substract the section
5622 base address to make it an offset. */
5623 asym
->value
-= section
->vma
;
5629 /* If this is an odd-valued function symbol, assume it's a MIPS16 one. */
5630 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
5631 && (asym
->value
& 1) != 0)
5634 elfsym
->internal_elf_sym
.st_other
5635 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
5639 /* Implement elf_backend_eh_frame_address_size. This differs from
5640 the default in the way it handles EABI64.
5642 EABI64 was originally specified as an LP64 ABI, and that is what
5643 -mabi=eabi normally gives on a 64-bit target. However, gcc has
5644 historically accepted the combination of -mabi=eabi and -mlong32,
5645 and this ILP32 variation has become semi-official over time.
5646 Both forms use elf32 and have pointer-sized FDE addresses.
5648 If an EABI object was generated by GCC 4.0 or above, it will have
5649 an empty .gcc_compiled_longXX section, where XX is the size of longs
5650 in bits. Unfortunately, ILP32 objects generated by earlier compilers
5651 have no special marking to distinguish them from LP64 objects.
5653 We don't want users of the official LP64 ABI to be punished for the
5654 existence of the ILP32 variant, but at the same time, we don't want
5655 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
5656 We therefore take the following approach:
5658 - If ABFD contains a .gcc_compiled_longXX section, use it to
5659 determine the pointer size.
5661 - Otherwise check the type of the first relocation. Assume that
5662 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
5666 The second check is enough to detect LP64 objects generated by pre-4.0
5667 compilers because, in the kind of output generated by those compilers,
5668 the first relocation will be associated with either a CIE personality
5669 routine or an FDE start address. Furthermore, the compilers never
5670 used a special (non-pointer) encoding for this ABI.
5672 Checking the relocation type should also be safe because there is no
5673 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
5677 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
5679 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
5681 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
5683 bfd_boolean long32_p
, long64_p
;
5685 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
5686 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
5687 if (long32_p
&& long64_p
)
5694 if (sec
->reloc_count
> 0
5695 && elf_section_data (sec
)->relocs
!= NULL
5696 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
5705 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
5706 relocations against two unnamed section symbols to resolve to the
5707 same address. For example, if we have code like:
5709 lw $4,%got_disp(.data)($gp)
5710 lw $25,%got_disp(.text)($gp)
5713 then the linker will resolve both relocations to .data and the program
5714 will jump there rather than to .text.
5716 We can work around this problem by giving names to local section symbols.
5717 This is also what the MIPSpro tools do. */
5720 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
5722 return SGI_COMPAT (abfd
);
5725 /* Work over a section just before writing it out. This routine is
5726 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
5727 sections that need the SHF_MIPS_GPREL flag by name; there has to be
5731 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
5733 if (hdr
->sh_type
== SHT_MIPS_REGINFO
5734 && hdr
->sh_size
> 0)
5738 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
5739 BFD_ASSERT (hdr
->contents
== NULL
);
5742 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
5745 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5746 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5750 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
5751 && hdr
->bfd_section
!= NULL
5752 && mips_elf_section_data (hdr
->bfd_section
) != NULL
5753 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
5755 bfd_byte
*contents
, *l
, *lend
;
5757 /* We stored the section contents in the tdata field in the
5758 set_section_contents routine. We save the section contents
5759 so that we don't have to read them again.
5760 At this point we know that elf_gp is set, so we can look
5761 through the section contents to see if there is an
5762 ODK_REGINFO structure. */
5764 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
5766 lend
= contents
+ hdr
->sh_size
;
5767 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5769 Elf_Internal_Options intopt
;
5771 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5773 if (intopt
.size
< sizeof (Elf_External_Options
))
5775 (*_bfd_error_handler
)
5776 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5777 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
5780 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
5787 + sizeof (Elf_External_Options
)
5788 + (sizeof (Elf64_External_RegInfo
) - 8)),
5791 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
5792 if (bfd_bwrite (buf
, 8, abfd
) != 8)
5795 else if (intopt
.kind
== ODK_REGINFO
)
5802 + sizeof (Elf_External_Options
)
5803 + (sizeof (Elf32_External_RegInfo
) - 4)),
5806 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5807 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5814 if (hdr
->bfd_section
!= NULL
)
5816 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
5818 if (strcmp (name
, ".sdata") == 0
5819 || strcmp (name
, ".lit8") == 0
5820 || strcmp (name
, ".lit4") == 0)
5822 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5823 hdr
->sh_type
= SHT_PROGBITS
;
5825 else if (strcmp (name
, ".sbss") == 0)
5827 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5828 hdr
->sh_type
= SHT_NOBITS
;
5830 else if (strcmp (name
, ".srdata") == 0)
5832 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
5833 hdr
->sh_type
= SHT_PROGBITS
;
5835 else if (strcmp (name
, ".compact_rel") == 0)
5838 hdr
->sh_type
= SHT_PROGBITS
;
5840 else if (strcmp (name
, ".rtproc") == 0)
5842 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
5844 unsigned int adjust
;
5846 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
5848 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
5856 /* Handle a MIPS specific section when reading an object file. This
5857 is called when elfcode.h finds a section with an unknown type.
5858 This routine supports both the 32-bit and 64-bit ELF ABI.
5860 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
5864 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
5865 Elf_Internal_Shdr
*hdr
,
5871 /* There ought to be a place to keep ELF backend specific flags, but
5872 at the moment there isn't one. We just keep track of the
5873 sections by their name, instead. Fortunately, the ABI gives
5874 suggested names for all the MIPS specific sections, so we will
5875 probably get away with this. */
5876 switch (hdr
->sh_type
)
5878 case SHT_MIPS_LIBLIST
:
5879 if (strcmp (name
, ".liblist") != 0)
5883 if (strcmp (name
, ".msym") != 0)
5886 case SHT_MIPS_CONFLICT
:
5887 if (strcmp (name
, ".conflict") != 0)
5890 case SHT_MIPS_GPTAB
:
5891 if (! CONST_STRNEQ (name
, ".gptab."))
5894 case SHT_MIPS_UCODE
:
5895 if (strcmp (name
, ".ucode") != 0)
5898 case SHT_MIPS_DEBUG
:
5899 if (strcmp (name
, ".mdebug") != 0)
5901 flags
= SEC_DEBUGGING
;
5903 case SHT_MIPS_REGINFO
:
5904 if (strcmp (name
, ".reginfo") != 0
5905 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
5907 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
5909 case SHT_MIPS_IFACE
:
5910 if (strcmp (name
, ".MIPS.interfaces") != 0)
5913 case SHT_MIPS_CONTENT
:
5914 if (! CONST_STRNEQ (name
, ".MIPS.content"))
5917 case SHT_MIPS_OPTIONS
:
5918 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
5921 case SHT_MIPS_DWARF
:
5922 if (! CONST_STRNEQ (name
, ".debug_")
5923 && ! CONST_STRNEQ (name
, ".zdebug_"))
5926 case SHT_MIPS_SYMBOL_LIB
:
5927 if (strcmp (name
, ".MIPS.symlib") != 0)
5930 case SHT_MIPS_EVENTS
:
5931 if (! CONST_STRNEQ (name
, ".MIPS.events")
5932 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
5939 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
5944 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
5945 (bfd_get_section_flags (abfd
,
5951 /* FIXME: We should record sh_info for a .gptab section. */
5953 /* For a .reginfo section, set the gp value in the tdata information
5954 from the contents of this section. We need the gp value while
5955 processing relocs, so we just get it now. The .reginfo section
5956 is not used in the 64-bit MIPS ELF ABI. */
5957 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
5959 Elf32_External_RegInfo ext
;
5962 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
5963 &ext
, 0, sizeof ext
))
5965 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
5966 elf_gp (abfd
) = s
.ri_gp_value
;
5969 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
5970 set the gp value based on what we find. We may see both
5971 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
5972 they should agree. */
5973 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
5975 bfd_byte
*contents
, *l
, *lend
;
5977 contents
= bfd_malloc (hdr
->sh_size
);
5978 if (contents
== NULL
)
5980 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
5987 lend
= contents
+ hdr
->sh_size
;
5988 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5990 Elf_Internal_Options intopt
;
5992 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5994 if (intopt
.size
< sizeof (Elf_External_Options
))
5996 (*_bfd_error_handler
)
5997 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5998 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6001 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6003 Elf64_Internal_RegInfo intreg
;
6005 bfd_mips_elf64_swap_reginfo_in
6007 ((Elf64_External_RegInfo
*)
6008 (l
+ sizeof (Elf_External_Options
))),
6010 elf_gp (abfd
) = intreg
.ri_gp_value
;
6012 else if (intopt
.kind
== ODK_REGINFO
)
6014 Elf32_RegInfo intreg
;
6016 bfd_mips_elf32_swap_reginfo_in
6018 ((Elf32_External_RegInfo
*)
6019 (l
+ sizeof (Elf_External_Options
))),
6021 elf_gp (abfd
) = intreg
.ri_gp_value
;
6031 /* Set the correct type for a MIPS ELF section. We do this by the
6032 section name, which is a hack, but ought to work. This routine is
6033 used by both the 32-bit and the 64-bit ABI. */
6036 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
6038 const char *name
= bfd_get_section_name (abfd
, sec
);
6040 if (strcmp (name
, ".liblist") == 0)
6042 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
6043 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
6044 /* The sh_link field is set in final_write_processing. */
6046 else if (strcmp (name
, ".conflict") == 0)
6047 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
6048 else if (CONST_STRNEQ (name
, ".gptab."))
6050 hdr
->sh_type
= SHT_MIPS_GPTAB
;
6051 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
6052 /* The sh_info field is set in final_write_processing. */
6054 else if (strcmp (name
, ".ucode") == 0)
6055 hdr
->sh_type
= SHT_MIPS_UCODE
;
6056 else if (strcmp (name
, ".mdebug") == 0)
6058 hdr
->sh_type
= SHT_MIPS_DEBUG
;
6059 /* In a shared object on IRIX 5.3, the .mdebug section has an
6060 entsize of 0. FIXME: Does this matter? */
6061 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
6062 hdr
->sh_entsize
= 0;
6064 hdr
->sh_entsize
= 1;
6066 else if (strcmp (name
, ".reginfo") == 0)
6068 hdr
->sh_type
= SHT_MIPS_REGINFO
;
6069 /* In a shared object on IRIX 5.3, the .reginfo section has an
6070 entsize of 0x18. FIXME: Does this matter? */
6071 if (SGI_COMPAT (abfd
))
6073 if ((abfd
->flags
& DYNAMIC
) != 0)
6074 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6076 hdr
->sh_entsize
= 1;
6079 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6081 else if (SGI_COMPAT (abfd
)
6082 && (strcmp (name
, ".hash") == 0
6083 || strcmp (name
, ".dynamic") == 0
6084 || strcmp (name
, ".dynstr") == 0))
6086 if (SGI_COMPAT (abfd
))
6087 hdr
->sh_entsize
= 0;
6089 /* This isn't how the IRIX6 linker behaves. */
6090 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6093 else if (strcmp (name
, ".got") == 0
6094 || strcmp (name
, ".srdata") == 0
6095 || strcmp (name
, ".sdata") == 0
6096 || strcmp (name
, ".sbss") == 0
6097 || strcmp (name
, ".lit4") == 0
6098 || strcmp (name
, ".lit8") == 0)
6099 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
6100 else if (strcmp (name
, ".MIPS.interfaces") == 0)
6102 hdr
->sh_type
= SHT_MIPS_IFACE
;
6103 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6105 else if (CONST_STRNEQ (name
, ".MIPS.content"))
6107 hdr
->sh_type
= SHT_MIPS_CONTENT
;
6108 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6109 /* The sh_info field is set in final_write_processing. */
6111 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6113 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
6114 hdr
->sh_entsize
= 1;
6115 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6117 else if (CONST_STRNEQ (name
, ".debug_")
6118 || CONST_STRNEQ (name
, ".zdebug_"))
6120 hdr
->sh_type
= SHT_MIPS_DWARF
;
6122 /* Irix facilities such as libexc expect a single .debug_frame
6123 per executable, the system ones have NOSTRIP set and the linker
6124 doesn't merge sections with different flags so ... */
6125 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
6126 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6128 else if (strcmp (name
, ".MIPS.symlib") == 0)
6130 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
6131 /* The sh_link and sh_info fields are set in
6132 final_write_processing. */
6134 else if (CONST_STRNEQ (name
, ".MIPS.events")
6135 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
6137 hdr
->sh_type
= SHT_MIPS_EVENTS
;
6138 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6139 /* The sh_link field is set in final_write_processing. */
6141 else if (strcmp (name
, ".msym") == 0)
6143 hdr
->sh_type
= SHT_MIPS_MSYM
;
6144 hdr
->sh_flags
|= SHF_ALLOC
;
6145 hdr
->sh_entsize
= 8;
6148 /* The generic elf_fake_sections will set up REL_HDR using the default
6149 kind of relocations. We used to set up a second header for the
6150 non-default kind of relocations here, but only NewABI would use
6151 these, and the IRIX ld doesn't like resulting empty RELA sections.
6152 Thus we create those header only on demand now. */
6157 /* Given a BFD section, try to locate the corresponding ELF section
6158 index. This is used by both the 32-bit and the 64-bit ABI.
6159 Actually, it's not clear to me that the 64-bit ABI supports these,
6160 but for non-PIC objects we will certainly want support for at least
6161 the .scommon section. */
6164 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6165 asection
*sec
, int *retval
)
6167 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
6169 *retval
= SHN_MIPS_SCOMMON
;
6172 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
6174 *retval
= SHN_MIPS_ACOMMON
;
6180 /* Hook called by the linker routine which adds symbols from an object
6181 file. We must handle the special MIPS section numbers here. */
6184 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6185 Elf_Internal_Sym
*sym
, const char **namep
,
6186 flagword
*flagsp ATTRIBUTE_UNUSED
,
6187 asection
**secp
, bfd_vma
*valp
)
6189 if (SGI_COMPAT (abfd
)
6190 && (abfd
->flags
& DYNAMIC
) != 0
6191 && strcmp (*namep
, "_rld_new_interface") == 0)
6193 /* Skip IRIX5 rld entry name. */
6198 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
6199 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
6200 by setting a DT_NEEDED for the shared object. Since _gp_disp is
6201 a magic symbol resolved by the linker, we ignore this bogus definition
6202 of _gp_disp. New ABI objects do not suffer from this problem so this
6203 is not done for them. */
6205 && (sym
->st_shndx
== SHN_ABS
)
6206 && (strcmp (*namep
, "_gp_disp") == 0))
6212 switch (sym
->st_shndx
)
6215 /* Common symbols less than the GP size are automatically
6216 treated as SHN_MIPS_SCOMMON symbols. */
6217 if (sym
->st_size
> elf_gp_size (abfd
)
6218 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
6219 || IRIX_COMPAT (abfd
) == ict_irix6
)
6222 case SHN_MIPS_SCOMMON
:
6223 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
6224 (*secp
)->flags
|= SEC_IS_COMMON
;
6225 *valp
= sym
->st_size
;
6229 /* This section is used in a shared object. */
6230 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
6232 asymbol
*elf_text_symbol
;
6233 asection
*elf_text_section
;
6234 bfd_size_type amt
= sizeof (asection
);
6236 elf_text_section
= bfd_zalloc (abfd
, amt
);
6237 if (elf_text_section
== NULL
)
6240 amt
= sizeof (asymbol
);
6241 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
6242 if (elf_text_symbol
== NULL
)
6245 /* Initialize the section. */
6247 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
6248 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
6250 elf_text_section
->symbol
= elf_text_symbol
;
6251 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
6253 elf_text_section
->name
= ".text";
6254 elf_text_section
->flags
= SEC_NO_FLAGS
;
6255 elf_text_section
->output_section
= NULL
;
6256 elf_text_section
->owner
= abfd
;
6257 elf_text_symbol
->name
= ".text";
6258 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6259 elf_text_symbol
->section
= elf_text_section
;
6261 /* This code used to do *secp = bfd_und_section_ptr if
6262 info->shared. I don't know why, and that doesn't make sense,
6263 so I took it out. */
6264 *secp
= elf_tdata (abfd
)->elf_text_section
;
6267 case SHN_MIPS_ACOMMON
:
6268 /* Fall through. XXX Can we treat this as allocated data? */
6270 /* This section is used in a shared object. */
6271 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
6273 asymbol
*elf_data_symbol
;
6274 asection
*elf_data_section
;
6275 bfd_size_type amt
= sizeof (asection
);
6277 elf_data_section
= bfd_zalloc (abfd
, amt
);
6278 if (elf_data_section
== NULL
)
6281 amt
= sizeof (asymbol
);
6282 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
6283 if (elf_data_symbol
== NULL
)
6286 /* Initialize the section. */
6288 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
6289 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
6291 elf_data_section
->symbol
= elf_data_symbol
;
6292 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
6294 elf_data_section
->name
= ".data";
6295 elf_data_section
->flags
= SEC_NO_FLAGS
;
6296 elf_data_section
->output_section
= NULL
;
6297 elf_data_section
->owner
= abfd
;
6298 elf_data_symbol
->name
= ".data";
6299 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6300 elf_data_symbol
->section
= elf_data_section
;
6302 /* This code used to do *secp = bfd_und_section_ptr if
6303 info->shared. I don't know why, and that doesn't make sense,
6304 so I took it out. */
6305 *secp
= elf_tdata (abfd
)->elf_data_section
;
6308 case SHN_MIPS_SUNDEFINED
:
6309 *secp
= bfd_und_section_ptr
;
6313 if (SGI_COMPAT (abfd
)
6315 && info
->output_bfd
->xvec
== abfd
->xvec
6316 && strcmp (*namep
, "__rld_obj_head") == 0)
6318 struct elf_link_hash_entry
*h
;
6319 struct bfd_link_hash_entry
*bh
;
6321 /* Mark __rld_obj_head as dynamic. */
6323 if (! (_bfd_generic_link_add_one_symbol
6324 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
6325 get_elf_backend_data (abfd
)->collect
, &bh
)))
6328 h
= (struct elf_link_hash_entry
*) bh
;
6331 h
->type
= STT_OBJECT
;
6333 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6336 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
6339 /* If this is a mips16 text symbol, add 1 to the value to make it
6340 odd. This will cause something like .word SYM to come up with
6341 the right value when it is loaded into the PC. */
6342 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6348 /* This hook function is called before the linker writes out a global
6349 symbol. We mark symbols as small common if appropriate. This is
6350 also where we undo the increment of the value for a mips16 symbol. */
6353 _bfd_mips_elf_link_output_symbol_hook
6354 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6355 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
6356 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
6358 /* If we see a common symbol, which implies a relocatable link, then
6359 if a symbol was small common in an input file, mark it as small
6360 common in the output file. */
6361 if (sym
->st_shndx
== SHN_COMMON
6362 && strcmp (input_sec
->name
, ".scommon") == 0)
6363 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6365 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6366 sym
->st_value
&= ~1;
6371 /* Functions for the dynamic linker. */
6373 /* Create dynamic sections when linking against a dynamic object. */
6376 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6378 struct elf_link_hash_entry
*h
;
6379 struct bfd_link_hash_entry
*bh
;
6381 register asection
*s
;
6382 const char * const *namep
;
6383 struct mips_elf_link_hash_table
*htab
;
6385 htab
= mips_elf_hash_table (info
);
6386 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6387 | SEC_LINKER_CREATED
| SEC_READONLY
);
6389 /* The psABI requires a read-only .dynamic section, but the VxWorks
6391 if (!htab
->is_vxworks
)
6393 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6396 if (! bfd_set_section_flags (abfd
, s
, flags
))
6401 /* We need to create .got section. */
6402 if (!mips_elf_create_got_section (abfd
, info
))
6405 if (! mips_elf_rel_dyn_section (info
, TRUE
))
6408 /* Create .stub section. */
6409 s
= bfd_make_section_with_flags (abfd
,
6410 MIPS_ELF_STUB_SECTION_NAME (abfd
),
6413 || ! bfd_set_section_alignment (abfd
, s
,
6414 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6418 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
6420 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6422 s
= bfd_make_section_with_flags (abfd
, ".rld_map",
6423 flags
&~ (flagword
) SEC_READONLY
);
6425 || ! bfd_set_section_alignment (abfd
, s
,
6426 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6430 /* On IRIX5, we adjust add some additional symbols and change the
6431 alignments of several sections. There is no ABI documentation
6432 indicating that this is necessary on IRIX6, nor any evidence that
6433 the linker takes such action. */
6434 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6436 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6439 if (! (_bfd_generic_link_add_one_symbol
6440 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
6441 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6444 h
= (struct elf_link_hash_entry
*) bh
;
6447 h
->type
= STT_SECTION
;
6449 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6453 /* We need to create a .compact_rel section. */
6454 if (SGI_COMPAT (abfd
))
6456 if (!mips_elf_create_compact_rel_section (abfd
, info
))
6460 /* Change alignments of some sections. */
6461 s
= bfd_get_section_by_name (abfd
, ".hash");
6463 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6464 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6466 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6467 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6469 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6470 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6472 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6473 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6475 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6482 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
6484 if (!(_bfd_generic_link_add_one_symbol
6485 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
6486 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6489 h
= (struct elf_link_hash_entry
*) bh
;
6492 h
->type
= STT_SECTION
;
6494 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6497 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
6499 /* __rld_map is a four byte word located in the .data section
6500 and is filled in by the rtld to contain a pointer to
6501 the _r_debug structure. Its symbol value will be set in
6502 _bfd_mips_elf_finish_dynamic_symbol. */
6503 s
= bfd_get_section_by_name (abfd
, ".rld_map");
6504 BFD_ASSERT (s
!= NULL
);
6506 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
6508 if (!(_bfd_generic_link_add_one_symbol
6509 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
6510 get_elf_backend_data (abfd
)->collect
, &bh
)))
6513 h
= (struct elf_link_hash_entry
*) bh
;
6516 h
->type
= STT_OBJECT
;
6518 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6523 if (htab
->is_vxworks
)
6525 /* Create the .plt, .rela.plt, .dynbss and .rela.bss sections.
6526 Also create the _PROCEDURE_LINKAGE_TABLE symbol. */
6527 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
6530 /* Cache the sections created above. */
6531 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
6532 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
6533 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
6534 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
6536 || (!htab
->srelbss
&& !info
->shared
)
6541 /* Do the usual VxWorks handling. */
6542 if (!elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
6545 /* Work out the PLT sizes. */
6548 htab
->plt_header_size
6549 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
6550 htab
->plt_entry_size
6551 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
6555 htab
->plt_header_size
6556 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
6557 htab
->plt_entry_size
6558 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
6565 /* Return true if relocation REL against section SEC is a REL rather than
6566 RELA relocation. RELOCS is the first relocation in the section and
6567 ABFD is the bfd that contains SEC. */
6570 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
6571 const Elf_Internal_Rela
*relocs
,
6572 const Elf_Internal_Rela
*rel
)
6574 Elf_Internal_Shdr
*rel_hdr
;
6575 const struct elf_backend_data
*bed
;
6577 /* To determine which flavor or relocation this is, we depend on the
6578 fact that the INPUT_SECTION's REL_HDR is read before its REL_HDR2. */
6579 rel_hdr
= &elf_section_data (sec
)->rel_hdr
;
6580 bed
= get_elf_backend_data (abfd
);
6581 if ((size_t) (rel
- relocs
)
6582 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
6583 rel_hdr
= elf_section_data (sec
)->rel_hdr2
;
6584 return rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (abfd
);
6587 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
6588 HOWTO is the relocation's howto and CONTENTS points to the contents
6589 of the section that REL is against. */
6592 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
6593 reloc_howto_type
*howto
, bfd_byte
*contents
)
6596 unsigned int r_type
;
6599 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6600 location
= contents
+ rel
->r_offset
;
6602 /* Get the addend, which is stored in the input file. */
6603 _bfd_mips16_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
6604 addend
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
6605 _bfd_mips16_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
6607 return addend
& howto
->src_mask
;
6610 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
6611 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
6612 and update *ADDEND with the final addend. Return true on success
6613 or false if the LO16 could not be found. RELEND is the exclusive
6614 upper bound on the relocations for REL's section. */
6617 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
6618 const Elf_Internal_Rela
*rel
,
6619 const Elf_Internal_Rela
*relend
,
6620 bfd_byte
*contents
, bfd_vma
*addend
)
6622 unsigned int r_type
, lo16_type
;
6623 const Elf_Internal_Rela
*lo16_relocation
;
6624 reloc_howto_type
*lo16_howto
;
6627 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6628 if (mips16_reloc_p (r_type
))
6629 lo16_type
= R_MIPS16_LO16
;
6631 lo16_type
= R_MIPS_LO16
;
6633 /* The combined value is the sum of the HI16 addend, left-shifted by
6634 sixteen bits, and the LO16 addend, sign extended. (Usually, the
6635 code does a `lui' of the HI16 value, and then an `addiu' of the
6638 Scan ahead to find a matching LO16 relocation.
6640 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
6641 be immediately following. However, for the IRIX6 ABI, the next
6642 relocation may be a composed relocation consisting of several
6643 relocations for the same address. In that case, the R_MIPS_LO16
6644 relocation may occur as one of these. We permit a similar
6645 extension in general, as that is useful for GCC.
6647 In some cases GCC dead code elimination removes the LO16 but keeps
6648 the corresponding HI16. This is strictly speaking a violation of
6649 the ABI but not immediately harmful. */
6650 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
6651 if (lo16_relocation
== NULL
)
6654 /* Obtain the addend kept there. */
6655 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
6656 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
6658 l
<<= lo16_howto
->rightshift
;
6659 l
= _bfd_mips_elf_sign_extend (l
, 16);
6666 /* Try to read the contents of section SEC in bfd ABFD. Return true and
6667 store the contents in *CONTENTS on success. Assume that *CONTENTS
6668 already holds the contents if it is nonull on entry. */
6671 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
6676 /* Get cached copy if it exists. */
6677 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6679 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
6683 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
6686 /* Look through the relocs for a section during the first phase, and
6687 allocate space in the global offset table. */
6690 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6691 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6695 Elf_Internal_Shdr
*symtab_hdr
;
6696 struct elf_link_hash_entry
**sym_hashes
;
6698 const Elf_Internal_Rela
*rel
;
6699 const Elf_Internal_Rela
*rel_end
;
6701 const struct elf_backend_data
*bed
;
6702 struct mips_elf_link_hash_table
*htab
;
6705 reloc_howto_type
*howto
;
6707 if (info
->relocatable
)
6710 htab
= mips_elf_hash_table (info
);
6711 dynobj
= elf_hash_table (info
)->dynobj
;
6712 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6713 sym_hashes
= elf_sym_hashes (abfd
);
6714 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6716 bed
= get_elf_backend_data (abfd
);
6717 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6719 /* Check for the mips16 stub sections. */
6721 name
= bfd_get_section_name (abfd
, sec
);
6722 if (FN_STUB_P (name
))
6724 unsigned long r_symndx
;
6726 /* Look at the relocation information to figure out which symbol
6729 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
6732 (*_bfd_error_handler
)
6733 (_("%B: Warning: cannot determine the target function for"
6734 " stub section `%s'"),
6736 bfd_set_error (bfd_error_bad_value
);
6740 if (r_symndx
< extsymoff
6741 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6745 /* This stub is for a local symbol. This stub will only be
6746 needed if there is some relocation in this BFD, other
6747 than a 16 bit function call, which refers to this symbol. */
6748 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6750 Elf_Internal_Rela
*sec_relocs
;
6751 const Elf_Internal_Rela
*r
, *rend
;
6753 /* We can ignore stub sections when looking for relocs. */
6754 if ((o
->flags
& SEC_RELOC
) == 0
6755 || o
->reloc_count
== 0
6756 || section_allows_mips16_refs_p (o
))
6760 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
6762 if (sec_relocs
== NULL
)
6765 rend
= sec_relocs
+ o
->reloc_count
;
6766 for (r
= sec_relocs
; r
< rend
; r
++)
6767 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
6768 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
6771 if (elf_section_data (o
)->relocs
!= sec_relocs
)
6780 /* There is no non-call reloc for this stub, so we do
6781 not need it. Since this function is called before
6782 the linker maps input sections to output sections, we
6783 can easily discard it by setting the SEC_EXCLUDE
6785 sec
->flags
|= SEC_EXCLUDE
;
6789 /* Record this stub in an array of local symbol stubs for
6791 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6793 unsigned long symcount
;
6797 if (elf_bad_symtab (abfd
))
6798 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
6800 symcount
= symtab_hdr
->sh_info
;
6801 amt
= symcount
* sizeof (asection
*);
6802 n
= bfd_zalloc (abfd
, amt
);
6805 elf_tdata (abfd
)->local_stubs
= n
;
6808 sec
->flags
|= SEC_KEEP
;
6809 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6811 /* We don't need to set mips16_stubs_seen in this case.
6812 That flag is used to see whether we need to look through
6813 the global symbol table for stubs. We don't need to set
6814 it here, because we just have a local stub. */
6818 struct mips_elf_link_hash_entry
*h
;
6820 h
= ((struct mips_elf_link_hash_entry
*)
6821 sym_hashes
[r_symndx
- extsymoff
]);
6823 while (h
->root
.root
.type
== bfd_link_hash_indirect
6824 || h
->root
.root
.type
== bfd_link_hash_warning
)
6825 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
6827 /* H is the symbol this stub is for. */
6829 /* If we already have an appropriate stub for this function, we
6830 don't need another one, so we can discard this one. Since
6831 this function is called before the linker maps input sections
6832 to output sections, we can easily discard it by setting the
6833 SEC_EXCLUDE flag. */
6834 if (h
->fn_stub
!= NULL
)
6836 sec
->flags
|= SEC_EXCLUDE
;
6840 sec
->flags
|= SEC_KEEP
;
6842 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
6845 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
6847 unsigned long r_symndx
;
6848 struct mips_elf_link_hash_entry
*h
;
6851 /* Look at the relocation information to figure out which symbol
6854 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
6857 (*_bfd_error_handler
)
6858 (_("%B: Warning: cannot determine the target function for"
6859 " stub section `%s'"),
6861 bfd_set_error (bfd_error_bad_value
);
6865 if (r_symndx
< extsymoff
6866 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6870 /* This stub is for a local symbol. This stub will only be
6871 needed if there is some relocation (R_MIPS16_26) in this BFD
6872 that refers to this symbol. */
6873 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6875 Elf_Internal_Rela
*sec_relocs
;
6876 const Elf_Internal_Rela
*r
, *rend
;
6878 /* We can ignore stub sections when looking for relocs. */
6879 if ((o
->flags
& SEC_RELOC
) == 0
6880 || o
->reloc_count
== 0
6881 || section_allows_mips16_refs_p (o
))
6885 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
6887 if (sec_relocs
== NULL
)
6890 rend
= sec_relocs
+ o
->reloc_count
;
6891 for (r
= sec_relocs
; r
< rend
; r
++)
6892 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
6893 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
6896 if (elf_section_data (o
)->relocs
!= sec_relocs
)
6905 /* There is no non-call reloc for this stub, so we do
6906 not need it. Since this function is called before
6907 the linker maps input sections to output sections, we
6908 can easily discard it by setting the SEC_EXCLUDE
6910 sec
->flags
|= SEC_EXCLUDE
;
6914 /* Record this stub in an array of local symbol call_stubs for
6916 if (elf_tdata (abfd
)->local_call_stubs
== NULL
)
6918 unsigned long symcount
;
6922 if (elf_bad_symtab (abfd
))
6923 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
6925 symcount
= symtab_hdr
->sh_info
;
6926 amt
= symcount
* sizeof (asection
*);
6927 n
= bfd_zalloc (abfd
, amt
);
6930 elf_tdata (abfd
)->local_call_stubs
= n
;
6933 sec
->flags
|= SEC_KEEP
;
6934 elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
6936 /* We don't need to set mips16_stubs_seen in this case.
6937 That flag is used to see whether we need to look through
6938 the global symbol table for stubs. We don't need to set
6939 it here, because we just have a local stub. */
6943 h
= ((struct mips_elf_link_hash_entry
*)
6944 sym_hashes
[r_symndx
- extsymoff
]);
6946 /* H is the symbol this stub is for. */
6948 if (CALL_FP_STUB_P (name
))
6949 loc
= &h
->call_fp_stub
;
6951 loc
= &h
->call_stub
;
6953 /* If we already have an appropriate stub for this function, we
6954 don't need another one, so we can discard this one. Since
6955 this function is called before the linker maps input sections
6956 to output sections, we can easily discard it by setting the
6957 SEC_EXCLUDE flag. */
6960 sec
->flags
|= SEC_EXCLUDE
;
6964 sec
->flags
|= SEC_KEEP
;
6966 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
6972 for (rel
= relocs
; rel
< rel_end
; ++rel
)
6974 unsigned long r_symndx
;
6975 unsigned int r_type
;
6976 struct elf_link_hash_entry
*h
;
6978 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
6979 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6981 if (r_symndx
< extsymoff
)
6983 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
6985 (*_bfd_error_handler
)
6986 (_("%B: Malformed reloc detected for section %s"),
6988 bfd_set_error (bfd_error_bad_value
);
6993 h
= sym_hashes
[r_symndx
- extsymoff
];
6995 /* This may be an indirect symbol created because of a version. */
6998 while (h
->root
.type
== bfd_link_hash_indirect
)
6999 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7003 /* Some relocs require a global offset table. */
7004 if (dynobj
== NULL
|| htab
->sgot
== NULL
)
7008 case R_MIPS16_GOT16
:
7009 case R_MIPS16_CALL16
:
7012 case R_MIPS_CALL_HI16
:
7013 case R_MIPS_CALL_LO16
:
7014 case R_MIPS_GOT_HI16
:
7015 case R_MIPS_GOT_LO16
:
7016 case R_MIPS_GOT_PAGE
:
7017 case R_MIPS_GOT_OFST
:
7018 case R_MIPS_GOT_DISP
:
7019 case R_MIPS_TLS_GOTTPREL
:
7021 case R_MIPS_TLS_LDM
:
7023 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7024 if (!mips_elf_create_got_section (dynobj
, info
))
7026 if (htab
->is_vxworks
&& !info
->shared
)
7028 (*_bfd_error_handler
)
7029 (_("%B: GOT reloc at 0x%lx not expected in executables"),
7030 abfd
, (unsigned long) rel
->r_offset
);
7031 bfd_set_error (bfd_error_bad_value
);
7039 /* In VxWorks executables, references to external symbols
7040 are handled using copy relocs or PLT stubs, so there's
7041 no need to add a dynamic relocation here. */
7043 && (info
->shared
|| (h
!= NULL
&& !htab
->is_vxworks
))
7044 && (sec
->flags
& SEC_ALLOC
) != 0)
7045 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7055 ((struct mips_elf_link_hash_entry
*) h
)->is_relocation_target
= TRUE
;
7057 /* Relocations against the special VxWorks __GOTT_BASE__ and
7058 __GOTT_INDEX__ symbols must be left to the loader. Allocate
7059 room for them in .rela.dyn. */
7060 if (is_gott_symbol (info
, h
))
7064 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7068 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7069 if (MIPS_ELF_READONLY_SECTION (sec
))
7070 /* We tell the dynamic linker that there are
7071 relocations against the text segment. */
7072 info
->flags
|= DF_TEXTREL
;
7075 else if (r_type
== R_MIPS_CALL_LO16
7076 || r_type
== R_MIPS_GOT_LO16
7077 || r_type
== R_MIPS_GOT_DISP
7078 || (got16_reloc_p (r_type
) && htab
->is_vxworks
))
7080 /* We may need a local GOT entry for this relocation. We
7081 don't count R_MIPS_GOT_PAGE because we can estimate the
7082 maximum number of pages needed by looking at the size of
7083 the segment. Similar comments apply to R_MIPS*_GOT16 and
7084 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
7085 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
7086 R_MIPS_CALL_HI16 because these are always followed by an
7087 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
7088 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7089 rel
->r_addend
, info
, 0))
7096 case R_MIPS16_CALL16
:
7099 (*_bfd_error_handler
)
7100 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
7101 abfd
, (unsigned long) rel
->r_offset
);
7102 bfd_set_error (bfd_error_bad_value
);
7107 case R_MIPS_CALL_HI16
:
7108 case R_MIPS_CALL_LO16
:
7111 /* VxWorks call relocations point the function's .got.plt
7112 entry, which will be allocated by adjust_dynamic_symbol.
7113 Otherwise, this symbol requires a global GOT entry. */
7114 if ((!htab
->is_vxworks
|| h
->forced_local
)
7115 && !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7118 /* We need a stub, not a plt entry for the undefined
7119 function. But we record it as if it needs plt. See
7120 _bfd_elf_adjust_dynamic_symbol. */
7126 case R_MIPS_GOT_PAGE
:
7127 /* If this is a global, overridable symbol, GOT_PAGE will
7128 decay to GOT_DISP, so we'll need a GOT entry for it. */
7131 struct mips_elf_link_hash_entry
*hmips
=
7132 (struct mips_elf_link_hash_entry
*) h
;
7134 while (hmips
->root
.root
.type
== bfd_link_hash_indirect
7135 || hmips
->root
.root
.type
== bfd_link_hash_warning
)
7136 hmips
= (struct mips_elf_link_hash_entry
*)
7137 hmips
->root
.root
.u
.i
.link
;
7139 /* This symbol is definitely not overridable. */
7140 if (hmips
->root
.def_regular
7141 && ! (info
->shared
&& ! info
->symbolic
7142 && ! hmips
->root
.forced_local
))
7147 case R_MIPS16_GOT16
:
7149 case R_MIPS_GOT_HI16
:
7150 case R_MIPS_GOT_LO16
:
7151 if (!h
|| r_type
== R_MIPS_GOT_PAGE
)
7153 /* This relocation needs (or may need, if h != NULL) a
7154 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
7155 know for sure until we know whether the symbol is
7157 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
7159 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7161 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7162 addend
= mips_elf_read_rel_addend (abfd
, rel
,
7164 if (r_type
== R_MIPS_GOT16
)
7165 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
7168 addend
<<= howto
->rightshift
;
7171 addend
= rel
->r_addend
;
7172 if (!mips_elf_record_got_page_entry (info
, abfd
, r_symndx
,
7179 case R_MIPS_GOT_DISP
:
7180 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7184 case R_MIPS_TLS_GOTTPREL
:
7186 info
->flags
|= DF_STATIC_TLS
;
7189 case R_MIPS_TLS_LDM
:
7190 if (r_type
== R_MIPS_TLS_LDM
)
7198 /* This symbol requires a global offset table entry, or two
7199 for TLS GD relocations. */
7201 unsigned char flag
= (r_type
== R_MIPS_TLS_GD
7203 : r_type
== R_MIPS_TLS_LDM
7208 struct mips_elf_link_hash_entry
*hmips
=
7209 (struct mips_elf_link_hash_entry
*) h
;
7210 hmips
->tls_type
|= flag
;
7212 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
,
7218 BFD_ASSERT (flag
== GOT_TLS_LDM
|| r_symndx
!= 0);
7220 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7231 /* In VxWorks executables, references to external symbols
7232 are handled using copy relocs or PLT stubs, so there's
7233 no need to add a .rela.dyn entry for this relocation. */
7234 if ((info
->shared
|| (h
!= NULL
&& !htab
->is_vxworks
))
7235 && !(h
&& strcmp (h
->root
.root
.string
, "__gnu_local_gp") == 0)
7236 && (sec
->flags
& SEC_ALLOC
) != 0)
7240 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7244 if (info
->shared
&& h
== NULL
)
7246 /* When creating a shared object, we must copy these
7247 reloc types into the output file as R_MIPS_REL32
7248 relocs. Make room for this reloc in .rel(a).dyn. */
7249 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7250 if (MIPS_ELF_READONLY_SECTION (sec
))
7251 /* We tell the dynamic linker that there are
7252 relocations against the text segment. */
7253 info
->flags
|= DF_TEXTREL
;
7257 struct mips_elf_link_hash_entry
*hmips
;
7259 /* For a shared object, we must copy this relocation
7260 unless the symbol turns out to be undefined and
7261 weak with non-default visibility, in which case
7262 it will be left as zero.
7264 We could elide R_MIPS_REL32 for locally binding symbols
7265 in shared libraries, but do not yet do so.
7267 For an executable, we only need to copy this
7268 reloc if the symbol is defined in a dynamic
7270 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7271 ++hmips
->possibly_dynamic_relocs
;
7272 if (MIPS_ELF_READONLY_SECTION (sec
))
7273 /* We need it to tell the dynamic linker if there
7274 are relocations against the text segment. */
7275 hmips
->readonly_reloc
= TRUE
;
7279 if (SGI_COMPAT (abfd
))
7280 mips_elf_hash_table (info
)->compact_rel_size
+=
7281 sizeof (Elf32_External_crinfo
);
7286 ((struct mips_elf_link_hash_entry
*) h
)->is_branch_target
= TRUE
;
7291 ((struct mips_elf_link_hash_entry
*) h
)->is_branch_target
= TRUE
;
7294 case R_MIPS_GPREL16
:
7295 case R_MIPS_LITERAL
:
7296 case R_MIPS_GPREL32
:
7297 if (SGI_COMPAT (abfd
))
7298 mips_elf_hash_table (info
)->compact_rel_size
+=
7299 sizeof (Elf32_External_crinfo
);
7302 /* This relocation describes the C++ object vtable hierarchy.
7303 Reconstruct it for later use during GC. */
7304 case R_MIPS_GNU_VTINHERIT
:
7305 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7309 /* This relocation describes which C++ vtable entries are actually
7310 used. Record for later use during GC. */
7311 case R_MIPS_GNU_VTENTRY
:
7312 BFD_ASSERT (h
!= NULL
);
7314 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7322 /* We must not create a stub for a symbol that has relocations
7323 related to taking the function's address. This doesn't apply to
7324 VxWorks, where CALL relocs refer to a .got.plt entry instead of
7325 a normal .got entry. */
7326 if (!htab
->is_vxworks
&& h
!= NULL
)
7330 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
7332 case R_MIPS16_CALL16
:
7334 case R_MIPS_CALL_HI16
:
7335 case R_MIPS_CALL_LO16
:
7340 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
7341 if there is one. We only need to handle global symbols here;
7342 we decide whether to keep or delete stubs for local symbols
7343 when processing the stub's relocations. */
7345 && !mips16_call_reloc_p (r_type
)
7346 && !section_allows_mips16_refs_p (sec
))
7348 struct mips_elf_link_hash_entry
*mh
;
7350 mh
= (struct mips_elf_link_hash_entry
*) h
;
7351 mh
->need_fn_stub
= TRUE
;
7359 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
7360 struct bfd_link_info
*link_info
,
7363 Elf_Internal_Rela
*internal_relocs
;
7364 Elf_Internal_Rela
*irel
, *irelend
;
7365 Elf_Internal_Shdr
*symtab_hdr
;
7366 bfd_byte
*contents
= NULL
;
7368 bfd_boolean changed_contents
= FALSE
;
7369 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
7370 Elf_Internal_Sym
*isymbuf
= NULL
;
7372 /* We are not currently changing any sizes, so only one pass. */
7375 if (link_info
->relocatable
)
7378 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
7379 link_info
->keep_memory
);
7380 if (internal_relocs
== NULL
)
7383 irelend
= internal_relocs
+ sec
->reloc_count
7384 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
7385 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7386 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7388 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
7391 bfd_signed_vma sym_offset
;
7392 unsigned int r_type
;
7393 unsigned long r_symndx
;
7395 unsigned long instruction
;
7397 /* Turn jalr into bgezal, and jr into beq, if they're marked
7398 with a JALR relocation, that indicate where they jump to.
7399 This saves some pipeline bubbles. */
7400 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
7401 if (r_type
!= R_MIPS_JALR
)
7404 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
7405 /* Compute the address of the jump target. */
7406 if (r_symndx
>= extsymoff
)
7408 struct mips_elf_link_hash_entry
*h
7409 = ((struct mips_elf_link_hash_entry
*)
7410 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
7412 while (h
->root
.root
.type
== bfd_link_hash_indirect
7413 || h
->root
.root
.type
== bfd_link_hash_warning
)
7414 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7416 /* If a symbol is undefined, or if it may be overridden,
7418 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
7419 || h
->root
.root
.type
== bfd_link_hash_defweak
)
7420 && h
->root
.root
.u
.def
.section
)
7421 || (link_info
->shared
&& ! link_info
->symbolic
7422 && !h
->root
.forced_local
))
7425 sym_sec
= h
->root
.root
.u
.def
.section
;
7426 if (sym_sec
->output_section
)
7427 symval
= (h
->root
.root
.u
.def
.value
7428 + sym_sec
->output_section
->vma
7429 + sym_sec
->output_offset
);
7431 symval
= h
->root
.root
.u
.def
.value
;
7435 Elf_Internal_Sym
*isym
;
7437 /* Read this BFD's symbols if we haven't done so already. */
7438 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
7440 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7441 if (isymbuf
== NULL
)
7442 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
7443 symtab_hdr
->sh_info
, 0,
7445 if (isymbuf
== NULL
)
7449 isym
= isymbuf
+ r_symndx
;
7450 if (isym
->st_shndx
== SHN_UNDEF
)
7452 else if (isym
->st_shndx
== SHN_ABS
)
7453 sym_sec
= bfd_abs_section_ptr
;
7454 else if (isym
->st_shndx
== SHN_COMMON
)
7455 sym_sec
= bfd_com_section_ptr
;
7458 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7459 symval
= isym
->st_value
7460 + sym_sec
->output_section
->vma
7461 + sym_sec
->output_offset
;
7464 /* Compute branch offset, from delay slot of the jump to the
7466 sym_offset
= (symval
+ irel
->r_addend
)
7467 - (sec_start
+ irel
->r_offset
+ 4);
7469 /* Branch offset must be properly aligned. */
7470 if ((sym_offset
& 3) != 0)
7475 /* Check that it's in range. */
7476 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
7479 /* Get the section contents if we haven't done so already. */
7480 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7483 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
7485 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
7486 if ((instruction
& 0xfc1fffff) == 0x0000f809)
7487 instruction
= 0x04110000;
7488 /* If it was jr <reg>, turn it into b <target>. */
7489 else if ((instruction
& 0xfc1fffff) == 0x00000008)
7490 instruction
= 0x10000000;
7494 instruction
|= (sym_offset
& 0xffff);
7495 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
7496 changed_contents
= TRUE
;
7499 if (contents
!= NULL
7500 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7502 if (!changed_contents
&& !link_info
->keep_memory
)
7506 /* Cache the section contents for elf_link_input_bfd. */
7507 elf_section_data (sec
)->this_hdr
.contents
= contents
;
7513 if (contents
!= NULL
7514 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7519 /* Allocate space for global sym dynamic relocs. */
7522 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7524 struct bfd_link_info
*info
= inf
;
7526 struct mips_elf_link_hash_entry
*hmips
;
7527 struct mips_elf_link_hash_table
*htab
;
7529 htab
= mips_elf_hash_table (info
);
7530 dynobj
= elf_hash_table (info
)->dynobj
;
7531 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7533 /* VxWorks executables are handled elsewhere; we only need to
7534 allocate relocations in shared objects. */
7535 if (htab
->is_vxworks
&& !info
->shared
)
7538 /* Ignore indirect and warning symbols. All relocations against
7539 such symbols will be redirected to the target symbol. */
7540 if (h
->root
.type
== bfd_link_hash_indirect
7541 || h
->root
.type
== bfd_link_hash_warning
)
7544 /* If this symbol is defined in a dynamic object, or we are creating
7545 a shared library, we will need to copy any R_MIPS_32 or
7546 R_MIPS_REL32 relocs against it into the output file. */
7547 if (! info
->relocatable
7548 && hmips
->possibly_dynamic_relocs
!= 0
7549 && (h
->root
.type
== bfd_link_hash_defweak
7553 bfd_boolean do_copy
= TRUE
;
7555 if (h
->root
.type
== bfd_link_hash_undefweak
)
7557 /* Do not copy relocations for undefined weak symbols with
7558 non-default visibility. */
7559 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7562 /* Make sure undefined weak symbols are output as a dynamic
7564 else if (h
->dynindx
== -1 && !h
->forced_local
)
7566 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7573 /* Even though we don't directly need a GOT entry for this symbol,
7574 a symbol must have a dynamic symbol table index greater that
7575 DT_MIPS_GOTSYM if there are dynamic relocations against it. */
7576 if (hmips
->global_got_area
> GGA_RELOC_ONLY
)
7577 hmips
->global_got_area
= GGA_RELOC_ONLY
;
7579 mips_elf_allocate_dynamic_relocations
7580 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
7581 if (hmips
->readonly_reloc
)
7582 /* We tell the dynamic linker that there are relocations
7583 against the text segment. */
7584 info
->flags
|= DF_TEXTREL
;
7591 /* Adjust a symbol defined by a dynamic object and referenced by a
7592 regular object. The current definition is in some section of the
7593 dynamic object, but we're not including those sections. We have to
7594 change the definition to something the rest of the link can
7598 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7599 struct elf_link_hash_entry
*h
)
7602 struct mips_elf_link_hash_entry
*hmips
;
7603 struct mips_elf_link_hash_table
*htab
;
7605 htab
= mips_elf_hash_table (info
);
7606 dynobj
= elf_hash_table (info
)->dynobj
;
7608 /* Make sure we know what is going on here. */
7609 BFD_ASSERT (dynobj
!= NULL
7611 || h
->u
.weakdef
!= NULL
7614 && !h
->def_regular
)));
7616 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7618 /* For a function, create a stub, if allowed. */
7619 if (! hmips
->no_fn_stub
7622 if (! elf_hash_table (info
)->dynamic_sections_created
)
7625 /* If this symbol is not defined in a regular file, then set
7626 the symbol to the stub location. This is required to make
7627 function pointers compare as equal between the normal
7628 executable and the shared library. */
7629 if (!h
->def_regular
)
7631 hmips
->needs_lazy_stub
= TRUE
;
7632 htab
->lazy_stub_count
++;
7636 else if ((h
->type
== STT_FUNC
)
7639 /* This will set the entry for this symbol in the GOT to 0, and
7640 the dynamic linker will take care of this. */
7641 h
->root
.u
.def
.value
= 0;
7645 /* If this is a weak symbol, and there is a real definition, the
7646 processor independent code will have arranged for us to see the
7647 real definition first, and we can just use the same value. */
7648 if (h
->u
.weakdef
!= NULL
)
7650 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7651 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7652 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7653 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7657 /* This is a reference to a symbol defined by a dynamic object which
7658 is not a function. */
7663 /* Likewise, for VxWorks. */
7666 _bfd_mips_vxworks_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7667 struct elf_link_hash_entry
*h
)
7670 struct mips_elf_link_hash_entry
*hmips
;
7671 struct mips_elf_link_hash_table
*htab
;
7673 htab
= mips_elf_hash_table (info
);
7674 dynobj
= elf_hash_table (info
)->dynobj
;
7675 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7677 /* Make sure we know what is going on here. */
7678 BFD_ASSERT (dynobj
!= NULL
7681 || h
->u
.weakdef
!= NULL
7684 && !h
->def_regular
)));
7686 /* If the symbol is defined by a dynamic object, we need a PLT stub if
7687 either (a) we want to branch to the symbol or (b) we're linking an
7688 executable that needs a canonical function address. In the latter
7689 case, the canonical address will be the address of the executable's
7691 if ((hmips
->is_branch_target
7693 && h
->type
== STT_FUNC
7694 && hmips
->is_relocation_target
))
7698 && !h
->forced_local
)
7701 /* Locally-binding symbols do not need a PLT stub; we can refer to
7702 the functions directly. */
7703 else if (h
->needs_plt
7704 && (SYMBOL_CALLS_LOCAL (info
, h
)
7705 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
7706 && h
->root
.type
== bfd_link_hash_undefweak
)))
7714 /* If this is the first symbol to need a PLT entry, allocate room
7715 for the header, and for the header's .rela.plt.unloaded entries. */
7716 if (htab
->splt
->size
== 0)
7718 htab
->splt
->size
+= htab
->plt_header_size
;
7720 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
7723 /* Assign the next .plt entry to this symbol. */
7724 h
->plt
.offset
= htab
->splt
->size
;
7725 htab
->splt
->size
+= htab
->plt_entry_size
;
7727 /* If the output file has no definition of the symbol, set the
7728 symbol's value to the address of the stub. Point at the PLT
7729 load stub rather than the lazy resolution stub; this stub
7730 will become the canonical function address. */
7731 if (!info
->shared
&& !h
->def_regular
)
7733 h
->root
.u
.def
.section
= htab
->splt
;
7734 h
->root
.u
.def
.value
= h
->plt
.offset
;
7735 h
->root
.u
.def
.value
+= 8;
7738 /* Make room for the .got.plt entry and the R_JUMP_SLOT relocation. */
7739 htab
->sgotplt
->size
+= 4;
7740 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
7742 /* Make room for the .rela.plt.unloaded relocations. */
7744 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
7749 /* If a function symbol is defined by a dynamic object, and we do not
7750 need a PLT stub for it, the symbol's value should be zero. */
7751 if (h
->type
== STT_FUNC
7756 h
->root
.u
.def
.value
= 0;
7760 /* If this is a weak symbol, and there is a real definition, the
7761 processor independent code will have arranged for us to see the
7762 real definition first, and we can just use the same value. */
7763 if (h
->u
.weakdef
!= NULL
)
7765 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7766 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7767 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7768 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7772 /* This is a reference to a symbol defined by a dynamic object which
7773 is not a function. */
7777 /* We must allocate the symbol in our .dynbss section, which will
7778 become part of the .bss section of the executable. There will be
7779 an entry for this symbol in the .dynsym section. The dynamic
7780 object will contain position independent code, so all references
7781 from the dynamic object to this symbol will go through the global
7782 offset table. The dynamic linker will use the .dynsym entry to
7783 determine the address it must put in the global offset table, so
7784 both the dynamic object and the regular object will refer to the
7785 same memory location for the variable. */
7787 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
7789 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
7793 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
7796 /* This function is called after all the input files have been read,
7797 and the input sections have been assigned to output sections. We
7798 check for any mips16 stub sections that we can discard. */
7801 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
7802 struct bfd_link_info
*info
)
7805 struct mips_elf_link_hash_table
*htab
;
7807 htab
= mips_elf_hash_table (info
);
7809 /* The .reginfo section has a fixed size. */
7810 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
7812 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
7814 if (! (info
->relocatable
7815 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
))
7816 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7817 mips_elf_check_mips16_stubs
, info
);
7822 /* If the link uses a GOT, lay it out and work out its size. */
7825 mips_elf_lay_out_got (bfd
*output_bfd
, struct bfd_link_info
*info
)
7829 struct mips_got_info
*g
;
7830 bfd_size_type loadable_size
= 0;
7831 bfd_size_type page_gotno
;
7833 struct mips_elf_count_tls_arg count_tls_arg
;
7834 struct mips_elf_link_hash_table
*htab
;
7836 htab
= mips_elf_hash_table (info
);
7841 dynobj
= elf_hash_table (info
)->dynobj
;
7844 /* Replace entries for indirect and warning symbols with entries for
7845 the target symbol. */
7846 if (!mips_elf_resolve_final_got_entries (g
))
7849 /* Count the number of GOT symbols. */
7850 mips_elf_link_hash_traverse (htab
, mips_elf_count_got_symbols
, g
);
7852 /* Calculate the total loadable size of the output. That
7853 will give us the maximum number of GOT_PAGE entries
7855 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
7857 asection
*subsection
;
7859 for (subsection
= sub
->sections
;
7861 subsection
= subsection
->next
)
7863 if ((subsection
->flags
& SEC_ALLOC
) == 0)
7865 loadable_size
+= ((subsection
->size
+ 0xf)
7866 &~ (bfd_size_type
) 0xf);
7870 if (htab
->is_vxworks
)
7871 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
7872 relocations against local symbols evaluate to "G", and the EABI does
7873 not include R_MIPS_GOT_PAGE. */
7876 /* Assume there are two loadable segments consisting of contiguous
7877 sections. Is 5 enough? */
7878 page_gotno
= (loadable_size
>> 16) + 5;
7880 /* Choose the smaller of the two estimates; both are intended to be
7882 if (page_gotno
> g
->page_gotno
)
7883 page_gotno
= g
->page_gotno
;
7885 g
->local_gotno
+= page_gotno
;
7886 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7887 s
->size
+= g
->global_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7889 /* We need to calculate tls_gotno for global symbols at this point
7890 instead of building it up earlier, to avoid doublecounting
7891 entries for one global symbol from multiple input files. */
7892 count_tls_arg
.info
= info
;
7893 count_tls_arg
.needed
= 0;
7894 elf_link_hash_traverse (elf_hash_table (info
),
7895 mips_elf_count_global_tls_entries
,
7897 g
->tls_gotno
+= count_tls_arg
.needed
;
7898 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7900 /* VxWorks does not support multiple GOTs. It initializes $gp to
7901 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
7903 if (htab
->is_vxworks
)
7905 /* VxWorks executables do not need a GOT. */
7908 /* Each VxWorks GOT entry needs an explicit relocation. */
7911 count
= g
->global_gotno
+ g
->local_gotno
- MIPS_RESERVED_GOTNO (info
);
7913 mips_elf_allocate_dynamic_relocations (dynobj
, info
, count
);
7916 else if (s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
7918 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
7923 struct mips_elf_count_tls_arg arg
;
7925 /* Set up TLS entries. */
7926 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
7927 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
7929 /* Allocate room for the TLS relocations. */
7932 htab_traverse (g
->got_entries
, mips_elf_count_local_tls_relocs
, &arg
);
7933 elf_link_hash_traverse (elf_hash_table (info
),
7934 mips_elf_count_global_tls_relocs
,
7937 mips_elf_allocate_dynamic_relocations (dynobj
, info
, arg
.needed
);
7943 /* Estimate the size of the .MIPS.stubs section. */
7946 mips_elf_estimate_stub_size (bfd
*output_bfd
, struct bfd_link_info
*info
)
7948 struct mips_elf_link_hash_table
*htab
;
7949 bfd_size_type dynsymcount
;
7951 htab
= mips_elf_hash_table (info
);
7952 if (htab
->lazy_stub_count
== 0)
7955 /* IRIX rld assumes that a function stub isn't at the end of the .text
7956 section, so add a dummy entry to the end. */
7957 htab
->lazy_stub_count
++;
7959 /* Get a worst-case estimate of the number of dynamic symbols needed.
7960 At this point, dynsymcount does not account for section symbols
7961 and count_section_dynsyms may overestimate the number that will
7963 dynsymcount
= (elf_hash_table (info
)->dynsymcount
7964 + count_section_dynsyms (output_bfd
, info
));
7966 /* Determine the size of one stub entry. */
7967 htab
->function_stub_size
= (dynsymcount
> 0x10000
7968 ? MIPS_FUNCTION_STUB_BIG_SIZE
7969 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
7971 htab
->sstubs
->size
= htab
->lazy_stub_count
* htab
->function_stub_size
;
7974 /* A mips_elf_link_hash_traverse callback for which DATA points to the
7975 MIPS hash table. If H needs a traditional MIPS lazy-binding stub,
7976 allocate an entry in the stubs section. */
7979 mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry
*h
, void **data
)
7981 struct mips_elf_link_hash_table
*htab
;
7983 htab
= (struct mips_elf_link_hash_table
*) data
;
7984 if (h
->needs_lazy_stub
)
7986 h
->root
.root
.u
.def
.section
= htab
->sstubs
;
7987 h
->root
.root
.u
.def
.value
= htab
->sstubs
->size
;
7988 h
->root
.plt
.offset
= htab
->sstubs
->size
;
7989 htab
->sstubs
->size
+= htab
->function_stub_size
;
7994 /* Allocate offsets in the stubs section to each symbol that needs one.
7995 Set the final size of the .MIPS.stub section. */
7998 mips_elf_lay_out_lazy_stubs (struct bfd_link_info
*info
)
8000 struct mips_elf_link_hash_table
*htab
;
8002 htab
= mips_elf_hash_table (info
);
8003 if (htab
->lazy_stub_count
== 0)
8006 htab
->sstubs
->size
= 0;
8007 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8008 mips_elf_allocate_lazy_stub
, htab
);
8009 htab
->sstubs
->size
+= htab
->function_stub_size
;
8010 BFD_ASSERT (htab
->sstubs
->size
8011 == htab
->lazy_stub_count
* htab
->function_stub_size
);
8014 /* Set the sizes of the dynamic sections. */
8017 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
8018 struct bfd_link_info
*info
)
8022 bfd_boolean reltext
;
8023 struct mips_elf_link_hash_table
*htab
;
8025 htab
= mips_elf_hash_table (info
);
8026 dynobj
= elf_hash_table (info
)->dynobj
;
8027 BFD_ASSERT (dynobj
!= NULL
);
8029 if (elf_hash_table (info
)->dynamic_sections_created
)
8031 /* Set the contents of the .interp section to the interpreter. */
8032 if (info
->executable
)
8034 s
= bfd_get_section_by_name (dynobj
, ".interp");
8035 BFD_ASSERT (s
!= NULL
);
8037 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8039 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8043 /* Allocate space for global sym dynamic relocs. */
8044 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
8046 mips_elf_estimate_stub_size (output_bfd
, info
);
8048 if (!mips_elf_lay_out_got (output_bfd
, info
))
8051 mips_elf_lay_out_lazy_stubs (info
);
8053 /* The check_relocs and adjust_dynamic_symbol entry points have
8054 determined the sizes of the various dynamic sections. Allocate
8057 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8061 /* It's OK to base decisions on the section name, because none
8062 of the dynobj section names depend upon the input files. */
8063 name
= bfd_get_section_name (dynobj
, s
);
8065 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8068 if (CONST_STRNEQ (name
, ".rel"))
8072 const char *outname
;
8075 /* If this relocation section applies to a read only
8076 section, then we probably need a DT_TEXTREL entry.
8077 If the relocation section is .rel(a).dyn, we always
8078 assert a DT_TEXTREL entry rather than testing whether
8079 there exists a relocation to a read only section or
8081 outname
= bfd_get_section_name (output_bfd
,
8083 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8085 && (target
->flags
& SEC_READONLY
) != 0
8086 && (target
->flags
& SEC_ALLOC
) != 0)
8087 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
8090 /* We use the reloc_count field as a counter if we need
8091 to copy relocs into the output file. */
8092 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
8095 /* If combreloc is enabled, elf_link_sort_relocs() will
8096 sort relocations, but in a different way than we do,
8097 and before we're done creating relocations. Also, it
8098 will move them around between input sections'
8099 relocation's contents, so our sorting would be
8100 broken, so don't let it run. */
8101 info
->combreloc
= 0;
8104 else if (! info
->shared
8105 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8106 && CONST_STRNEQ (name
, ".rld_map"))
8108 /* We add a room for __rld_map. It will be filled in by the
8109 rtld to contain a pointer to the _r_debug structure. */
8112 else if (SGI_COMPAT (output_bfd
)
8113 && CONST_STRNEQ (name
, ".compact_rel"))
8114 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8115 else if (! CONST_STRNEQ (name
, ".init")
8117 && s
!= htab
->sgotplt
8119 && s
!= htab
->sstubs
)
8121 /* It's not one of our sections, so don't allocate space. */
8127 s
->flags
|= SEC_EXCLUDE
;
8131 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8134 /* Allocate memory for the section contents. */
8135 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
8136 if (s
->contents
== NULL
)
8138 bfd_set_error (bfd_error_no_memory
);
8143 if (elf_hash_table (info
)->dynamic_sections_created
)
8145 /* Add some entries to the .dynamic section. We fill in the
8146 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
8147 must add the entries now so that we get the correct size for
8148 the .dynamic section. */
8150 /* SGI object has the equivalence of DT_DEBUG in the
8151 DT_MIPS_RLD_MAP entry. This must come first because glibc
8152 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and GDB only
8153 looks at the first one it sees. */
8155 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8158 /* The DT_DEBUG entry may be filled in by the dynamic linker and
8159 used by the debugger. */
8160 if (info
->executable
8161 && !SGI_COMPAT (output_bfd
)
8162 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8165 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
8166 info
->flags
|= DF_TEXTREL
;
8168 if ((info
->flags
& DF_TEXTREL
) != 0)
8170 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8173 /* Clear the DF_TEXTREL flag. It will be set again if we
8174 write out an actual text relocation; we may not, because
8175 at this point we do not know whether e.g. any .eh_frame
8176 absolute relocations have been converted to PC-relative. */
8177 info
->flags
&= ~DF_TEXTREL
;
8180 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8183 if (htab
->is_vxworks
)
8185 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
8186 use any of the DT_MIPS_* tags. */
8187 if (mips_elf_rel_dyn_section (info
, FALSE
))
8189 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
8192 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
8195 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
8198 if (htab
->splt
->size
> 0)
8200 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
8203 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
8206 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
8212 if (mips_elf_rel_dyn_section (info
, FALSE
))
8214 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8217 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8220 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8224 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8227 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8230 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8233 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8236 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8239 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8242 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8245 if (IRIX_COMPAT (dynobj
) == ict_irix5
8246 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8249 if (IRIX_COMPAT (dynobj
) == ict_irix6
8250 && (bfd_get_section_by_name
8251 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8252 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8255 if (htab
->is_vxworks
8256 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
8263 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
8264 Adjust its R_ADDEND field so that it is correct for the output file.
8265 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
8266 and sections respectively; both use symbol indexes. */
8269 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
8270 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
8271 asection
**local_sections
, Elf_Internal_Rela
*rel
)
8273 unsigned int r_type
, r_symndx
;
8274 Elf_Internal_Sym
*sym
;
8277 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8279 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8280 if (r_type
== R_MIPS16_GPREL
8281 || r_type
== R_MIPS_GPREL16
8282 || r_type
== R_MIPS_GPREL32
8283 || r_type
== R_MIPS_LITERAL
)
8285 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
8286 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
8289 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
8290 sym
= local_syms
+ r_symndx
;
8292 /* Adjust REL's addend to account for section merging. */
8293 if (!info
->relocatable
)
8295 sec
= local_sections
[r_symndx
];
8296 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
8299 /* This would normally be done by the rela_normal code in elflink.c. */
8300 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8301 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
8305 /* Relocate a MIPS ELF section. */
8308 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
8309 bfd
*input_bfd
, asection
*input_section
,
8310 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
8311 Elf_Internal_Sym
*local_syms
,
8312 asection
**local_sections
)
8314 Elf_Internal_Rela
*rel
;
8315 const Elf_Internal_Rela
*relend
;
8317 bfd_boolean use_saved_addend_p
= FALSE
;
8318 const struct elf_backend_data
*bed
;
8320 bed
= get_elf_backend_data (output_bfd
);
8321 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8322 for (rel
= relocs
; rel
< relend
; ++rel
)
8326 reloc_howto_type
*howto
;
8327 bfd_boolean require_jalx
;
8328 /* TRUE if the relocation is a RELA relocation, rather than a
8330 bfd_boolean rela_relocation_p
= TRUE
;
8331 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8333 unsigned long r_symndx
;
8335 Elf_Internal_Shdr
*symtab_hdr
;
8336 struct elf_link_hash_entry
*h
;
8338 /* Find the relocation howto for this relocation. */
8339 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
8340 NEWABI_P (input_bfd
)
8341 && (MIPS_RELOC_RELA_P
8342 (input_bfd
, input_section
,
8345 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
8346 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
8347 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8349 sec
= local_sections
[r_symndx
];
8354 unsigned long extsymoff
;
8357 if (!elf_bad_symtab (input_bfd
))
8358 extsymoff
= symtab_hdr
->sh_info
;
8359 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
8360 while (h
->root
.type
== bfd_link_hash_indirect
8361 || h
->root
.type
== bfd_link_hash_warning
)
8362 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8365 if (h
->root
.type
== bfd_link_hash_defined
8366 || h
->root
.type
== bfd_link_hash_defweak
)
8367 sec
= h
->root
.u
.def
.section
;
8370 if (sec
!= NULL
&& elf_discarded_section (sec
))
8372 /* For relocs against symbols from removed linkonce sections,
8373 or sections discarded by a linker script, we just want the
8374 section contents zeroed. Avoid any special processing. */
8375 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
8381 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
8383 /* Some 32-bit code uses R_MIPS_64. In particular, people use
8384 64-bit code, but make sure all their addresses are in the
8385 lowermost or uppermost 32-bit section of the 64-bit address
8386 space. Thus, when they use an R_MIPS_64 they mean what is
8387 usually meant by R_MIPS_32, with the exception that the
8388 stored value is sign-extended to 64 bits. */
8389 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
8391 /* On big-endian systems, we need to lie about the position
8393 if (bfd_big_endian (input_bfd
))
8397 if (!use_saved_addend_p
)
8399 /* If these relocations were originally of the REL variety,
8400 we must pull the addend out of the field that will be
8401 relocated. Otherwise, we simply use the contents of the
8403 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
8406 rela_relocation_p
= FALSE
;
8407 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
8409 if (hi16_reloc_p (r_type
)
8410 || (got16_reloc_p (r_type
)
8411 && mips_elf_local_relocation_p (input_bfd
, rel
,
8412 local_sections
, FALSE
)))
8414 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
8420 name
= h
->root
.root
.string
;
8422 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
8423 local_syms
+ r_symndx
,
8425 (*_bfd_error_handler
)
8426 (_("%B: Can't find matching LO16 reloc against `%s' for %s at 0x%lx in section `%A'"),
8427 input_bfd
, input_section
, name
, howto
->name
,
8432 addend
<<= howto
->rightshift
;
8435 addend
= rel
->r_addend
;
8436 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
8437 local_syms
, local_sections
, rel
);
8440 if (info
->relocatable
)
8442 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
8443 && bfd_big_endian (input_bfd
))
8446 if (!rela_relocation_p
&& rel
->r_addend
)
8448 addend
+= rel
->r_addend
;
8449 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
8450 addend
= mips_elf_high (addend
);
8451 else if (r_type
== R_MIPS_HIGHER
)
8452 addend
= mips_elf_higher (addend
);
8453 else if (r_type
== R_MIPS_HIGHEST
)
8454 addend
= mips_elf_highest (addend
);
8456 addend
>>= howto
->rightshift
;
8458 /* We use the source mask, rather than the destination
8459 mask because the place to which we are writing will be
8460 source of the addend in the final link. */
8461 addend
&= howto
->src_mask
;
8463 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
8464 /* See the comment above about using R_MIPS_64 in the 32-bit
8465 ABI. Here, we need to update the addend. It would be
8466 possible to get away with just using the R_MIPS_32 reloc
8467 but for endianness. */
8473 if (addend
& ((bfd_vma
) 1 << 31))
8475 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
8482 /* If we don't know that we have a 64-bit type,
8483 do two separate stores. */
8484 if (bfd_big_endian (input_bfd
))
8486 /* Store the sign-bits (which are most significant)
8488 low_bits
= sign_bits
;
8494 high_bits
= sign_bits
;
8496 bfd_put_32 (input_bfd
, low_bits
,
8497 contents
+ rel
->r_offset
);
8498 bfd_put_32 (input_bfd
, high_bits
,
8499 contents
+ rel
->r_offset
+ 4);
8503 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
8504 input_bfd
, input_section
,
8509 /* Go on to the next relocation. */
8513 /* In the N32 and 64-bit ABIs there may be multiple consecutive
8514 relocations for the same offset. In that case we are
8515 supposed to treat the output of each relocation as the addend
8517 if (rel
+ 1 < relend
8518 && rel
->r_offset
== rel
[1].r_offset
8519 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
8520 use_saved_addend_p
= TRUE
;
8522 use_saved_addend_p
= FALSE
;
8524 /* Figure out what value we are supposed to relocate. */
8525 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
8526 input_section
, info
, rel
,
8527 addend
, howto
, local_syms
,
8528 local_sections
, &value
,
8529 &name
, &require_jalx
,
8530 use_saved_addend_p
))
8532 case bfd_reloc_continue
:
8533 /* There's nothing to do. */
8536 case bfd_reloc_undefined
:
8537 /* mips_elf_calculate_relocation already called the
8538 undefined_symbol callback. There's no real point in
8539 trying to perform the relocation at this point, so we
8540 just skip ahead to the next relocation. */
8543 case bfd_reloc_notsupported
:
8544 msg
= _("internal error: unsupported relocation error");
8545 info
->callbacks
->warning
8546 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
8549 case bfd_reloc_overflow
:
8550 if (use_saved_addend_p
)
8551 /* Ignore overflow until we reach the last relocation for
8552 a given location. */
8556 struct mips_elf_link_hash_table
*htab
;
8558 htab
= mips_elf_hash_table (info
);
8559 BFD_ASSERT (name
!= NULL
);
8560 if (!htab
->small_data_overflow_reported
8561 && (howto
->type
== R_MIPS_GPREL16
8562 || howto
->type
== R_MIPS_LITERAL
))
8565 _("small-data section exceeds 64KB;"
8566 " lower small-data size limit (see option -G)");
8568 htab
->small_data_overflow_reported
= TRUE
;
8569 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
8571 if (! ((*info
->callbacks
->reloc_overflow
)
8572 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
8573 input_bfd
, input_section
, rel
->r_offset
)))
8586 /* If we've got another relocation for the address, keep going
8587 until we reach the last one. */
8588 if (use_saved_addend_p
)
8594 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
8595 /* See the comment above about using R_MIPS_64 in the 32-bit
8596 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
8597 that calculated the right value. Now, however, we
8598 sign-extend the 32-bit result to 64-bits, and store it as a
8599 64-bit value. We are especially generous here in that we
8600 go to extreme lengths to support this usage on systems with
8601 only a 32-bit VMA. */
8607 if (value
& ((bfd_vma
) 1 << 31))
8609 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
8616 /* If we don't know that we have a 64-bit type,
8617 do two separate stores. */
8618 if (bfd_big_endian (input_bfd
))
8620 /* Undo what we did above. */
8622 /* Store the sign-bits (which are most significant)
8624 low_bits
= sign_bits
;
8630 high_bits
= sign_bits
;
8632 bfd_put_32 (input_bfd
, low_bits
,
8633 contents
+ rel
->r_offset
);
8634 bfd_put_32 (input_bfd
, high_bits
,
8635 contents
+ rel
->r_offset
+ 4);
8639 /* Actually perform the relocation. */
8640 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
8641 input_bfd
, input_section
,
8642 contents
, require_jalx
))
8649 /* If NAME is one of the special IRIX6 symbols defined by the linker,
8650 adjust it appropriately now. */
8653 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
8654 const char *name
, Elf_Internal_Sym
*sym
)
8656 /* The linker script takes care of providing names and values for
8657 these, but we must place them into the right sections. */
8658 static const char* const text_section_symbols
[] = {
8661 "__dso_displacement",
8663 "__program_header_table",
8667 static const char* const data_section_symbols
[] = {
8675 const char* const *p
;
8678 for (i
= 0; i
< 2; ++i
)
8679 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
8682 if (strcmp (*p
, name
) == 0)
8684 /* All of these symbols are given type STT_SECTION by the
8686 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8687 sym
->st_other
= STO_PROTECTED
;
8689 /* The IRIX linker puts these symbols in special sections. */
8691 sym
->st_shndx
= SHN_MIPS_TEXT
;
8693 sym
->st_shndx
= SHN_MIPS_DATA
;
8699 /* Finish up dynamic symbol handling. We set the contents of various
8700 dynamic sections here. */
8703 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
8704 struct bfd_link_info
*info
,
8705 struct elf_link_hash_entry
*h
,
8706 Elf_Internal_Sym
*sym
)
8710 struct mips_got_info
*g
, *gg
;
8713 struct mips_elf_link_hash_table
*htab
;
8714 struct mips_elf_link_hash_entry
*hmips
;
8716 htab
= mips_elf_hash_table (info
);
8717 dynobj
= elf_hash_table (info
)->dynobj
;
8718 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8720 if (h
->plt
.offset
!= MINUS_ONE
)
8722 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
8724 /* This symbol has a stub. Set it up. */
8726 BFD_ASSERT (h
->dynindx
!= -1);
8728 BFD_ASSERT ((htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8729 || (h
->dynindx
<= 0xffff));
8731 /* Values up to 2^31 - 1 are allowed. Larger values would cause
8732 sign extension at runtime in the stub, resulting in a negative
8734 if (h
->dynindx
& ~0x7fffffff)
8737 /* Fill the stub. */
8739 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
8741 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ idx
);
8743 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8745 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
8749 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
8752 /* If a large stub is not required and sign extension is not a
8753 problem, then use legacy code in the stub. */
8754 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8755 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff), stub
+ idx
);
8756 else if (h
->dynindx
& ~0x7fff)
8757 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff), stub
+ idx
);
8759 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
8762 BFD_ASSERT (h
->plt
.offset
<= htab
->sstubs
->size
);
8763 memcpy (htab
->sstubs
->contents
+ h
->plt
.offset
,
8764 stub
, htab
->function_stub_size
);
8766 /* Mark the symbol as undefined. plt.offset != -1 occurs
8767 only for the referenced symbol. */
8768 sym
->st_shndx
= SHN_UNDEF
;
8770 /* The run-time linker uses the st_value field of the symbol
8771 to reset the global offset table entry for this external
8772 to its stub address when unlinking a shared object. */
8773 sym
->st_value
= (htab
->sstubs
->output_section
->vma
8774 + htab
->sstubs
->output_offset
8778 /* If we have a MIPS16 function with a stub, the dynamic symbol must
8779 refer to the stub, since only the stub uses the standard calling
8781 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
8783 BFD_ASSERT (hmips
->need_fn_stub
);
8784 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
8785 + hmips
->fn_stub
->output_offset
);
8786 sym
->st_size
= hmips
->fn_stub
->size
;
8787 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
8790 BFD_ASSERT (h
->dynindx
!= -1
8791 || h
->forced_local
);
8795 BFD_ASSERT (g
!= NULL
);
8797 /* Run through the global symbol table, creating GOT entries for all
8798 the symbols that need them. */
8799 if (g
->global_gotsym
!= NULL
8800 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
8805 value
= sym
->st_value
;
8806 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
8807 R_MIPS_GOT16
, info
);
8808 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
8811 if (g
->next
&& h
->dynindx
!= -1 && h
->type
!= STT_TLS
)
8813 struct mips_got_entry e
, *p
;
8819 e
.abfd
= output_bfd
;
8824 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
8827 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
8832 || (elf_hash_table (info
)->dynamic_sections_created
8834 && p
->d
.h
->root
.def_dynamic
8835 && !p
->d
.h
->root
.def_regular
))
8837 /* Create an R_MIPS_REL32 relocation for this entry. Due to
8838 the various compatibility problems, it's easier to mock
8839 up an R_MIPS_32 or R_MIPS_64 relocation and leave
8840 mips_elf_create_dynamic_relocation to calculate the
8841 appropriate addend. */
8842 Elf_Internal_Rela rel
[3];
8844 memset (rel
, 0, sizeof (rel
));
8845 if (ABI_64_P (output_bfd
))
8846 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
8848 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
8849 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
8852 if (! (mips_elf_create_dynamic_relocation
8853 (output_bfd
, info
, rel
,
8854 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
8858 entry
= sym
->st_value
;
8859 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
8864 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
8865 name
= h
->root
.root
.string
;
8866 if (strcmp (name
, "_DYNAMIC") == 0
8867 || h
== elf_hash_table (info
)->hgot
)
8868 sym
->st_shndx
= SHN_ABS
;
8869 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
8870 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
8872 sym
->st_shndx
= SHN_ABS
;
8873 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8876 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
8878 sym
->st_shndx
= SHN_ABS
;
8879 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8880 sym
->st_value
= elf_gp (output_bfd
);
8882 else if (SGI_COMPAT (output_bfd
))
8884 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
8885 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
8887 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8888 sym
->st_other
= STO_PROTECTED
;
8890 sym
->st_shndx
= SHN_MIPS_DATA
;
8892 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
8894 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8895 sym
->st_other
= STO_PROTECTED
;
8896 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
8897 sym
->st_shndx
= SHN_ABS
;
8899 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
8901 if (h
->type
== STT_FUNC
)
8902 sym
->st_shndx
= SHN_MIPS_TEXT
;
8903 else if (h
->type
== STT_OBJECT
)
8904 sym
->st_shndx
= SHN_MIPS_DATA
;
8908 /* Handle the IRIX6-specific symbols. */
8909 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8910 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
8914 if (! mips_elf_hash_table (info
)->use_rld_obj_head
8915 && (strcmp (name
, "__rld_map") == 0
8916 || strcmp (name
, "__RLD_MAP") == 0))
8918 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
8919 BFD_ASSERT (s
!= NULL
);
8920 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
8921 bfd_put_32 (output_bfd
, 0, s
->contents
);
8922 if (mips_elf_hash_table (info
)->rld_value
== 0)
8923 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8925 else if (mips_elf_hash_table (info
)->use_rld_obj_head
8926 && strcmp (name
, "__rld_obj_head") == 0)
8928 /* IRIX6 does not use a .rld_map section. */
8929 if (IRIX_COMPAT (output_bfd
) == ict_irix5
8930 || IRIX_COMPAT (output_bfd
) == ict_none
)
8931 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
8933 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8937 /* Keep dynamic MIPS16 symbols odd. This allows the dynamic linker to
8938 treat MIPS16 symbols like any other. */
8939 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
8941 BFD_ASSERT (sym
->st_value
& 1);
8942 sym
->st_other
-= STO_MIPS16
;
8948 /* Likewise, for VxWorks. */
8951 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
8952 struct bfd_link_info
*info
,
8953 struct elf_link_hash_entry
*h
,
8954 Elf_Internal_Sym
*sym
)
8958 struct mips_got_info
*g
;
8959 struct mips_elf_link_hash_table
*htab
;
8961 htab
= mips_elf_hash_table (info
);
8962 dynobj
= elf_hash_table (info
)->dynobj
;
8964 if (h
->plt
.offset
!= (bfd_vma
) -1)
8967 bfd_vma plt_address
, plt_index
, got_address
, got_offset
, branch_offset
;
8968 Elf_Internal_Rela rel
;
8969 static const bfd_vma
*plt_entry
;
8971 BFD_ASSERT (h
->dynindx
!= -1);
8972 BFD_ASSERT (htab
->splt
!= NULL
);
8973 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
8975 /* Calculate the address of the .plt entry. */
8976 plt_address
= (htab
->splt
->output_section
->vma
8977 + htab
->splt
->output_offset
8980 /* Calculate the index of the entry. */
8981 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
8982 / htab
->plt_entry_size
);
8984 /* Calculate the address of the .got.plt entry. */
8985 got_address
= (htab
->sgotplt
->output_section
->vma
8986 + htab
->sgotplt
->output_offset
8989 /* Calculate the offset of the .got.plt entry from
8990 _GLOBAL_OFFSET_TABLE_. */
8991 got_offset
= mips_elf_gotplt_index (info
, h
);
8993 /* Calculate the offset for the branch at the start of the PLT
8994 entry. The branch jumps to the beginning of .plt. */
8995 branch_offset
= -(h
->plt
.offset
/ 4 + 1) & 0xffff;
8997 /* Fill in the initial value of the .got.plt entry. */
8998 bfd_put_32 (output_bfd
, plt_address
,
8999 htab
->sgotplt
->contents
+ plt_index
* 4);
9001 /* Find out where the .plt entry should go. */
9002 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9006 plt_entry
= mips_vxworks_shared_plt_entry
;
9007 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9008 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9012 bfd_vma got_address_high
, got_address_low
;
9014 plt_entry
= mips_vxworks_exec_plt_entry
;
9015 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9016 got_address_low
= got_address
& 0xffff;
9018 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9019 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9020 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
9021 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
9022 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9023 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9024 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9025 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9027 loc
= (htab
->srelplt2
->contents
9028 + (plt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
9030 /* Emit a relocation for the .got.plt entry. */
9031 rel
.r_offset
= got_address
;
9032 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9033 rel
.r_addend
= h
->plt
.offset
;
9034 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9036 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
9037 loc
+= sizeof (Elf32_External_Rela
);
9038 rel
.r_offset
= plt_address
+ 8;
9039 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9040 rel
.r_addend
= got_offset
;
9041 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9043 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
9044 loc
+= sizeof (Elf32_External_Rela
);
9046 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9047 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9050 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9051 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
9052 rel
.r_offset
= got_address
;
9053 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
9055 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9057 if (!h
->def_regular
)
9058 sym
->st_shndx
= SHN_UNDEF
;
9061 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
9065 BFD_ASSERT (g
!= NULL
);
9067 /* See if this symbol has an entry in the GOT. */
9068 if (g
->global_gotsym
!= NULL
9069 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
9072 Elf_Internal_Rela outrel
;
9076 /* Install the symbol value in the GOT. */
9077 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9078 R_MIPS_GOT16
, info
);
9079 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
9081 /* Add a dynamic relocation for it. */
9082 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9083 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
9084 outrel
.r_offset
= (sgot
->output_section
->vma
9085 + sgot
->output_offset
9087 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
9088 outrel
.r_addend
= 0;
9089 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
9092 /* Emit a copy reloc, if needed. */
9095 Elf_Internal_Rela rel
;
9097 BFD_ASSERT (h
->dynindx
!= -1);
9099 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
9100 + h
->root
.u
.def
.section
->output_offset
9101 + h
->root
.u
.def
.value
);
9102 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
9104 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
9105 htab
->srelbss
->contents
9106 + (htab
->srelbss
->reloc_count
9107 * sizeof (Elf32_External_Rela
)));
9108 ++htab
->srelbss
->reloc_count
;
9111 /* If this is a mips16 symbol, force the value to be even. */
9112 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9113 sym
->st_value
&= ~1;
9118 /* Install the PLT header for a VxWorks executable and finalize the
9119 contents of .rela.plt.unloaded. */
9122 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9124 Elf_Internal_Rela rela
;
9126 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
9127 static const bfd_vma
*plt_entry
;
9128 struct mips_elf_link_hash_table
*htab
;
9130 htab
= mips_elf_hash_table (info
);
9131 plt_entry
= mips_vxworks_exec_plt0_entry
;
9133 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
9134 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
9135 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
9136 + htab
->root
.hgot
->root
.u
.def
.value
);
9138 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
9139 got_value_low
= got_value
& 0xffff;
9141 /* Calculate the address of the PLT header. */
9142 plt_address
= htab
->splt
->output_section
->vma
+ htab
->splt
->output_offset
;
9144 /* Install the PLT header. */
9145 loc
= htab
->splt
->contents
;
9146 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
9147 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
9148 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
9149 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9150 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9151 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9153 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
9154 loc
= htab
->srelplt2
->contents
;
9155 rela
.r_offset
= plt_address
;
9156 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9158 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9159 loc
+= sizeof (Elf32_External_Rela
);
9161 /* Output the relocation for the following addiu of
9162 %lo(_GLOBAL_OFFSET_TABLE_). */
9164 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9165 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9166 loc
+= sizeof (Elf32_External_Rela
);
9168 /* Fix up the remaining relocations. They may have the wrong
9169 symbol index for _G_O_T_ or _P_L_T_ depending on the order
9170 in which symbols were output. */
9171 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
9173 Elf_Internal_Rela rel
;
9175 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9176 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9177 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9178 loc
+= sizeof (Elf32_External_Rela
);
9180 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9181 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9182 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9183 loc
+= sizeof (Elf32_External_Rela
);
9185 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9186 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9187 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9188 loc
+= sizeof (Elf32_External_Rela
);
9192 /* Install the PLT header for a VxWorks shared library. */
9195 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9198 struct mips_elf_link_hash_table
*htab
;
9200 htab
= mips_elf_hash_table (info
);
9202 /* We just need to copy the entry byte-by-byte. */
9203 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
9204 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
9205 htab
->splt
->contents
+ i
* 4);
9208 /* Finish up the dynamic sections. */
9211 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
9212 struct bfd_link_info
*info
)
9217 struct mips_got_info
*gg
, *g
;
9218 struct mips_elf_link_hash_table
*htab
;
9220 htab
= mips_elf_hash_table (info
);
9221 dynobj
= elf_hash_table (info
)->dynobj
;
9223 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
9226 gg
= htab
->got_info
;
9228 if (elf_hash_table (info
)->dynamic_sections_created
)
9231 int dyn_to_skip
= 0, dyn_skipped
= 0;
9233 BFD_ASSERT (sdyn
!= NULL
);
9234 BFD_ASSERT (gg
!= NULL
);
9236 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
9237 BFD_ASSERT (g
!= NULL
);
9239 for (b
= sdyn
->contents
;
9240 b
< sdyn
->contents
+ sdyn
->size
;
9241 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9243 Elf_Internal_Dyn dyn
;
9247 bfd_boolean swap_out_p
;
9249 /* Read in the current dynamic entry. */
9250 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9252 /* Assume that we're going to modify it and write it out. */
9258 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
9262 BFD_ASSERT (htab
->is_vxworks
);
9263 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
9267 /* Rewrite DT_STRSZ. */
9269 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
9274 if (htab
->is_vxworks
)
9276 /* _GLOBAL_OFFSET_TABLE_ is defined to be the beginning
9277 of the ".got" section in DYNOBJ. */
9278 s
= bfd_get_section_by_name (dynobj
, name
);
9279 BFD_ASSERT (s
!= NULL
);
9280 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9284 s
= bfd_get_section_by_name (output_bfd
, name
);
9285 BFD_ASSERT (s
!= NULL
);
9286 dyn
.d_un
.d_ptr
= s
->vma
;
9290 case DT_MIPS_RLD_VERSION
:
9291 dyn
.d_un
.d_val
= 1; /* XXX */
9295 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
9298 case DT_MIPS_TIME_STAMP
:
9306 case DT_MIPS_ICHECKSUM
:
9311 case DT_MIPS_IVERSION
:
9316 case DT_MIPS_BASE_ADDRESS
:
9317 s
= output_bfd
->sections
;
9318 BFD_ASSERT (s
!= NULL
);
9319 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
9322 case DT_MIPS_LOCAL_GOTNO
:
9323 dyn
.d_un
.d_val
= g
->local_gotno
;
9326 case DT_MIPS_UNREFEXTNO
:
9327 /* The index into the dynamic symbol table which is the
9328 entry of the first external symbol that is not
9329 referenced within the same object. */
9330 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
9333 case DT_MIPS_GOTSYM
:
9334 if (gg
->global_gotsym
)
9336 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
9339 /* In case if we don't have global got symbols we default
9340 to setting DT_MIPS_GOTSYM to the same value as
9341 DT_MIPS_SYMTABNO, so we just fall through. */
9343 case DT_MIPS_SYMTABNO
:
9345 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
9346 s
= bfd_get_section_by_name (output_bfd
, name
);
9347 BFD_ASSERT (s
!= NULL
);
9349 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
9352 case DT_MIPS_HIPAGENO
:
9353 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO (info
);
9356 case DT_MIPS_RLD_MAP
:
9357 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
9360 case DT_MIPS_OPTIONS
:
9361 s
= (bfd_get_section_by_name
9362 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
9363 dyn
.d_un
.d_ptr
= s
->vma
;
9367 BFD_ASSERT (htab
->is_vxworks
);
9368 /* The count does not include the JUMP_SLOT relocations. */
9370 dyn
.d_un
.d_val
-= htab
->srelplt
->size
;
9374 BFD_ASSERT (htab
->is_vxworks
);
9375 dyn
.d_un
.d_val
= DT_RELA
;
9379 BFD_ASSERT (htab
->is_vxworks
);
9380 dyn
.d_un
.d_val
= htab
->srelplt
->size
;
9384 BFD_ASSERT (htab
->is_vxworks
);
9385 dyn
.d_un
.d_val
= (htab
->srelplt
->output_section
->vma
9386 + htab
->srelplt
->output_offset
);
9390 /* If we didn't need any text relocations after all, delete
9392 if (!(info
->flags
& DF_TEXTREL
))
9394 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
9400 /* If we didn't need any text relocations after all, clear
9401 DF_TEXTREL from DT_FLAGS. */
9402 if (!(info
->flags
& DF_TEXTREL
))
9403 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
9410 if (htab
->is_vxworks
9411 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
9416 if (swap_out_p
|| dyn_skipped
)
9417 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
9418 (dynobj
, &dyn
, b
- dyn_skipped
);
9422 dyn_skipped
+= dyn_to_skip
;
9427 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
9428 if (dyn_skipped
> 0)
9429 memset (b
- dyn_skipped
, 0, dyn_skipped
);
9432 if (sgot
!= NULL
&& sgot
->size
> 0
9433 && !bfd_is_abs_section (sgot
->output_section
))
9435 if (htab
->is_vxworks
)
9437 /* The first entry of the global offset table points to the
9438 ".dynamic" section. The second is initialized by the
9439 loader and contains the shared library identifier.
9440 The third is also initialized by the loader and points
9441 to the lazy resolution stub. */
9442 MIPS_ELF_PUT_WORD (output_bfd
,
9443 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
9445 MIPS_ELF_PUT_WORD (output_bfd
, 0,
9446 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
9447 MIPS_ELF_PUT_WORD (output_bfd
, 0,
9449 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
9453 /* The first entry of the global offset table will be filled at
9454 runtime. The second entry will be used by some runtime loaders.
9455 This isn't the case of IRIX rld. */
9456 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
9457 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
9458 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
9461 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
9462 = MIPS_ELF_GOT_SIZE (output_bfd
);
9465 /* Generate dynamic relocations for the non-primary gots. */
9466 if (gg
!= NULL
&& gg
->next
)
9468 Elf_Internal_Rela rel
[3];
9471 memset (rel
, 0, sizeof (rel
));
9472 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
9474 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
9476 bfd_vma index
= g
->next
->local_gotno
+ g
->next
->global_gotno
9477 + g
->next
->tls_gotno
;
9479 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
9480 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
9481 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
9483 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
9488 while (index
< g
->assigned_gotno
)
9490 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
9491 = index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
9492 if (!(mips_elf_create_dynamic_relocation
9493 (output_bfd
, info
, rel
, NULL
,
9494 bfd_abs_section_ptr
,
9497 BFD_ASSERT (addend
== 0);
9502 /* The generation of dynamic relocations for the non-primary gots
9503 adds more dynamic relocations. We cannot count them until
9506 if (elf_hash_table (info
)->dynamic_sections_created
)
9509 bfd_boolean swap_out_p
;
9511 BFD_ASSERT (sdyn
!= NULL
);
9513 for (b
= sdyn
->contents
;
9514 b
< sdyn
->contents
+ sdyn
->size
;
9515 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9517 Elf_Internal_Dyn dyn
;
9520 /* Read in the current dynamic entry. */
9521 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9523 /* Assume that we're going to modify it and write it out. */
9529 /* Reduce DT_RELSZ to account for any relocations we
9530 decided not to make. This is for the n64 irix rld,
9531 which doesn't seem to apply any relocations if there
9532 are trailing null entries. */
9533 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9534 dyn
.d_un
.d_val
= (s
->reloc_count
9535 * (ABI_64_P (output_bfd
)
9536 ? sizeof (Elf64_Mips_External_Rel
)
9537 : sizeof (Elf32_External_Rel
)));
9538 /* Adjust the section size too. Tools like the prelinker
9539 can reasonably expect the values to the same. */
9540 elf_section_data (s
->output_section
)->this_hdr
.sh_size
9550 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
9557 Elf32_compact_rel cpt
;
9559 if (SGI_COMPAT (output_bfd
))
9561 /* Write .compact_rel section out. */
9562 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
9566 cpt
.num
= s
->reloc_count
;
9568 cpt
.offset
= (s
->output_section
->filepos
9569 + sizeof (Elf32_External_compact_rel
));
9572 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
9573 ((Elf32_External_compact_rel
*)
9576 /* Clean up a dummy stub function entry in .text. */
9577 if (htab
->sstubs
!= NULL
)
9579 file_ptr dummy_offset
;
9581 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
9582 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
9583 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
9584 htab
->function_stub_size
);
9589 /* The psABI says that the dynamic relocations must be sorted in
9590 increasing order of r_symndx. The VxWorks EABI doesn't require
9591 this, and because the code below handles REL rather than RELA
9592 relocations, using it for VxWorks would be outright harmful. */
9593 if (!htab
->is_vxworks
)
9595 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9597 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
9599 reldyn_sorting_bfd
= output_bfd
;
9601 if (ABI_64_P (output_bfd
))
9602 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
9603 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
9604 sort_dynamic_relocs_64
);
9606 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
9607 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
9608 sort_dynamic_relocs
);
9613 if (htab
->is_vxworks
&& htab
->splt
->size
> 0)
9616 mips_vxworks_finish_shared_plt (output_bfd
, info
);
9618 mips_vxworks_finish_exec_plt (output_bfd
, info
);
9624 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
9627 mips_set_isa_flags (bfd
*abfd
)
9631 switch (bfd_get_mach (abfd
))
9634 case bfd_mach_mips3000
:
9635 val
= E_MIPS_ARCH_1
;
9638 case bfd_mach_mips3900
:
9639 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
9642 case bfd_mach_mips6000
:
9643 val
= E_MIPS_ARCH_2
;
9646 case bfd_mach_mips4000
:
9647 case bfd_mach_mips4300
:
9648 case bfd_mach_mips4400
:
9649 case bfd_mach_mips4600
:
9650 val
= E_MIPS_ARCH_3
;
9653 case bfd_mach_mips4010
:
9654 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
9657 case bfd_mach_mips4100
:
9658 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
9661 case bfd_mach_mips4111
:
9662 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
9665 case bfd_mach_mips4120
:
9666 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
9669 case bfd_mach_mips4650
:
9670 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
9673 case bfd_mach_mips5400
:
9674 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
9677 case bfd_mach_mips5500
:
9678 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
9681 case bfd_mach_mips9000
:
9682 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
9685 case bfd_mach_mips5000
:
9686 case bfd_mach_mips7000
:
9687 case bfd_mach_mips8000
:
9688 case bfd_mach_mips10000
:
9689 case bfd_mach_mips12000
:
9690 val
= E_MIPS_ARCH_4
;
9693 case bfd_mach_mips5
:
9694 val
= E_MIPS_ARCH_5
;
9697 case bfd_mach_mips_loongson_2e
:
9698 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
9701 case bfd_mach_mips_loongson_2f
:
9702 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
9705 case bfd_mach_mips_sb1
:
9706 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
9709 case bfd_mach_mips_octeon
:
9710 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
9713 case bfd_mach_mipsisa32
:
9714 val
= E_MIPS_ARCH_32
;
9717 case bfd_mach_mipsisa64
:
9718 val
= E_MIPS_ARCH_64
;
9721 case bfd_mach_mipsisa32r2
:
9722 val
= E_MIPS_ARCH_32R2
;
9725 case bfd_mach_mipsisa64r2
:
9726 val
= E_MIPS_ARCH_64R2
;
9729 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
9730 elf_elfheader (abfd
)->e_flags
|= val
;
9735 /* The final processing done just before writing out a MIPS ELF object
9736 file. This gets the MIPS architecture right based on the machine
9737 number. This is used by both the 32-bit and the 64-bit ABI. */
9740 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
9741 bfd_boolean linker ATTRIBUTE_UNUSED
)
9744 Elf_Internal_Shdr
**hdrpp
;
9748 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
9749 is nonzero. This is for compatibility with old objects, which used
9750 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
9751 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
9752 mips_set_isa_flags (abfd
);
9754 /* Set the sh_info field for .gptab sections and other appropriate
9755 info for each special section. */
9756 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
9757 i
< elf_numsections (abfd
);
9760 switch ((*hdrpp
)->sh_type
)
9763 case SHT_MIPS_LIBLIST
:
9764 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
9766 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9769 case SHT_MIPS_GPTAB
:
9770 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9771 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9772 BFD_ASSERT (name
!= NULL
9773 && CONST_STRNEQ (name
, ".gptab."));
9774 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
9775 BFD_ASSERT (sec
!= NULL
);
9776 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
9779 case SHT_MIPS_CONTENT
:
9780 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9781 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9782 BFD_ASSERT (name
!= NULL
9783 && CONST_STRNEQ (name
, ".MIPS.content"));
9784 sec
= bfd_get_section_by_name (abfd
,
9785 name
+ sizeof ".MIPS.content" - 1);
9786 BFD_ASSERT (sec
!= NULL
);
9787 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9790 case SHT_MIPS_SYMBOL_LIB
:
9791 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
9793 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9794 sec
= bfd_get_section_by_name (abfd
, ".liblist");
9796 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
9799 case SHT_MIPS_EVENTS
:
9800 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9801 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9802 BFD_ASSERT (name
!= NULL
);
9803 if (CONST_STRNEQ (name
, ".MIPS.events"))
9804 sec
= bfd_get_section_by_name (abfd
,
9805 name
+ sizeof ".MIPS.events" - 1);
9808 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
9809 sec
= bfd_get_section_by_name (abfd
,
9811 + sizeof ".MIPS.post_rel" - 1));
9813 BFD_ASSERT (sec
!= NULL
);
9814 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9821 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
9825 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
9826 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
9831 /* See if we need a PT_MIPS_REGINFO segment. */
9832 s
= bfd_get_section_by_name (abfd
, ".reginfo");
9833 if (s
&& (s
->flags
& SEC_LOAD
))
9836 /* See if we need a PT_MIPS_OPTIONS segment. */
9837 if (IRIX_COMPAT (abfd
) == ict_irix6
9838 && bfd_get_section_by_name (abfd
,
9839 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
9842 /* See if we need a PT_MIPS_RTPROC segment. */
9843 if (IRIX_COMPAT (abfd
) == ict_irix5
9844 && bfd_get_section_by_name (abfd
, ".dynamic")
9845 && bfd_get_section_by_name (abfd
, ".mdebug"))
9848 /* Allocate a PT_NULL header in dynamic objects. See
9849 _bfd_mips_elf_modify_segment_map for details. */
9850 if (!SGI_COMPAT (abfd
)
9851 && bfd_get_section_by_name (abfd
, ".dynamic"))
9857 /* Modify the segment map for an IRIX5 executable. */
9860 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
9861 struct bfd_link_info
*info
)
9864 struct elf_segment_map
*m
, **pm
;
9867 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
9869 s
= bfd_get_section_by_name (abfd
, ".reginfo");
9870 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
9872 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
9873 if (m
->p_type
== PT_MIPS_REGINFO
)
9878 m
= bfd_zalloc (abfd
, amt
);
9882 m
->p_type
= PT_MIPS_REGINFO
;
9886 /* We want to put it after the PHDR and INTERP segments. */
9887 pm
= &elf_tdata (abfd
)->segment_map
;
9889 && ((*pm
)->p_type
== PT_PHDR
9890 || (*pm
)->p_type
== PT_INTERP
))
9898 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
9899 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
9900 PT_MIPS_OPTIONS segment immediately following the program header
9903 /* On non-IRIX6 new abi, we'll have already created a segment
9904 for this section, so don't create another. I'm not sure this
9905 is not also the case for IRIX 6, but I can't test it right
9907 && IRIX_COMPAT (abfd
) == ict_irix6
)
9909 for (s
= abfd
->sections
; s
; s
= s
->next
)
9910 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
9915 struct elf_segment_map
*options_segment
;
9917 pm
= &elf_tdata (abfd
)->segment_map
;
9919 && ((*pm
)->p_type
== PT_PHDR
9920 || (*pm
)->p_type
== PT_INTERP
))
9923 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
9925 amt
= sizeof (struct elf_segment_map
);
9926 options_segment
= bfd_zalloc (abfd
, amt
);
9927 options_segment
->next
= *pm
;
9928 options_segment
->p_type
= PT_MIPS_OPTIONS
;
9929 options_segment
->p_flags
= PF_R
;
9930 options_segment
->p_flags_valid
= TRUE
;
9931 options_segment
->count
= 1;
9932 options_segment
->sections
[0] = s
;
9933 *pm
= options_segment
;
9939 if (IRIX_COMPAT (abfd
) == ict_irix5
)
9941 /* If there are .dynamic and .mdebug sections, we make a room
9942 for the RTPROC header. FIXME: Rewrite without section names. */
9943 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
9944 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
9945 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
9947 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
9948 if (m
->p_type
== PT_MIPS_RTPROC
)
9953 m
= bfd_zalloc (abfd
, amt
);
9957 m
->p_type
= PT_MIPS_RTPROC
;
9959 s
= bfd_get_section_by_name (abfd
, ".rtproc");
9964 m
->p_flags_valid
= 1;
9972 /* We want to put it after the DYNAMIC segment. */
9973 pm
= &elf_tdata (abfd
)->segment_map
;
9974 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
9984 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
9985 .dynstr, .dynsym, and .hash sections, and everything in
9987 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
9989 if ((*pm
)->p_type
== PT_DYNAMIC
)
9992 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
9994 /* For a normal mips executable the permissions for the PT_DYNAMIC
9995 segment are read, write and execute. We do that here since
9996 the code in elf.c sets only the read permission. This matters
9997 sometimes for the dynamic linker. */
9998 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
10000 m
->p_flags
= PF_R
| PF_W
| PF_X
;
10001 m
->p_flags_valid
= 1;
10004 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
10005 glibc's dynamic linker has traditionally derived the number of
10006 tags from the p_filesz field, and sometimes allocates stack
10007 arrays of that size. An overly-big PT_DYNAMIC segment can
10008 be actively harmful in such cases. Making PT_DYNAMIC contain
10009 other sections can also make life hard for the prelinker,
10010 which might move one of the other sections to a different
10011 PT_LOAD segment. */
10012 if (SGI_COMPAT (abfd
)
10015 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
10017 static const char *sec_names
[] =
10019 ".dynamic", ".dynstr", ".dynsym", ".hash"
10023 struct elf_segment_map
*n
;
10025 low
= ~(bfd_vma
) 0;
10027 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
10029 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
10030 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10037 if (high
< s
->vma
+ sz
)
10038 high
= s
->vma
+ sz
;
10043 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10044 if ((s
->flags
& SEC_LOAD
) != 0
10046 && s
->vma
+ s
->size
<= high
)
10049 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
10050 n
= bfd_zalloc (abfd
, amt
);
10057 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10059 if ((s
->flags
& SEC_LOAD
) != 0
10061 && s
->vma
+ s
->size
<= high
)
10063 n
->sections
[i
] = s
;
10072 /* Allocate a spare program header in dynamic objects so that tools
10073 like the prelinker can add an extra PT_LOAD entry.
10075 If the prelinker needs to make room for a new PT_LOAD entry, its
10076 standard procedure is to move the first (read-only) sections into
10077 the new (writable) segment. However, the MIPS ABI requires
10078 .dynamic to be in a read-only segment, and the section will often
10079 start within sizeof (ElfNN_Phdr) bytes of the last program header.
10081 Although the prelinker could in principle move .dynamic to a
10082 writable segment, it seems better to allocate a spare program
10083 header instead, and avoid the need to move any sections.
10084 There is a long tradition of allocating spare dynamic tags,
10085 so allocating a spare program header seems like a natural
10088 If INFO is NULL, we may be copying an already prelinked binary
10089 with objcopy or strip, so do not add this header. */
10091 && !SGI_COMPAT (abfd
)
10092 && bfd_get_section_by_name (abfd
, ".dynamic"))
10094 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
10095 if ((*pm
)->p_type
== PT_NULL
)
10099 m
= bfd_zalloc (abfd
, sizeof (*m
));
10103 m
->p_type
= PT_NULL
;
10111 /* Return the section that should be marked against GC for a given
10115 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
10116 struct bfd_link_info
*info
,
10117 Elf_Internal_Rela
*rel
,
10118 struct elf_link_hash_entry
*h
,
10119 Elf_Internal_Sym
*sym
)
10121 /* ??? Do mips16 stub sections need to be handled special? */
10124 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
10126 case R_MIPS_GNU_VTINHERIT
:
10127 case R_MIPS_GNU_VTENTRY
:
10131 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
10134 /* Update the got entry reference counts for the section being removed. */
10137 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
10138 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
10139 asection
*sec ATTRIBUTE_UNUSED
,
10140 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
10143 Elf_Internal_Shdr
*symtab_hdr
;
10144 struct elf_link_hash_entry
**sym_hashes
;
10145 bfd_signed_vma
*local_got_refcounts
;
10146 const Elf_Internal_Rela
*rel
, *relend
;
10147 unsigned long r_symndx
;
10148 struct elf_link_hash_entry
*h
;
10150 if (info
->relocatable
)
10153 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
10154 sym_hashes
= elf_sym_hashes (abfd
);
10155 local_got_refcounts
= elf_local_got_refcounts (abfd
);
10157 relend
= relocs
+ sec
->reloc_count
;
10158 for (rel
= relocs
; rel
< relend
; rel
++)
10159 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
10161 case R_MIPS16_GOT16
:
10162 case R_MIPS16_CALL16
:
10164 case R_MIPS_CALL16
:
10165 case R_MIPS_CALL_HI16
:
10166 case R_MIPS_CALL_LO16
:
10167 case R_MIPS_GOT_HI16
:
10168 case R_MIPS_GOT_LO16
:
10169 case R_MIPS_GOT_DISP
:
10170 case R_MIPS_GOT_PAGE
:
10171 case R_MIPS_GOT_OFST
:
10172 /* ??? It would seem that the existing MIPS code does no sort
10173 of reference counting or whatnot on its GOT and PLT entries,
10174 so it is not possible to garbage collect them at this time. */
10185 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
10186 hiding the old indirect symbol. Process additional relocation
10187 information. Also called for weakdefs, in which case we just let
10188 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
10191 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
10192 struct elf_link_hash_entry
*dir
,
10193 struct elf_link_hash_entry
*ind
)
10195 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
10197 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
10199 if (ind
->root
.type
!= bfd_link_hash_indirect
)
10202 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
10203 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
10204 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
10205 if (indmips
->readonly_reloc
)
10206 dirmips
->readonly_reloc
= TRUE
;
10207 if (indmips
->no_fn_stub
)
10208 dirmips
->no_fn_stub
= TRUE
;
10209 if (indmips
->global_got_area
< dirmips
->global_got_area
)
10210 dirmips
->global_got_area
= indmips
->global_got_area
;
10211 if (indmips
->global_got_area
< GGA_NONE
)
10212 indmips
->global_got_area
= GGA_NONE
;
10214 if (dirmips
->tls_type
== 0)
10215 dirmips
->tls_type
= indmips
->tls_type
;
10218 #define PDR_SIZE 32
10221 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
10222 struct bfd_link_info
*info
)
10225 bfd_boolean ret
= FALSE
;
10226 unsigned char *tdata
;
10229 o
= bfd_get_section_by_name (abfd
, ".pdr");
10234 if (o
->size
% PDR_SIZE
!= 0)
10236 if (o
->output_section
!= NULL
10237 && bfd_is_abs_section (o
->output_section
))
10240 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
10244 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
10245 info
->keep_memory
);
10252 cookie
->rel
= cookie
->rels
;
10253 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
10255 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
10257 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
10266 mips_elf_section_data (o
)->u
.tdata
= tdata
;
10267 o
->size
-= skip
* PDR_SIZE
;
10273 if (! info
->keep_memory
)
10274 free (cookie
->rels
);
10280 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
10282 if (strcmp (sec
->name
, ".pdr") == 0)
10288 _bfd_mips_elf_write_section (bfd
*output_bfd
,
10289 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
10290 asection
*sec
, bfd_byte
*contents
)
10292 bfd_byte
*to
, *from
, *end
;
10295 if (strcmp (sec
->name
, ".pdr") != 0)
10298 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
10302 end
= contents
+ sec
->size
;
10303 for (from
= contents
, i
= 0;
10305 from
+= PDR_SIZE
, i
++)
10307 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
10310 memcpy (to
, from
, PDR_SIZE
);
10313 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
10314 sec
->output_offset
, sec
->size
);
10318 /* MIPS ELF uses a special find_nearest_line routine in order the
10319 handle the ECOFF debugging information. */
10321 struct mips_elf_find_line
10323 struct ecoff_debug_info d
;
10324 struct ecoff_find_line i
;
10328 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
10329 asymbol
**symbols
, bfd_vma offset
,
10330 const char **filename_ptr
,
10331 const char **functionname_ptr
,
10332 unsigned int *line_ptr
)
10336 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
10337 filename_ptr
, functionname_ptr
,
10341 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
10342 filename_ptr
, functionname_ptr
,
10343 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
10344 &elf_tdata (abfd
)->dwarf2_find_line_info
))
10347 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
10350 flagword origflags
;
10351 struct mips_elf_find_line
*fi
;
10352 const struct ecoff_debug_swap
* const swap
=
10353 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
10355 /* If we are called during a link, mips_elf_final_link may have
10356 cleared the SEC_HAS_CONTENTS field. We force it back on here
10357 if appropriate (which it normally will be). */
10358 origflags
= msec
->flags
;
10359 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
10360 msec
->flags
|= SEC_HAS_CONTENTS
;
10362 fi
= elf_tdata (abfd
)->find_line_info
;
10365 bfd_size_type external_fdr_size
;
10368 struct fdr
*fdr_ptr
;
10369 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
10371 fi
= bfd_zalloc (abfd
, amt
);
10374 msec
->flags
= origflags
;
10378 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
10380 msec
->flags
= origflags
;
10384 /* Swap in the FDR information. */
10385 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
10386 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
10387 if (fi
->d
.fdr
== NULL
)
10389 msec
->flags
= origflags
;
10392 external_fdr_size
= swap
->external_fdr_size
;
10393 fdr_ptr
= fi
->d
.fdr
;
10394 fraw_src
= (char *) fi
->d
.external_fdr
;
10395 fraw_end
= (fraw_src
10396 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
10397 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
10398 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
10400 elf_tdata (abfd
)->find_line_info
= fi
;
10402 /* Note that we don't bother to ever free this information.
10403 find_nearest_line is either called all the time, as in
10404 objdump -l, so the information should be saved, or it is
10405 rarely called, as in ld error messages, so the memory
10406 wasted is unimportant. Still, it would probably be a
10407 good idea for free_cached_info to throw it away. */
10410 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
10411 &fi
->i
, filename_ptr
, functionname_ptr
,
10414 msec
->flags
= origflags
;
10418 msec
->flags
= origflags
;
10421 /* Fall back on the generic ELF find_nearest_line routine. */
10423 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
10424 filename_ptr
, functionname_ptr
,
10429 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
10430 const char **filename_ptr
,
10431 const char **functionname_ptr
,
10432 unsigned int *line_ptr
)
10435 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
10436 functionname_ptr
, line_ptr
,
10437 & elf_tdata (abfd
)->dwarf2_find_line_info
);
10442 /* When are writing out the .options or .MIPS.options section,
10443 remember the bytes we are writing out, so that we can install the
10444 GP value in the section_processing routine. */
10447 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
10448 const void *location
,
10449 file_ptr offset
, bfd_size_type count
)
10451 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
10455 if (elf_section_data (section
) == NULL
)
10457 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
10458 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
10459 if (elf_section_data (section
) == NULL
)
10462 c
= mips_elf_section_data (section
)->u
.tdata
;
10465 c
= bfd_zalloc (abfd
, section
->size
);
10468 mips_elf_section_data (section
)->u
.tdata
= c
;
10471 memcpy (c
+ offset
, location
, count
);
10474 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
10478 /* This is almost identical to bfd_generic_get_... except that some
10479 MIPS relocations need to be handled specially. Sigh. */
10482 _bfd_elf_mips_get_relocated_section_contents
10484 struct bfd_link_info
*link_info
,
10485 struct bfd_link_order
*link_order
,
10487 bfd_boolean relocatable
,
10490 /* Get enough memory to hold the stuff */
10491 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
10492 asection
*input_section
= link_order
->u
.indirect
.section
;
10495 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
10496 arelent
**reloc_vector
= NULL
;
10499 if (reloc_size
< 0)
10502 reloc_vector
= bfd_malloc (reloc_size
);
10503 if (reloc_vector
== NULL
&& reloc_size
!= 0)
10506 /* read in the section */
10507 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
10508 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
10511 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
10515 if (reloc_count
< 0)
10518 if (reloc_count
> 0)
10523 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
10526 struct bfd_hash_entry
*h
;
10527 struct bfd_link_hash_entry
*lh
;
10528 /* Skip all this stuff if we aren't mixing formats. */
10529 if (abfd
&& input_bfd
10530 && abfd
->xvec
== input_bfd
->xvec
)
10534 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
10535 lh
= (struct bfd_link_hash_entry
*) h
;
10542 case bfd_link_hash_undefined
:
10543 case bfd_link_hash_undefweak
:
10544 case bfd_link_hash_common
:
10547 case bfd_link_hash_defined
:
10548 case bfd_link_hash_defweak
:
10550 gp
= lh
->u
.def
.value
;
10552 case bfd_link_hash_indirect
:
10553 case bfd_link_hash_warning
:
10555 /* @@FIXME ignoring warning for now */
10557 case bfd_link_hash_new
:
10566 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
10568 char *error_message
= NULL
;
10569 bfd_reloc_status_type r
;
10571 /* Specific to MIPS: Deal with relocation types that require
10572 knowing the gp of the output bfd. */
10573 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
10575 /* If we've managed to find the gp and have a special
10576 function for the relocation then go ahead, else default
10577 to the generic handling. */
10579 && (*parent
)->howto
->special_function
10580 == _bfd_mips_elf32_gprel16_reloc
)
10581 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
10582 input_section
, relocatable
,
10585 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
10587 relocatable
? abfd
: NULL
,
10592 asection
*os
= input_section
->output_section
;
10594 /* A partial link, so keep the relocs */
10595 os
->orelocation
[os
->reloc_count
] = *parent
;
10599 if (r
!= bfd_reloc_ok
)
10603 case bfd_reloc_undefined
:
10604 if (!((*link_info
->callbacks
->undefined_symbol
)
10605 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
10606 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
10609 case bfd_reloc_dangerous
:
10610 BFD_ASSERT (error_message
!= NULL
);
10611 if (!((*link_info
->callbacks
->reloc_dangerous
)
10612 (link_info
, error_message
, input_bfd
, input_section
,
10613 (*parent
)->address
)))
10616 case bfd_reloc_overflow
:
10617 if (!((*link_info
->callbacks
->reloc_overflow
)
10619 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
10620 (*parent
)->howto
->name
, (*parent
)->addend
,
10621 input_bfd
, input_section
, (*parent
)->address
)))
10624 case bfd_reloc_outofrange
:
10633 if (reloc_vector
!= NULL
)
10634 free (reloc_vector
);
10638 if (reloc_vector
!= NULL
)
10639 free (reloc_vector
);
10643 /* Create a MIPS ELF linker hash table. */
10645 struct bfd_link_hash_table
*
10646 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
10648 struct mips_elf_link_hash_table
*ret
;
10649 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
10651 ret
= bfd_malloc (amt
);
10655 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
10656 mips_elf_link_hash_newfunc
,
10657 sizeof (struct mips_elf_link_hash_entry
)))
10664 /* We no longer use this. */
10665 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
10666 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
10668 ret
->procedure_count
= 0;
10669 ret
->compact_rel_size
= 0;
10670 ret
->use_rld_obj_head
= FALSE
;
10671 ret
->rld_value
= 0;
10672 ret
->mips16_stubs_seen
= FALSE
;
10673 ret
->is_vxworks
= FALSE
;
10674 ret
->small_data_overflow_reported
= FALSE
;
10675 ret
->srelbss
= NULL
;
10676 ret
->sdynbss
= NULL
;
10677 ret
->srelplt
= NULL
;
10678 ret
->srelplt2
= NULL
;
10679 ret
->sgotplt
= NULL
;
10681 ret
->sstubs
= NULL
;
10683 ret
->got_info
= NULL
;
10684 ret
->plt_header_size
= 0;
10685 ret
->plt_entry_size
= 0;
10686 ret
->lazy_stub_count
= 0;
10687 ret
->function_stub_size
= 0;
10689 return &ret
->root
.root
;
10692 /* Likewise, but indicate that the target is VxWorks. */
10694 struct bfd_link_hash_table
*
10695 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
10697 struct bfd_link_hash_table
*ret
;
10699 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
10702 struct mips_elf_link_hash_table
*htab
;
10704 htab
= (struct mips_elf_link_hash_table
*) ret
;
10705 htab
->is_vxworks
= 1;
10710 /* We need to use a special link routine to handle the .reginfo and
10711 the .mdebug sections. We need to merge all instances of these
10712 sections together, not write them all out sequentially. */
10715 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
10718 struct bfd_link_order
*p
;
10719 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
10720 asection
*rtproc_sec
;
10721 Elf32_RegInfo reginfo
;
10722 struct ecoff_debug_info debug
;
10723 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
10724 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
10725 HDRR
*symhdr
= &debug
.symbolic_header
;
10726 void *mdebug_handle
= NULL
;
10731 struct mips_elf_link_hash_table
*htab
;
10733 static const char * const secname
[] =
10735 ".text", ".init", ".fini", ".data",
10736 ".rodata", ".sdata", ".sbss", ".bss"
10738 static const int sc
[] =
10740 scText
, scInit
, scFini
, scData
,
10741 scRData
, scSData
, scSBss
, scBss
10744 /* Sort the dynamic symbols so that those with GOT entries come after
10746 htab
= mips_elf_hash_table (info
);
10747 if (!mips_elf_sort_hash_table (abfd
, info
))
10750 /* Get a value for the GP register. */
10751 if (elf_gp (abfd
) == 0)
10753 struct bfd_link_hash_entry
*h
;
10755 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
10756 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
10757 elf_gp (abfd
) = (h
->u
.def
.value
10758 + h
->u
.def
.section
->output_section
->vma
10759 + h
->u
.def
.section
->output_offset
);
10760 else if (htab
->is_vxworks
10761 && (h
= bfd_link_hash_lookup (info
->hash
,
10762 "_GLOBAL_OFFSET_TABLE_",
10763 FALSE
, FALSE
, TRUE
))
10764 && h
->type
== bfd_link_hash_defined
)
10765 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
10766 + h
->u
.def
.section
->output_offset
10768 else if (info
->relocatable
)
10770 bfd_vma lo
= MINUS_ONE
;
10772 /* Find the GP-relative section with the lowest offset. */
10773 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10775 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
10778 /* And calculate GP relative to that. */
10779 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
10783 /* If the relocate_section function needs to do a reloc
10784 involving the GP value, it should make a reloc_dangerous
10785 callback to warn that GP is not defined. */
10789 /* Go through the sections and collect the .reginfo and .mdebug
10791 reginfo_sec
= NULL
;
10793 gptab_data_sec
= NULL
;
10794 gptab_bss_sec
= NULL
;
10795 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10797 if (strcmp (o
->name
, ".reginfo") == 0)
10799 memset (®info
, 0, sizeof reginfo
);
10801 /* We have found the .reginfo section in the output file.
10802 Look through all the link_orders comprising it and merge
10803 the information together. */
10804 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10806 asection
*input_section
;
10808 Elf32_External_RegInfo ext
;
10811 if (p
->type
!= bfd_indirect_link_order
)
10813 if (p
->type
== bfd_data_link_order
)
10818 input_section
= p
->u
.indirect
.section
;
10819 input_bfd
= input_section
->owner
;
10821 if (! bfd_get_section_contents (input_bfd
, input_section
,
10822 &ext
, 0, sizeof ext
))
10825 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
10827 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
10828 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
10829 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
10830 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
10831 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
10833 /* ri_gp_value is set by the function
10834 mips_elf32_section_processing when the section is
10835 finally written out. */
10837 /* Hack: reset the SEC_HAS_CONTENTS flag so that
10838 elf_link_input_bfd ignores this section. */
10839 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
10842 /* Size has been set in _bfd_mips_elf_always_size_sections. */
10843 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
10845 /* Skip this section later on (I don't think this currently
10846 matters, but someday it might). */
10847 o
->map_head
.link_order
= NULL
;
10852 if (strcmp (o
->name
, ".mdebug") == 0)
10854 struct extsym_info einfo
;
10857 /* We have found the .mdebug section in the output file.
10858 Look through all the link_orders comprising it and merge
10859 the information together. */
10860 symhdr
->magic
= swap
->sym_magic
;
10861 /* FIXME: What should the version stamp be? */
10862 symhdr
->vstamp
= 0;
10863 symhdr
->ilineMax
= 0;
10864 symhdr
->cbLine
= 0;
10865 symhdr
->idnMax
= 0;
10866 symhdr
->ipdMax
= 0;
10867 symhdr
->isymMax
= 0;
10868 symhdr
->ioptMax
= 0;
10869 symhdr
->iauxMax
= 0;
10870 symhdr
->issMax
= 0;
10871 symhdr
->issExtMax
= 0;
10872 symhdr
->ifdMax
= 0;
10874 symhdr
->iextMax
= 0;
10876 /* We accumulate the debugging information itself in the
10877 debug_info structure. */
10879 debug
.external_dnr
= NULL
;
10880 debug
.external_pdr
= NULL
;
10881 debug
.external_sym
= NULL
;
10882 debug
.external_opt
= NULL
;
10883 debug
.external_aux
= NULL
;
10885 debug
.ssext
= debug
.ssext_end
= NULL
;
10886 debug
.external_fdr
= NULL
;
10887 debug
.external_rfd
= NULL
;
10888 debug
.external_ext
= debug
.external_ext_end
= NULL
;
10890 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
10891 if (mdebug_handle
== NULL
)
10895 esym
.cobol_main
= 0;
10899 esym
.asym
.iss
= issNil
;
10900 esym
.asym
.st
= stLocal
;
10901 esym
.asym
.reserved
= 0;
10902 esym
.asym
.index
= indexNil
;
10904 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
10906 esym
.asym
.sc
= sc
[i
];
10907 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
10910 esym
.asym
.value
= s
->vma
;
10911 last
= s
->vma
+ s
->size
;
10914 esym
.asym
.value
= last
;
10915 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
10916 secname
[i
], &esym
))
10920 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10922 asection
*input_section
;
10924 const struct ecoff_debug_swap
*input_swap
;
10925 struct ecoff_debug_info input_debug
;
10929 if (p
->type
!= bfd_indirect_link_order
)
10931 if (p
->type
== bfd_data_link_order
)
10936 input_section
= p
->u
.indirect
.section
;
10937 input_bfd
= input_section
->owner
;
10939 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
10940 || (get_elf_backend_data (input_bfd
)
10941 ->elf_backend_ecoff_debug_swap
) == NULL
)
10943 /* I don't know what a non MIPS ELF bfd would be
10944 doing with a .mdebug section, but I don't really
10945 want to deal with it. */
10949 input_swap
= (get_elf_backend_data (input_bfd
)
10950 ->elf_backend_ecoff_debug_swap
);
10952 BFD_ASSERT (p
->size
== input_section
->size
);
10954 /* The ECOFF linking code expects that we have already
10955 read in the debugging information and set up an
10956 ecoff_debug_info structure, so we do that now. */
10957 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
10961 if (! (bfd_ecoff_debug_accumulate
10962 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
10963 &input_debug
, input_swap
, info
)))
10966 /* Loop through the external symbols. For each one with
10967 interesting information, try to find the symbol in
10968 the linker global hash table and save the information
10969 for the output external symbols. */
10970 eraw_src
= input_debug
.external_ext
;
10971 eraw_end
= (eraw_src
10972 + (input_debug
.symbolic_header
.iextMax
10973 * input_swap
->external_ext_size
));
10975 eraw_src
< eraw_end
;
10976 eraw_src
+= input_swap
->external_ext_size
)
10980 struct mips_elf_link_hash_entry
*h
;
10982 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
10983 if (ext
.asym
.sc
== scNil
10984 || ext
.asym
.sc
== scUndefined
10985 || ext
.asym
.sc
== scSUndefined
)
10988 name
= input_debug
.ssext
+ ext
.asym
.iss
;
10989 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
10990 name
, FALSE
, FALSE
, TRUE
);
10991 if (h
== NULL
|| h
->esym
.ifd
!= -2)
10996 BFD_ASSERT (ext
.ifd
10997 < input_debug
.symbolic_header
.ifdMax
);
10998 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
11004 /* Free up the information we just read. */
11005 free (input_debug
.line
);
11006 free (input_debug
.external_dnr
);
11007 free (input_debug
.external_pdr
);
11008 free (input_debug
.external_sym
);
11009 free (input_debug
.external_opt
);
11010 free (input_debug
.external_aux
);
11011 free (input_debug
.ss
);
11012 free (input_debug
.ssext
);
11013 free (input_debug
.external_fdr
);
11014 free (input_debug
.external_rfd
);
11015 free (input_debug
.external_ext
);
11017 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11018 elf_link_input_bfd ignores this section. */
11019 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11022 if (SGI_COMPAT (abfd
) && info
->shared
)
11024 /* Create .rtproc section. */
11025 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11026 if (rtproc_sec
== NULL
)
11028 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
11029 | SEC_LINKER_CREATED
| SEC_READONLY
);
11031 rtproc_sec
= bfd_make_section_with_flags (abfd
,
11034 if (rtproc_sec
== NULL
11035 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
11039 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
11045 /* Build the external symbol information. */
11048 einfo
.debug
= &debug
;
11050 einfo
.failed
= FALSE
;
11051 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
11052 mips_elf_output_extsym
, &einfo
);
11056 /* Set the size of the .mdebug section. */
11057 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
11059 /* Skip this section later on (I don't think this currently
11060 matters, but someday it might). */
11061 o
->map_head
.link_order
= NULL
;
11066 if (CONST_STRNEQ (o
->name
, ".gptab."))
11068 const char *subname
;
11071 Elf32_External_gptab
*ext_tab
;
11074 /* The .gptab.sdata and .gptab.sbss sections hold
11075 information describing how the small data area would
11076 change depending upon the -G switch. These sections
11077 not used in executables files. */
11078 if (! info
->relocatable
)
11080 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11082 asection
*input_section
;
11084 if (p
->type
!= bfd_indirect_link_order
)
11086 if (p
->type
== bfd_data_link_order
)
11091 input_section
= p
->u
.indirect
.section
;
11093 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11094 elf_link_input_bfd ignores this section. */
11095 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11098 /* Skip this section later on (I don't think this
11099 currently matters, but someday it might). */
11100 o
->map_head
.link_order
= NULL
;
11102 /* Really remove the section. */
11103 bfd_section_list_remove (abfd
, o
);
11104 --abfd
->section_count
;
11109 /* There is one gptab for initialized data, and one for
11110 uninitialized data. */
11111 if (strcmp (o
->name
, ".gptab.sdata") == 0)
11112 gptab_data_sec
= o
;
11113 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
11117 (*_bfd_error_handler
)
11118 (_("%s: illegal section name `%s'"),
11119 bfd_get_filename (abfd
), o
->name
);
11120 bfd_set_error (bfd_error_nonrepresentable_section
);
11124 /* The linker script always combines .gptab.data and
11125 .gptab.sdata into .gptab.sdata, and likewise for
11126 .gptab.bss and .gptab.sbss. It is possible that there is
11127 no .sdata or .sbss section in the output file, in which
11128 case we must change the name of the output section. */
11129 subname
= o
->name
+ sizeof ".gptab" - 1;
11130 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
11132 if (o
== gptab_data_sec
)
11133 o
->name
= ".gptab.data";
11135 o
->name
= ".gptab.bss";
11136 subname
= o
->name
+ sizeof ".gptab" - 1;
11137 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
11140 /* Set up the first entry. */
11142 amt
= c
* sizeof (Elf32_gptab
);
11143 tab
= bfd_malloc (amt
);
11146 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
11147 tab
[0].gt_header
.gt_unused
= 0;
11149 /* Combine the input sections. */
11150 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11152 asection
*input_section
;
11154 bfd_size_type size
;
11155 unsigned long last
;
11156 bfd_size_type gpentry
;
11158 if (p
->type
!= bfd_indirect_link_order
)
11160 if (p
->type
== bfd_data_link_order
)
11165 input_section
= p
->u
.indirect
.section
;
11166 input_bfd
= input_section
->owner
;
11168 /* Combine the gptab entries for this input section one
11169 by one. We know that the input gptab entries are
11170 sorted by ascending -G value. */
11171 size
= input_section
->size
;
11173 for (gpentry
= sizeof (Elf32_External_gptab
);
11175 gpentry
+= sizeof (Elf32_External_gptab
))
11177 Elf32_External_gptab ext_gptab
;
11178 Elf32_gptab int_gptab
;
11184 if (! (bfd_get_section_contents
11185 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
11186 sizeof (Elf32_External_gptab
))))
11192 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
11194 val
= int_gptab
.gt_entry
.gt_g_value
;
11195 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
11198 for (look
= 1; look
< c
; look
++)
11200 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
11201 tab
[look
].gt_entry
.gt_bytes
+= add
;
11203 if (tab
[look
].gt_entry
.gt_g_value
== val
)
11209 Elf32_gptab
*new_tab
;
11212 /* We need a new table entry. */
11213 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
11214 new_tab
= bfd_realloc (tab
, amt
);
11215 if (new_tab
== NULL
)
11221 tab
[c
].gt_entry
.gt_g_value
= val
;
11222 tab
[c
].gt_entry
.gt_bytes
= add
;
11224 /* Merge in the size for the next smallest -G
11225 value, since that will be implied by this new
11228 for (look
= 1; look
< c
; look
++)
11230 if (tab
[look
].gt_entry
.gt_g_value
< val
11232 || (tab
[look
].gt_entry
.gt_g_value
11233 > tab
[max
].gt_entry
.gt_g_value
)))
11237 tab
[c
].gt_entry
.gt_bytes
+=
11238 tab
[max
].gt_entry
.gt_bytes
;
11243 last
= int_gptab
.gt_entry
.gt_bytes
;
11246 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11247 elf_link_input_bfd ignores this section. */
11248 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11251 /* The table must be sorted by -G value. */
11253 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
11255 /* Swap out the table. */
11256 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
11257 ext_tab
= bfd_alloc (abfd
, amt
);
11258 if (ext_tab
== NULL
)
11264 for (j
= 0; j
< c
; j
++)
11265 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
11268 o
->size
= c
* sizeof (Elf32_External_gptab
);
11269 o
->contents
= (bfd_byte
*) ext_tab
;
11271 /* Skip this section later on (I don't think this currently
11272 matters, but someday it might). */
11273 o
->map_head
.link_order
= NULL
;
11277 /* Invoke the regular ELF backend linker to do all the work. */
11278 if (!bfd_elf_final_link (abfd
, info
))
11281 /* Now write out the computed sections. */
11283 if (reginfo_sec
!= NULL
)
11285 Elf32_External_RegInfo ext
;
11287 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
11288 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
11292 if (mdebug_sec
!= NULL
)
11294 BFD_ASSERT (abfd
->output_has_begun
);
11295 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
11297 mdebug_sec
->filepos
))
11300 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
11303 if (gptab_data_sec
!= NULL
)
11305 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
11306 gptab_data_sec
->contents
,
11307 0, gptab_data_sec
->size
))
11311 if (gptab_bss_sec
!= NULL
)
11313 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
11314 gptab_bss_sec
->contents
,
11315 0, gptab_bss_sec
->size
))
11319 if (SGI_COMPAT (abfd
))
11321 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11322 if (rtproc_sec
!= NULL
)
11324 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
11325 rtproc_sec
->contents
,
11326 0, rtproc_sec
->size
))
11334 /* Structure for saying that BFD machine EXTENSION extends BASE. */
11336 struct mips_mach_extension
{
11337 unsigned long extension
, base
;
11341 /* An array describing how BFD machines relate to one another. The entries
11342 are ordered topologically with MIPS I extensions listed last. */
11344 static const struct mips_mach_extension mips_mach_extensions
[] = {
11345 /* MIPS64r2 extensions. */
11346 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
11348 /* MIPS64 extensions. */
11349 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
11350 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
11352 /* MIPS V extensions. */
11353 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
11355 /* R10000 extensions. */
11356 { bfd_mach_mips12000
, bfd_mach_mips10000
},
11358 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
11359 vr5400 ISA, but doesn't include the multimedia stuff. It seems
11360 better to allow vr5400 and vr5500 code to be merged anyway, since
11361 many libraries will just use the core ISA. Perhaps we could add
11362 some sort of ASE flag if this ever proves a problem. */
11363 { bfd_mach_mips5500
, bfd_mach_mips5400
},
11364 { bfd_mach_mips5400
, bfd_mach_mips5000
},
11366 /* MIPS IV extensions. */
11367 { bfd_mach_mips5
, bfd_mach_mips8000
},
11368 { bfd_mach_mips10000
, bfd_mach_mips8000
},
11369 { bfd_mach_mips5000
, bfd_mach_mips8000
},
11370 { bfd_mach_mips7000
, bfd_mach_mips8000
},
11371 { bfd_mach_mips9000
, bfd_mach_mips8000
},
11373 /* VR4100 extensions. */
11374 { bfd_mach_mips4120
, bfd_mach_mips4100
},
11375 { bfd_mach_mips4111
, bfd_mach_mips4100
},
11377 /* MIPS III extensions. */
11378 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
11379 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
11380 { bfd_mach_mips8000
, bfd_mach_mips4000
},
11381 { bfd_mach_mips4650
, bfd_mach_mips4000
},
11382 { bfd_mach_mips4600
, bfd_mach_mips4000
},
11383 { bfd_mach_mips4400
, bfd_mach_mips4000
},
11384 { bfd_mach_mips4300
, bfd_mach_mips4000
},
11385 { bfd_mach_mips4100
, bfd_mach_mips4000
},
11386 { bfd_mach_mips4010
, bfd_mach_mips4000
},
11388 /* MIPS32 extensions. */
11389 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
11391 /* MIPS II extensions. */
11392 { bfd_mach_mips4000
, bfd_mach_mips6000
},
11393 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
11395 /* MIPS I extensions. */
11396 { bfd_mach_mips6000
, bfd_mach_mips3000
},
11397 { bfd_mach_mips3900
, bfd_mach_mips3000
}
11401 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
11404 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
11408 if (extension
== base
)
11411 if (base
== bfd_mach_mipsisa32
11412 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
11415 if (base
== bfd_mach_mipsisa32r2
11416 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
11419 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
11420 if (extension
== mips_mach_extensions
[i
].extension
)
11422 extension
= mips_mach_extensions
[i
].base
;
11423 if (extension
== base
)
11431 /* Return true if the given ELF header flags describe a 32-bit binary. */
11434 mips_32bit_flags_p (flagword flags
)
11436 return ((flags
& EF_MIPS_32BITMODE
) != 0
11437 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
11438 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
11439 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
11440 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
11441 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
11442 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
11446 /* Merge object attributes from IBFD into OBFD. Raise an error if
11447 there are conflicting attributes. */
11449 mips_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
11451 obj_attribute
*in_attr
;
11452 obj_attribute
*out_attr
;
11454 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
11456 /* This is the first object. Copy the attributes. */
11457 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
11459 /* Use the Tag_null value to indicate the attributes have been
11461 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
11466 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
11467 non-conflicting ones. */
11468 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
11469 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
11470 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11472 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
11473 if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
11474 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
11475 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
11477 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
11479 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
11480 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
11481 else if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
11483 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
11484 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
11486 switch (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11489 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11493 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
11499 (_("Warning: %B uses hard float, %B uses soft float"),
11505 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
11515 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11519 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
11525 (_("Warning: %B uses hard float, %B uses soft float"),
11531 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
11541 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11547 (_("Warning: %B uses hard float, %B uses soft float"),
11557 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11561 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
11567 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
11573 (_("Warning: %B uses hard float, %B uses soft float"),
11587 /* Merge Tag_compatibility attributes and any common GNU ones. */
11588 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
11593 /* Merge backend specific data from an object file to the output
11594 object file when linking. */
11597 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
11599 flagword old_flags
;
11600 flagword new_flags
;
11602 bfd_boolean null_input_bfd
= TRUE
;
11605 /* Check if we have the same endianess */
11606 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
11608 (*_bfd_error_handler
)
11609 (_("%B: endianness incompatible with that of the selected emulation"),
11614 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
11615 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
11618 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
11620 (*_bfd_error_handler
)
11621 (_("%B: ABI is incompatible with that of the selected emulation"),
11626 if (!mips_elf_merge_obj_attributes (ibfd
, obfd
))
11629 new_flags
= elf_elfheader (ibfd
)->e_flags
;
11630 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
11631 old_flags
= elf_elfheader (obfd
)->e_flags
;
11633 if (! elf_flags_init (obfd
))
11635 elf_flags_init (obfd
) = TRUE
;
11636 elf_elfheader (obfd
)->e_flags
= new_flags
;
11637 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
11638 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
11640 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
11641 && (bfd_get_arch_info (obfd
)->the_default
11642 || mips_mach_extends_p (bfd_get_mach (obfd
),
11643 bfd_get_mach (ibfd
))))
11645 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
11646 bfd_get_mach (ibfd
)))
11653 /* Check flag compatibility. */
11655 new_flags
&= ~EF_MIPS_NOREORDER
;
11656 old_flags
&= ~EF_MIPS_NOREORDER
;
11658 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
11659 doesn't seem to matter. */
11660 new_flags
&= ~EF_MIPS_XGOT
;
11661 old_flags
&= ~EF_MIPS_XGOT
;
11663 /* MIPSpro generates ucode info in n64 objects. Again, we should
11664 just be able to ignore this. */
11665 new_flags
&= ~EF_MIPS_UCODE
;
11666 old_flags
&= ~EF_MIPS_UCODE
;
11668 /* Don't care about the PIC flags from dynamic objects; they are
11670 if ((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0
11671 && (ibfd
->flags
& DYNAMIC
) != 0)
11672 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11674 if (new_flags
== old_flags
)
11677 /* Check to see if the input BFD actually contains any sections.
11678 If not, its flags may not have been initialised either, but it cannot
11679 actually cause any incompatibility. */
11680 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
11682 /* Ignore synthetic sections and empty .text, .data and .bss sections
11683 which are automatically generated by gas. */
11684 if (strcmp (sec
->name
, ".reginfo")
11685 && strcmp (sec
->name
, ".mdebug")
11687 || (strcmp (sec
->name
, ".text")
11688 && strcmp (sec
->name
, ".data")
11689 && strcmp (sec
->name
, ".bss"))))
11691 null_input_bfd
= FALSE
;
11695 if (null_input_bfd
)
11700 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
11701 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
11703 (*_bfd_error_handler
)
11704 (_("%B: warning: linking PIC files with non-PIC files"),
11709 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
11710 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
11711 if (! (new_flags
& EF_MIPS_PIC
))
11712 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
11714 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11715 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11717 /* Compare the ISAs. */
11718 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
11720 (*_bfd_error_handler
)
11721 (_("%B: linking 32-bit code with 64-bit code"),
11725 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
11727 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
11728 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
11730 /* Copy the architecture info from IBFD to OBFD. Also copy
11731 the 32-bit flag (if set) so that we continue to recognise
11732 OBFD as a 32-bit binary. */
11733 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
11734 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
11735 elf_elfheader (obfd
)->e_flags
11736 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11738 /* Copy across the ABI flags if OBFD doesn't use them
11739 and if that was what caused us to treat IBFD as 32-bit. */
11740 if ((old_flags
& EF_MIPS_ABI
) == 0
11741 && mips_32bit_flags_p (new_flags
)
11742 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
11743 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
11747 /* The ISAs aren't compatible. */
11748 (*_bfd_error_handler
)
11749 (_("%B: linking %s module with previous %s modules"),
11751 bfd_printable_name (ibfd
),
11752 bfd_printable_name (obfd
));
11757 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11758 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11760 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
11761 does set EI_CLASS differently from any 32-bit ABI. */
11762 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
11763 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
11764 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
11766 /* Only error if both are set (to different values). */
11767 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
11768 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
11769 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
11771 (*_bfd_error_handler
)
11772 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
11774 elf_mips_abi_name (ibfd
),
11775 elf_mips_abi_name (obfd
));
11778 new_flags
&= ~EF_MIPS_ABI
;
11779 old_flags
&= ~EF_MIPS_ABI
;
11782 /* For now, allow arbitrary mixing of ASEs (retain the union). */
11783 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
11785 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
11787 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
11788 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
11791 /* Warn about any other mismatches */
11792 if (new_flags
!= old_flags
)
11794 (*_bfd_error_handler
)
11795 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
11796 ibfd
, (unsigned long) new_flags
,
11797 (unsigned long) old_flags
);
11803 bfd_set_error (bfd_error_bad_value
);
11810 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
11813 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
11815 BFD_ASSERT (!elf_flags_init (abfd
)
11816 || elf_elfheader (abfd
)->e_flags
== flags
);
11818 elf_elfheader (abfd
)->e_flags
= flags
;
11819 elf_flags_init (abfd
) = TRUE
;
11824 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
11828 default: return "";
11829 case DT_MIPS_RLD_VERSION
:
11830 return "MIPS_RLD_VERSION";
11831 case DT_MIPS_TIME_STAMP
:
11832 return "MIPS_TIME_STAMP";
11833 case DT_MIPS_ICHECKSUM
:
11834 return "MIPS_ICHECKSUM";
11835 case DT_MIPS_IVERSION
:
11836 return "MIPS_IVERSION";
11837 case DT_MIPS_FLAGS
:
11838 return "MIPS_FLAGS";
11839 case DT_MIPS_BASE_ADDRESS
:
11840 return "MIPS_BASE_ADDRESS";
11842 return "MIPS_MSYM";
11843 case DT_MIPS_CONFLICT
:
11844 return "MIPS_CONFLICT";
11845 case DT_MIPS_LIBLIST
:
11846 return "MIPS_LIBLIST";
11847 case DT_MIPS_LOCAL_GOTNO
:
11848 return "MIPS_LOCAL_GOTNO";
11849 case DT_MIPS_CONFLICTNO
:
11850 return "MIPS_CONFLICTNO";
11851 case DT_MIPS_LIBLISTNO
:
11852 return "MIPS_LIBLISTNO";
11853 case DT_MIPS_SYMTABNO
:
11854 return "MIPS_SYMTABNO";
11855 case DT_MIPS_UNREFEXTNO
:
11856 return "MIPS_UNREFEXTNO";
11857 case DT_MIPS_GOTSYM
:
11858 return "MIPS_GOTSYM";
11859 case DT_MIPS_HIPAGENO
:
11860 return "MIPS_HIPAGENO";
11861 case DT_MIPS_RLD_MAP
:
11862 return "MIPS_RLD_MAP";
11863 case DT_MIPS_DELTA_CLASS
:
11864 return "MIPS_DELTA_CLASS";
11865 case DT_MIPS_DELTA_CLASS_NO
:
11866 return "MIPS_DELTA_CLASS_NO";
11867 case DT_MIPS_DELTA_INSTANCE
:
11868 return "MIPS_DELTA_INSTANCE";
11869 case DT_MIPS_DELTA_INSTANCE_NO
:
11870 return "MIPS_DELTA_INSTANCE_NO";
11871 case DT_MIPS_DELTA_RELOC
:
11872 return "MIPS_DELTA_RELOC";
11873 case DT_MIPS_DELTA_RELOC_NO
:
11874 return "MIPS_DELTA_RELOC_NO";
11875 case DT_MIPS_DELTA_SYM
:
11876 return "MIPS_DELTA_SYM";
11877 case DT_MIPS_DELTA_SYM_NO
:
11878 return "MIPS_DELTA_SYM_NO";
11879 case DT_MIPS_DELTA_CLASSSYM
:
11880 return "MIPS_DELTA_CLASSSYM";
11881 case DT_MIPS_DELTA_CLASSSYM_NO
:
11882 return "MIPS_DELTA_CLASSSYM_NO";
11883 case DT_MIPS_CXX_FLAGS
:
11884 return "MIPS_CXX_FLAGS";
11885 case DT_MIPS_PIXIE_INIT
:
11886 return "MIPS_PIXIE_INIT";
11887 case DT_MIPS_SYMBOL_LIB
:
11888 return "MIPS_SYMBOL_LIB";
11889 case DT_MIPS_LOCALPAGE_GOTIDX
:
11890 return "MIPS_LOCALPAGE_GOTIDX";
11891 case DT_MIPS_LOCAL_GOTIDX
:
11892 return "MIPS_LOCAL_GOTIDX";
11893 case DT_MIPS_HIDDEN_GOTIDX
:
11894 return "MIPS_HIDDEN_GOTIDX";
11895 case DT_MIPS_PROTECTED_GOTIDX
:
11896 return "MIPS_PROTECTED_GOT_IDX";
11897 case DT_MIPS_OPTIONS
:
11898 return "MIPS_OPTIONS";
11899 case DT_MIPS_INTERFACE
:
11900 return "MIPS_INTERFACE";
11901 case DT_MIPS_DYNSTR_ALIGN
:
11902 return "DT_MIPS_DYNSTR_ALIGN";
11903 case DT_MIPS_INTERFACE_SIZE
:
11904 return "DT_MIPS_INTERFACE_SIZE";
11905 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
11906 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
11907 case DT_MIPS_PERF_SUFFIX
:
11908 return "DT_MIPS_PERF_SUFFIX";
11909 case DT_MIPS_COMPACT_SIZE
:
11910 return "DT_MIPS_COMPACT_SIZE";
11911 case DT_MIPS_GP_VALUE
:
11912 return "DT_MIPS_GP_VALUE";
11913 case DT_MIPS_AUX_DYNAMIC
:
11914 return "DT_MIPS_AUX_DYNAMIC";
11919 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
11923 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
11925 /* Print normal ELF private data. */
11926 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
11928 /* xgettext:c-format */
11929 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
11931 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
11932 fprintf (file
, _(" [abi=O32]"));
11933 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
11934 fprintf (file
, _(" [abi=O64]"));
11935 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
11936 fprintf (file
, _(" [abi=EABI32]"));
11937 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
11938 fprintf (file
, _(" [abi=EABI64]"));
11939 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
11940 fprintf (file
, _(" [abi unknown]"));
11941 else if (ABI_N32_P (abfd
))
11942 fprintf (file
, _(" [abi=N32]"));
11943 else if (ABI_64_P (abfd
))
11944 fprintf (file
, _(" [abi=64]"));
11946 fprintf (file
, _(" [no abi set]"));
11948 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
11949 fprintf (file
, " [mips1]");
11950 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
11951 fprintf (file
, " [mips2]");
11952 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
11953 fprintf (file
, " [mips3]");
11954 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
11955 fprintf (file
, " [mips4]");
11956 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
11957 fprintf (file
, " [mips5]");
11958 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
11959 fprintf (file
, " [mips32]");
11960 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
11961 fprintf (file
, " [mips64]");
11962 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
11963 fprintf (file
, " [mips32r2]");
11964 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
11965 fprintf (file
, " [mips64r2]");
11967 fprintf (file
, _(" [unknown ISA]"));
11969 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
11970 fprintf (file
, " [mdmx]");
11972 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
11973 fprintf (file
, " [mips16]");
11975 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
11976 fprintf (file
, " [32bitmode]");
11978 fprintf (file
, _(" [not 32bitmode]"));
11980 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
11981 fprintf (file
, " [noreorder]");
11983 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
11984 fprintf (file
, " [PIC]");
11986 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
11987 fprintf (file
, " [CPIC]");
11989 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
11990 fprintf (file
, " [XGOT]");
11992 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
11993 fprintf (file
, " [UCODE]");
11995 fputc ('\n', file
);
12000 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
12002 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12003 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12004 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
12005 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12006 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12007 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
12008 { NULL
, 0, 0, 0, 0 }
12011 /* Merge non visibility st_other attributes. Ensure that the
12012 STO_OPTIONAL flag is copied into h->other, even if this is not a
12013 definiton of the symbol. */
12015 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
12016 const Elf_Internal_Sym
*isym
,
12017 bfd_boolean definition
,
12018 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
12020 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
12022 unsigned char other
;
12024 other
= (definition
? isym
->st_other
: h
->other
);
12025 other
&= ~ELF_ST_VISIBILITY (-1);
12026 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
12030 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
12031 h
->other
|= STO_OPTIONAL
;
12034 /* Decide whether an undefined symbol is special and can be ignored.
12035 This is the case for OPTIONAL symbols on IRIX. */
12037 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
12039 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
12043 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
12045 return (sym
->st_shndx
== SHN_COMMON
12046 || sym
->st_shndx
== SHN_MIPS_ACOMMON
12047 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);