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 .got slots used for TLS. */
149 unsigned int tls_gotno
;
150 /* The first unused TLS .got entry. Used only during
151 mips_elf_initialize_tls_index. */
152 unsigned int tls_assigned_gotno
;
153 /* The number of local .got entries, eventually including page entries. */
154 unsigned int local_gotno
;
155 /* The maximum number of page entries needed. */
156 unsigned int page_gotno
;
157 /* The number of local .got entries we have used. */
158 unsigned int assigned_gotno
;
159 /* A hash table holding members of the got. */
160 struct htab
*got_entries
;
161 /* A hash table of mips_got_page_entry structures. */
162 struct htab
*got_page_entries
;
163 /* A hash table mapping input bfds to other mips_got_info. NULL
164 unless multi-got was necessary. */
165 struct htab
*bfd2got
;
166 /* In multi-got links, a pointer to the next got (err, rather, most
167 of the time, it points to the previous got). */
168 struct mips_got_info
*next
;
169 /* This is the GOT index of the TLS LDM entry for the GOT, MINUS_ONE
170 for none, or MINUS_TWO for not yet assigned. This is needed
171 because a single-GOT link may have multiple hash table entries
172 for the LDM. It does not get initialized in multi-GOT mode. */
173 bfd_vma tls_ldm_offset
;
176 /* Map an input bfd to a got in a multi-got link. */
178 struct mips_elf_bfd2got_hash
{
180 struct mips_got_info
*g
;
183 /* Structure passed when traversing the bfd2got hash table, used to
184 create and merge bfd's gots. */
186 struct mips_elf_got_per_bfd_arg
188 /* A hashtable that maps bfds to gots. */
190 /* The output bfd. */
192 /* The link information. */
193 struct bfd_link_info
*info
;
194 /* A pointer to the primary got, i.e., the one that's going to get
195 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
197 struct mips_got_info
*primary
;
198 /* A non-primary got we're trying to merge with other input bfd's
200 struct mips_got_info
*current
;
201 /* The maximum number of got entries that can be addressed with a
203 unsigned int max_count
;
204 /* The maximum number of page entries needed by each got. */
205 unsigned int max_pages
;
206 /* The total number of global entries which will live in the
207 primary got and be automatically relocated. This includes
208 those not referenced by the primary GOT but included in
210 unsigned int global_count
;
213 /* Another structure used to pass arguments for got entries traversal. */
215 struct mips_elf_set_global_got_offset_arg
217 struct mips_got_info
*g
;
219 unsigned int needed_relocs
;
220 struct bfd_link_info
*info
;
223 /* A structure used to count TLS relocations or GOT entries, for GOT
224 entry or ELF symbol table traversal. */
226 struct mips_elf_count_tls_arg
228 struct bfd_link_info
*info
;
232 struct _mips_elf_section_data
234 struct bfd_elf_section_data elf
;
241 #define mips_elf_section_data(sec) \
242 ((struct _mips_elf_section_data *) elf_section_data (sec))
244 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
245 the dynamic symbols. */
247 struct mips_elf_hash_sort_data
249 /* The symbol in the global GOT with the lowest dynamic symbol table
251 struct elf_link_hash_entry
*low
;
252 /* The least dynamic symbol table index corresponding to a non-TLS
253 symbol with a GOT entry. */
254 long min_got_dynindx
;
255 /* The greatest dynamic symbol table index corresponding to a symbol
256 with a GOT entry that is not referenced (e.g., a dynamic symbol
257 with dynamic relocations pointing to it from non-primary GOTs). */
258 long max_unref_got_dynindx
;
259 /* The greatest dynamic symbol table index not corresponding to a
260 symbol without a GOT entry. */
261 long max_non_got_dynindx
;
264 /* The MIPS ELF linker needs additional information for each symbol in
265 the global hash table. */
267 struct mips_elf_link_hash_entry
269 struct elf_link_hash_entry root
;
271 /* External symbol information. */
274 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
276 unsigned int possibly_dynamic_relocs
;
278 /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
279 a readonly section. */
280 bfd_boolean readonly_reloc
;
282 /* We must not create a stub for a symbol that has relocations
283 related to taking the function's address, i.e. any but
284 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
286 bfd_boolean no_fn_stub
;
288 /* If there is a stub that 32 bit functions should use to call this
289 16 bit function, this points to the section containing the stub. */
292 /* Whether we need the fn_stub; this is set if this symbol appears
293 in any relocs other than a 16 bit call. */
294 bfd_boolean need_fn_stub
;
296 /* If there is a stub that 16 bit functions should use to call this
297 32 bit function, this points to the section containing the stub. */
300 /* This is like the call_stub field, but it is used if the function
301 being called returns a floating point value. */
302 asection
*call_fp_stub
;
304 /* Are we forced local? This will only be set if we have converted
305 the initial global GOT entry to a local GOT entry. */
306 bfd_boolean forced_local
;
308 /* Are we referenced by some kind of relocation? */
309 bfd_boolean is_relocation_target
;
311 /* Are we referenced by branch relocations? */
312 bfd_boolean is_branch_target
;
316 #define GOT_TLS_LDM 2
318 #define GOT_TLS_OFFSET_DONE 0x40
319 #define GOT_TLS_DONE 0x80
320 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
;
330 /* MIPS ELF linker hash table. */
332 struct mips_elf_link_hash_table
334 struct elf_link_hash_table root
;
336 /* We no longer use this. */
337 /* String section indices for the dynamic section symbols. */
338 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
340 /* The number of .rtproc entries. */
341 bfd_size_type procedure_count
;
342 /* The size of the .compact_rel section (if SGI_COMPAT). */
343 bfd_size_type compact_rel_size
;
344 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
345 entry is set to the address of __rld_obj_head as in IRIX5. */
346 bfd_boolean use_rld_obj_head
;
347 /* This is the value of the __rld_map or __rld_obj_head symbol. */
349 /* This is set if we see any mips16 stub sections. */
350 bfd_boolean mips16_stubs_seen
;
351 /* True if we've computed the size of the GOT. */
352 bfd_boolean computed_got_sizes
;
353 /* True if we're generating code for VxWorks. */
354 bfd_boolean is_vxworks
;
355 /* True if we already reported the small-data section overflow. */
356 bfd_boolean small_data_overflow_reported
;
357 /* Shortcuts to some dynamic sections, or NULL if they are not
367 /* The master GOT information. */
368 struct mips_got_info
*got_info
;
369 /* The size of the PLT header in bytes (VxWorks only). */
370 bfd_vma plt_header_size
;
371 /* The size of a PLT entry in bytes (VxWorks only). */
372 bfd_vma plt_entry_size
;
373 /* The size of a function stub entry in bytes. */
374 bfd_vma function_stub_size
;
377 #define TLS_RELOC_P(r_type) \
378 (r_type == R_MIPS_TLS_DTPMOD32 \
379 || r_type == R_MIPS_TLS_DTPMOD64 \
380 || r_type == R_MIPS_TLS_DTPREL32 \
381 || r_type == R_MIPS_TLS_DTPREL64 \
382 || r_type == R_MIPS_TLS_GD \
383 || r_type == R_MIPS_TLS_LDM \
384 || r_type == R_MIPS_TLS_DTPREL_HI16 \
385 || r_type == R_MIPS_TLS_DTPREL_LO16 \
386 || r_type == R_MIPS_TLS_GOTTPREL \
387 || r_type == R_MIPS_TLS_TPREL32 \
388 || r_type == R_MIPS_TLS_TPREL64 \
389 || r_type == R_MIPS_TLS_TPREL_HI16 \
390 || r_type == R_MIPS_TLS_TPREL_LO16)
392 /* Structure used to pass information to mips_elf_output_extsym. */
397 struct bfd_link_info
*info
;
398 struct ecoff_debug_info
*debug
;
399 const struct ecoff_debug_swap
*swap
;
403 /* The names of the runtime procedure table symbols used on IRIX5. */
405 static const char * const mips_elf_dynsym_rtproc_names
[] =
408 "_procedure_string_table",
409 "_procedure_table_size",
413 /* These structures are used to generate the .compact_rel section on
418 unsigned long id1
; /* Always one? */
419 unsigned long num
; /* Number of compact relocation entries. */
420 unsigned long id2
; /* Always two? */
421 unsigned long offset
; /* The file offset of the first relocation. */
422 unsigned long reserved0
; /* Zero? */
423 unsigned long reserved1
; /* Zero? */
432 bfd_byte reserved0
[4];
433 bfd_byte reserved1
[4];
434 } Elf32_External_compact_rel
;
438 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
439 unsigned int rtype
: 4; /* Relocation types. See below. */
440 unsigned int dist2to
: 8;
441 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
442 unsigned long konst
; /* KONST field. See below. */
443 unsigned long vaddr
; /* VADDR to be relocated. */
448 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
449 unsigned int rtype
: 4; /* Relocation types. See below. */
450 unsigned int dist2to
: 8;
451 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
452 unsigned long konst
; /* KONST field. See below. */
460 } Elf32_External_crinfo
;
466 } Elf32_External_crinfo2
;
468 /* These are the constants used to swap the bitfields in a crinfo. */
470 #define CRINFO_CTYPE (0x1)
471 #define CRINFO_CTYPE_SH (31)
472 #define CRINFO_RTYPE (0xf)
473 #define CRINFO_RTYPE_SH (27)
474 #define CRINFO_DIST2TO (0xff)
475 #define CRINFO_DIST2TO_SH (19)
476 #define CRINFO_RELVADDR (0x7ffff)
477 #define CRINFO_RELVADDR_SH (0)
479 /* A compact relocation info has long (3 words) or short (2 words)
480 formats. A short format doesn't have VADDR field and relvaddr
481 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
482 #define CRF_MIPS_LONG 1
483 #define CRF_MIPS_SHORT 0
485 /* There are 4 types of compact relocation at least. The value KONST
486 has different meaning for each type:
489 CT_MIPS_REL32 Address in data
490 CT_MIPS_WORD Address in word (XXX)
491 CT_MIPS_GPHI_LO GP - vaddr
492 CT_MIPS_JMPAD Address to jump
495 #define CRT_MIPS_REL32 0xa
496 #define CRT_MIPS_WORD 0xb
497 #define CRT_MIPS_GPHI_LO 0xc
498 #define CRT_MIPS_JMPAD 0xd
500 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
501 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
502 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
503 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
505 /* The structure of the runtime procedure descriptor created by the
506 loader for use by the static exception system. */
508 typedef struct runtime_pdr
{
509 bfd_vma adr
; /* Memory address of start of procedure. */
510 long regmask
; /* Save register mask. */
511 long regoffset
; /* Save register offset. */
512 long fregmask
; /* Save floating point register mask. */
513 long fregoffset
; /* Save floating point register offset. */
514 long frameoffset
; /* Frame size. */
515 short framereg
; /* Frame pointer register. */
516 short pcreg
; /* Offset or reg of return pc. */
517 long irpss
; /* Index into the runtime string table. */
519 struct exception_info
*exception_info
;/* Pointer to exception array. */
521 #define cbRPDR sizeof (RPDR)
522 #define rpdNil ((pRPDR) 0)
524 static struct mips_got_entry
*mips_elf_create_local_got_entry
525 (bfd
*, struct bfd_link_info
*, bfd
*, bfd_vma
, unsigned long,
526 struct mips_elf_link_hash_entry
*, int);
527 static bfd_boolean mips_elf_sort_hash_table_f
528 (struct mips_elf_link_hash_entry
*, void *);
529 static bfd_vma mips_elf_high
531 static bfd_boolean mips_elf_create_dynamic_relocation
532 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
533 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
534 bfd_vma
*, asection
*);
535 static hashval_t mips_elf_got_entry_hash
537 static bfd_vma mips_elf_adjust_gp
538 (bfd
*, struct mips_got_info
*, bfd
*);
539 static struct mips_got_info
*mips_elf_got_for_ibfd
540 (struct mips_got_info
*, bfd
*);
542 /* This will be used when we sort the dynamic relocation records. */
543 static bfd
*reldyn_sorting_bfd
;
545 /* Nonzero if ABFD is using the N32 ABI. */
546 #define ABI_N32_P(abfd) \
547 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
549 /* Nonzero if ABFD is using the N64 ABI. */
550 #define ABI_64_P(abfd) \
551 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
553 /* Nonzero if ABFD is using NewABI conventions. */
554 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
556 /* The IRIX compatibility level we are striving for. */
557 #define IRIX_COMPAT(abfd) \
558 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
560 /* Whether we are trying to be compatible with IRIX at all. */
561 #define SGI_COMPAT(abfd) \
562 (IRIX_COMPAT (abfd) != ict_none)
564 /* The name of the options section. */
565 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
566 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
568 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
569 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
570 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
571 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
573 /* Whether the section is readonly. */
574 #define MIPS_ELF_READONLY_SECTION(sec) \
575 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
576 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
578 /* The name of the stub section. */
579 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
581 /* The size of an external REL relocation. */
582 #define MIPS_ELF_REL_SIZE(abfd) \
583 (get_elf_backend_data (abfd)->s->sizeof_rel)
585 /* The size of an external RELA relocation. */
586 #define MIPS_ELF_RELA_SIZE(abfd) \
587 (get_elf_backend_data (abfd)->s->sizeof_rela)
589 /* The size of an external dynamic table entry. */
590 #define MIPS_ELF_DYN_SIZE(abfd) \
591 (get_elf_backend_data (abfd)->s->sizeof_dyn)
593 /* The size of a GOT entry. */
594 #define MIPS_ELF_GOT_SIZE(abfd) \
595 (get_elf_backend_data (abfd)->s->arch_size / 8)
597 /* The size of a symbol-table entry. */
598 #define MIPS_ELF_SYM_SIZE(abfd) \
599 (get_elf_backend_data (abfd)->s->sizeof_sym)
601 /* The default alignment for sections, as a power of two. */
602 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
603 (get_elf_backend_data (abfd)->s->log_file_align)
605 /* Get word-sized data. */
606 #define MIPS_ELF_GET_WORD(abfd, ptr) \
607 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
609 /* Put out word-sized data. */
610 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
612 ? bfd_put_64 (abfd, val, ptr) \
613 : bfd_put_32 (abfd, val, ptr))
615 /* Add a dynamic symbol table-entry. */
616 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
617 _bfd_elf_add_dynamic_entry (info, tag, val)
619 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
620 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
622 /* Determine whether the internal relocation of index REL_IDX is REL
623 (zero) or RELA (non-zero). The assumption is that, if there are
624 two relocation sections for this section, one of them is REL and
625 the other is RELA. If the index of the relocation we're testing is
626 in range for the first relocation section, check that the external
627 relocation size is that for RELA. It is also assumed that, if
628 rel_idx is not in range for the first section, and this first
629 section contains REL relocs, then the relocation is in the second
630 section, that is RELA. */
631 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
632 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
633 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
634 > (bfd_vma)(rel_idx)) \
635 == (elf_section_data (sec)->rel_hdr.sh_entsize \
636 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
637 : sizeof (Elf32_External_Rela))))
639 /* The name of the dynamic relocation section. */
640 #define MIPS_ELF_REL_DYN_NAME(INFO) \
641 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
643 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
644 from smaller values. Start with zero, widen, *then* decrement. */
645 #define MINUS_ONE (((bfd_vma)0) - 1)
646 #define MINUS_TWO (((bfd_vma)0) - 2)
648 /* The number of local .got entries we reserve. */
649 #define MIPS_RESERVED_GOTNO(INFO) \
650 (mips_elf_hash_table (INFO)->is_vxworks ? 3 : 2)
652 /* The value to write into got[1] for SVR4 targets, to identify it is
653 a GNU object. The dynamic linker can then use got[1] to store the
655 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
656 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
658 /* The offset of $gp from the beginning of the .got section. */
659 #define ELF_MIPS_GP_OFFSET(INFO) \
660 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
662 /* The maximum size of the GOT for it to be addressable using 16-bit
664 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
666 /* Instructions which appear in a stub. */
667 #define STUB_LW(abfd) \
669 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
670 : 0x8f998010)) /* lw t9,0x8010(gp) */
671 #define STUB_MOVE(abfd) \
673 ? 0x03e0782d /* daddu t7,ra */ \
674 : 0x03e07821)) /* addu t7,ra */
675 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
676 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
677 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
678 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
679 #define STUB_LI16S(abfd, VAL) \
681 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
682 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
684 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
685 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
687 /* The name of the dynamic interpreter. This is put in the .interp
690 #define ELF_DYNAMIC_INTERPRETER(abfd) \
691 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
692 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
693 : "/usr/lib/libc.so.1")
696 #define MNAME(bfd,pre,pos) \
697 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
698 #define ELF_R_SYM(bfd, i) \
699 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
700 #define ELF_R_TYPE(bfd, i) \
701 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
702 #define ELF_R_INFO(bfd, s, t) \
703 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
705 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
706 #define ELF_R_SYM(bfd, i) \
708 #define ELF_R_TYPE(bfd, i) \
710 #define ELF_R_INFO(bfd, s, t) \
711 (ELF32_R_INFO (s, t))
714 /* The mips16 compiler uses a couple of special sections to handle
715 floating point arguments.
717 Section names that look like .mips16.fn.FNNAME contain stubs that
718 copy floating point arguments from the fp regs to the gp regs and
719 then jump to FNNAME. If any 32 bit function calls FNNAME, the
720 call should be redirected to the stub instead. If no 32 bit
721 function calls FNNAME, the stub should be discarded. We need to
722 consider any reference to the function, not just a call, because
723 if the address of the function is taken we will need the stub,
724 since the address might be passed to a 32 bit function.
726 Section names that look like .mips16.call.FNNAME contain stubs
727 that copy floating point arguments from the gp regs to the fp
728 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
729 then any 16 bit function that calls FNNAME should be redirected
730 to the stub instead. If FNNAME is not a 32 bit function, the
731 stub should be discarded.
733 .mips16.call.fp.FNNAME sections are similar, but contain stubs
734 which call FNNAME and then copy the return value from the fp regs
735 to the gp regs. These stubs store the return value in $18 while
736 calling FNNAME; any function which might call one of these stubs
737 must arrange to save $18 around the call. (This case is not
738 needed for 32 bit functions that call 16 bit functions, because
739 16 bit functions always return floating point values in both
742 Note that in all cases FNNAME might be defined statically.
743 Therefore, FNNAME is not used literally. Instead, the relocation
744 information will indicate which symbol the section is for.
746 We record any stubs that we find in the symbol table. */
748 #define FN_STUB ".mips16.fn."
749 #define CALL_STUB ".mips16.call."
750 #define CALL_FP_STUB ".mips16.call.fp."
752 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
753 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
754 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
756 /* The format of the first PLT entry in a VxWorks executable. */
757 static const bfd_vma mips_vxworks_exec_plt0_entry
[] = {
758 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
759 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
760 0x8f390008, /* lw t9, 8(t9) */
761 0x00000000, /* nop */
762 0x03200008, /* jr t9 */
766 /* The format of subsequent PLT entries. */
767 static const bfd_vma mips_vxworks_exec_plt_entry
[] = {
768 0x10000000, /* b .PLT_resolver */
769 0x24180000, /* li t8, <pltindex> */
770 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
771 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
772 0x8f390000, /* lw t9, 0(t9) */
773 0x00000000, /* nop */
774 0x03200008, /* jr t9 */
778 /* The format of the first PLT entry in a VxWorks shared object. */
779 static const bfd_vma mips_vxworks_shared_plt0_entry
[] = {
780 0x8f990008, /* lw t9, 8(gp) */
781 0x00000000, /* nop */
782 0x03200008, /* jr t9 */
783 0x00000000, /* nop */
784 0x00000000, /* nop */
788 /* The format of subsequent PLT entries. */
789 static const bfd_vma mips_vxworks_shared_plt_entry
[] = {
790 0x10000000, /* b .PLT_resolver */
791 0x24180000 /* li t8, <pltindex> */
794 /* Look up an entry in a MIPS ELF linker hash table. */
796 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
797 ((struct mips_elf_link_hash_entry *) \
798 elf_link_hash_lookup (&(table)->root, (string), (create), \
801 /* Traverse a MIPS ELF linker hash table. */
803 #define mips_elf_link_hash_traverse(table, func, info) \
804 (elf_link_hash_traverse \
806 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
809 /* Get the MIPS ELF linker hash table from a link_info structure. */
811 #define mips_elf_hash_table(p) \
812 ((struct mips_elf_link_hash_table *) ((p)->hash))
814 /* Find the base offsets for thread-local storage in this object,
815 for GD/LD and IE/LE respectively. */
817 #define TP_OFFSET 0x7000
818 #define DTP_OFFSET 0x8000
821 dtprel_base (struct bfd_link_info
*info
)
823 /* If tls_sec is NULL, we should have signalled an error already. */
824 if (elf_hash_table (info
)->tls_sec
== NULL
)
826 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
830 tprel_base (struct bfd_link_info
*info
)
832 /* If tls_sec is NULL, we should have signalled an error already. */
833 if (elf_hash_table (info
)->tls_sec
== NULL
)
835 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
838 /* Create an entry in a MIPS ELF linker hash table. */
840 static struct bfd_hash_entry
*
841 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
842 struct bfd_hash_table
*table
, const char *string
)
844 struct mips_elf_link_hash_entry
*ret
=
845 (struct mips_elf_link_hash_entry
*) entry
;
847 /* Allocate the structure if it has not already been allocated by a
850 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
852 return (struct bfd_hash_entry
*) ret
;
854 /* Call the allocation method of the superclass. */
855 ret
= ((struct mips_elf_link_hash_entry
*)
856 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
860 /* Set local fields. */
861 memset (&ret
->esym
, 0, sizeof (EXTR
));
862 /* We use -2 as a marker to indicate that the information has
863 not been set. -1 means there is no associated ifd. */
865 ret
->possibly_dynamic_relocs
= 0;
866 ret
->readonly_reloc
= FALSE
;
867 ret
->no_fn_stub
= FALSE
;
869 ret
->need_fn_stub
= FALSE
;
870 ret
->call_stub
= NULL
;
871 ret
->call_fp_stub
= NULL
;
872 ret
->forced_local
= FALSE
;
873 ret
->is_branch_target
= FALSE
;
874 ret
->is_relocation_target
= FALSE
;
875 ret
->tls_type
= GOT_NORMAL
;
878 return (struct bfd_hash_entry
*) ret
;
882 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
884 if (!sec
->used_by_bfd
)
886 struct _mips_elf_section_data
*sdata
;
887 bfd_size_type amt
= sizeof (*sdata
);
889 sdata
= bfd_zalloc (abfd
, amt
);
892 sec
->used_by_bfd
= sdata
;
895 return _bfd_elf_new_section_hook (abfd
, sec
);
898 /* Read ECOFF debugging information from a .mdebug section into a
899 ecoff_debug_info structure. */
902 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
903 struct ecoff_debug_info
*debug
)
906 const struct ecoff_debug_swap
*swap
;
909 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
910 memset (debug
, 0, sizeof (*debug
));
912 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
913 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
916 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
917 swap
->external_hdr_size
))
920 symhdr
= &debug
->symbolic_header
;
921 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
923 /* The symbolic header contains absolute file offsets and sizes to
925 #define READ(ptr, offset, count, size, type) \
926 if (symhdr->count == 0) \
930 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
931 debug->ptr = bfd_malloc (amt); \
932 if (debug->ptr == NULL) \
934 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
935 || bfd_bread (debug->ptr, amt, abfd) != amt) \
939 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
940 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
941 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
942 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
943 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
944 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
946 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
947 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
948 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
949 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
950 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
960 if (debug
->line
!= NULL
)
962 if (debug
->external_dnr
!= NULL
)
963 free (debug
->external_dnr
);
964 if (debug
->external_pdr
!= NULL
)
965 free (debug
->external_pdr
);
966 if (debug
->external_sym
!= NULL
)
967 free (debug
->external_sym
);
968 if (debug
->external_opt
!= NULL
)
969 free (debug
->external_opt
);
970 if (debug
->external_aux
!= NULL
)
971 free (debug
->external_aux
);
972 if (debug
->ss
!= NULL
)
974 if (debug
->ssext
!= NULL
)
976 if (debug
->external_fdr
!= NULL
)
977 free (debug
->external_fdr
);
978 if (debug
->external_rfd
!= NULL
)
979 free (debug
->external_rfd
);
980 if (debug
->external_ext
!= NULL
)
981 free (debug
->external_ext
);
985 /* Swap RPDR (runtime procedure table entry) for output. */
988 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
990 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
991 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
992 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
993 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
994 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
995 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
997 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
998 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1000 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1003 /* Create a runtime procedure table from the .mdebug section. */
1006 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1007 struct bfd_link_info
*info
, asection
*s
,
1008 struct ecoff_debug_info
*debug
)
1010 const struct ecoff_debug_swap
*swap
;
1011 HDRR
*hdr
= &debug
->symbolic_header
;
1013 struct rpdr_ext
*erp
;
1015 struct pdr_ext
*epdr
;
1016 struct sym_ext
*esym
;
1020 bfd_size_type count
;
1021 unsigned long sindex
;
1025 const char *no_name_func
= _("static procedure (no name)");
1033 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1035 sindex
= strlen (no_name_func
) + 1;
1036 count
= hdr
->ipdMax
;
1039 size
= swap
->external_pdr_size
;
1041 epdr
= bfd_malloc (size
* count
);
1045 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1048 size
= sizeof (RPDR
);
1049 rp
= rpdr
= bfd_malloc (size
* count
);
1053 size
= sizeof (char *);
1054 sv
= bfd_malloc (size
* count
);
1058 count
= hdr
->isymMax
;
1059 size
= swap
->external_sym_size
;
1060 esym
= bfd_malloc (size
* count
);
1064 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1067 count
= hdr
->issMax
;
1068 ss
= bfd_malloc (count
);
1071 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1074 count
= hdr
->ipdMax
;
1075 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1077 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1078 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1079 rp
->adr
= sym
.value
;
1080 rp
->regmask
= pdr
.regmask
;
1081 rp
->regoffset
= pdr
.regoffset
;
1082 rp
->fregmask
= pdr
.fregmask
;
1083 rp
->fregoffset
= pdr
.fregoffset
;
1084 rp
->frameoffset
= pdr
.frameoffset
;
1085 rp
->framereg
= pdr
.framereg
;
1086 rp
->pcreg
= pdr
.pcreg
;
1088 sv
[i
] = ss
+ sym
.iss
;
1089 sindex
+= strlen (sv
[i
]) + 1;
1093 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1094 size
= BFD_ALIGN (size
, 16);
1095 rtproc
= bfd_alloc (abfd
, size
);
1098 mips_elf_hash_table (info
)->procedure_count
= 0;
1102 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1105 memset (erp
, 0, sizeof (struct rpdr_ext
));
1107 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1108 strcpy (str
, no_name_func
);
1109 str
+= strlen (no_name_func
) + 1;
1110 for (i
= 0; i
< count
; i
++)
1112 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1113 strcpy (str
, sv
[i
]);
1114 str
+= strlen (sv
[i
]) + 1;
1116 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1118 /* Set the size and contents of .rtproc section. */
1120 s
->contents
= rtproc
;
1122 /* Skip this section later on (I don't think this currently
1123 matters, but someday it might). */
1124 s
->map_head
.link_order
= NULL
;
1153 /* We're about to redefine H. Create a symbol to represent H's
1154 current value and size, to help make the disassembly easier
1158 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1159 struct mips_elf_link_hash_entry
*h
,
1162 struct bfd_link_hash_entry
*bh
;
1163 struct elf_link_hash_entry
*elfh
;
1168 /* Read the symbol's value. */
1169 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1170 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1171 s
= h
->root
.root
.u
.def
.section
;
1172 value
= h
->root
.root
.u
.def
.value
;
1174 /* Create a new symbol. */
1175 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1177 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1178 BSF_LOCAL
, s
, value
, NULL
,
1182 /* Make it local and copy the other attributes from H. */
1183 elfh
= (struct elf_link_hash_entry
*) bh
;
1184 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1185 elfh
->other
= h
->root
.other
;
1186 elfh
->size
= h
->root
.size
;
1187 elfh
->forced_local
= 1;
1191 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1192 function rather than to a hard-float stub. */
1195 section_allows_mips16_refs_p (asection
*section
)
1199 name
= bfd_get_section_name (section
->owner
, section
);
1200 return (FN_STUB_P (name
)
1201 || CALL_STUB_P (name
)
1202 || CALL_FP_STUB_P (name
)
1203 || strcmp (name
, ".pdr") == 0);
1206 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1207 stub section of some kind. Return the R_SYMNDX of the target
1208 function, or 0 if we can't decide which function that is. */
1210 static unsigned long
1211 mips16_stub_symndx (asection
*sec
, const Elf_Internal_Rela
*relocs
,
1212 const Elf_Internal_Rela
*relend
)
1214 const Elf_Internal_Rela
*rel
;
1216 /* Trust the first R_MIPS_NONE relocation, if any. */
1217 for (rel
= relocs
; rel
< relend
; rel
++)
1218 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1219 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1221 /* Otherwise trust the first relocation, whatever its kind. This is
1222 the traditional behavior. */
1223 if (relocs
< relend
)
1224 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1229 /* Check the mips16 stubs for a particular symbol, and see if we can
1233 mips_elf_check_mips16_stubs (struct mips_elf_link_hash_entry
*h
, void *data
)
1235 struct bfd_link_info
*info
;
1237 info
= (struct bfd_link_info
*) data
;
1238 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1239 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1241 /* Dynamic symbols must use the standard call interface, in case other
1242 objects try to call them. */
1243 if (h
->fn_stub
!= NULL
1244 && h
->root
.dynindx
!= -1)
1246 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1247 h
->need_fn_stub
= TRUE
;
1250 if (h
->fn_stub
!= NULL
1251 && ! h
->need_fn_stub
)
1253 /* We don't need the fn_stub; the only references to this symbol
1254 are 16 bit calls. Clobber the size to 0 to prevent it from
1255 being included in the link. */
1256 h
->fn_stub
->size
= 0;
1257 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1258 h
->fn_stub
->reloc_count
= 0;
1259 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1262 if (h
->call_stub
!= NULL
1263 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1265 /* We don't need the call_stub; this is a 16 bit function, so
1266 calls from other 16 bit functions are OK. Clobber the size
1267 to 0 to prevent it from being included in the link. */
1268 h
->call_stub
->size
= 0;
1269 h
->call_stub
->flags
&= ~SEC_RELOC
;
1270 h
->call_stub
->reloc_count
= 0;
1271 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1274 if (h
->call_fp_stub
!= NULL
1275 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1277 /* We don't need the call_stub; this is a 16 bit function, so
1278 calls from other 16 bit functions are OK. Clobber the size
1279 to 0 to prevent it from being included in the link. */
1280 h
->call_fp_stub
->size
= 0;
1281 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1282 h
->call_fp_stub
->reloc_count
= 0;
1283 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1289 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1290 Most mips16 instructions are 16 bits, but these instructions
1293 The format of these instructions is:
1295 +--------------+--------------------------------+
1296 | JALX | X| Imm 20:16 | Imm 25:21 |
1297 +--------------+--------------------------------+
1299 +-----------------------------------------------+
1301 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1302 Note that the immediate value in the first word is swapped.
1304 When producing a relocatable object file, R_MIPS16_26 is
1305 handled mostly like R_MIPS_26. In particular, the addend is
1306 stored as a straight 26-bit value in a 32-bit instruction.
1307 (gas makes life simpler for itself by never adjusting a
1308 R_MIPS16_26 reloc to be against a section, so the addend is
1309 always zero). However, the 32 bit instruction is stored as 2
1310 16-bit values, rather than a single 32-bit value. In a
1311 big-endian file, the result is the same; in a little-endian
1312 file, the two 16-bit halves of the 32 bit value are swapped.
1313 This is so that a disassembler can recognize the jal
1316 When doing a final link, R_MIPS16_26 is treated as a 32 bit
1317 instruction stored as two 16-bit values. The addend A is the
1318 contents of the targ26 field. The calculation is the same as
1319 R_MIPS_26. When storing the calculated value, reorder the
1320 immediate value as shown above, and don't forget to store the
1321 value as two 16-bit values.
1323 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
1327 +--------+----------------------+
1331 +--------+----------------------+
1334 +----------+------+-------------+
1338 +----------+--------------------+
1339 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
1340 ((sub1 << 16) | sub2)).
1342 When producing a relocatable object file, the calculation is
1343 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1344 When producing a fully linked file, the calculation is
1345 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1346 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
1348 The table below lists the other MIPS16 instruction relocations.
1349 Each one is calculated in the same way as the non-MIPS16 relocation
1350 given on the right, but using the extended MIPS16 layout of 16-bit
1353 R_MIPS16_GPREL R_MIPS_GPREL16
1354 R_MIPS16_GOT16 R_MIPS_GOT16
1355 R_MIPS16_CALL16 R_MIPS_CALL16
1356 R_MIPS16_HI16 R_MIPS_HI16
1357 R_MIPS16_LO16 R_MIPS_LO16
1359 A typical instruction will have a format like this:
1361 +--------------+--------------------------------+
1362 | EXTEND | Imm 10:5 | Imm 15:11 |
1363 +--------------+--------------------------------+
1364 | Major | rx | ry | Imm 4:0 |
1365 +--------------+--------------------------------+
1367 EXTEND is the five bit value 11110. Major is the instruction
1370 All we need to do here is shuffle the bits appropriately.
1371 As above, the two 16-bit halves must be swapped on a
1372 little-endian system. */
1374 static inline bfd_boolean
1375 mips16_reloc_p (int r_type
)
1380 case R_MIPS16_GPREL
:
1381 case R_MIPS16_GOT16
:
1382 case R_MIPS16_CALL16
:
1392 static inline bfd_boolean
1393 got16_reloc_p (int r_type
)
1395 return r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS16_GOT16
;
1398 static inline bfd_boolean
1399 call16_reloc_p (int r_type
)
1401 return r_type
== R_MIPS_CALL16
|| r_type
== R_MIPS16_CALL16
;
1404 static inline bfd_boolean
1405 hi16_reloc_p (int r_type
)
1407 return r_type
== R_MIPS_HI16
|| r_type
== R_MIPS16_HI16
;
1410 static inline bfd_boolean
1411 lo16_reloc_p (int r_type
)
1413 return r_type
== R_MIPS_LO16
|| r_type
== R_MIPS16_LO16
;
1416 static inline bfd_boolean
1417 mips16_call_reloc_p (int r_type
)
1419 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
1423 _bfd_mips16_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
1424 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1426 bfd_vma extend
, insn
, val
;
1428 if (!mips16_reloc_p (r_type
))
1431 /* Pick up the mips16 extend instruction and the real instruction. */
1432 extend
= bfd_get_16 (abfd
, data
);
1433 insn
= bfd_get_16 (abfd
, data
+ 2);
1434 if (r_type
== R_MIPS16_26
)
1437 val
= ((extend
& 0xfc00) << 16) | ((extend
& 0x3e0) << 11)
1438 | ((extend
& 0x1f) << 21) | insn
;
1440 val
= extend
<< 16 | insn
;
1443 val
= ((extend
& 0xf800) << 16) | ((insn
& 0xffe0) << 11)
1444 | ((extend
& 0x1f) << 11) | (extend
& 0x7e0) | (insn
& 0x1f);
1445 bfd_put_32 (abfd
, val
, data
);
1449 _bfd_mips16_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
1450 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1452 bfd_vma extend
, insn
, val
;
1454 if (!mips16_reloc_p (r_type
))
1457 val
= bfd_get_32 (abfd
, data
);
1458 if (r_type
== R_MIPS16_26
)
1462 insn
= val
& 0xffff;
1463 extend
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
1464 | ((val
>> 21) & 0x1f);
1468 insn
= val
& 0xffff;
1474 insn
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
1475 extend
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
1477 bfd_put_16 (abfd
, insn
, data
+ 2);
1478 bfd_put_16 (abfd
, extend
, data
);
1481 bfd_reloc_status_type
1482 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1483 arelent
*reloc_entry
, asection
*input_section
,
1484 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1488 bfd_reloc_status_type status
;
1490 if (bfd_is_com_section (symbol
->section
))
1493 relocation
= symbol
->value
;
1495 relocation
+= symbol
->section
->output_section
->vma
;
1496 relocation
+= symbol
->section
->output_offset
;
1498 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1499 return bfd_reloc_outofrange
;
1501 /* Set val to the offset into the section or symbol. */
1502 val
= reloc_entry
->addend
;
1504 _bfd_mips_elf_sign_extend (val
, 16);
1506 /* Adjust val for the final section location and GP value. If we
1507 are producing relocatable output, we don't want to do this for
1508 an external symbol. */
1510 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1511 val
+= relocation
- gp
;
1513 if (reloc_entry
->howto
->partial_inplace
)
1515 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1517 + reloc_entry
->address
);
1518 if (status
!= bfd_reloc_ok
)
1522 reloc_entry
->addend
= val
;
1525 reloc_entry
->address
+= input_section
->output_offset
;
1527 return bfd_reloc_ok
;
1530 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
1531 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
1532 that contains the relocation field and DATA points to the start of
1537 struct mips_hi16
*next
;
1539 asection
*input_section
;
1543 /* FIXME: This should not be a static variable. */
1545 static struct mips_hi16
*mips_hi16_list
;
1547 /* A howto special_function for REL *HI16 relocations. We can only
1548 calculate the correct value once we've seen the partnering
1549 *LO16 relocation, so just save the information for later.
1551 The ABI requires that the *LO16 immediately follow the *HI16.
1552 However, as a GNU extension, we permit an arbitrary number of
1553 *HI16s to be associated with a single *LO16. This significantly
1554 simplies the relocation handling in gcc. */
1556 bfd_reloc_status_type
1557 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1558 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
1559 asection
*input_section
, bfd
*output_bfd
,
1560 char **error_message ATTRIBUTE_UNUSED
)
1562 struct mips_hi16
*n
;
1564 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1565 return bfd_reloc_outofrange
;
1567 n
= bfd_malloc (sizeof *n
);
1569 return bfd_reloc_outofrange
;
1571 n
->next
= mips_hi16_list
;
1573 n
->input_section
= input_section
;
1574 n
->rel
= *reloc_entry
;
1577 if (output_bfd
!= NULL
)
1578 reloc_entry
->address
+= input_section
->output_offset
;
1580 return bfd_reloc_ok
;
1583 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
1584 like any other 16-bit relocation when applied to global symbols, but is
1585 treated in the same as R_MIPS_HI16 when applied to local symbols. */
1587 bfd_reloc_status_type
1588 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1589 void *data
, asection
*input_section
,
1590 bfd
*output_bfd
, char **error_message
)
1592 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
1593 || bfd_is_und_section (bfd_get_section (symbol
))
1594 || bfd_is_com_section (bfd_get_section (symbol
)))
1595 /* The relocation is against a global symbol. */
1596 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1597 input_section
, output_bfd
,
1600 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1601 input_section
, output_bfd
, error_message
);
1604 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
1605 is a straightforward 16 bit inplace relocation, but we must deal with
1606 any partnering high-part relocations as well. */
1608 bfd_reloc_status_type
1609 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1610 void *data
, asection
*input_section
,
1611 bfd
*output_bfd
, char **error_message
)
1614 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1616 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1617 return bfd_reloc_outofrange
;
1619 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1621 vallo
= bfd_get_32 (abfd
, location
);
1622 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1625 while (mips_hi16_list
!= NULL
)
1627 bfd_reloc_status_type ret
;
1628 struct mips_hi16
*hi
;
1630 hi
= mips_hi16_list
;
1632 /* R_MIPS*_GOT16 relocations are something of a special case. We
1633 want to install the addend in the same way as for a R_MIPS*_HI16
1634 relocation (with a rightshift of 16). However, since GOT16
1635 relocations can also be used with global symbols, their howto
1636 has a rightshift of 0. */
1637 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
1638 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
1639 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
1640 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
1642 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
1643 carry or borrow will induce a change of +1 or -1 in the high part. */
1644 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
1646 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
1647 hi
->input_section
, output_bfd
,
1649 if (ret
!= bfd_reloc_ok
)
1652 mips_hi16_list
= hi
->next
;
1656 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1657 input_section
, output_bfd
,
1661 /* A generic howto special_function. This calculates and installs the
1662 relocation itself, thus avoiding the oft-discussed problems in
1663 bfd_perform_relocation and bfd_install_relocation. */
1665 bfd_reloc_status_type
1666 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1667 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
1668 asection
*input_section
, bfd
*output_bfd
,
1669 char **error_message ATTRIBUTE_UNUSED
)
1672 bfd_reloc_status_type status
;
1673 bfd_boolean relocatable
;
1675 relocatable
= (output_bfd
!= NULL
);
1677 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1678 return bfd_reloc_outofrange
;
1680 /* Build up the field adjustment in VAL. */
1682 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1684 /* Either we're calculating the final field value or we have a
1685 relocation against a section symbol. Add in the section's
1686 offset or address. */
1687 val
+= symbol
->section
->output_section
->vma
;
1688 val
+= symbol
->section
->output_offset
;
1693 /* We're calculating the final field value. Add in the symbol's value
1694 and, if pc-relative, subtract the address of the field itself. */
1695 val
+= symbol
->value
;
1696 if (reloc_entry
->howto
->pc_relative
)
1698 val
-= input_section
->output_section
->vma
;
1699 val
-= input_section
->output_offset
;
1700 val
-= reloc_entry
->address
;
1704 /* VAL is now the final adjustment. If we're keeping this relocation
1705 in the output file, and if the relocation uses a separate addend,
1706 we just need to add VAL to that addend. Otherwise we need to add
1707 VAL to the relocation field itself. */
1708 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
1709 reloc_entry
->addend
+= val
;
1712 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1714 /* Add in the separate addend, if any. */
1715 val
+= reloc_entry
->addend
;
1717 /* Add VAL to the relocation field. */
1718 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1720 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1722 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1725 if (status
!= bfd_reloc_ok
)
1730 reloc_entry
->address
+= input_section
->output_offset
;
1732 return bfd_reloc_ok
;
1735 /* Swap an entry in a .gptab section. Note that these routines rely
1736 on the equivalence of the two elements of the union. */
1739 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
1742 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1743 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1747 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
1748 Elf32_External_gptab
*ex
)
1750 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
1751 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
1755 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
1756 Elf32_External_compact_rel
*ex
)
1758 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1759 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1760 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1761 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1762 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1763 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1767 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
1768 Elf32_External_crinfo
*ex
)
1772 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1773 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1774 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1775 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1776 H_PUT_32 (abfd
, l
, ex
->info
);
1777 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1778 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1781 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1782 routines swap this structure in and out. They are used outside of
1783 BFD, so they are globally visible. */
1786 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
1789 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1790 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1791 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1792 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1793 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1794 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1798 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
1799 Elf32_External_RegInfo
*ex
)
1801 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1802 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1803 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1804 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1805 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1806 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1809 /* In the 64 bit ABI, the .MIPS.options section holds register
1810 information in an Elf64_Reginfo structure. These routines swap
1811 them in and out. They are globally visible because they are used
1812 outside of BFD. These routines are here so that gas can call them
1813 without worrying about whether the 64 bit ABI has been included. */
1816 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
1817 Elf64_Internal_RegInfo
*in
)
1819 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1820 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1821 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1822 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1823 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1824 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1825 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1829 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
1830 Elf64_External_RegInfo
*ex
)
1832 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1833 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1834 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1835 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1836 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1837 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1838 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1841 /* Swap in an options header. */
1844 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
1845 Elf_Internal_Options
*in
)
1847 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1848 in
->size
= H_GET_8 (abfd
, ex
->size
);
1849 in
->section
= H_GET_16 (abfd
, ex
->section
);
1850 in
->info
= H_GET_32 (abfd
, ex
->info
);
1853 /* Swap out an options header. */
1856 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
1857 Elf_External_Options
*ex
)
1859 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1860 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1861 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1862 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1865 /* This function is called via qsort() to sort the dynamic relocation
1866 entries by increasing r_symndx value. */
1869 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
1871 Elf_Internal_Rela int_reloc1
;
1872 Elf_Internal_Rela int_reloc2
;
1875 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1876 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1878 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
1882 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
1884 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
1889 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
1892 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
1893 const void *arg2 ATTRIBUTE_UNUSED
)
1896 Elf_Internal_Rela int_reloc1
[3];
1897 Elf_Internal_Rela int_reloc2
[3];
1899 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1900 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
1901 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1902 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
1904 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
1906 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
1909 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
1911 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
1920 /* This routine is used to write out ECOFF debugging external symbol
1921 information. It is called via mips_elf_link_hash_traverse. The
1922 ECOFF external symbol information must match the ELF external
1923 symbol information. Unfortunately, at this point we don't know
1924 whether a symbol is required by reloc information, so the two
1925 tables may wind up being different. We must sort out the external
1926 symbol information before we can set the final size of the .mdebug
1927 section, and we must set the size of the .mdebug section before we
1928 can relocate any sections, and we can't know which symbols are
1929 required by relocation until we relocate the sections.
1930 Fortunately, it is relatively unlikely that any symbol will be
1931 stripped but required by a reloc. In particular, it can not happen
1932 when generating a final executable. */
1935 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
1937 struct extsym_info
*einfo
= data
;
1939 asection
*sec
, *output_section
;
1941 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1942 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1944 if (h
->root
.indx
== -2)
1946 else if ((h
->root
.def_dynamic
1947 || h
->root
.ref_dynamic
1948 || h
->root
.type
== bfd_link_hash_new
)
1949 && !h
->root
.def_regular
1950 && !h
->root
.ref_regular
)
1952 else if (einfo
->info
->strip
== strip_all
1953 || (einfo
->info
->strip
== strip_some
1954 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1955 h
->root
.root
.root
.string
,
1956 FALSE
, FALSE
) == NULL
))
1964 if (h
->esym
.ifd
== -2)
1967 h
->esym
.cobol_main
= 0;
1968 h
->esym
.weakext
= 0;
1969 h
->esym
.reserved
= 0;
1970 h
->esym
.ifd
= ifdNil
;
1971 h
->esym
.asym
.value
= 0;
1972 h
->esym
.asym
.st
= stGlobal
;
1974 if (h
->root
.root
.type
== bfd_link_hash_undefined
1975 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
1979 /* Use undefined class. Also, set class and type for some
1981 name
= h
->root
.root
.root
.string
;
1982 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
1983 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
1985 h
->esym
.asym
.sc
= scData
;
1986 h
->esym
.asym
.st
= stLabel
;
1987 h
->esym
.asym
.value
= 0;
1989 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
1991 h
->esym
.asym
.sc
= scAbs
;
1992 h
->esym
.asym
.st
= stLabel
;
1993 h
->esym
.asym
.value
=
1994 mips_elf_hash_table (einfo
->info
)->procedure_count
;
1996 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
1998 h
->esym
.asym
.sc
= scAbs
;
1999 h
->esym
.asym
.st
= stLabel
;
2000 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2003 h
->esym
.asym
.sc
= scUndefined
;
2005 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2006 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2007 h
->esym
.asym
.sc
= scAbs
;
2012 sec
= h
->root
.root
.u
.def
.section
;
2013 output_section
= sec
->output_section
;
2015 /* When making a shared library and symbol h is the one from
2016 the another shared library, OUTPUT_SECTION may be null. */
2017 if (output_section
== NULL
)
2018 h
->esym
.asym
.sc
= scUndefined
;
2021 name
= bfd_section_name (output_section
->owner
, output_section
);
2023 if (strcmp (name
, ".text") == 0)
2024 h
->esym
.asym
.sc
= scText
;
2025 else if (strcmp (name
, ".data") == 0)
2026 h
->esym
.asym
.sc
= scData
;
2027 else if (strcmp (name
, ".sdata") == 0)
2028 h
->esym
.asym
.sc
= scSData
;
2029 else if (strcmp (name
, ".rodata") == 0
2030 || strcmp (name
, ".rdata") == 0)
2031 h
->esym
.asym
.sc
= scRData
;
2032 else if (strcmp (name
, ".bss") == 0)
2033 h
->esym
.asym
.sc
= scBss
;
2034 else if (strcmp (name
, ".sbss") == 0)
2035 h
->esym
.asym
.sc
= scSBss
;
2036 else if (strcmp (name
, ".init") == 0)
2037 h
->esym
.asym
.sc
= scInit
;
2038 else if (strcmp (name
, ".fini") == 0)
2039 h
->esym
.asym
.sc
= scFini
;
2041 h
->esym
.asym
.sc
= scAbs
;
2045 h
->esym
.asym
.reserved
= 0;
2046 h
->esym
.asym
.index
= indexNil
;
2049 if (h
->root
.root
.type
== bfd_link_hash_common
)
2050 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2051 else if (h
->root
.root
.type
== bfd_link_hash_defined
2052 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2054 if (h
->esym
.asym
.sc
== scCommon
)
2055 h
->esym
.asym
.sc
= scBss
;
2056 else if (h
->esym
.asym
.sc
== scSCommon
)
2057 h
->esym
.asym
.sc
= scSBss
;
2059 sec
= h
->root
.root
.u
.def
.section
;
2060 output_section
= sec
->output_section
;
2061 if (output_section
!= NULL
)
2062 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2063 + sec
->output_offset
2064 + output_section
->vma
);
2066 h
->esym
.asym
.value
= 0;
2068 else if (h
->root
.needs_plt
)
2070 struct mips_elf_link_hash_entry
*hd
= h
;
2071 bfd_boolean no_fn_stub
= h
->no_fn_stub
;
2073 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
2075 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2076 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
2081 /* Set type and value for a symbol with a function stub. */
2082 h
->esym
.asym
.st
= stProc
;
2083 sec
= hd
->root
.root
.u
.def
.section
;
2085 h
->esym
.asym
.value
= 0;
2088 output_section
= sec
->output_section
;
2089 if (output_section
!= NULL
)
2090 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
2091 + sec
->output_offset
2092 + output_section
->vma
);
2094 h
->esym
.asym
.value
= 0;
2099 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2100 h
->root
.root
.root
.string
,
2103 einfo
->failed
= TRUE
;
2110 /* A comparison routine used to sort .gptab entries. */
2113 gptab_compare (const void *p1
, const void *p2
)
2115 const Elf32_gptab
*a1
= p1
;
2116 const Elf32_gptab
*a2
= p2
;
2118 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
2121 /* Functions to manage the got entry hash table. */
2123 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
2126 static INLINE hashval_t
2127 mips_elf_hash_bfd_vma (bfd_vma addr
)
2130 return addr
+ (addr
>> 32);
2136 /* got_entries only match if they're identical, except for gotidx, so
2137 use all fields to compute the hash, and compare the appropriate
2141 mips_elf_got_entry_hash (const void *entry_
)
2143 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2145 return entry
->symndx
2146 + ((entry
->tls_type
& GOT_TLS_LDM
) << 17)
2147 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
2149 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
2150 : entry
->d
.h
->root
.root
.root
.hash
));
2154 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
2156 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2157 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2159 /* An LDM entry can only match another LDM entry. */
2160 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2163 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
2164 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
2165 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
2166 : e1
->d
.h
== e2
->d
.h
);
2169 /* multi_got_entries are still a match in the case of global objects,
2170 even if the input bfd in which they're referenced differs, so the
2171 hash computation and compare functions are adjusted
2175 mips_elf_multi_got_entry_hash (const void *entry_
)
2177 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2179 return entry
->symndx
2181 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
2182 : entry
->symndx
>= 0
2183 ? ((entry
->tls_type
& GOT_TLS_LDM
)
2184 ? (GOT_TLS_LDM
<< 17)
2186 + mips_elf_hash_bfd_vma (entry
->d
.addend
)))
2187 : entry
->d
.h
->root
.root
.root
.hash
);
2191 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
2193 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2194 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2196 /* Any two LDM entries match. */
2197 if (e1
->tls_type
& e2
->tls_type
& GOT_TLS_LDM
)
2200 /* Nothing else matches an LDM entry. */
2201 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2204 return e1
->symndx
== e2
->symndx
2205 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
2206 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
2207 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
2208 : e1
->d
.h
== e2
->d
.h
);
2212 mips_got_page_entry_hash (const void *entry_
)
2214 const struct mips_got_page_entry
*entry
;
2216 entry
= (const struct mips_got_page_entry
*) entry_
;
2217 return entry
->abfd
->id
+ entry
->symndx
;
2221 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
2223 const struct mips_got_page_entry
*entry1
, *entry2
;
2225 entry1
= (const struct mips_got_page_entry
*) entry1_
;
2226 entry2
= (const struct mips_got_page_entry
*) entry2_
;
2227 return entry1
->abfd
== entry2
->abfd
&& entry1
->symndx
== entry2
->symndx
;
2230 /* Return the dynamic relocation section. If it doesn't exist, try to
2231 create a new it if CREATE_P, otherwise return NULL. Also return NULL
2232 if creation fails. */
2235 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
2241 dname
= MIPS_ELF_REL_DYN_NAME (info
);
2242 dynobj
= elf_hash_table (info
)->dynobj
;
2243 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
2244 if (sreloc
== NULL
&& create_p
)
2246 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
2251 | SEC_LINKER_CREATED
2254 || ! bfd_set_section_alignment (dynobj
, sreloc
,
2255 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
2261 /* Returns the GOT section, if it hasn't been excluded. */
2264 mips_elf_got_section (struct bfd_link_info
*info
)
2266 struct mips_elf_link_hash_table
*htab
;
2268 htab
= mips_elf_hash_table (info
);
2269 if (htab
->sgot
== NULL
|| (htab
->sgot
->flags
& SEC_EXCLUDE
) != 0)
2274 /* Count the number of relocations needed for a TLS GOT entry, with
2275 access types from TLS_TYPE, and symbol H (or a local symbol if H
2279 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
2280 struct elf_link_hash_entry
*h
)
2284 bfd_boolean need_relocs
= FALSE
;
2285 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2287 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2288 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
2291 if ((info
->shared
|| indx
!= 0)
2293 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2294 || h
->root
.type
!= bfd_link_hash_undefweak
))
2300 if (tls_type
& GOT_TLS_GD
)
2307 if (tls_type
& GOT_TLS_IE
)
2310 if ((tls_type
& GOT_TLS_LDM
) && info
->shared
)
2316 /* Count the number of TLS relocations required for the GOT entry in
2317 ARG1, if it describes a local symbol. */
2320 mips_elf_count_local_tls_relocs (void **arg1
, void *arg2
)
2322 struct mips_got_entry
*entry
= * (struct mips_got_entry
**) arg1
;
2323 struct mips_elf_count_tls_arg
*arg
= arg2
;
2325 if (entry
->abfd
!= NULL
&& entry
->symndx
!= -1)
2326 arg
->needed
+= mips_tls_got_relocs (arg
->info
, entry
->tls_type
, NULL
);
2331 /* Count the number of TLS GOT entries required for the global (or
2332 forced-local) symbol in ARG1. */
2335 mips_elf_count_global_tls_entries (void *arg1
, void *arg2
)
2337 struct mips_elf_link_hash_entry
*hm
2338 = (struct mips_elf_link_hash_entry
*) arg1
;
2339 struct mips_elf_count_tls_arg
*arg
= arg2
;
2341 if (hm
->tls_type
& GOT_TLS_GD
)
2343 if (hm
->tls_type
& GOT_TLS_IE
)
2349 /* Count the number of TLS relocations required for the global (or
2350 forced-local) symbol in ARG1. */
2353 mips_elf_count_global_tls_relocs (void *arg1
, void *arg2
)
2355 struct mips_elf_link_hash_entry
*hm
2356 = (struct mips_elf_link_hash_entry
*) arg1
;
2357 struct mips_elf_count_tls_arg
*arg
= arg2
;
2359 arg
->needed
+= mips_tls_got_relocs (arg
->info
, hm
->tls_type
, &hm
->root
);
2364 /* Output a simple dynamic relocation into SRELOC. */
2367 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
2373 Elf_Internal_Rela rel
[3];
2375 memset (rel
, 0, sizeof (rel
));
2377 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
2378 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
2380 if (ABI_64_P (output_bfd
))
2382 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2383 (output_bfd
, &rel
[0],
2385 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
2388 bfd_elf32_swap_reloc_out
2389 (output_bfd
, &rel
[0],
2391 + sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
2392 ++sreloc
->reloc_count
;
2395 /* Initialize a set of TLS GOT entries for one symbol. */
2398 mips_elf_initialize_tls_slots (bfd
*abfd
, bfd_vma got_offset
,
2399 unsigned char *tls_type_p
,
2400 struct bfd_link_info
*info
,
2401 struct mips_elf_link_hash_entry
*h
,
2405 asection
*sreloc
, *sgot
;
2406 bfd_vma offset
, offset2
;
2407 bfd_boolean need_relocs
= FALSE
;
2409 sgot
= mips_elf_got_section (info
);
2414 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2416 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
2417 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
2418 indx
= h
->root
.dynindx
;
2421 if (*tls_type_p
& GOT_TLS_DONE
)
2424 if ((info
->shared
|| indx
!= 0)
2426 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
2427 || h
->root
.type
!= bfd_link_hash_undefweak
))
2430 /* MINUS_ONE means the symbol is not defined in this object. It may not
2431 be defined at all; assume that the value doesn't matter in that
2432 case. Otherwise complain if we would use the value. */
2433 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
2434 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
2436 /* Emit necessary relocations. */
2437 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
2439 /* General Dynamic. */
2440 if (*tls_type_p
& GOT_TLS_GD
)
2442 offset
= got_offset
;
2443 offset2
= offset
+ MIPS_ELF_GOT_SIZE (abfd
);
2447 mips_elf_output_dynamic_relocation
2448 (abfd
, sreloc
, indx
,
2449 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2450 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2453 mips_elf_output_dynamic_relocation
2454 (abfd
, sreloc
, indx
,
2455 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
2456 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset2
);
2458 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2459 sgot
->contents
+ offset2
);
2463 MIPS_ELF_PUT_WORD (abfd
, 1,
2464 sgot
->contents
+ offset
);
2465 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2466 sgot
->contents
+ offset2
);
2469 got_offset
+= 2 * MIPS_ELF_GOT_SIZE (abfd
);
2472 /* Initial Exec model. */
2473 if (*tls_type_p
& GOT_TLS_IE
)
2475 offset
= got_offset
;
2480 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
2481 sgot
->contents
+ offset
);
2483 MIPS_ELF_PUT_WORD (abfd
, 0,
2484 sgot
->contents
+ offset
);
2486 mips_elf_output_dynamic_relocation
2487 (abfd
, sreloc
, indx
,
2488 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
2489 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2492 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
2493 sgot
->contents
+ offset
);
2496 if (*tls_type_p
& GOT_TLS_LDM
)
2498 /* The initial offset is zero, and the LD offsets will include the
2499 bias by DTP_OFFSET. */
2500 MIPS_ELF_PUT_WORD (abfd
, 0,
2501 sgot
->contents
+ got_offset
2502 + MIPS_ELF_GOT_SIZE (abfd
));
2505 MIPS_ELF_PUT_WORD (abfd
, 1,
2506 sgot
->contents
+ got_offset
);
2508 mips_elf_output_dynamic_relocation
2509 (abfd
, sreloc
, indx
,
2510 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2511 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
2514 *tls_type_p
|= GOT_TLS_DONE
;
2517 /* Return the GOT index to use for a relocation of type R_TYPE against
2518 a symbol accessed using TLS_TYPE models. The GOT entries for this
2519 symbol in this GOT start at GOT_INDEX. This function initializes the
2520 GOT entries and corresponding relocations. */
2523 mips_tls_got_index (bfd
*abfd
, bfd_vma got_index
, unsigned char *tls_type
,
2524 int r_type
, struct bfd_link_info
*info
,
2525 struct mips_elf_link_hash_entry
*h
, bfd_vma symbol
)
2527 BFD_ASSERT (r_type
== R_MIPS_TLS_GOTTPREL
|| r_type
== R_MIPS_TLS_GD
2528 || r_type
== R_MIPS_TLS_LDM
);
2530 mips_elf_initialize_tls_slots (abfd
, got_index
, tls_type
, info
, h
, symbol
);
2532 if (r_type
== R_MIPS_TLS_GOTTPREL
)
2534 BFD_ASSERT (*tls_type
& GOT_TLS_IE
);
2535 if (*tls_type
& GOT_TLS_GD
)
2536 return got_index
+ 2 * MIPS_ELF_GOT_SIZE (abfd
);
2541 if (r_type
== R_MIPS_TLS_GD
)
2543 BFD_ASSERT (*tls_type
& GOT_TLS_GD
);
2547 if (r_type
== R_MIPS_TLS_LDM
)
2549 BFD_ASSERT (*tls_type
& GOT_TLS_LDM
);
2556 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
2557 for global symbol H. .got.plt comes before the GOT, so the offset
2558 will be negative. */
2561 mips_elf_gotplt_index (struct bfd_link_info
*info
,
2562 struct elf_link_hash_entry
*h
)
2564 bfd_vma plt_index
, got_address
, got_value
;
2565 struct mips_elf_link_hash_table
*htab
;
2567 htab
= mips_elf_hash_table (info
);
2568 BFD_ASSERT (h
->plt
.offset
!= (bfd_vma
) -1);
2570 /* Calculate the index of the symbol's PLT entry. */
2571 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
2573 /* Calculate the address of the associated .got.plt entry. */
2574 got_address
= (htab
->sgotplt
->output_section
->vma
2575 + htab
->sgotplt
->output_offset
2578 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
2579 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
2580 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
2581 + htab
->root
.hgot
->root
.u
.def
.value
);
2583 return got_address
- got_value
;
2586 /* Return the GOT offset for address VALUE. If there is not yet a GOT
2587 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
2588 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
2589 offset can be found. */
2592 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2593 bfd_vma value
, unsigned long r_symndx
,
2594 struct mips_elf_link_hash_entry
*h
, int r_type
)
2596 struct mips_elf_link_hash_table
*htab
;
2597 struct mips_got_entry
*entry
;
2599 htab
= mips_elf_hash_table (info
);
2600 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
2601 r_symndx
, h
, r_type
);
2605 if (TLS_RELOC_P (r_type
))
2607 if (entry
->symndx
== -1 && htab
->got_info
->next
== NULL
)
2608 /* A type (3) entry in the single-GOT case. We use the symbol's
2609 hash table entry to track the index. */
2610 return mips_tls_got_index (abfd
, h
->tls_got_offset
, &h
->tls_type
,
2611 r_type
, info
, h
, value
);
2613 return mips_tls_got_index (abfd
, entry
->gotidx
, &entry
->tls_type
,
2614 r_type
, info
, h
, value
);
2617 return entry
->gotidx
;
2620 /* Returns the GOT index for the global symbol indicated by H. */
2623 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
,
2624 int r_type
, struct bfd_link_info
*info
)
2626 struct mips_elf_link_hash_table
*htab
;
2628 struct mips_got_info
*g
, *gg
;
2629 long global_got_dynindx
= 0;
2631 htab
= mips_elf_hash_table (info
);
2632 gg
= g
= htab
->got_info
;
2633 if (g
->bfd2got
&& ibfd
)
2635 struct mips_got_entry e
, *p
;
2637 BFD_ASSERT (h
->dynindx
>= 0);
2639 g
= mips_elf_got_for_ibfd (g
, ibfd
);
2640 if (g
->next
!= gg
|| TLS_RELOC_P (r_type
))
2644 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
2647 p
= htab_find (g
->got_entries
, &e
);
2649 BFD_ASSERT (p
->gotidx
> 0);
2651 if (TLS_RELOC_P (r_type
))
2653 bfd_vma value
= MINUS_ONE
;
2654 if ((h
->root
.type
== bfd_link_hash_defined
2655 || h
->root
.type
== bfd_link_hash_defweak
)
2656 && h
->root
.u
.def
.section
->output_section
)
2657 value
= (h
->root
.u
.def
.value
2658 + h
->root
.u
.def
.section
->output_offset
2659 + h
->root
.u
.def
.section
->output_section
->vma
);
2661 return mips_tls_got_index (abfd
, p
->gotidx
, &p
->tls_type
, r_type
,
2662 info
, e
.d
.h
, value
);
2669 if (gg
->global_gotsym
!= NULL
)
2670 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
2672 if (TLS_RELOC_P (r_type
))
2674 struct mips_elf_link_hash_entry
*hm
2675 = (struct mips_elf_link_hash_entry
*) h
;
2676 bfd_vma value
= MINUS_ONE
;
2678 if ((h
->root
.type
== bfd_link_hash_defined
2679 || h
->root
.type
== bfd_link_hash_defweak
)
2680 && h
->root
.u
.def
.section
->output_section
)
2681 value
= (h
->root
.u
.def
.value
2682 + h
->root
.u
.def
.section
->output_offset
2683 + h
->root
.u
.def
.section
->output_section
->vma
);
2685 index
= mips_tls_got_index (abfd
, hm
->tls_got_offset
, &hm
->tls_type
,
2686 r_type
, info
, hm
, value
);
2690 /* Once we determine the global GOT entry with the lowest dynamic
2691 symbol table index, we must put all dynamic symbols with greater
2692 indices into the GOT. That makes it easy to calculate the GOT
2694 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
2695 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
2696 * MIPS_ELF_GOT_SIZE (abfd
));
2698 BFD_ASSERT (index
< htab
->sgot
->size
);
2703 /* Find a GOT page entry that points to within 32KB of VALUE. These
2704 entries are supposed to be placed at small offsets in the GOT, i.e.,
2705 within 32KB of GP. Return the index of the GOT entry, or -1 if no
2706 entry could be created. If OFFSETP is nonnull, use it to return the
2707 offset of the GOT entry from VALUE. */
2710 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2711 bfd_vma value
, bfd_vma
*offsetp
)
2713 bfd_vma page
, index
;
2714 struct mips_got_entry
*entry
;
2716 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
2717 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
2718 NULL
, R_MIPS_GOT_PAGE
);
2723 index
= entry
->gotidx
;
2726 *offsetp
= value
- entry
->d
.address
;
2731 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
2732 EXTERNAL is true if the relocation was against a global symbol
2733 that has been forced local. */
2736 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2737 bfd_vma value
, bfd_boolean external
)
2739 struct mips_got_entry
*entry
;
2741 /* GOT16 relocations against local symbols are followed by a LO16
2742 relocation; those against global symbols are not. Thus if the
2743 symbol was originally local, the GOT16 relocation should load the
2744 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
2746 value
= mips_elf_high (value
) << 16;
2748 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
2749 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
2750 same in all cases. */
2751 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
2752 NULL
, R_MIPS_GOT16
);
2754 return entry
->gotidx
;
2759 /* Returns the offset for the entry at the INDEXth position
2763 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
2764 bfd
*input_bfd
, bfd_vma index
)
2766 struct mips_elf_link_hash_table
*htab
;
2770 htab
= mips_elf_hash_table (info
);
2772 gp
= _bfd_get_gp_value (output_bfd
)
2773 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
2775 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
2778 /* Create and return a local GOT entry for VALUE, which was calculated
2779 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
2780 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
2783 static struct mips_got_entry
*
2784 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
2785 bfd
*ibfd
, bfd_vma value
,
2786 unsigned long r_symndx
,
2787 struct mips_elf_link_hash_entry
*h
,
2790 struct mips_got_entry entry
, **loc
;
2791 struct mips_got_info
*g
;
2792 struct mips_elf_link_hash_table
*htab
;
2794 htab
= mips_elf_hash_table (info
);
2798 entry
.d
.address
= value
;
2801 g
= mips_elf_got_for_ibfd (htab
->got_info
, ibfd
);
2804 g
= mips_elf_got_for_ibfd (htab
->got_info
, abfd
);
2805 BFD_ASSERT (g
!= NULL
);
2808 /* We might have a symbol, H, if it has been forced local. Use the
2809 global entry then. It doesn't matter whether an entry is local
2810 or global for TLS, since the dynamic linker does not
2811 automatically relocate TLS GOT entries. */
2812 BFD_ASSERT (h
== NULL
|| h
->root
.forced_local
);
2813 if (TLS_RELOC_P (r_type
))
2815 struct mips_got_entry
*p
;
2818 if (r_type
== R_MIPS_TLS_LDM
)
2820 entry
.tls_type
= GOT_TLS_LDM
;
2826 entry
.symndx
= r_symndx
;
2832 p
= (struct mips_got_entry
*)
2833 htab_find (g
->got_entries
, &entry
);
2839 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
2844 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
2847 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2852 memcpy (*loc
, &entry
, sizeof entry
);
2854 if (g
->assigned_gotno
> g
->local_gotno
)
2856 (*loc
)->gotidx
= -1;
2857 /* We didn't allocate enough space in the GOT. */
2858 (*_bfd_error_handler
)
2859 (_("not enough GOT space for local GOT entries"));
2860 bfd_set_error (bfd_error_bad_value
);
2864 MIPS_ELF_PUT_WORD (abfd
, value
,
2865 (htab
->sgot
->contents
+ entry
.gotidx
));
2867 /* These GOT entries need a dynamic relocation on VxWorks. */
2868 if (htab
->is_vxworks
)
2870 Elf_Internal_Rela outrel
;
2873 bfd_vma got_address
;
2875 s
= mips_elf_rel_dyn_section (info
, FALSE
);
2876 got_address
= (htab
->sgot
->output_section
->vma
2877 + htab
->sgot
->output_offset
2880 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
2881 outrel
.r_offset
= got_address
;
2882 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
2883 outrel
.r_addend
= value
;
2884 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
2890 /* Sort the dynamic symbol table so that symbols that need GOT entries
2891 appear towards the end. This reduces the amount of GOT space
2892 required. MAX_LOCAL is used to set the number of local symbols
2893 known to be in the dynamic symbol table. During
2894 _bfd_mips_elf_size_dynamic_sections, this value is 1. Afterward, the
2895 section symbols are added and the count is higher. */
2898 mips_elf_sort_hash_table (struct bfd_link_info
*info
, unsigned long max_local
)
2900 struct mips_elf_link_hash_table
*htab
;
2901 struct mips_elf_hash_sort_data hsd
;
2902 struct mips_got_info
*g
;
2904 htab
= mips_elf_hash_table (info
);
2908 hsd
.max_unref_got_dynindx
=
2909 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
2910 /* In the multi-got case, assigned_gotno of the master got_info
2911 indicate the number of entries that aren't referenced in the
2912 primary GOT, but that must have entries because there are
2913 dynamic relocations that reference it. Since they aren't
2914 referenced, we move them to the end of the GOT, so that they
2915 don't prevent other entries that are referenced from getting
2916 too large offsets. */
2917 - (g
->next
? g
->assigned_gotno
: 0);
2918 hsd
.max_non_got_dynindx
= max_local
;
2919 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
2920 elf_hash_table (info
)),
2921 mips_elf_sort_hash_table_f
,
2924 /* There should have been enough room in the symbol table to
2925 accommodate both the GOT and non-GOT symbols. */
2926 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
2927 BFD_ASSERT ((unsigned long)hsd
.max_unref_got_dynindx
2928 <= elf_hash_table (info
)->dynsymcount
);
2930 /* Now we know which dynamic symbol has the lowest dynamic symbol
2931 table index in the GOT. */
2932 g
->global_gotsym
= hsd
.low
;
2937 /* If H needs a GOT entry, assign it the highest available dynamic
2938 index. Otherwise, assign it the lowest available dynamic
2942 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
2944 struct mips_elf_hash_sort_data
*hsd
= data
;
2946 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2947 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2949 /* Symbols without dynamic symbol table entries aren't interesting
2951 if (h
->root
.dynindx
== -1)
2954 /* Global symbols that need GOT entries that are not explicitly
2955 referenced are marked with got offset 2. Those that are
2956 referenced get a 1, and those that don't need GOT entries get
2957 -1. Forced local symbols may also be marked with got offset 1,
2958 but are never given global GOT entries. */
2959 if (h
->root
.got
.offset
== 2)
2961 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
2963 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
2964 hsd
->low
= (struct elf_link_hash_entry
*) h
;
2965 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
2967 else if (h
->root
.got
.offset
!= 1 || h
->forced_local
)
2968 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
2971 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
2973 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
2974 hsd
->low
= (struct elf_link_hash_entry
*) h
;
2980 /* If H is a symbol that needs a global GOT entry, but has a dynamic
2981 symbol table index lower than any we've seen to date, record it for
2985 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
2986 bfd
*abfd
, struct bfd_link_info
*info
,
2987 unsigned char tls_flag
)
2989 struct mips_elf_link_hash_table
*htab
;
2990 struct mips_got_entry entry
, **loc
;
2991 struct mips_got_info
*g
;
2993 htab
= mips_elf_hash_table (info
);
2995 /* A global symbol in the GOT must also be in the dynamic symbol
2997 if (h
->dynindx
== -1)
2999 switch (ELF_ST_VISIBILITY (h
->other
))
3003 _bfd_mips_elf_hide_symbol (info
, h
, TRUE
);
3006 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3010 /* Make sure we have a GOT to put this entry into. */
3012 BFD_ASSERT (g
!= NULL
);
3016 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3019 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3022 /* If we've already marked this entry as needing GOT space, we don't
3023 need to do it again. */
3026 (*loc
)->tls_type
|= tls_flag
;
3030 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3036 entry
.tls_type
= tls_flag
;
3038 memcpy (*loc
, &entry
, sizeof entry
);
3040 if (h
->got
.offset
!= MINUS_ONE
)
3045 /* By setting this to a value other than -1, we are indicating that
3046 there needs to be a GOT entry for H. Avoid using zero, as the
3047 generic ELF copy_indirect_symbol tests for <= 0. */
3049 if (h
->forced_local
)
3056 /* Reserve space in G for a GOT entry containing the value of symbol
3057 SYMNDX in input bfd ABDF, plus ADDEND. */
3060 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
3061 struct bfd_link_info
*info
,
3062 unsigned char tls_flag
)
3064 struct mips_elf_link_hash_table
*htab
;
3065 struct mips_got_info
*g
;
3066 struct mips_got_entry entry
, **loc
;
3068 htab
= mips_elf_hash_table (info
);
3070 BFD_ASSERT (g
!= NULL
);
3073 entry
.symndx
= symndx
;
3074 entry
.d
.addend
= addend
;
3075 entry
.tls_type
= tls_flag
;
3076 loc
= (struct mips_got_entry
**)
3077 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
3081 if (tls_flag
== GOT_TLS_GD
&& !((*loc
)->tls_type
& GOT_TLS_GD
))
3084 (*loc
)->tls_type
|= tls_flag
;
3086 else if (tls_flag
== GOT_TLS_IE
&& !((*loc
)->tls_type
& GOT_TLS_IE
))
3089 (*loc
)->tls_type
|= tls_flag
;
3097 entry
.tls_type
= tls_flag
;
3098 if (tls_flag
== GOT_TLS_IE
)
3100 else if (tls_flag
== GOT_TLS_GD
)
3102 else if (g
->tls_ldm_offset
== MINUS_ONE
)
3104 g
->tls_ldm_offset
= MINUS_TWO
;
3110 entry
.gotidx
= g
->local_gotno
++;
3114 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3119 memcpy (*loc
, &entry
, sizeof entry
);
3124 /* Return the maximum number of GOT page entries required for RANGE. */
3127 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
3129 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
3132 /* Record that ABFD has a page relocation against symbol SYMNDX and
3133 that ADDEND is the addend for that relocation.
3135 This function creates an upper bound on the number of GOT slots
3136 required; no attempt is made to combine references to non-overridable
3137 global symbols across multiple input files. */
3140 mips_elf_record_got_page_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3141 long symndx
, bfd_signed_vma addend
)
3143 struct mips_elf_link_hash_table
*htab
;
3144 struct mips_got_info
*g
;
3145 struct mips_got_page_entry lookup
, *entry
;
3146 struct mips_got_page_range
**range_ptr
, *range
;
3147 bfd_vma old_pages
, new_pages
;
3150 htab
= mips_elf_hash_table (info
);
3152 BFD_ASSERT (g
!= NULL
);
3154 /* Find the mips_got_page_entry hash table entry for this symbol. */
3156 lookup
.symndx
= symndx
;
3157 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
3161 /* Create a mips_got_page_entry if this is the first time we've
3163 entry
= (struct mips_got_page_entry
*) *loc
;
3166 entry
= bfd_alloc (abfd
, sizeof (*entry
));
3171 entry
->symndx
= symndx
;
3172 entry
->ranges
= NULL
;
3173 entry
->num_pages
= 0;
3177 /* Skip over ranges whose maximum extent cannot share a page entry
3179 range_ptr
= &entry
->ranges
;
3180 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
3181 range_ptr
= &(*range_ptr
)->next
;
3183 /* If we scanned to the end of the list, or found a range whose
3184 minimum extent cannot share a page entry with ADDEND, create
3185 a new singleton range. */
3187 if (!range
|| addend
< range
->min_addend
- 0xffff)
3189 range
= bfd_alloc (abfd
, sizeof (*range
));
3193 range
->next
= *range_ptr
;
3194 range
->min_addend
= addend
;
3195 range
->max_addend
= addend
;
3203 /* Remember how many pages the old range contributed. */
3204 old_pages
= mips_elf_pages_for_range (range
);
3206 /* Update the ranges. */
3207 if (addend
< range
->min_addend
)
3208 range
->min_addend
= addend
;
3209 else if (addend
> range
->max_addend
)
3211 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
3213 old_pages
+= mips_elf_pages_for_range (range
->next
);
3214 range
->max_addend
= range
->next
->max_addend
;
3215 range
->next
= range
->next
->next
;
3218 range
->max_addend
= addend
;
3221 /* Record any change in the total estimate. */
3222 new_pages
= mips_elf_pages_for_range (range
);
3223 if (old_pages
!= new_pages
)
3225 entry
->num_pages
+= new_pages
- old_pages
;
3226 g
->page_gotno
+= new_pages
- old_pages
;
3232 /* Compute the hash value of the bfd in a bfd2got hash entry. */
3235 mips_elf_bfd2got_entry_hash (const void *entry_
)
3237 const struct mips_elf_bfd2got_hash
*entry
3238 = (struct mips_elf_bfd2got_hash
*)entry_
;
3240 return entry
->bfd
->id
;
3243 /* Check whether two hash entries have the same bfd. */
3246 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
3248 const struct mips_elf_bfd2got_hash
*e1
3249 = (const struct mips_elf_bfd2got_hash
*)entry1
;
3250 const struct mips_elf_bfd2got_hash
*e2
3251 = (const struct mips_elf_bfd2got_hash
*)entry2
;
3253 return e1
->bfd
== e2
->bfd
;
3256 /* In a multi-got link, determine the GOT to be used for IBFD. G must
3257 be the master GOT data. */
3259 static struct mips_got_info
*
3260 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
3262 struct mips_elf_bfd2got_hash e
, *p
;
3268 p
= htab_find (g
->bfd2got
, &e
);
3269 return p
? p
->g
: NULL
;
3272 /* Use BFD2GOT to find ABFD's got entry, creating one if none exists.
3273 Return NULL if an error occured. */
3275 static struct mips_got_info
*
3276 mips_elf_get_got_for_bfd (struct htab
*bfd2got
, bfd
*output_bfd
,
3279 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
3280 struct mips_got_info
*g
;
3283 bfdgot_entry
.bfd
= input_bfd
;
3284 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
3285 bfdgot
= (struct mips_elf_bfd2got_hash
*) *bfdgotp
;
3289 bfdgot
= ((struct mips_elf_bfd2got_hash
*)
3290 bfd_alloc (output_bfd
, sizeof (struct mips_elf_bfd2got_hash
)));
3296 g
= ((struct mips_got_info
*)
3297 bfd_alloc (output_bfd
, sizeof (struct mips_got_info
)));
3301 bfdgot
->bfd
= input_bfd
;
3304 g
->global_gotsym
= NULL
;
3305 g
->global_gotno
= 0;
3308 g
->assigned_gotno
= -1;
3310 g
->tls_assigned_gotno
= 0;
3311 g
->tls_ldm_offset
= MINUS_ONE
;
3312 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3313 mips_elf_multi_got_entry_eq
, NULL
);
3314 if (g
->got_entries
== NULL
)
3317 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3318 mips_got_page_entry_eq
, NULL
);
3319 if (g
->got_page_entries
== NULL
)
3329 /* A htab_traverse callback for the entries in the master got.
3330 Create one separate got for each bfd that has entries in the global
3331 got, such that we can tell how many local and global entries each
3335 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
3337 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3338 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3339 struct mips_got_info
*g
;
3341 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3348 /* Insert the GOT entry in the bfd's got entry hash table. */
3349 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
3350 if (*entryp
!= NULL
)
3355 if (entry
->tls_type
)
3357 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3359 if (entry
->tls_type
& GOT_TLS_IE
)
3362 else if (entry
->symndx
>= 0 || entry
->d
.h
->forced_local
)
3370 /* A htab_traverse callback for the page entries in the master got.
3371 Associate each page entry with the bfd's got. */
3374 mips_elf_make_got_pages_per_bfd (void **entryp
, void *p
)
3376 struct mips_got_page_entry
*entry
= (struct mips_got_page_entry
*) *entryp
;
3377 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*) p
;
3378 struct mips_got_info
*g
;
3380 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3387 /* Insert the GOT entry in the bfd's got entry hash table. */
3388 entryp
= htab_find_slot (g
->got_page_entries
, entry
, INSERT
);
3389 if (*entryp
!= NULL
)
3393 g
->page_gotno
+= entry
->num_pages
;
3397 /* Consider merging the got described by BFD2GOT with TO, using the
3398 information given by ARG. Return -1 if this would lead to overflow,
3399 1 if they were merged successfully, and 0 if a merge failed due to
3400 lack of memory. (These values are chosen so that nonnegative return
3401 values can be returned by a htab_traverse callback.) */
3404 mips_elf_merge_got_with (struct mips_elf_bfd2got_hash
*bfd2got
,
3405 struct mips_got_info
*to
,
3406 struct mips_elf_got_per_bfd_arg
*arg
)
3408 struct mips_got_info
*from
= bfd2got
->g
;
3409 unsigned int estimate
;
3411 /* Work out how many page entries we would need for the combined GOT. */
3412 estimate
= arg
->max_pages
;
3413 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
3414 estimate
= from
->page_gotno
+ to
->page_gotno
;
3416 /* And conservatively estimate how many local, global and TLS entries
3418 estimate
+= (from
->local_gotno
3419 + from
->global_gotno
3425 /* Bail out if the combined GOT might be too big. */
3426 if (estimate
> arg
->max_count
)
3429 /* Commit to the merge. Record that TO is now the bfd for this got. */
3432 /* Transfer the bfd's got information from FROM to TO. */
3433 htab_traverse (from
->got_entries
, mips_elf_make_got_per_bfd
, arg
);
3434 if (arg
->obfd
== NULL
)
3437 htab_traverse (from
->got_page_entries
, mips_elf_make_got_pages_per_bfd
, arg
);
3438 if (arg
->obfd
== NULL
)
3441 /* We don't have to worry about releasing memory of the actual
3442 got entries, since they're all in the master got_entries hash
3444 htab_delete (from
->got_entries
);
3445 htab_delete (from
->got_page_entries
);
3449 /* Attempt to merge gots of different input bfds. Try to use as much
3450 as possible of the primary got, since it doesn't require explicit
3451 dynamic relocations, but don't use bfds that would reference global
3452 symbols out of the addressable range. Failing the primary got,
3453 attempt to merge with the current got, or finish the current got
3454 and then make make the new got current. */
3457 mips_elf_merge_gots (void **bfd2got_
, void *p
)
3459 struct mips_elf_bfd2got_hash
*bfd2got
3460 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
3461 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3462 struct mips_got_info
*g
;
3463 unsigned int estimate
;
3468 /* Work out the number of page, local and TLS entries. */
3469 estimate
= arg
->max_pages
;
3470 if (estimate
> g
->page_gotno
)
3471 estimate
= g
->page_gotno
;
3472 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
3474 /* We place TLS GOT entries after both locals and globals. The globals
3475 for the primary GOT may overflow the normal GOT size limit, so be
3476 sure not to merge a GOT which requires TLS with the primary GOT in that
3477 case. This doesn't affect non-primary GOTs. */
3478 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
3480 if (estimate
<= arg
->max_count
)
3482 /* If we don't have a primary GOT, use it as
3483 a starting point for the primary GOT. */
3486 arg
->primary
= bfd2got
->g
;
3490 /* Try merging with the primary GOT. */
3491 result
= mips_elf_merge_got_with (bfd2got
, arg
->primary
, arg
);
3496 /* If we can merge with the last-created got, do it. */
3499 result
= mips_elf_merge_got_with (bfd2got
, arg
->current
, arg
);
3504 /* Well, we couldn't merge, so create a new GOT. Don't check if it
3505 fits; if it turns out that it doesn't, we'll get relocation
3506 overflows anyway. */
3507 g
->next
= arg
->current
;
3513 /* Set the TLS GOT index for the GOT entry in ENTRYP. ENTRYP's NEXT field
3514 is null iff there is just a single GOT. */
3517 mips_elf_initialize_tls_index (void **entryp
, void *p
)
3519 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3520 struct mips_got_info
*g
= p
;
3522 unsigned char tls_type
;
3524 /* We're only interested in TLS symbols. */
3525 if (entry
->tls_type
== 0)
3528 next_index
= MIPS_ELF_GOT_SIZE (entry
->abfd
) * (long) g
->tls_assigned_gotno
;
3530 if (entry
->symndx
== -1 && g
->next
== NULL
)
3532 /* A type (3) got entry in the single-GOT case. We use the symbol's
3533 hash table entry to track its index. */
3534 if (entry
->d
.h
->tls_type
& GOT_TLS_OFFSET_DONE
)
3536 entry
->d
.h
->tls_type
|= GOT_TLS_OFFSET_DONE
;
3537 entry
->d
.h
->tls_got_offset
= next_index
;
3538 tls_type
= entry
->d
.h
->tls_type
;
3542 if (entry
->tls_type
& GOT_TLS_LDM
)
3544 /* There are separate mips_got_entry objects for each input bfd
3545 that requires an LDM entry. Make sure that all LDM entries in
3546 a GOT resolve to the same index. */
3547 if (g
->tls_ldm_offset
!= MINUS_TWO
&& g
->tls_ldm_offset
!= MINUS_ONE
)
3549 entry
->gotidx
= g
->tls_ldm_offset
;
3552 g
->tls_ldm_offset
= next_index
;
3554 entry
->gotidx
= next_index
;
3555 tls_type
= entry
->tls_type
;
3558 /* Account for the entries we've just allocated. */
3559 if (tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3560 g
->tls_assigned_gotno
+= 2;
3561 if (tls_type
& GOT_TLS_IE
)
3562 g
->tls_assigned_gotno
+= 1;
3567 /* If passed a NULL mips_got_info in the argument, set the marker used
3568 to tell whether a global symbol needs a got entry (in the primary
3569 got) to the given VALUE.
3571 If passed a pointer G to a mips_got_info in the argument (it must
3572 not be the primary GOT), compute the offset from the beginning of
3573 the (primary) GOT section to the entry in G corresponding to the
3574 global symbol. G's assigned_gotno must contain the index of the
3575 first available global GOT entry in G. VALUE must contain the size
3576 of a GOT entry in bytes. For each global GOT entry that requires a
3577 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
3578 marked as not eligible for lazy resolution through a function
3581 mips_elf_set_global_got_offset (void **entryp
, void *p
)
3583 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3584 struct mips_elf_set_global_got_offset_arg
*arg
3585 = (struct mips_elf_set_global_got_offset_arg
*)p
;
3586 struct mips_got_info
*g
= arg
->g
;
3588 if (g
&& entry
->tls_type
!= GOT_NORMAL
)
3589 arg
->needed_relocs
+=
3590 mips_tls_got_relocs (arg
->info
, entry
->tls_type
,
3591 entry
->symndx
== -1 ? &entry
->d
.h
->root
: NULL
);
3593 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1
3594 && entry
->d
.h
->root
.dynindx
!= -1
3595 && !entry
->d
.h
->forced_local
3596 && entry
->d
.h
->tls_type
== GOT_NORMAL
)
3600 BFD_ASSERT (g
->global_gotsym
== NULL
);
3602 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
3603 if (arg
->info
->shared
3604 || (elf_hash_table (arg
->info
)->dynamic_sections_created
3605 && entry
->d
.h
->root
.def_dynamic
3606 && !entry
->d
.h
->root
.def_regular
))
3607 ++arg
->needed_relocs
;
3610 entry
->d
.h
->root
.got
.offset
= arg
->value
;
3616 /* Mark any global symbols referenced in the GOT we are iterating over
3617 as inelligible for lazy resolution stubs. */
3619 mips_elf_set_no_stub (void **entryp
, void *p ATTRIBUTE_UNUSED
)
3621 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3623 if (entry
->abfd
!= NULL
3624 && entry
->symndx
== -1
3625 && entry
->d
.h
->root
.dynindx
!= -1)
3626 entry
->d
.h
->no_fn_stub
= TRUE
;
3631 /* Follow indirect and warning hash entries so that each got entry
3632 points to the final symbol definition. P must point to a pointer
3633 to the hash table we're traversing. Since this traversal may
3634 modify the hash table, we set this pointer to NULL to indicate
3635 we've made a potentially-destructive change to the hash table, so
3636 the traversal must be restarted. */
3638 mips_elf_resolve_final_got_entry (void **entryp
, void *p
)
3640 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3641 htab_t got_entries
= *(htab_t
*)p
;
3643 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3645 struct mips_elf_link_hash_entry
*h
= entry
->d
.h
;
3647 while (h
->root
.root
.type
== bfd_link_hash_indirect
3648 || h
->root
.root
.type
== bfd_link_hash_warning
)
3649 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3651 if (entry
->d
.h
== h
)
3656 /* If we can't find this entry with the new bfd hash, re-insert
3657 it, and get the traversal restarted. */
3658 if (! htab_find (got_entries
, entry
))
3660 htab_clear_slot (got_entries
, entryp
);
3661 entryp
= htab_find_slot (got_entries
, entry
, INSERT
);
3664 /* Abort the traversal, since the whole table may have
3665 moved, and leave it up to the parent to restart the
3667 *(htab_t
*)p
= NULL
;
3670 /* We might want to decrement the global_gotno count, but it's
3671 either too early or too late for that at this point. */
3677 /* Turn indirect got entries in a got_entries table into their final
3680 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
3686 got_entries
= g
->got_entries
;
3688 htab_traverse (got_entries
,
3689 mips_elf_resolve_final_got_entry
,
3692 while (got_entries
== NULL
);
3695 /* Return the offset of an input bfd IBFD's GOT from the beginning of
3698 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
3700 if (g
->bfd2got
== NULL
)
3703 g
= mips_elf_got_for_ibfd (g
, ibfd
);
3707 BFD_ASSERT (g
->next
);
3711 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
3712 * MIPS_ELF_GOT_SIZE (abfd
);
3715 /* Turn a single GOT that is too big for 16-bit addressing into
3716 a sequence of GOTs, each one 16-bit addressable. */
3719 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
3720 asection
*got
, bfd_size_type pages
)
3722 struct mips_elf_link_hash_table
*htab
;
3723 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
3724 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
3725 struct mips_got_info
*g
, *gg
;
3726 unsigned int assign
;
3728 htab
= mips_elf_hash_table (info
);
3730 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
3731 mips_elf_bfd2got_entry_eq
, NULL
);
3732 if (g
->bfd2got
== NULL
)
3735 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
3736 got_per_bfd_arg
.obfd
= abfd
;
3737 got_per_bfd_arg
.info
= info
;
3739 /* Count how many GOT entries each input bfd requires, creating a
3740 map from bfd to got info while at that. */
3741 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
3742 if (got_per_bfd_arg
.obfd
== NULL
)
3745 /* Also count how many page entries each input bfd requires. */
3746 htab_traverse (g
->got_page_entries
, mips_elf_make_got_pages_per_bfd
,
3748 if (got_per_bfd_arg
.obfd
== NULL
)
3751 got_per_bfd_arg
.current
= NULL
;
3752 got_per_bfd_arg
.primary
= NULL
;
3753 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
3754 / MIPS_ELF_GOT_SIZE (abfd
))
3755 - MIPS_RESERVED_GOTNO (info
));
3756 got_per_bfd_arg
.max_pages
= pages
;
3757 /* The number of globals that will be included in the primary GOT.
3758 See the calls to mips_elf_set_global_got_offset below for more
3760 got_per_bfd_arg
.global_count
= g
->global_gotno
;
3762 /* Try to merge the GOTs of input bfds together, as long as they
3763 don't seem to exceed the maximum GOT size, choosing one of them
3764 to be the primary GOT. */
3765 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
3766 if (got_per_bfd_arg
.obfd
== NULL
)
3769 /* If we do not find any suitable primary GOT, create an empty one. */
3770 if (got_per_bfd_arg
.primary
== NULL
)
3772 g
->next
= (struct mips_got_info
*)
3773 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
3774 if (g
->next
== NULL
)
3777 g
->next
->global_gotsym
= NULL
;
3778 g
->next
->global_gotno
= 0;
3779 g
->next
->local_gotno
= 0;
3780 g
->next
->page_gotno
= 0;
3781 g
->next
->tls_gotno
= 0;
3782 g
->next
->assigned_gotno
= 0;
3783 g
->next
->tls_assigned_gotno
= 0;
3784 g
->next
->tls_ldm_offset
= MINUS_ONE
;
3785 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3786 mips_elf_multi_got_entry_eq
,
3788 if (g
->next
->got_entries
== NULL
)
3790 g
->next
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3791 mips_got_page_entry_eq
,
3793 if (g
->next
->got_page_entries
== NULL
)
3795 g
->next
->bfd2got
= NULL
;
3798 g
->next
= got_per_bfd_arg
.primary
;
3799 g
->next
->next
= got_per_bfd_arg
.current
;
3801 /* GG is now the master GOT, and G is the primary GOT. */
3805 /* Map the output bfd to the primary got. That's what we're going
3806 to use for bfds that use GOT16 or GOT_PAGE relocations that we
3807 didn't mark in check_relocs, and we want a quick way to find it.
3808 We can't just use gg->next because we're going to reverse the
3811 struct mips_elf_bfd2got_hash
*bfdgot
;
3814 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
3815 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
3822 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
3824 BFD_ASSERT (*bfdgotp
== NULL
);
3828 /* The IRIX dynamic linker requires every symbol that is referenced
3829 in a dynamic relocation to be present in the primary GOT, so
3830 arrange for them to appear after those that are actually
3833 GNU/Linux could very well do without it, but it would slow down
3834 the dynamic linker, since it would have to resolve every dynamic
3835 symbol referenced in other GOTs more than once, without help from
3836 the cache. Also, knowing that every external symbol has a GOT
3837 helps speed up the resolution of local symbols too, so GNU/Linux
3838 follows IRIX's practice.
3840 The number 2 is used by mips_elf_sort_hash_table_f to count
3841 global GOT symbols that are unreferenced in the primary GOT, with
3842 an initial dynamic index computed from gg->assigned_gotno, where
3843 the number of unreferenced global entries in the primary GOT is
3847 gg
->assigned_gotno
= gg
->global_gotno
- g
->global_gotno
;
3848 g
->global_gotno
= gg
->global_gotno
;
3849 set_got_offset_arg
.value
= 2;
3853 /* This could be used for dynamic linkers that don't optimize
3854 symbol resolution while applying relocations so as to use
3855 primary GOT entries or assuming the symbol is locally-defined.
3856 With this code, we assign lower dynamic indices to global
3857 symbols that are not referenced in the primary GOT, so that
3858 their entries can be omitted. */
3859 gg
->assigned_gotno
= 0;
3860 set_got_offset_arg
.value
= -1;
3863 /* Reorder dynamic symbols as described above (which behavior
3864 depends on the setting of VALUE). */
3865 set_got_offset_arg
.g
= NULL
;
3866 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
3867 &set_got_offset_arg
);
3868 set_got_offset_arg
.value
= 1;
3869 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
3870 &set_got_offset_arg
);
3871 if (! mips_elf_sort_hash_table (info
, 1))
3874 /* Now go through the GOTs assigning them offset ranges.
3875 [assigned_gotno, local_gotno[ will be set to the range of local
3876 entries in each GOT. We can then compute the end of a GOT by
3877 adding local_gotno to global_gotno. We reverse the list and make
3878 it circular since then we'll be able to quickly compute the
3879 beginning of a GOT, by computing the end of its predecessor. To
3880 avoid special cases for the primary GOT, while still preserving
3881 assertions that are valid for both single- and multi-got links,
3882 we arrange for the main got struct to have the right number of
3883 global entries, but set its local_gotno such that the initial
3884 offset of the primary GOT is zero. Remember that the primary GOT
3885 will become the last item in the circular linked list, so it
3886 points back to the master GOT. */
3887 gg
->local_gotno
= -g
->global_gotno
;
3888 gg
->global_gotno
= g
->global_gotno
;
3895 struct mips_got_info
*gn
;
3897 assign
+= MIPS_RESERVED_GOTNO (info
);
3898 g
->assigned_gotno
= assign
;
3899 g
->local_gotno
+= assign
;
3900 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
3901 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
3903 /* Take g out of the direct list, and push it onto the reversed
3904 list that gg points to. g->next is guaranteed to be nonnull after
3905 this operation, as required by mips_elf_initialize_tls_index. */
3910 /* Set up any TLS entries. We always place the TLS entries after
3911 all non-TLS entries. */
3912 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
3913 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
3915 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
3918 /* Mark global symbols in every non-primary GOT as ineligible for
3921 htab_traverse (g
->got_entries
, mips_elf_set_no_stub
, NULL
);
3925 got
->size
= (gg
->next
->local_gotno
3926 + gg
->next
->global_gotno
3927 + gg
->next
->tls_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
3933 /* Returns the first relocation of type r_type found, beginning with
3934 RELOCATION. RELEND is one-past-the-end of the relocation table. */
3936 static const Elf_Internal_Rela
*
3937 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
3938 const Elf_Internal_Rela
*relocation
,
3939 const Elf_Internal_Rela
*relend
)
3941 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
3943 while (relocation
< relend
)
3945 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
3946 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
3952 /* We didn't find it. */
3956 /* Return whether a relocation is against a local symbol. */
3959 mips_elf_local_relocation_p (bfd
*input_bfd
,
3960 const Elf_Internal_Rela
*relocation
,
3961 asection
**local_sections
,
3962 bfd_boolean check_forced
)
3964 unsigned long r_symndx
;
3965 Elf_Internal_Shdr
*symtab_hdr
;
3966 struct mips_elf_link_hash_entry
*h
;
3969 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
3970 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3971 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
3973 if (r_symndx
< extsymoff
)
3975 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
3980 /* Look up the hash table to check whether the symbol
3981 was forced local. */
3982 h
= (struct mips_elf_link_hash_entry
*)
3983 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
3984 /* Find the real hash-table entry for this symbol. */
3985 while (h
->root
.root
.type
== bfd_link_hash_indirect
3986 || h
->root
.root
.type
== bfd_link_hash_warning
)
3987 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3988 if (h
->root
.forced_local
)
3995 /* Sign-extend VALUE, which has the indicated number of BITS. */
3998 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
4000 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
4001 /* VALUE is negative. */
4002 value
|= ((bfd_vma
) - 1) << bits
;
4007 /* Return non-zero if the indicated VALUE has overflowed the maximum
4008 range expressible by a signed number with the indicated number of
4012 mips_elf_overflow_p (bfd_vma value
, int bits
)
4014 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
4016 if (svalue
> (1 << (bits
- 1)) - 1)
4017 /* The value is too big. */
4019 else if (svalue
< -(1 << (bits
- 1)))
4020 /* The value is too small. */
4027 /* Calculate the %high function. */
4030 mips_elf_high (bfd_vma value
)
4032 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
4035 /* Calculate the %higher function. */
4038 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
4041 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
4048 /* Calculate the %highest function. */
4051 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
4054 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
4061 /* Create the .compact_rel section. */
4064 mips_elf_create_compact_rel_section
4065 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4068 register asection
*s
;
4070 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4072 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
4075 s
= bfd_make_section_with_flags (abfd
, ".compact_rel", flags
);
4077 || ! bfd_set_section_alignment (abfd
, s
,
4078 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4081 s
->size
= sizeof (Elf32_External_compact_rel
);
4087 /* Create the .got section to hold the global offset table. */
4090 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
,
4091 bfd_boolean maybe_exclude
)
4094 register asection
*s
;
4095 struct elf_link_hash_entry
*h
;
4096 struct bfd_link_hash_entry
*bh
;
4097 struct mips_got_info
*g
;
4099 struct mips_elf_link_hash_table
*htab
;
4101 htab
= mips_elf_hash_table (info
);
4103 /* This function may be called more than once. */
4107 if (! maybe_exclude
)
4108 s
->flags
&= ~SEC_EXCLUDE
;
4112 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4113 | SEC_LINKER_CREATED
);
4116 flags
|= SEC_EXCLUDE
;
4118 /* We have to use an alignment of 2**4 here because this is hardcoded
4119 in the function stub generation and in the linker script. */
4120 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4122 || ! bfd_set_section_alignment (abfd
, s
, 4))
4126 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4127 linker script because we don't want to define the symbol if we
4128 are not creating a global offset table. */
4130 if (! (_bfd_generic_link_add_one_symbol
4131 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4132 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4135 h
= (struct elf_link_hash_entry
*) bh
;
4138 h
->type
= STT_OBJECT
;
4139 elf_hash_table (info
)->hgot
= h
;
4142 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4145 amt
= sizeof (struct mips_got_info
);
4146 g
= bfd_alloc (abfd
, amt
);
4149 g
->global_gotsym
= NULL
;
4150 g
->global_gotno
= 0;
4152 g
->local_gotno
= MIPS_RESERVED_GOTNO (info
);
4154 g
->assigned_gotno
= MIPS_RESERVED_GOTNO (info
);
4157 g
->tls_ldm_offset
= MINUS_ONE
;
4158 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
4159 mips_elf_got_entry_eq
, NULL
);
4160 if (g
->got_entries
== NULL
)
4162 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4163 mips_got_page_entry_eq
, NULL
);
4164 if (g
->got_page_entries
== NULL
)
4167 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
4168 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
4170 /* VxWorks also needs a .got.plt section. */
4171 if (htab
->is_vxworks
)
4173 s
= bfd_make_section_with_flags (abfd
, ".got.plt",
4174 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4175 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4176 if (s
== NULL
|| !bfd_set_section_alignment (abfd
, s
, 4))
4184 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
4185 __GOTT_INDEX__ symbols. These symbols are only special for
4186 shared objects; they are not used in executables. */
4189 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
4191 return (mips_elf_hash_table (info
)->is_vxworks
4193 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
4194 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
4197 /* Calculate the value produced by the RELOCATION (which comes from
4198 the INPUT_BFD). The ADDEND is the addend to use for this
4199 RELOCATION; RELOCATION->R_ADDEND is ignored.
4201 The result of the relocation calculation is stored in VALUEP.
4202 REQUIRE_JALXP indicates whether or not the opcode used with this
4203 relocation must be JALX.
4205 This function returns bfd_reloc_continue if the caller need take no
4206 further action regarding this relocation, bfd_reloc_notsupported if
4207 something goes dramatically wrong, bfd_reloc_overflow if an
4208 overflow occurs, and bfd_reloc_ok to indicate success. */
4210 static bfd_reloc_status_type
4211 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
4212 asection
*input_section
,
4213 struct bfd_link_info
*info
,
4214 const Elf_Internal_Rela
*relocation
,
4215 bfd_vma addend
, reloc_howto_type
*howto
,
4216 Elf_Internal_Sym
*local_syms
,
4217 asection
**local_sections
, bfd_vma
*valuep
,
4218 const char **namep
, bfd_boolean
*require_jalxp
,
4219 bfd_boolean save_addend
)
4221 /* The eventual value we will return. */
4223 /* The address of the symbol against which the relocation is
4226 /* The final GP value to be used for the relocatable, executable, or
4227 shared object file being produced. */
4229 /* The place (section offset or address) of the storage unit being
4232 /* The value of GP used to create the relocatable object. */
4234 /* The offset into the global offset table at which the address of
4235 the relocation entry symbol, adjusted by the addend, resides
4236 during execution. */
4237 bfd_vma g
= MINUS_ONE
;
4238 /* The section in which the symbol referenced by the relocation is
4240 asection
*sec
= NULL
;
4241 struct mips_elf_link_hash_entry
*h
= NULL
;
4242 /* TRUE if the symbol referred to by this relocation is a local
4244 bfd_boolean local_p
, was_local_p
;
4245 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
4246 bfd_boolean gp_disp_p
= FALSE
;
4247 /* TRUE if the symbol referred to by this relocation is
4248 "__gnu_local_gp". */
4249 bfd_boolean gnu_local_gp_p
= FALSE
;
4250 Elf_Internal_Shdr
*symtab_hdr
;
4252 unsigned long r_symndx
;
4254 /* TRUE if overflow occurred during the calculation of the
4255 relocation value. */
4256 bfd_boolean overflowed_p
;
4257 /* TRUE if this relocation refers to a MIPS16 function. */
4258 bfd_boolean target_is_16_bit_code_p
= FALSE
;
4259 struct mips_elf_link_hash_table
*htab
;
4262 dynobj
= elf_hash_table (info
)->dynobj
;
4263 htab
= mips_elf_hash_table (info
);
4265 /* Parse the relocation. */
4266 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4267 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4268 p
= (input_section
->output_section
->vma
4269 + input_section
->output_offset
4270 + relocation
->r_offset
);
4272 /* Assume that there will be no overflow. */
4273 overflowed_p
= FALSE
;
4275 /* Figure out whether or not the symbol is local, and get the offset
4276 used in the array of hash table entries. */
4277 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4278 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4279 local_sections
, FALSE
);
4280 was_local_p
= local_p
;
4281 if (! elf_bad_symtab (input_bfd
))
4282 extsymoff
= symtab_hdr
->sh_info
;
4285 /* The symbol table does not follow the rule that local symbols
4286 must come before globals. */
4290 /* Figure out the value of the symbol. */
4293 Elf_Internal_Sym
*sym
;
4295 sym
= local_syms
+ r_symndx
;
4296 sec
= local_sections
[r_symndx
];
4298 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4299 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
4300 || (sec
->flags
& SEC_MERGE
))
4301 symbol
+= sym
->st_value
;
4302 if ((sec
->flags
& SEC_MERGE
)
4303 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4305 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
4307 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
4310 /* MIPS16 text labels should be treated as odd. */
4311 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
4314 /* Record the name of this symbol, for our caller. */
4315 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
4316 symtab_hdr
->sh_link
,
4319 *namep
= bfd_section_name (input_bfd
, sec
);
4321 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
4325 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
4327 /* For global symbols we look up the symbol in the hash-table. */
4328 h
= ((struct mips_elf_link_hash_entry
*)
4329 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
4330 /* Find the real hash-table entry for this symbol. */
4331 while (h
->root
.root
.type
== bfd_link_hash_indirect
4332 || h
->root
.root
.type
== bfd_link_hash_warning
)
4333 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4335 /* Record the name of this symbol, for our caller. */
4336 *namep
= h
->root
.root
.root
.string
;
4338 /* See if this is the special _gp_disp symbol. Note that such a
4339 symbol must always be a global symbol. */
4340 if (strcmp (*namep
, "_gp_disp") == 0
4341 && ! NEWABI_P (input_bfd
))
4343 /* Relocations against _gp_disp are permitted only with
4344 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
4345 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
4346 return bfd_reloc_notsupported
;
4350 /* See if this is the special _gp symbol. Note that such a
4351 symbol must always be a global symbol. */
4352 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
4353 gnu_local_gp_p
= TRUE
;
4356 /* If this symbol is defined, calculate its address. Note that
4357 _gp_disp is a magic symbol, always implicitly defined by the
4358 linker, so it's inappropriate to check to see whether or not
4360 else if ((h
->root
.root
.type
== bfd_link_hash_defined
4361 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4362 && h
->root
.root
.u
.def
.section
)
4364 sec
= h
->root
.root
.u
.def
.section
;
4365 if (sec
->output_section
)
4366 symbol
= (h
->root
.root
.u
.def
.value
4367 + sec
->output_section
->vma
4368 + sec
->output_offset
);
4370 symbol
= h
->root
.root
.u
.def
.value
;
4372 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
4373 /* We allow relocations against undefined weak symbols, giving
4374 it the value zero, so that you can undefined weak functions
4375 and check to see if they exist by looking at their
4378 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4379 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4381 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
4382 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
4384 /* If this is a dynamic link, we should have created a
4385 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
4386 in in _bfd_mips_elf_create_dynamic_sections.
4387 Otherwise, we should define the symbol with a value of 0.
4388 FIXME: It should probably get into the symbol table
4390 BFD_ASSERT (! info
->shared
);
4391 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
4394 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
4396 /* This is an optional symbol - an Irix specific extension to the
4397 ELF spec. Ignore it for now.
4398 XXX - FIXME - there is more to the spec for OPTIONAL symbols
4399 than simply ignoring them, but we do not handle this for now.
4400 For information see the "64-bit ELF Object File Specification"
4401 which is available from here:
4402 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
4407 if (! ((*info
->callbacks
->undefined_symbol
)
4408 (info
, h
->root
.root
.root
.string
, input_bfd
,
4409 input_section
, relocation
->r_offset
,
4410 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
4411 || ELF_ST_VISIBILITY (h
->root
.other
))))
4412 return bfd_reloc_undefined
;
4416 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
4419 /* If this is a reference to a 16-bit function with a stub, we need
4420 to redirect the relocation to the stub unless:
4422 (a) the relocation is for a MIPS16 JAL;
4424 (b) the relocation is for a MIPS16 PIC call, and there are no
4425 non-MIPS16 uses of the GOT slot; or
4427 (c) the section allows direct references to MIPS16 functions. */
4428 if (r_type
!= R_MIPS16_26
4429 && !info
->relocatable
4431 && h
->fn_stub
!= NULL
4432 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
4434 && elf_tdata (input_bfd
)->local_stubs
!= NULL
4435 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
4436 && !section_allows_mips16_refs_p (input_section
))
4438 /* This is a 32- or 64-bit call to a 16-bit function. We should
4439 have already noticed that we were going to need the
4442 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
4445 BFD_ASSERT (h
->need_fn_stub
);
4449 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4450 /* The target is 16-bit, but the stub isn't. */
4451 target_is_16_bit_code_p
= FALSE
;
4453 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
4454 need to redirect the call to the stub. Note that we specifically
4455 exclude R_MIPS16_CALL16 from this behavior; indirect calls should
4456 use an indirect stub instead. */
4457 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
4458 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
4460 && elf_tdata (input_bfd
)->local_call_stubs
!= NULL
4461 && elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
4462 && !target_is_16_bit_code_p
)
4465 sec
= elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
4468 /* If both call_stub and call_fp_stub are defined, we can figure
4469 out which one to use by checking which one appears in the input
4471 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
4476 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4478 if (CALL_FP_STUB_P (bfd_get_section_name (input_bfd
, o
)))
4480 sec
= h
->call_fp_stub
;
4487 else if (h
->call_stub
!= NULL
)
4490 sec
= h
->call_fp_stub
;
4493 BFD_ASSERT (sec
->size
> 0);
4494 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4497 /* Calls from 16-bit code to 32-bit code and vice versa require the
4498 special jalx instruction. */
4499 *require_jalxp
= (!info
->relocatable
4500 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
4501 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
4503 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4504 local_sections
, TRUE
);
4506 gp0
= _bfd_get_gp_value (input_bfd
);
4507 gp
= _bfd_get_gp_value (abfd
);
4509 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
4514 /* If we haven't already determined the GOT offset, oand we're going
4515 to need it, get it now. */
4518 case R_MIPS_GOT_PAGE
:
4519 case R_MIPS_GOT_OFST
:
4520 /* We need to decay to GOT_DISP/addend if the symbol doesn't
4522 local_p
= local_p
|| _bfd_elf_symbol_refs_local_p (&h
->root
, info
, 1);
4523 if (local_p
|| r_type
== R_MIPS_GOT_OFST
)
4527 case R_MIPS16_CALL16
:
4528 case R_MIPS16_GOT16
:
4531 case R_MIPS_GOT_DISP
:
4532 case R_MIPS_GOT_HI16
:
4533 case R_MIPS_CALL_HI16
:
4534 case R_MIPS_GOT_LO16
:
4535 case R_MIPS_CALL_LO16
:
4537 case R_MIPS_TLS_GOTTPREL
:
4538 case R_MIPS_TLS_LDM
:
4539 /* Find the index into the GOT where this value is located. */
4540 if (r_type
== R_MIPS_TLS_LDM
)
4542 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
4543 0, 0, NULL
, r_type
);
4545 return bfd_reloc_outofrange
;
4549 /* On VxWorks, CALL relocations should refer to the .got.plt
4550 entry, which is initialized to point at the PLT stub. */
4551 if (htab
->is_vxworks
4552 && (r_type
== R_MIPS_CALL_HI16
4553 || r_type
== R_MIPS_CALL_LO16
4554 || call16_reloc_p (r_type
)))
4556 BFD_ASSERT (addend
== 0);
4557 BFD_ASSERT (h
->root
.needs_plt
);
4558 g
= mips_elf_gotplt_index (info
, &h
->root
);
4562 /* GOT_PAGE may take a non-zero addend, that is ignored in a
4563 GOT_PAGE relocation that decays to GOT_DISP because the
4564 symbol turns out to be global. The addend is then added
4566 BFD_ASSERT (addend
== 0 || r_type
== R_MIPS_GOT_PAGE
);
4567 g
= mips_elf_global_got_index (dynobj
, input_bfd
,
4568 &h
->root
, r_type
, info
);
4569 if (h
->tls_type
== GOT_NORMAL
4570 && (! elf_hash_table(info
)->dynamic_sections_created
4572 && (info
->symbolic
|| h
->root
.forced_local
)
4573 && h
->root
.def_regular
)))
4574 /* This is a static link or a -Bsymbolic link. The
4575 symbol is defined locally, or was forced to be local.
4576 We must initialize this entry in the GOT. */
4577 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->sgot
->contents
+ g
);
4580 else if (!htab
->is_vxworks
4581 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
4582 /* The calculation below does not involve "g". */
4586 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
4587 symbol
+ addend
, r_symndx
, h
, r_type
);
4589 return bfd_reloc_outofrange
;
4592 /* Convert GOT indices to actual offsets. */
4593 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
4597 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
4598 symbols are resolved by the loader. Add them to .rela.dyn. */
4599 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
4601 Elf_Internal_Rela outrel
;
4605 s
= mips_elf_rel_dyn_section (info
, FALSE
);
4606 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4608 outrel
.r_offset
= (input_section
->output_section
->vma
4609 + input_section
->output_offset
4610 + relocation
->r_offset
);
4611 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
4612 outrel
.r_addend
= addend
;
4613 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
4615 /* If we've written this relocation for a readonly section,
4616 we need to set DF_TEXTREL again, so that we do not delete the
4618 if (MIPS_ELF_READONLY_SECTION (input_section
))
4619 info
->flags
|= DF_TEXTREL
;
4622 return bfd_reloc_ok
;
4625 /* Figure out what kind of relocation is being performed. */
4629 return bfd_reloc_continue
;
4632 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
4633 overflowed_p
= mips_elf_overflow_p (value
, 16);
4640 || (!htab
->is_vxworks
4641 && htab
->root
.dynamic_sections_created
4643 && h
->root
.def_dynamic
4644 && !h
->root
.def_regular
))
4647 || h
->root
.root
.type
!= bfd_link_hash_undefweak
4648 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4649 && (input_section
->flags
& SEC_ALLOC
) != 0)
4651 /* If we're creating a shared library, or this relocation is
4652 against a symbol in a shared library, then we can't know
4653 where the symbol will end up. So, we create a relocation
4654 record in the output, and leave the job up to the dynamic
4657 In VxWorks executables, references to external symbols
4658 are handled using copy relocs or PLT stubs, so there's
4659 no need to add a dynamic relocation here. */
4661 if (!mips_elf_create_dynamic_relocation (abfd
,
4669 return bfd_reloc_undefined
;
4673 if (r_type
!= R_MIPS_REL32
)
4674 value
= symbol
+ addend
;
4678 value
&= howto
->dst_mask
;
4682 value
= symbol
+ addend
- p
;
4683 value
&= howto
->dst_mask
;
4687 /* The calculation for R_MIPS16_26 is just the same as for an
4688 R_MIPS_26. It's only the storage of the relocated field into
4689 the output file that's different. That's handled in
4690 mips_elf_perform_relocation. So, we just fall through to the
4691 R_MIPS_26 case here. */
4694 value
= ((addend
| ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
4697 value
= (_bfd_mips_elf_sign_extend (addend
, 28) + symbol
) >> 2;
4698 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
)
4699 overflowed_p
= (value
>> 26) != ((p
+ 4) >> 28);
4701 value
&= howto
->dst_mask
;
4704 case R_MIPS_TLS_DTPREL_HI16
:
4705 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
4709 case R_MIPS_TLS_DTPREL_LO16
:
4710 case R_MIPS_TLS_DTPREL32
:
4711 case R_MIPS_TLS_DTPREL64
:
4712 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
4715 case R_MIPS_TLS_TPREL_HI16
:
4716 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
4720 case R_MIPS_TLS_TPREL_LO16
:
4721 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
4728 value
= mips_elf_high (addend
+ symbol
);
4729 value
&= howto
->dst_mask
;
4733 /* For MIPS16 ABI code we generate this sequence
4734 0: li $v0,%hi(_gp_disp)
4735 4: addiupc $v1,%lo(_gp_disp)
4739 So the offsets of hi and lo relocs are the same, but the
4740 $pc is four higher than $t9 would be, so reduce
4741 both reloc addends by 4. */
4742 if (r_type
== R_MIPS16_HI16
)
4743 value
= mips_elf_high (addend
+ gp
- p
- 4);
4745 value
= mips_elf_high (addend
+ gp
- p
);
4746 overflowed_p
= mips_elf_overflow_p (value
, 16);
4753 value
= (symbol
+ addend
) & howto
->dst_mask
;
4756 /* See the comment for R_MIPS16_HI16 above for the reason
4757 for this conditional. */
4758 if (r_type
== R_MIPS16_LO16
)
4759 value
= addend
+ gp
- p
;
4761 value
= addend
+ gp
- p
+ 4;
4762 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
4763 for overflow. But, on, say, IRIX5, relocations against
4764 _gp_disp are normally generated from the .cpload
4765 pseudo-op. It generates code that normally looks like
4768 lui $gp,%hi(_gp_disp)
4769 addiu $gp,$gp,%lo(_gp_disp)
4772 Here $t9 holds the address of the function being called,
4773 as required by the MIPS ELF ABI. The R_MIPS_LO16
4774 relocation can easily overflow in this situation, but the
4775 R_MIPS_HI16 relocation will handle the overflow.
4776 Therefore, we consider this a bug in the MIPS ABI, and do
4777 not check for overflow here. */
4781 case R_MIPS_LITERAL
:
4782 /* Because we don't merge literal sections, we can handle this
4783 just like R_MIPS_GPREL16. In the long run, we should merge
4784 shared literals, and then we will need to additional work
4789 case R_MIPS16_GPREL
:
4790 /* The R_MIPS16_GPREL performs the same calculation as
4791 R_MIPS_GPREL16, but stores the relocated bits in a different
4792 order. We don't need to do anything special here; the
4793 differences are handled in mips_elf_perform_relocation. */
4794 case R_MIPS_GPREL16
:
4795 /* Only sign-extend the addend if it was extracted from the
4796 instruction. If the addend was separate, leave it alone,
4797 otherwise we may lose significant bits. */
4798 if (howto
->partial_inplace
)
4799 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
4800 value
= symbol
+ addend
- gp
;
4801 /* If the symbol was local, any earlier relocatable links will
4802 have adjusted its addend with the gp offset, so compensate
4803 for that now. Don't do it for symbols forced local in this
4804 link, though, since they won't have had the gp offset applied
4808 overflowed_p
= mips_elf_overflow_p (value
, 16);
4811 case R_MIPS16_GOT16
:
4812 case R_MIPS16_CALL16
:
4815 /* VxWorks does not have separate local and global semantics for
4816 R_MIPS*_GOT16; every relocation evaluates to "G". */
4817 if (!htab
->is_vxworks
&& local_p
)
4821 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
4822 local_sections
, FALSE
);
4823 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
4824 symbol
+ addend
, forced
);
4825 if (value
== MINUS_ONE
)
4826 return bfd_reloc_outofrange
;
4828 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
4829 overflowed_p
= mips_elf_overflow_p (value
, 16);
4836 case R_MIPS_TLS_GOTTPREL
:
4837 case R_MIPS_TLS_LDM
:
4838 case R_MIPS_GOT_DISP
:
4841 overflowed_p
= mips_elf_overflow_p (value
, 16);
4844 case R_MIPS_GPREL32
:
4845 value
= (addend
+ symbol
+ gp0
- gp
);
4847 value
&= howto
->dst_mask
;
4851 case R_MIPS_GNU_REL16_S2
:
4852 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
4853 overflowed_p
= mips_elf_overflow_p (value
, 18);
4854 value
>>= howto
->rightshift
;
4855 value
&= howto
->dst_mask
;
4858 case R_MIPS_GOT_HI16
:
4859 case R_MIPS_CALL_HI16
:
4860 /* We're allowed to handle these two relocations identically.
4861 The dynamic linker is allowed to handle the CALL relocations
4862 differently by creating a lazy evaluation stub. */
4864 value
= mips_elf_high (value
);
4865 value
&= howto
->dst_mask
;
4868 case R_MIPS_GOT_LO16
:
4869 case R_MIPS_CALL_LO16
:
4870 value
= g
& howto
->dst_mask
;
4873 case R_MIPS_GOT_PAGE
:
4874 /* GOT_PAGE relocations that reference non-local symbols decay
4875 to GOT_DISP. The corresponding GOT_OFST relocation decays to
4879 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
4880 if (value
== MINUS_ONE
)
4881 return bfd_reloc_outofrange
;
4882 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
4883 overflowed_p
= mips_elf_overflow_p (value
, 16);
4886 case R_MIPS_GOT_OFST
:
4888 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
4891 overflowed_p
= mips_elf_overflow_p (value
, 16);
4895 value
= symbol
- addend
;
4896 value
&= howto
->dst_mask
;
4900 value
= mips_elf_higher (addend
+ symbol
);
4901 value
&= howto
->dst_mask
;
4904 case R_MIPS_HIGHEST
:
4905 value
= mips_elf_highest (addend
+ symbol
);
4906 value
&= howto
->dst_mask
;
4909 case R_MIPS_SCN_DISP
:
4910 value
= symbol
+ addend
- sec
->output_offset
;
4911 value
&= howto
->dst_mask
;
4915 /* This relocation is only a hint. In some cases, we optimize
4916 it into a bal instruction. But we don't try to optimize
4917 branches to the PLT; that will wind up wasting time. */
4918 if (h
!= NULL
&& h
->root
.plt
.offset
!= (bfd_vma
) -1)
4919 return bfd_reloc_continue
;
4920 value
= symbol
+ addend
;
4924 case R_MIPS_GNU_VTINHERIT
:
4925 case R_MIPS_GNU_VTENTRY
:
4926 /* We don't do anything with these at present. */
4927 return bfd_reloc_continue
;
4930 /* An unrecognized relocation type. */
4931 return bfd_reloc_notsupported
;
4934 /* Store the VALUE for our caller. */
4936 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
4939 /* Obtain the field relocated by RELOCATION. */
4942 mips_elf_obtain_contents (reloc_howto_type
*howto
,
4943 const Elf_Internal_Rela
*relocation
,
4944 bfd
*input_bfd
, bfd_byte
*contents
)
4947 bfd_byte
*location
= contents
+ relocation
->r_offset
;
4949 /* Obtain the bytes. */
4950 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
4955 /* It has been determined that the result of the RELOCATION is the
4956 VALUE. Use HOWTO to place VALUE into the output file at the
4957 appropriate position. The SECTION is the section to which the
4958 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
4959 for the relocation must be either JAL or JALX, and it is
4960 unconditionally converted to JALX.
4962 Returns FALSE if anything goes wrong. */
4965 mips_elf_perform_relocation (struct bfd_link_info
*info
,
4966 reloc_howto_type
*howto
,
4967 const Elf_Internal_Rela
*relocation
,
4968 bfd_vma value
, bfd
*input_bfd
,
4969 asection
*input_section
, bfd_byte
*contents
,
4970 bfd_boolean require_jalx
)
4974 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4976 /* Figure out where the relocation is occurring. */
4977 location
= contents
+ relocation
->r_offset
;
4979 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
4981 /* Obtain the current value. */
4982 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
4984 /* Clear the field we are setting. */
4985 x
&= ~howto
->dst_mask
;
4987 /* Set the field. */
4988 x
|= (value
& howto
->dst_mask
);
4990 /* If required, turn JAL into JALX. */
4994 bfd_vma opcode
= x
>> 26;
4995 bfd_vma jalx_opcode
;
4997 /* Check to see if the opcode is already JAL or JALX. */
4998 if (r_type
== R_MIPS16_26
)
5000 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
5005 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
5009 /* If the opcode is not JAL or JALX, there's a problem. */
5012 (*_bfd_error_handler
)
5013 (_("%B: %A+0x%lx: jump to stub routine which is not jal"),
5016 (unsigned long) relocation
->r_offset
);
5017 bfd_set_error (bfd_error_bad_value
);
5021 /* Make this the JALX opcode. */
5022 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
5025 /* On the RM9000, bal is faster than jal, because bal uses branch
5026 prediction hardware. If we are linking for the RM9000, and we
5027 see jal, and bal fits, use it instead. Note that this
5028 transformation should be safe for all architectures. */
5029 if (bfd_get_mach (input_bfd
) == bfd_mach_mips9000
5030 && !info
->relocatable
5032 && ((r_type
== R_MIPS_26
&& (x
>> 26) == 0x3) /* jal addr */
5033 || (r_type
== R_MIPS_JALR
&& x
== 0x0320f809))) /* jalr t9 */
5039 addr
= (input_section
->output_section
->vma
5040 + input_section
->output_offset
5041 + relocation
->r_offset
5043 if (r_type
== R_MIPS_26
)
5044 dest
= (value
<< 2) | ((addr
>> 28) << 28);
5048 if (off
<= 0x1ffff && off
>= -0x20000)
5049 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
5052 /* Put the value into the output. */
5053 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
5055 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, !info
->relocatable
,
5061 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
5064 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
5068 struct mips_elf_link_hash_table
*htab
;
5070 htab
= mips_elf_hash_table (info
);
5071 s
= mips_elf_rel_dyn_section (info
, FALSE
);
5072 BFD_ASSERT (s
!= NULL
);
5074 if (htab
->is_vxworks
)
5075 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
5080 /* Make room for a null element. */
5081 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
5084 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
5088 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5089 is the original relocation, which is now being transformed into a
5090 dynamic relocation. The ADDENDP is adjusted if necessary; the
5091 caller should store the result in place of the original addend. */
5094 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
5095 struct bfd_link_info
*info
,
5096 const Elf_Internal_Rela
*rel
,
5097 struct mips_elf_link_hash_entry
*h
,
5098 asection
*sec
, bfd_vma symbol
,
5099 bfd_vma
*addendp
, asection
*input_section
)
5101 Elf_Internal_Rela outrel
[3];
5106 bfd_boolean defined_p
;
5107 struct mips_elf_link_hash_table
*htab
;
5109 htab
= mips_elf_hash_table (info
);
5110 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5111 dynobj
= elf_hash_table (info
)->dynobj
;
5112 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
5113 BFD_ASSERT (sreloc
!= NULL
);
5114 BFD_ASSERT (sreloc
->contents
!= NULL
);
5115 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
5118 outrel
[0].r_offset
=
5119 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
5120 if (ABI_64_P (output_bfd
))
5122 outrel
[1].r_offset
=
5123 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
5124 outrel
[2].r_offset
=
5125 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
5128 if (outrel
[0].r_offset
== MINUS_ONE
)
5129 /* The relocation field has been deleted. */
5132 if (outrel
[0].r_offset
== MINUS_TWO
)
5134 /* The relocation field has been converted into a relative value of
5135 some sort. Functions like _bfd_elf_write_section_eh_frame expect
5136 the field to be fully relocated, so add in the symbol's value. */
5141 /* We must now calculate the dynamic symbol table index to use
5142 in the relocation. */
5144 && (!h
->root
.def_regular
5145 || (info
->shared
&& !info
->symbolic
&& !h
->root
.forced_local
)))
5147 indx
= h
->root
.dynindx
;
5148 if (SGI_COMPAT (output_bfd
))
5149 defined_p
= h
->root
.def_regular
;
5151 /* ??? glibc's ld.so just adds the final GOT entry to the
5152 relocation field. It therefore treats relocs against
5153 defined symbols in the same way as relocs against
5154 undefined symbols. */
5159 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5161 else if (sec
== NULL
|| sec
->owner
== NULL
)
5163 bfd_set_error (bfd_error_bad_value
);
5168 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5171 asection
*osec
= htab
->root
.text_index_section
;
5172 indx
= elf_section_data (osec
)->dynindx
;
5178 /* Instead of generating a relocation using the section
5179 symbol, we may as well make it a fully relative
5180 relocation. We want to avoid generating relocations to
5181 local symbols because we used to generate them
5182 incorrectly, without adding the original symbol value,
5183 which is mandated by the ABI for section symbols. In
5184 order to give dynamic loaders and applications time to
5185 phase out the incorrect use, we refrain from emitting
5186 section-relative relocations. It's not like they're
5187 useful, after all. This should be a bit more efficient
5189 /* ??? Although this behavior is compatible with glibc's ld.so,
5190 the ABI says that relocations against STN_UNDEF should have
5191 a symbol value of 0. Irix rld honors this, so relocations
5192 against STN_UNDEF have no effect. */
5193 if (!SGI_COMPAT (output_bfd
))
5198 /* If the relocation was previously an absolute relocation and
5199 this symbol will not be referred to by the relocation, we must
5200 adjust it by the value we give it in the dynamic symbol table.
5201 Otherwise leave the job up to the dynamic linker. */
5202 if (defined_p
&& r_type
!= R_MIPS_REL32
)
5205 if (htab
->is_vxworks
)
5206 /* VxWorks uses non-relative relocations for this. */
5207 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
5209 /* The relocation is always an REL32 relocation because we don't
5210 know where the shared library will wind up at load-time. */
5211 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
5214 /* For strict adherence to the ABI specification, we should
5215 generate a R_MIPS_64 relocation record by itself before the
5216 _REL32/_64 record as well, such that the addend is read in as
5217 a 64-bit value (REL32 is a 32-bit relocation, after all).
5218 However, since none of the existing ELF64 MIPS dynamic
5219 loaders seems to care, we don't waste space with these
5220 artificial relocations. If this turns out to not be true,
5221 mips_elf_allocate_dynamic_relocation() should be tweaked so
5222 as to make room for a pair of dynamic relocations per
5223 invocation if ABI_64_P, and here we should generate an
5224 additional relocation record with R_MIPS_64 by itself for a
5225 NULL symbol before this relocation record. */
5226 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
5227 ABI_64_P (output_bfd
)
5230 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
5232 /* Adjust the output offset of the relocation to reference the
5233 correct location in the output file. */
5234 outrel
[0].r_offset
+= (input_section
->output_section
->vma
5235 + input_section
->output_offset
);
5236 outrel
[1].r_offset
+= (input_section
->output_section
->vma
5237 + input_section
->output_offset
);
5238 outrel
[2].r_offset
+= (input_section
->output_section
->vma
5239 + input_section
->output_offset
);
5241 /* Put the relocation back out. We have to use the special
5242 relocation outputter in the 64-bit case since the 64-bit
5243 relocation format is non-standard. */
5244 if (ABI_64_P (output_bfd
))
5246 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5247 (output_bfd
, &outrel
[0],
5249 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5251 else if (htab
->is_vxworks
)
5253 /* VxWorks uses RELA rather than REL dynamic relocations. */
5254 outrel
[0].r_addend
= *addendp
;
5255 bfd_elf32_swap_reloca_out
5256 (output_bfd
, &outrel
[0],
5258 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
5261 bfd_elf32_swap_reloc_out
5262 (output_bfd
, &outrel
[0],
5263 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
5265 /* We've now added another relocation. */
5266 ++sreloc
->reloc_count
;
5268 /* Make sure the output section is writable. The dynamic linker
5269 will be writing to it. */
5270 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5273 /* On IRIX5, make an entry of compact relocation info. */
5274 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
5276 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5281 Elf32_crinfo cptrel
;
5283 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5284 cptrel
.vaddr
= (rel
->r_offset
5285 + input_section
->output_section
->vma
5286 + input_section
->output_offset
);
5287 if (r_type
== R_MIPS_REL32
)
5288 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5290 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5291 mips_elf_set_cr_dist2to (cptrel
, 0);
5292 cptrel
.konst
= *addendp
;
5294 cr
= (scpt
->contents
5295 + sizeof (Elf32_External_compact_rel
));
5296 mips_elf_set_cr_relvaddr (cptrel
, 0);
5297 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5298 ((Elf32_External_crinfo
*) cr
5299 + scpt
->reloc_count
));
5300 ++scpt
->reloc_count
;
5304 /* If we've written this relocation for a readonly section,
5305 we need to set DF_TEXTREL again, so that we do not delete the
5307 if (MIPS_ELF_READONLY_SECTION (input_section
))
5308 info
->flags
|= DF_TEXTREL
;
5313 /* Return the MACH for a MIPS e_flags value. */
5316 _bfd_elf_mips_mach (flagword flags
)
5318 switch (flags
& EF_MIPS_MACH
)
5320 case E_MIPS_MACH_3900
:
5321 return bfd_mach_mips3900
;
5323 case E_MIPS_MACH_4010
:
5324 return bfd_mach_mips4010
;
5326 case E_MIPS_MACH_4100
:
5327 return bfd_mach_mips4100
;
5329 case E_MIPS_MACH_4111
:
5330 return bfd_mach_mips4111
;
5332 case E_MIPS_MACH_4120
:
5333 return bfd_mach_mips4120
;
5335 case E_MIPS_MACH_4650
:
5336 return bfd_mach_mips4650
;
5338 case E_MIPS_MACH_5400
:
5339 return bfd_mach_mips5400
;
5341 case E_MIPS_MACH_5500
:
5342 return bfd_mach_mips5500
;
5344 case E_MIPS_MACH_9000
:
5345 return bfd_mach_mips9000
;
5347 case E_MIPS_MACH_SB1
:
5348 return bfd_mach_mips_sb1
;
5350 case E_MIPS_MACH_LS2E
:
5351 return bfd_mach_mips_loongson_2e
;
5353 case E_MIPS_MACH_LS2F
:
5354 return bfd_mach_mips_loongson_2f
;
5356 case E_MIPS_MACH_OCTEON
:
5357 return bfd_mach_mips_octeon
;
5360 switch (flags
& EF_MIPS_ARCH
)
5364 return bfd_mach_mips3000
;
5367 return bfd_mach_mips6000
;
5370 return bfd_mach_mips4000
;
5373 return bfd_mach_mips8000
;
5376 return bfd_mach_mips5
;
5378 case E_MIPS_ARCH_32
:
5379 return bfd_mach_mipsisa32
;
5381 case E_MIPS_ARCH_64
:
5382 return bfd_mach_mipsisa64
;
5384 case E_MIPS_ARCH_32R2
:
5385 return bfd_mach_mipsisa32r2
;
5387 case E_MIPS_ARCH_64R2
:
5388 return bfd_mach_mipsisa64r2
;
5395 /* Return printable name for ABI. */
5397 static INLINE
char *
5398 elf_mips_abi_name (bfd
*abfd
)
5402 flags
= elf_elfheader (abfd
)->e_flags
;
5403 switch (flags
& EF_MIPS_ABI
)
5406 if (ABI_N32_P (abfd
))
5408 else if (ABI_64_P (abfd
))
5412 case E_MIPS_ABI_O32
:
5414 case E_MIPS_ABI_O64
:
5416 case E_MIPS_ABI_EABI32
:
5418 case E_MIPS_ABI_EABI64
:
5421 return "unknown abi";
5425 /* MIPS ELF uses two common sections. One is the usual one, and the
5426 other is for small objects. All the small objects are kept
5427 together, and then referenced via the gp pointer, which yields
5428 faster assembler code. This is what we use for the small common
5429 section. This approach is copied from ecoff.c. */
5430 static asection mips_elf_scom_section
;
5431 static asymbol mips_elf_scom_symbol
;
5432 static asymbol
*mips_elf_scom_symbol_ptr
;
5434 /* MIPS ELF also uses an acommon section, which represents an
5435 allocated common symbol which may be overridden by a
5436 definition in a shared library. */
5437 static asection mips_elf_acom_section
;
5438 static asymbol mips_elf_acom_symbol
;
5439 static asymbol
*mips_elf_acom_symbol_ptr
;
5441 /* This is used for both the 32-bit and the 64-bit ABI. */
5444 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
5446 elf_symbol_type
*elfsym
;
5448 /* Handle the special MIPS section numbers that a symbol may use. */
5449 elfsym
= (elf_symbol_type
*) asym
;
5450 switch (elfsym
->internal_elf_sym
.st_shndx
)
5452 case SHN_MIPS_ACOMMON
:
5453 /* This section is used in a dynamically linked executable file.
5454 It is an allocated common section. The dynamic linker can
5455 either resolve these symbols to something in a shared
5456 library, or it can just leave them here. For our purposes,
5457 we can consider these symbols to be in a new section. */
5458 if (mips_elf_acom_section
.name
== NULL
)
5460 /* Initialize the acommon section. */
5461 mips_elf_acom_section
.name
= ".acommon";
5462 mips_elf_acom_section
.flags
= SEC_ALLOC
;
5463 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
5464 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
5465 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
5466 mips_elf_acom_symbol
.name
= ".acommon";
5467 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
5468 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
5469 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
5471 asym
->section
= &mips_elf_acom_section
;
5475 /* Common symbols less than the GP size are automatically
5476 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
5477 if (asym
->value
> elf_gp_size (abfd
)
5478 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
5479 || IRIX_COMPAT (abfd
) == ict_irix6
)
5482 case SHN_MIPS_SCOMMON
:
5483 if (mips_elf_scom_section
.name
== NULL
)
5485 /* Initialize the small common section. */
5486 mips_elf_scom_section
.name
= ".scommon";
5487 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
5488 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
5489 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
5490 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
5491 mips_elf_scom_symbol
.name
= ".scommon";
5492 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
5493 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
5494 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
5496 asym
->section
= &mips_elf_scom_section
;
5497 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
5500 case SHN_MIPS_SUNDEFINED
:
5501 asym
->section
= bfd_und_section_ptr
;
5506 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
5508 BFD_ASSERT (SGI_COMPAT (abfd
));
5509 if (section
!= NULL
)
5511 asym
->section
= section
;
5512 /* MIPS_TEXT is a bit special, the address is not an offset
5513 to the base of the .text section. So substract the section
5514 base address to make it an offset. */
5515 asym
->value
-= section
->vma
;
5522 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
5524 BFD_ASSERT (SGI_COMPAT (abfd
));
5525 if (section
!= NULL
)
5527 asym
->section
= section
;
5528 /* MIPS_DATA is a bit special, the address is not an offset
5529 to the base of the .data section. So substract the section
5530 base address to make it an offset. */
5531 asym
->value
-= section
->vma
;
5537 /* If this is an odd-valued function symbol, assume it's a MIPS16 one. */
5538 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
5539 && (asym
->value
& 1) != 0)
5542 elfsym
->internal_elf_sym
.st_other
5543 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
5547 /* Implement elf_backend_eh_frame_address_size. This differs from
5548 the default in the way it handles EABI64.
5550 EABI64 was originally specified as an LP64 ABI, and that is what
5551 -mabi=eabi normally gives on a 64-bit target. However, gcc has
5552 historically accepted the combination of -mabi=eabi and -mlong32,
5553 and this ILP32 variation has become semi-official over time.
5554 Both forms use elf32 and have pointer-sized FDE addresses.
5556 If an EABI object was generated by GCC 4.0 or above, it will have
5557 an empty .gcc_compiled_longXX section, where XX is the size of longs
5558 in bits. Unfortunately, ILP32 objects generated by earlier compilers
5559 have no special marking to distinguish them from LP64 objects.
5561 We don't want users of the official LP64 ABI to be punished for the
5562 existence of the ILP32 variant, but at the same time, we don't want
5563 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
5564 We therefore take the following approach:
5566 - If ABFD contains a .gcc_compiled_longXX section, use it to
5567 determine the pointer size.
5569 - Otherwise check the type of the first relocation. Assume that
5570 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
5574 The second check is enough to detect LP64 objects generated by pre-4.0
5575 compilers because, in the kind of output generated by those compilers,
5576 the first relocation will be associated with either a CIE personality
5577 routine or an FDE start address. Furthermore, the compilers never
5578 used a special (non-pointer) encoding for this ABI.
5580 Checking the relocation type should also be safe because there is no
5581 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
5585 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
5587 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
5589 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
5591 bfd_boolean long32_p
, long64_p
;
5593 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
5594 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
5595 if (long32_p
&& long64_p
)
5602 if (sec
->reloc_count
> 0
5603 && elf_section_data (sec
)->relocs
!= NULL
5604 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
5613 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
5614 relocations against two unnamed section symbols to resolve to the
5615 same address. For example, if we have code like:
5617 lw $4,%got_disp(.data)($gp)
5618 lw $25,%got_disp(.text)($gp)
5621 then the linker will resolve both relocations to .data and the program
5622 will jump there rather than to .text.
5624 We can work around this problem by giving names to local section symbols.
5625 This is also what the MIPSpro tools do. */
5628 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
5630 return SGI_COMPAT (abfd
);
5633 /* Work over a section just before writing it out. This routine is
5634 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
5635 sections that need the SHF_MIPS_GPREL flag by name; there has to be
5639 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
5641 if (hdr
->sh_type
== SHT_MIPS_REGINFO
5642 && hdr
->sh_size
> 0)
5646 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
5647 BFD_ASSERT (hdr
->contents
== NULL
);
5650 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
5653 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5654 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5658 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
5659 && hdr
->bfd_section
!= NULL
5660 && mips_elf_section_data (hdr
->bfd_section
) != NULL
5661 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
5663 bfd_byte
*contents
, *l
, *lend
;
5665 /* We stored the section contents in the tdata field in the
5666 set_section_contents routine. We save the section contents
5667 so that we don't have to read them again.
5668 At this point we know that elf_gp is set, so we can look
5669 through the section contents to see if there is an
5670 ODK_REGINFO structure. */
5672 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
5674 lend
= contents
+ hdr
->sh_size
;
5675 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5677 Elf_Internal_Options intopt
;
5679 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5681 if (intopt
.size
< sizeof (Elf_External_Options
))
5683 (*_bfd_error_handler
)
5684 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5685 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
5688 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
5695 + sizeof (Elf_External_Options
)
5696 + (sizeof (Elf64_External_RegInfo
) - 8)),
5699 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
5700 if (bfd_bwrite (buf
, 8, abfd
) != 8)
5703 else if (intopt
.kind
== ODK_REGINFO
)
5710 + sizeof (Elf_External_Options
)
5711 + (sizeof (Elf32_External_RegInfo
) - 4)),
5714 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5715 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5722 if (hdr
->bfd_section
!= NULL
)
5724 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
5726 if (strcmp (name
, ".sdata") == 0
5727 || strcmp (name
, ".lit8") == 0
5728 || strcmp (name
, ".lit4") == 0)
5730 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5731 hdr
->sh_type
= SHT_PROGBITS
;
5733 else if (strcmp (name
, ".sbss") == 0)
5735 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5736 hdr
->sh_type
= SHT_NOBITS
;
5738 else if (strcmp (name
, ".srdata") == 0)
5740 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
5741 hdr
->sh_type
= SHT_PROGBITS
;
5743 else if (strcmp (name
, ".compact_rel") == 0)
5746 hdr
->sh_type
= SHT_PROGBITS
;
5748 else if (strcmp (name
, ".rtproc") == 0)
5750 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
5752 unsigned int adjust
;
5754 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
5756 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
5764 /* Handle a MIPS specific section when reading an object file. This
5765 is called when elfcode.h finds a section with an unknown type.
5766 This routine supports both the 32-bit and 64-bit ELF ABI.
5768 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
5772 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
5773 Elf_Internal_Shdr
*hdr
,
5779 /* There ought to be a place to keep ELF backend specific flags, but
5780 at the moment there isn't one. We just keep track of the
5781 sections by their name, instead. Fortunately, the ABI gives
5782 suggested names for all the MIPS specific sections, so we will
5783 probably get away with this. */
5784 switch (hdr
->sh_type
)
5786 case SHT_MIPS_LIBLIST
:
5787 if (strcmp (name
, ".liblist") != 0)
5791 if (strcmp (name
, ".msym") != 0)
5794 case SHT_MIPS_CONFLICT
:
5795 if (strcmp (name
, ".conflict") != 0)
5798 case SHT_MIPS_GPTAB
:
5799 if (! CONST_STRNEQ (name
, ".gptab."))
5802 case SHT_MIPS_UCODE
:
5803 if (strcmp (name
, ".ucode") != 0)
5806 case SHT_MIPS_DEBUG
:
5807 if (strcmp (name
, ".mdebug") != 0)
5809 flags
= SEC_DEBUGGING
;
5811 case SHT_MIPS_REGINFO
:
5812 if (strcmp (name
, ".reginfo") != 0
5813 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
5815 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
5817 case SHT_MIPS_IFACE
:
5818 if (strcmp (name
, ".MIPS.interfaces") != 0)
5821 case SHT_MIPS_CONTENT
:
5822 if (! CONST_STRNEQ (name
, ".MIPS.content"))
5825 case SHT_MIPS_OPTIONS
:
5826 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
5829 case SHT_MIPS_DWARF
:
5830 if (! CONST_STRNEQ (name
, ".debug_")
5831 && ! CONST_STRNEQ (name
, ".zdebug_"))
5834 case SHT_MIPS_SYMBOL_LIB
:
5835 if (strcmp (name
, ".MIPS.symlib") != 0)
5838 case SHT_MIPS_EVENTS
:
5839 if (! CONST_STRNEQ (name
, ".MIPS.events")
5840 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
5847 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
5852 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
5853 (bfd_get_section_flags (abfd
,
5859 /* FIXME: We should record sh_info for a .gptab section. */
5861 /* For a .reginfo section, set the gp value in the tdata information
5862 from the contents of this section. We need the gp value while
5863 processing relocs, so we just get it now. The .reginfo section
5864 is not used in the 64-bit MIPS ELF ABI. */
5865 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
5867 Elf32_External_RegInfo ext
;
5870 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
5871 &ext
, 0, sizeof ext
))
5873 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
5874 elf_gp (abfd
) = s
.ri_gp_value
;
5877 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
5878 set the gp value based on what we find. We may see both
5879 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
5880 they should agree. */
5881 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
5883 bfd_byte
*contents
, *l
, *lend
;
5885 contents
= bfd_malloc (hdr
->sh_size
);
5886 if (contents
== NULL
)
5888 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
5895 lend
= contents
+ hdr
->sh_size
;
5896 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5898 Elf_Internal_Options intopt
;
5900 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5902 if (intopt
.size
< sizeof (Elf_External_Options
))
5904 (*_bfd_error_handler
)
5905 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5906 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
5909 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
5911 Elf64_Internal_RegInfo intreg
;
5913 bfd_mips_elf64_swap_reginfo_in
5915 ((Elf64_External_RegInfo
*)
5916 (l
+ sizeof (Elf_External_Options
))),
5918 elf_gp (abfd
) = intreg
.ri_gp_value
;
5920 else if (intopt
.kind
== ODK_REGINFO
)
5922 Elf32_RegInfo intreg
;
5924 bfd_mips_elf32_swap_reginfo_in
5926 ((Elf32_External_RegInfo
*)
5927 (l
+ sizeof (Elf_External_Options
))),
5929 elf_gp (abfd
) = intreg
.ri_gp_value
;
5939 /* Set the correct type for a MIPS ELF section. We do this by the
5940 section name, which is a hack, but ought to work. This routine is
5941 used by both the 32-bit and the 64-bit ABI. */
5944 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
5946 const char *name
= bfd_get_section_name (abfd
, sec
);
5948 if (strcmp (name
, ".liblist") == 0)
5950 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
5951 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
5952 /* The sh_link field is set in final_write_processing. */
5954 else if (strcmp (name
, ".conflict") == 0)
5955 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
5956 else if (CONST_STRNEQ (name
, ".gptab."))
5958 hdr
->sh_type
= SHT_MIPS_GPTAB
;
5959 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
5960 /* The sh_info field is set in final_write_processing. */
5962 else if (strcmp (name
, ".ucode") == 0)
5963 hdr
->sh_type
= SHT_MIPS_UCODE
;
5964 else if (strcmp (name
, ".mdebug") == 0)
5966 hdr
->sh_type
= SHT_MIPS_DEBUG
;
5967 /* In a shared object on IRIX 5.3, the .mdebug section has an
5968 entsize of 0. FIXME: Does this matter? */
5969 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
5970 hdr
->sh_entsize
= 0;
5972 hdr
->sh_entsize
= 1;
5974 else if (strcmp (name
, ".reginfo") == 0)
5976 hdr
->sh_type
= SHT_MIPS_REGINFO
;
5977 /* In a shared object on IRIX 5.3, the .reginfo section has an
5978 entsize of 0x18. FIXME: Does this matter? */
5979 if (SGI_COMPAT (abfd
))
5981 if ((abfd
->flags
& DYNAMIC
) != 0)
5982 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
5984 hdr
->sh_entsize
= 1;
5987 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
5989 else if (SGI_COMPAT (abfd
)
5990 && (strcmp (name
, ".hash") == 0
5991 || strcmp (name
, ".dynamic") == 0
5992 || strcmp (name
, ".dynstr") == 0))
5994 if (SGI_COMPAT (abfd
))
5995 hdr
->sh_entsize
= 0;
5997 /* This isn't how the IRIX6 linker behaves. */
5998 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6001 else if (strcmp (name
, ".got") == 0
6002 || strcmp (name
, ".srdata") == 0
6003 || strcmp (name
, ".sdata") == 0
6004 || strcmp (name
, ".sbss") == 0
6005 || strcmp (name
, ".lit4") == 0
6006 || strcmp (name
, ".lit8") == 0)
6007 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
6008 else if (strcmp (name
, ".MIPS.interfaces") == 0)
6010 hdr
->sh_type
= SHT_MIPS_IFACE
;
6011 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6013 else if (CONST_STRNEQ (name
, ".MIPS.content"))
6015 hdr
->sh_type
= SHT_MIPS_CONTENT
;
6016 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6017 /* The sh_info field is set in final_write_processing. */
6019 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6021 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
6022 hdr
->sh_entsize
= 1;
6023 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6025 else if (CONST_STRNEQ (name
, ".debug_")
6026 || CONST_STRNEQ (name
, ".zdebug_"))
6028 hdr
->sh_type
= SHT_MIPS_DWARF
;
6030 /* Irix facilities such as libexc expect a single .debug_frame
6031 per executable, the system ones have NOSTRIP set and the linker
6032 doesn't merge sections with different flags so ... */
6033 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
6034 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6036 else if (strcmp (name
, ".MIPS.symlib") == 0)
6038 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
6039 /* The sh_link and sh_info fields are set in
6040 final_write_processing. */
6042 else if (CONST_STRNEQ (name
, ".MIPS.events")
6043 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
6045 hdr
->sh_type
= SHT_MIPS_EVENTS
;
6046 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6047 /* The sh_link field is set in final_write_processing. */
6049 else if (strcmp (name
, ".msym") == 0)
6051 hdr
->sh_type
= SHT_MIPS_MSYM
;
6052 hdr
->sh_flags
|= SHF_ALLOC
;
6053 hdr
->sh_entsize
= 8;
6056 /* The generic elf_fake_sections will set up REL_HDR using the default
6057 kind of relocations. We used to set up a second header for the
6058 non-default kind of relocations here, but only NewABI would use
6059 these, and the IRIX ld doesn't like resulting empty RELA sections.
6060 Thus we create those header only on demand now. */
6065 /* Given a BFD section, try to locate the corresponding ELF section
6066 index. This is used by both the 32-bit and the 64-bit ABI.
6067 Actually, it's not clear to me that the 64-bit ABI supports these,
6068 but for non-PIC objects we will certainly want support for at least
6069 the .scommon section. */
6072 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6073 asection
*sec
, int *retval
)
6075 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
6077 *retval
= SHN_MIPS_SCOMMON
;
6080 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
6082 *retval
= SHN_MIPS_ACOMMON
;
6088 /* Hook called by the linker routine which adds symbols from an object
6089 file. We must handle the special MIPS section numbers here. */
6092 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6093 Elf_Internal_Sym
*sym
, const char **namep
,
6094 flagword
*flagsp ATTRIBUTE_UNUSED
,
6095 asection
**secp
, bfd_vma
*valp
)
6097 if (SGI_COMPAT (abfd
)
6098 && (abfd
->flags
& DYNAMIC
) != 0
6099 && strcmp (*namep
, "_rld_new_interface") == 0)
6101 /* Skip IRIX5 rld entry name. */
6106 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
6107 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
6108 by setting a DT_NEEDED for the shared object. Since _gp_disp is
6109 a magic symbol resolved by the linker, we ignore this bogus definition
6110 of _gp_disp. New ABI objects do not suffer from this problem so this
6111 is not done for them. */
6113 && (sym
->st_shndx
== SHN_ABS
)
6114 && (strcmp (*namep
, "_gp_disp") == 0))
6120 switch (sym
->st_shndx
)
6123 /* Common symbols less than the GP size are automatically
6124 treated as SHN_MIPS_SCOMMON symbols. */
6125 if (sym
->st_size
> elf_gp_size (abfd
)
6126 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
6127 || IRIX_COMPAT (abfd
) == ict_irix6
)
6130 case SHN_MIPS_SCOMMON
:
6131 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
6132 (*secp
)->flags
|= SEC_IS_COMMON
;
6133 *valp
= sym
->st_size
;
6137 /* This section is used in a shared object. */
6138 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
6140 asymbol
*elf_text_symbol
;
6141 asection
*elf_text_section
;
6142 bfd_size_type amt
= sizeof (asection
);
6144 elf_text_section
= bfd_zalloc (abfd
, amt
);
6145 if (elf_text_section
== NULL
)
6148 amt
= sizeof (asymbol
);
6149 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
6150 if (elf_text_symbol
== NULL
)
6153 /* Initialize the section. */
6155 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
6156 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
6158 elf_text_section
->symbol
= elf_text_symbol
;
6159 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
6161 elf_text_section
->name
= ".text";
6162 elf_text_section
->flags
= SEC_NO_FLAGS
;
6163 elf_text_section
->output_section
= NULL
;
6164 elf_text_section
->owner
= abfd
;
6165 elf_text_symbol
->name
= ".text";
6166 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6167 elf_text_symbol
->section
= elf_text_section
;
6169 /* This code used to do *secp = bfd_und_section_ptr if
6170 info->shared. I don't know why, and that doesn't make sense,
6171 so I took it out. */
6172 *secp
= elf_tdata (abfd
)->elf_text_section
;
6175 case SHN_MIPS_ACOMMON
:
6176 /* Fall through. XXX Can we treat this as allocated data? */
6178 /* This section is used in a shared object. */
6179 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
6181 asymbol
*elf_data_symbol
;
6182 asection
*elf_data_section
;
6183 bfd_size_type amt
= sizeof (asection
);
6185 elf_data_section
= bfd_zalloc (abfd
, amt
);
6186 if (elf_data_section
== NULL
)
6189 amt
= sizeof (asymbol
);
6190 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
6191 if (elf_data_symbol
== NULL
)
6194 /* Initialize the section. */
6196 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
6197 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
6199 elf_data_section
->symbol
= elf_data_symbol
;
6200 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
6202 elf_data_section
->name
= ".data";
6203 elf_data_section
->flags
= SEC_NO_FLAGS
;
6204 elf_data_section
->output_section
= NULL
;
6205 elf_data_section
->owner
= abfd
;
6206 elf_data_symbol
->name
= ".data";
6207 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6208 elf_data_symbol
->section
= elf_data_section
;
6210 /* This code used to do *secp = bfd_und_section_ptr if
6211 info->shared. I don't know why, and that doesn't make sense,
6212 so I took it out. */
6213 *secp
= elf_tdata (abfd
)->elf_data_section
;
6216 case SHN_MIPS_SUNDEFINED
:
6217 *secp
= bfd_und_section_ptr
;
6221 if (SGI_COMPAT (abfd
)
6223 && info
->output_bfd
->xvec
== abfd
->xvec
6224 && strcmp (*namep
, "__rld_obj_head") == 0)
6226 struct elf_link_hash_entry
*h
;
6227 struct bfd_link_hash_entry
*bh
;
6229 /* Mark __rld_obj_head as dynamic. */
6231 if (! (_bfd_generic_link_add_one_symbol
6232 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
6233 get_elf_backend_data (abfd
)->collect
, &bh
)))
6236 h
= (struct elf_link_hash_entry
*) bh
;
6239 h
->type
= STT_OBJECT
;
6241 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6244 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
6247 /* If this is a mips16 text symbol, add 1 to the value to make it
6248 odd. This will cause something like .word SYM to come up with
6249 the right value when it is loaded into the PC. */
6250 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6256 /* This hook function is called before the linker writes out a global
6257 symbol. We mark symbols as small common if appropriate. This is
6258 also where we undo the increment of the value for a mips16 symbol. */
6261 _bfd_mips_elf_link_output_symbol_hook
6262 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6263 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
6264 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
6266 /* If we see a common symbol, which implies a relocatable link, then
6267 if a symbol was small common in an input file, mark it as small
6268 common in the output file. */
6269 if (sym
->st_shndx
== SHN_COMMON
6270 && strcmp (input_sec
->name
, ".scommon") == 0)
6271 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6273 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6274 sym
->st_value
&= ~1;
6279 /* Functions for the dynamic linker. */
6281 /* Create dynamic sections when linking against a dynamic object. */
6284 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6286 struct elf_link_hash_entry
*h
;
6287 struct bfd_link_hash_entry
*bh
;
6289 register asection
*s
;
6290 const char * const *namep
;
6291 struct mips_elf_link_hash_table
*htab
;
6293 htab
= mips_elf_hash_table (info
);
6294 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6295 | SEC_LINKER_CREATED
| SEC_READONLY
);
6297 /* The psABI requires a read-only .dynamic section, but the VxWorks
6299 if (!htab
->is_vxworks
)
6301 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6304 if (! bfd_set_section_flags (abfd
, s
, flags
))
6309 /* We need to create .got section. */
6310 if (! mips_elf_create_got_section (abfd
, info
, FALSE
))
6313 if (! mips_elf_rel_dyn_section (info
, TRUE
))
6316 /* Create .stub section. */
6317 s
= bfd_make_section_with_flags (abfd
,
6318 MIPS_ELF_STUB_SECTION_NAME (abfd
),
6321 || ! bfd_set_section_alignment (abfd
, s
,
6322 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6326 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
6328 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6330 s
= bfd_make_section_with_flags (abfd
, ".rld_map",
6331 flags
&~ (flagword
) SEC_READONLY
);
6333 || ! bfd_set_section_alignment (abfd
, s
,
6334 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6338 /* On IRIX5, we adjust add some additional symbols and change the
6339 alignments of several sections. There is no ABI documentation
6340 indicating that this is necessary on IRIX6, nor any evidence that
6341 the linker takes such action. */
6342 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6344 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6347 if (! (_bfd_generic_link_add_one_symbol
6348 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
6349 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6352 h
= (struct elf_link_hash_entry
*) bh
;
6355 h
->type
= STT_SECTION
;
6357 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6361 /* We need to create a .compact_rel section. */
6362 if (SGI_COMPAT (abfd
))
6364 if (!mips_elf_create_compact_rel_section (abfd
, info
))
6368 /* Change alignments of some sections. */
6369 s
= bfd_get_section_by_name (abfd
, ".hash");
6371 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6372 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6374 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6375 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6377 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6378 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6380 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6381 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6383 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6390 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
6392 if (!(_bfd_generic_link_add_one_symbol
6393 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
6394 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6397 h
= (struct elf_link_hash_entry
*) bh
;
6400 h
->type
= STT_SECTION
;
6402 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6405 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
6407 /* __rld_map is a four byte word located in the .data section
6408 and is filled in by the rtld to contain a pointer to
6409 the _r_debug structure. Its symbol value will be set in
6410 _bfd_mips_elf_finish_dynamic_symbol. */
6411 s
= bfd_get_section_by_name (abfd
, ".rld_map");
6412 BFD_ASSERT (s
!= NULL
);
6414 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
6416 if (!(_bfd_generic_link_add_one_symbol
6417 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
6418 get_elf_backend_data (abfd
)->collect
, &bh
)))
6421 h
= (struct elf_link_hash_entry
*) bh
;
6424 h
->type
= STT_OBJECT
;
6426 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6431 if (htab
->is_vxworks
)
6433 /* Create the .plt, .rela.plt, .dynbss and .rela.bss sections.
6434 Also create the _PROCEDURE_LINKAGE_TABLE symbol. */
6435 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
6438 /* Cache the sections created above. */
6439 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
6440 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
6441 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
6442 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
6444 || (!htab
->srelbss
&& !info
->shared
)
6449 /* Do the usual VxWorks handling. */
6450 if (!elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
6453 /* Work out the PLT sizes. */
6456 htab
->plt_header_size
6457 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
6458 htab
->plt_entry_size
6459 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
6463 htab
->plt_header_size
6464 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
6465 htab
->plt_entry_size
6466 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
6473 /* Return true if relocation REL against section SEC is a REL rather than
6474 RELA relocation. RELOCS is the first relocation in the section and
6475 ABFD is the bfd that contains SEC. */
6478 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
6479 const Elf_Internal_Rela
*relocs
,
6480 const Elf_Internal_Rela
*rel
)
6482 Elf_Internal_Shdr
*rel_hdr
;
6483 const struct elf_backend_data
*bed
;
6485 /* To determine which flavor or relocation this is, we depend on the
6486 fact that the INPUT_SECTION's REL_HDR is read before its REL_HDR2. */
6487 rel_hdr
= &elf_section_data (sec
)->rel_hdr
;
6488 bed
= get_elf_backend_data (abfd
);
6489 if ((size_t) (rel
- relocs
)
6490 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
6491 rel_hdr
= elf_section_data (sec
)->rel_hdr2
;
6492 return rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (abfd
);
6495 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
6496 HOWTO is the relocation's howto and CONTENTS points to the contents
6497 of the section that REL is against. */
6500 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
6501 reloc_howto_type
*howto
, bfd_byte
*contents
)
6504 unsigned int r_type
;
6507 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6508 location
= contents
+ rel
->r_offset
;
6510 /* Get the addend, which is stored in the input file. */
6511 _bfd_mips16_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
6512 addend
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
6513 _bfd_mips16_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
6515 return addend
& howto
->src_mask
;
6518 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
6519 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
6520 and update *ADDEND with the final addend. Return true on success
6521 or false if the LO16 could not be found. RELEND is the exclusive
6522 upper bound on the relocations for REL's section. */
6525 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
6526 const Elf_Internal_Rela
*rel
,
6527 const Elf_Internal_Rela
*relend
,
6528 bfd_byte
*contents
, bfd_vma
*addend
)
6530 unsigned int r_type
, lo16_type
;
6531 const Elf_Internal_Rela
*lo16_relocation
;
6532 reloc_howto_type
*lo16_howto
;
6535 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6536 if (mips16_reloc_p (r_type
))
6537 lo16_type
= R_MIPS16_LO16
;
6539 lo16_type
= R_MIPS_LO16
;
6541 /* The combined value is the sum of the HI16 addend, left-shifted by
6542 sixteen bits, and the LO16 addend, sign extended. (Usually, the
6543 code does a `lui' of the HI16 value, and then an `addiu' of the
6546 Scan ahead to find a matching LO16 relocation.
6548 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
6549 be immediately following. However, for the IRIX6 ABI, the next
6550 relocation may be a composed relocation consisting of several
6551 relocations for the same address. In that case, the R_MIPS_LO16
6552 relocation may occur as one of these. We permit a similar
6553 extension in general, as that is useful for GCC.
6555 In some cases GCC dead code elimination removes the LO16 but keeps
6556 the corresponding HI16. This is strictly speaking a violation of
6557 the ABI but not immediately harmful. */
6558 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
6559 if (lo16_relocation
== NULL
)
6562 /* Obtain the addend kept there. */
6563 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
6564 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
6566 l
<<= lo16_howto
->rightshift
;
6567 l
= _bfd_mips_elf_sign_extend (l
, 16);
6574 /* Try to read the contents of section SEC in bfd ABFD. Return true and
6575 store the contents in *CONTENTS on success. Assume that *CONTENTS
6576 already holds the contents if it is nonull on entry. */
6579 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
6584 /* Get cached copy if it exists. */
6585 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6587 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
6591 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
6594 /* Look through the relocs for a section during the first phase, and
6595 allocate space in the global offset table. */
6598 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6599 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6603 Elf_Internal_Shdr
*symtab_hdr
;
6604 struct elf_link_hash_entry
**sym_hashes
;
6606 const Elf_Internal_Rela
*rel
;
6607 const Elf_Internal_Rela
*rel_end
;
6609 const struct elf_backend_data
*bed
;
6610 struct mips_elf_link_hash_table
*htab
;
6613 reloc_howto_type
*howto
;
6615 if (info
->relocatable
)
6618 htab
= mips_elf_hash_table (info
);
6619 dynobj
= elf_hash_table (info
)->dynobj
;
6620 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6621 sym_hashes
= elf_sym_hashes (abfd
);
6622 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6624 bed
= get_elf_backend_data (abfd
);
6625 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6627 /* Check for the mips16 stub sections. */
6629 name
= bfd_get_section_name (abfd
, sec
);
6630 if (FN_STUB_P (name
))
6632 unsigned long r_symndx
;
6634 /* Look at the relocation information to figure out which symbol
6637 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
6640 (*_bfd_error_handler
)
6641 (_("%B: Warning: cannot determine the target function for"
6642 " stub section `%s'"),
6644 bfd_set_error (bfd_error_bad_value
);
6648 if (r_symndx
< extsymoff
6649 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6653 /* This stub is for a local symbol. This stub will only be
6654 needed if there is some relocation in this BFD, other
6655 than a 16 bit function call, which refers to this symbol. */
6656 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6658 Elf_Internal_Rela
*sec_relocs
;
6659 const Elf_Internal_Rela
*r
, *rend
;
6661 /* We can ignore stub sections when looking for relocs. */
6662 if ((o
->flags
& SEC_RELOC
) == 0
6663 || o
->reloc_count
== 0
6664 || section_allows_mips16_refs_p (o
))
6668 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
6670 if (sec_relocs
== NULL
)
6673 rend
= sec_relocs
+ o
->reloc_count
;
6674 for (r
= sec_relocs
; r
< rend
; r
++)
6675 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
6676 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
6679 if (elf_section_data (o
)->relocs
!= sec_relocs
)
6688 /* There is no non-call reloc for this stub, so we do
6689 not need it. Since this function is called before
6690 the linker maps input sections to output sections, we
6691 can easily discard it by setting the SEC_EXCLUDE
6693 sec
->flags
|= SEC_EXCLUDE
;
6697 /* Record this stub in an array of local symbol stubs for
6699 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6701 unsigned long symcount
;
6705 if (elf_bad_symtab (abfd
))
6706 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
6708 symcount
= symtab_hdr
->sh_info
;
6709 amt
= symcount
* sizeof (asection
*);
6710 n
= bfd_zalloc (abfd
, amt
);
6713 elf_tdata (abfd
)->local_stubs
= n
;
6716 sec
->flags
|= SEC_KEEP
;
6717 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6719 /* We don't need to set mips16_stubs_seen in this case.
6720 That flag is used to see whether we need to look through
6721 the global symbol table for stubs. We don't need to set
6722 it here, because we just have a local stub. */
6726 struct mips_elf_link_hash_entry
*h
;
6728 h
= ((struct mips_elf_link_hash_entry
*)
6729 sym_hashes
[r_symndx
- extsymoff
]);
6731 while (h
->root
.root
.type
== bfd_link_hash_indirect
6732 || h
->root
.root
.type
== bfd_link_hash_warning
)
6733 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
6735 /* H is the symbol this stub is for. */
6737 /* If we already have an appropriate stub for this function, we
6738 don't need another one, so we can discard this one. Since
6739 this function is called before the linker maps input sections
6740 to output sections, we can easily discard it by setting the
6741 SEC_EXCLUDE flag. */
6742 if (h
->fn_stub
!= NULL
)
6744 sec
->flags
|= SEC_EXCLUDE
;
6748 sec
->flags
|= SEC_KEEP
;
6750 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
6753 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
6755 unsigned long r_symndx
;
6756 struct mips_elf_link_hash_entry
*h
;
6759 /* Look at the relocation information to figure out which symbol
6762 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
6765 (*_bfd_error_handler
)
6766 (_("%B: Warning: cannot determine the target function for"
6767 " stub section `%s'"),
6769 bfd_set_error (bfd_error_bad_value
);
6773 if (r_symndx
< extsymoff
6774 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6778 /* This stub is for a local symbol. This stub will only be
6779 needed if there is some relocation (R_MIPS16_26) in this BFD
6780 that refers to this symbol. */
6781 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6783 Elf_Internal_Rela
*sec_relocs
;
6784 const Elf_Internal_Rela
*r
, *rend
;
6786 /* We can ignore stub sections when looking for relocs. */
6787 if ((o
->flags
& SEC_RELOC
) == 0
6788 || o
->reloc_count
== 0
6789 || section_allows_mips16_refs_p (o
))
6793 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
6795 if (sec_relocs
== NULL
)
6798 rend
= sec_relocs
+ o
->reloc_count
;
6799 for (r
= sec_relocs
; r
< rend
; r
++)
6800 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
6801 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
6804 if (elf_section_data (o
)->relocs
!= sec_relocs
)
6813 /* There is no non-call reloc for this stub, so we do
6814 not need it. Since this function is called before
6815 the linker maps input sections to output sections, we
6816 can easily discard it by setting the SEC_EXCLUDE
6818 sec
->flags
|= SEC_EXCLUDE
;
6822 /* Record this stub in an array of local symbol call_stubs for
6824 if (elf_tdata (abfd
)->local_call_stubs
== NULL
)
6826 unsigned long symcount
;
6830 if (elf_bad_symtab (abfd
))
6831 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
6833 symcount
= symtab_hdr
->sh_info
;
6834 amt
= symcount
* sizeof (asection
*);
6835 n
= bfd_zalloc (abfd
, amt
);
6838 elf_tdata (abfd
)->local_call_stubs
= n
;
6841 sec
->flags
|= SEC_KEEP
;
6842 elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
6844 /* We don't need to set mips16_stubs_seen in this case.
6845 That flag is used to see whether we need to look through
6846 the global symbol table for stubs. We don't need to set
6847 it here, because we just have a local stub. */
6851 h
= ((struct mips_elf_link_hash_entry
*)
6852 sym_hashes
[r_symndx
- extsymoff
]);
6854 /* H is the symbol this stub is for. */
6856 if (CALL_FP_STUB_P (name
))
6857 loc
= &h
->call_fp_stub
;
6859 loc
= &h
->call_stub
;
6861 /* If we already have an appropriate stub for this function, we
6862 don't need another one, so we can discard this one. Since
6863 this function is called before the linker maps input sections
6864 to output sections, we can easily discard it by setting the
6865 SEC_EXCLUDE flag. */
6868 sec
->flags
|= SEC_EXCLUDE
;
6872 sec
->flags
|= SEC_KEEP
;
6874 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
6880 for (rel
= relocs
; rel
< rel_end
; ++rel
)
6882 unsigned long r_symndx
;
6883 unsigned int r_type
;
6884 struct elf_link_hash_entry
*h
;
6886 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
6887 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6889 if (r_symndx
< extsymoff
)
6891 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
6893 (*_bfd_error_handler
)
6894 (_("%B: Malformed reloc detected for section %s"),
6896 bfd_set_error (bfd_error_bad_value
);
6901 h
= sym_hashes
[r_symndx
- extsymoff
];
6903 /* This may be an indirect symbol created because of a version. */
6906 while (h
->root
.type
== bfd_link_hash_indirect
)
6907 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6911 /* Some relocs require a global offset table. */
6912 if (dynobj
== NULL
|| htab
->sgot
== NULL
)
6916 case R_MIPS16_GOT16
:
6917 case R_MIPS16_CALL16
:
6920 case R_MIPS_CALL_HI16
:
6921 case R_MIPS_CALL_LO16
:
6922 case R_MIPS_GOT_HI16
:
6923 case R_MIPS_GOT_LO16
:
6924 case R_MIPS_GOT_PAGE
:
6925 case R_MIPS_GOT_OFST
:
6926 case R_MIPS_GOT_DISP
:
6927 case R_MIPS_TLS_GOTTPREL
:
6929 case R_MIPS_TLS_LDM
:
6931 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6932 if (! mips_elf_create_got_section (dynobj
, info
, FALSE
))
6934 if (htab
->is_vxworks
&& !info
->shared
)
6936 (*_bfd_error_handler
)
6937 (_("%B: GOT reloc at 0x%lx not expected in executables"),
6938 abfd
, (unsigned long) rel
->r_offset
);
6939 bfd_set_error (bfd_error_bad_value
);
6947 /* In VxWorks executables, references to external symbols
6948 are handled using copy relocs or PLT stubs, so there's
6949 no need to add a dynamic relocation here. */
6951 && (info
->shared
|| (h
!= NULL
&& !htab
->is_vxworks
))
6952 && (sec
->flags
& SEC_ALLOC
) != 0)
6953 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6963 ((struct mips_elf_link_hash_entry
*) h
)->is_relocation_target
= TRUE
;
6965 /* Relocations against the special VxWorks __GOTT_BASE__ and
6966 __GOTT_INDEX__ symbols must be left to the loader. Allocate
6967 room for them in .rela.dyn. */
6968 if (is_gott_symbol (info
, h
))
6972 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
6976 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
6977 if (MIPS_ELF_READONLY_SECTION (sec
))
6978 /* We tell the dynamic linker that there are
6979 relocations against the text segment. */
6980 info
->flags
|= DF_TEXTREL
;
6983 else if (r_type
== R_MIPS_CALL_LO16
6984 || r_type
== R_MIPS_GOT_LO16
6985 || r_type
== R_MIPS_GOT_DISP
6986 || (got16_reloc_p (r_type
) && htab
->is_vxworks
))
6988 /* We may need a local GOT entry for this relocation. We
6989 don't count R_MIPS_GOT_PAGE because we can estimate the
6990 maximum number of pages needed by looking at the size of
6991 the segment. Similar comments apply to R_MIPS*_GOT16 and
6992 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
6993 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
6994 R_MIPS_CALL_HI16 because these are always followed by an
6995 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
6996 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
6997 rel
->r_addend
, info
, 0))
7004 case R_MIPS16_CALL16
:
7007 (*_bfd_error_handler
)
7008 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
7009 abfd
, (unsigned long) rel
->r_offset
);
7010 bfd_set_error (bfd_error_bad_value
);
7015 case R_MIPS_CALL_HI16
:
7016 case R_MIPS_CALL_LO16
:
7019 /* VxWorks call relocations point the function's .got.plt
7020 entry, which will be allocated by adjust_dynamic_symbol.
7021 Otherwise, this symbol requires a global GOT entry. */
7022 if ((!htab
->is_vxworks
|| h
->forced_local
)
7023 && !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7026 /* We need a stub, not a plt entry for the undefined
7027 function. But we record it as if it needs plt. See
7028 _bfd_elf_adjust_dynamic_symbol. */
7034 case R_MIPS_GOT_PAGE
:
7035 /* If this is a global, overridable symbol, GOT_PAGE will
7036 decay to GOT_DISP, so we'll need a GOT entry for it. */
7039 struct mips_elf_link_hash_entry
*hmips
=
7040 (struct mips_elf_link_hash_entry
*) h
;
7042 while (hmips
->root
.root
.type
== bfd_link_hash_indirect
7043 || hmips
->root
.root
.type
== bfd_link_hash_warning
)
7044 hmips
= (struct mips_elf_link_hash_entry
*)
7045 hmips
->root
.root
.u
.i
.link
;
7047 /* This symbol is definitely not overridable. */
7048 if (hmips
->root
.def_regular
7049 && ! (info
->shared
&& ! info
->symbolic
7050 && ! hmips
->root
.forced_local
))
7055 case R_MIPS16_GOT16
:
7057 case R_MIPS_GOT_HI16
:
7058 case R_MIPS_GOT_LO16
:
7059 if (!h
|| r_type
== R_MIPS_GOT_PAGE
)
7061 /* This relocation needs (or may need, if h != NULL) a
7062 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
7063 know for sure until we know whether the symbol is
7065 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
7067 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7069 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7070 addend
= mips_elf_read_rel_addend (abfd
, rel
,
7072 if (r_type
== R_MIPS_GOT16
)
7073 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
7076 addend
<<= howto
->rightshift
;
7079 addend
= rel
->r_addend
;
7080 if (!mips_elf_record_got_page_entry (info
, abfd
, r_symndx
,
7087 case R_MIPS_GOT_DISP
:
7088 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7092 case R_MIPS_TLS_GOTTPREL
:
7094 info
->flags
|= DF_STATIC_TLS
;
7097 case R_MIPS_TLS_LDM
:
7098 if (r_type
== R_MIPS_TLS_LDM
)
7106 /* This symbol requires a global offset table entry, or two
7107 for TLS GD relocations. */
7109 unsigned char flag
= (r_type
== R_MIPS_TLS_GD
7111 : r_type
== R_MIPS_TLS_LDM
7116 struct mips_elf_link_hash_entry
*hmips
=
7117 (struct mips_elf_link_hash_entry
*) h
;
7118 hmips
->tls_type
|= flag
;
7120 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
,
7126 BFD_ASSERT (flag
== GOT_TLS_LDM
|| r_symndx
!= 0);
7128 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7139 /* In VxWorks executables, references to external symbols
7140 are handled using copy relocs or PLT stubs, so there's
7141 no need to add a .rela.dyn entry for this relocation. */
7142 if ((info
->shared
|| (h
!= NULL
&& !htab
->is_vxworks
))
7143 && !(h
&& strcmp (h
->root
.root
.string
, "__gnu_local_gp") == 0)
7144 && (sec
->flags
& SEC_ALLOC
) != 0)
7148 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7152 if (info
->shared
&& h
== NULL
)
7154 /* When creating a shared object, we must copy these
7155 reloc types into the output file as R_MIPS_REL32
7156 relocs. Make room for this reloc in .rel(a).dyn. */
7157 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7158 if (MIPS_ELF_READONLY_SECTION (sec
))
7159 /* We tell the dynamic linker that there are
7160 relocations against the text segment. */
7161 info
->flags
|= DF_TEXTREL
;
7165 struct mips_elf_link_hash_entry
*hmips
;
7167 /* For a shared object, we must copy this relocation
7168 unless the symbol turns out to be undefined and
7169 weak with non-default visibility, in which case
7170 it will be left as zero.
7172 We could elide R_MIPS_REL32 for locally binding symbols
7173 in shared libraries, but do not yet do so.
7175 For an executable, we only need to copy this
7176 reloc if the symbol is defined in a dynamic
7178 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7179 ++hmips
->possibly_dynamic_relocs
;
7180 if (MIPS_ELF_READONLY_SECTION (sec
))
7181 /* We need it to tell the dynamic linker if there
7182 are relocations against the text segment. */
7183 hmips
->readonly_reloc
= TRUE
;
7186 /* Even though we don't directly need a GOT entry for
7187 this symbol, a symbol must have a dynamic symbol
7188 table index greater that DT_MIPS_GOTSYM if there are
7189 dynamic relocations against it. This does not apply
7190 to VxWorks, which does not have the usual coupling
7191 between global GOT entries and .dynsym entries. */
7192 if (h
!= NULL
&& !htab
->is_vxworks
)
7195 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7196 if (! mips_elf_create_got_section (dynobj
, info
, TRUE
))
7198 if (!mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7203 if (SGI_COMPAT (abfd
))
7204 mips_elf_hash_table (info
)->compact_rel_size
+=
7205 sizeof (Elf32_External_crinfo
);
7210 ((struct mips_elf_link_hash_entry
*) h
)->is_branch_target
= TRUE
;
7215 ((struct mips_elf_link_hash_entry
*) h
)->is_branch_target
= TRUE
;
7218 case R_MIPS_GPREL16
:
7219 case R_MIPS_LITERAL
:
7220 case R_MIPS_GPREL32
:
7221 if (SGI_COMPAT (abfd
))
7222 mips_elf_hash_table (info
)->compact_rel_size
+=
7223 sizeof (Elf32_External_crinfo
);
7226 /* This relocation describes the C++ object vtable hierarchy.
7227 Reconstruct it for later use during GC. */
7228 case R_MIPS_GNU_VTINHERIT
:
7229 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7233 /* This relocation describes which C++ vtable entries are actually
7234 used. Record for later use during GC. */
7235 case R_MIPS_GNU_VTENTRY
:
7236 BFD_ASSERT (h
!= NULL
);
7238 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7246 /* We must not create a stub for a symbol that has relocations
7247 related to taking the function's address. This doesn't apply to
7248 VxWorks, where CALL relocs refer to a .got.plt entry instead of
7249 a normal .got entry. */
7250 if (!htab
->is_vxworks
&& h
!= NULL
)
7254 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
7256 case R_MIPS16_CALL16
:
7258 case R_MIPS_CALL_HI16
:
7259 case R_MIPS_CALL_LO16
:
7264 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
7265 if there is one. We only need to handle global symbols here;
7266 we decide whether to keep or delete stubs for local symbols
7267 when processing the stub's relocations. */
7269 && !mips16_call_reloc_p (r_type
)
7270 && !section_allows_mips16_refs_p (sec
))
7272 struct mips_elf_link_hash_entry
*mh
;
7274 mh
= (struct mips_elf_link_hash_entry
*) h
;
7275 mh
->need_fn_stub
= TRUE
;
7283 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
7284 struct bfd_link_info
*link_info
,
7287 Elf_Internal_Rela
*internal_relocs
;
7288 Elf_Internal_Rela
*irel
, *irelend
;
7289 Elf_Internal_Shdr
*symtab_hdr
;
7290 bfd_byte
*contents
= NULL
;
7292 bfd_boolean changed_contents
= FALSE
;
7293 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
7294 Elf_Internal_Sym
*isymbuf
= NULL
;
7296 /* We are not currently changing any sizes, so only one pass. */
7299 if (link_info
->relocatable
)
7302 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
7303 link_info
->keep_memory
);
7304 if (internal_relocs
== NULL
)
7307 irelend
= internal_relocs
+ sec
->reloc_count
7308 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
7309 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7310 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7312 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
7315 bfd_signed_vma sym_offset
;
7316 unsigned int r_type
;
7317 unsigned long r_symndx
;
7319 unsigned long instruction
;
7321 /* Turn jalr into bgezal, and jr into beq, if they're marked
7322 with a JALR relocation, that indicate where they jump to.
7323 This saves some pipeline bubbles. */
7324 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
7325 if (r_type
!= R_MIPS_JALR
)
7328 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
7329 /* Compute the address of the jump target. */
7330 if (r_symndx
>= extsymoff
)
7332 struct mips_elf_link_hash_entry
*h
7333 = ((struct mips_elf_link_hash_entry
*)
7334 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
7336 while (h
->root
.root
.type
== bfd_link_hash_indirect
7337 || h
->root
.root
.type
== bfd_link_hash_warning
)
7338 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7340 /* If a symbol is undefined, or if it may be overridden,
7342 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
7343 || h
->root
.root
.type
== bfd_link_hash_defweak
)
7344 && h
->root
.root
.u
.def
.section
)
7345 || (link_info
->shared
&& ! link_info
->symbolic
7346 && !h
->root
.forced_local
))
7349 sym_sec
= h
->root
.root
.u
.def
.section
;
7350 if (sym_sec
->output_section
)
7351 symval
= (h
->root
.root
.u
.def
.value
7352 + sym_sec
->output_section
->vma
7353 + sym_sec
->output_offset
);
7355 symval
= h
->root
.root
.u
.def
.value
;
7359 Elf_Internal_Sym
*isym
;
7361 /* Read this BFD's symbols if we haven't done so already. */
7362 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
7364 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7365 if (isymbuf
== NULL
)
7366 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
7367 symtab_hdr
->sh_info
, 0,
7369 if (isymbuf
== NULL
)
7373 isym
= isymbuf
+ r_symndx
;
7374 if (isym
->st_shndx
== SHN_UNDEF
)
7376 else if (isym
->st_shndx
== SHN_ABS
)
7377 sym_sec
= bfd_abs_section_ptr
;
7378 else if (isym
->st_shndx
== SHN_COMMON
)
7379 sym_sec
= bfd_com_section_ptr
;
7382 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7383 symval
= isym
->st_value
7384 + sym_sec
->output_section
->vma
7385 + sym_sec
->output_offset
;
7388 /* Compute branch offset, from delay slot of the jump to the
7390 sym_offset
= (symval
+ irel
->r_addend
)
7391 - (sec_start
+ irel
->r_offset
+ 4);
7393 /* Branch offset must be properly aligned. */
7394 if ((sym_offset
& 3) != 0)
7399 /* Check that it's in range. */
7400 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
7403 /* Get the section contents if we haven't done so already. */
7404 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7407 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
7409 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
7410 if ((instruction
& 0xfc1fffff) == 0x0000f809)
7411 instruction
= 0x04110000;
7412 /* If it was jr <reg>, turn it into b <target>. */
7413 else if ((instruction
& 0xfc1fffff) == 0x00000008)
7414 instruction
= 0x10000000;
7418 instruction
|= (sym_offset
& 0xffff);
7419 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
7420 changed_contents
= TRUE
;
7423 if (contents
!= NULL
7424 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7426 if (!changed_contents
&& !link_info
->keep_memory
)
7430 /* Cache the section contents for elf_link_input_bfd. */
7431 elf_section_data (sec
)->this_hdr
.contents
= contents
;
7437 if (contents
!= NULL
7438 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7443 /* Allocate space for global sym dynamic relocs. */
7446 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7448 struct bfd_link_info
*info
= inf
;
7450 struct mips_elf_link_hash_entry
*hmips
;
7451 struct mips_elf_link_hash_table
*htab
;
7453 htab
= mips_elf_hash_table (info
);
7454 dynobj
= elf_hash_table (info
)->dynobj
;
7455 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7457 /* VxWorks executables are handled elsewhere; we only need to
7458 allocate relocations in shared objects. */
7459 if (htab
->is_vxworks
&& !info
->shared
)
7462 /* If this symbol is defined in a dynamic object, or we are creating
7463 a shared library, we will need to copy any R_MIPS_32 or
7464 R_MIPS_REL32 relocs against it into the output file. */
7465 if (! info
->relocatable
7466 && hmips
->possibly_dynamic_relocs
!= 0
7467 && (h
->root
.type
== bfd_link_hash_defweak
7471 bfd_boolean do_copy
= TRUE
;
7473 if (h
->root
.type
== bfd_link_hash_undefweak
)
7475 /* Do not copy relocations for undefined weak symbols with
7476 non-default visibility. */
7477 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7480 /* Make sure undefined weak symbols are output as a dynamic
7482 else if (h
->dynindx
== -1 && !h
->forced_local
)
7484 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7491 mips_elf_allocate_dynamic_relocations
7492 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
7493 if (hmips
->readonly_reloc
)
7494 /* We tell the dynamic linker that there are relocations
7495 against the text segment. */
7496 info
->flags
|= DF_TEXTREL
;
7503 /* Adjust a symbol defined by a dynamic object and referenced by a
7504 regular object. The current definition is in some section of the
7505 dynamic object, but we're not including those sections. We have to
7506 change the definition to something the rest of the link can
7510 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7511 struct elf_link_hash_entry
*h
)
7514 struct mips_elf_link_hash_entry
*hmips
;
7515 struct mips_elf_link_hash_table
*htab
;
7517 htab
= mips_elf_hash_table (info
);
7518 dynobj
= elf_hash_table (info
)->dynobj
;
7520 /* Make sure we know what is going on here. */
7521 BFD_ASSERT (dynobj
!= NULL
7523 || h
->u
.weakdef
!= NULL
7526 && !h
->def_regular
)));
7528 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7530 /* For a function, create a stub, if allowed. */
7531 if (! hmips
->no_fn_stub
7534 if (! elf_hash_table (info
)->dynamic_sections_created
)
7537 /* If this symbol is not defined in a regular file, then set
7538 the symbol to the stub location. This is required to make
7539 function pointers compare as equal between the normal
7540 executable and the shared library. */
7541 if (!h
->def_regular
)
7543 /* We need .stub section. */
7544 h
->root
.u
.def
.section
= htab
->sstubs
;
7545 h
->root
.u
.def
.value
= htab
->sstubs
->size
;
7547 /* XXX Write this stub address somewhere. */
7548 h
->plt
.offset
= htab
->sstubs
->size
;
7550 /* Make room for this stub code. */
7551 htab
->sstubs
->size
+= htab
->function_stub_size
;
7553 /* The last half word of the stub will be filled with the index
7554 of this symbol in .dynsym section. */
7558 else if ((h
->type
== STT_FUNC
)
7561 /* This will set the entry for this symbol in the GOT to 0, and
7562 the dynamic linker will take care of this. */
7563 h
->root
.u
.def
.value
= 0;
7567 /* If this is a weak symbol, and there is a real definition, the
7568 processor independent code will have arranged for us to see the
7569 real definition first, and we can just use the same value. */
7570 if (h
->u
.weakdef
!= NULL
)
7572 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7573 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7574 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7575 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7579 /* This is a reference to a symbol defined by a dynamic object which
7580 is not a function. */
7585 /* Likewise, for VxWorks. */
7588 _bfd_mips_vxworks_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7589 struct elf_link_hash_entry
*h
)
7592 struct mips_elf_link_hash_entry
*hmips
;
7593 struct mips_elf_link_hash_table
*htab
;
7595 htab
= mips_elf_hash_table (info
);
7596 dynobj
= elf_hash_table (info
)->dynobj
;
7597 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7599 /* Make sure we know what is going on here. */
7600 BFD_ASSERT (dynobj
!= NULL
7603 || h
->u
.weakdef
!= NULL
7606 && !h
->def_regular
)));
7608 /* If the symbol is defined by a dynamic object, we need a PLT stub if
7609 either (a) we want to branch to the symbol or (b) we're linking an
7610 executable that needs a canonical function address. In the latter
7611 case, the canonical address will be the address of the executable's
7613 if ((hmips
->is_branch_target
7615 && h
->type
== STT_FUNC
7616 && hmips
->is_relocation_target
))
7620 && !h
->forced_local
)
7623 /* Locally-binding symbols do not need a PLT stub; we can refer to
7624 the functions directly. */
7625 else if (h
->needs_plt
7626 && (SYMBOL_CALLS_LOCAL (info
, h
)
7627 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
7628 && h
->root
.type
== bfd_link_hash_undefweak
)))
7636 /* If this is the first symbol to need a PLT entry, allocate room
7637 for the header, and for the header's .rela.plt.unloaded entries. */
7638 if (htab
->splt
->size
== 0)
7640 htab
->splt
->size
+= htab
->plt_header_size
;
7642 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
7645 /* Assign the next .plt entry to this symbol. */
7646 h
->plt
.offset
= htab
->splt
->size
;
7647 htab
->splt
->size
+= htab
->plt_entry_size
;
7649 /* If the output file has no definition of the symbol, set the
7650 symbol's value to the address of the stub. Point at the PLT
7651 load stub rather than the lazy resolution stub; this stub
7652 will become the canonical function address. */
7653 if (!info
->shared
&& !h
->def_regular
)
7655 h
->root
.u
.def
.section
= htab
->splt
;
7656 h
->root
.u
.def
.value
= h
->plt
.offset
;
7657 h
->root
.u
.def
.value
+= 8;
7660 /* Make room for the .got.plt entry and the R_JUMP_SLOT relocation. */
7661 htab
->sgotplt
->size
+= 4;
7662 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
7664 /* Make room for the .rela.plt.unloaded relocations. */
7666 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
7671 /* If a function symbol is defined by a dynamic object, and we do not
7672 need a PLT stub for it, the symbol's value should be zero. */
7673 if (h
->type
== STT_FUNC
7678 h
->root
.u
.def
.value
= 0;
7682 /* If this is a weak symbol, and there is a real definition, the
7683 processor independent code will have arranged for us to see the
7684 real definition first, and we can just use the same value. */
7685 if (h
->u
.weakdef
!= NULL
)
7687 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7688 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7689 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7690 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7694 /* This is a reference to a symbol defined by a dynamic object which
7695 is not a function. */
7699 /* We must allocate the symbol in our .dynbss section, which will
7700 become part of the .bss section of the executable. There will be
7701 an entry for this symbol in the .dynsym section. The dynamic
7702 object will contain position independent code, so all references
7703 from the dynamic object to this symbol will go through the global
7704 offset table. The dynamic linker will use the .dynsym entry to
7705 determine the address it must put in the global offset table, so
7706 both the dynamic object and the regular object will refer to the
7707 same memory location for the variable. */
7709 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
7711 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
7715 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
7718 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
7719 The number might be exact or a worst-case estimate, depending on how
7720 much information is available to elf_backend_omit_section_dynsym at
7721 the current linking stage. */
7723 static bfd_size_type
7724 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
7726 bfd_size_type count
;
7729 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
7732 const struct elf_backend_data
*bed
;
7734 bed
= get_elf_backend_data (output_bfd
);
7735 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
7736 if ((p
->flags
& SEC_EXCLUDE
) == 0
7737 && (p
->flags
& SEC_ALLOC
) != 0
7738 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
7744 /* This function is called after all the input files have been read,
7745 and the input sections have been assigned to output sections. We
7746 check for any mips16 stub sections that we can discard. */
7749 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
7750 struct bfd_link_info
*info
)
7755 struct mips_got_info
*g
;
7757 bfd_size_type loadable_size
= 0;
7758 bfd_size_type page_gotno
;
7759 bfd_size_type dynsymcount
;
7761 struct mips_elf_count_tls_arg count_tls_arg
;
7762 struct mips_elf_link_hash_table
*htab
;
7764 htab
= mips_elf_hash_table (info
);
7766 /* The .reginfo section has a fixed size. */
7767 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
7769 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
7771 if (! (info
->relocatable
7772 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
))
7773 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7774 mips_elf_check_mips16_stubs
, info
);
7782 /* Calculate the total loadable size of the output. That
7783 will give us the maximum number of GOT_PAGE entries
7785 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
7787 asection
*subsection
;
7789 for (subsection
= sub
->sections
;
7791 subsection
= subsection
->next
)
7793 if ((subsection
->flags
& SEC_ALLOC
) == 0)
7795 loadable_size
+= ((subsection
->size
+ 0xf)
7796 &~ (bfd_size_type
) 0xf);
7800 /* There has to be a global GOT entry for every symbol with
7801 a dynamic symbol table index of DT_MIPS_GOTSYM or
7802 higher. Therefore, it make sense to put those symbols
7803 that need GOT entries at the end of the symbol table. We
7805 if (! mips_elf_sort_hash_table (info
, 1))
7808 if (g
->global_gotsym
!= NULL
)
7809 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
7811 /* If there are no global symbols, or none requiring
7812 relocations, then GLOBAL_GOTSYM will be NULL. */
7815 /* Get a worst-case estimate of the number of dynamic symbols needed.
7816 At this point, dynsymcount does not account for section symbols
7817 and count_section_dynsyms may overestimate the number that will
7819 dynsymcount
= (elf_hash_table (info
)->dynsymcount
7820 + count_section_dynsyms (output_bfd
, info
));
7822 /* Determine the size of one stub entry. */
7823 htab
->function_stub_size
= (dynsymcount
> 0x10000
7824 ? MIPS_FUNCTION_STUB_BIG_SIZE
7825 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
7827 /* In the worst case, we'll get one stub per dynamic symbol, plus
7828 one to account for the dummy entry at the end required by IRIX
7830 loadable_size
+= htab
->function_stub_size
* (i
+ 1);
7832 if (htab
->is_vxworks
)
7833 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
7834 relocations against local symbols evaluate to "G", and the EABI does
7835 not include R_MIPS_GOT_PAGE. */
7838 /* Assume there are two loadable segments consisting of contiguous
7839 sections. Is 5 enough? */
7840 page_gotno
= (loadable_size
>> 16) + 5;
7842 /* Choose the smaller of the two estimates; both are intended to be
7844 if (page_gotno
> g
->page_gotno
)
7845 page_gotno
= g
->page_gotno
;
7847 g
->local_gotno
+= page_gotno
;
7848 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7850 g
->global_gotno
= i
;
7851 s
->size
+= i
* MIPS_ELF_GOT_SIZE (output_bfd
);
7853 /* We need to calculate tls_gotno for global symbols at this point
7854 instead of building it up earlier, to avoid doublecounting
7855 entries for one global symbol from multiple input files. */
7856 count_tls_arg
.info
= info
;
7857 count_tls_arg
.needed
= 0;
7858 elf_link_hash_traverse (elf_hash_table (info
),
7859 mips_elf_count_global_tls_entries
,
7861 g
->tls_gotno
+= count_tls_arg
.needed
;
7862 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7864 mips_elf_resolve_final_got_entries (g
);
7866 /* VxWorks does not support multiple GOTs. It initializes $gp to
7867 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
7869 if (!htab
->is_vxworks
&& s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
7871 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
7876 /* Set up TLS entries for the first GOT. */
7877 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
7878 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
7880 htab
->computed_got_sizes
= TRUE
;
7885 /* Set the sizes of the dynamic sections. */
7888 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
7889 struct bfd_link_info
*info
)
7892 asection
*s
, *sreldyn
;
7893 bfd_boolean reltext
;
7894 struct mips_elf_link_hash_table
*htab
;
7896 htab
= mips_elf_hash_table (info
);
7897 dynobj
= elf_hash_table (info
)->dynobj
;
7898 BFD_ASSERT (dynobj
!= NULL
);
7900 if (elf_hash_table (info
)->dynamic_sections_created
)
7902 /* Set the contents of the .interp section to the interpreter. */
7903 if (info
->executable
)
7905 s
= bfd_get_section_by_name (dynobj
, ".interp");
7906 BFD_ASSERT (s
!= NULL
);
7908 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
7910 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
7914 /* IRIX rld assumes that the function stub isn't at the end
7915 of the .text section, so add a dummy entry to the end. */
7916 if (htab
->sstubs
&& htab
->sstubs
->size
> 0)
7917 htab
->sstubs
->size
+= htab
->function_stub_size
;
7919 /* Allocate space for global sym dynamic relocs. */
7920 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
7922 /* The check_relocs and adjust_dynamic_symbol entry points have
7923 determined the sizes of the various dynamic sections. Allocate
7927 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7931 /* It's OK to base decisions on the section name, because none
7932 of the dynobj section names depend upon the input files. */
7933 name
= bfd_get_section_name (dynobj
, s
);
7935 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7938 if (CONST_STRNEQ (name
, ".rel"))
7942 const char *outname
;
7945 /* If this relocation section applies to a read only
7946 section, then we probably need a DT_TEXTREL entry.
7947 If the relocation section is .rel(a).dyn, we always
7948 assert a DT_TEXTREL entry rather than testing whether
7949 there exists a relocation to a read only section or
7951 outname
= bfd_get_section_name (output_bfd
,
7953 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
7955 && (target
->flags
& SEC_READONLY
) != 0
7956 && (target
->flags
& SEC_ALLOC
) != 0)
7957 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
7960 /* We use the reloc_count field as a counter if we need
7961 to copy relocs into the output file. */
7962 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
7965 /* If combreloc is enabled, elf_link_sort_relocs() will
7966 sort relocations, but in a different way than we do,
7967 and before we're done creating relocations. Also, it
7968 will move them around between input sections'
7969 relocation's contents, so our sorting would be
7970 broken, so don't let it run. */
7971 info
->combreloc
= 0;
7974 else if (htab
->is_vxworks
&& strcmp (name
, ".got") == 0)
7976 /* Executables do not need a GOT. */
7979 /* Allocate relocations for all but the reserved entries. */
7982 count
= (htab
->got_info
->global_gotno
7983 + htab
->got_info
->local_gotno
7984 - MIPS_RESERVED_GOTNO (info
));
7985 mips_elf_allocate_dynamic_relocations (dynobj
, info
, count
);
7988 else if (!htab
->is_vxworks
&& CONST_STRNEQ (name
, ".got"))
7990 /* _bfd_mips_elf_always_size_sections() has already done
7991 most of the work, but some symbols may have been mapped
7992 to versions that we must now resolve in the got_entries
7994 struct mips_got_info
*gg
= htab
->got_info
;
7995 struct mips_got_info
*g
= gg
;
7996 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
7997 unsigned int needed_relocs
= 0;
8001 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (output_bfd
);
8002 set_got_offset_arg
.info
= info
;
8004 /* NOTE 2005-02-03: How can this call, or the next, ever
8005 find any indirect entries to resolve? They were all
8006 resolved in mips_elf_multi_got. */
8007 mips_elf_resolve_final_got_entries (gg
);
8008 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
8010 unsigned int save_assign
;
8012 mips_elf_resolve_final_got_entries (g
);
8014 /* Assign offsets to global GOT entries. */
8015 save_assign
= g
->assigned_gotno
;
8016 g
->assigned_gotno
= g
->local_gotno
;
8017 set_got_offset_arg
.g
= g
;
8018 set_got_offset_arg
.needed_relocs
= 0;
8019 htab_traverse (g
->got_entries
,
8020 mips_elf_set_global_got_offset
,
8021 &set_got_offset_arg
);
8022 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
8023 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
8024 <= g
->global_gotno
);
8026 g
->assigned_gotno
= save_assign
;
8029 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
8030 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
8031 + g
->next
->global_gotno
8032 + g
->next
->tls_gotno
8033 + MIPS_RESERVED_GOTNO (info
));
8039 struct mips_elf_count_tls_arg arg
;
8043 htab_traverse (gg
->got_entries
, mips_elf_count_local_tls_relocs
,
8045 elf_link_hash_traverse (elf_hash_table (info
),
8046 mips_elf_count_global_tls_relocs
,
8049 needed_relocs
+= arg
.needed
;
8053 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
8056 else if (! info
->shared
8057 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8058 && CONST_STRNEQ (name
, ".rld_map"))
8060 /* We add a room for __rld_map. It will be filled in by the
8061 rtld to contain a pointer to the _r_debug structure. */
8064 else if (SGI_COMPAT (output_bfd
)
8065 && CONST_STRNEQ (name
, ".compact_rel"))
8066 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8067 else if (! CONST_STRNEQ (name
, ".init")
8068 && s
!= htab
->sgotplt
8070 && s
!= htab
->sstubs
)
8072 /* It's not one of our sections, so don't allocate space. */
8078 s
->flags
|= SEC_EXCLUDE
;
8082 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8085 /* Allocate memory for this section last, since we may increase its
8087 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
8093 /* Allocate memory for the section contents. */
8094 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
8095 if (s
->contents
== NULL
)
8097 bfd_set_error (bfd_error_no_memory
);
8102 /* Allocate memory for the .rel(a).dyn section. */
8103 if (sreldyn
!= NULL
)
8105 sreldyn
->contents
= bfd_zalloc (dynobj
, sreldyn
->size
);
8106 if (sreldyn
->contents
== NULL
)
8108 bfd_set_error (bfd_error_no_memory
);
8113 if (elf_hash_table (info
)->dynamic_sections_created
)
8115 /* Add some entries to the .dynamic section. We fill in the
8116 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
8117 must add the entries now so that we get the correct size for
8118 the .dynamic section. */
8120 /* SGI object has the equivalence of DT_DEBUG in the
8121 DT_MIPS_RLD_MAP entry. This must come first because glibc
8122 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and GDB only
8123 looks at the first one it sees. */
8125 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8128 /* The DT_DEBUG entry may be filled in by the dynamic linker and
8129 used by the debugger. */
8130 if (info
->executable
8131 && !SGI_COMPAT (output_bfd
)
8132 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8135 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
8136 info
->flags
|= DF_TEXTREL
;
8138 if ((info
->flags
& DF_TEXTREL
) != 0)
8140 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8143 /* Clear the DF_TEXTREL flag. It will be set again if we
8144 write out an actual text relocation; we may not, because
8145 at this point we do not know whether e.g. any .eh_frame
8146 absolute relocations have been converted to PC-relative. */
8147 info
->flags
&= ~DF_TEXTREL
;
8150 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8153 if (htab
->is_vxworks
)
8155 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
8156 use any of the DT_MIPS_* tags. */
8157 if (mips_elf_rel_dyn_section (info
, FALSE
))
8159 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
8162 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
8165 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
8168 if (htab
->splt
->size
> 0)
8170 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
8173 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
8176 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
8182 if (mips_elf_rel_dyn_section (info
, FALSE
))
8184 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8187 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8190 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8194 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8197 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8200 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8203 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8206 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8209 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8212 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8215 if (IRIX_COMPAT (dynobj
) == ict_irix5
8216 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8219 if (IRIX_COMPAT (dynobj
) == ict_irix6
8220 && (bfd_get_section_by_name
8221 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8222 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8225 if (htab
->is_vxworks
8226 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
8233 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
8234 Adjust its R_ADDEND field so that it is correct for the output file.
8235 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
8236 and sections respectively; both use symbol indexes. */
8239 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
8240 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
8241 asection
**local_sections
, Elf_Internal_Rela
*rel
)
8243 unsigned int r_type
, r_symndx
;
8244 Elf_Internal_Sym
*sym
;
8247 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8249 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8250 if (r_type
== R_MIPS16_GPREL
8251 || r_type
== R_MIPS_GPREL16
8252 || r_type
== R_MIPS_GPREL32
8253 || r_type
== R_MIPS_LITERAL
)
8255 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
8256 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
8259 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
8260 sym
= local_syms
+ r_symndx
;
8262 /* Adjust REL's addend to account for section merging. */
8263 if (!info
->relocatable
)
8265 sec
= local_sections
[r_symndx
];
8266 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
8269 /* This would normally be done by the rela_normal code in elflink.c. */
8270 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8271 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
8275 /* Relocate a MIPS ELF section. */
8278 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
8279 bfd
*input_bfd
, asection
*input_section
,
8280 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
8281 Elf_Internal_Sym
*local_syms
,
8282 asection
**local_sections
)
8284 Elf_Internal_Rela
*rel
;
8285 const Elf_Internal_Rela
*relend
;
8287 bfd_boolean use_saved_addend_p
= FALSE
;
8288 const struct elf_backend_data
*bed
;
8290 bed
= get_elf_backend_data (output_bfd
);
8291 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8292 for (rel
= relocs
; rel
< relend
; ++rel
)
8296 reloc_howto_type
*howto
;
8297 bfd_boolean require_jalx
;
8298 /* TRUE if the relocation is a RELA relocation, rather than a
8300 bfd_boolean rela_relocation_p
= TRUE
;
8301 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8303 unsigned long r_symndx
;
8305 Elf_Internal_Shdr
*symtab_hdr
;
8306 struct elf_link_hash_entry
*h
;
8308 /* Find the relocation howto for this relocation. */
8309 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
8310 NEWABI_P (input_bfd
)
8311 && (MIPS_RELOC_RELA_P
8312 (input_bfd
, input_section
,
8315 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
8316 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
8317 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8319 sec
= local_sections
[r_symndx
];
8324 unsigned long extsymoff
;
8327 if (!elf_bad_symtab (input_bfd
))
8328 extsymoff
= symtab_hdr
->sh_info
;
8329 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
8330 while (h
->root
.type
== bfd_link_hash_indirect
8331 || h
->root
.type
== bfd_link_hash_warning
)
8332 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8335 if (h
->root
.type
== bfd_link_hash_defined
8336 || h
->root
.type
== bfd_link_hash_defweak
)
8337 sec
= h
->root
.u
.def
.section
;
8340 if (sec
!= NULL
&& elf_discarded_section (sec
))
8342 /* For relocs against symbols from removed linkonce sections,
8343 or sections discarded by a linker script, we just want the
8344 section contents zeroed. Avoid any special processing. */
8345 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
8351 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
8353 /* Some 32-bit code uses R_MIPS_64. In particular, people use
8354 64-bit code, but make sure all their addresses are in the
8355 lowermost or uppermost 32-bit section of the 64-bit address
8356 space. Thus, when they use an R_MIPS_64 they mean what is
8357 usually meant by R_MIPS_32, with the exception that the
8358 stored value is sign-extended to 64 bits. */
8359 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
8361 /* On big-endian systems, we need to lie about the position
8363 if (bfd_big_endian (input_bfd
))
8367 if (!use_saved_addend_p
)
8369 /* If these relocations were originally of the REL variety,
8370 we must pull the addend out of the field that will be
8371 relocated. Otherwise, we simply use the contents of the
8373 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
8376 rela_relocation_p
= FALSE
;
8377 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
8379 if (hi16_reloc_p (r_type
)
8380 || (got16_reloc_p (r_type
)
8381 && mips_elf_local_relocation_p (input_bfd
, rel
,
8382 local_sections
, FALSE
)))
8384 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
8390 name
= h
->root
.root
.string
;
8392 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
8393 local_syms
+ r_symndx
,
8395 (*_bfd_error_handler
)
8396 (_("%B: Can't find matching LO16 reloc against `%s' for %s at 0x%lx in section `%A'"),
8397 input_bfd
, input_section
, name
, howto
->name
,
8402 addend
<<= howto
->rightshift
;
8405 addend
= rel
->r_addend
;
8406 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
8407 local_syms
, local_sections
, rel
);
8410 if (info
->relocatable
)
8412 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
8413 && bfd_big_endian (input_bfd
))
8416 if (!rela_relocation_p
&& rel
->r_addend
)
8418 addend
+= rel
->r_addend
;
8419 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
8420 addend
= mips_elf_high (addend
);
8421 else if (r_type
== R_MIPS_HIGHER
)
8422 addend
= mips_elf_higher (addend
);
8423 else if (r_type
== R_MIPS_HIGHEST
)
8424 addend
= mips_elf_highest (addend
);
8426 addend
>>= howto
->rightshift
;
8428 /* We use the source mask, rather than the destination
8429 mask because the place to which we are writing will be
8430 source of the addend in the final link. */
8431 addend
&= howto
->src_mask
;
8433 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
8434 /* See the comment above about using R_MIPS_64 in the 32-bit
8435 ABI. Here, we need to update the addend. It would be
8436 possible to get away with just using the R_MIPS_32 reloc
8437 but for endianness. */
8443 if (addend
& ((bfd_vma
) 1 << 31))
8445 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
8452 /* If we don't know that we have a 64-bit type,
8453 do two separate stores. */
8454 if (bfd_big_endian (input_bfd
))
8456 /* Store the sign-bits (which are most significant)
8458 low_bits
= sign_bits
;
8464 high_bits
= sign_bits
;
8466 bfd_put_32 (input_bfd
, low_bits
,
8467 contents
+ rel
->r_offset
);
8468 bfd_put_32 (input_bfd
, high_bits
,
8469 contents
+ rel
->r_offset
+ 4);
8473 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
8474 input_bfd
, input_section
,
8479 /* Go on to the next relocation. */
8483 /* In the N32 and 64-bit ABIs there may be multiple consecutive
8484 relocations for the same offset. In that case we are
8485 supposed to treat the output of each relocation as the addend
8487 if (rel
+ 1 < relend
8488 && rel
->r_offset
== rel
[1].r_offset
8489 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
8490 use_saved_addend_p
= TRUE
;
8492 use_saved_addend_p
= FALSE
;
8494 /* Figure out what value we are supposed to relocate. */
8495 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
8496 input_section
, info
, rel
,
8497 addend
, howto
, local_syms
,
8498 local_sections
, &value
,
8499 &name
, &require_jalx
,
8500 use_saved_addend_p
))
8502 case bfd_reloc_continue
:
8503 /* There's nothing to do. */
8506 case bfd_reloc_undefined
:
8507 /* mips_elf_calculate_relocation already called the
8508 undefined_symbol callback. There's no real point in
8509 trying to perform the relocation at this point, so we
8510 just skip ahead to the next relocation. */
8513 case bfd_reloc_notsupported
:
8514 msg
= _("internal error: unsupported relocation error");
8515 info
->callbacks
->warning
8516 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
8519 case bfd_reloc_overflow
:
8520 if (use_saved_addend_p
)
8521 /* Ignore overflow until we reach the last relocation for
8522 a given location. */
8526 struct mips_elf_link_hash_table
*htab
;
8528 htab
= mips_elf_hash_table (info
);
8529 BFD_ASSERT (name
!= NULL
);
8530 if (!htab
->small_data_overflow_reported
8531 && (howto
->type
== R_MIPS_GPREL16
8532 || howto
->type
== R_MIPS_LITERAL
))
8535 _("small-data section exceeds 64KB;"
8536 " lower small-data size limit (see option -G)");
8538 htab
->small_data_overflow_reported
= TRUE
;
8539 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
8541 if (! ((*info
->callbacks
->reloc_overflow
)
8542 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
8543 input_bfd
, input_section
, rel
->r_offset
)))
8556 /* If we've got another relocation for the address, keep going
8557 until we reach the last one. */
8558 if (use_saved_addend_p
)
8564 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
8565 /* See the comment above about using R_MIPS_64 in the 32-bit
8566 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
8567 that calculated the right value. Now, however, we
8568 sign-extend the 32-bit result to 64-bits, and store it as a
8569 64-bit value. We are especially generous here in that we
8570 go to extreme lengths to support this usage on systems with
8571 only a 32-bit VMA. */
8577 if (value
& ((bfd_vma
) 1 << 31))
8579 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
8586 /* If we don't know that we have a 64-bit type,
8587 do two separate stores. */
8588 if (bfd_big_endian (input_bfd
))
8590 /* Undo what we did above. */
8592 /* Store the sign-bits (which are most significant)
8594 low_bits
= sign_bits
;
8600 high_bits
= sign_bits
;
8602 bfd_put_32 (input_bfd
, low_bits
,
8603 contents
+ rel
->r_offset
);
8604 bfd_put_32 (input_bfd
, high_bits
,
8605 contents
+ rel
->r_offset
+ 4);
8609 /* Actually perform the relocation. */
8610 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
8611 input_bfd
, input_section
,
8612 contents
, require_jalx
))
8619 /* If NAME is one of the special IRIX6 symbols defined by the linker,
8620 adjust it appropriately now. */
8623 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
8624 const char *name
, Elf_Internal_Sym
*sym
)
8626 /* The linker script takes care of providing names and values for
8627 these, but we must place them into the right sections. */
8628 static const char* const text_section_symbols
[] = {
8631 "__dso_displacement",
8633 "__program_header_table",
8637 static const char* const data_section_symbols
[] = {
8645 const char* const *p
;
8648 for (i
= 0; i
< 2; ++i
)
8649 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
8652 if (strcmp (*p
, name
) == 0)
8654 /* All of these symbols are given type STT_SECTION by the
8656 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8657 sym
->st_other
= STO_PROTECTED
;
8659 /* The IRIX linker puts these symbols in special sections. */
8661 sym
->st_shndx
= SHN_MIPS_TEXT
;
8663 sym
->st_shndx
= SHN_MIPS_DATA
;
8669 /* Finish up dynamic symbol handling. We set the contents of various
8670 dynamic sections here. */
8673 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
8674 struct bfd_link_info
*info
,
8675 struct elf_link_hash_entry
*h
,
8676 Elf_Internal_Sym
*sym
)
8680 struct mips_got_info
*g
, *gg
;
8683 struct mips_elf_link_hash_table
*htab
;
8684 struct mips_elf_link_hash_entry
*hmips
;
8686 htab
= mips_elf_hash_table (info
);
8687 dynobj
= elf_hash_table (info
)->dynobj
;
8688 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8690 if (h
->plt
.offset
!= MINUS_ONE
)
8692 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
8694 /* This symbol has a stub. Set it up. */
8696 BFD_ASSERT (h
->dynindx
!= -1);
8698 BFD_ASSERT ((htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8699 || (h
->dynindx
<= 0xffff));
8701 /* Values up to 2^31 - 1 are allowed. Larger values would cause
8702 sign extension at runtime in the stub, resulting in a negative
8704 if (h
->dynindx
& ~0x7fffffff)
8707 /* Fill the stub. */
8709 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
8711 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ idx
);
8713 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8715 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
8719 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
8722 /* If a large stub is not required and sign extension is not a
8723 problem, then use legacy code in the stub. */
8724 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8725 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff), stub
+ idx
);
8726 else if (h
->dynindx
& ~0x7fff)
8727 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff), stub
+ idx
);
8729 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
8732 BFD_ASSERT (h
->plt
.offset
<= htab
->sstubs
->size
);
8733 memcpy (htab
->sstubs
->contents
+ h
->plt
.offset
,
8734 stub
, htab
->function_stub_size
);
8736 /* Mark the symbol as undefined. plt.offset != -1 occurs
8737 only for the referenced symbol. */
8738 sym
->st_shndx
= SHN_UNDEF
;
8740 /* The run-time linker uses the st_value field of the symbol
8741 to reset the global offset table entry for this external
8742 to its stub address when unlinking a shared object. */
8743 sym
->st_value
= (htab
->sstubs
->output_section
->vma
8744 + htab
->sstubs
->output_offset
8748 /* If we have a MIPS16 function with a stub, the dynamic symbol must
8749 refer to the stub, since only the stub uses the standard calling
8751 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
8753 BFD_ASSERT (hmips
->need_fn_stub
);
8754 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
8755 + hmips
->fn_stub
->output_offset
);
8756 sym
->st_size
= hmips
->fn_stub
->size
;
8757 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
8760 BFD_ASSERT (h
->dynindx
!= -1
8761 || h
->forced_local
);
8763 sgot
= mips_elf_got_section (info
);
8764 BFD_ASSERT (sgot
!= NULL
);
8766 BFD_ASSERT (g
!= NULL
);
8768 /* Run through the global symbol table, creating GOT entries for all
8769 the symbols that need them. */
8770 if (g
->global_gotsym
!= NULL
8771 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
8776 value
= sym
->st_value
;
8777 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
8778 R_MIPS_GOT16
, info
);
8779 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
8782 if (g
->next
&& h
->dynindx
!= -1 && h
->type
!= STT_TLS
)
8784 struct mips_got_entry e
, *p
;
8790 e
.abfd
= output_bfd
;
8795 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
8798 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
8803 || (elf_hash_table (info
)->dynamic_sections_created
8805 && p
->d
.h
->root
.def_dynamic
8806 && !p
->d
.h
->root
.def_regular
))
8808 /* Create an R_MIPS_REL32 relocation for this entry. Due to
8809 the various compatibility problems, it's easier to mock
8810 up an R_MIPS_32 or R_MIPS_64 relocation and leave
8811 mips_elf_create_dynamic_relocation to calculate the
8812 appropriate addend. */
8813 Elf_Internal_Rela rel
[3];
8815 memset (rel
, 0, sizeof (rel
));
8816 if (ABI_64_P (output_bfd
))
8817 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
8819 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
8820 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
8823 if (! (mips_elf_create_dynamic_relocation
8824 (output_bfd
, info
, rel
,
8825 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
8829 entry
= sym
->st_value
;
8830 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
8835 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
8836 name
= h
->root
.root
.string
;
8837 if (strcmp (name
, "_DYNAMIC") == 0
8838 || h
== elf_hash_table (info
)->hgot
)
8839 sym
->st_shndx
= SHN_ABS
;
8840 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
8841 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
8843 sym
->st_shndx
= SHN_ABS
;
8844 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8847 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
8849 sym
->st_shndx
= SHN_ABS
;
8850 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8851 sym
->st_value
= elf_gp (output_bfd
);
8853 else if (SGI_COMPAT (output_bfd
))
8855 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
8856 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
8858 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8859 sym
->st_other
= STO_PROTECTED
;
8861 sym
->st_shndx
= SHN_MIPS_DATA
;
8863 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
8865 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8866 sym
->st_other
= STO_PROTECTED
;
8867 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
8868 sym
->st_shndx
= SHN_ABS
;
8870 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
8872 if (h
->type
== STT_FUNC
)
8873 sym
->st_shndx
= SHN_MIPS_TEXT
;
8874 else if (h
->type
== STT_OBJECT
)
8875 sym
->st_shndx
= SHN_MIPS_DATA
;
8879 /* Handle the IRIX6-specific symbols. */
8880 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8881 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
8885 if (! mips_elf_hash_table (info
)->use_rld_obj_head
8886 && (strcmp (name
, "__rld_map") == 0
8887 || strcmp (name
, "__RLD_MAP") == 0))
8889 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
8890 BFD_ASSERT (s
!= NULL
);
8891 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
8892 bfd_put_32 (output_bfd
, 0, s
->contents
);
8893 if (mips_elf_hash_table (info
)->rld_value
== 0)
8894 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8896 else if (mips_elf_hash_table (info
)->use_rld_obj_head
8897 && strcmp (name
, "__rld_obj_head") == 0)
8899 /* IRIX6 does not use a .rld_map section. */
8900 if (IRIX_COMPAT (output_bfd
) == ict_irix5
8901 || IRIX_COMPAT (output_bfd
) == ict_none
)
8902 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
8904 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8908 /* Keep dynamic MIPS16 symbols odd. This allows the dynamic linker to
8909 treat MIPS16 symbols like any other. */
8910 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
8912 BFD_ASSERT (sym
->st_value
& 1);
8913 sym
->st_other
-= STO_MIPS16
;
8919 /* Likewise, for VxWorks. */
8922 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
8923 struct bfd_link_info
*info
,
8924 struct elf_link_hash_entry
*h
,
8925 Elf_Internal_Sym
*sym
)
8929 struct mips_got_info
*g
;
8930 struct mips_elf_link_hash_table
*htab
;
8932 htab
= mips_elf_hash_table (info
);
8933 dynobj
= elf_hash_table (info
)->dynobj
;
8935 if (h
->plt
.offset
!= (bfd_vma
) -1)
8938 bfd_vma plt_address
, plt_index
, got_address
, got_offset
, branch_offset
;
8939 Elf_Internal_Rela rel
;
8940 static const bfd_vma
*plt_entry
;
8942 BFD_ASSERT (h
->dynindx
!= -1);
8943 BFD_ASSERT (htab
->splt
!= NULL
);
8944 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
8946 /* Calculate the address of the .plt entry. */
8947 plt_address
= (htab
->splt
->output_section
->vma
8948 + htab
->splt
->output_offset
8951 /* Calculate the index of the entry. */
8952 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
8953 / htab
->plt_entry_size
);
8955 /* Calculate the address of the .got.plt entry. */
8956 got_address
= (htab
->sgotplt
->output_section
->vma
8957 + htab
->sgotplt
->output_offset
8960 /* Calculate the offset of the .got.plt entry from
8961 _GLOBAL_OFFSET_TABLE_. */
8962 got_offset
= mips_elf_gotplt_index (info
, h
);
8964 /* Calculate the offset for the branch at the start of the PLT
8965 entry. The branch jumps to the beginning of .plt. */
8966 branch_offset
= -(h
->plt
.offset
/ 4 + 1) & 0xffff;
8968 /* Fill in the initial value of the .got.plt entry. */
8969 bfd_put_32 (output_bfd
, plt_address
,
8970 htab
->sgotplt
->contents
+ plt_index
* 4);
8972 /* Find out where the .plt entry should go. */
8973 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
8977 plt_entry
= mips_vxworks_shared_plt_entry
;
8978 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
8979 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
8983 bfd_vma got_address_high
, got_address_low
;
8985 plt_entry
= mips_vxworks_exec_plt_entry
;
8986 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
8987 got_address_low
= got_address
& 0xffff;
8989 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
8990 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
8991 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
8992 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
8993 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
8994 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
8995 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
8996 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
8998 loc
= (htab
->srelplt2
->contents
8999 + (plt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
9001 /* Emit a relocation for the .got.plt entry. */
9002 rel
.r_offset
= got_address
;
9003 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9004 rel
.r_addend
= h
->plt
.offset
;
9005 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9007 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
9008 loc
+= sizeof (Elf32_External_Rela
);
9009 rel
.r_offset
= plt_address
+ 8;
9010 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9011 rel
.r_addend
= got_offset
;
9012 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9014 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
9015 loc
+= sizeof (Elf32_External_Rela
);
9017 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9018 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9021 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9022 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
9023 rel
.r_offset
= got_address
;
9024 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
9026 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9028 if (!h
->def_regular
)
9029 sym
->st_shndx
= SHN_UNDEF
;
9032 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
9034 sgot
= mips_elf_got_section (info
);
9035 BFD_ASSERT (sgot
!= NULL
);
9037 BFD_ASSERT (g
!= NULL
);
9039 /* See if this symbol has an entry in the GOT. */
9040 if (g
->global_gotsym
!= NULL
9041 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
9044 Elf_Internal_Rela outrel
;
9048 /* Install the symbol value in the GOT. */
9049 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9050 R_MIPS_GOT16
, info
);
9051 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
9053 /* Add a dynamic relocation for it. */
9054 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9055 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
9056 outrel
.r_offset
= (sgot
->output_section
->vma
9057 + sgot
->output_offset
9059 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
9060 outrel
.r_addend
= 0;
9061 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
9064 /* Emit a copy reloc, if needed. */
9067 Elf_Internal_Rela rel
;
9069 BFD_ASSERT (h
->dynindx
!= -1);
9071 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
9072 + h
->root
.u
.def
.section
->output_offset
9073 + h
->root
.u
.def
.value
);
9074 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
9076 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
9077 htab
->srelbss
->contents
9078 + (htab
->srelbss
->reloc_count
9079 * sizeof (Elf32_External_Rela
)));
9080 ++htab
->srelbss
->reloc_count
;
9083 /* If this is a mips16 symbol, force the value to be even. */
9084 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9085 sym
->st_value
&= ~1;
9090 /* Install the PLT header for a VxWorks executable and finalize the
9091 contents of .rela.plt.unloaded. */
9094 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9096 Elf_Internal_Rela rela
;
9098 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
9099 static const bfd_vma
*plt_entry
;
9100 struct mips_elf_link_hash_table
*htab
;
9102 htab
= mips_elf_hash_table (info
);
9103 plt_entry
= mips_vxworks_exec_plt0_entry
;
9105 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
9106 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
9107 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
9108 + htab
->root
.hgot
->root
.u
.def
.value
);
9110 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
9111 got_value_low
= got_value
& 0xffff;
9113 /* Calculate the address of the PLT header. */
9114 plt_address
= htab
->splt
->output_section
->vma
+ htab
->splt
->output_offset
;
9116 /* Install the PLT header. */
9117 loc
= htab
->splt
->contents
;
9118 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
9119 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
9120 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
9121 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9122 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9123 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9125 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
9126 loc
= htab
->srelplt2
->contents
;
9127 rela
.r_offset
= plt_address
;
9128 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9130 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9131 loc
+= sizeof (Elf32_External_Rela
);
9133 /* Output the relocation for the following addiu of
9134 %lo(_GLOBAL_OFFSET_TABLE_). */
9136 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9137 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9138 loc
+= sizeof (Elf32_External_Rela
);
9140 /* Fix up the remaining relocations. They may have the wrong
9141 symbol index for _G_O_T_ or _P_L_T_ depending on the order
9142 in which symbols were output. */
9143 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
9145 Elf_Internal_Rela rel
;
9147 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9148 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9149 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9150 loc
+= sizeof (Elf32_External_Rela
);
9152 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9153 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9154 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9155 loc
+= sizeof (Elf32_External_Rela
);
9157 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9158 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9159 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9160 loc
+= sizeof (Elf32_External_Rela
);
9164 /* Install the PLT header for a VxWorks shared library. */
9167 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9170 struct mips_elf_link_hash_table
*htab
;
9172 htab
= mips_elf_hash_table (info
);
9174 /* We just need to copy the entry byte-by-byte. */
9175 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
9176 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
9177 htab
->splt
->contents
+ i
* 4);
9180 /* Finish up the dynamic sections. */
9183 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
9184 struct bfd_link_info
*info
)
9189 struct mips_got_info
*gg
, *g
;
9190 struct mips_elf_link_hash_table
*htab
;
9192 htab
= mips_elf_hash_table (info
);
9193 dynobj
= elf_hash_table (info
)->dynobj
;
9195 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
9197 sgot
= mips_elf_got_section (info
);
9202 gg
= htab
->got_info
;
9203 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
9204 BFD_ASSERT (g
!= NULL
);
9207 if (elf_hash_table (info
)->dynamic_sections_created
)
9210 int dyn_to_skip
= 0, dyn_skipped
= 0;
9212 BFD_ASSERT (sdyn
!= NULL
);
9213 BFD_ASSERT (g
!= NULL
);
9215 for (b
= sdyn
->contents
;
9216 b
< sdyn
->contents
+ sdyn
->size
;
9217 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9219 Elf_Internal_Dyn dyn
;
9223 bfd_boolean swap_out_p
;
9225 /* Read in the current dynamic entry. */
9226 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9228 /* Assume that we're going to modify it and write it out. */
9234 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
9238 BFD_ASSERT (htab
->is_vxworks
);
9239 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
9243 /* Rewrite DT_STRSZ. */
9245 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
9250 if (htab
->is_vxworks
)
9252 /* _GLOBAL_OFFSET_TABLE_ is defined to be the beginning
9253 of the ".got" section in DYNOBJ. */
9254 s
= bfd_get_section_by_name (dynobj
, name
);
9255 BFD_ASSERT (s
!= NULL
);
9256 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9260 s
= bfd_get_section_by_name (output_bfd
, name
);
9261 BFD_ASSERT (s
!= NULL
);
9262 dyn
.d_un
.d_ptr
= s
->vma
;
9266 case DT_MIPS_RLD_VERSION
:
9267 dyn
.d_un
.d_val
= 1; /* XXX */
9271 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
9274 case DT_MIPS_TIME_STAMP
:
9282 case DT_MIPS_ICHECKSUM
:
9287 case DT_MIPS_IVERSION
:
9292 case DT_MIPS_BASE_ADDRESS
:
9293 s
= output_bfd
->sections
;
9294 BFD_ASSERT (s
!= NULL
);
9295 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
9298 case DT_MIPS_LOCAL_GOTNO
:
9299 dyn
.d_un
.d_val
= g
->local_gotno
;
9302 case DT_MIPS_UNREFEXTNO
:
9303 /* The index into the dynamic symbol table which is the
9304 entry of the first external symbol that is not
9305 referenced within the same object. */
9306 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
9309 case DT_MIPS_GOTSYM
:
9310 if (gg
->global_gotsym
)
9312 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
9315 /* In case if we don't have global got symbols we default
9316 to setting DT_MIPS_GOTSYM to the same value as
9317 DT_MIPS_SYMTABNO, so we just fall through. */
9319 case DT_MIPS_SYMTABNO
:
9321 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
9322 s
= bfd_get_section_by_name (output_bfd
, name
);
9323 BFD_ASSERT (s
!= NULL
);
9325 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
9328 case DT_MIPS_HIPAGENO
:
9329 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO (info
);
9332 case DT_MIPS_RLD_MAP
:
9333 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
9336 case DT_MIPS_OPTIONS
:
9337 s
= (bfd_get_section_by_name
9338 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
9339 dyn
.d_un
.d_ptr
= s
->vma
;
9343 BFD_ASSERT (htab
->is_vxworks
);
9344 /* The count does not include the JUMP_SLOT relocations. */
9346 dyn
.d_un
.d_val
-= htab
->srelplt
->size
;
9350 BFD_ASSERT (htab
->is_vxworks
);
9351 dyn
.d_un
.d_val
= DT_RELA
;
9355 BFD_ASSERT (htab
->is_vxworks
);
9356 dyn
.d_un
.d_val
= htab
->srelplt
->size
;
9360 BFD_ASSERT (htab
->is_vxworks
);
9361 dyn
.d_un
.d_val
= (htab
->srelplt
->output_section
->vma
9362 + htab
->srelplt
->output_offset
);
9366 /* If we didn't need any text relocations after all, delete
9368 if (!(info
->flags
& DF_TEXTREL
))
9370 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
9376 /* If we didn't need any text relocations after all, clear
9377 DF_TEXTREL from DT_FLAGS. */
9378 if (!(info
->flags
& DF_TEXTREL
))
9379 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
9386 if (htab
->is_vxworks
9387 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
9392 if (swap_out_p
|| dyn_skipped
)
9393 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
9394 (dynobj
, &dyn
, b
- dyn_skipped
);
9398 dyn_skipped
+= dyn_to_skip
;
9403 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
9404 if (dyn_skipped
> 0)
9405 memset (b
- dyn_skipped
, 0, dyn_skipped
);
9408 if (sgot
!= NULL
&& sgot
->size
> 0
9409 && !bfd_is_abs_section (sgot
->output_section
))
9411 if (htab
->is_vxworks
)
9413 /* The first entry of the global offset table points to the
9414 ".dynamic" section. The second is initialized by the
9415 loader and contains the shared library identifier.
9416 The third is also initialized by the loader and points
9417 to the lazy resolution stub. */
9418 MIPS_ELF_PUT_WORD (output_bfd
,
9419 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
9421 MIPS_ELF_PUT_WORD (output_bfd
, 0,
9422 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
9423 MIPS_ELF_PUT_WORD (output_bfd
, 0,
9425 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
9429 /* The first entry of the global offset table will be filled at
9430 runtime. The second entry will be used by some runtime loaders.
9431 This isn't the case of IRIX rld. */
9432 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
9433 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
9434 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
9437 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
9438 = MIPS_ELF_GOT_SIZE (output_bfd
);
9441 /* Generate dynamic relocations for the non-primary gots. */
9442 if (gg
!= NULL
&& gg
->next
)
9444 Elf_Internal_Rela rel
[3];
9447 memset (rel
, 0, sizeof (rel
));
9448 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
9450 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
9452 bfd_vma index
= g
->next
->local_gotno
+ g
->next
->global_gotno
9453 + g
->next
->tls_gotno
;
9455 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
9456 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
9457 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
9459 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
9464 while (index
< g
->assigned_gotno
)
9466 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
9467 = index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
9468 if (!(mips_elf_create_dynamic_relocation
9469 (output_bfd
, info
, rel
, NULL
,
9470 bfd_abs_section_ptr
,
9473 BFD_ASSERT (addend
== 0);
9478 /* The generation of dynamic relocations for the non-primary gots
9479 adds more dynamic relocations. We cannot count them until
9482 if (elf_hash_table (info
)->dynamic_sections_created
)
9485 bfd_boolean swap_out_p
;
9487 BFD_ASSERT (sdyn
!= NULL
);
9489 for (b
= sdyn
->contents
;
9490 b
< sdyn
->contents
+ sdyn
->size
;
9491 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9493 Elf_Internal_Dyn dyn
;
9496 /* Read in the current dynamic entry. */
9497 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9499 /* Assume that we're going to modify it and write it out. */
9505 /* Reduce DT_RELSZ to account for any relocations we
9506 decided not to make. This is for the n64 irix rld,
9507 which doesn't seem to apply any relocations if there
9508 are trailing null entries. */
9509 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9510 dyn
.d_un
.d_val
= (s
->reloc_count
9511 * (ABI_64_P (output_bfd
)
9512 ? sizeof (Elf64_Mips_External_Rel
)
9513 : sizeof (Elf32_External_Rel
)));
9514 /* Adjust the section size too. Tools like the prelinker
9515 can reasonably expect the values to the same. */
9516 elf_section_data (s
->output_section
)->this_hdr
.sh_size
9526 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
9533 Elf32_compact_rel cpt
;
9535 if (SGI_COMPAT (output_bfd
))
9537 /* Write .compact_rel section out. */
9538 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
9542 cpt
.num
= s
->reloc_count
;
9544 cpt
.offset
= (s
->output_section
->filepos
9545 + sizeof (Elf32_External_compact_rel
));
9548 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
9549 ((Elf32_External_compact_rel
*)
9552 /* Clean up a dummy stub function entry in .text. */
9553 if (htab
->sstubs
!= NULL
)
9555 file_ptr dummy_offset
;
9557 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
9558 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
9559 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
9560 htab
->function_stub_size
);
9565 /* The psABI says that the dynamic relocations must be sorted in
9566 increasing order of r_symndx. The VxWorks EABI doesn't require
9567 this, and because the code below handles REL rather than RELA
9568 relocations, using it for VxWorks would be outright harmful. */
9569 if (!htab
->is_vxworks
)
9571 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9573 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
9575 reldyn_sorting_bfd
= output_bfd
;
9577 if (ABI_64_P (output_bfd
))
9578 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
9579 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
9580 sort_dynamic_relocs_64
);
9582 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
9583 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
9584 sort_dynamic_relocs
);
9589 if (htab
->is_vxworks
&& htab
->splt
->size
> 0)
9592 mips_vxworks_finish_shared_plt (output_bfd
, info
);
9594 mips_vxworks_finish_exec_plt (output_bfd
, info
);
9600 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
9603 mips_set_isa_flags (bfd
*abfd
)
9607 switch (bfd_get_mach (abfd
))
9610 case bfd_mach_mips3000
:
9611 val
= E_MIPS_ARCH_1
;
9614 case bfd_mach_mips3900
:
9615 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
9618 case bfd_mach_mips6000
:
9619 val
= E_MIPS_ARCH_2
;
9622 case bfd_mach_mips4000
:
9623 case bfd_mach_mips4300
:
9624 case bfd_mach_mips4400
:
9625 case bfd_mach_mips4600
:
9626 val
= E_MIPS_ARCH_3
;
9629 case bfd_mach_mips4010
:
9630 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
9633 case bfd_mach_mips4100
:
9634 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
9637 case bfd_mach_mips4111
:
9638 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
9641 case bfd_mach_mips4120
:
9642 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
9645 case bfd_mach_mips4650
:
9646 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
9649 case bfd_mach_mips5400
:
9650 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
9653 case bfd_mach_mips5500
:
9654 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
9657 case bfd_mach_mips9000
:
9658 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
9661 case bfd_mach_mips5000
:
9662 case bfd_mach_mips7000
:
9663 case bfd_mach_mips8000
:
9664 case bfd_mach_mips10000
:
9665 case bfd_mach_mips12000
:
9666 val
= E_MIPS_ARCH_4
;
9669 case bfd_mach_mips5
:
9670 val
= E_MIPS_ARCH_5
;
9673 case bfd_mach_mips_loongson_2e
:
9674 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
9677 case bfd_mach_mips_loongson_2f
:
9678 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
9681 case bfd_mach_mips_sb1
:
9682 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
9685 case bfd_mach_mips_octeon
:
9686 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
9689 case bfd_mach_mipsisa32
:
9690 val
= E_MIPS_ARCH_32
;
9693 case bfd_mach_mipsisa64
:
9694 val
= E_MIPS_ARCH_64
;
9697 case bfd_mach_mipsisa32r2
:
9698 val
= E_MIPS_ARCH_32R2
;
9701 case bfd_mach_mipsisa64r2
:
9702 val
= E_MIPS_ARCH_64R2
;
9705 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
9706 elf_elfheader (abfd
)->e_flags
|= val
;
9711 /* The final processing done just before writing out a MIPS ELF object
9712 file. This gets the MIPS architecture right based on the machine
9713 number. This is used by both the 32-bit and the 64-bit ABI. */
9716 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
9717 bfd_boolean linker ATTRIBUTE_UNUSED
)
9720 Elf_Internal_Shdr
**hdrpp
;
9724 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
9725 is nonzero. This is for compatibility with old objects, which used
9726 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
9727 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
9728 mips_set_isa_flags (abfd
);
9730 /* Set the sh_info field for .gptab sections and other appropriate
9731 info for each special section. */
9732 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
9733 i
< elf_numsections (abfd
);
9736 switch ((*hdrpp
)->sh_type
)
9739 case SHT_MIPS_LIBLIST
:
9740 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
9742 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9745 case SHT_MIPS_GPTAB
:
9746 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9747 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9748 BFD_ASSERT (name
!= NULL
9749 && CONST_STRNEQ (name
, ".gptab."));
9750 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
9751 BFD_ASSERT (sec
!= NULL
);
9752 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
9755 case SHT_MIPS_CONTENT
:
9756 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9757 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9758 BFD_ASSERT (name
!= NULL
9759 && CONST_STRNEQ (name
, ".MIPS.content"));
9760 sec
= bfd_get_section_by_name (abfd
,
9761 name
+ sizeof ".MIPS.content" - 1);
9762 BFD_ASSERT (sec
!= NULL
);
9763 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9766 case SHT_MIPS_SYMBOL_LIB
:
9767 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
9769 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9770 sec
= bfd_get_section_by_name (abfd
, ".liblist");
9772 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
9775 case SHT_MIPS_EVENTS
:
9776 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9777 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9778 BFD_ASSERT (name
!= NULL
);
9779 if (CONST_STRNEQ (name
, ".MIPS.events"))
9780 sec
= bfd_get_section_by_name (abfd
,
9781 name
+ sizeof ".MIPS.events" - 1);
9784 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
9785 sec
= bfd_get_section_by_name (abfd
,
9787 + sizeof ".MIPS.post_rel" - 1));
9789 BFD_ASSERT (sec
!= NULL
);
9790 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9797 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
9801 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
9802 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
9807 /* See if we need a PT_MIPS_REGINFO segment. */
9808 s
= bfd_get_section_by_name (abfd
, ".reginfo");
9809 if (s
&& (s
->flags
& SEC_LOAD
))
9812 /* See if we need a PT_MIPS_OPTIONS segment. */
9813 if (IRIX_COMPAT (abfd
) == ict_irix6
9814 && bfd_get_section_by_name (abfd
,
9815 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
9818 /* See if we need a PT_MIPS_RTPROC segment. */
9819 if (IRIX_COMPAT (abfd
) == ict_irix5
9820 && bfd_get_section_by_name (abfd
, ".dynamic")
9821 && bfd_get_section_by_name (abfd
, ".mdebug"))
9824 /* Allocate a PT_NULL header in dynamic objects. See
9825 _bfd_mips_elf_modify_segment_map for details. */
9826 if (!SGI_COMPAT (abfd
)
9827 && bfd_get_section_by_name (abfd
, ".dynamic"))
9833 /* Modify the segment map for an IRIX5 executable. */
9836 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
9837 struct bfd_link_info
*info
)
9840 struct elf_segment_map
*m
, **pm
;
9843 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
9845 s
= bfd_get_section_by_name (abfd
, ".reginfo");
9846 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
9848 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
9849 if (m
->p_type
== PT_MIPS_REGINFO
)
9854 m
= bfd_zalloc (abfd
, amt
);
9858 m
->p_type
= PT_MIPS_REGINFO
;
9862 /* We want to put it after the PHDR and INTERP segments. */
9863 pm
= &elf_tdata (abfd
)->segment_map
;
9865 && ((*pm
)->p_type
== PT_PHDR
9866 || (*pm
)->p_type
== PT_INTERP
))
9874 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
9875 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
9876 PT_MIPS_OPTIONS segment immediately following the program header
9879 /* On non-IRIX6 new abi, we'll have already created a segment
9880 for this section, so don't create another. I'm not sure this
9881 is not also the case for IRIX 6, but I can't test it right
9883 && IRIX_COMPAT (abfd
) == ict_irix6
)
9885 for (s
= abfd
->sections
; s
; s
= s
->next
)
9886 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
9891 struct elf_segment_map
*options_segment
;
9893 pm
= &elf_tdata (abfd
)->segment_map
;
9895 && ((*pm
)->p_type
== PT_PHDR
9896 || (*pm
)->p_type
== PT_INTERP
))
9899 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
9901 amt
= sizeof (struct elf_segment_map
);
9902 options_segment
= bfd_zalloc (abfd
, amt
);
9903 options_segment
->next
= *pm
;
9904 options_segment
->p_type
= PT_MIPS_OPTIONS
;
9905 options_segment
->p_flags
= PF_R
;
9906 options_segment
->p_flags_valid
= TRUE
;
9907 options_segment
->count
= 1;
9908 options_segment
->sections
[0] = s
;
9909 *pm
= options_segment
;
9915 if (IRIX_COMPAT (abfd
) == ict_irix5
)
9917 /* If there are .dynamic and .mdebug sections, we make a room
9918 for the RTPROC header. FIXME: Rewrite without section names. */
9919 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
9920 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
9921 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
9923 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
9924 if (m
->p_type
== PT_MIPS_RTPROC
)
9929 m
= bfd_zalloc (abfd
, amt
);
9933 m
->p_type
= PT_MIPS_RTPROC
;
9935 s
= bfd_get_section_by_name (abfd
, ".rtproc");
9940 m
->p_flags_valid
= 1;
9948 /* We want to put it after the DYNAMIC segment. */
9949 pm
= &elf_tdata (abfd
)->segment_map
;
9950 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
9960 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
9961 .dynstr, .dynsym, and .hash sections, and everything in
9963 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
9965 if ((*pm
)->p_type
== PT_DYNAMIC
)
9968 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
9970 /* For a normal mips executable the permissions for the PT_DYNAMIC
9971 segment are read, write and execute. We do that here since
9972 the code in elf.c sets only the read permission. This matters
9973 sometimes for the dynamic linker. */
9974 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
9976 m
->p_flags
= PF_R
| PF_W
| PF_X
;
9977 m
->p_flags_valid
= 1;
9980 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
9981 glibc's dynamic linker has traditionally derived the number of
9982 tags from the p_filesz field, and sometimes allocates stack
9983 arrays of that size. An overly-big PT_DYNAMIC segment can
9984 be actively harmful in such cases. Making PT_DYNAMIC contain
9985 other sections can also make life hard for the prelinker,
9986 which might move one of the other sections to a different
9988 if (SGI_COMPAT (abfd
)
9991 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
9993 static const char *sec_names
[] =
9995 ".dynamic", ".dynstr", ".dynsym", ".hash"
9999 struct elf_segment_map
*n
;
10001 low
= ~(bfd_vma
) 0;
10003 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
10005 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
10006 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10013 if (high
< s
->vma
+ sz
)
10014 high
= s
->vma
+ sz
;
10019 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10020 if ((s
->flags
& SEC_LOAD
) != 0
10022 && s
->vma
+ s
->size
<= high
)
10025 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
10026 n
= bfd_zalloc (abfd
, amt
);
10033 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10035 if ((s
->flags
& SEC_LOAD
) != 0
10037 && s
->vma
+ s
->size
<= high
)
10039 n
->sections
[i
] = s
;
10048 /* Allocate a spare program header in dynamic objects so that tools
10049 like the prelinker can add an extra PT_LOAD entry.
10051 If the prelinker needs to make room for a new PT_LOAD entry, its
10052 standard procedure is to move the first (read-only) sections into
10053 the new (writable) segment. However, the MIPS ABI requires
10054 .dynamic to be in a read-only segment, and the section will often
10055 start within sizeof (ElfNN_Phdr) bytes of the last program header.
10057 Although the prelinker could in principle move .dynamic to a
10058 writable segment, it seems better to allocate a spare program
10059 header instead, and avoid the need to move any sections.
10060 There is a long tradition of allocating spare dynamic tags,
10061 so allocating a spare program header seems like a natural
10064 If INFO is NULL, we may be copying an already prelinked binary
10065 with objcopy or strip, so do not add this header. */
10067 && !SGI_COMPAT (abfd
)
10068 && bfd_get_section_by_name (abfd
, ".dynamic"))
10070 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
10071 if ((*pm
)->p_type
== PT_NULL
)
10075 m
= bfd_zalloc (abfd
, sizeof (*m
));
10079 m
->p_type
= PT_NULL
;
10087 /* Return the section that should be marked against GC for a given
10091 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
10092 struct bfd_link_info
*info
,
10093 Elf_Internal_Rela
*rel
,
10094 struct elf_link_hash_entry
*h
,
10095 Elf_Internal_Sym
*sym
)
10097 /* ??? Do mips16 stub sections need to be handled special? */
10100 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
10102 case R_MIPS_GNU_VTINHERIT
:
10103 case R_MIPS_GNU_VTENTRY
:
10107 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
10110 /* Update the got entry reference counts for the section being removed. */
10113 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
10114 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
10115 asection
*sec ATTRIBUTE_UNUSED
,
10116 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
10119 Elf_Internal_Shdr
*symtab_hdr
;
10120 struct elf_link_hash_entry
**sym_hashes
;
10121 bfd_signed_vma
*local_got_refcounts
;
10122 const Elf_Internal_Rela
*rel
, *relend
;
10123 unsigned long r_symndx
;
10124 struct elf_link_hash_entry
*h
;
10126 if (info
->relocatable
)
10129 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
10130 sym_hashes
= elf_sym_hashes (abfd
);
10131 local_got_refcounts
= elf_local_got_refcounts (abfd
);
10133 relend
= relocs
+ sec
->reloc_count
;
10134 for (rel
= relocs
; rel
< relend
; rel
++)
10135 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
10137 case R_MIPS16_GOT16
:
10138 case R_MIPS16_CALL16
:
10140 case R_MIPS_CALL16
:
10141 case R_MIPS_CALL_HI16
:
10142 case R_MIPS_CALL_LO16
:
10143 case R_MIPS_GOT_HI16
:
10144 case R_MIPS_GOT_LO16
:
10145 case R_MIPS_GOT_DISP
:
10146 case R_MIPS_GOT_PAGE
:
10147 case R_MIPS_GOT_OFST
:
10148 /* ??? It would seem that the existing MIPS code does no sort
10149 of reference counting or whatnot on its GOT and PLT entries,
10150 so it is not possible to garbage collect them at this time. */
10161 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
10162 hiding the old indirect symbol. Process additional relocation
10163 information. Also called for weakdefs, in which case we just let
10164 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
10167 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
10168 struct elf_link_hash_entry
*dir
,
10169 struct elf_link_hash_entry
*ind
)
10171 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
10173 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
10175 if (ind
->root
.type
!= bfd_link_hash_indirect
)
10178 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
10179 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
10180 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
10181 if (indmips
->readonly_reloc
)
10182 dirmips
->readonly_reloc
= TRUE
;
10183 if (indmips
->no_fn_stub
)
10184 dirmips
->no_fn_stub
= TRUE
;
10186 if (dirmips
->tls_type
== 0)
10187 dirmips
->tls_type
= indmips
->tls_type
;
10191 _bfd_mips_elf_hide_symbol (struct bfd_link_info
*info
,
10192 struct elf_link_hash_entry
*entry
,
10193 bfd_boolean force_local
)
10196 struct mips_got_info
*g
;
10197 struct mips_elf_link_hash_entry
*h
;
10198 struct mips_elf_link_hash_table
*htab
;
10200 h
= (struct mips_elf_link_hash_entry
*) entry
;
10201 if (h
->forced_local
)
10203 h
->forced_local
= force_local
;
10205 dynobj
= elf_hash_table (info
)->dynobj
;
10206 htab
= mips_elf_hash_table (info
);
10209 && h
->root
.type
!= STT_TLS
10210 && htab
->got_info
!= NULL
)
10212 g
= htab
->got_info
;
10215 struct mips_got_entry e
;
10216 struct mips_got_info
*gg
= g
;
10218 /* Since we're turning what used to be a global symbol into a
10219 local one, bump up the number of local entries of each GOT
10220 that had an entry for it. This will automatically decrease
10221 the number of global entries, since global_gotno is actually
10222 the upper limit of global entries. */
10228 for (g
= g
->next
; g
!= gg
; g
= g
->next
)
10229 if (htab_find (g
->got_entries
, &e
))
10231 BFD_ASSERT (g
->global_gotno
> 0);
10236 /* If this was a global symbol forced into the primary GOT, we
10237 no longer need an entry for it. We can't release the entry
10238 at this point, but we must at least stop counting it as one
10239 of the symbols that required a forced got entry. */
10240 if (h
->root
.got
.offset
== 2)
10242 BFD_ASSERT (gg
->assigned_gotno
> 0);
10243 gg
->assigned_gotno
--;
10246 else if (h
->root
.got
.offset
== 1)
10248 /* check_relocs didn't know that this symbol would be
10249 forced-local, so add an extra local got entry. */
10251 if (htab
->computed_got_sizes
)
10253 /* We'll have treated this symbol as global rather
10255 BFD_ASSERT (g
->global_gotno
> 0);
10259 else if (htab
->is_vxworks
&& h
->root
.needs_plt
)
10261 /* check_relocs didn't know that this symbol would be
10262 forced-local, so add an extra local got entry. */
10264 if (htab
->computed_got_sizes
)
10265 /* The symbol is only used in call relocations, so we'll
10266 have assumed it only needs a .got.plt entry. Increase
10267 the size of .got accordingly. */
10268 htab
->sgot
->size
+= MIPS_ELF_GOT_SIZE (dynobj
);
10272 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
10275 #define PDR_SIZE 32
10278 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
10279 struct bfd_link_info
*info
)
10282 bfd_boolean ret
= FALSE
;
10283 unsigned char *tdata
;
10286 o
= bfd_get_section_by_name (abfd
, ".pdr");
10291 if (o
->size
% PDR_SIZE
!= 0)
10293 if (o
->output_section
!= NULL
10294 && bfd_is_abs_section (o
->output_section
))
10297 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
10301 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
10302 info
->keep_memory
);
10309 cookie
->rel
= cookie
->rels
;
10310 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
10312 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
10314 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
10323 mips_elf_section_data (o
)->u
.tdata
= tdata
;
10324 o
->size
-= skip
* PDR_SIZE
;
10330 if (! info
->keep_memory
)
10331 free (cookie
->rels
);
10337 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
10339 if (strcmp (sec
->name
, ".pdr") == 0)
10345 _bfd_mips_elf_write_section (bfd
*output_bfd
,
10346 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
10347 asection
*sec
, bfd_byte
*contents
)
10349 bfd_byte
*to
, *from
, *end
;
10352 if (strcmp (sec
->name
, ".pdr") != 0)
10355 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
10359 end
= contents
+ sec
->size
;
10360 for (from
= contents
, i
= 0;
10362 from
+= PDR_SIZE
, i
++)
10364 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
10367 memcpy (to
, from
, PDR_SIZE
);
10370 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
10371 sec
->output_offset
, sec
->size
);
10375 /* MIPS ELF uses a special find_nearest_line routine in order the
10376 handle the ECOFF debugging information. */
10378 struct mips_elf_find_line
10380 struct ecoff_debug_info d
;
10381 struct ecoff_find_line i
;
10385 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
10386 asymbol
**symbols
, bfd_vma offset
,
10387 const char **filename_ptr
,
10388 const char **functionname_ptr
,
10389 unsigned int *line_ptr
)
10393 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
10394 filename_ptr
, functionname_ptr
,
10398 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
10399 filename_ptr
, functionname_ptr
,
10400 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
10401 &elf_tdata (abfd
)->dwarf2_find_line_info
))
10404 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
10407 flagword origflags
;
10408 struct mips_elf_find_line
*fi
;
10409 const struct ecoff_debug_swap
* const swap
=
10410 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
10412 /* If we are called during a link, mips_elf_final_link may have
10413 cleared the SEC_HAS_CONTENTS field. We force it back on here
10414 if appropriate (which it normally will be). */
10415 origflags
= msec
->flags
;
10416 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
10417 msec
->flags
|= SEC_HAS_CONTENTS
;
10419 fi
= elf_tdata (abfd
)->find_line_info
;
10422 bfd_size_type external_fdr_size
;
10425 struct fdr
*fdr_ptr
;
10426 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
10428 fi
= bfd_zalloc (abfd
, amt
);
10431 msec
->flags
= origflags
;
10435 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
10437 msec
->flags
= origflags
;
10441 /* Swap in the FDR information. */
10442 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
10443 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
10444 if (fi
->d
.fdr
== NULL
)
10446 msec
->flags
= origflags
;
10449 external_fdr_size
= swap
->external_fdr_size
;
10450 fdr_ptr
= fi
->d
.fdr
;
10451 fraw_src
= (char *) fi
->d
.external_fdr
;
10452 fraw_end
= (fraw_src
10453 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
10454 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
10455 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
10457 elf_tdata (abfd
)->find_line_info
= fi
;
10459 /* Note that we don't bother to ever free this information.
10460 find_nearest_line is either called all the time, as in
10461 objdump -l, so the information should be saved, or it is
10462 rarely called, as in ld error messages, so the memory
10463 wasted is unimportant. Still, it would probably be a
10464 good idea for free_cached_info to throw it away. */
10467 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
10468 &fi
->i
, filename_ptr
, functionname_ptr
,
10471 msec
->flags
= origflags
;
10475 msec
->flags
= origflags
;
10478 /* Fall back on the generic ELF find_nearest_line routine. */
10480 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
10481 filename_ptr
, functionname_ptr
,
10486 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
10487 const char **filename_ptr
,
10488 const char **functionname_ptr
,
10489 unsigned int *line_ptr
)
10492 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
10493 functionname_ptr
, line_ptr
,
10494 & elf_tdata (abfd
)->dwarf2_find_line_info
);
10499 /* When are writing out the .options or .MIPS.options section,
10500 remember the bytes we are writing out, so that we can install the
10501 GP value in the section_processing routine. */
10504 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
10505 const void *location
,
10506 file_ptr offset
, bfd_size_type count
)
10508 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
10512 if (elf_section_data (section
) == NULL
)
10514 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
10515 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
10516 if (elf_section_data (section
) == NULL
)
10519 c
= mips_elf_section_data (section
)->u
.tdata
;
10522 c
= bfd_zalloc (abfd
, section
->size
);
10525 mips_elf_section_data (section
)->u
.tdata
= c
;
10528 memcpy (c
+ offset
, location
, count
);
10531 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
10535 /* This is almost identical to bfd_generic_get_... except that some
10536 MIPS relocations need to be handled specially. Sigh. */
10539 _bfd_elf_mips_get_relocated_section_contents
10541 struct bfd_link_info
*link_info
,
10542 struct bfd_link_order
*link_order
,
10544 bfd_boolean relocatable
,
10547 /* Get enough memory to hold the stuff */
10548 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
10549 asection
*input_section
= link_order
->u
.indirect
.section
;
10552 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
10553 arelent
**reloc_vector
= NULL
;
10556 if (reloc_size
< 0)
10559 reloc_vector
= bfd_malloc (reloc_size
);
10560 if (reloc_vector
== NULL
&& reloc_size
!= 0)
10563 /* read in the section */
10564 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
10565 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
10568 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
10572 if (reloc_count
< 0)
10575 if (reloc_count
> 0)
10580 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
10583 struct bfd_hash_entry
*h
;
10584 struct bfd_link_hash_entry
*lh
;
10585 /* Skip all this stuff if we aren't mixing formats. */
10586 if (abfd
&& input_bfd
10587 && abfd
->xvec
== input_bfd
->xvec
)
10591 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
10592 lh
= (struct bfd_link_hash_entry
*) h
;
10599 case bfd_link_hash_undefined
:
10600 case bfd_link_hash_undefweak
:
10601 case bfd_link_hash_common
:
10604 case bfd_link_hash_defined
:
10605 case bfd_link_hash_defweak
:
10607 gp
= lh
->u
.def
.value
;
10609 case bfd_link_hash_indirect
:
10610 case bfd_link_hash_warning
:
10612 /* @@FIXME ignoring warning for now */
10614 case bfd_link_hash_new
:
10623 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
10625 char *error_message
= NULL
;
10626 bfd_reloc_status_type r
;
10628 /* Specific to MIPS: Deal with relocation types that require
10629 knowing the gp of the output bfd. */
10630 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
10632 /* If we've managed to find the gp and have a special
10633 function for the relocation then go ahead, else default
10634 to the generic handling. */
10636 && (*parent
)->howto
->special_function
10637 == _bfd_mips_elf32_gprel16_reloc
)
10638 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
10639 input_section
, relocatable
,
10642 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
10644 relocatable
? abfd
: NULL
,
10649 asection
*os
= input_section
->output_section
;
10651 /* A partial link, so keep the relocs */
10652 os
->orelocation
[os
->reloc_count
] = *parent
;
10656 if (r
!= bfd_reloc_ok
)
10660 case bfd_reloc_undefined
:
10661 if (!((*link_info
->callbacks
->undefined_symbol
)
10662 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
10663 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
10666 case bfd_reloc_dangerous
:
10667 BFD_ASSERT (error_message
!= NULL
);
10668 if (!((*link_info
->callbacks
->reloc_dangerous
)
10669 (link_info
, error_message
, input_bfd
, input_section
,
10670 (*parent
)->address
)))
10673 case bfd_reloc_overflow
:
10674 if (!((*link_info
->callbacks
->reloc_overflow
)
10676 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
10677 (*parent
)->howto
->name
, (*parent
)->addend
,
10678 input_bfd
, input_section
, (*parent
)->address
)))
10681 case bfd_reloc_outofrange
:
10690 if (reloc_vector
!= NULL
)
10691 free (reloc_vector
);
10695 if (reloc_vector
!= NULL
)
10696 free (reloc_vector
);
10700 /* Create a MIPS ELF linker hash table. */
10702 struct bfd_link_hash_table
*
10703 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
10705 struct mips_elf_link_hash_table
*ret
;
10706 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
10708 ret
= bfd_malloc (amt
);
10712 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
10713 mips_elf_link_hash_newfunc
,
10714 sizeof (struct mips_elf_link_hash_entry
)))
10721 /* We no longer use this. */
10722 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
10723 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
10725 ret
->procedure_count
= 0;
10726 ret
->compact_rel_size
= 0;
10727 ret
->use_rld_obj_head
= FALSE
;
10728 ret
->rld_value
= 0;
10729 ret
->mips16_stubs_seen
= FALSE
;
10730 ret
->computed_got_sizes
= FALSE
;
10731 ret
->is_vxworks
= FALSE
;
10732 ret
->small_data_overflow_reported
= FALSE
;
10733 ret
->srelbss
= NULL
;
10734 ret
->sdynbss
= NULL
;
10735 ret
->srelplt
= NULL
;
10736 ret
->srelplt2
= NULL
;
10737 ret
->sgotplt
= NULL
;
10739 ret
->sstubs
= NULL
;
10741 ret
->got_info
= NULL
;
10742 ret
->plt_header_size
= 0;
10743 ret
->plt_entry_size
= 0;
10744 ret
->function_stub_size
= 0;
10746 return &ret
->root
.root
;
10749 /* Likewise, but indicate that the target is VxWorks. */
10751 struct bfd_link_hash_table
*
10752 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
10754 struct bfd_link_hash_table
*ret
;
10756 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
10759 struct mips_elf_link_hash_table
*htab
;
10761 htab
= (struct mips_elf_link_hash_table
*) ret
;
10762 htab
->is_vxworks
= 1;
10767 /* We need to use a special link routine to handle the .reginfo and
10768 the .mdebug sections. We need to merge all instances of these
10769 sections together, not write them all out sequentially. */
10772 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
10775 struct bfd_link_order
*p
;
10776 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
10777 asection
*rtproc_sec
;
10778 Elf32_RegInfo reginfo
;
10779 struct ecoff_debug_info debug
;
10780 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
10781 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
10782 HDRR
*symhdr
= &debug
.symbolic_header
;
10783 void *mdebug_handle
= NULL
;
10788 struct mips_elf_link_hash_table
*htab
;
10790 static const char * const secname
[] =
10792 ".text", ".init", ".fini", ".data",
10793 ".rodata", ".sdata", ".sbss", ".bss"
10795 static const int sc
[] =
10797 scText
, scInit
, scFini
, scData
,
10798 scRData
, scSData
, scSBss
, scBss
10801 /* We'd carefully arranged the dynamic symbol indices, and then the
10802 generic size_dynamic_sections renumbered them out from under us.
10803 Rather than trying somehow to prevent the renumbering, just do
10805 htab
= mips_elf_hash_table (info
);
10806 if (elf_hash_table (info
)->dynamic_sections_created
)
10808 struct mips_got_info
*g
;
10809 bfd_size_type dynsecsymcount
;
10811 /* When we resort, we must tell mips_elf_sort_hash_table what
10812 the lowest index it may use is. That's the number of section
10813 symbols we're going to add. The generic ELF linker only
10814 adds these symbols when building a shared object. Note that
10815 we count the sections after (possibly) removing the .options
10818 dynsecsymcount
= count_section_dynsyms (abfd
, info
);
10819 if (! mips_elf_sort_hash_table (info
, dynsecsymcount
+ 1))
10822 /* Make sure we didn't grow the global .got region. */
10823 g
= htab
->got_info
;
10824 if (g
->global_gotsym
!= NULL
)
10825 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
10826 - g
->global_gotsym
->dynindx
)
10827 <= g
->global_gotno
);
10830 /* Get a value for the GP register. */
10831 if (elf_gp (abfd
) == 0)
10833 struct bfd_link_hash_entry
*h
;
10835 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
10836 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
10837 elf_gp (abfd
) = (h
->u
.def
.value
10838 + h
->u
.def
.section
->output_section
->vma
10839 + h
->u
.def
.section
->output_offset
);
10840 else if (htab
->is_vxworks
10841 && (h
= bfd_link_hash_lookup (info
->hash
,
10842 "_GLOBAL_OFFSET_TABLE_",
10843 FALSE
, FALSE
, TRUE
))
10844 && h
->type
== bfd_link_hash_defined
)
10845 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
10846 + h
->u
.def
.section
->output_offset
10848 else if (info
->relocatable
)
10850 bfd_vma lo
= MINUS_ONE
;
10852 /* Find the GP-relative section with the lowest offset. */
10853 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10855 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
10858 /* And calculate GP relative to that. */
10859 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
10863 /* If the relocate_section function needs to do a reloc
10864 involving the GP value, it should make a reloc_dangerous
10865 callback to warn that GP is not defined. */
10869 /* Go through the sections and collect the .reginfo and .mdebug
10871 reginfo_sec
= NULL
;
10873 gptab_data_sec
= NULL
;
10874 gptab_bss_sec
= NULL
;
10875 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10877 if (strcmp (o
->name
, ".reginfo") == 0)
10879 memset (®info
, 0, sizeof reginfo
);
10881 /* We have found the .reginfo section in the output file.
10882 Look through all the link_orders comprising it and merge
10883 the information together. */
10884 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10886 asection
*input_section
;
10888 Elf32_External_RegInfo ext
;
10891 if (p
->type
!= bfd_indirect_link_order
)
10893 if (p
->type
== bfd_data_link_order
)
10898 input_section
= p
->u
.indirect
.section
;
10899 input_bfd
= input_section
->owner
;
10901 if (! bfd_get_section_contents (input_bfd
, input_section
,
10902 &ext
, 0, sizeof ext
))
10905 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
10907 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
10908 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
10909 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
10910 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
10911 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
10913 /* ri_gp_value is set by the function
10914 mips_elf32_section_processing when the section is
10915 finally written out. */
10917 /* Hack: reset the SEC_HAS_CONTENTS flag so that
10918 elf_link_input_bfd ignores this section. */
10919 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
10922 /* Size has been set in _bfd_mips_elf_always_size_sections. */
10923 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
10925 /* Skip this section later on (I don't think this currently
10926 matters, but someday it might). */
10927 o
->map_head
.link_order
= NULL
;
10932 if (strcmp (o
->name
, ".mdebug") == 0)
10934 struct extsym_info einfo
;
10937 /* We have found the .mdebug section in the output file.
10938 Look through all the link_orders comprising it and merge
10939 the information together. */
10940 symhdr
->magic
= swap
->sym_magic
;
10941 /* FIXME: What should the version stamp be? */
10942 symhdr
->vstamp
= 0;
10943 symhdr
->ilineMax
= 0;
10944 symhdr
->cbLine
= 0;
10945 symhdr
->idnMax
= 0;
10946 symhdr
->ipdMax
= 0;
10947 symhdr
->isymMax
= 0;
10948 symhdr
->ioptMax
= 0;
10949 symhdr
->iauxMax
= 0;
10950 symhdr
->issMax
= 0;
10951 symhdr
->issExtMax
= 0;
10952 symhdr
->ifdMax
= 0;
10954 symhdr
->iextMax
= 0;
10956 /* We accumulate the debugging information itself in the
10957 debug_info structure. */
10959 debug
.external_dnr
= NULL
;
10960 debug
.external_pdr
= NULL
;
10961 debug
.external_sym
= NULL
;
10962 debug
.external_opt
= NULL
;
10963 debug
.external_aux
= NULL
;
10965 debug
.ssext
= debug
.ssext_end
= NULL
;
10966 debug
.external_fdr
= NULL
;
10967 debug
.external_rfd
= NULL
;
10968 debug
.external_ext
= debug
.external_ext_end
= NULL
;
10970 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
10971 if (mdebug_handle
== NULL
)
10975 esym
.cobol_main
= 0;
10979 esym
.asym
.iss
= issNil
;
10980 esym
.asym
.st
= stLocal
;
10981 esym
.asym
.reserved
= 0;
10982 esym
.asym
.index
= indexNil
;
10984 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
10986 esym
.asym
.sc
= sc
[i
];
10987 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
10990 esym
.asym
.value
= s
->vma
;
10991 last
= s
->vma
+ s
->size
;
10994 esym
.asym
.value
= last
;
10995 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
10996 secname
[i
], &esym
))
11000 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11002 asection
*input_section
;
11004 const struct ecoff_debug_swap
*input_swap
;
11005 struct ecoff_debug_info input_debug
;
11009 if (p
->type
!= bfd_indirect_link_order
)
11011 if (p
->type
== bfd_data_link_order
)
11016 input_section
= p
->u
.indirect
.section
;
11017 input_bfd
= input_section
->owner
;
11019 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
11020 || (get_elf_backend_data (input_bfd
)
11021 ->elf_backend_ecoff_debug_swap
) == NULL
)
11023 /* I don't know what a non MIPS ELF bfd would be
11024 doing with a .mdebug section, but I don't really
11025 want to deal with it. */
11029 input_swap
= (get_elf_backend_data (input_bfd
)
11030 ->elf_backend_ecoff_debug_swap
);
11032 BFD_ASSERT (p
->size
== input_section
->size
);
11034 /* The ECOFF linking code expects that we have already
11035 read in the debugging information and set up an
11036 ecoff_debug_info structure, so we do that now. */
11037 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
11041 if (! (bfd_ecoff_debug_accumulate
11042 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
11043 &input_debug
, input_swap
, info
)))
11046 /* Loop through the external symbols. For each one with
11047 interesting information, try to find the symbol in
11048 the linker global hash table and save the information
11049 for the output external symbols. */
11050 eraw_src
= input_debug
.external_ext
;
11051 eraw_end
= (eraw_src
11052 + (input_debug
.symbolic_header
.iextMax
11053 * input_swap
->external_ext_size
));
11055 eraw_src
< eraw_end
;
11056 eraw_src
+= input_swap
->external_ext_size
)
11060 struct mips_elf_link_hash_entry
*h
;
11062 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
11063 if (ext
.asym
.sc
== scNil
11064 || ext
.asym
.sc
== scUndefined
11065 || ext
.asym
.sc
== scSUndefined
)
11068 name
= input_debug
.ssext
+ ext
.asym
.iss
;
11069 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
11070 name
, FALSE
, FALSE
, TRUE
);
11071 if (h
== NULL
|| h
->esym
.ifd
!= -2)
11076 BFD_ASSERT (ext
.ifd
11077 < input_debug
.symbolic_header
.ifdMax
);
11078 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
11084 /* Free up the information we just read. */
11085 free (input_debug
.line
);
11086 free (input_debug
.external_dnr
);
11087 free (input_debug
.external_pdr
);
11088 free (input_debug
.external_sym
);
11089 free (input_debug
.external_opt
);
11090 free (input_debug
.external_aux
);
11091 free (input_debug
.ss
);
11092 free (input_debug
.ssext
);
11093 free (input_debug
.external_fdr
);
11094 free (input_debug
.external_rfd
);
11095 free (input_debug
.external_ext
);
11097 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11098 elf_link_input_bfd ignores this section. */
11099 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11102 if (SGI_COMPAT (abfd
) && info
->shared
)
11104 /* Create .rtproc section. */
11105 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11106 if (rtproc_sec
== NULL
)
11108 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
11109 | SEC_LINKER_CREATED
| SEC_READONLY
);
11111 rtproc_sec
= bfd_make_section_with_flags (abfd
,
11114 if (rtproc_sec
== NULL
11115 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
11119 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
11125 /* Build the external symbol information. */
11128 einfo
.debug
= &debug
;
11130 einfo
.failed
= FALSE
;
11131 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
11132 mips_elf_output_extsym
, &einfo
);
11136 /* Set the size of the .mdebug section. */
11137 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
11139 /* Skip this section later on (I don't think this currently
11140 matters, but someday it might). */
11141 o
->map_head
.link_order
= NULL
;
11146 if (CONST_STRNEQ (o
->name
, ".gptab."))
11148 const char *subname
;
11151 Elf32_External_gptab
*ext_tab
;
11154 /* The .gptab.sdata and .gptab.sbss sections hold
11155 information describing how the small data area would
11156 change depending upon the -G switch. These sections
11157 not used in executables files. */
11158 if (! info
->relocatable
)
11160 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11162 asection
*input_section
;
11164 if (p
->type
!= bfd_indirect_link_order
)
11166 if (p
->type
== bfd_data_link_order
)
11171 input_section
= p
->u
.indirect
.section
;
11173 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11174 elf_link_input_bfd ignores this section. */
11175 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11178 /* Skip this section later on (I don't think this
11179 currently matters, but someday it might). */
11180 o
->map_head
.link_order
= NULL
;
11182 /* Really remove the section. */
11183 bfd_section_list_remove (abfd
, o
);
11184 --abfd
->section_count
;
11189 /* There is one gptab for initialized data, and one for
11190 uninitialized data. */
11191 if (strcmp (o
->name
, ".gptab.sdata") == 0)
11192 gptab_data_sec
= o
;
11193 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
11197 (*_bfd_error_handler
)
11198 (_("%s: illegal section name `%s'"),
11199 bfd_get_filename (abfd
), o
->name
);
11200 bfd_set_error (bfd_error_nonrepresentable_section
);
11204 /* The linker script always combines .gptab.data and
11205 .gptab.sdata into .gptab.sdata, and likewise for
11206 .gptab.bss and .gptab.sbss. It is possible that there is
11207 no .sdata or .sbss section in the output file, in which
11208 case we must change the name of the output section. */
11209 subname
= o
->name
+ sizeof ".gptab" - 1;
11210 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
11212 if (o
== gptab_data_sec
)
11213 o
->name
= ".gptab.data";
11215 o
->name
= ".gptab.bss";
11216 subname
= o
->name
+ sizeof ".gptab" - 1;
11217 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
11220 /* Set up the first entry. */
11222 amt
= c
* sizeof (Elf32_gptab
);
11223 tab
= bfd_malloc (amt
);
11226 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
11227 tab
[0].gt_header
.gt_unused
= 0;
11229 /* Combine the input sections. */
11230 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11232 asection
*input_section
;
11234 bfd_size_type size
;
11235 unsigned long last
;
11236 bfd_size_type gpentry
;
11238 if (p
->type
!= bfd_indirect_link_order
)
11240 if (p
->type
== bfd_data_link_order
)
11245 input_section
= p
->u
.indirect
.section
;
11246 input_bfd
= input_section
->owner
;
11248 /* Combine the gptab entries for this input section one
11249 by one. We know that the input gptab entries are
11250 sorted by ascending -G value. */
11251 size
= input_section
->size
;
11253 for (gpentry
= sizeof (Elf32_External_gptab
);
11255 gpentry
+= sizeof (Elf32_External_gptab
))
11257 Elf32_External_gptab ext_gptab
;
11258 Elf32_gptab int_gptab
;
11264 if (! (bfd_get_section_contents
11265 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
11266 sizeof (Elf32_External_gptab
))))
11272 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
11274 val
= int_gptab
.gt_entry
.gt_g_value
;
11275 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
11278 for (look
= 1; look
< c
; look
++)
11280 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
11281 tab
[look
].gt_entry
.gt_bytes
+= add
;
11283 if (tab
[look
].gt_entry
.gt_g_value
== val
)
11289 Elf32_gptab
*new_tab
;
11292 /* We need a new table entry. */
11293 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
11294 new_tab
= bfd_realloc (tab
, amt
);
11295 if (new_tab
== NULL
)
11301 tab
[c
].gt_entry
.gt_g_value
= val
;
11302 tab
[c
].gt_entry
.gt_bytes
= add
;
11304 /* Merge in the size for the next smallest -G
11305 value, since that will be implied by this new
11308 for (look
= 1; look
< c
; look
++)
11310 if (tab
[look
].gt_entry
.gt_g_value
< val
11312 || (tab
[look
].gt_entry
.gt_g_value
11313 > tab
[max
].gt_entry
.gt_g_value
)))
11317 tab
[c
].gt_entry
.gt_bytes
+=
11318 tab
[max
].gt_entry
.gt_bytes
;
11323 last
= int_gptab
.gt_entry
.gt_bytes
;
11326 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11327 elf_link_input_bfd ignores this section. */
11328 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11331 /* The table must be sorted by -G value. */
11333 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
11335 /* Swap out the table. */
11336 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
11337 ext_tab
= bfd_alloc (abfd
, amt
);
11338 if (ext_tab
== NULL
)
11344 for (j
= 0; j
< c
; j
++)
11345 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
11348 o
->size
= c
* sizeof (Elf32_External_gptab
);
11349 o
->contents
= (bfd_byte
*) ext_tab
;
11351 /* Skip this section later on (I don't think this currently
11352 matters, but someday it might). */
11353 o
->map_head
.link_order
= NULL
;
11357 /* Invoke the regular ELF backend linker to do all the work. */
11358 if (!bfd_elf_final_link (abfd
, info
))
11361 /* Now write out the computed sections. */
11363 if (reginfo_sec
!= NULL
)
11365 Elf32_External_RegInfo ext
;
11367 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
11368 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
11372 if (mdebug_sec
!= NULL
)
11374 BFD_ASSERT (abfd
->output_has_begun
);
11375 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
11377 mdebug_sec
->filepos
))
11380 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
11383 if (gptab_data_sec
!= NULL
)
11385 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
11386 gptab_data_sec
->contents
,
11387 0, gptab_data_sec
->size
))
11391 if (gptab_bss_sec
!= NULL
)
11393 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
11394 gptab_bss_sec
->contents
,
11395 0, gptab_bss_sec
->size
))
11399 if (SGI_COMPAT (abfd
))
11401 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11402 if (rtproc_sec
!= NULL
)
11404 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
11405 rtproc_sec
->contents
,
11406 0, rtproc_sec
->size
))
11414 /* Structure for saying that BFD machine EXTENSION extends BASE. */
11416 struct mips_mach_extension
{
11417 unsigned long extension
, base
;
11421 /* An array describing how BFD machines relate to one another. The entries
11422 are ordered topologically with MIPS I extensions listed last. */
11424 static const struct mips_mach_extension mips_mach_extensions
[] = {
11425 /* MIPS64r2 extensions. */
11426 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
11428 /* MIPS64 extensions. */
11429 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
11430 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
11432 /* MIPS V extensions. */
11433 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
11435 /* R10000 extensions. */
11436 { bfd_mach_mips12000
, bfd_mach_mips10000
},
11438 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
11439 vr5400 ISA, but doesn't include the multimedia stuff. It seems
11440 better to allow vr5400 and vr5500 code to be merged anyway, since
11441 many libraries will just use the core ISA. Perhaps we could add
11442 some sort of ASE flag if this ever proves a problem. */
11443 { bfd_mach_mips5500
, bfd_mach_mips5400
},
11444 { bfd_mach_mips5400
, bfd_mach_mips5000
},
11446 /* MIPS IV extensions. */
11447 { bfd_mach_mips5
, bfd_mach_mips8000
},
11448 { bfd_mach_mips10000
, bfd_mach_mips8000
},
11449 { bfd_mach_mips5000
, bfd_mach_mips8000
},
11450 { bfd_mach_mips7000
, bfd_mach_mips8000
},
11451 { bfd_mach_mips9000
, bfd_mach_mips8000
},
11453 /* VR4100 extensions. */
11454 { bfd_mach_mips4120
, bfd_mach_mips4100
},
11455 { bfd_mach_mips4111
, bfd_mach_mips4100
},
11457 /* MIPS III extensions. */
11458 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
11459 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
11460 { bfd_mach_mips8000
, bfd_mach_mips4000
},
11461 { bfd_mach_mips4650
, bfd_mach_mips4000
},
11462 { bfd_mach_mips4600
, bfd_mach_mips4000
},
11463 { bfd_mach_mips4400
, bfd_mach_mips4000
},
11464 { bfd_mach_mips4300
, bfd_mach_mips4000
},
11465 { bfd_mach_mips4100
, bfd_mach_mips4000
},
11466 { bfd_mach_mips4010
, bfd_mach_mips4000
},
11468 /* MIPS32 extensions. */
11469 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
11471 /* MIPS II extensions. */
11472 { bfd_mach_mips4000
, bfd_mach_mips6000
},
11473 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
11475 /* MIPS I extensions. */
11476 { bfd_mach_mips6000
, bfd_mach_mips3000
},
11477 { bfd_mach_mips3900
, bfd_mach_mips3000
}
11481 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
11484 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
11488 if (extension
== base
)
11491 if (base
== bfd_mach_mipsisa32
11492 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
11495 if (base
== bfd_mach_mipsisa32r2
11496 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
11499 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
11500 if (extension
== mips_mach_extensions
[i
].extension
)
11502 extension
= mips_mach_extensions
[i
].base
;
11503 if (extension
== base
)
11511 /* Return true if the given ELF header flags describe a 32-bit binary. */
11514 mips_32bit_flags_p (flagword flags
)
11516 return ((flags
& EF_MIPS_32BITMODE
) != 0
11517 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
11518 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
11519 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
11520 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
11521 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
11522 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
11526 /* Merge object attributes from IBFD into OBFD. Raise an error if
11527 there are conflicting attributes. */
11529 mips_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
11531 obj_attribute
*in_attr
;
11532 obj_attribute
*out_attr
;
11534 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
11536 /* This is the first object. Copy the attributes. */
11537 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
11539 /* Use the Tag_null value to indicate the attributes have been
11541 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
11546 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
11547 non-conflicting ones. */
11548 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
11549 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
11550 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11552 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
11553 if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
11554 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
11555 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
11557 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
11559 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
11560 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
11561 else if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
11563 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
11564 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
11566 switch (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11569 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11573 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
11579 (_("Warning: %B uses hard float, %B uses soft float"),
11585 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
11595 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11599 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
11605 (_("Warning: %B uses hard float, %B uses soft float"),
11611 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
11621 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11627 (_("Warning: %B uses hard float, %B uses soft float"),
11637 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11641 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
11647 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
11653 (_("Warning: %B uses hard float, %B uses soft float"),
11667 /* Merge Tag_compatibility attributes and any common GNU ones. */
11668 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
11673 /* Merge backend specific data from an object file to the output
11674 object file when linking. */
11677 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
11679 flagword old_flags
;
11680 flagword new_flags
;
11682 bfd_boolean null_input_bfd
= TRUE
;
11685 /* Check if we have the same endianess */
11686 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
11688 (*_bfd_error_handler
)
11689 (_("%B: endianness incompatible with that of the selected emulation"),
11694 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
11695 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
11698 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
11700 (*_bfd_error_handler
)
11701 (_("%B: ABI is incompatible with that of the selected emulation"),
11706 if (!mips_elf_merge_obj_attributes (ibfd
, obfd
))
11709 new_flags
= elf_elfheader (ibfd
)->e_flags
;
11710 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
11711 old_flags
= elf_elfheader (obfd
)->e_flags
;
11713 if (! elf_flags_init (obfd
))
11715 elf_flags_init (obfd
) = TRUE
;
11716 elf_elfheader (obfd
)->e_flags
= new_flags
;
11717 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
11718 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
11720 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
11721 && (bfd_get_arch_info (obfd
)->the_default
11722 || mips_mach_extends_p (bfd_get_mach (obfd
),
11723 bfd_get_mach (ibfd
))))
11725 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
11726 bfd_get_mach (ibfd
)))
11733 /* Check flag compatibility. */
11735 new_flags
&= ~EF_MIPS_NOREORDER
;
11736 old_flags
&= ~EF_MIPS_NOREORDER
;
11738 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
11739 doesn't seem to matter. */
11740 new_flags
&= ~EF_MIPS_XGOT
;
11741 old_flags
&= ~EF_MIPS_XGOT
;
11743 /* MIPSpro generates ucode info in n64 objects. Again, we should
11744 just be able to ignore this. */
11745 new_flags
&= ~EF_MIPS_UCODE
;
11746 old_flags
&= ~EF_MIPS_UCODE
;
11748 /* Don't care about the PIC flags from dynamic objects; they are
11750 if ((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0
11751 && (ibfd
->flags
& DYNAMIC
) != 0)
11752 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11754 if (new_flags
== old_flags
)
11757 /* Check to see if the input BFD actually contains any sections.
11758 If not, its flags may not have been initialised either, but it cannot
11759 actually cause any incompatibility. */
11760 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
11762 /* Ignore synthetic sections and empty .text, .data and .bss sections
11763 which are automatically generated by gas. */
11764 if (strcmp (sec
->name
, ".reginfo")
11765 && strcmp (sec
->name
, ".mdebug")
11767 || (strcmp (sec
->name
, ".text")
11768 && strcmp (sec
->name
, ".data")
11769 && strcmp (sec
->name
, ".bss"))))
11771 null_input_bfd
= FALSE
;
11775 if (null_input_bfd
)
11780 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
11781 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
11783 (*_bfd_error_handler
)
11784 (_("%B: warning: linking PIC files with non-PIC files"),
11789 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
11790 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
11791 if (! (new_flags
& EF_MIPS_PIC
))
11792 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
11794 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11795 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11797 /* Compare the ISAs. */
11798 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
11800 (*_bfd_error_handler
)
11801 (_("%B: linking 32-bit code with 64-bit code"),
11805 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
11807 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
11808 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
11810 /* Copy the architecture info from IBFD to OBFD. Also copy
11811 the 32-bit flag (if set) so that we continue to recognise
11812 OBFD as a 32-bit binary. */
11813 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
11814 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
11815 elf_elfheader (obfd
)->e_flags
11816 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11818 /* Copy across the ABI flags if OBFD doesn't use them
11819 and if that was what caused us to treat IBFD as 32-bit. */
11820 if ((old_flags
& EF_MIPS_ABI
) == 0
11821 && mips_32bit_flags_p (new_flags
)
11822 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
11823 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
11827 /* The ISAs aren't compatible. */
11828 (*_bfd_error_handler
)
11829 (_("%B: linking %s module with previous %s modules"),
11831 bfd_printable_name (ibfd
),
11832 bfd_printable_name (obfd
));
11837 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11838 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11840 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
11841 does set EI_CLASS differently from any 32-bit ABI. */
11842 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
11843 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
11844 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
11846 /* Only error if both are set (to different values). */
11847 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
11848 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
11849 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
11851 (*_bfd_error_handler
)
11852 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
11854 elf_mips_abi_name (ibfd
),
11855 elf_mips_abi_name (obfd
));
11858 new_flags
&= ~EF_MIPS_ABI
;
11859 old_flags
&= ~EF_MIPS_ABI
;
11862 /* For now, allow arbitrary mixing of ASEs (retain the union). */
11863 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
11865 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
11867 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
11868 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
11871 /* Warn about any other mismatches */
11872 if (new_flags
!= old_flags
)
11874 (*_bfd_error_handler
)
11875 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
11876 ibfd
, (unsigned long) new_flags
,
11877 (unsigned long) old_flags
);
11883 bfd_set_error (bfd_error_bad_value
);
11890 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
11893 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
11895 BFD_ASSERT (!elf_flags_init (abfd
)
11896 || elf_elfheader (abfd
)->e_flags
== flags
);
11898 elf_elfheader (abfd
)->e_flags
= flags
;
11899 elf_flags_init (abfd
) = TRUE
;
11904 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
11908 default: return "";
11909 case DT_MIPS_RLD_VERSION
:
11910 return "MIPS_RLD_VERSION";
11911 case DT_MIPS_TIME_STAMP
:
11912 return "MIPS_TIME_STAMP";
11913 case DT_MIPS_ICHECKSUM
:
11914 return "MIPS_ICHECKSUM";
11915 case DT_MIPS_IVERSION
:
11916 return "MIPS_IVERSION";
11917 case DT_MIPS_FLAGS
:
11918 return "MIPS_FLAGS";
11919 case DT_MIPS_BASE_ADDRESS
:
11920 return "MIPS_BASE_ADDRESS";
11922 return "MIPS_MSYM";
11923 case DT_MIPS_CONFLICT
:
11924 return "MIPS_CONFLICT";
11925 case DT_MIPS_LIBLIST
:
11926 return "MIPS_LIBLIST";
11927 case DT_MIPS_LOCAL_GOTNO
:
11928 return "MIPS_LOCAL_GOTNO";
11929 case DT_MIPS_CONFLICTNO
:
11930 return "MIPS_CONFLICTNO";
11931 case DT_MIPS_LIBLISTNO
:
11932 return "MIPS_LIBLISTNO";
11933 case DT_MIPS_SYMTABNO
:
11934 return "MIPS_SYMTABNO";
11935 case DT_MIPS_UNREFEXTNO
:
11936 return "MIPS_UNREFEXTNO";
11937 case DT_MIPS_GOTSYM
:
11938 return "MIPS_GOTSYM";
11939 case DT_MIPS_HIPAGENO
:
11940 return "MIPS_HIPAGENO";
11941 case DT_MIPS_RLD_MAP
:
11942 return "MIPS_RLD_MAP";
11943 case DT_MIPS_DELTA_CLASS
:
11944 return "MIPS_DELTA_CLASS";
11945 case DT_MIPS_DELTA_CLASS_NO
:
11946 return "MIPS_DELTA_CLASS_NO";
11947 case DT_MIPS_DELTA_INSTANCE
:
11948 return "MIPS_DELTA_INSTANCE";
11949 case DT_MIPS_DELTA_INSTANCE_NO
:
11950 return "MIPS_DELTA_INSTANCE_NO";
11951 case DT_MIPS_DELTA_RELOC
:
11952 return "MIPS_DELTA_RELOC";
11953 case DT_MIPS_DELTA_RELOC_NO
:
11954 return "MIPS_DELTA_RELOC_NO";
11955 case DT_MIPS_DELTA_SYM
:
11956 return "MIPS_DELTA_SYM";
11957 case DT_MIPS_DELTA_SYM_NO
:
11958 return "MIPS_DELTA_SYM_NO";
11959 case DT_MIPS_DELTA_CLASSSYM
:
11960 return "MIPS_DELTA_CLASSSYM";
11961 case DT_MIPS_DELTA_CLASSSYM_NO
:
11962 return "MIPS_DELTA_CLASSSYM_NO";
11963 case DT_MIPS_CXX_FLAGS
:
11964 return "MIPS_CXX_FLAGS";
11965 case DT_MIPS_PIXIE_INIT
:
11966 return "MIPS_PIXIE_INIT";
11967 case DT_MIPS_SYMBOL_LIB
:
11968 return "MIPS_SYMBOL_LIB";
11969 case DT_MIPS_LOCALPAGE_GOTIDX
:
11970 return "MIPS_LOCALPAGE_GOTIDX";
11971 case DT_MIPS_LOCAL_GOTIDX
:
11972 return "MIPS_LOCAL_GOTIDX";
11973 case DT_MIPS_HIDDEN_GOTIDX
:
11974 return "MIPS_HIDDEN_GOTIDX";
11975 case DT_MIPS_PROTECTED_GOTIDX
:
11976 return "MIPS_PROTECTED_GOT_IDX";
11977 case DT_MIPS_OPTIONS
:
11978 return "MIPS_OPTIONS";
11979 case DT_MIPS_INTERFACE
:
11980 return "MIPS_INTERFACE";
11981 case DT_MIPS_DYNSTR_ALIGN
:
11982 return "DT_MIPS_DYNSTR_ALIGN";
11983 case DT_MIPS_INTERFACE_SIZE
:
11984 return "DT_MIPS_INTERFACE_SIZE";
11985 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
11986 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
11987 case DT_MIPS_PERF_SUFFIX
:
11988 return "DT_MIPS_PERF_SUFFIX";
11989 case DT_MIPS_COMPACT_SIZE
:
11990 return "DT_MIPS_COMPACT_SIZE";
11991 case DT_MIPS_GP_VALUE
:
11992 return "DT_MIPS_GP_VALUE";
11993 case DT_MIPS_AUX_DYNAMIC
:
11994 return "DT_MIPS_AUX_DYNAMIC";
11999 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
12003 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
12005 /* Print normal ELF private data. */
12006 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
12008 /* xgettext:c-format */
12009 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
12011 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
12012 fprintf (file
, _(" [abi=O32]"));
12013 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
12014 fprintf (file
, _(" [abi=O64]"));
12015 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
12016 fprintf (file
, _(" [abi=EABI32]"));
12017 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
12018 fprintf (file
, _(" [abi=EABI64]"));
12019 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
12020 fprintf (file
, _(" [abi unknown]"));
12021 else if (ABI_N32_P (abfd
))
12022 fprintf (file
, _(" [abi=N32]"));
12023 else if (ABI_64_P (abfd
))
12024 fprintf (file
, _(" [abi=64]"));
12026 fprintf (file
, _(" [no abi set]"));
12028 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
12029 fprintf (file
, " [mips1]");
12030 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
12031 fprintf (file
, " [mips2]");
12032 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
12033 fprintf (file
, " [mips3]");
12034 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
12035 fprintf (file
, " [mips4]");
12036 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
12037 fprintf (file
, " [mips5]");
12038 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
12039 fprintf (file
, " [mips32]");
12040 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
12041 fprintf (file
, " [mips64]");
12042 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
12043 fprintf (file
, " [mips32r2]");
12044 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
12045 fprintf (file
, " [mips64r2]");
12047 fprintf (file
, _(" [unknown ISA]"));
12049 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
12050 fprintf (file
, " [mdmx]");
12052 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
12053 fprintf (file
, " [mips16]");
12055 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
12056 fprintf (file
, " [32bitmode]");
12058 fprintf (file
, _(" [not 32bitmode]"));
12060 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
12061 fprintf (file
, " [noreorder]");
12063 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
12064 fprintf (file
, " [PIC]");
12066 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
12067 fprintf (file
, " [CPIC]");
12069 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
12070 fprintf (file
, " [XGOT]");
12072 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
12073 fprintf (file
, " [UCODE]");
12075 fputc ('\n', file
);
12080 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
12082 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12083 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12084 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
12085 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12086 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12087 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
12088 { NULL
, 0, 0, 0, 0 }
12091 /* Merge non visibility st_other attributes. Ensure that the
12092 STO_OPTIONAL flag is copied into h->other, even if this is not a
12093 definiton of the symbol. */
12095 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
12096 const Elf_Internal_Sym
*isym
,
12097 bfd_boolean definition
,
12098 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
12100 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
12102 unsigned char other
;
12104 other
= (definition
? isym
->st_other
: h
->other
);
12105 other
&= ~ELF_ST_VISIBILITY (-1);
12106 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
12110 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
12111 h
->other
|= STO_OPTIONAL
;
12114 /* Decide whether an undefined symbol is special and can be ignored.
12115 This is the case for OPTIONAL symbols on IRIX. */
12117 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
12119 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
12123 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
12125 return (sym
->st_shndx
== SHN_COMMON
12126 || sym
->st_shndx
== SHN_MIPS_ACOMMON
12127 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);