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 there is a stub that 32 bit functions should use to call this
279 16 bit function, this points to the section containing the stub. */
282 /* If there is a stub that 16 bit functions should use to call this
283 32 bit function, this points to the section containing the stub. */
286 /* This is like the call_stub field, but it is used if the function
287 being called returns a floating point value. */
288 asection
*call_fp_stub
;
292 #define GOT_TLS_LDM 2
294 #define GOT_TLS_OFFSET_DONE 0x40
295 #define GOT_TLS_DONE 0x80
296 unsigned char tls_type
;
298 /* This is only used in single-GOT mode; in multi-GOT mode there
299 is one mips_got_entry per GOT entry, so the offset is stored
300 there. In single-GOT mode there may be many mips_got_entry
301 structures all referring to the same GOT slot. It might be
302 possible to use root.got.offset instead, but that field is
303 overloaded already. */
304 bfd_vma tls_got_offset
;
306 /* True if one of the relocations described by possibly_dynamic_relocs
307 is against a readonly section. */
308 unsigned int readonly_reloc
: 1;
310 /* True if we must not create a .MIPS.stubs entry for this symbol.
311 This is set, for example, if there are relocations related to
312 taking the function's address, i.e. any but R_MIPS_CALL*16 ones.
313 See "MIPS ABI Supplement, 3rd Edition", p. 4-20. */
314 unsigned int no_fn_stub
: 1;
316 /* Whether we need the fn_stub; this is true if this symbol appears
317 in any relocs other than a 16 bit call. */
318 unsigned int need_fn_stub
: 1;
320 /* Are we referenced by some kind of relocation? */
321 unsigned int is_relocation_target
: 1;
323 /* Are we referenced by branch relocations? */
324 unsigned int is_branch_target
: 1;
326 /* Does this symbol need a traditional MIPS lazy-binding stub
327 (as opposed to a PLT entry)? */
328 unsigned int needs_lazy_stub
: 1;
331 /* MIPS ELF linker hash table. */
333 struct mips_elf_link_hash_table
335 struct elf_link_hash_table root
;
337 /* We no longer use this. */
338 /* String section indices for the dynamic section symbols. */
339 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
341 /* The number of .rtproc entries. */
342 bfd_size_type procedure_count
;
343 /* The size of the .compact_rel section (if SGI_COMPAT). */
344 bfd_size_type compact_rel_size
;
345 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
346 entry is set to the address of __rld_obj_head as in IRIX5. */
347 bfd_boolean use_rld_obj_head
;
348 /* This is the value of the __rld_map or __rld_obj_head symbol. */
350 /* This is set if we see any mips16 stub sections. */
351 bfd_boolean mips16_stubs_seen
;
352 /* True if we're generating code for VxWorks. */
353 bfd_boolean is_vxworks
;
354 /* True if we already reported the small-data section overflow. */
355 bfd_boolean small_data_overflow_reported
;
356 /* Shortcuts to some dynamic sections, or NULL if they are not
366 /* The master GOT information. */
367 struct mips_got_info
*got_info
;
368 /* The size of the PLT header in bytes (VxWorks only). */
369 bfd_vma plt_header_size
;
370 /* The size of a PLT entry in bytes (VxWorks only). */
371 bfd_vma plt_entry_size
;
372 /* The number of functions that need a lazy-binding stub. */
373 bfd_vma lazy_stub_count
;
374 /* The size of a function stub entry in bytes. */
375 bfd_vma function_stub_size
;
378 #define TLS_RELOC_P(r_type) \
379 (r_type == R_MIPS_TLS_DTPMOD32 \
380 || r_type == R_MIPS_TLS_DTPMOD64 \
381 || r_type == R_MIPS_TLS_DTPREL32 \
382 || r_type == R_MIPS_TLS_DTPREL64 \
383 || r_type == R_MIPS_TLS_GD \
384 || r_type == R_MIPS_TLS_LDM \
385 || r_type == R_MIPS_TLS_DTPREL_HI16 \
386 || r_type == R_MIPS_TLS_DTPREL_LO16 \
387 || r_type == R_MIPS_TLS_GOTTPREL \
388 || r_type == R_MIPS_TLS_TPREL32 \
389 || r_type == R_MIPS_TLS_TPREL64 \
390 || r_type == R_MIPS_TLS_TPREL_HI16 \
391 || r_type == R_MIPS_TLS_TPREL_LO16)
393 /* Structure used to pass information to mips_elf_output_extsym. */
398 struct bfd_link_info
*info
;
399 struct ecoff_debug_info
*debug
;
400 const struct ecoff_debug_swap
*swap
;
404 /* The names of the runtime procedure table symbols used on IRIX5. */
406 static const char * const mips_elf_dynsym_rtproc_names
[] =
409 "_procedure_string_table",
410 "_procedure_table_size",
414 /* These structures are used to generate the .compact_rel section on
419 unsigned long id1
; /* Always one? */
420 unsigned long num
; /* Number of compact relocation entries. */
421 unsigned long id2
; /* Always two? */
422 unsigned long offset
; /* The file offset of the first relocation. */
423 unsigned long reserved0
; /* Zero? */
424 unsigned long reserved1
; /* Zero? */
433 bfd_byte reserved0
[4];
434 bfd_byte reserved1
[4];
435 } Elf32_External_compact_rel
;
439 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
440 unsigned int rtype
: 4; /* Relocation types. See below. */
441 unsigned int dist2to
: 8;
442 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
443 unsigned long konst
; /* KONST field. See below. */
444 unsigned long vaddr
; /* VADDR to be relocated. */
449 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
450 unsigned int rtype
: 4; /* Relocation types. See below. */
451 unsigned int dist2to
: 8;
452 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
453 unsigned long konst
; /* KONST field. See below. */
461 } Elf32_External_crinfo
;
467 } Elf32_External_crinfo2
;
469 /* These are the constants used to swap the bitfields in a crinfo. */
471 #define CRINFO_CTYPE (0x1)
472 #define CRINFO_CTYPE_SH (31)
473 #define CRINFO_RTYPE (0xf)
474 #define CRINFO_RTYPE_SH (27)
475 #define CRINFO_DIST2TO (0xff)
476 #define CRINFO_DIST2TO_SH (19)
477 #define CRINFO_RELVADDR (0x7ffff)
478 #define CRINFO_RELVADDR_SH (0)
480 /* A compact relocation info has long (3 words) or short (2 words)
481 formats. A short format doesn't have VADDR field and relvaddr
482 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
483 #define CRF_MIPS_LONG 1
484 #define CRF_MIPS_SHORT 0
486 /* There are 4 types of compact relocation at least. The value KONST
487 has different meaning for each type:
490 CT_MIPS_REL32 Address in data
491 CT_MIPS_WORD Address in word (XXX)
492 CT_MIPS_GPHI_LO GP - vaddr
493 CT_MIPS_JMPAD Address to jump
496 #define CRT_MIPS_REL32 0xa
497 #define CRT_MIPS_WORD 0xb
498 #define CRT_MIPS_GPHI_LO 0xc
499 #define CRT_MIPS_JMPAD 0xd
501 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
502 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
503 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
504 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
506 /* The structure of the runtime procedure descriptor created by the
507 loader for use by the static exception system. */
509 typedef struct runtime_pdr
{
510 bfd_vma adr
; /* Memory address of start of procedure. */
511 long regmask
; /* Save register mask. */
512 long regoffset
; /* Save register offset. */
513 long fregmask
; /* Save floating point register mask. */
514 long fregoffset
; /* Save floating point register offset. */
515 long frameoffset
; /* Frame size. */
516 short framereg
; /* Frame pointer register. */
517 short pcreg
; /* Offset or reg of return pc. */
518 long irpss
; /* Index into the runtime string table. */
520 struct exception_info
*exception_info
;/* Pointer to exception array. */
522 #define cbRPDR sizeof (RPDR)
523 #define rpdNil ((pRPDR) 0)
525 static struct mips_got_entry
*mips_elf_create_local_got_entry
526 (bfd
*, struct bfd_link_info
*, bfd
*, bfd_vma
, unsigned long,
527 struct mips_elf_link_hash_entry
*, int);
528 static bfd_boolean mips_elf_sort_hash_table_f
529 (struct mips_elf_link_hash_entry
*, void *);
530 static bfd_vma mips_elf_high
532 static bfd_boolean mips_elf_create_dynamic_relocation
533 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
534 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
535 bfd_vma
*, asection
*);
536 static hashval_t mips_elf_got_entry_hash
538 static bfd_vma mips_elf_adjust_gp
539 (bfd
*, struct mips_got_info
*, bfd
*);
540 static struct mips_got_info
*mips_elf_got_for_ibfd
541 (struct mips_got_info
*, bfd
*);
543 /* This will be used when we sort the dynamic relocation records. */
544 static bfd
*reldyn_sorting_bfd
;
546 /* Nonzero if ABFD is using the N32 ABI. */
547 #define ABI_N32_P(abfd) \
548 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
550 /* Nonzero if ABFD is using the N64 ABI. */
551 #define ABI_64_P(abfd) \
552 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
554 /* Nonzero if ABFD is using NewABI conventions. */
555 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
557 /* The IRIX compatibility level we are striving for. */
558 #define IRIX_COMPAT(abfd) \
559 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
561 /* Whether we are trying to be compatible with IRIX at all. */
562 #define SGI_COMPAT(abfd) \
563 (IRIX_COMPAT (abfd) != ict_none)
565 /* The name of the options section. */
566 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
567 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
569 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
570 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
571 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
572 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
574 /* Whether the section is readonly. */
575 #define MIPS_ELF_READONLY_SECTION(sec) \
576 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
577 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
579 /* The name of the stub section. */
580 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
582 /* The size of an external REL relocation. */
583 #define MIPS_ELF_REL_SIZE(abfd) \
584 (get_elf_backend_data (abfd)->s->sizeof_rel)
586 /* The size of an external RELA relocation. */
587 #define MIPS_ELF_RELA_SIZE(abfd) \
588 (get_elf_backend_data (abfd)->s->sizeof_rela)
590 /* The size of an external dynamic table entry. */
591 #define MIPS_ELF_DYN_SIZE(abfd) \
592 (get_elf_backend_data (abfd)->s->sizeof_dyn)
594 /* The size of a GOT entry. */
595 #define MIPS_ELF_GOT_SIZE(abfd) \
596 (get_elf_backend_data (abfd)->s->arch_size / 8)
598 /* The size of a symbol-table entry. */
599 #define MIPS_ELF_SYM_SIZE(abfd) \
600 (get_elf_backend_data (abfd)->s->sizeof_sym)
602 /* The default alignment for sections, as a power of two. */
603 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
604 (get_elf_backend_data (abfd)->s->log_file_align)
606 /* Get word-sized data. */
607 #define MIPS_ELF_GET_WORD(abfd, ptr) \
608 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
610 /* Put out word-sized data. */
611 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
613 ? bfd_put_64 (abfd, val, ptr) \
614 : bfd_put_32 (abfd, val, ptr))
616 /* Add a dynamic symbol table-entry. */
617 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
618 _bfd_elf_add_dynamic_entry (info, tag, val)
620 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
621 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
623 /* Determine whether the internal relocation of index REL_IDX is REL
624 (zero) or RELA (non-zero). The assumption is that, if there are
625 two relocation sections for this section, one of them is REL and
626 the other is RELA. If the index of the relocation we're testing is
627 in range for the first relocation section, check that the external
628 relocation size is that for RELA. It is also assumed that, if
629 rel_idx is not in range for the first section, and this first
630 section contains REL relocs, then the relocation is in the second
631 section, that is RELA. */
632 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
633 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
634 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
635 > (bfd_vma)(rel_idx)) \
636 == (elf_section_data (sec)->rel_hdr.sh_entsize \
637 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
638 : sizeof (Elf32_External_Rela))))
640 /* The name of the dynamic relocation section. */
641 #define MIPS_ELF_REL_DYN_NAME(INFO) \
642 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
644 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
645 from smaller values. Start with zero, widen, *then* decrement. */
646 #define MINUS_ONE (((bfd_vma)0) - 1)
647 #define MINUS_TWO (((bfd_vma)0) - 2)
649 /* The number of local .got entries we reserve. */
650 #define MIPS_RESERVED_GOTNO(INFO) \
651 (mips_elf_hash_table (INFO)->is_vxworks ? 3 : 2)
653 /* The value to write into got[1] for SVR4 targets, to identify it is
654 a GNU object. The dynamic linker can then use got[1] to store the
656 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
657 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
659 /* The offset of $gp from the beginning of the .got section. */
660 #define ELF_MIPS_GP_OFFSET(INFO) \
661 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
663 /* The maximum size of the GOT for it to be addressable using 16-bit
665 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
667 /* Instructions which appear in a stub. */
668 #define STUB_LW(abfd) \
670 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
671 : 0x8f998010)) /* lw t9,0x8010(gp) */
672 #define STUB_MOVE(abfd) \
674 ? 0x03e0782d /* daddu t7,ra */ \
675 : 0x03e07821)) /* addu t7,ra */
676 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
677 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
678 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
679 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
680 #define STUB_LI16S(abfd, VAL) \
682 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
683 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
685 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
686 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
688 /* The name of the dynamic interpreter. This is put in the .interp
691 #define ELF_DYNAMIC_INTERPRETER(abfd) \
692 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
693 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
694 : "/usr/lib/libc.so.1")
697 #define MNAME(bfd,pre,pos) \
698 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
699 #define ELF_R_SYM(bfd, i) \
700 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
701 #define ELF_R_TYPE(bfd, i) \
702 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
703 #define ELF_R_INFO(bfd, s, t) \
704 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
706 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
707 #define ELF_R_SYM(bfd, i) \
709 #define ELF_R_TYPE(bfd, i) \
711 #define ELF_R_INFO(bfd, s, t) \
712 (ELF32_R_INFO (s, t))
715 /* The mips16 compiler uses a couple of special sections to handle
716 floating point arguments.
718 Section names that look like .mips16.fn.FNNAME contain stubs that
719 copy floating point arguments from the fp regs to the gp regs and
720 then jump to FNNAME. If any 32 bit function calls FNNAME, the
721 call should be redirected to the stub instead. If no 32 bit
722 function calls FNNAME, the stub should be discarded. We need to
723 consider any reference to the function, not just a call, because
724 if the address of the function is taken we will need the stub,
725 since the address might be passed to a 32 bit function.
727 Section names that look like .mips16.call.FNNAME contain stubs
728 that copy floating point arguments from the gp regs to the fp
729 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
730 then any 16 bit function that calls FNNAME should be redirected
731 to the stub instead. If FNNAME is not a 32 bit function, the
732 stub should be discarded.
734 .mips16.call.fp.FNNAME sections are similar, but contain stubs
735 which call FNNAME and then copy the return value from the fp regs
736 to the gp regs. These stubs store the return value in $18 while
737 calling FNNAME; any function which might call one of these stubs
738 must arrange to save $18 around the call. (This case is not
739 needed for 32 bit functions that call 16 bit functions, because
740 16 bit functions always return floating point values in both
743 Note that in all cases FNNAME might be defined statically.
744 Therefore, FNNAME is not used literally. Instead, the relocation
745 information will indicate which symbol the section is for.
747 We record any stubs that we find in the symbol table. */
749 #define FN_STUB ".mips16.fn."
750 #define CALL_STUB ".mips16.call."
751 #define CALL_FP_STUB ".mips16.call.fp."
753 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
754 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
755 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
757 /* The format of the first PLT entry in a VxWorks executable. */
758 static const bfd_vma mips_vxworks_exec_plt0_entry
[] = {
759 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
760 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
761 0x8f390008, /* lw t9, 8(t9) */
762 0x00000000, /* nop */
763 0x03200008, /* jr t9 */
767 /* The format of subsequent PLT entries. */
768 static const bfd_vma mips_vxworks_exec_plt_entry
[] = {
769 0x10000000, /* b .PLT_resolver */
770 0x24180000, /* li t8, <pltindex> */
771 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
772 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
773 0x8f390000, /* lw t9, 0(t9) */
774 0x00000000, /* nop */
775 0x03200008, /* jr t9 */
779 /* The format of the first PLT entry in a VxWorks shared object. */
780 static const bfd_vma mips_vxworks_shared_plt0_entry
[] = {
781 0x8f990008, /* lw t9, 8(gp) */
782 0x00000000, /* nop */
783 0x03200008, /* jr t9 */
784 0x00000000, /* nop */
785 0x00000000, /* nop */
789 /* The format of subsequent PLT entries. */
790 static const bfd_vma mips_vxworks_shared_plt_entry
[] = {
791 0x10000000, /* b .PLT_resolver */
792 0x24180000 /* li t8, <pltindex> */
795 /* Look up an entry in a MIPS ELF linker hash table. */
797 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
798 ((struct mips_elf_link_hash_entry *) \
799 elf_link_hash_lookup (&(table)->root, (string), (create), \
802 /* Traverse a MIPS ELF linker hash table. */
804 #define mips_elf_link_hash_traverse(table, func, info) \
805 (elf_link_hash_traverse \
807 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
810 /* Get the MIPS ELF linker hash table from a link_info structure. */
812 #define mips_elf_hash_table(p) \
813 ((struct mips_elf_link_hash_table *) ((p)->hash))
815 /* Find the base offsets for thread-local storage in this object,
816 for GD/LD and IE/LE respectively. */
818 #define TP_OFFSET 0x7000
819 #define DTP_OFFSET 0x8000
822 dtprel_base (struct bfd_link_info
*info
)
824 /* If tls_sec is NULL, we should have signalled an error already. */
825 if (elf_hash_table (info
)->tls_sec
== NULL
)
827 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
831 tprel_base (struct bfd_link_info
*info
)
833 /* If tls_sec is NULL, we should have signalled an error already. */
834 if (elf_hash_table (info
)->tls_sec
== NULL
)
836 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
839 /* Create an entry in a MIPS ELF linker hash table. */
841 static struct bfd_hash_entry
*
842 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
843 struct bfd_hash_table
*table
, const char *string
)
845 struct mips_elf_link_hash_entry
*ret
=
846 (struct mips_elf_link_hash_entry
*) entry
;
848 /* Allocate the structure if it has not already been allocated by a
851 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
853 return (struct bfd_hash_entry
*) ret
;
855 /* Call the allocation method of the superclass. */
856 ret
= ((struct mips_elf_link_hash_entry
*)
857 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
861 /* Set local fields. */
862 memset (&ret
->esym
, 0, sizeof (EXTR
));
863 /* We use -2 as a marker to indicate that the information has
864 not been set. -1 means there is no associated ifd. */
866 ret
->possibly_dynamic_relocs
= 0;
868 ret
->call_stub
= NULL
;
869 ret
->call_fp_stub
= NULL
;
870 ret
->tls_type
= GOT_NORMAL
;
871 ret
->readonly_reloc
= FALSE
;
872 ret
->no_fn_stub
= FALSE
;
873 ret
->need_fn_stub
= FALSE
;
874 ret
->is_relocation_target
= FALSE
;
875 ret
->is_branch_target
= FALSE
;
876 ret
->needs_lazy_stub
= FALSE
;
879 return (struct bfd_hash_entry
*) ret
;
883 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
885 if (!sec
->used_by_bfd
)
887 struct _mips_elf_section_data
*sdata
;
888 bfd_size_type amt
= sizeof (*sdata
);
890 sdata
= bfd_zalloc (abfd
, amt
);
893 sec
->used_by_bfd
= sdata
;
896 return _bfd_elf_new_section_hook (abfd
, sec
);
899 /* Read ECOFF debugging information from a .mdebug section into a
900 ecoff_debug_info structure. */
903 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
904 struct ecoff_debug_info
*debug
)
907 const struct ecoff_debug_swap
*swap
;
910 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
911 memset (debug
, 0, sizeof (*debug
));
913 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
914 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
917 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
918 swap
->external_hdr_size
))
921 symhdr
= &debug
->symbolic_header
;
922 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
924 /* The symbolic header contains absolute file offsets and sizes to
926 #define READ(ptr, offset, count, size, type) \
927 if (symhdr->count == 0) \
931 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
932 debug->ptr = bfd_malloc (amt); \
933 if (debug->ptr == NULL) \
935 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
936 || bfd_bread (debug->ptr, amt, abfd) != amt) \
940 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
941 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
942 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
943 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
944 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
945 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
947 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
948 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
949 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
950 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
951 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
961 if (debug
->line
!= NULL
)
963 if (debug
->external_dnr
!= NULL
)
964 free (debug
->external_dnr
);
965 if (debug
->external_pdr
!= NULL
)
966 free (debug
->external_pdr
);
967 if (debug
->external_sym
!= NULL
)
968 free (debug
->external_sym
);
969 if (debug
->external_opt
!= NULL
)
970 free (debug
->external_opt
);
971 if (debug
->external_aux
!= NULL
)
972 free (debug
->external_aux
);
973 if (debug
->ss
!= NULL
)
975 if (debug
->ssext
!= NULL
)
977 if (debug
->external_fdr
!= NULL
)
978 free (debug
->external_fdr
);
979 if (debug
->external_rfd
!= NULL
)
980 free (debug
->external_rfd
);
981 if (debug
->external_ext
!= NULL
)
982 free (debug
->external_ext
);
986 /* Swap RPDR (runtime procedure table entry) for output. */
989 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
991 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
992 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
993 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
994 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
995 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
996 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
998 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
999 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1001 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1004 /* Create a runtime procedure table from the .mdebug section. */
1007 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1008 struct bfd_link_info
*info
, asection
*s
,
1009 struct ecoff_debug_info
*debug
)
1011 const struct ecoff_debug_swap
*swap
;
1012 HDRR
*hdr
= &debug
->symbolic_header
;
1014 struct rpdr_ext
*erp
;
1016 struct pdr_ext
*epdr
;
1017 struct sym_ext
*esym
;
1021 bfd_size_type count
;
1022 unsigned long sindex
;
1026 const char *no_name_func
= _("static procedure (no name)");
1034 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1036 sindex
= strlen (no_name_func
) + 1;
1037 count
= hdr
->ipdMax
;
1040 size
= swap
->external_pdr_size
;
1042 epdr
= bfd_malloc (size
* count
);
1046 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1049 size
= sizeof (RPDR
);
1050 rp
= rpdr
= bfd_malloc (size
* count
);
1054 size
= sizeof (char *);
1055 sv
= bfd_malloc (size
* count
);
1059 count
= hdr
->isymMax
;
1060 size
= swap
->external_sym_size
;
1061 esym
= bfd_malloc (size
* count
);
1065 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1068 count
= hdr
->issMax
;
1069 ss
= bfd_malloc (count
);
1072 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1075 count
= hdr
->ipdMax
;
1076 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1078 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1079 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1080 rp
->adr
= sym
.value
;
1081 rp
->regmask
= pdr
.regmask
;
1082 rp
->regoffset
= pdr
.regoffset
;
1083 rp
->fregmask
= pdr
.fregmask
;
1084 rp
->fregoffset
= pdr
.fregoffset
;
1085 rp
->frameoffset
= pdr
.frameoffset
;
1086 rp
->framereg
= pdr
.framereg
;
1087 rp
->pcreg
= pdr
.pcreg
;
1089 sv
[i
] = ss
+ sym
.iss
;
1090 sindex
+= strlen (sv
[i
]) + 1;
1094 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1095 size
= BFD_ALIGN (size
, 16);
1096 rtproc
= bfd_alloc (abfd
, size
);
1099 mips_elf_hash_table (info
)->procedure_count
= 0;
1103 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1106 memset (erp
, 0, sizeof (struct rpdr_ext
));
1108 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1109 strcpy (str
, no_name_func
);
1110 str
+= strlen (no_name_func
) + 1;
1111 for (i
= 0; i
< count
; i
++)
1113 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1114 strcpy (str
, sv
[i
]);
1115 str
+= strlen (sv
[i
]) + 1;
1117 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1119 /* Set the size and contents of .rtproc section. */
1121 s
->contents
= rtproc
;
1123 /* Skip this section later on (I don't think this currently
1124 matters, but someday it might). */
1125 s
->map_head
.link_order
= NULL
;
1154 /* We're about to redefine H. Create a symbol to represent H's
1155 current value and size, to help make the disassembly easier
1159 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1160 struct mips_elf_link_hash_entry
*h
,
1163 struct bfd_link_hash_entry
*bh
;
1164 struct elf_link_hash_entry
*elfh
;
1169 /* Read the symbol's value. */
1170 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1171 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1172 s
= h
->root
.root
.u
.def
.section
;
1173 value
= h
->root
.root
.u
.def
.value
;
1175 /* Create a new symbol. */
1176 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1178 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1179 BSF_LOCAL
, s
, value
, NULL
,
1183 /* Make it local and copy the other attributes from H. */
1184 elfh
= (struct elf_link_hash_entry
*) bh
;
1185 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1186 elfh
->other
= h
->root
.other
;
1187 elfh
->size
= h
->root
.size
;
1188 elfh
->forced_local
= 1;
1192 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1193 function rather than to a hard-float stub. */
1196 section_allows_mips16_refs_p (asection
*section
)
1200 name
= bfd_get_section_name (section
->owner
, section
);
1201 return (FN_STUB_P (name
)
1202 || CALL_STUB_P (name
)
1203 || CALL_FP_STUB_P (name
)
1204 || strcmp (name
, ".pdr") == 0);
1207 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1208 stub section of some kind. Return the R_SYMNDX of the target
1209 function, or 0 if we can't decide which function that is. */
1211 static unsigned long
1212 mips16_stub_symndx (asection
*sec
, const Elf_Internal_Rela
*relocs
,
1213 const Elf_Internal_Rela
*relend
)
1215 const Elf_Internal_Rela
*rel
;
1217 /* Trust the first R_MIPS_NONE relocation, if any. */
1218 for (rel
= relocs
; rel
< relend
; rel
++)
1219 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1220 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1222 /* Otherwise trust the first relocation, whatever its kind. This is
1223 the traditional behavior. */
1224 if (relocs
< relend
)
1225 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1230 /* Check the mips16 stubs for a particular symbol, and see if we can
1234 mips_elf_check_mips16_stubs (struct mips_elf_link_hash_entry
*h
, void *data
)
1236 struct bfd_link_info
*info
;
1238 info
= (struct bfd_link_info
*) data
;
1239 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1240 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1242 /* Dynamic symbols must use the standard call interface, in case other
1243 objects try to call them. */
1244 if (h
->fn_stub
!= NULL
1245 && h
->root
.dynindx
!= -1)
1247 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1248 h
->need_fn_stub
= TRUE
;
1251 if (h
->fn_stub
!= NULL
1252 && ! h
->need_fn_stub
)
1254 /* We don't need the fn_stub; the only references to this symbol
1255 are 16 bit calls. Clobber the size to 0 to prevent it from
1256 being included in the link. */
1257 h
->fn_stub
->size
= 0;
1258 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1259 h
->fn_stub
->reloc_count
= 0;
1260 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1263 if (h
->call_stub
!= NULL
1264 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1266 /* We don't need the call_stub; this is a 16 bit function, so
1267 calls from other 16 bit functions are OK. Clobber the size
1268 to 0 to prevent it from being included in the link. */
1269 h
->call_stub
->size
= 0;
1270 h
->call_stub
->flags
&= ~SEC_RELOC
;
1271 h
->call_stub
->reloc_count
= 0;
1272 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1275 if (h
->call_fp_stub
!= NULL
1276 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1278 /* We don't need the call_stub; this is a 16 bit function, so
1279 calls from other 16 bit functions are OK. Clobber the size
1280 to 0 to prevent it from being included in the link. */
1281 h
->call_fp_stub
->size
= 0;
1282 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1283 h
->call_fp_stub
->reloc_count
= 0;
1284 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1290 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1291 Most mips16 instructions are 16 bits, but these instructions
1294 The format of these instructions is:
1296 +--------------+--------------------------------+
1297 | JALX | X| Imm 20:16 | Imm 25:21 |
1298 +--------------+--------------------------------+
1300 +-----------------------------------------------+
1302 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1303 Note that the immediate value in the first word is swapped.
1305 When producing a relocatable object file, R_MIPS16_26 is
1306 handled mostly like R_MIPS_26. In particular, the addend is
1307 stored as a straight 26-bit value in a 32-bit instruction.
1308 (gas makes life simpler for itself by never adjusting a
1309 R_MIPS16_26 reloc to be against a section, so the addend is
1310 always zero). However, the 32 bit instruction is stored as 2
1311 16-bit values, rather than a single 32-bit value. In a
1312 big-endian file, the result is the same; in a little-endian
1313 file, the two 16-bit halves of the 32 bit value are swapped.
1314 This is so that a disassembler can recognize the jal
1317 When doing a final link, R_MIPS16_26 is treated as a 32 bit
1318 instruction stored as two 16-bit values. The addend A is the
1319 contents of the targ26 field. The calculation is the same as
1320 R_MIPS_26. When storing the calculated value, reorder the
1321 immediate value as shown above, and don't forget to store the
1322 value as two 16-bit values.
1324 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
1328 +--------+----------------------+
1332 +--------+----------------------+
1335 +----------+------+-------------+
1339 +----------+--------------------+
1340 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
1341 ((sub1 << 16) | sub2)).
1343 When producing a relocatable object file, the calculation is
1344 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1345 When producing a fully linked file, the calculation is
1346 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1347 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
1349 The table below lists the other MIPS16 instruction relocations.
1350 Each one is calculated in the same way as the non-MIPS16 relocation
1351 given on the right, but using the extended MIPS16 layout of 16-bit
1354 R_MIPS16_GPREL R_MIPS_GPREL16
1355 R_MIPS16_GOT16 R_MIPS_GOT16
1356 R_MIPS16_CALL16 R_MIPS_CALL16
1357 R_MIPS16_HI16 R_MIPS_HI16
1358 R_MIPS16_LO16 R_MIPS_LO16
1360 A typical instruction will have a format like this:
1362 +--------------+--------------------------------+
1363 | EXTEND | Imm 10:5 | Imm 15:11 |
1364 +--------------+--------------------------------+
1365 | Major | rx | ry | Imm 4:0 |
1366 +--------------+--------------------------------+
1368 EXTEND is the five bit value 11110. Major is the instruction
1371 All we need to do here is shuffle the bits appropriately.
1372 As above, the two 16-bit halves must be swapped on a
1373 little-endian system. */
1375 static inline bfd_boolean
1376 mips16_reloc_p (int r_type
)
1381 case R_MIPS16_GPREL
:
1382 case R_MIPS16_GOT16
:
1383 case R_MIPS16_CALL16
:
1393 static inline bfd_boolean
1394 got16_reloc_p (int r_type
)
1396 return r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS16_GOT16
;
1399 static inline bfd_boolean
1400 call16_reloc_p (int r_type
)
1402 return r_type
== R_MIPS_CALL16
|| r_type
== R_MIPS16_CALL16
;
1405 static inline bfd_boolean
1406 hi16_reloc_p (int r_type
)
1408 return r_type
== R_MIPS_HI16
|| r_type
== R_MIPS16_HI16
;
1411 static inline bfd_boolean
1412 lo16_reloc_p (int r_type
)
1414 return r_type
== R_MIPS_LO16
|| r_type
== R_MIPS16_LO16
;
1417 static inline bfd_boolean
1418 mips16_call_reloc_p (int r_type
)
1420 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
1424 _bfd_mips16_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
1425 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1427 bfd_vma extend
, insn
, val
;
1429 if (!mips16_reloc_p (r_type
))
1432 /* Pick up the mips16 extend instruction and the real instruction. */
1433 extend
= bfd_get_16 (abfd
, data
);
1434 insn
= bfd_get_16 (abfd
, data
+ 2);
1435 if (r_type
== R_MIPS16_26
)
1438 val
= ((extend
& 0xfc00) << 16) | ((extend
& 0x3e0) << 11)
1439 | ((extend
& 0x1f) << 21) | insn
;
1441 val
= extend
<< 16 | insn
;
1444 val
= ((extend
& 0xf800) << 16) | ((insn
& 0xffe0) << 11)
1445 | ((extend
& 0x1f) << 11) | (extend
& 0x7e0) | (insn
& 0x1f);
1446 bfd_put_32 (abfd
, val
, data
);
1450 _bfd_mips16_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
1451 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1453 bfd_vma extend
, insn
, val
;
1455 if (!mips16_reloc_p (r_type
))
1458 val
= bfd_get_32 (abfd
, data
);
1459 if (r_type
== R_MIPS16_26
)
1463 insn
= val
& 0xffff;
1464 extend
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
1465 | ((val
>> 21) & 0x1f);
1469 insn
= val
& 0xffff;
1475 insn
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
1476 extend
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
1478 bfd_put_16 (abfd
, insn
, data
+ 2);
1479 bfd_put_16 (abfd
, extend
, data
);
1482 bfd_reloc_status_type
1483 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1484 arelent
*reloc_entry
, asection
*input_section
,
1485 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1489 bfd_reloc_status_type status
;
1491 if (bfd_is_com_section (symbol
->section
))
1494 relocation
= symbol
->value
;
1496 relocation
+= symbol
->section
->output_section
->vma
;
1497 relocation
+= symbol
->section
->output_offset
;
1499 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1500 return bfd_reloc_outofrange
;
1502 /* Set val to the offset into the section or symbol. */
1503 val
= reloc_entry
->addend
;
1505 _bfd_mips_elf_sign_extend (val
, 16);
1507 /* Adjust val for the final section location and GP value. If we
1508 are producing relocatable output, we don't want to do this for
1509 an external symbol. */
1511 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1512 val
+= relocation
- gp
;
1514 if (reloc_entry
->howto
->partial_inplace
)
1516 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1518 + reloc_entry
->address
);
1519 if (status
!= bfd_reloc_ok
)
1523 reloc_entry
->addend
= val
;
1526 reloc_entry
->address
+= input_section
->output_offset
;
1528 return bfd_reloc_ok
;
1531 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
1532 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
1533 that contains the relocation field and DATA points to the start of
1538 struct mips_hi16
*next
;
1540 asection
*input_section
;
1544 /* FIXME: This should not be a static variable. */
1546 static struct mips_hi16
*mips_hi16_list
;
1548 /* A howto special_function for REL *HI16 relocations. We can only
1549 calculate the correct value once we've seen the partnering
1550 *LO16 relocation, so just save the information for later.
1552 The ABI requires that the *LO16 immediately follow the *HI16.
1553 However, as a GNU extension, we permit an arbitrary number of
1554 *HI16s to be associated with a single *LO16. This significantly
1555 simplies the relocation handling in gcc. */
1557 bfd_reloc_status_type
1558 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1559 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
1560 asection
*input_section
, bfd
*output_bfd
,
1561 char **error_message ATTRIBUTE_UNUSED
)
1563 struct mips_hi16
*n
;
1565 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1566 return bfd_reloc_outofrange
;
1568 n
= bfd_malloc (sizeof *n
);
1570 return bfd_reloc_outofrange
;
1572 n
->next
= mips_hi16_list
;
1574 n
->input_section
= input_section
;
1575 n
->rel
= *reloc_entry
;
1578 if (output_bfd
!= NULL
)
1579 reloc_entry
->address
+= input_section
->output_offset
;
1581 return bfd_reloc_ok
;
1584 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
1585 like any other 16-bit relocation when applied to global symbols, but is
1586 treated in the same as R_MIPS_HI16 when applied to local symbols. */
1588 bfd_reloc_status_type
1589 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1590 void *data
, asection
*input_section
,
1591 bfd
*output_bfd
, char **error_message
)
1593 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
1594 || bfd_is_und_section (bfd_get_section (symbol
))
1595 || bfd_is_com_section (bfd_get_section (symbol
)))
1596 /* The relocation is against a global symbol. */
1597 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1598 input_section
, output_bfd
,
1601 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1602 input_section
, output_bfd
, error_message
);
1605 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
1606 is a straightforward 16 bit inplace relocation, but we must deal with
1607 any partnering high-part relocations as well. */
1609 bfd_reloc_status_type
1610 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1611 void *data
, asection
*input_section
,
1612 bfd
*output_bfd
, char **error_message
)
1615 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1617 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1618 return bfd_reloc_outofrange
;
1620 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1622 vallo
= bfd_get_32 (abfd
, location
);
1623 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1626 while (mips_hi16_list
!= NULL
)
1628 bfd_reloc_status_type ret
;
1629 struct mips_hi16
*hi
;
1631 hi
= mips_hi16_list
;
1633 /* R_MIPS*_GOT16 relocations are something of a special case. We
1634 want to install the addend in the same way as for a R_MIPS*_HI16
1635 relocation (with a rightshift of 16). However, since GOT16
1636 relocations can also be used with global symbols, their howto
1637 has a rightshift of 0. */
1638 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
1639 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
1640 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
1641 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
1643 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
1644 carry or borrow will induce a change of +1 or -1 in the high part. */
1645 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
1647 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
1648 hi
->input_section
, output_bfd
,
1650 if (ret
!= bfd_reloc_ok
)
1653 mips_hi16_list
= hi
->next
;
1657 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1658 input_section
, output_bfd
,
1662 /* A generic howto special_function. This calculates and installs the
1663 relocation itself, thus avoiding the oft-discussed problems in
1664 bfd_perform_relocation and bfd_install_relocation. */
1666 bfd_reloc_status_type
1667 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1668 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
1669 asection
*input_section
, bfd
*output_bfd
,
1670 char **error_message ATTRIBUTE_UNUSED
)
1673 bfd_reloc_status_type status
;
1674 bfd_boolean relocatable
;
1676 relocatable
= (output_bfd
!= NULL
);
1678 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1679 return bfd_reloc_outofrange
;
1681 /* Build up the field adjustment in VAL. */
1683 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1685 /* Either we're calculating the final field value or we have a
1686 relocation against a section symbol. Add in the section's
1687 offset or address. */
1688 val
+= symbol
->section
->output_section
->vma
;
1689 val
+= symbol
->section
->output_offset
;
1694 /* We're calculating the final field value. Add in the symbol's value
1695 and, if pc-relative, subtract the address of the field itself. */
1696 val
+= symbol
->value
;
1697 if (reloc_entry
->howto
->pc_relative
)
1699 val
-= input_section
->output_section
->vma
;
1700 val
-= input_section
->output_offset
;
1701 val
-= reloc_entry
->address
;
1705 /* VAL is now the final adjustment. If we're keeping this relocation
1706 in the output file, and if the relocation uses a separate addend,
1707 we just need to add VAL to that addend. Otherwise we need to add
1708 VAL to the relocation field itself. */
1709 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
1710 reloc_entry
->addend
+= val
;
1713 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1715 /* Add in the separate addend, if any. */
1716 val
+= reloc_entry
->addend
;
1718 /* Add VAL to the relocation field. */
1719 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1721 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1723 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1726 if (status
!= bfd_reloc_ok
)
1731 reloc_entry
->address
+= input_section
->output_offset
;
1733 return bfd_reloc_ok
;
1736 /* Swap an entry in a .gptab section. Note that these routines rely
1737 on the equivalence of the two elements of the union. */
1740 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
1743 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1744 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1748 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
1749 Elf32_External_gptab
*ex
)
1751 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
1752 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
1756 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
1757 Elf32_External_compact_rel
*ex
)
1759 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1760 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1761 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1762 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1763 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1764 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1768 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
1769 Elf32_External_crinfo
*ex
)
1773 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1774 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1775 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1776 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1777 H_PUT_32 (abfd
, l
, ex
->info
);
1778 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1779 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1782 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1783 routines swap this structure in and out. They are used outside of
1784 BFD, so they are globally visible. */
1787 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
1790 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1791 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1792 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1793 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1794 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1795 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1799 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
1800 Elf32_External_RegInfo
*ex
)
1802 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1803 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1804 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1805 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1806 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1807 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1810 /* In the 64 bit ABI, the .MIPS.options section holds register
1811 information in an Elf64_Reginfo structure. These routines swap
1812 them in and out. They are globally visible because they are used
1813 outside of BFD. These routines are here so that gas can call them
1814 without worrying about whether the 64 bit ABI has been included. */
1817 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
1818 Elf64_Internal_RegInfo
*in
)
1820 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1821 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1822 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1823 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1824 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1825 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1826 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1830 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
1831 Elf64_External_RegInfo
*ex
)
1833 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1834 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1835 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1836 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1837 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1838 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1839 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1842 /* Swap in an options header. */
1845 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
1846 Elf_Internal_Options
*in
)
1848 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1849 in
->size
= H_GET_8 (abfd
, ex
->size
);
1850 in
->section
= H_GET_16 (abfd
, ex
->section
);
1851 in
->info
= H_GET_32 (abfd
, ex
->info
);
1854 /* Swap out an options header. */
1857 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
1858 Elf_External_Options
*ex
)
1860 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1861 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1862 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1863 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1866 /* This function is called via qsort() to sort the dynamic relocation
1867 entries by increasing r_symndx value. */
1870 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
1872 Elf_Internal_Rela int_reloc1
;
1873 Elf_Internal_Rela int_reloc2
;
1876 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1877 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1879 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
1883 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
1885 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
1890 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
1893 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
1894 const void *arg2 ATTRIBUTE_UNUSED
)
1897 Elf_Internal_Rela int_reloc1
[3];
1898 Elf_Internal_Rela int_reloc2
[3];
1900 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1901 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
1902 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1903 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
1905 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
1907 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
1910 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
1912 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
1921 /* This routine is used to write out ECOFF debugging external symbol
1922 information. It is called via mips_elf_link_hash_traverse. The
1923 ECOFF external symbol information must match the ELF external
1924 symbol information. Unfortunately, at this point we don't know
1925 whether a symbol is required by reloc information, so the two
1926 tables may wind up being different. We must sort out the external
1927 symbol information before we can set the final size of the .mdebug
1928 section, and we must set the size of the .mdebug section before we
1929 can relocate any sections, and we can't know which symbols are
1930 required by relocation until we relocate the sections.
1931 Fortunately, it is relatively unlikely that any symbol will be
1932 stripped but required by a reloc. In particular, it can not happen
1933 when generating a final executable. */
1936 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
1938 struct extsym_info
*einfo
= data
;
1940 asection
*sec
, *output_section
;
1942 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1943 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1945 if (h
->root
.indx
== -2)
1947 else if ((h
->root
.def_dynamic
1948 || h
->root
.ref_dynamic
1949 || h
->root
.type
== bfd_link_hash_new
)
1950 && !h
->root
.def_regular
1951 && !h
->root
.ref_regular
)
1953 else if (einfo
->info
->strip
== strip_all
1954 || (einfo
->info
->strip
== strip_some
1955 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1956 h
->root
.root
.root
.string
,
1957 FALSE
, FALSE
) == NULL
))
1965 if (h
->esym
.ifd
== -2)
1968 h
->esym
.cobol_main
= 0;
1969 h
->esym
.weakext
= 0;
1970 h
->esym
.reserved
= 0;
1971 h
->esym
.ifd
= ifdNil
;
1972 h
->esym
.asym
.value
= 0;
1973 h
->esym
.asym
.st
= stGlobal
;
1975 if (h
->root
.root
.type
== bfd_link_hash_undefined
1976 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
1980 /* Use undefined class. Also, set class and type for some
1982 name
= h
->root
.root
.root
.string
;
1983 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
1984 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
1986 h
->esym
.asym
.sc
= scData
;
1987 h
->esym
.asym
.st
= stLabel
;
1988 h
->esym
.asym
.value
= 0;
1990 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
1992 h
->esym
.asym
.sc
= scAbs
;
1993 h
->esym
.asym
.st
= stLabel
;
1994 h
->esym
.asym
.value
=
1995 mips_elf_hash_table (einfo
->info
)->procedure_count
;
1997 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
1999 h
->esym
.asym
.sc
= scAbs
;
2000 h
->esym
.asym
.st
= stLabel
;
2001 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2004 h
->esym
.asym
.sc
= scUndefined
;
2006 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2007 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2008 h
->esym
.asym
.sc
= scAbs
;
2013 sec
= h
->root
.root
.u
.def
.section
;
2014 output_section
= sec
->output_section
;
2016 /* When making a shared library and symbol h is the one from
2017 the another shared library, OUTPUT_SECTION may be null. */
2018 if (output_section
== NULL
)
2019 h
->esym
.asym
.sc
= scUndefined
;
2022 name
= bfd_section_name (output_section
->owner
, output_section
);
2024 if (strcmp (name
, ".text") == 0)
2025 h
->esym
.asym
.sc
= scText
;
2026 else if (strcmp (name
, ".data") == 0)
2027 h
->esym
.asym
.sc
= scData
;
2028 else if (strcmp (name
, ".sdata") == 0)
2029 h
->esym
.asym
.sc
= scSData
;
2030 else if (strcmp (name
, ".rodata") == 0
2031 || strcmp (name
, ".rdata") == 0)
2032 h
->esym
.asym
.sc
= scRData
;
2033 else if (strcmp (name
, ".bss") == 0)
2034 h
->esym
.asym
.sc
= scBss
;
2035 else if (strcmp (name
, ".sbss") == 0)
2036 h
->esym
.asym
.sc
= scSBss
;
2037 else if (strcmp (name
, ".init") == 0)
2038 h
->esym
.asym
.sc
= scInit
;
2039 else if (strcmp (name
, ".fini") == 0)
2040 h
->esym
.asym
.sc
= scFini
;
2042 h
->esym
.asym
.sc
= scAbs
;
2046 h
->esym
.asym
.reserved
= 0;
2047 h
->esym
.asym
.index
= indexNil
;
2050 if (h
->root
.root
.type
== bfd_link_hash_common
)
2051 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2052 else if (h
->root
.root
.type
== bfd_link_hash_defined
2053 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2055 if (h
->esym
.asym
.sc
== scCommon
)
2056 h
->esym
.asym
.sc
= scBss
;
2057 else if (h
->esym
.asym
.sc
== scSCommon
)
2058 h
->esym
.asym
.sc
= scSBss
;
2060 sec
= h
->root
.root
.u
.def
.section
;
2061 output_section
= sec
->output_section
;
2062 if (output_section
!= NULL
)
2063 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2064 + sec
->output_offset
2065 + output_section
->vma
);
2067 h
->esym
.asym
.value
= 0;
2071 struct mips_elf_link_hash_entry
*hd
= h
;
2073 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
2074 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2076 if (hd
->needs_lazy_stub
)
2078 /* Set type and value for a symbol with a function stub. */
2079 h
->esym
.asym
.st
= stProc
;
2080 sec
= hd
->root
.root
.u
.def
.section
;
2082 h
->esym
.asym
.value
= 0;
2085 output_section
= sec
->output_section
;
2086 if (output_section
!= NULL
)
2087 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
2088 + sec
->output_offset
2089 + output_section
->vma
);
2091 h
->esym
.asym
.value
= 0;
2096 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2097 h
->root
.root
.root
.string
,
2100 einfo
->failed
= TRUE
;
2107 /* A comparison routine used to sort .gptab entries. */
2110 gptab_compare (const void *p1
, const void *p2
)
2112 const Elf32_gptab
*a1
= p1
;
2113 const Elf32_gptab
*a2
= p2
;
2115 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
2118 /* Functions to manage the got entry hash table. */
2120 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
2123 static INLINE hashval_t
2124 mips_elf_hash_bfd_vma (bfd_vma addr
)
2127 return addr
+ (addr
>> 32);
2133 /* got_entries only match if they're identical, except for gotidx, so
2134 use all fields to compute the hash, and compare the appropriate
2138 mips_elf_got_entry_hash (const void *entry_
)
2140 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2142 return entry
->symndx
2143 + ((entry
->tls_type
& GOT_TLS_LDM
) << 17)
2144 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
2146 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
2147 : entry
->d
.h
->root
.root
.root
.hash
));
2151 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
2153 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2154 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2156 /* An LDM entry can only match another LDM entry. */
2157 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2160 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
2161 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
2162 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
2163 : e1
->d
.h
== e2
->d
.h
);
2166 /* multi_got_entries are still a match in the case of global objects,
2167 even if the input bfd in which they're referenced differs, so the
2168 hash computation and compare functions are adjusted
2172 mips_elf_multi_got_entry_hash (const void *entry_
)
2174 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2176 return entry
->symndx
2178 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
2179 : entry
->symndx
>= 0
2180 ? ((entry
->tls_type
& GOT_TLS_LDM
)
2181 ? (GOT_TLS_LDM
<< 17)
2183 + mips_elf_hash_bfd_vma (entry
->d
.addend
)))
2184 : entry
->d
.h
->root
.root
.root
.hash
);
2188 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
2190 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2191 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2193 /* Any two LDM entries match. */
2194 if (e1
->tls_type
& e2
->tls_type
& GOT_TLS_LDM
)
2197 /* Nothing else matches an LDM entry. */
2198 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2201 return e1
->symndx
== e2
->symndx
2202 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
2203 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
2204 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
2205 : e1
->d
.h
== e2
->d
.h
);
2209 mips_got_page_entry_hash (const void *entry_
)
2211 const struct mips_got_page_entry
*entry
;
2213 entry
= (const struct mips_got_page_entry
*) entry_
;
2214 return entry
->abfd
->id
+ entry
->symndx
;
2218 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
2220 const struct mips_got_page_entry
*entry1
, *entry2
;
2222 entry1
= (const struct mips_got_page_entry
*) entry1_
;
2223 entry2
= (const struct mips_got_page_entry
*) entry2_
;
2224 return entry1
->abfd
== entry2
->abfd
&& entry1
->symndx
== entry2
->symndx
;
2227 /* Return the dynamic relocation section. If it doesn't exist, try to
2228 create a new it if CREATE_P, otherwise return NULL. Also return NULL
2229 if creation fails. */
2232 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
2238 dname
= MIPS_ELF_REL_DYN_NAME (info
);
2239 dynobj
= elf_hash_table (info
)->dynobj
;
2240 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
2241 if (sreloc
== NULL
&& create_p
)
2243 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
2248 | SEC_LINKER_CREATED
2251 || ! bfd_set_section_alignment (dynobj
, sreloc
,
2252 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
2258 /* Returns the GOT section, if it hasn't been excluded. */
2261 mips_elf_got_section (struct bfd_link_info
*info
)
2263 struct mips_elf_link_hash_table
*htab
;
2265 htab
= mips_elf_hash_table (info
);
2266 if (htab
->sgot
== NULL
|| (htab
->sgot
->flags
& SEC_EXCLUDE
) != 0)
2271 /* Count the number of relocations needed for a TLS GOT entry, with
2272 access types from TLS_TYPE, and symbol H (or a local symbol if H
2276 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
2277 struct elf_link_hash_entry
*h
)
2281 bfd_boolean need_relocs
= FALSE
;
2282 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2284 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2285 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
2288 if ((info
->shared
|| indx
!= 0)
2290 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2291 || h
->root
.type
!= bfd_link_hash_undefweak
))
2297 if (tls_type
& GOT_TLS_GD
)
2304 if (tls_type
& GOT_TLS_IE
)
2307 if ((tls_type
& GOT_TLS_LDM
) && info
->shared
)
2313 /* Count the number of TLS relocations required for the GOT entry in
2314 ARG1, if it describes a local symbol. */
2317 mips_elf_count_local_tls_relocs (void **arg1
, void *arg2
)
2319 struct mips_got_entry
*entry
= * (struct mips_got_entry
**) arg1
;
2320 struct mips_elf_count_tls_arg
*arg
= arg2
;
2322 if (entry
->abfd
!= NULL
&& entry
->symndx
!= -1)
2323 arg
->needed
+= mips_tls_got_relocs (arg
->info
, entry
->tls_type
, NULL
);
2328 /* Count the number of TLS GOT entries required for the global (or
2329 forced-local) symbol in ARG1. */
2332 mips_elf_count_global_tls_entries (void *arg1
, void *arg2
)
2334 struct mips_elf_link_hash_entry
*hm
2335 = (struct mips_elf_link_hash_entry
*) arg1
;
2336 struct mips_elf_count_tls_arg
*arg
= arg2
;
2338 if (hm
->tls_type
& GOT_TLS_GD
)
2340 if (hm
->tls_type
& GOT_TLS_IE
)
2346 /* Count the number of TLS relocations required for the global (or
2347 forced-local) symbol in ARG1. */
2350 mips_elf_count_global_tls_relocs (void *arg1
, void *arg2
)
2352 struct mips_elf_link_hash_entry
*hm
2353 = (struct mips_elf_link_hash_entry
*) arg1
;
2354 struct mips_elf_count_tls_arg
*arg
= arg2
;
2356 arg
->needed
+= mips_tls_got_relocs (arg
->info
, hm
->tls_type
, &hm
->root
);
2361 /* Output a simple dynamic relocation into SRELOC. */
2364 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
2370 Elf_Internal_Rela rel
[3];
2372 memset (rel
, 0, sizeof (rel
));
2374 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
2375 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
2377 if (ABI_64_P (output_bfd
))
2379 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2380 (output_bfd
, &rel
[0],
2382 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
2385 bfd_elf32_swap_reloc_out
2386 (output_bfd
, &rel
[0],
2388 + sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
2389 ++sreloc
->reloc_count
;
2392 /* Initialize a set of TLS GOT entries for one symbol. */
2395 mips_elf_initialize_tls_slots (bfd
*abfd
, bfd_vma got_offset
,
2396 unsigned char *tls_type_p
,
2397 struct bfd_link_info
*info
,
2398 struct mips_elf_link_hash_entry
*h
,
2402 asection
*sreloc
, *sgot
;
2403 bfd_vma offset
, offset2
;
2404 bfd_boolean need_relocs
= FALSE
;
2406 sgot
= mips_elf_got_section (info
);
2411 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2413 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
2414 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
2415 indx
= h
->root
.dynindx
;
2418 if (*tls_type_p
& GOT_TLS_DONE
)
2421 if ((info
->shared
|| indx
!= 0)
2423 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
2424 || h
->root
.type
!= bfd_link_hash_undefweak
))
2427 /* MINUS_ONE means the symbol is not defined in this object. It may not
2428 be defined at all; assume that the value doesn't matter in that
2429 case. Otherwise complain if we would use the value. */
2430 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
2431 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
2433 /* Emit necessary relocations. */
2434 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
2436 /* General Dynamic. */
2437 if (*tls_type_p
& GOT_TLS_GD
)
2439 offset
= got_offset
;
2440 offset2
= offset
+ MIPS_ELF_GOT_SIZE (abfd
);
2444 mips_elf_output_dynamic_relocation
2445 (abfd
, sreloc
, indx
,
2446 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2447 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2450 mips_elf_output_dynamic_relocation
2451 (abfd
, sreloc
, indx
,
2452 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
2453 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset2
);
2455 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2456 sgot
->contents
+ offset2
);
2460 MIPS_ELF_PUT_WORD (abfd
, 1,
2461 sgot
->contents
+ offset
);
2462 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2463 sgot
->contents
+ offset2
);
2466 got_offset
+= 2 * MIPS_ELF_GOT_SIZE (abfd
);
2469 /* Initial Exec model. */
2470 if (*tls_type_p
& GOT_TLS_IE
)
2472 offset
= got_offset
;
2477 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
2478 sgot
->contents
+ offset
);
2480 MIPS_ELF_PUT_WORD (abfd
, 0,
2481 sgot
->contents
+ offset
);
2483 mips_elf_output_dynamic_relocation
2484 (abfd
, sreloc
, indx
,
2485 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
2486 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2489 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
2490 sgot
->contents
+ offset
);
2493 if (*tls_type_p
& GOT_TLS_LDM
)
2495 /* The initial offset is zero, and the LD offsets will include the
2496 bias by DTP_OFFSET. */
2497 MIPS_ELF_PUT_WORD (abfd
, 0,
2498 sgot
->contents
+ got_offset
2499 + MIPS_ELF_GOT_SIZE (abfd
));
2502 MIPS_ELF_PUT_WORD (abfd
, 1,
2503 sgot
->contents
+ got_offset
);
2505 mips_elf_output_dynamic_relocation
2506 (abfd
, sreloc
, indx
,
2507 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2508 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
2511 *tls_type_p
|= GOT_TLS_DONE
;
2514 /* Return the GOT index to use for a relocation of type R_TYPE against
2515 a symbol accessed using TLS_TYPE models. The GOT entries for this
2516 symbol in this GOT start at GOT_INDEX. This function initializes the
2517 GOT entries and corresponding relocations. */
2520 mips_tls_got_index (bfd
*abfd
, bfd_vma got_index
, unsigned char *tls_type
,
2521 int r_type
, struct bfd_link_info
*info
,
2522 struct mips_elf_link_hash_entry
*h
, bfd_vma symbol
)
2524 BFD_ASSERT (r_type
== R_MIPS_TLS_GOTTPREL
|| r_type
== R_MIPS_TLS_GD
2525 || r_type
== R_MIPS_TLS_LDM
);
2527 mips_elf_initialize_tls_slots (abfd
, got_index
, tls_type
, info
, h
, symbol
);
2529 if (r_type
== R_MIPS_TLS_GOTTPREL
)
2531 BFD_ASSERT (*tls_type
& GOT_TLS_IE
);
2532 if (*tls_type
& GOT_TLS_GD
)
2533 return got_index
+ 2 * MIPS_ELF_GOT_SIZE (abfd
);
2538 if (r_type
== R_MIPS_TLS_GD
)
2540 BFD_ASSERT (*tls_type
& GOT_TLS_GD
);
2544 if (r_type
== R_MIPS_TLS_LDM
)
2546 BFD_ASSERT (*tls_type
& GOT_TLS_LDM
);
2553 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
2554 for global symbol H. .got.plt comes before the GOT, so the offset
2555 will be negative. */
2558 mips_elf_gotplt_index (struct bfd_link_info
*info
,
2559 struct elf_link_hash_entry
*h
)
2561 bfd_vma plt_index
, got_address
, got_value
;
2562 struct mips_elf_link_hash_table
*htab
;
2564 htab
= mips_elf_hash_table (info
);
2565 BFD_ASSERT (h
->plt
.offset
!= (bfd_vma
) -1);
2567 /* Calculate the index of the symbol's PLT entry. */
2568 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
2570 /* Calculate the address of the associated .got.plt entry. */
2571 got_address
= (htab
->sgotplt
->output_section
->vma
2572 + htab
->sgotplt
->output_offset
2575 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
2576 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
2577 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
2578 + htab
->root
.hgot
->root
.u
.def
.value
);
2580 return got_address
- got_value
;
2583 /* Return the GOT offset for address VALUE. If there is not yet a GOT
2584 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
2585 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
2586 offset can be found. */
2589 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2590 bfd_vma value
, unsigned long r_symndx
,
2591 struct mips_elf_link_hash_entry
*h
, int r_type
)
2593 struct mips_elf_link_hash_table
*htab
;
2594 struct mips_got_entry
*entry
;
2596 htab
= mips_elf_hash_table (info
);
2597 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
2598 r_symndx
, h
, r_type
);
2602 if (TLS_RELOC_P (r_type
))
2604 if (entry
->symndx
== -1 && htab
->got_info
->next
== NULL
)
2605 /* A type (3) entry in the single-GOT case. We use the symbol's
2606 hash table entry to track the index. */
2607 return mips_tls_got_index (abfd
, h
->tls_got_offset
, &h
->tls_type
,
2608 r_type
, info
, h
, value
);
2610 return mips_tls_got_index (abfd
, entry
->gotidx
, &entry
->tls_type
,
2611 r_type
, info
, h
, value
);
2614 return entry
->gotidx
;
2617 /* Returns the GOT index for the global symbol indicated by H. */
2620 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
,
2621 int r_type
, struct bfd_link_info
*info
)
2623 struct mips_elf_link_hash_table
*htab
;
2625 struct mips_got_info
*g
, *gg
;
2626 long global_got_dynindx
= 0;
2628 htab
= mips_elf_hash_table (info
);
2629 gg
= g
= htab
->got_info
;
2630 if (g
->bfd2got
&& ibfd
)
2632 struct mips_got_entry e
, *p
;
2634 BFD_ASSERT (h
->dynindx
>= 0);
2636 g
= mips_elf_got_for_ibfd (g
, ibfd
);
2637 if (g
->next
!= gg
|| TLS_RELOC_P (r_type
))
2641 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
2644 p
= htab_find (g
->got_entries
, &e
);
2646 BFD_ASSERT (p
->gotidx
> 0);
2648 if (TLS_RELOC_P (r_type
))
2650 bfd_vma value
= MINUS_ONE
;
2651 if ((h
->root
.type
== bfd_link_hash_defined
2652 || h
->root
.type
== bfd_link_hash_defweak
)
2653 && h
->root
.u
.def
.section
->output_section
)
2654 value
= (h
->root
.u
.def
.value
2655 + h
->root
.u
.def
.section
->output_offset
2656 + h
->root
.u
.def
.section
->output_section
->vma
);
2658 return mips_tls_got_index (abfd
, p
->gotidx
, &p
->tls_type
, r_type
,
2659 info
, e
.d
.h
, value
);
2666 if (gg
->global_gotsym
!= NULL
)
2667 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
2669 if (TLS_RELOC_P (r_type
))
2671 struct mips_elf_link_hash_entry
*hm
2672 = (struct mips_elf_link_hash_entry
*) h
;
2673 bfd_vma value
= MINUS_ONE
;
2675 if ((h
->root
.type
== bfd_link_hash_defined
2676 || h
->root
.type
== bfd_link_hash_defweak
)
2677 && h
->root
.u
.def
.section
->output_section
)
2678 value
= (h
->root
.u
.def
.value
2679 + h
->root
.u
.def
.section
->output_offset
2680 + h
->root
.u
.def
.section
->output_section
->vma
);
2682 index
= mips_tls_got_index (abfd
, hm
->tls_got_offset
, &hm
->tls_type
,
2683 r_type
, info
, hm
, value
);
2687 /* Once we determine the global GOT entry with the lowest dynamic
2688 symbol table index, we must put all dynamic symbols with greater
2689 indices into the GOT. That makes it easy to calculate the GOT
2691 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
2692 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
2693 * MIPS_ELF_GOT_SIZE (abfd
));
2695 BFD_ASSERT (index
< htab
->sgot
->size
);
2700 /* Find a GOT page entry that points to within 32KB of VALUE. These
2701 entries are supposed to be placed at small offsets in the GOT, i.e.,
2702 within 32KB of GP. Return the index of the GOT entry, or -1 if no
2703 entry could be created. If OFFSETP is nonnull, use it to return the
2704 offset of the GOT entry from VALUE. */
2707 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2708 bfd_vma value
, bfd_vma
*offsetp
)
2710 bfd_vma page
, index
;
2711 struct mips_got_entry
*entry
;
2713 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
2714 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
2715 NULL
, R_MIPS_GOT_PAGE
);
2720 index
= entry
->gotidx
;
2723 *offsetp
= value
- entry
->d
.address
;
2728 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
2729 EXTERNAL is true if the relocation was against a global symbol
2730 that has been forced local. */
2733 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2734 bfd_vma value
, bfd_boolean external
)
2736 struct mips_got_entry
*entry
;
2738 /* GOT16 relocations against local symbols are followed by a LO16
2739 relocation; those against global symbols are not. Thus if the
2740 symbol was originally local, the GOT16 relocation should load the
2741 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
2743 value
= mips_elf_high (value
) << 16;
2745 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
2746 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
2747 same in all cases. */
2748 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
2749 NULL
, R_MIPS_GOT16
);
2751 return entry
->gotidx
;
2756 /* Returns the offset for the entry at the INDEXth position
2760 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
2761 bfd
*input_bfd
, bfd_vma index
)
2763 struct mips_elf_link_hash_table
*htab
;
2767 htab
= mips_elf_hash_table (info
);
2769 gp
= _bfd_get_gp_value (output_bfd
)
2770 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
2772 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
2775 /* Create and return a local GOT entry for VALUE, which was calculated
2776 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
2777 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
2780 static struct mips_got_entry
*
2781 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
2782 bfd
*ibfd
, bfd_vma value
,
2783 unsigned long r_symndx
,
2784 struct mips_elf_link_hash_entry
*h
,
2787 struct mips_got_entry entry
, **loc
;
2788 struct mips_got_info
*g
;
2789 struct mips_elf_link_hash_table
*htab
;
2791 htab
= mips_elf_hash_table (info
);
2795 entry
.d
.address
= value
;
2798 g
= mips_elf_got_for_ibfd (htab
->got_info
, ibfd
);
2801 g
= mips_elf_got_for_ibfd (htab
->got_info
, abfd
);
2802 BFD_ASSERT (g
!= NULL
);
2805 /* We might have a symbol, H, if it has been forced local. Use the
2806 global entry then. It doesn't matter whether an entry is local
2807 or global for TLS, since the dynamic linker does not
2808 automatically relocate TLS GOT entries. */
2809 BFD_ASSERT (h
== NULL
|| h
->root
.forced_local
);
2810 if (TLS_RELOC_P (r_type
))
2812 struct mips_got_entry
*p
;
2815 if (r_type
== R_MIPS_TLS_LDM
)
2817 entry
.tls_type
= GOT_TLS_LDM
;
2823 entry
.symndx
= r_symndx
;
2829 p
= (struct mips_got_entry
*)
2830 htab_find (g
->got_entries
, &entry
);
2836 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
2841 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
2844 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2849 memcpy (*loc
, &entry
, sizeof entry
);
2851 if (g
->assigned_gotno
> g
->local_gotno
)
2853 (*loc
)->gotidx
= -1;
2854 /* We didn't allocate enough space in the GOT. */
2855 (*_bfd_error_handler
)
2856 (_("not enough GOT space for local GOT entries"));
2857 bfd_set_error (bfd_error_bad_value
);
2861 MIPS_ELF_PUT_WORD (abfd
, value
,
2862 (htab
->sgot
->contents
+ entry
.gotidx
));
2864 /* These GOT entries need a dynamic relocation on VxWorks. */
2865 if (htab
->is_vxworks
)
2867 Elf_Internal_Rela outrel
;
2870 bfd_vma got_address
;
2872 s
= mips_elf_rel_dyn_section (info
, FALSE
);
2873 got_address
= (htab
->sgot
->output_section
->vma
2874 + htab
->sgot
->output_offset
2877 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
2878 outrel
.r_offset
= got_address
;
2879 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
2880 outrel
.r_addend
= value
;
2881 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
2887 /* Sort the dynamic symbol table so that symbols that need GOT entries
2888 appear towards the end. This reduces the amount of GOT space
2889 required. MAX_LOCAL is used to set the number of local symbols
2890 known to be in the dynamic symbol table. During
2891 _bfd_mips_elf_size_dynamic_sections, this value is 1. Afterward, the
2892 section symbols are added and the count is higher. */
2895 mips_elf_sort_hash_table (struct bfd_link_info
*info
, unsigned long max_local
)
2897 struct mips_elf_link_hash_table
*htab
;
2898 struct mips_elf_hash_sort_data hsd
;
2899 struct mips_got_info
*g
;
2901 htab
= mips_elf_hash_table (info
);
2905 hsd
.max_unref_got_dynindx
=
2906 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
2907 /* In the multi-got case, assigned_gotno of the master got_info
2908 indicate the number of entries that aren't referenced in the
2909 primary GOT, but that must have entries because there are
2910 dynamic relocations that reference it. Since they aren't
2911 referenced, we move them to the end of the GOT, so that they
2912 don't prevent other entries that are referenced from getting
2913 too large offsets. */
2914 - (g
->next
? g
->assigned_gotno
: 0);
2915 hsd
.max_non_got_dynindx
= max_local
;
2916 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
2917 elf_hash_table (info
)),
2918 mips_elf_sort_hash_table_f
,
2921 /* There should have been enough room in the symbol table to
2922 accommodate both the GOT and non-GOT symbols. */
2923 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
2924 BFD_ASSERT ((unsigned long)hsd
.max_unref_got_dynindx
2925 <= elf_hash_table (info
)->dynsymcount
);
2927 /* Now we know which dynamic symbol has the lowest dynamic symbol
2928 table index in the GOT. */
2929 g
->global_gotsym
= hsd
.low
;
2934 /* If H needs a GOT entry, assign it the highest available dynamic
2935 index. Otherwise, assign it the lowest available dynamic
2939 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
2941 struct mips_elf_hash_sort_data
*hsd
= data
;
2943 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2944 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2946 /* Symbols without dynamic symbol table entries aren't interesting
2948 if (h
->root
.dynindx
== -1)
2951 /* Global symbols that need GOT entries that are not explicitly
2952 referenced are marked with got offset 2. Those that are
2953 referenced get a 1, and those that don't need GOT entries get
2954 -1. Forced local symbols may also be marked with got offset 1,
2955 but are never given global GOT entries. */
2956 if (h
->root
.got
.offset
== 2)
2958 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
2960 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
2961 hsd
->low
= (struct elf_link_hash_entry
*) h
;
2962 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
2964 else if (h
->root
.got
.offset
!= 1 || h
->root
.forced_local
)
2965 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
2968 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
2970 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
2971 hsd
->low
= (struct elf_link_hash_entry
*) h
;
2977 /* If H is a symbol that needs a global GOT entry, but has a dynamic
2978 symbol table index lower than any we've seen to date, record it for
2982 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
2983 bfd
*abfd
, struct bfd_link_info
*info
,
2984 unsigned char tls_flag
)
2986 struct mips_elf_link_hash_table
*htab
;
2987 struct mips_got_entry entry
, **loc
;
2988 struct mips_got_info
*g
;
2990 htab
= mips_elf_hash_table (info
);
2992 /* A global symbol in the GOT must also be in the dynamic symbol
2994 if (h
->dynindx
== -1)
2996 switch (ELF_ST_VISIBILITY (h
->other
))
3000 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
3003 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3007 /* Make sure we have a GOT to put this entry into. */
3009 BFD_ASSERT (g
!= NULL
);
3013 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3016 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3019 /* If we've already marked this entry as needing GOT space, we don't
3020 need to do it again. */
3023 (*loc
)->tls_type
|= tls_flag
;
3027 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3033 entry
.tls_type
= tls_flag
;
3035 memcpy (*loc
, &entry
, sizeof entry
);
3037 if (h
->got
.offset
!= MINUS_ONE
)
3041 /* By setting this to a value other than -1, we are indicating that
3042 there needs to be a GOT entry for H. Avoid using zero, as the
3043 generic ELF copy_indirect_symbol tests for <= 0. */
3049 /* Reserve space in G for a GOT entry containing the value of symbol
3050 SYMNDX in input bfd ABDF, plus ADDEND. */
3053 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
3054 struct bfd_link_info
*info
,
3055 unsigned char tls_flag
)
3057 struct mips_elf_link_hash_table
*htab
;
3058 struct mips_got_info
*g
;
3059 struct mips_got_entry entry
, **loc
;
3061 htab
= mips_elf_hash_table (info
);
3063 BFD_ASSERT (g
!= NULL
);
3066 entry
.symndx
= symndx
;
3067 entry
.d
.addend
= addend
;
3068 entry
.tls_type
= tls_flag
;
3069 loc
= (struct mips_got_entry
**)
3070 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
3074 if (tls_flag
== GOT_TLS_GD
&& !((*loc
)->tls_type
& GOT_TLS_GD
))
3077 (*loc
)->tls_type
|= tls_flag
;
3079 else if (tls_flag
== GOT_TLS_IE
&& !((*loc
)->tls_type
& GOT_TLS_IE
))
3082 (*loc
)->tls_type
|= tls_flag
;
3090 entry
.tls_type
= tls_flag
;
3091 if (tls_flag
== GOT_TLS_IE
)
3093 else if (tls_flag
== GOT_TLS_GD
)
3095 else if (g
->tls_ldm_offset
== MINUS_ONE
)
3097 g
->tls_ldm_offset
= MINUS_TWO
;
3103 entry
.gotidx
= g
->local_gotno
++;
3107 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3112 memcpy (*loc
, &entry
, sizeof entry
);
3117 /* Return the maximum number of GOT page entries required for RANGE. */
3120 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
3122 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
3125 /* Record that ABFD has a page relocation against symbol SYMNDX and
3126 that ADDEND is the addend for that relocation.
3128 This function creates an upper bound on the number of GOT slots
3129 required; no attempt is made to combine references to non-overridable
3130 global symbols across multiple input files. */
3133 mips_elf_record_got_page_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3134 long symndx
, bfd_signed_vma addend
)
3136 struct mips_elf_link_hash_table
*htab
;
3137 struct mips_got_info
*g
;
3138 struct mips_got_page_entry lookup
, *entry
;
3139 struct mips_got_page_range
**range_ptr
, *range
;
3140 bfd_vma old_pages
, new_pages
;
3143 htab
= mips_elf_hash_table (info
);
3145 BFD_ASSERT (g
!= NULL
);
3147 /* Find the mips_got_page_entry hash table entry for this symbol. */
3149 lookup
.symndx
= symndx
;
3150 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
3154 /* Create a mips_got_page_entry if this is the first time we've
3156 entry
= (struct mips_got_page_entry
*) *loc
;
3159 entry
= bfd_alloc (abfd
, sizeof (*entry
));
3164 entry
->symndx
= symndx
;
3165 entry
->ranges
= NULL
;
3166 entry
->num_pages
= 0;
3170 /* Skip over ranges whose maximum extent cannot share a page entry
3172 range_ptr
= &entry
->ranges
;
3173 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
3174 range_ptr
= &(*range_ptr
)->next
;
3176 /* If we scanned to the end of the list, or found a range whose
3177 minimum extent cannot share a page entry with ADDEND, create
3178 a new singleton range. */
3180 if (!range
|| addend
< range
->min_addend
- 0xffff)
3182 range
= bfd_alloc (abfd
, sizeof (*range
));
3186 range
->next
= *range_ptr
;
3187 range
->min_addend
= addend
;
3188 range
->max_addend
= addend
;
3196 /* Remember how many pages the old range contributed. */
3197 old_pages
= mips_elf_pages_for_range (range
);
3199 /* Update the ranges. */
3200 if (addend
< range
->min_addend
)
3201 range
->min_addend
= addend
;
3202 else if (addend
> range
->max_addend
)
3204 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
3206 old_pages
+= mips_elf_pages_for_range (range
->next
);
3207 range
->max_addend
= range
->next
->max_addend
;
3208 range
->next
= range
->next
->next
;
3211 range
->max_addend
= addend
;
3214 /* Record any change in the total estimate. */
3215 new_pages
= mips_elf_pages_for_range (range
);
3216 if (old_pages
!= new_pages
)
3218 entry
->num_pages
+= new_pages
- old_pages
;
3219 g
->page_gotno
+= new_pages
- old_pages
;
3225 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
3228 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
3232 struct mips_elf_link_hash_table
*htab
;
3234 htab
= mips_elf_hash_table (info
);
3235 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3236 BFD_ASSERT (s
!= NULL
);
3238 if (htab
->is_vxworks
)
3239 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
3244 /* Make room for a null element. */
3245 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
3248 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
3252 /* A htab_traverse callback for GOT entries. Set boolean *DATA to true
3253 if the GOT entry is for an indirect or warning symbol. */
3256 mips_elf_check_recreate_got (void **entryp
, void *data
)
3258 struct mips_got_entry
*entry
;
3259 bfd_boolean
*must_recreate
;
3261 entry
= (struct mips_got_entry
*) *entryp
;
3262 must_recreate
= (bfd_boolean
*) data
;
3263 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3265 struct mips_elf_link_hash_entry
*h
;
3268 if (h
->root
.root
.type
== bfd_link_hash_indirect
3269 || h
->root
.root
.type
== bfd_link_hash_warning
)
3271 *must_recreate
= TRUE
;
3278 /* A htab_traverse callback for GOT entries. Add all entries to
3279 hash table *DATA, converting entries for indirect and warning
3280 symbols into entries for the target symbol. Set *DATA to null
3284 mips_elf_recreate_got (void **entryp
, void *data
)
3287 struct mips_got_entry
*entry
;
3290 new_got
= (htab_t
*) data
;
3291 entry
= (struct mips_got_entry
*) *entryp
;
3292 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3294 struct mips_elf_link_hash_entry
*h
;
3297 while (h
->root
.root
.type
== bfd_link_hash_indirect
3298 || h
->root
.root
.type
== bfd_link_hash_warning
)
3299 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3302 slot
= htab_find_slot (*new_got
, entry
, INSERT
);
3315 /* If any entries in G->got_entries are for indirect or warning symbols,
3316 replace them with entries for the target symbol. */
3319 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
3321 bfd_boolean must_recreate
;
3324 must_recreate
= FALSE
;
3325 htab_traverse (g
->got_entries
, mips_elf_check_recreate_got
, &must_recreate
);
3328 new_got
= htab_create (htab_size (g
->got_entries
),
3329 mips_elf_got_entry_hash
,
3330 mips_elf_got_entry_eq
, NULL
);
3331 htab_traverse (g
->got_entries
, mips_elf_recreate_got
, &new_got
);
3332 if (new_got
== NULL
)
3335 /* Each entry in g->got_entries has either been copied to new_got
3336 or freed. Now delete the hash table itself. */
3337 htab_delete (g
->got_entries
);
3338 g
->got_entries
= new_got
;
3343 /* An elf_link_hash_traverse callback for which DATA points to a mips_got_info.
3344 Add each forced-local GOT symbol to DATA's local_gotno field. */
3347 mips_elf_count_forced_local_got_symbols (struct elf_link_hash_entry
*h
,
3350 struct mips_got_info
*g
;
3352 g
= (struct mips_got_info
*) data
;
3353 if (h
->got
.offset
!= MINUS_ONE
3354 && (h
->forced_local
|| h
->dynindx
== -1))
3356 /* We no longer need this entry if it was only used for
3357 relocations; those relocations will be against the
3358 null or section symbol instead of H. */
3359 if (h
->got
.offset
== 2)
3360 h
->got
.offset
= MINUS_ONE
;
3367 /* Compute the hash value of the bfd in a bfd2got hash entry. */
3370 mips_elf_bfd2got_entry_hash (const void *entry_
)
3372 const struct mips_elf_bfd2got_hash
*entry
3373 = (struct mips_elf_bfd2got_hash
*)entry_
;
3375 return entry
->bfd
->id
;
3378 /* Check whether two hash entries have the same bfd. */
3381 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
3383 const struct mips_elf_bfd2got_hash
*e1
3384 = (const struct mips_elf_bfd2got_hash
*)entry1
;
3385 const struct mips_elf_bfd2got_hash
*e2
3386 = (const struct mips_elf_bfd2got_hash
*)entry2
;
3388 return e1
->bfd
== e2
->bfd
;
3391 /* In a multi-got link, determine the GOT to be used for IBFD. G must
3392 be the master GOT data. */
3394 static struct mips_got_info
*
3395 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
3397 struct mips_elf_bfd2got_hash e
, *p
;
3403 p
= htab_find (g
->bfd2got
, &e
);
3404 return p
? p
->g
: NULL
;
3407 /* Use BFD2GOT to find ABFD's got entry, creating one if none exists.
3408 Return NULL if an error occured. */
3410 static struct mips_got_info
*
3411 mips_elf_get_got_for_bfd (struct htab
*bfd2got
, bfd
*output_bfd
,
3414 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
3415 struct mips_got_info
*g
;
3418 bfdgot_entry
.bfd
= input_bfd
;
3419 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
3420 bfdgot
= (struct mips_elf_bfd2got_hash
*) *bfdgotp
;
3424 bfdgot
= ((struct mips_elf_bfd2got_hash
*)
3425 bfd_alloc (output_bfd
, sizeof (struct mips_elf_bfd2got_hash
)));
3431 g
= ((struct mips_got_info
*)
3432 bfd_alloc (output_bfd
, sizeof (struct mips_got_info
)));
3436 bfdgot
->bfd
= input_bfd
;
3439 g
->global_gotsym
= NULL
;
3440 g
->global_gotno
= 0;
3443 g
->assigned_gotno
= -1;
3445 g
->tls_assigned_gotno
= 0;
3446 g
->tls_ldm_offset
= MINUS_ONE
;
3447 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3448 mips_elf_multi_got_entry_eq
, NULL
);
3449 if (g
->got_entries
== NULL
)
3452 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3453 mips_got_page_entry_eq
, NULL
);
3454 if (g
->got_page_entries
== NULL
)
3464 /* A htab_traverse callback for the entries in the master got.
3465 Create one separate got for each bfd that has entries in the global
3466 got, such that we can tell how many local and global entries each
3470 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
3472 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3473 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3474 struct mips_got_info
*g
;
3476 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3483 /* Insert the GOT entry in the bfd's got entry hash table. */
3484 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
3485 if (*entryp
!= NULL
)
3490 if (entry
->tls_type
)
3492 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3494 if (entry
->tls_type
& GOT_TLS_IE
)
3497 else if (entry
->symndx
>= 0 || entry
->d
.h
->root
.forced_local
)
3505 /* A htab_traverse callback for the page entries in the master got.
3506 Associate each page entry with the bfd's got. */
3509 mips_elf_make_got_pages_per_bfd (void **entryp
, void *p
)
3511 struct mips_got_page_entry
*entry
= (struct mips_got_page_entry
*) *entryp
;
3512 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*) p
;
3513 struct mips_got_info
*g
;
3515 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3522 /* Insert the GOT entry in the bfd's got entry hash table. */
3523 entryp
= htab_find_slot (g
->got_page_entries
, entry
, INSERT
);
3524 if (*entryp
!= NULL
)
3528 g
->page_gotno
+= entry
->num_pages
;
3532 /* Consider merging the got described by BFD2GOT with TO, using the
3533 information given by ARG. Return -1 if this would lead to overflow,
3534 1 if they were merged successfully, and 0 if a merge failed due to
3535 lack of memory. (These values are chosen so that nonnegative return
3536 values can be returned by a htab_traverse callback.) */
3539 mips_elf_merge_got_with (struct mips_elf_bfd2got_hash
*bfd2got
,
3540 struct mips_got_info
*to
,
3541 struct mips_elf_got_per_bfd_arg
*arg
)
3543 struct mips_got_info
*from
= bfd2got
->g
;
3544 unsigned int estimate
;
3546 /* Work out how many page entries we would need for the combined GOT. */
3547 estimate
= arg
->max_pages
;
3548 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
3549 estimate
= from
->page_gotno
+ to
->page_gotno
;
3551 /* And conservatively estimate how many local, global and TLS entries
3553 estimate
+= (from
->local_gotno
3554 + from
->global_gotno
3560 /* Bail out if the combined GOT might be too big. */
3561 if (estimate
> arg
->max_count
)
3564 /* Commit to the merge. Record that TO is now the bfd for this got. */
3567 /* Transfer the bfd's got information from FROM to TO. */
3568 htab_traverse (from
->got_entries
, mips_elf_make_got_per_bfd
, arg
);
3569 if (arg
->obfd
== NULL
)
3572 htab_traverse (from
->got_page_entries
, mips_elf_make_got_pages_per_bfd
, arg
);
3573 if (arg
->obfd
== NULL
)
3576 /* We don't have to worry about releasing memory of the actual
3577 got entries, since they're all in the master got_entries hash
3579 htab_delete (from
->got_entries
);
3580 htab_delete (from
->got_page_entries
);
3584 /* Attempt to merge gots of different input bfds. Try to use as much
3585 as possible of the primary got, since it doesn't require explicit
3586 dynamic relocations, but don't use bfds that would reference global
3587 symbols out of the addressable range. Failing the primary got,
3588 attempt to merge with the current got, or finish the current got
3589 and then make make the new got current. */
3592 mips_elf_merge_gots (void **bfd2got_
, void *p
)
3594 struct mips_elf_bfd2got_hash
*bfd2got
3595 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
3596 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3597 struct mips_got_info
*g
;
3598 unsigned int estimate
;
3603 /* Work out the number of page, local and TLS entries. */
3604 estimate
= arg
->max_pages
;
3605 if (estimate
> g
->page_gotno
)
3606 estimate
= g
->page_gotno
;
3607 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
3609 /* We place TLS GOT entries after both locals and globals. The globals
3610 for the primary GOT may overflow the normal GOT size limit, so be
3611 sure not to merge a GOT which requires TLS with the primary GOT in that
3612 case. This doesn't affect non-primary GOTs. */
3613 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
3615 if (estimate
<= arg
->max_count
)
3617 /* If we don't have a primary GOT, use it as
3618 a starting point for the primary GOT. */
3621 arg
->primary
= bfd2got
->g
;
3625 /* Try merging with the primary GOT. */
3626 result
= mips_elf_merge_got_with (bfd2got
, arg
->primary
, arg
);
3631 /* If we can merge with the last-created got, do it. */
3634 result
= mips_elf_merge_got_with (bfd2got
, arg
->current
, arg
);
3639 /* Well, we couldn't merge, so create a new GOT. Don't check if it
3640 fits; if it turns out that it doesn't, we'll get relocation
3641 overflows anyway. */
3642 g
->next
= arg
->current
;
3648 /* Set the TLS GOT index for the GOT entry in ENTRYP. ENTRYP's NEXT field
3649 is null iff there is just a single GOT. */
3652 mips_elf_initialize_tls_index (void **entryp
, void *p
)
3654 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3655 struct mips_got_info
*g
= p
;
3657 unsigned char tls_type
;
3659 /* We're only interested in TLS symbols. */
3660 if (entry
->tls_type
== 0)
3663 next_index
= MIPS_ELF_GOT_SIZE (entry
->abfd
) * (long) g
->tls_assigned_gotno
;
3665 if (entry
->symndx
== -1 && g
->next
== NULL
)
3667 /* A type (3) got entry in the single-GOT case. We use the symbol's
3668 hash table entry to track its index. */
3669 if (entry
->d
.h
->tls_type
& GOT_TLS_OFFSET_DONE
)
3671 entry
->d
.h
->tls_type
|= GOT_TLS_OFFSET_DONE
;
3672 entry
->d
.h
->tls_got_offset
= next_index
;
3673 tls_type
= entry
->d
.h
->tls_type
;
3677 if (entry
->tls_type
& GOT_TLS_LDM
)
3679 /* There are separate mips_got_entry objects for each input bfd
3680 that requires an LDM entry. Make sure that all LDM entries in
3681 a GOT resolve to the same index. */
3682 if (g
->tls_ldm_offset
!= MINUS_TWO
&& g
->tls_ldm_offset
!= MINUS_ONE
)
3684 entry
->gotidx
= g
->tls_ldm_offset
;
3687 g
->tls_ldm_offset
= next_index
;
3689 entry
->gotidx
= next_index
;
3690 tls_type
= entry
->tls_type
;
3693 /* Account for the entries we've just allocated. */
3694 if (tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3695 g
->tls_assigned_gotno
+= 2;
3696 if (tls_type
& GOT_TLS_IE
)
3697 g
->tls_assigned_gotno
+= 1;
3702 /* If passed a NULL mips_got_info in the argument, set the marker used
3703 to tell whether a global symbol needs a got entry (in the primary
3704 got) to the given VALUE.
3706 If passed a pointer G to a mips_got_info in the argument (it must
3707 not be the primary GOT), compute the offset from the beginning of
3708 the (primary) GOT section to the entry in G corresponding to the
3709 global symbol. G's assigned_gotno must contain the index of the
3710 first available global GOT entry in G. VALUE must contain the size
3711 of a GOT entry in bytes. For each global GOT entry that requires a
3712 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
3713 marked as not eligible for lazy resolution through a function
3716 mips_elf_set_global_got_offset (void **entryp
, void *p
)
3718 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3719 struct mips_elf_set_global_got_offset_arg
*arg
3720 = (struct mips_elf_set_global_got_offset_arg
*)p
;
3721 struct mips_got_info
*g
= arg
->g
;
3723 if (g
&& entry
->tls_type
!= GOT_NORMAL
)
3724 arg
->needed_relocs
+=
3725 mips_tls_got_relocs (arg
->info
, entry
->tls_type
,
3726 entry
->symndx
== -1 ? &entry
->d
.h
->root
: NULL
);
3728 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1
3729 && entry
->d
.h
->root
.dynindx
!= -1
3730 && !entry
->d
.h
->root
.forced_local
3731 && entry
->d
.h
->tls_type
== GOT_NORMAL
)
3735 BFD_ASSERT (g
->global_gotsym
== NULL
);
3737 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
3738 if (arg
->info
->shared
3739 || (elf_hash_table (arg
->info
)->dynamic_sections_created
3740 && entry
->d
.h
->root
.def_dynamic
3741 && !entry
->d
.h
->root
.def_regular
))
3742 ++arg
->needed_relocs
;
3745 entry
->d
.h
->root
.got
.offset
= arg
->value
;
3751 /* A htab_traverse callback for GOT entries for which DATA is the
3752 bfd_link_info. Forbid any global symbols from having traditional
3753 lazy-binding stubs. */
3756 mips_elf_forbid_lazy_stubs (void **entryp
, void *data
)
3758 struct bfd_link_info
*info
;
3759 struct mips_elf_link_hash_table
*htab
;
3760 struct mips_got_entry
*entry
;
3762 entry
= (struct mips_got_entry
*) *entryp
;
3763 info
= (struct bfd_link_info
*) data
;
3764 htab
= mips_elf_hash_table (info
);
3765 if (entry
->abfd
!= NULL
3766 && entry
->symndx
== -1
3767 && entry
->d
.h
->needs_lazy_stub
)
3769 entry
->d
.h
->needs_lazy_stub
= FALSE
;
3770 htab
->lazy_stub_count
--;
3776 /* Return the offset of an input bfd IBFD's GOT from the beginning of
3779 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
3781 if (g
->bfd2got
== NULL
)
3784 g
= mips_elf_got_for_ibfd (g
, ibfd
);
3788 BFD_ASSERT (g
->next
);
3792 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
3793 * MIPS_ELF_GOT_SIZE (abfd
);
3796 /* Turn a single GOT that is too big for 16-bit addressing into
3797 a sequence of GOTs, each one 16-bit addressable. */
3800 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
3801 asection
*got
, bfd_size_type pages
)
3803 struct mips_elf_link_hash_table
*htab
;
3804 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
3805 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
3806 struct mips_got_info
*g
, *gg
;
3807 unsigned int assign
, needed_relocs
;
3810 dynobj
= elf_hash_table (info
)->dynobj
;
3811 htab
= mips_elf_hash_table (info
);
3813 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
3814 mips_elf_bfd2got_entry_eq
, NULL
);
3815 if (g
->bfd2got
== NULL
)
3818 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
3819 got_per_bfd_arg
.obfd
= abfd
;
3820 got_per_bfd_arg
.info
= info
;
3822 /* Count how many GOT entries each input bfd requires, creating a
3823 map from bfd to got info while at that. */
3824 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
3825 if (got_per_bfd_arg
.obfd
== NULL
)
3828 /* Also count how many page entries each input bfd requires. */
3829 htab_traverse (g
->got_page_entries
, mips_elf_make_got_pages_per_bfd
,
3831 if (got_per_bfd_arg
.obfd
== NULL
)
3834 got_per_bfd_arg
.current
= NULL
;
3835 got_per_bfd_arg
.primary
= NULL
;
3836 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
3837 / MIPS_ELF_GOT_SIZE (abfd
))
3838 - MIPS_RESERVED_GOTNO (info
));
3839 got_per_bfd_arg
.max_pages
= pages
;
3840 /* The number of globals that will be included in the primary GOT.
3841 See the calls to mips_elf_set_global_got_offset below for more
3843 got_per_bfd_arg
.global_count
= g
->global_gotno
;
3845 /* Try to merge the GOTs of input bfds together, as long as they
3846 don't seem to exceed the maximum GOT size, choosing one of them
3847 to be the primary GOT. */
3848 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
3849 if (got_per_bfd_arg
.obfd
== NULL
)
3852 /* If we do not find any suitable primary GOT, create an empty one. */
3853 if (got_per_bfd_arg
.primary
== NULL
)
3855 g
->next
= (struct mips_got_info
*)
3856 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
3857 if (g
->next
== NULL
)
3860 g
->next
->global_gotsym
= NULL
;
3861 g
->next
->global_gotno
= 0;
3862 g
->next
->local_gotno
= 0;
3863 g
->next
->page_gotno
= 0;
3864 g
->next
->tls_gotno
= 0;
3865 g
->next
->assigned_gotno
= 0;
3866 g
->next
->tls_assigned_gotno
= 0;
3867 g
->next
->tls_ldm_offset
= MINUS_ONE
;
3868 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3869 mips_elf_multi_got_entry_eq
,
3871 if (g
->next
->got_entries
== NULL
)
3873 g
->next
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3874 mips_got_page_entry_eq
,
3876 if (g
->next
->got_page_entries
== NULL
)
3878 g
->next
->bfd2got
= NULL
;
3881 g
->next
= got_per_bfd_arg
.primary
;
3882 g
->next
->next
= got_per_bfd_arg
.current
;
3884 /* GG is now the master GOT, and G is the primary GOT. */
3888 /* Map the output bfd to the primary got. That's what we're going
3889 to use for bfds that use GOT16 or GOT_PAGE relocations that we
3890 didn't mark in check_relocs, and we want a quick way to find it.
3891 We can't just use gg->next because we're going to reverse the
3894 struct mips_elf_bfd2got_hash
*bfdgot
;
3897 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
3898 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
3905 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
3907 BFD_ASSERT (*bfdgotp
== NULL
);
3911 /* The IRIX dynamic linker requires every symbol that is referenced
3912 in a dynamic relocation to be present in the primary GOT, so
3913 arrange for them to appear after those that are actually
3916 GNU/Linux could very well do without it, but it would slow down
3917 the dynamic linker, since it would have to resolve every dynamic
3918 symbol referenced in other GOTs more than once, without help from
3919 the cache. Also, knowing that every external symbol has a GOT
3920 helps speed up the resolution of local symbols too, so GNU/Linux
3921 follows IRIX's practice.
3923 The number 2 is used by mips_elf_sort_hash_table_f to count
3924 global GOT symbols that are unreferenced in the primary GOT, with
3925 an initial dynamic index computed from gg->assigned_gotno, where
3926 the number of unreferenced global entries in the primary GOT is
3930 gg
->assigned_gotno
= gg
->global_gotno
- g
->global_gotno
;
3931 g
->global_gotno
= gg
->global_gotno
;
3932 set_got_offset_arg
.value
= 2;
3936 /* This could be used for dynamic linkers that don't optimize
3937 symbol resolution while applying relocations so as to use
3938 primary GOT entries or assuming the symbol is locally-defined.
3939 With this code, we assign lower dynamic indices to global
3940 symbols that are not referenced in the primary GOT, so that
3941 their entries can be omitted. */
3942 gg
->assigned_gotno
= 0;
3943 set_got_offset_arg
.value
= -1;
3946 /* Reorder dynamic symbols as described above (which behavior
3947 depends on the setting of VALUE). */
3948 set_got_offset_arg
.g
= NULL
;
3949 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
3950 &set_got_offset_arg
);
3951 set_got_offset_arg
.value
= 1;
3952 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
3953 &set_got_offset_arg
);
3954 if (! mips_elf_sort_hash_table (info
, 1))
3957 /* Now go through the GOTs assigning them offset ranges.
3958 [assigned_gotno, local_gotno[ will be set to the range of local
3959 entries in each GOT. We can then compute the end of a GOT by
3960 adding local_gotno to global_gotno. We reverse the list and make
3961 it circular since then we'll be able to quickly compute the
3962 beginning of a GOT, by computing the end of its predecessor. To
3963 avoid special cases for the primary GOT, while still preserving
3964 assertions that are valid for both single- and multi-got links,
3965 we arrange for the main got struct to have the right number of
3966 global entries, but set its local_gotno such that the initial
3967 offset of the primary GOT is zero. Remember that the primary GOT
3968 will become the last item in the circular linked list, so it
3969 points back to the master GOT. */
3970 gg
->local_gotno
= -g
->global_gotno
;
3971 gg
->global_gotno
= g
->global_gotno
;
3978 struct mips_got_info
*gn
;
3980 assign
+= MIPS_RESERVED_GOTNO (info
);
3981 g
->assigned_gotno
= assign
;
3982 g
->local_gotno
+= assign
;
3983 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
3984 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
3986 /* Take g out of the direct list, and push it onto the reversed
3987 list that gg points to. g->next is guaranteed to be nonnull after
3988 this operation, as required by mips_elf_initialize_tls_index. */
3993 /* Set up any TLS entries. We always place the TLS entries after
3994 all non-TLS entries. */
3995 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
3996 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
3998 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
4001 /* Forbid global symbols in every non-primary GOT from having
4002 lazy-binding stubs. */
4004 htab_traverse (g
->got_entries
, mips_elf_forbid_lazy_stubs
, info
);
4008 got
->size
= (gg
->next
->local_gotno
4009 + gg
->next
->global_gotno
4010 + gg
->next
->tls_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
4013 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4014 set_got_offset_arg
.info
= info
;
4015 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
4017 unsigned int save_assign
;
4019 /* Assign offsets to global GOT entries. */
4020 save_assign
= g
->assigned_gotno
;
4021 g
->assigned_gotno
= g
->local_gotno
;
4022 set_got_offset_arg
.g
= g
;
4023 set_got_offset_arg
.needed_relocs
= 0;
4024 htab_traverse (g
->got_entries
,
4025 mips_elf_set_global_got_offset
,
4026 &set_got_offset_arg
);
4027 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
4028 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
<= g
->global_gotno
);
4030 g
->assigned_gotno
= save_assign
;
4033 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
4034 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
4035 + g
->next
->global_gotno
4036 + g
->next
->tls_gotno
4037 + MIPS_RESERVED_GOTNO (info
));
4042 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
4049 /* Returns the first relocation of type r_type found, beginning with
4050 RELOCATION. RELEND is one-past-the-end of the relocation table. */
4052 static const Elf_Internal_Rela
*
4053 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
4054 const Elf_Internal_Rela
*relocation
,
4055 const Elf_Internal_Rela
*relend
)
4057 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
4059 while (relocation
< relend
)
4061 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
4062 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
4068 /* We didn't find it. */
4072 /* Return whether a relocation is against a local symbol. */
4075 mips_elf_local_relocation_p (bfd
*input_bfd
,
4076 const Elf_Internal_Rela
*relocation
,
4077 asection
**local_sections
,
4078 bfd_boolean check_forced
)
4080 unsigned long r_symndx
;
4081 Elf_Internal_Shdr
*symtab_hdr
;
4082 struct mips_elf_link_hash_entry
*h
;
4085 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4086 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4087 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
4089 if (r_symndx
< extsymoff
)
4091 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
4096 /* Look up the hash table to check whether the symbol
4097 was forced local. */
4098 h
= (struct mips_elf_link_hash_entry
*)
4099 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
4100 /* Find the real hash-table entry for this symbol. */
4101 while (h
->root
.root
.type
== bfd_link_hash_indirect
4102 || h
->root
.root
.type
== bfd_link_hash_warning
)
4103 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4104 if (h
->root
.forced_local
)
4111 /* Sign-extend VALUE, which has the indicated number of BITS. */
4114 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
4116 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
4117 /* VALUE is negative. */
4118 value
|= ((bfd_vma
) - 1) << bits
;
4123 /* Return non-zero if the indicated VALUE has overflowed the maximum
4124 range expressible by a signed number with the indicated number of
4128 mips_elf_overflow_p (bfd_vma value
, int bits
)
4130 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
4132 if (svalue
> (1 << (bits
- 1)) - 1)
4133 /* The value is too big. */
4135 else if (svalue
< -(1 << (bits
- 1)))
4136 /* The value is too small. */
4143 /* Calculate the %high function. */
4146 mips_elf_high (bfd_vma value
)
4148 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
4151 /* Calculate the %higher function. */
4154 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
4157 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
4164 /* Calculate the %highest function. */
4167 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
4170 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
4177 /* Create the .compact_rel section. */
4180 mips_elf_create_compact_rel_section
4181 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4184 register asection
*s
;
4186 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4188 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
4191 s
= bfd_make_section_with_flags (abfd
, ".compact_rel", flags
);
4193 || ! bfd_set_section_alignment (abfd
, s
,
4194 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4197 s
->size
= sizeof (Elf32_External_compact_rel
);
4203 /* Create the .got section to hold the global offset table. */
4206 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
,
4207 bfd_boolean maybe_exclude
)
4210 register asection
*s
;
4211 struct elf_link_hash_entry
*h
;
4212 struct bfd_link_hash_entry
*bh
;
4213 struct mips_got_info
*g
;
4215 struct mips_elf_link_hash_table
*htab
;
4217 htab
= mips_elf_hash_table (info
);
4219 /* This function may be called more than once. */
4223 if (! maybe_exclude
)
4224 s
->flags
&= ~SEC_EXCLUDE
;
4228 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4229 | SEC_LINKER_CREATED
);
4232 flags
|= SEC_EXCLUDE
;
4234 /* We have to use an alignment of 2**4 here because this is hardcoded
4235 in the function stub generation and in the linker script. */
4236 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4238 || ! bfd_set_section_alignment (abfd
, s
, 4))
4242 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4243 linker script because we don't want to define the symbol if we
4244 are not creating a global offset table. */
4246 if (! (_bfd_generic_link_add_one_symbol
4247 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4248 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4251 h
= (struct elf_link_hash_entry
*) bh
;
4254 h
->type
= STT_OBJECT
;
4255 elf_hash_table (info
)->hgot
= h
;
4258 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4261 amt
= sizeof (struct mips_got_info
);
4262 g
= bfd_alloc (abfd
, amt
);
4265 g
->global_gotsym
= NULL
;
4266 g
->global_gotno
= 0;
4268 g
->local_gotno
= MIPS_RESERVED_GOTNO (info
);
4270 g
->assigned_gotno
= MIPS_RESERVED_GOTNO (info
);
4273 g
->tls_ldm_offset
= MINUS_ONE
;
4274 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
4275 mips_elf_got_entry_eq
, NULL
);
4276 if (g
->got_entries
== NULL
)
4278 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4279 mips_got_page_entry_eq
, NULL
);
4280 if (g
->got_page_entries
== NULL
)
4283 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
4284 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
4286 /* VxWorks also needs a .got.plt section. */
4287 if (htab
->is_vxworks
)
4289 s
= bfd_make_section_with_flags (abfd
, ".got.plt",
4290 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4291 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4292 if (s
== NULL
|| !bfd_set_section_alignment (abfd
, s
, 4))
4300 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
4301 __GOTT_INDEX__ symbols. These symbols are only special for
4302 shared objects; they are not used in executables. */
4305 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
4307 return (mips_elf_hash_table (info
)->is_vxworks
4309 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
4310 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
4313 /* Calculate the value produced by the RELOCATION (which comes from
4314 the INPUT_BFD). The ADDEND is the addend to use for this
4315 RELOCATION; RELOCATION->R_ADDEND is ignored.
4317 The result of the relocation calculation is stored in VALUEP.
4318 REQUIRE_JALXP indicates whether or not the opcode used with this
4319 relocation must be JALX.
4321 This function returns bfd_reloc_continue if the caller need take no
4322 further action regarding this relocation, bfd_reloc_notsupported if
4323 something goes dramatically wrong, bfd_reloc_overflow if an
4324 overflow occurs, and bfd_reloc_ok to indicate success. */
4326 static bfd_reloc_status_type
4327 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
4328 asection
*input_section
,
4329 struct bfd_link_info
*info
,
4330 const Elf_Internal_Rela
*relocation
,
4331 bfd_vma addend
, reloc_howto_type
*howto
,
4332 Elf_Internal_Sym
*local_syms
,
4333 asection
**local_sections
, bfd_vma
*valuep
,
4334 const char **namep
, bfd_boolean
*require_jalxp
,
4335 bfd_boolean save_addend
)
4337 /* The eventual value we will return. */
4339 /* The address of the symbol against which the relocation is
4342 /* The final GP value to be used for the relocatable, executable, or
4343 shared object file being produced. */
4345 /* The place (section offset or address) of the storage unit being
4348 /* The value of GP used to create the relocatable object. */
4350 /* The offset into the global offset table at which the address of
4351 the relocation entry symbol, adjusted by the addend, resides
4352 during execution. */
4353 bfd_vma g
= MINUS_ONE
;
4354 /* The section in which the symbol referenced by the relocation is
4356 asection
*sec
= NULL
;
4357 struct mips_elf_link_hash_entry
*h
= NULL
;
4358 /* TRUE if the symbol referred to by this relocation is a local
4360 bfd_boolean local_p
, was_local_p
;
4361 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
4362 bfd_boolean gp_disp_p
= FALSE
;
4363 /* TRUE if the symbol referred to by this relocation is
4364 "__gnu_local_gp". */
4365 bfd_boolean gnu_local_gp_p
= FALSE
;
4366 Elf_Internal_Shdr
*symtab_hdr
;
4368 unsigned long r_symndx
;
4370 /* TRUE if overflow occurred during the calculation of the
4371 relocation value. */
4372 bfd_boolean overflowed_p
;
4373 /* TRUE if this relocation refers to a MIPS16 function. */
4374 bfd_boolean target_is_16_bit_code_p
= FALSE
;
4375 struct mips_elf_link_hash_table
*htab
;
4378 dynobj
= elf_hash_table (info
)->dynobj
;
4379 htab
= mips_elf_hash_table (info
);
4381 /* Parse the relocation. */
4382 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4383 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4384 p
= (input_section
->output_section
->vma
4385 + input_section
->output_offset
4386 + relocation
->r_offset
);
4388 /* Assume that there will be no overflow. */
4389 overflowed_p
= FALSE
;
4391 /* Figure out whether or not the symbol is local, and get the offset
4392 used in the array of hash table entries. */
4393 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4394 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4395 local_sections
, FALSE
);
4396 was_local_p
= local_p
;
4397 if (! elf_bad_symtab (input_bfd
))
4398 extsymoff
= symtab_hdr
->sh_info
;
4401 /* The symbol table does not follow the rule that local symbols
4402 must come before globals. */
4406 /* Figure out the value of the symbol. */
4409 Elf_Internal_Sym
*sym
;
4411 sym
= local_syms
+ r_symndx
;
4412 sec
= local_sections
[r_symndx
];
4414 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4415 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
4416 || (sec
->flags
& SEC_MERGE
))
4417 symbol
+= sym
->st_value
;
4418 if ((sec
->flags
& SEC_MERGE
)
4419 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4421 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
4423 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
4426 /* MIPS16 text labels should be treated as odd. */
4427 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
4430 /* Record the name of this symbol, for our caller. */
4431 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
4432 symtab_hdr
->sh_link
,
4435 *namep
= bfd_section_name (input_bfd
, sec
);
4437 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
4441 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
4443 /* For global symbols we look up the symbol in the hash-table. */
4444 h
= ((struct mips_elf_link_hash_entry
*)
4445 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
4446 /* Find the real hash-table entry for this symbol. */
4447 while (h
->root
.root
.type
== bfd_link_hash_indirect
4448 || h
->root
.root
.type
== bfd_link_hash_warning
)
4449 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4451 /* Record the name of this symbol, for our caller. */
4452 *namep
= h
->root
.root
.root
.string
;
4454 /* See if this is the special _gp_disp symbol. Note that such a
4455 symbol must always be a global symbol. */
4456 if (strcmp (*namep
, "_gp_disp") == 0
4457 && ! NEWABI_P (input_bfd
))
4459 /* Relocations against _gp_disp are permitted only with
4460 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
4461 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
4462 return bfd_reloc_notsupported
;
4466 /* See if this is the special _gp symbol. Note that such a
4467 symbol must always be a global symbol. */
4468 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
4469 gnu_local_gp_p
= TRUE
;
4472 /* If this symbol is defined, calculate its address. Note that
4473 _gp_disp is a magic symbol, always implicitly defined by the
4474 linker, so it's inappropriate to check to see whether or not
4476 else if ((h
->root
.root
.type
== bfd_link_hash_defined
4477 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4478 && h
->root
.root
.u
.def
.section
)
4480 sec
= h
->root
.root
.u
.def
.section
;
4481 if (sec
->output_section
)
4482 symbol
= (h
->root
.root
.u
.def
.value
4483 + sec
->output_section
->vma
4484 + sec
->output_offset
);
4486 symbol
= h
->root
.root
.u
.def
.value
;
4488 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
4489 /* We allow relocations against undefined weak symbols, giving
4490 it the value zero, so that you can undefined weak functions
4491 and check to see if they exist by looking at their
4494 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4495 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4497 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
4498 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
4500 /* If this is a dynamic link, we should have created a
4501 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
4502 in in _bfd_mips_elf_create_dynamic_sections.
4503 Otherwise, we should define the symbol with a value of 0.
4504 FIXME: It should probably get into the symbol table
4506 BFD_ASSERT (! info
->shared
);
4507 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
4510 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
4512 /* This is an optional symbol - an Irix specific extension to the
4513 ELF spec. Ignore it for now.
4514 XXX - FIXME - there is more to the spec for OPTIONAL symbols
4515 than simply ignoring them, but we do not handle this for now.
4516 For information see the "64-bit ELF Object File Specification"
4517 which is available from here:
4518 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
4523 if (! ((*info
->callbacks
->undefined_symbol
)
4524 (info
, h
->root
.root
.root
.string
, input_bfd
,
4525 input_section
, relocation
->r_offset
,
4526 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
4527 || ELF_ST_VISIBILITY (h
->root
.other
))))
4528 return bfd_reloc_undefined
;
4532 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
4535 /* If this is a reference to a 16-bit function with a stub, we need
4536 to redirect the relocation to the stub unless:
4538 (a) the relocation is for a MIPS16 JAL;
4540 (b) the relocation is for a MIPS16 PIC call, and there are no
4541 non-MIPS16 uses of the GOT slot; or
4543 (c) the section allows direct references to MIPS16 functions. */
4544 if (r_type
!= R_MIPS16_26
4545 && !info
->relocatable
4547 && h
->fn_stub
!= NULL
4548 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
4550 && elf_tdata (input_bfd
)->local_stubs
!= NULL
4551 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
4552 && !section_allows_mips16_refs_p (input_section
))
4554 /* This is a 32- or 64-bit call to a 16-bit function. We should
4555 have already noticed that we were going to need the
4558 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
4561 BFD_ASSERT (h
->need_fn_stub
);
4565 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4566 /* The target is 16-bit, but the stub isn't. */
4567 target_is_16_bit_code_p
= FALSE
;
4569 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
4570 need to redirect the call to the stub. Note that we specifically
4571 exclude R_MIPS16_CALL16 from this behavior; indirect calls should
4572 use an indirect stub instead. */
4573 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
4574 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
4576 && elf_tdata (input_bfd
)->local_call_stubs
!= NULL
4577 && elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
4578 && !target_is_16_bit_code_p
)
4581 sec
= elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
4584 /* If both call_stub and call_fp_stub are defined, we can figure
4585 out which one to use by checking which one appears in the input
4587 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
4592 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4594 if (CALL_FP_STUB_P (bfd_get_section_name (input_bfd
, o
)))
4596 sec
= h
->call_fp_stub
;
4603 else if (h
->call_stub
!= NULL
)
4606 sec
= h
->call_fp_stub
;
4609 BFD_ASSERT (sec
->size
> 0);
4610 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4613 /* Calls from 16-bit code to 32-bit code and vice versa require the
4614 special jalx instruction. */
4615 *require_jalxp
= (!info
->relocatable
4616 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
4617 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
4619 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4620 local_sections
, TRUE
);
4622 gp0
= _bfd_get_gp_value (input_bfd
);
4623 gp
= _bfd_get_gp_value (abfd
);
4625 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
4630 /* If we haven't already determined the GOT offset, oand we're going
4631 to need it, get it now. */
4634 case R_MIPS_GOT_PAGE
:
4635 case R_MIPS_GOT_OFST
:
4636 /* We need to decay to GOT_DISP/addend if the symbol doesn't
4638 local_p
= local_p
|| _bfd_elf_symbol_refs_local_p (&h
->root
, info
, 1);
4639 if (local_p
|| r_type
== R_MIPS_GOT_OFST
)
4643 case R_MIPS16_CALL16
:
4644 case R_MIPS16_GOT16
:
4647 case R_MIPS_GOT_DISP
:
4648 case R_MIPS_GOT_HI16
:
4649 case R_MIPS_CALL_HI16
:
4650 case R_MIPS_GOT_LO16
:
4651 case R_MIPS_CALL_LO16
:
4653 case R_MIPS_TLS_GOTTPREL
:
4654 case R_MIPS_TLS_LDM
:
4655 /* Find the index into the GOT where this value is located. */
4656 if (r_type
== R_MIPS_TLS_LDM
)
4658 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
4659 0, 0, NULL
, r_type
);
4661 return bfd_reloc_outofrange
;
4665 /* On VxWorks, CALL relocations should refer to the .got.plt
4666 entry, which is initialized to point at the PLT stub. */
4667 if (htab
->is_vxworks
4668 && (r_type
== R_MIPS_CALL_HI16
4669 || r_type
== R_MIPS_CALL_LO16
4670 || call16_reloc_p (r_type
)))
4672 BFD_ASSERT (addend
== 0);
4673 BFD_ASSERT (h
->root
.needs_plt
);
4674 g
= mips_elf_gotplt_index (info
, &h
->root
);
4678 /* GOT_PAGE may take a non-zero addend, that is ignored in a
4679 GOT_PAGE relocation that decays to GOT_DISP because the
4680 symbol turns out to be global. The addend is then added
4682 BFD_ASSERT (addend
== 0 || r_type
== R_MIPS_GOT_PAGE
);
4683 g
= mips_elf_global_got_index (dynobj
, input_bfd
,
4684 &h
->root
, r_type
, info
);
4685 if (h
->tls_type
== GOT_NORMAL
4686 && (! elf_hash_table(info
)->dynamic_sections_created
4688 && (info
->symbolic
|| h
->root
.forced_local
)
4689 && h
->root
.def_regular
)))
4690 /* This is a static link or a -Bsymbolic link. The
4691 symbol is defined locally, or was forced to be local.
4692 We must initialize this entry in the GOT. */
4693 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->sgot
->contents
+ g
);
4696 else if (!htab
->is_vxworks
4697 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
4698 /* The calculation below does not involve "g". */
4702 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
4703 symbol
+ addend
, r_symndx
, h
, r_type
);
4705 return bfd_reloc_outofrange
;
4708 /* Convert GOT indices to actual offsets. */
4709 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
4713 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
4714 symbols are resolved by the loader. Add them to .rela.dyn. */
4715 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
4717 Elf_Internal_Rela outrel
;
4721 s
= mips_elf_rel_dyn_section (info
, FALSE
);
4722 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4724 outrel
.r_offset
= (input_section
->output_section
->vma
4725 + input_section
->output_offset
4726 + relocation
->r_offset
);
4727 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
4728 outrel
.r_addend
= addend
;
4729 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
4731 /* If we've written this relocation for a readonly section,
4732 we need to set DF_TEXTREL again, so that we do not delete the
4734 if (MIPS_ELF_READONLY_SECTION (input_section
))
4735 info
->flags
|= DF_TEXTREL
;
4738 return bfd_reloc_ok
;
4741 /* Figure out what kind of relocation is being performed. */
4745 return bfd_reloc_continue
;
4748 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
4749 overflowed_p
= mips_elf_overflow_p (value
, 16);
4756 || (!htab
->is_vxworks
4757 && htab
->root
.dynamic_sections_created
4759 && h
->root
.def_dynamic
4760 && !h
->root
.def_regular
))
4763 || h
->root
.root
.type
!= bfd_link_hash_undefweak
4764 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4765 && (input_section
->flags
& SEC_ALLOC
) != 0)
4767 /* If we're creating a shared library, or this relocation is
4768 against a symbol in a shared library, then we can't know
4769 where the symbol will end up. So, we create a relocation
4770 record in the output, and leave the job up to the dynamic
4773 In VxWorks executables, references to external symbols
4774 are handled using copy relocs or PLT stubs, so there's
4775 no need to add a dynamic relocation here. */
4777 if (!mips_elf_create_dynamic_relocation (abfd
,
4785 return bfd_reloc_undefined
;
4789 if (r_type
!= R_MIPS_REL32
)
4790 value
= symbol
+ addend
;
4794 value
&= howto
->dst_mask
;
4798 value
= symbol
+ addend
- p
;
4799 value
&= howto
->dst_mask
;
4803 /* The calculation for R_MIPS16_26 is just the same as for an
4804 R_MIPS_26. It's only the storage of the relocated field into
4805 the output file that's different. That's handled in
4806 mips_elf_perform_relocation. So, we just fall through to the
4807 R_MIPS_26 case here. */
4810 value
= ((addend
| ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
4813 value
= (_bfd_mips_elf_sign_extend (addend
, 28) + symbol
) >> 2;
4814 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
)
4815 overflowed_p
= (value
>> 26) != ((p
+ 4) >> 28);
4817 value
&= howto
->dst_mask
;
4820 case R_MIPS_TLS_DTPREL_HI16
:
4821 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
4825 case R_MIPS_TLS_DTPREL_LO16
:
4826 case R_MIPS_TLS_DTPREL32
:
4827 case R_MIPS_TLS_DTPREL64
:
4828 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
4831 case R_MIPS_TLS_TPREL_HI16
:
4832 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
4836 case R_MIPS_TLS_TPREL_LO16
:
4837 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
4844 value
= mips_elf_high (addend
+ symbol
);
4845 value
&= howto
->dst_mask
;
4849 /* For MIPS16 ABI code we generate this sequence
4850 0: li $v0,%hi(_gp_disp)
4851 4: addiupc $v1,%lo(_gp_disp)
4855 So the offsets of hi and lo relocs are the same, but the
4856 $pc is four higher than $t9 would be, so reduce
4857 both reloc addends by 4. */
4858 if (r_type
== R_MIPS16_HI16
)
4859 value
= mips_elf_high (addend
+ gp
- p
- 4);
4861 value
= mips_elf_high (addend
+ gp
- p
);
4862 overflowed_p
= mips_elf_overflow_p (value
, 16);
4869 value
= (symbol
+ addend
) & howto
->dst_mask
;
4872 /* See the comment for R_MIPS16_HI16 above for the reason
4873 for this conditional. */
4874 if (r_type
== R_MIPS16_LO16
)
4875 value
= addend
+ gp
- p
;
4877 value
= addend
+ gp
- p
+ 4;
4878 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
4879 for overflow. But, on, say, IRIX5, relocations against
4880 _gp_disp are normally generated from the .cpload
4881 pseudo-op. It generates code that normally looks like
4884 lui $gp,%hi(_gp_disp)
4885 addiu $gp,$gp,%lo(_gp_disp)
4888 Here $t9 holds the address of the function being called,
4889 as required by the MIPS ELF ABI. The R_MIPS_LO16
4890 relocation can easily overflow in this situation, but the
4891 R_MIPS_HI16 relocation will handle the overflow.
4892 Therefore, we consider this a bug in the MIPS ABI, and do
4893 not check for overflow here. */
4897 case R_MIPS_LITERAL
:
4898 /* Because we don't merge literal sections, we can handle this
4899 just like R_MIPS_GPREL16. In the long run, we should merge
4900 shared literals, and then we will need to additional work
4905 case R_MIPS16_GPREL
:
4906 /* The R_MIPS16_GPREL performs the same calculation as
4907 R_MIPS_GPREL16, but stores the relocated bits in a different
4908 order. We don't need to do anything special here; the
4909 differences are handled in mips_elf_perform_relocation. */
4910 case R_MIPS_GPREL16
:
4911 /* Only sign-extend the addend if it was extracted from the
4912 instruction. If the addend was separate, leave it alone,
4913 otherwise we may lose significant bits. */
4914 if (howto
->partial_inplace
)
4915 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
4916 value
= symbol
+ addend
- gp
;
4917 /* If the symbol was local, any earlier relocatable links will
4918 have adjusted its addend with the gp offset, so compensate
4919 for that now. Don't do it for symbols forced local in this
4920 link, though, since they won't have had the gp offset applied
4924 overflowed_p
= mips_elf_overflow_p (value
, 16);
4927 case R_MIPS16_GOT16
:
4928 case R_MIPS16_CALL16
:
4931 /* VxWorks does not have separate local and global semantics for
4932 R_MIPS*_GOT16; every relocation evaluates to "G". */
4933 if (!htab
->is_vxworks
&& local_p
)
4937 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
4938 local_sections
, FALSE
);
4939 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
4940 symbol
+ addend
, forced
);
4941 if (value
== MINUS_ONE
)
4942 return bfd_reloc_outofrange
;
4944 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
4945 overflowed_p
= mips_elf_overflow_p (value
, 16);
4952 case R_MIPS_TLS_GOTTPREL
:
4953 case R_MIPS_TLS_LDM
:
4954 case R_MIPS_GOT_DISP
:
4957 overflowed_p
= mips_elf_overflow_p (value
, 16);
4960 case R_MIPS_GPREL32
:
4961 value
= (addend
+ symbol
+ gp0
- gp
);
4963 value
&= howto
->dst_mask
;
4967 case R_MIPS_GNU_REL16_S2
:
4968 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
4969 overflowed_p
= mips_elf_overflow_p (value
, 18);
4970 value
>>= howto
->rightshift
;
4971 value
&= howto
->dst_mask
;
4974 case R_MIPS_GOT_HI16
:
4975 case R_MIPS_CALL_HI16
:
4976 /* We're allowed to handle these two relocations identically.
4977 The dynamic linker is allowed to handle the CALL relocations
4978 differently by creating a lazy evaluation stub. */
4980 value
= mips_elf_high (value
);
4981 value
&= howto
->dst_mask
;
4984 case R_MIPS_GOT_LO16
:
4985 case R_MIPS_CALL_LO16
:
4986 value
= g
& howto
->dst_mask
;
4989 case R_MIPS_GOT_PAGE
:
4990 /* GOT_PAGE relocations that reference non-local symbols decay
4991 to GOT_DISP. The corresponding GOT_OFST relocation decays to
4995 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
4996 if (value
== MINUS_ONE
)
4997 return bfd_reloc_outofrange
;
4998 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
4999 overflowed_p
= mips_elf_overflow_p (value
, 16);
5002 case R_MIPS_GOT_OFST
:
5004 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
5007 overflowed_p
= mips_elf_overflow_p (value
, 16);
5011 value
= symbol
- addend
;
5012 value
&= howto
->dst_mask
;
5016 value
= mips_elf_higher (addend
+ symbol
);
5017 value
&= howto
->dst_mask
;
5020 case R_MIPS_HIGHEST
:
5021 value
= mips_elf_highest (addend
+ symbol
);
5022 value
&= howto
->dst_mask
;
5025 case R_MIPS_SCN_DISP
:
5026 value
= symbol
+ addend
- sec
->output_offset
;
5027 value
&= howto
->dst_mask
;
5031 /* This relocation is only a hint. In some cases, we optimize
5032 it into a bal instruction. But we don't try to optimize
5033 branches to the PLT; that will wind up wasting time. */
5034 if (h
!= NULL
&& h
->root
.plt
.offset
!= (bfd_vma
) -1)
5035 return bfd_reloc_continue
;
5036 value
= symbol
+ addend
;
5040 case R_MIPS_GNU_VTINHERIT
:
5041 case R_MIPS_GNU_VTENTRY
:
5042 /* We don't do anything with these at present. */
5043 return bfd_reloc_continue
;
5046 /* An unrecognized relocation type. */
5047 return bfd_reloc_notsupported
;
5050 /* Store the VALUE for our caller. */
5052 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
5055 /* Obtain the field relocated by RELOCATION. */
5058 mips_elf_obtain_contents (reloc_howto_type
*howto
,
5059 const Elf_Internal_Rela
*relocation
,
5060 bfd
*input_bfd
, bfd_byte
*contents
)
5063 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5065 /* Obtain the bytes. */
5066 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
5071 /* It has been determined that the result of the RELOCATION is the
5072 VALUE. Use HOWTO to place VALUE into the output file at the
5073 appropriate position. The SECTION is the section to which the
5074 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
5075 for the relocation must be either JAL or JALX, and it is
5076 unconditionally converted to JALX.
5078 Returns FALSE if anything goes wrong. */
5081 mips_elf_perform_relocation (struct bfd_link_info
*info
,
5082 reloc_howto_type
*howto
,
5083 const Elf_Internal_Rela
*relocation
,
5084 bfd_vma value
, bfd
*input_bfd
,
5085 asection
*input_section
, bfd_byte
*contents
,
5086 bfd_boolean require_jalx
)
5090 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5092 /* Figure out where the relocation is occurring. */
5093 location
= contents
+ relocation
->r_offset
;
5095 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
5097 /* Obtain the current value. */
5098 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
5100 /* Clear the field we are setting. */
5101 x
&= ~howto
->dst_mask
;
5103 /* Set the field. */
5104 x
|= (value
& howto
->dst_mask
);
5106 /* If required, turn JAL into JALX. */
5110 bfd_vma opcode
= x
>> 26;
5111 bfd_vma jalx_opcode
;
5113 /* Check to see if the opcode is already JAL or JALX. */
5114 if (r_type
== R_MIPS16_26
)
5116 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
5121 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
5125 /* If the opcode is not JAL or JALX, there's a problem. */
5128 (*_bfd_error_handler
)
5129 (_("%B: %A+0x%lx: jump to stub routine which is not jal"),
5132 (unsigned long) relocation
->r_offset
);
5133 bfd_set_error (bfd_error_bad_value
);
5137 /* Make this the JALX opcode. */
5138 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
5141 /* On the RM9000, bal is faster than jal, because bal uses branch
5142 prediction hardware. If we are linking for the RM9000, and we
5143 see jal, and bal fits, use it instead. Note that this
5144 transformation should be safe for all architectures. */
5145 if (bfd_get_mach (input_bfd
) == bfd_mach_mips9000
5146 && !info
->relocatable
5148 && ((r_type
== R_MIPS_26
&& (x
>> 26) == 0x3) /* jal addr */
5149 || (r_type
== R_MIPS_JALR
&& x
== 0x0320f809))) /* jalr t9 */
5155 addr
= (input_section
->output_section
->vma
5156 + input_section
->output_offset
5157 + relocation
->r_offset
5159 if (r_type
== R_MIPS_26
)
5160 dest
= (value
<< 2) | ((addr
>> 28) << 28);
5164 if (off
<= 0x1ffff && off
>= -0x20000)
5165 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
5168 /* Put the value into the output. */
5169 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
5171 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, !info
->relocatable
,
5177 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5178 is the original relocation, which is now being transformed into a
5179 dynamic relocation. The ADDENDP is adjusted if necessary; the
5180 caller should store the result in place of the original addend. */
5183 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
5184 struct bfd_link_info
*info
,
5185 const Elf_Internal_Rela
*rel
,
5186 struct mips_elf_link_hash_entry
*h
,
5187 asection
*sec
, bfd_vma symbol
,
5188 bfd_vma
*addendp
, asection
*input_section
)
5190 Elf_Internal_Rela outrel
[3];
5195 bfd_boolean defined_p
;
5196 struct mips_elf_link_hash_table
*htab
;
5198 htab
= mips_elf_hash_table (info
);
5199 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5200 dynobj
= elf_hash_table (info
)->dynobj
;
5201 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
5202 BFD_ASSERT (sreloc
!= NULL
);
5203 BFD_ASSERT (sreloc
->contents
!= NULL
);
5204 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
5207 outrel
[0].r_offset
=
5208 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
5209 if (ABI_64_P (output_bfd
))
5211 outrel
[1].r_offset
=
5212 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
5213 outrel
[2].r_offset
=
5214 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
5217 if (outrel
[0].r_offset
== MINUS_ONE
)
5218 /* The relocation field has been deleted. */
5221 if (outrel
[0].r_offset
== MINUS_TWO
)
5223 /* The relocation field has been converted into a relative value of
5224 some sort. Functions like _bfd_elf_write_section_eh_frame expect
5225 the field to be fully relocated, so add in the symbol's value. */
5230 /* We must now calculate the dynamic symbol table index to use
5231 in the relocation. */
5233 && (!h
->root
.def_regular
5234 || (info
->shared
&& !info
->symbolic
&& !h
->root
.forced_local
)))
5236 indx
= h
->root
.dynindx
;
5237 if (SGI_COMPAT (output_bfd
))
5238 defined_p
= h
->root
.def_regular
;
5240 /* ??? glibc's ld.so just adds the final GOT entry to the
5241 relocation field. It therefore treats relocs against
5242 defined symbols in the same way as relocs against
5243 undefined symbols. */
5248 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5250 else if (sec
== NULL
|| sec
->owner
== NULL
)
5252 bfd_set_error (bfd_error_bad_value
);
5257 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5260 asection
*osec
= htab
->root
.text_index_section
;
5261 indx
= elf_section_data (osec
)->dynindx
;
5267 /* Instead of generating a relocation using the section
5268 symbol, we may as well make it a fully relative
5269 relocation. We want to avoid generating relocations to
5270 local symbols because we used to generate them
5271 incorrectly, without adding the original symbol value,
5272 which is mandated by the ABI for section symbols. In
5273 order to give dynamic loaders and applications time to
5274 phase out the incorrect use, we refrain from emitting
5275 section-relative relocations. It's not like they're
5276 useful, after all. This should be a bit more efficient
5278 /* ??? Although this behavior is compatible with glibc's ld.so,
5279 the ABI says that relocations against STN_UNDEF should have
5280 a symbol value of 0. Irix rld honors this, so relocations
5281 against STN_UNDEF have no effect. */
5282 if (!SGI_COMPAT (output_bfd
))
5287 /* If the relocation was previously an absolute relocation and
5288 this symbol will not be referred to by the relocation, we must
5289 adjust it by the value we give it in the dynamic symbol table.
5290 Otherwise leave the job up to the dynamic linker. */
5291 if (defined_p
&& r_type
!= R_MIPS_REL32
)
5294 if (htab
->is_vxworks
)
5295 /* VxWorks uses non-relative relocations for this. */
5296 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
5298 /* The relocation is always an REL32 relocation because we don't
5299 know where the shared library will wind up at load-time. */
5300 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
5303 /* For strict adherence to the ABI specification, we should
5304 generate a R_MIPS_64 relocation record by itself before the
5305 _REL32/_64 record as well, such that the addend is read in as
5306 a 64-bit value (REL32 is a 32-bit relocation, after all).
5307 However, since none of the existing ELF64 MIPS dynamic
5308 loaders seems to care, we don't waste space with these
5309 artificial relocations. If this turns out to not be true,
5310 mips_elf_allocate_dynamic_relocation() should be tweaked so
5311 as to make room for a pair of dynamic relocations per
5312 invocation if ABI_64_P, and here we should generate an
5313 additional relocation record with R_MIPS_64 by itself for a
5314 NULL symbol before this relocation record. */
5315 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
5316 ABI_64_P (output_bfd
)
5319 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
5321 /* Adjust the output offset of the relocation to reference the
5322 correct location in the output file. */
5323 outrel
[0].r_offset
+= (input_section
->output_section
->vma
5324 + input_section
->output_offset
);
5325 outrel
[1].r_offset
+= (input_section
->output_section
->vma
5326 + input_section
->output_offset
);
5327 outrel
[2].r_offset
+= (input_section
->output_section
->vma
5328 + input_section
->output_offset
);
5330 /* Put the relocation back out. We have to use the special
5331 relocation outputter in the 64-bit case since the 64-bit
5332 relocation format is non-standard. */
5333 if (ABI_64_P (output_bfd
))
5335 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5336 (output_bfd
, &outrel
[0],
5338 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5340 else if (htab
->is_vxworks
)
5342 /* VxWorks uses RELA rather than REL dynamic relocations. */
5343 outrel
[0].r_addend
= *addendp
;
5344 bfd_elf32_swap_reloca_out
5345 (output_bfd
, &outrel
[0],
5347 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
5350 bfd_elf32_swap_reloc_out
5351 (output_bfd
, &outrel
[0],
5352 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
5354 /* We've now added another relocation. */
5355 ++sreloc
->reloc_count
;
5357 /* Make sure the output section is writable. The dynamic linker
5358 will be writing to it. */
5359 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5362 /* On IRIX5, make an entry of compact relocation info. */
5363 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
5365 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5370 Elf32_crinfo cptrel
;
5372 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5373 cptrel
.vaddr
= (rel
->r_offset
5374 + input_section
->output_section
->vma
5375 + input_section
->output_offset
);
5376 if (r_type
== R_MIPS_REL32
)
5377 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5379 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5380 mips_elf_set_cr_dist2to (cptrel
, 0);
5381 cptrel
.konst
= *addendp
;
5383 cr
= (scpt
->contents
5384 + sizeof (Elf32_External_compact_rel
));
5385 mips_elf_set_cr_relvaddr (cptrel
, 0);
5386 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5387 ((Elf32_External_crinfo
*) cr
5388 + scpt
->reloc_count
));
5389 ++scpt
->reloc_count
;
5393 /* If we've written this relocation for a readonly section,
5394 we need to set DF_TEXTREL again, so that we do not delete the
5396 if (MIPS_ELF_READONLY_SECTION (input_section
))
5397 info
->flags
|= DF_TEXTREL
;
5402 /* Return the MACH for a MIPS e_flags value. */
5405 _bfd_elf_mips_mach (flagword flags
)
5407 switch (flags
& EF_MIPS_MACH
)
5409 case E_MIPS_MACH_3900
:
5410 return bfd_mach_mips3900
;
5412 case E_MIPS_MACH_4010
:
5413 return bfd_mach_mips4010
;
5415 case E_MIPS_MACH_4100
:
5416 return bfd_mach_mips4100
;
5418 case E_MIPS_MACH_4111
:
5419 return bfd_mach_mips4111
;
5421 case E_MIPS_MACH_4120
:
5422 return bfd_mach_mips4120
;
5424 case E_MIPS_MACH_4650
:
5425 return bfd_mach_mips4650
;
5427 case E_MIPS_MACH_5400
:
5428 return bfd_mach_mips5400
;
5430 case E_MIPS_MACH_5500
:
5431 return bfd_mach_mips5500
;
5433 case E_MIPS_MACH_9000
:
5434 return bfd_mach_mips9000
;
5436 case E_MIPS_MACH_SB1
:
5437 return bfd_mach_mips_sb1
;
5439 case E_MIPS_MACH_LS2E
:
5440 return bfd_mach_mips_loongson_2e
;
5442 case E_MIPS_MACH_LS2F
:
5443 return bfd_mach_mips_loongson_2f
;
5445 case E_MIPS_MACH_OCTEON
:
5446 return bfd_mach_mips_octeon
;
5449 switch (flags
& EF_MIPS_ARCH
)
5453 return bfd_mach_mips3000
;
5456 return bfd_mach_mips6000
;
5459 return bfd_mach_mips4000
;
5462 return bfd_mach_mips8000
;
5465 return bfd_mach_mips5
;
5467 case E_MIPS_ARCH_32
:
5468 return bfd_mach_mipsisa32
;
5470 case E_MIPS_ARCH_64
:
5471 return bfd_mach_mipsisa64
;
5473 case E_MIPS_ARCH_32R2
:
5474 return bfd_mach_mipsisa32r2
;
5476 case E_MIPS_ARCH_64R2
:
5477 return bfd_mach_mipsisa64r2
;
5484 /* Return printable name for ABI. */
5486 static INLINE
char *
5487 elf_mips_abi_name (bfd
*abfd
)
5491 flags
= elf_elfheader (abfd
)->e_flags
;
5492 switch (flags
& EF_MIPS_ABI
)
5495 if (ABI_N32_P (abfd
))
5497 else if (ABI_64_P (abfd
))
5501 case E_MIPS_ABI_O32
:
5503 case E_MIPS_ABI_O64
:
5505 case E_MIPS_ABI_EABI32
:
5507 case E_MIPS_ABI_EABI64
:
5510 return "unknown abi";
5514 /* MIPS ELF uses two common sections. One is the usual one, and the
5515 other is for small objects. All the small objects are kept
5516 together, and then referenced via the gp pointer, which yields
5517 faster assembler code. This is what we use for the small common
5518 section. This approach is copied from ecoff.c. */
5519 static asection mips_elf_scom_section
;
5520 static asymbol mips_elf_scom_symbol
;
5521 static asymbol
*mips_elf_scom_symbol_ptr
;
5523 /* MIPS ELF also uses an acommon section, which represents an
5524 allocated common symbol which may be overridden by a
5525 definition in a shared library. */
5526 static asection mips_elf_acom_section
;
5527 static asymbol mips_elf_acom_symbol
;
5528 static asymbol
*mips_elf_acom_symbol_ptr
;
5530 /* This is used for both the 32-bit and the 64-bit ABI. */
5533 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
5535 elf_symbol_type
*elfsym
;
5537 /* Handle the special MIPS section numbers that a symbol may use. */
5538 elfsym
= (elf_symbol_type
*) asym
;
5539 switch (elfsym
->internal_elf_sym
.st_shndx
)
5541 case SHN_MIPS_ACOMMON
:
5542 /* This section is used in a dynamically linked executable file.
5543 It is an allocated common section. The dynamic linker can
5544 either resolve these symbols to something in a shared
5545 library, or it can just leave them here. For our purposes,
5546 we can consider these symbols to be in a new section. */
5547 if (mips_elf_acom_section
.name
== NULL
)
5549 /* Initialize the acommon section. */
5550 mips_elf_acom_section
.name
= ".acommon";
5551 mips_elf_acom_section
.flags
= SEC_ALLOC
;
5552 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
5553 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
5554 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
5555 mips_elf_acom_symbol
.name
= ".acommon";
5556 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
5557 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
5558 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
5560 asym
->section
= &mips_elf_acom_section
;
5564 /* Common symbols less than the GP size are automatically
5565 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
5566 if (asym
->value
> elf_gp_size (abfd
)
5567 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
5568 || IRIX_COMPAT (abfd
) == ict_irix6
)
5571 case SHN_MIPS_SCOMMON
:
5572 if (mips_elf_scom_section
.name
== NULL
)
5574 /* Initialize the small common section. */
5575 mips_elf_scom_section
.name
= ".scommon";
5576 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
5577 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
5578 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
5579 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
5580 mips_elf_scom_symbol
.name
= ".scommon";
5581 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
5582 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
5583 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
5585 asym
->section
= &mips_elf_scom_section
;
5586 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
5589 case SHN_MIPS_SUNDEFINED
:
5590 asym
->section
= bfd_und_section_ptr
;
5595 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
5597 BFD_ASSERT (SGI_COMPAT (abfd
));
5598 if (section
!= NULL
)
5600 asym
->section
= section
;
5601 /* MIPS_TEXT is a bit special, the address is not an offset
5602 to the base of the .text section. So substract the section
5603 base address to make it an offset. */
5604 asym
->value
-= section
->vma
;
5611 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
5613 BFD_ASSERT (SGI_COMPAT (abfd
));
5614 if (section
!= NULL
)
5616 asym
->section
= section
;
5617 /* MIPS_DATA is a bit special, the address is not an offset
5618 to the base of the .data section. So substract the section
5619 base address to make it an offset. */
5620 asym
->value
-= section
->vma
;
5626 /* If this is an odd-valued function symbol, assume it's a MIPS16 one. */
5627 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
5628 && (asym
->value
& 1) != 0)
5631 elfsym
->internal_elf_sym
.st_other
5632 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
5636 /* Implement elf_backend_eh_frame_address_size. This differs from
5637 the default in the way it handles EABI64.
5639 EABI64 was originally specified as an LP64 ABI, and that is what
5640 -mabi=eabi normally gives on a 64-bit target. However, gcc has
5641 historically accepted the combination of -mabi=eabi and -mlong32,
5642 and this ILP32 variation has become semi-official over time.
5643 Both forms use elf32 and have pointer-sized FDE addresses.
5645 If an EABI object was generated by GCC 4.0 or above, it will have
5646 an empty .gcc_compiled_longXX section, where XX is the size of longs
5647 in bits. Unfortunately, ILP32 objects generated by earlier compilers
5648 have no special marking to distinguish them from LP64 objects.
5650 We don't want users of the official LP64 ABI to be punished for the
5651 existence of the ILP32 variant, but at the same time, we don't want
5652 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
5653 We therefore take the following approach:
5655 - If ABFD contains a .gcc_compiled_longXX section, use it to
5656 determine the pointer size.
5658 - Otherwise check the type of the first relocation. Assume that
5659 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
5663 The second check is enough to detect LP64 objects generated by pre-4.0
5664 compilers because, in the kind of output generated by those compilers,
5665 the first relocation will be associated with either a CIE personality
5666 routine or an FDE start address. Furthermore, the compilers never
5667 used a special (non-pointer) encoding for this ABI.
5669 Checking the relocation type should also be safe because there is no
5670 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
5674 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
5676 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
5678 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
5680 bfd_boolean long32_p
, long64_p
;
5682 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
5683 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
5684 if (long32_p
&& long64_p
)
5691 if (sec
->reloc_count
> 0
5692 && elf_section_data (sec
)->relocs
!= NULL
5693 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
5702 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
5703 relocations against two unnamed section symbols to resolve to the
5704 same address. For example, if we have code like:
5706 lw $4,%got_disp(.data)($gp)
5707 lw $25,%got_disp(.text)($gp)
5710 then the linker will resolve both relocations to .data and the program
5711 will jump there rather than to .text.
5713 We can work around this problem by giving names to local section symbols.
5714 This is also what the MIPSpro tools do. */
5717 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
5719 return SGI_COMPAT (abfd
);
5722 /* Work over a section just before writing it out. This routine is
5723 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
5724 sections that need the SHF_MIPS_GPREL flag by name; there has to be
5728 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
5730 if (hdr
->sh_type
== SHT_MIPS_REGINFO
5731 && hdr
->sh_size
> 0)
5735 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
5736 BFD_ASSERT (hdr
->contents
== NULL
);
5739 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
5742 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5743 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5747 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
5748 && hdr
->bfd_section
!= NULL
5749 && mips_elf_section_data (hdr
->bfd_section
) != NULL
5750 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
5752 bfd_byte
*contents
, *l
, *lend
;
5754 /* We stored the section contents in the tdata field in the
5755 set_section_contents routine. We save the section contents
5756 so that we don't have to read them again.
5757 At this point we know that elf_gp is set, so we can look
5758 through the section contents to see if there is an
5759 ODK_REGINFO structure. */
5761 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
5763 lend
= contents
+ hdr
->sh_size
;
5764 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5766 Elf_Internal_Options intopt
;
5768 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5770 if (intopt
.size
< sizeof (Elf_External_Options
))
5772 (*_bfd_error_handler
)
5773 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5774 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
5777 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
5784 + sizeof (Elf_External_Options
)
5785 + (sizeof (Elf64_External_RegInfo
) - 8)),
5788 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
5789 if (bfd_bwrite (buf
, 8, abfd
) != 8)
5792 else if (intopt
.kind
== ODK_REGINFO
)
5799 + sizeof (Elf_External_Options
)
5800 + (sizeof (Elf32_External_RegInfo
) - 4)),
5803 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5804 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5811 if (hdr
->bfd_section
!= NULL
)
5813 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
5815 if (strcmp (name
, ".sdata") == 0
5816 || strcmp (name
, ".lit8") == 0
5817 || strcmp (name
, ".lit4") == 0)
5819 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5820 hdr
->sh_type
= SHT_PROGBITS
;
5822 else if (strcmp (name
, ".sbss") == 0)
5824 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5825 hdr
->sh_type
= SHT_NOBITS
;
5827 else if (strcmp (name
, ".srdata") == 0)
5829 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
5830 hdr
->sh_type
= SHT_PROGBITS
;
5832 else if (strcmp (name
, ".compact_rel") == 0)
5835 hdr
->sh_type
= SHT_PROGBITS
;
5837 else if (strcmp (name
, ".rtproc") == 0)
5839 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
5841 unsigned int adjust
;
5843 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
5845 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
5853 /* Handle a MIPS specific section when reading an object file. This
5854 is called when elfcode.h finds a section with an unknown type.
5855 This routine supports both the 32-bit and 64-bit ELF ABI.
5857 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
5861 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
5862 Elf_Internal_Shdr
*hdr
,
5868 /* There ought to be a place to keep ELF backend specific flags, but
5869 at the moment there isn't one. We just keep track of the
5870 sections by their name, instead. Fortunately, the ABI gives
5871 suggested names for all the MIPS specific sections, so we will
5872 probably get away with this. */
5873 switch (hdr
->sh_type
)
5875 case SHT_MIPS_LIBLIST
:
5876 if (strcmp (name
, ".liblist") != 0)
5880 if (strcmp (name
, ".msym") != 0)
5883 case SHT_MIPS_CONFLICT
:
5884 if (strcmp (name
, ".conflict") != 0)
5887 case SHT_MIPS_GPTAB
:
5888 if (! CONST_STRNEQ (name
, ".gptab."))
5891 case SHT_MIPS_UCODE
:
5892 if (strcmp (name
, ".ucode") != 0)
5895 case SHT_MIPS_DEBUG
:
5896 if (strcmp (name
, ".mdebug") != 0)
5898 flags
= SEC_DEBUGGING
;
5900 case SHT_MIPS_REGINFO
:
5901 if (strcmp (name
, ".reginfo") != 0
5902 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
5904 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
5906 case SHT_MIPS_IFACE
:
5907 if (strcmp (name
, ".MIPS.interfaces") != 0)
5910 case SHT_MIPS_CONTENT
:
5911 if (! CONST_STRNEQ (name
, ".MIPS.content"))
5914 case SHT_MIPS_OPTIONS
:
5915 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
5918 case SHT_MIPS_DWARF
:
5919 if (! CONST_STRNEQ (name
, ".debug_")
5920 && ! CONST_STRNEQ (name
, ".zdebug_"))
5923 case SHT_MIPS_SYMBOL_LIB
:
5924 if (strcmp (name
, ".MIPS.symlib") != 0)
5927 case SHT_MIPS_EVENTS
:
5928 if (! CONST_STRNEQ (name
, ".MIPS.events")
5929 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
5936 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
5941 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
5942 (bfd_get_section_flags (abfd
,
5948 /* FIXME: We should record sh_info for a .gptab section. */
5950 /* For a .reginfo section, set the gp value in the tdata information
5951 from the contents of this section. We need the gp value while
5952 processing relocs, so we just get it now. The .reginfo section
5953 is not used in the 64-bit MIPS ELF ABI. */
5954 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
5956 Elf32_External_RegInfo ext
;
5959 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
5960 &ext
, 0, sizeof ext
))
5962 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
5963 elf_gp (abfd
) = s
.ri_gp_value
;
5966 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
5967 set the gp value based on what we find. We may see both
5968 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
5969 they should agree. */
5970 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
5972 bfd_byte
*contents
, *l
, *lend
;
5974 contents
= bfd_malloc (hdr
->sh_size
);
5975 if (contents
== NULL
)
5977 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
5984 lend
= contents
+ hdr
->sh_size
;
5985 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5987 Elf_Internal_Options intopt
;
5989 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5991 if (intopt
.size
< sizeof (Elf_External_Options
))
5993 (*_bfd_error_handler
)
5994 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5995 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
5998 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6000 Elf64_Internal_RegInfo intreg
;
6002 bfd_mips_elf64_swap_reginfo_in
6004 ((Elf64_External_RegInfo
*)
6005 (l
+ sizeof (Elf_External_Options
))),
6007 elf_gp (abfd
) = intreg
.ri_gp_value
;
6009 else if (intopt
.kind
== ODK_REGINFO
)
6011 Elf32_RegInfo intreg
;
6013 bfd_mips_elf32_swap_reginfo_in
6015 ((Elf32_External_RegInfo
*)
6016 (l
+ sizeof (Elf_External_Options
))),
6018 elf_gp (abfd
) = intreg
.ri_gp_value
;
6028 /* Set the correct type for a MIPS ELF section. We do this by the
6029 section name, which is a hack, but ought to work. This routine is
6030 used by both the 32-bit and the 64-bit ABI. */
6033 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
6035 const char *name
= bfd_get_section_name (abfd
, sec
);
6037 if (strcmp (name
, ".liblist") == 0)
6039 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
6040 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
6041 /* The sh_link field is set in final_write_processing. */
6043 else if (strcmp (name
, ".conflict") == 0)
6044 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
6045 else if (CONST_STRNEQ (name
, ".gptab."))
6047 hdr
->sh_type
= SHT_MIPS_GPTAB
;
6048 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
6049 /* The sh_info field is set in final_write_processing. */
6051 else if (strcmp (name
, ".ucode") == 0)
6052 hdr
->sh_type
= SHT_MIPS_UCODE
;
6053 else if (strcmp (name
, ".mdebug") == 0)
6055 hdr
->sh_type
= SHT_MIPS_DEBUG
;
6056 /* In a shared object on IRIX 5.3, the .mdebug section has an
6057 entsize of 0. FIXME: Does this matter? */
6058 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
6059 hdr
->sh_entsize
= 0;
6061 hdr
->sh_entsize
= 1;
6063 else if (strcmp (name
, ".reginfo") == 0)
6065 hdr
->sh_type
= SHT_MIPS_REGINFO
;
6066 /* In a shared object on IRIX 5.3, the .reginfo section has an
6067 entsize of 0x18. FIXME: Does this matter? */
6068 if (SGI_COMPAT (abfd
))
6070 if ((abfd
->flags
& DYNAMIC
) != 0)
6071 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6073 hdr
->sh_entsize
= 1;
6076 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6078 else if (SGI_COMPAT (abfd
)
6079 && (strcmp (name
, ".hash") == 0
6080 || strcmp (name
, ".dynamic") == 0
6081 || strcmp (name
, ".dynstr") == 0))
6083 if (SGI_COMPAT (abfd
))
6084 hdr
->sh_entsize
= 0;
6086 /* This isn't how the IRIX6 linker behaves. */
6087 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6090 else if (strcmp (name
, ".got") == 0
6091 || strcmp (name
, ".srdata") == 0
6092 || strcmp (name
, ".sdata") == 0
6093 || strcmp (name
, ".sbss") == 0
6094 || strcmp (name
, ".lit4") == 0
6095 || strcmp (name
, ".lit8") == 0)
6096 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
6097 else if (strcmp (name
, ".MIPS.interfaces") == 0)
6099 hdr
->sh_type
= SHT_MIPS_IFACE
;
6100 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6102 else if (CONST_STRNEQ (name
, ".MIPS.content"))
6104 hdr
->sh_type
= SHT_MIPS_CONTENT
;
6105 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6106 /* The sh_info field is set in final_write_processing. */
6108 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6110 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
6111 hdr
->sh_entsize
= 1;
6112 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6114 else if (CONST_STRNEQ (name
, ".debug_")
6115 || CONST_STRNEQ (name
, ".zdebug_"))
6117 hdr
->sh_type
= SHT_MIPS_DWARF
;
6119 /* Irix facilities such as libexc expect a single .debug_frame
6120 per executable, the system ones have NOSTRIP set and the linker
6121 doesn't merge sections with different flags so ... */
6122 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
6123 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6125 else if (strcmp (name
, ".MIPS.symlib") == 0)
6127 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
6128 /* The sh_link and sh_info fields are set in
6129 final_write_processing. */
6131 else if (CONST_STRNEQ (name
, ".MIPS.events")
6132 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
6134 hdr
->sh_type
= SHT_MIPS_EVENTS
;
6135 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6136 /* The sh_link field is set in final_write_processing. */
6138 else if (strcmp (name
, ".msym") == 0)
6140 hdr
->sh_type
= SHT_MIPS_MSYM
;
6141 hdr
->sh_flags
|= SHF_ALLOC
;
6142 hdr
->sh_entsize
= 8;
6145 /* The generic elf_fake_sections will set up REL_HDR using the default
6146 kind of relocations. We used to set up a second header for the
6147 non-default kind of relocations here, but only NewABI would use
6148 these, and the IRIX ld doesn't like resulting empty RELA sections.
6149 Thus we create those header only on demand now. */
6154 /* Given a BFD section, try to locate the corresponding ELF section
6155 index. This is used by both the 32-bit and the 64-bit ABI.
6156 Actually, it's not clear to me that the 64-bit ABI supports these,
6157 but for non-PIC objects we will certainly want support for at least
6158 the .scommon section. */
6161 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6162 asection
*sec
, int *retval
)
6164 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
6166 *retval
= SHN_MIPS_SCOMMON
;
6169 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
6171 *retval
= SHN_MIPS_ACOMMON
;
6177 /* Hook called by the linker routine which adds symbols from an object
6178 file. We must handle the special MIPS section numbers here. */
6181 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6182 Elf_Internal_Sym
*sym
, const char **namep
,
6183 flagword
*flagsp ATTRIBUTE_UNUSED
,
6184 asection
**secp
, bfd_vma
*valp
)
6186 if (SGI_COMPAT (abfd
)
6187 && (abfd
->flags
& DYNAMIC
) != 0
6188 && strcmp (*namep
, "_rld_new_interface") == 0)
6190 /* Skip IRIX5 rld entry name. */
6195 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
6196 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
6197 by setting a DT_NEEDED for the shared object. Since _gp_disp is
6198 a magic symbol resolved by the linker, we ignore this bogus definition
6199 of _gp_disp. New ABI objects do not suffer from this problem so this
6200 is not done for them. */
6202 && (sym
->st_shndx
== SHN_ABS
)
6203 && (strcmp (*namep
, "_gp_disp") == 0))
6209 switch (sym
->st_shndx
)
6212 /* Common symbols less than the GP size are automatically
6213 treated as SHN_MIPS_SCOMMON symbols. */
6214 if (sym
->st_size
> elf_gp_size (abfd
)
6215 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
6216 || IRIX_COMPAT (abfd
) == ict_irix6
)
6219 case SHN_MIPS_SCOMMON
:
6220 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
6221 (*secp
)->flags
|= SEC_IS_COMMON
;
6222 *valp
= sym
->st_size
;
6226 /* This section is used in a shared object. */
6227 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
6229 asymbol
*elf_text_symbol
;
6230 asection
*elf_text_section
;
6231 bfd_size_type amt
= sizeof (asection
);
6233 elf_text_section
= bfd_zalloc (abfd
, amt
);
6234 if (elf_text_section
== NULL
)
6237 amt
= sizeof (asymbol
);
6238 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
6239 if (elf_text_symbol
== NULL
)
6242 /* Initialize the section. */
6244 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
6245 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
6247 elf_text_section
->symbol
= elf_text_symbol
;
6248 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
6250 elf_text_section
->name
= ".text";
6251 elf_text_section
->flags
= SEC_NO_FLAGS
;
6252 elf_text_section
->output_section
= NULL
;
6253 elf_text_section
->owner
= abfd
;
6254 elf_text_symbol
->name
= ".text";
6255 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6256 elf_text_symbol
->section
= elf_text_section
;
6258 /* This code used to do *secp = bfd_und_section_ptr if
6259 info->shared. I don't know why, and that doesn't make sense,
6260 so I took it out. */
6261 *secp
= elf_tdata (abfd
)->elf_text_section
;
6264 case SHN_MIPS_ACOMMON
:
6265 /* Fall through. XXX Can we treat this as allocated data? */
6267 /* This section is used in a shared object. */
6268 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
6270 asymbol
*elf_data_symbol
;
6271 asection
*elf_data_section
;
6272 bfd_size_type amt
= sizeof (asection
);
6274 elf_data_section
= bfd_zalloc (abfd
, amt
);
6275 if (elf_data_section
== NULL
)
6278 amt
= sizeof (asymbol
);
6279 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
6280 if (elf_data_symbol
== NULL
)
6283 /* Initialize the section. */
6285 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
6286 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
6288 elf_data_section
->symbol
= elf_data_symbol
;
6289 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
6291 elf_data_section
->name
= ".data";
6292 elf_data_section
->flags
= SEC_NO_FLAGS
;
6293 elf_data_section
->output_section
= NULL
;
6294 elf_data_section
->owner
= abfd
;
6295 elf_data_symbol
->name
= ".data";
6296 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6297 elf_data_symbol
->section
= elf_data_section
;
6299 /* This code used to do *secp = bfd_und_section_ptr if
6300 info->shared. I don't know why, and that doesn't make sense,
6301 so I took it out. */
6302 *secp
= elf_tdata (abfd
)->elf_data_section
;
6305 case SHN_MIPS_SUNDEFINED
:
6306 *secp
= bfd_und_section_ptr
;
6310 if (SGI_COMPAT (abfd
)
6312 && info
->output_bfd
->xvec
== abfd
->xvec
6313 && strcmp (*namep
, "__rld_obj_head") == 0)
6315 struct elf_link_hash_entry
*h
;
6316 struct bfd_link_hash_entry
*bh
;
6318 /* Mark __rld_obj_head as dynamic. */
6320 if (! (_bfd_generic_link_add_one_symbol
6321 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
6322 get_elf_backend_data (abfd
)->collect
, &bh
)))
6325 h
= (struct elf_link_hash_entry
*) bh
;
6328 h
->type
= STT_OBJECT
;
6330 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6333 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
6336 /* If this is a mips16 text symbol, add 1 to the value to make it
6337 odd. This will cause something like .word SYM to come up with
6338 the right value when it is loaded into the PC. */
6339 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6345 /* This hook function is called before the linker writes out a global
6346 symbol. We mark symbols as small common if appropriate. This is
6347 also where we undo the increment of the value for a mips16 symbol. */
6350 _bfd_mips_elf_link_output_symbol_hook
6351 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6352 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
6353 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
6355 /* If we see a common symbol, which implies a relocatable link, then
6356 if a symbol was small common in an input file, mark it as small
6357 common in the output file. */
6358 if (sym
->st_shndx
== SHN_COMMON
6359 && strcmp (input_sec
->name
, ".scommon") == 0)
6360 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6362 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6363 sym
->st_value
&= ~1;
6368 /* Functions for the dynamic linker. */
6370 /* Create dynamic sections when linking against a dynamic object. */
6373 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6375 struct elf_link_hash_entry
*h
;
6376 struct bfd_link_hash_entry
*bh
;
6378 register asection
*s
;
6379 const char * const *namep
;
6380 struct mips_elf_link_hash_table
*htab
;
6382 htab
= mips_elf_hash_table (info
);
6383 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6384 | SEC_LINKER_CREATED
| SEC_READONLY
);
6386 /* The psABI requires a read-only .dynamic section, but the VxWorks
6388 if (!htab
->is_vxworks
)
6390 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6393 if (! bfd_set_section_flags (abfd
, s
, flags
))
6398 /* We need to create .got section. */
6399 if (! mips_elf_create_got_section (abfd
, info
, FALSE
))
6402 if (! mips_elf_rel_dyn_section (info
, TRUE
))
6405 /* Create .stub section. */
6406 s
= bfd_make_section_with_flags (abfd
,
6407 MIPS_ELF_STUB_SECTION_NAME (abfd
),
6410 || ! bfd_set_section_alignment (abfd
, s
,
6411 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6415 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
6417 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6419 s
= bfd_make_section_with_flags (abfd
, ".rld_map",
6420 flags
&~ (flagword
) SEC_READONLY
);
6422 || ! bfd_set_section_alignment (abfd
, s
,
6423 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6427 /* On IRIX5, we adjust add some additional symbols and change the
6428 alignments of several sections. There is no ABI documentation
6429 indicating that this is necessary on IRIX6, nor any evidence that
6430 the linker takes such action. */
6431 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6433 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6436 if (! (_bfd_generic_link_add_one_symbol
6437 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
6438 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6441 h
= (struct elf_link_hash_entry
*) bh
;
6444 h
->type
= STT_SECTION
;
6446 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6450 /* We need to create a .compact_rel section. */
6451 if (SGI_COMPAT (abfd
))
6453 if (!mips_elf_create_compact_rel_section (abfd
, info
))
6457 /* Change alignments of some sections. */
6458 s
= bfd_get_section_by_name (abfd
, ".hash");
6460 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6461 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6463 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6464 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6466 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6467 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6469 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6470 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6472 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6479 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
6481 if (!(_bfd_generic_link_add_one_symbol
6482 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
6483 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6486 h
= (struct elf_link_hash_entry
*) bh
;
6489 h
->type
= STT_SECTION
;
6491 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6494 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
6496 /* __rld_map is a four byte word located in the .data section
6497 and is filled in by the rtld to contain a pointer to
6498 the _r_debug structure. Its symbol value will be set in
6499 _bfd_mips_elf_finish_dynamic_symbol. */
6500 s
= bfd_get_section_by_name (abfd
, ".rld_map");
6501 BFD_ASSERT (s
!= NULL
);
6503 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
6505 if (!(_bfd_generic_link_add_one_symbol
6506 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
6507 get_elf_backend_data (abfd
)->collect
, &bh
)))
6510 h
= (struct elf_link_hash_entry
*) bh
;
6513 h
->type
= STT_OBJECT
;
6515 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6520 if (htab
->is_vxworks
)
6522 /* Create the .plt, .rela.plt, .dynbss and .rela.bss sections.
6523 Also create the _PROCEDURE_LINKAGE_TABLE symbol. */
6524 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
6527 /* Cache the sections created above. */
6528 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
6529 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
6530 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
6531 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
6533 || (!htab
->srelbss
&& !info
->shared
)
6538 /* Do the usual VxWorks handling. */
6539 if (!elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
6542 /* Work out the PLT sizes. */
6545 htab
->plt_header_size
6546 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
6547 htab
->plt_entry_size
6548 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
6552 htab
->plt_header_size
6553 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
6554 htab
->plt_entry_size
6555 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
6562 /* Return true if relocation REL against section SEC is a REL rather than
6563 RELA relocation. RELOCS is the first relocation in the section and
6564 ABFD is the bfd that contains SEC. */
6567 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
6568 const Elf_Internal_Rela
*relocs
,
6569 const Elf_Internal_Rela
*rel
)
6571 Elf_Internal_Shdr
*rel_hdr
;
6572 const struct elf_backend_data
*bed
;
6574 /* To determine which flavor or relocation this is, we depend on the
6575 fact that the INPUT_SECTION's REL_HDR is read before its REL_HDR2. */
6576 rel_hdr
= &elf_section_data (sec
)->rel_hdr
;
6577 bed
= get_elf_backend_data (abfd
);
6578 if ((size_t) (rel
- relocs
)
6579 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
6580 rel_hdr
= elf_section_data (sec
)->rel_hdr2
;
6581 return rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (abfd
);
6584 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
6585 HOWTO is the relocation's howto and CONTENTS points to the contents
6586 of the section that REL is against. */
6589 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
6590 reloc_howto_type
*howto
, bfd_byte
*contents
)
6593 unsigned int r_type
;
6596 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6597 location
= contents
+ rel
->r_offset
;
6599 /* Get the addend, which is stored in the input file. */
6600 _bfd_mips16_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
6601 addend
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
6602 _bfd_mips16_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
6604 return addend
& howto
->src_mask
;
6607 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
6608 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
6609 and update *ADDEND with the final addend. Return true on success
6610 or false if the LO16 could not be found. RELEND is the exclusive
6611 upper bound on the relocations for REL's section. */
6614 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
6615 const Elf_Internal_Rela
*rel
,
6616 const Elf_Internal_Rela
*relend
,
6617 bfd_byte
*contents
, bfd_vma
*addend
)
6619 unsigned int r_type
, lo16_type
;
6620 const Elf_Internal_Rela
*lo16_relocation
;
6621 reloc_howto_type
*lo16_howto
;
6624 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6625 if (mips16_reloc_p (r_type
))
6626 lo16_type
= R_MIPS16_LO16
;
6628 lo16_type
= R_MIPS_LO16
;
6630 /* The combined value is the sum of the HI16 addend, left-shifted by
6631 sixteen bits, and the LO16 addend, sign extended. (Usually, the
6632 code does a `lui' of the HI16 value, and then an `addiu' of the
6635 Scan ahead to find a matching LO16 relocation.
6637 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
6638 be immediately following. However, for the IRIX6 ABI, the next
6639 relocation may be a composed relocation consisting of several
6640 relocations for the same address. In that case, the R_MIPS_LO16
6641 relocation may occur as one of these. We permit a similar
6642 extension in general, as that is useful for GCC.
6644 In some cases GCC dead code elimination removes the LO16 but keeps
6645 the corresponding HI16. This is strictly speaking a violation of
6646 the ABI but not immediately harmful. */
6647 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
6648 if (lo16_relocation
== NULL
)
6651 /* Obtain the addend kept there. */
6652 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
6653 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
6655 l
<<= lo16_howto
->rightshift
;
6656 l
= _bfd_mips_elf_sign_extend (l
, 16);
6663 /* Try to read the contents of section SEC in bfd ABFD. Return true and
6664 store the contents in *CONTENTS on success. Assume that *CONTENTS
6665 already holds the contents if it is nonull on entry. */
6668 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
6673 /* Get cached copy if it exists. */
6674 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6676 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
6680 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
6683 /* Look through the relocs for a section during the first phase, and
6684 allocate space in the global offset table. */
6687 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6688 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6692 Elf_Internal_Shdr
*symtab_hdr
;
6693 struct elf_link_hash_entry
**sym_hashes
;
6695 const Elf_Internal_Rela
*rel
;
6696 const Elf_Internal_Rela
*rel_end
;
6698 const struct elf_backend_data
*bed
;
6699 struct mips_elf_link_hash_table
*htab
;
6702 reloc_howto_type
*howto
;
6704 if (info
->relocatable
)
6707 htab
= mips_elf_hash_table (info
);
6708 dynobj
= elf_hash_table (info
)->dynobj
;
6709 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6710 sym_hashes
= elf_sym_hashes (abfd
);
6711 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6713 bed
= get_elf_backend_data (abfd
);
6714 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6716 /* Check for the mips16 stub sections. */
6718 name
= bfd_get_section_name (abfd
, sec
);
6719 if (FN_STUB_P (name
))
6721 unsigned long r_symndx
;
6723 /* Look at the relocation information to figure out which symbol
6726 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
6729 (*_bfd_error_handler
)
6730 (_("%B: Warning: cannot determine the target function for"
6731 " stub section `%s'"),
6733 bfd_set_error (bfd_error_bad_value
);
6737 if (r_symndx
< extsymoff
6738 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6742 /* This stub is for a local symbol. This stub will only be
6743 needed if there is some relocation in this BFD, other
6744 than a 16 bit function call, which refers to this symbol. */
6745 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6747 Elf_Internal_Rela
*sec_relocs
;
6748 const Elf_Internal_Rela
*r
, *rend
;
6750 /* We can ignore stub sections when looking for relocs. */
6751 if ((o
->flags
& SEC_RELOC
) == 0
6752 || o
->reloc_count
== 0
6753 || section_allows_mips16_refs_p (o
))
6757 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
6759 if (sec_relocs
== NULL
)
6762 rend
= sec_relocs
+ o
->reloc_count
;
6763 for (r
= sec_relocs
; r
< rend
; r
++)
6764 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
6765 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
6768 if (elf_section_data (o
)->relocs
!= sec_relocs
)
6777 /* There is no non-call reloc for this stub, so we do
6778 not need it. Since this function is called before
6779 the linker maps input sections to output sections, we
6780 can easily discard it by setting the SEC_EXCLUDE
6782 sec
->flags
|= SEC_EXCLUDE
;
6786 /* Record this stub in an array of local symbol stubs for
6788 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6790 unsigned long symcount
;
6794 if (elf_bad_symtab (abfd
))
6795 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
6797 symcount
= symtab_hdr
->sh_info
;
6798 amt
= symcount
* sizeof (asection
*);
6799 n
= bfd_zalloc (abfd
, amt
);
6802 elf_tdata (abfd
)->local_stubs
= n
;
6805 sec
->flags
|= SEC_KEEP
;
6806 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6808 /* We don't need to set mips16_stubs_seen in this case.
6809 That flag is used to see whether we need to look through
6810 the global symbol table for stubs. We don't need to set
6811 it here, because we just have a local stub. */
6815 struct mips_elf_link_hash_entry
*h
;
6817 h
= ((struct mips_elf_link_hash_entry
*)
6818 sym_hashes
[r_symndx
- extsymoff
]);
6820 while (h
->root
.root
.type
== bfd_link_hash_indirect
6821 || h
->root
.root
.type
== bfd_link_hash_warning
)
6822 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
6824 /* H is the symbol this stub is for. */
6826 /* If we already have an appropriate stub for this function, we
6827 don't need another one, so we can discard this one. Since
6828 this function is called before the linker maps input sections
6829 to output sections, we can easily discard it by setting the
6830 SEC_EXCLUDE flag. */
6831 if (h
->fn_stub
!= NULL
)
6833 sec
->flags
|= SEC_EXCLUDE
;
6837 sec
->flags
|= SEC_KEEP
;
6839 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
6842 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
6844 unsigned long r_symndx
;
6845 struct mips_elf_link_hash_entry
*h
;
6848 /* Look at the relocation information to figure out which symbol
6851 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
6854 (*_bfd_error_handler
)
6855 (_("%B: Warning: cannot determine the target function for"
6856 " stub section `%s'"),
6858 bfd_set_error (bfd_error_bad_value
);
6862 if (r_symndx
< extsymoff
6863 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6867 /* This stub is for a local symbol. This stub will only be
6868 needed if there is some relocation (R_MIPS16_26) in this BFD
6869 that refers to this symbol. */
6870 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6872 Elf_Internal_Rela
*sec_relocs
;
6873 const Elf_Internal_Rela
*r
, *rend
;
6875 /* We can ignore stub sections when looking for relocs. */
6876 if ((o
->flags
& SEC_RELOC
) == 0
6877 || o
->reloc_count
== 0
6878 || section_allows_mips16_refs_p (o
))
6882 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
6884 if (sec_relocs
== NULL
)
6887 rend
= sec_relocs
+ o
->reloc_count
;
6888 for (r
= sec_relocs
; r
< rend
; r
++)
6889 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
6890 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
6893 if (elf_section_data (o
)->relocs
!= sec_relocs
)
6902 /* There is no non-call reloc for this stub, so we do
6903 not need it. Since this function is called before
6904 the linker maps input sections to output sections, we
6905 can easily discard it by setting the SEC_EXCLUDE
6907 sec
->flags
|= SEC_EXCLUDE
;
6911 /* Record this stub in an array of local symbol call_stubs for
6913 if (elf_tdata (abfd
)->local_call_stubs
== NULL
)
6915 unsigned long symcount
;
6919 if (elf_bad_symtab (abfd
))
6920 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
6922 symcount
= symtab_hdr
->sh_info
;
6923 amt
= symcount
* sizeof (asection
*);
6924 n
= bfd_zalloc (abfd
, amt
);
6927 elf_tdata (abfd
)->local_call_stubs
= n
;
6930 sec
->flags
|= SEC_KEEP
;
6931 elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
6933 /* We don't need to set mips16_stubs_seen in this case.
6934 That flag is used to see whether we need to look through
6935 the global symbol table for stubs. We don't need to set
6936 it here, because we just have a local stub. */
6940 h
= ((struct mips_elf_link_hash_entry
*)
6941 sym_hashes
[r_symndx
- extsymoff
]);
6943 /* H is the symbol this stub is for. */
6945 if (CALL_FP_STUB_P (name
))
6946 loc
= &h
->call_fp_stub
;
6948 loc
= &h
->call_stub
;
6950 /* If we already have an appropriate stub for this function, we
6951 don't need another one, so we can discard this one. Since
6952 this function is called before the linker maps input sections
6953 to output sections, we can easily discard it by setting the
6954 SEC_EXCLUDE flag. */
6957 sec
->flags
|= SEC_EXCLUDE
;
6961 sec
->flags
|= SEC_KEEP
;
6963 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
6969 for (rel
= relocs
; rel
< rel_end
; ++rel
)
6971 unsigned long r_symndx
;
6972 unsigned int r_type
;
6973 struct elf_link_hash_entry
*h
;
6975 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
6976 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6978 if (r_symndx
< extsymoff
)
6980 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
6982 (*_bfd_error_handler
)
6983 (_("%B: Malformed reloc detected for section %s"),
6985 bfd_set_error (bfd_error_bad_value
);
6990 h
= sym_hashes
[r_symndx
- extsymoff
];
6992 /* This may be an indirect symbol created because of a version. */
6995 while (h
->root
.type
== bfd_link_hash_indirect
)
6996 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7000 /* Some relocs require a global offset table. */
7001 if (dynobj
== NULL
|| htab
->sgot
== NULL
)
7005 case R_MIPS16_GOT16
:
7006 case R_MIPS16_CALL16
:
7009 case R_MIPS_CALL_HI16
:
7010 case R_MIPS_CALL_LO16
:
7011 case R_MIPS_GOT_HI16
:
7012 case R_MIPS_GOT_LO16
:
7013 case R_MIPS_GOT_PAGE
:
7014 case R_MIPS_GOT_OFST
:
7015 case R_MIPS_GOT_DISP
:
7016 case R_MIPS_TLS_GOTTPREL
:
7018 case R_MIPS_TLS_LDM
:
7020 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7021 if (! mips_elf_create_got_section (dynobj
, info
, FALSE
))
7023 if (htab
->is_vxworks
&& !info
->shared
)
7025 (*_bfd_error_handler
)
7026 (_("%B: GOT reloc at 0x%lx not expected in executables"),
7027 abfd
, (unsigned long) rel
->r_offset
);
7028 bfd_set_error (bfd_error_bad_value
);
7036 /* In VxWorks executables, references to external symbols
7037 are handled using copy relocs or PLT stubs, so there's
7038 no need to add a dynamic relocation here. */
7040 && (info
->shared
|| (h
!= NULL
&& !htab
->is_vxworks
))
7041 && (sec
->flags
& SEC_ALLOC
) != 0)
7042 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7052 ((struct mips_elf_link_hash_entry
*) h
)->is_relocation_target
= TRUE
;
7054 /* Relocations against the special VxWorks __GOTT_BASE__ and
7055 __GOTT_INDEX__ symbols must be left to the loader. Allocate
7056 room for them in .rela.dyn. */
7057 if (is_gott_symbol (info
, h
))
7061 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7065 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7066 if (MIPS_ELF_READONLY_SECTION (sec
))
7067 /* We tell the dynamic linker that there are
7068 relocations against the text segment. */
7069 info
->flags
|= DF_TEXTREL
;
7072 else if (r_type
== R_MIPS_CALL_LO16
7073 || r_type
== R_MIPS_GOT_LO16
7074 || r_type
== R_MIPS_GOT_DISP
7075 || (got16_reloc_p (r_type
) && htab
->is_vxworks
))
7077 /* We may need a local GOT entry for this relocation. We
7078 don't count R_MIPS_GOT_PAGE because we can estimate the
7079 maximum number of pages needed by looking at the size of
7080 the segment. Similar comments apply to R_MIPS*_GOT16 and
7081 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
7082 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
7083 R_MIPS_CALL_HI16 because these are always followed by an
7084 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
7085 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7086 rel
->r_addend
, info
, 0))
7093 case R_MIPS16_CALL16
:
7096 (*_bfd_error_handler
)
7097 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
7098 abfd
, (unsigned long) rel
->r_offset
);
7099 bfd_set_error (bfd_error_bad_value
);
7104 case R_MIPS_CALL_HI16
:
7105 case R_MIPS_CALL_LO16
:
7108 /* VxWorks call relocations point the function's .got.plt
7109 entry, which will be allocated by adjust_dynamic_symbol.
7110 Otherwise, this symbol requires a global GOT entry. */
7111 if ((!htab
->is_vxworks
|| h
->forced_local
)
7112 && !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7115 /* We need a stub, not a plt entry for the undefined
7116 function. But we record it as if it needs plt. See
7117 _bfd_elf_adjust_dynamic_symbol. */
7123 case R_MIPS_GOT_PAGE
:
7124 /* If this is a global, overridable symbol, GOT_PAGE will
7125 decay to GOT_DISP, so we'll need a GOT entry for it. */
7128 struct mips_elf_link_hash_entry
*hmips
=
7129 (struct mips_elf_link_hash_entry
*) h
;
7131 while (hmips
->root
.root
.type
== bfd_link_hash_indirect
7132 || hmips
->root
.root
.type
== bfd_link_hash_warning
)
7133 hmips
= (struct mips_elf_link_hash_entry
*)
7134 hmips
->root
.root
.u
.i
.link
;
7136 /* This symbol is definitely not overridable. */
7137 if (hmips
->root
.def_regular
7138 && ! (info
->shared
&& ! info
->symbolic
7139 && ! hmips
->root
.forced_local
))
7144 case R_MIPS16_GOT16
:
7146 case R_MIPS_GOT_HI16
:
7147 case R_MIPS_GOT_LO16
:
7148 if (!h
|| r_type
== R_MIPS_GOT_PAGE
)
7150 /* This relocation needs (or may need, if h != NULL) a
7151 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
7152 know for sure until we know whether the symbol is
7154 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
7156 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7158 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7159 addend
= mips_elf_read_rel_addend (abfd
, rel
,
7161 if (r_type
== R_MIPS_GOT16
)
7162 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
7165 addend
<<= howto
->rightshift
;
7168 addend
= rel
->r_addend
;
7169 if (!mips_elf_record_got_page_entry (info
, abfd
, r_symndx
,
7176 case R_MIPS_GOT_DISP
:
7177 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7181 case R_MIPS_TLS_GOTTPREL
:
7183 info
->flags
|= DF_STATIC_TLS
;
7186 case R_MIPS_TLS_LDM
:
7187 if (r_type
== R_MIPS_TLS_LDM
)
7195 /* This symbol requires a global offset table entry, or two
7196 for TLS GD relocations. */
7198 unsigned char flag
= (r_type
== R_MIPS_TLS_GD
7200 : r_type
== R_MIPS_TLS_LDM
7205 struct mips_elf_link_hash_entry
*hmips
=
7206 (struct mips_elf_link_hash_entry
*) h
;
7207 hmips
->tls_type
|= flag
;
7209 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
,
7215 BFD_ASSERT (flag
== GOT_TLS_LDM
|| r_symndx
!= 0);
7217 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7228 /* In VxWorks executables, references to external symbols
7229 are handled using copy relocs or PLT stubs, so there's
7230 no need to add a .rela.dyn entry for this relocation. */
7231 if ((info
->shared
|| (h
!= NULL
&& !htab
->is_vxworks
))
7232 && !(h
&& strcmp (h
->root
.root
.string
, "__gnu_local_gp") == 0)
7233 && (sec
->flags
& SEC_ALLOC
) != 0)
7237 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7241 if (info
->shared
&& h
== NULL
)
7243 /* When creating a shared object, we must copy these
7244 reloc types into the output file as R_MIPS_REL32
7245 relocs. Make room for this reloc in .rel(a).dyn. */
7246 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7247 if (MIPS_ELF_READONLY_SECTION (sec
))
7248 /* We tell the dynamic linker that there are
7249 relocations against the text segment. */
7250 info
->flags
|= DF_TEXTREL
;
7254 struct mips_elf_link_hash_entry
*hmips
;
7256 /* For a shared object, we must copy this relocation
7257 unless the symbol turns out to be undefined and
7258 weak with non-default visibility, in which case
7259 it will be left as zero.
7261 We could elide R_MIPS_REL32 for locally binding symbols
7262 in shared libraries, but do not yet do so.
7264 For an executable, we only need to copy this
7265 reloc if the symbol is defined in a dynamic
7267 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7268 ++hmips
->possibly_dynamic_relocs
;
7269 if (MIPS_ELF_READONLY_SECTION (sec
))
7270 /* We need it to tell the dynamic linker if there
7271 are relocations against the text segment. */
7272 hmips
->readonly_reloc
= TRUE
;
7275 /* Even though we don't directly need a GOT entry for
7276 this symbol, a symbol must have a dynamic symbol
7277 table index greater that DT_MIPS_GOTSYM if there are
7278 dynamic relocations against it. This does not apply
7279 to VxWorks, which does not have the usual coupling
7280 between global GOT entries and .dynsym entries. */
7281 if (h
!= NULL
&& !htab
->is_vxworks
)
7284 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7285 if (! mips_elf_create_got_section (dynobj
, info
, TRUE
))
7287 if (!mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7292 if (SGI_COMPAT (abfd
))
7293 mips_elf_hash_table (info
)->compact_rel_size
+=
7294 sizeof (Elf32_External_crinfo
);
7299 ((struct mips_elf_link_hash_entry
*) h
)->is_branch_target
= TRUE
;
7304 ((struct mips_elf_link_hash_entry
*) h
)->is_branch_target
= TRUE
;
7307 case R_MIPS_GPREL16
:
7308 case R_MIPS_LITERAL
:
7309 case R_MIPS_GPREL32
:
7310 if (SGI_COMPAT (abfd
))
7311 mips_elf_hash_table (info
)->compact_rel_size
+=
7312 sizeof (Elf32_External_crinfo
);
7315 /* This relocation describes the C++ object vtable hierarchy.
7316 Reconstruct it for later use during GC. */
7317 case R_MIPS_GNU_VTINHERIT
:
7318 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7322 /* This relocation describes which C++ vtable entries are actually
7323 used. Record for later use during GC. */
7324 case R_MIPS_GNU_VTENTRY
:
7325 BFD_ASSERT (h
!= NULL
);
7327 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7335 /* We must not create a stub for a symbol that has relocations
7336 related to taking the function's address. This doesn't apply to
7337 VxWorks, where CALL relocs refer to a .got.plt entry instead of
7338 a normal .got entry. */
7339 if (!htab
->is_vxworks
&& h
!= NULL
)
7343 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
7345 case R_MIPS16_CALL16
:
7347 case R_MIPS_CALL_HI16
:
7348 case R_MIPS_CALL_LO16
:
7353 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
7354 if there is one. We only need to handle global symbols here;
7355 we decide whether to keep or delete stubs for local symbols
7356 when processing the stub's relocations. */
7358 && !mips16_call_reloc_p (r_type
)
7359 && !section_allows_mips16_refs_p (sec
))
7361 struct mips_elf_link_hash_entry
*mh
;
7363 mh
= (struct mips_elf_link_hash_entry
*) h
;
7364 mh
->need_fn_stub
= TRUE
;
7372 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
7373 struct bfd_link_info
*link_info
,
7376 Elf_Internal_Rela
*internal_relocs
;
7377 Elf_Internal_Rela
*irel
, *irelend
;
7378 Elf_Internal_Shdr
*symtab_hdr
;
7379 bfd_byte
*contents
= NULL
;
7381 bfd_boolean changed_contents
= FALSE
;
7382 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
7383 Elf_Internal_Sym
*isymbuf
= NULL
;
7385 /* We are not currently changing any sizes, so only one pass. */
7388 if (link_info
->relocatable
)
7391 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
7392 link_info
->keep_memory
);
7393 if (internal_relocs
== NULL
)
7396 irelend
= internal_relocs
+ sec
->reloc_count
7397 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
7398 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7399 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7401 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
7404 bfd_signed_vma sym_offset
;
7405 unsigned int r_type
;
7406 unsigned long r_symndx
;
7408 unsigned long instruction
;
7410 /* Turn jalr into bgezal, and jr into beq, if they're marked
7411 with a JALR relocation, that indicate where they jump to.
7412 This saves some pipeline bubbles. */
7413 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
7414 if (r_type
!= R_MIPS_JALR
)
7417 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
7418 /* Compute the address of the jump target. */
7419 if (r_symndx
>= extsymoff
)
7421 struct mips_elf_link_hash_entry
*h
7422 = ((struct mips_elf_link_hash_entry
*)
7423 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
7425 while (h
->root
.root
.type
== bfd_link_hash_indirect
7426 || h
->root
.root
.type
== bfd_link_hash_warning
)
7427 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7429 /* If a symbol is undefined, or if it may be overridden,
7431 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
7432 || h
->root
.root
.type
== bfd_link_hash_defweak
)
7433 && h
->root
.root
.u
.def
.section
)
7434 || (link_info
->shared
&& ! link_info
->symbolic
7435 && !h
->root
.forced_local
))
7438 sym_sec
= h
->root
.root
.u
.def
.section
;
7439 if (sym_sec
->output_section
)
7440 symval
= (h
->root
.root
.u
.def
.value
7441 + sym_sec
->output_section
->vma
7442 + sym_sec
->output_offset
);
7444 symval
= h
->root
.root
.u
.def
.value
;
7448 Elf_Internal_Sym
*isym
;
7450 /* Read this BFD's symbols if we haven't done so already. */
7451 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
7453 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7454 if (isymbuf
== NULL
)
7455 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
7456 symtab_hdr
->sh_info
, 0,
7458 if (isymbuf
== NULL
)
7462 isym
= isymbuf
+ r_symndx
;
7463 if (isym
->st_shndx
== SHN_UNDEF
)
7465 else if (isym
->st_shndx
== SHN_ABS
)
7466 sym_sec
= bfd_abs_section_ptr
;
7467 else if (isym
->st_shndx
== SHN_COMMON
)
7468 sym_sec
= bfd_com_section_ptr
;
7471 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7472 symval
= isym
->st_value
7473 + sym_sec
->output_section
->vma
7474 + sym_sec
->output_offset
;
7477 /* Compute branch offset, from delay slot of the jump to the
7479 sym_offset
= (symval
+ irel
->r_addend
)
7480 - (sec_start
+ irel
->r_offset
+ 4);
7482 /* Branch offset must be properly aligned. */
7483 if ((sym_offset
& 3) != 0)
7488 /* Check that it's in range. */
7489 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
7492 /* Get the section contents if we haven't done so already. */
7493 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7496 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
7498 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
7499 if ((instruction
& 0xfc1fffff) == 0x0000f809)
7500 instruction
= 0x04110000;
7501 /* If it was jr <reg>, turn it into b <target>. */
7502 else if ((instruction
& 0xfc1fffff) == 0x00000008)
7503 instruction
= 0x10000000;
7507 instruction
|= (sym_offset
& 0xffff);
7508 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
7509 changed_contents
= TRUE
;
7512 if (contents
!= NULL
7513 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7515 if (!changed_contents
&& !link_info
->keep_memory
)
7519 /* Cache the section contents for elf_link_input_bfd. */
7520 elf_section_data (sec
)->this_hdr
.contents
= contents
;
7526 if (contents
!= NULL
7527 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7532 /* Allocate space for global sym dynamic relocs. */
7535 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7537 struct bfd_link_info
*info
= inf
;
7539 struct mips_elf_link_hash_entry
*hmips
;
7540 struct mips_elf_link_hash_table
*htab
;
7542 htab
= mips_elf_hash_table (info
);
7543 dynobj
= elf_hash_table (info
)->dynobj
;
7544 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7546 /* VxWorks executables are handled elsewhere; we only need to
7547 allocate relocations in shared objects. */
7548 if (htab
->is_vxworks
&& !info
->shared
)
7551 /* Ignore indirect and warning symbols. All relocations against
7552 such symbols will be redirected to the target symbol. */
7553 if (h
->root
.type
== bfd_link_hash_indirect
7554 || h
->root
.type
== bfd_link_hash_warning
)
7557 /* If this symbol is defined in a dynamic object, or we are creating
7558 a shared library, we will need to copy any R_MIPS_32 or
7559 R_MIPS_REL32 relocs against it into the output file. */
7560 if (! info
->relocatable
7561 && hmips
->possibly_dynamic_relocs
!= 0
7562 && (h
->root
.type
== bfd_link_hash_defweak
7566 bfd_boolean do_copy
= TRUE
;
7568 if (h
->root
.type
== bfd_link_hash_undefweak
)
7570 /* Do not copy relocations for undefined weak symbols with
7571 non-default visibility. */
7572 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7575 /* Make sure undefined weak symbols are output as a dynamic
7577 else if (h
->dynindx
== -1 && !h
->forced_local
)
7579 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7586 mips_elf_allocate_dynamic_relocations
7587 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
7588 if (hmips
->readonly_reloc
)
7589 /* We tell the dynamic linker that there are relocations
7590 against the text segment. */
7591 info
->flags
|= DF_TEXTREL
;
7598 /* Adjust a symbol defined by a dynamic object and referenced by a
7599 regular object. The current definition is in some section of the
7600 dynamic object, but we're not including those sections. We have to
7601 change the definition to something the rest of the link can
7605 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7606 struct elf_link_hash_entry
*h
)
7609 struct mips_elf_link_hash_entry
*hmips
;
7610 struct mips_elf_link_hash_table
*htab
;
7612 htab
= mips_elf_hash_table (info
);
7613 dynobj
= elf_hash_table (info
)->dynobj
;
7615 /* Make sure we know what is going on here. */
7616 BFD_ASSERT (dynobj
!= NULL
7618 || h
->u
.weakdef
!= NULL
7621 && !h
->def_regular
)));
7623 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7625 /* For a function, create a stub, if allowed. */
7626 if (! hmips
->no_fn_stub
7629 if (! elf_hash_table (info
)->dynamic_sections_created
)
7632 /* If this symbol is not defined in a regular file, then set
7633 the symbol to the stub location. This is required to make
7634 function pointers compare as equal between the normal
7635 executable and the shared library. */
7636 if (!h
->def_regular
)
7638 hmips
->needs_lazy_stub
= TRUE
;
7639 htab
->lazy_stub_count
++;
7643 else if ((h
->type
== STT_FUNC
)
7646 /* This will set the entry for this symbol in the GOT to 0, and
7647 the dynamic linker will take care of this. */
7648 h
->root
.u
.def
.value
= 0;
7652 /* If this is a weak symbol, and there is a real definition, the
7653 processor independent code will have arranged for us to see the
7654 real definition first, and we can just use the same value. */
7655 if (h
->u
.weakdef
!= NULL
)
7657 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7658 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7659 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7660 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7664 /* This is a reference to a symbol defined by a dynamic object which
7665 is not a function. */
7670 /* Likewise, for VxWorks. */
7673 _bfd_mips_vxworks_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7674 struct elf_link_hash_entry
*h
)
7677 struct mips_elf_link_hash_entry
*hmips
;
7678 struct mips_elf_link_hash_table
*htab
;
7680 htab
= mips_elf_hash_table (info
);
7681 dynobj
= elf_hash_table (info
)->dynobj
;
7682 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7684 /* Make sure we know what is going on here. */
7685 BFD_ASSERT (dynobj
!= NULL
7688 || h
->u
.weakdef
!= NULL
7691 && !h
->def_regular
)));
7693 /* If the symbol is defined by a dynamic object, we need a PLT stub if
7694 either (a) we want to branch to the symbol or (b) we're linking an
7695 executable that needs a canonical function address. In the latter
7696 case, the canonical address will be the address of the executable's
7698 if ((hmips
->is_branch_target
7700 && h
->type
== STT_FUNC
7701 && hmips
->is_relocation_target
))
7705 && !h
->forced_local
)
7708 /* Locally-binding symbols do not need a PLT stub; we can refer to
7709 the functions directly. */
7710 else if (h
->needs_plt
7711 && (SYMBOL_CALLS_LOCAL (info
, h
)
7712 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
7713 && h
->root
.type
== bfd_link_hash_undefweak
)))
7721 /* If this is the first symbol to need a PLT entry, allocate room
7722 for the header, and for the header's .rela.plt.unloaded entries. */
7723 if (htab
->splt
->size
== 0)
7725 htab
->splt
->size
+= htab
->plt_header_size
;
7727 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
7730 /* Assign the next .plt entry to this symbol. */
7731 h
->plt
.offset
= htab
->splt
->size
;
7732 htab
->splt
->size
+= htab
->plt_entry_size
;
7734 /* If the output file has no definition of the symbol, set the
7735 symbol's value to the address of the stub. Point at the PLT
7736 load stub rather than the lazy resolution stub; this stub
7737 will become the canonical function address. */
7738 if (!info
->shared
&& !h
->def_regular
)
7740 h
->root
.u
.def
.section
= htab
->splt
;
7741 h
->root
.u
.def
.value
= h
->plt
.offset
;
7742 h
->root
.u
.def
.value
+= 8;
7745 /* Make room for the .got.plt entry and the R_JUMP_SLOT relocation. */
7746 htab
->sgotplt
->size
+= 4;
7747 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
7749 /* Make room for the .rela.plt.unloaded relocations. */
7751 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
7756 /* If a function symbol is defined by a dynamic object, and we do not
7757 need a PLT stub for it, the symbol's value should be zero. */
7758 if (h
->type
== STT_FUNC
7763 h
->root
.u
.def
.value
= 0;
7767 /* If this is a weak symbol, and there is a real definition, the
7768 processor independent code will have arranged for us to see the
7769 real definition first, and we can just use the same value. */
7770 if (h
->u
.weakdef
!= NULL
)
7772 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7773 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7774 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7775 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7779 /* This is a reference to a symbol defined by a dynamic object which
7780 is not a function. */
7784 /* We must allocate the symbol in our .dynbss section, which will
7785 become part of the .bss section of the executable. There will be
7786 an entry for this symbol in the .dynsym section. The dynamic
7787 object will contain position independent code, so all references
7788 from the dynamic object to this symbol will go through the global
7789 offset table. The dynamic linker will use the .dynsym entry to
7790 determine the address it must put in the global offset table, so
7791 both the dynamic object and the regular object will refer to the
7792 same memory location for the variable. */
7794 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
7796 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
7800 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
7803 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
7804 The number might be exact or a worst-case estimate, depending on how
7805 much information is available to elf_backend_omit_section_dynsym at
7806 the current linking stage. */
7808 static bfd_size_type
7809 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
7811 bfd_size_type count
;
7814 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
7817 const struct elf_backend_data
*bed
;
7819 bed
= get_elf_backend_data (output_bfd
);
7820 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
7821 if ((p
->flags
& SEC_EXCLUDE
) == 0
7822 && (p
->flags
& SEC_ALLOC
) != 0
7823 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
7829 /* This function is called after all the input files have been read,
7830 and the input sections have been assigned to output sections. We
7831 check for any mips16 stub sections that we can discard. */
7834 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
7835 struct bfd_link_info
*info
)
7838 struct mips_elf_link_hash_table
*htab
;
7840 htab
= mips_elf_hash_table (info
);
7842 /* The .reginfo section has a fixed size. */
7843 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
7845 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
7847 if (! (info
->relocatable
7848 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
))
7849 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7850 mips_elf_check_mips16_stubs
, info
);
7855 /* If the link uses a GOT, lay it out and work out its size. */
7858 mips_elf_lay_out_got (bfd
*output_bfd
, struct bfd_link_info
*info
)
7862 struct mips_got_info
*g
;
7864 bfd_size_type loadable_size
= 0;
7865 bfd_size_type page_gotno
;
7867 struct mips_elf_count_tls_arg count_tls_arg
;
7868 struct mips_elf_link_hash_table
*htab
;
7870 htab
= mips_elf_hash_table (info
);
7875 dynobj
= elf_hash_table (info
)->dynobj
;
7878 /* Replace entries for indirect and warning symbols with entries for
7879 the target symbol. */
7880 if (!mips_elf_resolve_final_got_entries (g
))
7883 /* Count the number of forced-local entries. */
7884 elf_link_hash_traverse (elf_hash_table (info
),
7885 mips_elf_count_forced_local_got_symbols
, g
);
7887 /* There has to be a global GOT entry for every symbol with
7888 a dynamic symbol table index of DT_MIPS_GOTSYM or
7889 higher. Therefore, it make sense to put those symbols
7890 that need GOT entries at the end of the symbol table. We
7892 if (! mips_elf_sort_hash_table (info
, 1))
7895 if (g
->global_gotsym
!= NULL
)
7896 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
7898 /* If there are no global symbols, or none requiring
7899 relocations, then GLOBAL_GOTSYM will be NULL. */
7902 /* Calculate the total loadable size of the output. That
7903 will give us the maximum number of GOT_PAGE entries
7905 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
7907 asection
*subsection
;
7909 for (subsection
= sub
->sections
;
7911 subsection
= subsection
->next
)
7913 if ((subsection
->flags
& SEC_ALLOC
) == 0)
7915 loadable_size
+= ((subsection
->size
+ 0xf)
7916 &~ (bfd_size_type
) 0xf);
7920 if (htab
->is_vxworks
)
7921 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
7922 relocations against local symbols evaluate to "G", and the EABI does
7923 not include R_MIPS_GOT_PAGE. */
7926 /* Assume there are two loadable segments consisting of contiguous
7927 sections. Is 5 enough? */
7928 page_gotno
= (loadable_size
>> 16) + 5;
7930 /* Choose the smaller of the two estimates; both are intended to be
7932 if (page_gotno
> g
->page_gotno
)
7933 page_gotno
= g
->page_gotno
;
7935 g
->local_gotno
+= page_gotno
;
7936 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7938 g
->global_gotno
= i
;
7939 s
->size
+= i
* MIPS_ELF_GOT_SIZE (output_bfd
);
7941 /* We need to calculate tls_gotno for global symbols at this point
7942 instead of building it up earlier, to avoid doublecounting
7943 entries for one global symbol from multiple input files. */
7944 count_tls_arg
.info
= info
;
7945 count_tls_arg
.needed
= 0;
7946 elf_link_hash_traverse (elf_hash_table (info
),
7947 mips_elf_count_global_tls_entries
,
7949 g
->tls_gotno
+= count_tls_arg
.needed
;
7950 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7952 /* VxWorks does not support multiple GOTs. It initializes $gp to
7953 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
7955 if (htab
->is_vxworks
)
7957 /* VxWorks executables do not need a GOT. */
7960 /* Each VxWorks GOT entry needs an explicit relocation. */
7963 count
= g
->global_gotno
+ g
->local_gotno
- MIPS_RESERVED_GOTNO (info
);
7965 mips_elf_allocate_dynamic_relocations (dynobj
, info
, count
);
7968 else if (s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
7970 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
7975 struct mips_elf_count_tls_arg arg
;
7977 /* Set up TLS entries. */
7978 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
7979 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
7981 /* Allocate room for the TLS relocations. */
7984 htab_traverse (g
->got_entries
, mips_elf_count_local_tls_relocs
, &arg
);
7985 elf_link_hash_traverse (elf_hash_table (info
),
7986 mips_elf_count_global_tls_relocs
,
7989 mips_elf_allocate_dynamic_relocations (dynobj
, info
, arg
.needed
);
7995 /* Estimate the size of the .MIPS.stubs section. */
7998 mips_elf_estimate_stub_size (bfd
*output_bfd
, struct bfd_link_info
*info
)
8000 struct mips_elf_link_hash_table
*htab
;
8001 bfd_size_type dynsymcount
;
8003 htab
= mips_elf_hash_table (info
);
8004 if (htab
->lazy_stub_count
== 0)
8007 /* IRIX rld assumes that a function stub isn't at the end of the .text
8008 section, so add a dummy entry to the end. */
8009 htab
->lazy_stub_count
++;
8011 /* Get a worst-case estimate of the number of dynamic symbols needed.
8012 At this point, dynsymcount does not account for section symbols
8013 and count_section_dynsyms may overestimate the number that will
8015 dynsymcount
= (elf_hash_table (info
)->dynsymcount
8016 + count_section_dynsyms (output_bfd
, info
));
8018 /* Determine the size of one stub entry. */
8019 htab
->function_stub_size
= (dynsymcount
> 0x10000
8020 ? MIPS_FUNCTION_STUB_BIG_SIZE
8021 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
8023 htab
->sstubs
->size
= htab
->lazy_stub_count
* htab
->function_stub_size
;
8026 /* A mips_elf_link_hash_traverse callback for which DATA points to the
8027 MIPS hash table. If H needs a traditional MIPS lazy-binding stub,
8028 allocate an entry in the stubs section. */
8031 mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry
*h
, void **data
)
8033 struct mips_elf_link_hash_table
*htab
;
8035 htab
= (struct mips_elf_link_hash_table
*) data
;
8036 if (h
->needs_lazy_stub
)
8038 h
->root
.root
.u
.def
.section
= htab
->sstubs
;
8039 h
->root
.root
.u
.def
.value
= htab
->sstubs
->size
;
8040 h
->root
.plt
.offset
= htab
->sstubs
->size
;
8041 htab
->sstubs
->size
+= htab
->function_stub_size
;
8046 /* Allocate offsets in the stubs section to each symbol that needs one.
8047 Set the final size of the .MIPS.stub section. */
8050 mips_elf_lay_out_lazy_stubs (struct bfd_link_info
*info
)
8052 struct mips_elf_link_hash_table
*htab
;
8054 htab
= mips_elf_hash_table (info
);
8055 if (htab
->lazy_stub_count
== 0)
8058 htab
->sstubs
->size
= 0;
8059 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8060 mips_elf_allocate_lazy_stub
, htab
);
8061 htab
->sstubs
->size
+= htab
->function_stub_size
;
8062 BFD_ASSERT (htab
->sstubs
->size
8063 == htab
->lazy_stub_count
* htab
->function_stub_size
);
8066 /* Set the sizes of the dynamic sections. */
8069 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
8070 struct bfd_link_info
*info
)
8074 bfd_boolean reltext
;
8075 struct mips_elf_link_hash_table
*htab
;
8077 htab
= mips_elf_hash_table (info
);
8078 dynobj
= elf_hash_table (info
)->dynobj
;
8079 BFD_ASSERT (dynobj
!= NULL
);
8081 if (elf_hash_table (info
)->dynamic_sections_created
)
8083 /* Set the contents of the .interp section to the interpreter. */
8084 if (info
->executable
)
8086 s
= bfd_get_section_by_name (dynobj
, ".interp");
8087 BFD_ASSERT (s
!= NULL
);
8089 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8091 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8095 /* Allocate space for global sym dynamic relocs. */
8096 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
8098 mips_elf_estimate_stub_size (output_bfd
, info
);
8100 if (!mips_elf_lay_out_got (output_bfd
, info
))
8103 mips_elf_lay_out_lazy_stubs (info
);
8105 /* The check_relocs and adjust_dynamic_symbol entry points have
8106 determined the sizes of the various dynamic sections. Allocate
8109 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8113 /* It's OK to base decisions on the section name, because none
8114 of the dynobj section names depend upon the input files. */
8115 name
= bfd_get_section_name (dynobj
, s
);
8117 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8120 if (CONST_STRNEQ (name
, ".rel"))
8124 const char *outname
;
8127 /* If this relocation section applies to a read only
8128 section, then we probably need a DT_TEXTREL entry.
8129 If the relocation section is .rel(a).dyn, we always
8130 assert a DT_TEXTREL entry rather than testing whether
8131 there exists a relocation to a read only section or
8133 outname
= bfd_get_section_name (output_bfd
,
8135 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8137 && (target
->flags
& SEC_READONLY
) != 0
8138 && (target
->flags
& SEC_ALLOC
) != 0)
8139 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
8142 /* We use the reloc_count field as a counter if we need
8143 to copy relocs into the output file. */
8144 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
8147 /* If combreloc is enabled, elf_link_sort_relocs() will
8148 sort relocations, but in a different way than we do,
8149 and before we're done creating relocations. Also, it
8150 will move them around between input sections'
8151 relocation's contents, so our sorting would be
8152 broken, so don't let it run. */
8153 info
->combreloc
= 0;
8156 else if (! info
->shared
8157 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8158 && CONST_STRNEQ (name
, ".rld_map"))
8160 /* We add a room for __rld_map. It will be filled in by the
8161 rtld to contain a pointer to the _r_debug structure. */
8164 else if (SGI_COMPAT (output_bfd
)
8165 && CONST_STRNEQ (name
, ".compact_rel"))
8166 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8167 else if (! CONST_STRNEQ (name
, ".init")
8169 && s
!= htab
->sgotplt
8171 && s
!= htab
->sstubs
)
8173 /* It's not one of our sections, so don't allocate space. */
8179 s
->flags
|= SEC_EXCLUDE
;
8183 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8186 /* Allocate memory for the section contents. */
8187 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
8188 if (s
->contents
== NULL
)
8190 bfd_set_error (bfd_error_no_memory
);
8195 if (elf_hash_table (info
)->dynamic_sections_created
)
8197 /* Add some entries to the .dynamic section. We fill in the
8198 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
8199 must add the entries now so that we get the correct size for
8200 the .dynamic section. */
8202 /* SGI object has the equivalence of DT_DEBUG in the
8203 DT_MIPS_RLD_MAP entry. This must come first because glibc
8204 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and GDB only
8205 looks at the first one it sees. */
8207 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8210 /* The DT_DEBUG entry may be filled in by the dynamic linker and
8211 used by the debugger. */
8212 if (info
->executable
8213 && !SGI_COMPAT (output_bfd
)
8214 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8217 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
8218 info
->flags
|= DF_TEXTREL
;
8220 if ((info
->flags
& DF_TEXTREL
) != 0)
8222 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8225 /* Clear the DF_TEXTREL flag. It will be set again if we
8226 write out an actual text relocation; we may not, because
8227 at this point we do not know whether e.g. any .eh_frame
8228 absolute relocations have been converted to PC-relative. */
8229 info
->flags
&= ~DF_TEXTREL
;
8232 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8235 if (htab
->is_vxworks
)
8237 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
8238 use any of the DT_MIPS_* tags. */
8239 if (mips_elf_rel_dyn_section (info
, FALSE
))
8241 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
8244 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
8247 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
8250 if (htab
->splt
->size
> 0)
8252 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
8255 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
8258 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
8264 if (mips_elf_rel_dyn_section (info
, FALSE
))
8266 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8269 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8272 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8276 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8279 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8282 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8285 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8288 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8291 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8294 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8297 if (IRIX_COMPAT (dynobj
) == ict_irix5
8298 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8301 if (IRIX_COMPAT (dynobj
) == ict_irix6
8302 && (bfd_get_section_by_name
8303 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8304 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8307 if (htab
->is_vxworks
8308 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
8315 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
8316 Adjust its R_ADDEND field so that it is correct for the output file.
8317 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
8318 and sections respectively; both use symbol indexes. */
8321 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
8322 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
8323 asection
**local_sections
, Elf_Internal_Rela
*rel
)
8325 unsigned int r_type
, r_symndx
;
8326 Elf_Internal_Sym
*sym
;
8329 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8331 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8332 if (r_type
== R_MIPS16_GPREL
8333 || r_type
== R_MIPS_GPREL16
8334 || r_type
== R_MIPS_GPREL32
8335 || r_type
== R_MIPS_LITERAL
)
8337 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
8338 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
8341 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
8342 sym
= local_syms
+ r_symndx
;
8344 /* Adjust REL's addend to account for section merging. */
8345 if (!info
->relocatable
)
8347 sec
= local_sections
[r_symndx
];
8348 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
8351 /* This would normally be done by the rela_normal code in elflink.c. */
8352 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8353 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
8357 /* Relocate a MIPS ELF section. */
8360 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
8361 bfd
*input_bfd
, asection
*input_section
,
8362 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
8363 Elf_Internal_Sym
*local_syms
,
8364 asection
**local_sections
)
8366 Elf_Internal_Rela
*rel
;
8367 const Elf_Internal_Rela
*relend
;
8369 bfd_boolean use_saved_addend_p
= FALSE
;
8370 const struct elf_backend_data
*bed
;
8372 bed
= get_elf_backend_data (output_bfd
);
8373 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8374 for (rel
= relocs
; rel
< relend
; ++rel
)
8378 reloc_howto_type
*howto
;
8379 bfd_boolean require_jalx
;
8380 /* TRUE if the relocation is a RELA relocation, rather than a
8382 bfd_boolean rela_relocation_p
= TRUE
;
8383 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8385 unsigned long r_symndx
;
8387 Elf_Internal_Shdr
*symtab_hdr
;
8388 struct elf_link_hash_entry
*h
;
8390 /* Find the relocation howto for this relocation. */
8391 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
8392 NEWABI_P (input_bfd
)
8393 && (MIPS_RELOC_RELA_P
8394 (input_bfd
, input_section
,
8397 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
8398 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
8399 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8401 sec
= local_sections
[r_symndx
];
8406 unsigned long extsymoff
;
8409 if (!elf_bad_symtab (input_bfd
))
8410 extsymoff
= symtab_hdr
->sh_info
;
8411 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
8412 while (h
->root
.type
== bfd_link_hash_indirect
8413 || h
->root
.type
== bfd_link_hash_warning
)
8414 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8417 if (h
->root
.type
== bfd_link_hash_defined
8418 || h
->root
.type
== bfd_link_hash_defweak
)
8419 sec
= h
->root
.u
.def
.section
;
8422 if (sec
!= NULL
&& elf_discarded_section (sec
))
8424 /* For relocs against symbols from removed linkonce sections,
8425 or sections discarded by a linker script, we just want the
8426 section contents zeroed. Avoid any special processing. */
8427 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
8433 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
8435 /* Some 32-bit code uses R_MIPS_64. In particular, people use
8436 64-bit code, but make sure all their addresses are in the
8437 lowermost or uppermost 32-bit section of the 64-bit address
8438 space. Thus, when they use an R_MIPS_64 they mean what is
8439 usually meant by R_MIPS_32, with the exception that the
8440 stored value is sign-extended to 64 bits. */
8441 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
8443 /* On big-endian systems, we need to lie about the position
8445 if (bfd_big_endian (input_bfd
))
8449 if (!use_saved_addend_p
)
8451 /* If these relocations were originally of the REL variety,
8452 we must pull the addend out of the field that will be
8453 relocated. Otherwise, we simply use the contents of the
8455 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
8458 rela_relocation_p
= FALSE
;
8459 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
8461 if (hi16_reloc_p (r_type
)
8462 || (got16_reloc_p (r_type
)
8463 && mips_elf_local_relocation_p (input_bfd
, rel
,
8464 local_sections
, FALSE
)))
8466 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
8472 name
= h
->root
.root
.string
;
8474 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
8475 local_syms
+ r_symndx
,
8477 (*_bfd_error_handler
)
8478 (_("%B: Can't find matching LO16 reloc against `%s' for %s at 0x%lx in section `%A'"),
8479 input_bfd
, input_section
, name
, howto
->name
,
8484 addend
<<= howto
->rightshift
;
8487 addend
= rel
->r_addend
;
8488 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
8489 local_syms
, local_sections
, rel
);
8492 if (info
->relocatable
)
8494 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
8495 && bfd_big_endian (input_bfd
))
8498 if (!rela_relocation_p
&& rel
->r_addend
)
8500 addend
+= rel
->r_addend
;
8501 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
8502 addend
= mips_elf_high (addend
);
8503 else if (r_type
== R_MIPS_HIGHER
)
8504 addend
= mips_elf_higher (addend
);
8505 else if (r_type
== R_MIPS_HIGHEST
)
8506 addend
= mips_elf_highest (addend
);
8508 addend
>>= howto
->rightshift
;
8510 /* We use the source mask, rather than the destination
8511 mask because the place to which we are writing will be
8512 source of the addend in the final link. */
8513 addend
&= howto
->src_mask
;
8515 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
8516 /* See the comment above about using R_MIPS_64 in the 32-bit
8517 ABI. Here, we need to update the addend. It would be
8518 possible to get away with just using the R_MIPS_32 reloc
8519 but for endianness. */
8525 if (addend
& ((bfd_vma
) 1 << 31))
8527 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
8534 /* If we don't know that we have a 64-bit type,
8535 do two separate stores. */
8536 if (bfd_big_endian (input_bfd
))
8538 /* Store the sign-bits (which are most significant)
8540 low_bits
= sign_bits
;
8546 high_bits
= sign_bits
;
8548 bfd_put_32 (input_bfd
, low_bits
,
8549 contents
+ rel
->r_offset
);
8550 bfd_put_32 (input_bfd
, high_bits
,
8551 contents
+ rel
->r_offset
+ 4);
8555 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
8556 input_bfd
, input_section
,
8561 /* Go on to the next relocation. */
8565 /* In the N32 and 64-bit ABIs there may be multiple consecutive
8566 relocations for the same offset. In that case we are
8567 supposed to treat the output of each relocation as the addend
8569 if (rel
+ 1 < relend
8570 && rel
->r_offset
== rel
[1].r_offset
8571 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
8572 use_saved_addend_p
= TRUE
;
8574 use_saved_addend_p
= FALSE
;
8576 /* Figure out what value we are supposed to relocate. */
8577 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
8578 input_section
, info
, rel
,
8579 addend
, howto
, local_syms
,
8580 local_sections
, &value
,
8581 &name
, &require_jalx
,
8582 use_saved_addend_p
))
8584 case bfd_reloc_continue
:
8585 /* There's nothing to do. */
8588 case bfd_reloc_undefined
:
8589 /* mips_elf_calculate_relocation already called the
8590 undefined_symbol callback. There's no real point in
8591 trying to perform the relocation at this point, so we
8592 just skip ahead to the next relocation. */
8595 case bfd_reloc_notsupported
:
8596 msg
= _("internal error: unsupported relocation error");
8597 info
->callbacks
->warning
8598 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
8601 case bfd_reloc_overflow
:
8602 if (use_saved_addend_p
)
8603 /* Ignore overflow until we reach the last relocation for
8604 a given location. */
8608 struct mips_elf_link_hash_table
*htab
;
8610 htab
= mips_elf_hash_table (info
);
8611 BFD_ASSERT (name
!= NULL
);
8612 if (!htab
->small_data_overflow_reported
8613 && (howto
->type
== R_MIPS_GPREL16
8614 || howto
->type
== R_MIPS_LITERAL
))
8617 _("small-data section exceeds 64KB;"
8618 " lower small-data size limit (see option -G)");
8620 htab
->small_data_overflow_reported
= TRUE
;
8621 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
8623 if (! ((*info
->callbacks
->reloc_overflow
)
8624 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
8625 input_bfd
, input_section
, rel
->r_offset
)))
8638 /* If we've got another relocation for the address, keep going
8639 until we reach the last one. */
8640 if (use_saved_addend_p
)
8646 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
8647 /* See the comment above about using R_MIPS_64 in the 32-bit
8648 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
8649 that calculated the right value. Now, however, we
8650 sign-extend the 32-bit result to 64-bits, and store it as a
8651 64-bit value. We are especially generous here in that we
8652 go to extreme lengths to support this usage on systems with
8653 only a 32-bit VMA. */
8659 if (value
& ((bfd_vma
) 1 << 31))
8661 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
8668 /* If we don't know that we have a 64-bit type,
8669 do two separate stores. */
8670 if (bfd_big_endian (input_bfd
))
8672 /* Undo what we did above. */
8674 /* Store the sign-bits (which are most significant)
8676 low_bits
= sign_bits
;
8682 high_bits
= sign_bits
;
8684 bfd_put_32 (input_bfd
, low_bits
,
8685 contents
+ rel
->r_offset
);
8686 bfd_put_32 (input_bfd
, high_bits
,
8687 contents
+ rel
->r_offset
+ 4);
8691 /* Actually perform the relocation. */
8692 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
8693 input_bfd
, input_section
,
8694 contents
, require_jalx
))
8701 /* If NAME is one of the special IRIX6 symbols defined by the linker,
8702 adjust it appropriately now. */
8705 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
8706 const char *name
, Elf_Internal_Sym
*sym
)
8708 /* The linker script takes care of providing names and values for
8709 these, but we must place them into the right sections. */
8710 static const char* const text_section_symbols
[] = {
8713 "__dso_displacement",
8715 "__program_header_table",
8719 static const char* const data_section_symbols
[] = {
8727 const char* const *p
;
8730 for (i
= 0; i
< 2; ++i
)
8731 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
8734 if (strcmp (*p
, name
) == 0)
8736 /* All of these symbols are given type STT_SECTION by the
8738 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8739 sym
->st_other
= STO_PROTECTED
;
8741 /* The IRIX linker puts these symbols in special sections. */
8743 sym
->st_shndx
= SHN_MIPS_TEXT
;
8745 sym
->st_shndx
= SHN_MIPS_DATA
;
8751 /* Finish up dynamic symbol handling. We set the contents of various
8752 dynamic sections here. */
8755 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
8756 struct bfd_link_info
*info
,
8757 struct elf_link_hash_entry
*h
,
8758 Elf_Internal_Sym
*sym
)
8762 struct mips_got_info
*g
, *gg
;
8765 struct mips_elf_link_hash_table
*htab
;
8766 struct mips_elf_link_hash_entry
*hmips
;
8768 htab
= mips_elf_hash_table (info
);
8769 dynobj
= elf_hash_table (info
)->dynobj
;
8770 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8772 if (h
->plt
.offset
!= MINUS_ONE
)
8774 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
8776 /* This symbol has a stub. Set it up. */
8778 BFD_ASSERT (h
->dynindx
!= -1);
8780 BFD_ASSERT ((htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8781 || (h
->dynindx
<= 0xffff));
8783 /* Values up to 2^31 - 1 are allowed. Larger values would cause
8784 sign extension at runtime in the stub, resulting in a negative
8786 if (h
->dynindx
& ~0x7fffffff)
8789 /* Fill the stub. */
8791 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
8793 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ idx
);
8795 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8797 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
8801 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
8804 /* If a large stub is not required and sign extension is not a
8805 problem, then use legacy code in the stub. */
8806 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8807 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff), stub
+ idx
);
8808 else if (h
->dynindx
& ~0x7fff)
8809 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff), stub
+ idx
);
8811 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
8814 BFD_ASSERT (h
->plt
.offset
<= htab
->sstubs
->size
);
8815 memcpy (htab
->sstubs
->contents
+ h
->plt
.offset
,
8816 stub
, htab
->function_stub_size
);
8818 /* Mark the symbol as undefined. plt.offset != -1 occurs
8819 only for the referenced symbol. */
8820 sym
->st_shndx
= SHN_UNDEF
;
8822 /* The run-time linker uses the st_value field of the symbol
8823 to reset the global offset table entry for this external
8824 to its stub address when unlinking a shared object. */
8825 sym
->st_value
= (htab
->sstubs
->output_section
->vma
8826 + htab
->sstubs
->output_offset
8830 /* If we have a MIPS16 function with a stub, the dynamic symbol must
8831 refer to the stub, since only the stub uses the standard calling
8833 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
8835 BFD_ASSERT (hmips
->need_fn_stub
);
8836 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
8837 + hmips
->fn_stub
->output_offset
);
8838 sym
->st_size
= hmips
->fn_stub
->size
;
8839 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
8842 BFD_ASSERT (h
->dynindx
!= -1
8843 || h
->forced_local
);
8845 sgot
= mips_elf_got_section (info
);
8846 BFD_ASSERT (sgot
!= NULL
);
8848 BFD_ASSERT (g
!= NULL
);
8850 /* Run through the global symbol table, creating GOT entries for all
8851 the symbols that need them. */
8852 if (g
->global_gotsym
!= NULL
8853 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
8858 value
= sym
->st_value
;
8859 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
8860 R_MIPS_GOT16
, info
);
8861 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
8864 if (g
->next
&& h
->dynindx
!= -1 && h
->type
!= STT_TLS
)
8866 struct mips_got_entry e
, *p
;
8872 e
.abfd
= output_bfd
;
8877 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
8880 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
8885 || (elf_hash_table (info
)->dynamic_sections_created
8887 && p
->d
.h
->root
.def_dynamic
8888 && !p
->d
.h
->root
.def_regular
))
8890 /* Create an R_MIPS_REL32 relocation for this entry. Due to
8891 the various compatibility problems, it's easier to mock
8892 up an R_MIPS_32 or R_MIPS_64 relocation and leave
8893 mips_elf_create_dynamic_relocation to calculate the
8894 appropriate addend. */
8895 Elf_Internal_Rela rel
[3];
8897 memset (rel
, 0, sizeof (rel
));
8898 if (ABI_64_P (output_bfd
))
8899 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
8901 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
8902 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
8905 if (! (mips_elf_create_dynamic_relocation
8906 (output_bfd
, info
, rel
,
8907 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
8911 entry
= sym
->st_value
;
8912 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
8917 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
8918 name
= h
->root
.root
.string
;
8919 if (strcmp (name
, "_DYNAMIC") == 0
8920 || h
== elf_hash_table (info
)->hgot
)
8921 sym
->st_shndx
= SHN_ABS
;
8922 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
8923 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
8925 sym
->st_shndx
= SHN_ABS
;
8926 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8929 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
8931 sym
->st_shndx
= SHN_ABS
;
8932 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8933 sym
->st_value
= elf_gp (output_bfd
);
8935 else if (SGI_COMPAT (output_bfd
))
8937 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
8938 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
8940 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8941 sym
->st_other
= STO_PROTECTED
;
8943 sym
->st_shndx
= SHN_MIPS_DATA
;
8945 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
8947 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8948 sym
->st_other
= STO_PROTECTED
;
8949 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
8950 sym
->st_shndx
= SHN_ABS
;
8952 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
8954 if (h
->type
== STT_FUNC
)
8955 sym
->st_shndx
= SHN_MIPS_TEXT
;
8956 else if (h
->type
== STT_OBJECT
)
8957 sym
->st_shndx
= SHN_MIPS_DATA
;
8961 /* Handle the IRIX6-specific symbols. */
8962 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8963 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
8967 if (! mips_elf_hash_table (info
)->use_rld_obj_head
8968 && (strcmp (name
, "__rld_map") == 0
8969 || strcmp (name
, "__RLD_MAP") == 0))
8971 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
8972 BFD_ASSERT (s
!= NULL
);
8973 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
8974 bfd_put_32 (output_bfd
, 0, s
->contents
);
8975 if (mips_elf_hash_table (info
)->rld_value
== 0)
8976 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8978 else if (mips_elf_hash_table (info
)->use_rld_obj_head
8979 && strcmp (name
, "__rld_obj_head") == 0)
8981 /* IRIX6 does not use a .rld_map section. */
8982 if (IRIX_COMPAT (output_bfd
) == ict_irix5
8983 || IRIX_COMPAT (output_bfd
) == ict_none
)
8984 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
8986 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8990 /* Keep dynamic MIPS16 symbols odd. This allows the dynamic linker to
8991 treat MIPS16 symbols like any other. */
8992 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
8994 BFD_ASSERT (sym
->st_value
& 1);
8995 sym
->st_other
-= STO_MIPS16
;
9001 /* Likewise, for VxWorks. */
9004 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
9005 struct bfd_link_info
*info
,
9006 struct elf_link_hash_entry
*h
,
9007 Elf_Internal_Sym
*sym
)
9011 struct mips_got_info
*g
;
9012 struct mips_elf_link_hash_table
*htab
;
9014 htab
= mips_elf_hash_table (info
);
9015 dynobj
= elf_hash_table (info
)->dynobj
;
9017 if (h
->plt
.offset
!= (bfd_vma
) -1)
9020 bfd_vma plt_address
, plt_index
, got_address
, got_offset
, branch_offset
;
9021 Elf_Internal_Rela rel
;
9022 static const bfd_vma
*plt_entry
;
9024 BFD_ASSERT (h
->dynindx
!= -1);
9025 BFD_ASSERT (htab
->splt
!= NULL
);
9026 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
9028 /* Calculate the address of the .plt entry. */
9029 plt_address
= (htab
->splt
->output_section
->vma
9030 + htab
->splt
->output_offset
9033 /* Calculate the index of the entry. */
9034 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
9035 / htab
->plt_entry_size
);
9037 /* Calculate the address of the .got.plt entry. */
9038 got_address
= (htab
->sgotplt
->output_section
->vma
9039 + htab
->sgotplt
->output_offset
9042 /* Calculate the offset of the .got.plt entry from
9043 _GLOBAL_OFFSET_TABLE_. */
9044 got_offset
= mips_elf_gotplt_index (info
, h
);
9046 /* Calculate the offset for the branch at the start of the PLT
9047 entry. The branch jumps to the beginning of .plt. */
9048 branch_offset
= -(h
->plt
.offset
/ 4 + 1) & 0xffff;
9050 /* Fill in the initial value of the .got.plt entry. */
9051 bfd_put_32 (output_bfd
, plt_address
,
9052 htab
->sgotplt
->contents
+ plt_index
* 4);
9054 /* Find out where the .plt entry should go. */
9055 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9059 plt_entry
= mips_vxworks_shared_plt_entry
;
9060 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9061 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9065 bfd_vma got_address_high
, got_address_low
;
9067 plt_entry
= mips_vxworks_exec_plt_entry
;
9068 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9069 got_address_low
= got_address
& 0xffff;
9071 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9072 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9073 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
9074 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
9075 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9076 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9077 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9078 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9080 loc
= (htab
->srelplt2
->contents
9081 + (plt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
9083 /* Emit a relocation for the .got.plt entry. */
9084 rel
.r_offset
= got_address
;
9085 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9086 rel
.r_addend
= h
->plt
.offset
;
9087 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9089 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
9090 loc
+= sizeof (Elf32_External_Rela
);
9091 rel
.r_offset
= plt_address
+ 8;
9092 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9093 rel
.r_addend
= got_offset
;
9094 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9096 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
9097 loc
+= sizeof (Elf32_External_Rela
);
9099 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9100 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9103 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9104 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
9105 rel
.r_offset
= got_address
;
9106 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
9108 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9110 if (!h
->def_regular
)
9111 sym
->st_shndx
= SHN_UNDEF
;
9114 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
9116 sgot
= mips_elf_got_section (info
);
9117 BFD_ASSERT (sgot
!= NULL
);
9119 BFD_ASSERT (g
!= NULL
);
9121 /* See if this symbol has an entry in the GOT. */
9122 if (g
->global_gotsym
!= NULL
9123 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
9126 Elf_Internal_Rela outrel
;
9130 /* Install the symbol value in the GOT. */
9131 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9132 R_MIPS_GOT16
, info
);
9133 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
9135 /* Add a dynamic relocation for it. */
9136 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9137 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
9138 outrel
.r_offset
= (sgot
->output_section
->vma
9139 + sgot
->output_offset
9141 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
9142 outrel
.r_addend
= 0;
9143 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
9146 /* Emit a copy reloc, if needed. */
9149 Elf_Internal_Rela rel
;
9151 BFD_ASSERT (h
->dynindx
!= -1);
9153 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
9154 + h
->root
.u
.def
.section
->output_offset
9155 + h
->root
.u
.def
.value
);
9156 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
9158 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
9159 htab
->srelbss
->contents
9160 + (htab
->srelbss
->reloc_count
9161 * sizeof (Elf32_External_Rela
)));
9162 ++htab
->srelbss
->reloc_count
;
9165 /* If this is a mips16 symbol, force the value to be even. */
9166 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9167 sym
->st_value
&= ~1;
9172 /* Install the PLT header for a VxWorks executable and finalize the
9173 contents of .rela.plt.unloaded. */
9176 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9178 Elf_Internal_Rela rela
;
9180 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
9181 static const bfd_vma
*plt_entry
;
9182 struct mips_elf_link_hash_table
*htab
;
9184 htab
= mips_elf_hash_table (info
);
9185 plt_entry
= mips_vxworks_exec_plt0_entry
;
9187 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
9188 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
9189 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
9190 + htab
->root
.hgot
->root
.u
.def
.value
);
9192 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
9193 got_value_low
= got_value
& 0xffff;
9195 /* Calculate the address of the PLT header. */
9196 plt_address
= htab
->splt
->output_section
->vma
+ htab
->splt
->output_offset
;
9198 /* Install the PLT header. */
9199 loc
= htab
->splt
->contents
;
9200 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
9201 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
9202 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
9203 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9204 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9205 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9207 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
9208 loc
= htab
->srelplt2
->contents
;
9209 rela
.r_offset
= plt_address
;
9210 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9212 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9213 loc
+= sizeof (Elf32_External_Rela
);
9215 /* Output the relocation for the following addiu of
9216 %lo(_GLOBAL_OFFSET_TABLE_). */
9218 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9219 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9220 loc
+= sizeof (Elf32_External_Rela
);
9222 /* Fix up the remaining relocations. They may have the wrong
9223 symbol index for _G_O_T_ or _P_L_T_ depending on the order
9224 in which symbols were output. */
9225 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
9227 Elf_Internal_Rela rel
;
9229 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9230 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9231 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9232 loc
+= sizeof (Elf32_External_Rela
);
9234 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9235 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9236 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9237 loc
+= sizeof (Elf32_External_Rela
);
9239 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9240 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9241 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9242 loc
+= sizeof (Elf32_External_Rela
);
9246 /* Install the PLT header for a VxWorks shared library. */
9249 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9252 struct mips_elf_link_hash_table
*htab
;
9254 htab
= mips_elf_hash_table (info
);
9256 /* We just need to copy the entry byte-by-byte. */
9257 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
9258 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
9259 htab
->splt
->contents
+ i
* 4);
9262 /* Finish up the dynamic sections. */
9265 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
9266 struct bfd_link_info
*info
)
9271 struct mips_got_info
*gg
, *g
;
9272 struct mips_elf_link_hash_table
*htab
;
9274 htab
= mips_elf_hash_table (info
);
9275 dynobj
= elf_hash_table (info
)->dynobj
;
9277 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
9279 sgot
= mips_elf_got_section (info
);
9284 gg
= htab
->got_info
;
9285 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
9286 BFD_ASSERT (g
!= NULL
);
9289 if (elf_hash_table (info
)->dynamic_sections_created
)
9292 int dyn_to_skip
= 0, dyn_skipped
= 0;
9294 BFD_ASSERT (sdyn
!= NULL
);
9295 BFD_ASSERT (g
!= NULL
);
9297 for (b
= sdyn
->contents
;
9298 b
< sdyn
->contents
+ sdyn
->size
;
9299 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9301 Elf_Internal_Dyn dyn
;
9305 bfd_boolean swap_out_p
;
9307 /* Read in the current dynamic entry. */
9308 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9310 /* Assume that we're going to modify it and write it out. */
9316 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
9320 BFD_ASSERT (htab
->is_vxworks
);
9321 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
9325 /* Rewrite DT_STRSZ. */
9327 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
9332 if (htab
->is_vxworks
)
9334 /* _GLOBAL_OFFSET_TABLE_ is defined to be the beginning
9335 of the ".got" section in DYNOBJ. */
9336 s
= bfd_get_section_by_name (dynobj
, name
);
9337 BFD_ASSERT (s
!= NULL
);
9338 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9342 s
= bfd_get_section_by_name (output_bfd
, name
);
9343 BFD_ASSERT (s
!= NULL
);
9344 dyn
.d_un
.d_ptr
= s
->vma
;
9348 case DT_MIPS_RLD_VERSION
:
9349 dyn
.d_un
.d_val
= 1; /* XXX */
9353 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
9356 case DT_MIPS_TIME_STAMP
:
9364 case DT_MIPS_ICHECKSUM
:
9369 case DT_MIPS_IVERSION
:
9374 case DT_MIPS_BASE_ADDRESS
:
9375 s
= output_bfd
->sections
;
9376 BFD_ASSERT (s
!= NULL
);
9377 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
9380 case DT_MIPS_LOCAL_GOTNO
:
9381 dyn
.d_un
.d_val
= g
->local_gotno
;
9384 case DT_MIPS_UNREFEXTNO
:
9385 /* The index into the dynamic symbol table which is the
9386 entry of the first external symbol that is not
9387 referenced within the same object. */
9388 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
9391 case DT_MIPS_GOTSYM
:
9392 if (gg
->global_gotsym
)
9394 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
9397 /* In case if we don't have global got symbols we default
9398 to setting DT_MIPS_GOTSYM to the same value as
9399 DT_MIPS_SYMTABNO, so we just fall through. */
9401 case DT_MIPS_SYMTABNO
:
9403 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
9404 s
= bfd_get_section_by_name (output_bfd
, name
);
9405 BFD_ASSERT (s
!= NULL
);
9407 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
9410 case DT_MIPS_HIPAGENO
:
9411 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO (info
);
9414 case DT_MIPS_RLD_MAP
:
9415 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
9418 case DT_MIPS_OPTIONS
:
9419 s
= (bfd_get_section_by_name
9420 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
9421 dyn
.d_un
.d_ptr
= s
->vma
;
9425 BFD_ASSERT (htab
->is_vxworks
);
9426 /* The count does not include the JUMP_SLOT relocations. */
9428 dyn
.d_un
.d_val
-= htab
->srelplt
->size
;
9432 BFD_ASSERT (htab
->is_vxworks
);
9433 dyn
.d_un
.d_val
= DT_RELA
;
9437 BFD_ASSERT (htab
->is_vxworks
);
9438 dyn
.d_un
.d_val
= htab
->srelplt
->size
;
9442 BFD_ASSERT (htab
->is_vxworks
);
9443 dyn
.d_un
.d_val
= (htab
->srelplt
->output_section
->vma
9444 + htab
->srelplt
->output_offset
);
9448 /* If we didn't need any text relocations after all, delete
9450 if (!(info
->flags
& DF_TEXTREL
))
9452 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
9458 /* If we didn't need any text relocations after all, clear
9459 DF_TEXTREL from DT_FLAGS. */
9460 if (!(info
->flags
& DF_TEXTREL
))
9461 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
9468 if (htab
->is_vxworks
9469 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
9474 if (swap_out_p
|| dyn_skipped
)
9475 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
9476 (dynobj
, &dyn
, b
- dyn_skipped
);
9480 dyn_skipped
+= dyn_to_skip
;
9485 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
9486 if (dyn_skipped
> 0)
9487 memset (b
- dyn_skipped
, 0, dyn_skipped
);
9490 if (sgot
!= NULL
&& sgot
->size
> 0
9491 && !bfd_is_abs_section (sgot
->output_section
))
9493 if (htab
->is_vxworks
)
9495 /* The first entry of the global offset table points to the
9496 ".dynamic" section. The second is initialized by the
9497 loader and contains the shared library identifier.
9498 The third is also initialized by the loader and points
9499 to the lazy resolution stub. */
9500 MIPS_ELF_PUT_WORD (output_bfd
,
9501 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
9503 MIPS_ELF_PUT_WORD (output_bfd
, 0,
9504 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
9505 MIPS_ELF_PUT_WORD (output_bfd
, 0,
9507 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
9511 /* The first entry of the global offset table will be filled at
9512 runtime. The second entry will be used by some runtime loaders.
9513 This isn't the case of IRIX rld. */
9514 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
9515 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
9516 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
9519 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
9520 = MIPS_ELF_GOT_SIZE (output_bfd
);
9523 /* Generate dynamic relocations for the non-primary gots. */
9524 if (gg
!= NULL
&& gg
->next
)
9526 Elf_Internal_Rela rel
[3];
9529 memset (rel
, 0, sizeof (rel
));
9530 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
9532 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
9534 bfd_vma index
= g
->next
->local_gotno
+ g
->next
->global_gotno
9535 + g
->next
->tls_gotno
;
9537 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
9538 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
9539 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
9541 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
9546 while (index
< g
->assigned_gotno
)
9548 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
9549 = index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
9550 if (!(mips_elf_create_dynamic_relocation
9551 (output_bfd
, info
, rel
, NULL
,
9552 bfd_abs_section_ptr
,
9555 BFD_ASSERT (addend
== 0);
9560 /* The generation of dynamic relocations for the non-primary gots
9561 adds more dynamic relocations. We cannot count them until
9564 if (elf_hash_table (info
)->dynamic_sections_created
)
9567 bfd_boolean swap_out_p
;
9569 BFD_ASSERT (sdyn
!= NULL
);
9571 for (b
= sdyn
->contents
;
9572 b
< sdyn
->contents
+ sdyn
->size
;
9573 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9575 Elf_Internal_Dyn dyn
;
9578 /* Read in the current dynamic entry. */
9579 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9581 /* Assume that we're going to modify it and write it out. */
9587 /* Reduce DT_RELSZ to account for any relocations we
9588 decided not to make. This is for the n64 irix rld,
9589 which doesn't seem to apply any relocations if there
9590 are trailing null entries. */
9591 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9592 dyn
.d_un
.d_val
= (s
->reloc_count
9593 * (ABI_64_P (output_bfd
)
9594 ? sizeof (Elf64_Mips_External_Rel
)
9595 : sizeof (Elf32_External_Rel
)));
9596 /* Adjust the section size too. Tools like the prelinker
9597 can reasonably expect the values to the same. */
9598 elf_section_data (s
->output_section
)->this_hdr
.sh_size
9608 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
9615 Elf32_compact_rel cpt
;
9617 if (SGI_COMPAT (output_bfd
))
9619 /* Write .compact_rel section out. */
9620 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
9624 cpt
.num
= s
->reloc_count
;
9626 cpt
.offset
= (s
->output_section
->filepos
9627 + sizeof (Elf32_External_compact_rel
));
9630 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
9631 ((Elf32_External_compact_rel
*)
9634 /* Clean up a dummy stub function entry in .text. */
9635 if (htab
->sstubs
!= NULL
)
9637 file_ptr dummy_offset
;
9639 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
9640 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
9641 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
9642 htab
->function_stub_size
);
9647 /* The psABI says that the dynamic relocations must be sorted in
9648 increasing order of r_symndx. The VxWorks EABI doesn't require
9649 this, and because the code below handles REL rather than RELA
9650 relocations, using it for VxWorks would be outright harmful. */
9651 if (!htab
->is_vxworks
)
9653 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9655 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
9657 reldyn_sorting_bfd
= output_bfd
;
9659 if (ABI_64_P (output_bfd
))
9660 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
9661 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
9662 sort_dynamic_relocs_64
);
9664 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
9665 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
9666 sort_dynamic_relocs
);
9671 if (htab
->is_vxworks
&& htab
->splt
->size
> 0)
9674 mips_vxworks_finish_shared_plt (output_bfd
, info
);
9676 mips_vxworks_finish_exec_plt (output_bfd
, info
);
9682 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
9685 mips_set_isa_flags (bfd
*abfd
)
9689 switch (bfd_get_mach (abfd
))
9692 case bfd_mach_mips3000
:
9693 val
= E_MIPS_ARCH_1
;
9696 case bfd_mach_mips3900
:
9697 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
9700 case bfd_mach_mips6000
:
9701 val
= E_MIPS_ARCH_2
;
9704 case bfd_mach_mips4000
:
9705 case bfd_mach_mips4300
:
9706 case bfd_mach_mips4400
:
9707 case bfd_mach_mips4600
:
9708 val
= E_MIPS_ARCH_3
;
9711 case bfd_mach_mips4010
:
9712 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
9715 case bfd_mach_mips4100
:
9716 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
9719 case bfd_mach_mips4111
:
9720 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
9723 case bfd_mach_mips4120
:
9724 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
9727 case bfd_mach_mips4650
:
9728 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
9731 case bfd_mach_mips5400
:
9732 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
9735 case bfd_mach_mips5500
:
9736 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
9739 case bfd_mach_mips9000
:
9740 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
9743 case bfd_mach_mips5000
:
9744 case bfd_mach_mips7000
:
9745 case bfd_mach_mips8000
:
9746 case bfd_mach_mips10000
:
9747 case bfd_mach_mips12000
:
9748 val
= E_MIPS_ARCH_4
;
9751 case bfd_mach_mips5
:
9752 val
= E_MIPS_ARCH_5
;
9755 case bfd_mach_mips_loongson_2e
:
9756 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
9759 case bfd_mach_mips_loongson_2f
:
9760 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
9763 case bfd_mach_mips_sb1
:
9764 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
9767 case bfd_mach_mips_octeon
:
9768 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
9771 case bfd_mach_mipsisa32
:
9772 val
= E_MIPS_ARCH_32
;
9775 case bfd_mach_mipsisa64
:
9776 val
= E_MIPS_ARCH_64
;
9779 case bfd_mach_mipsisa32r2
:
9780 val
= E_MIPS_ARCH_32R2
;
9783 case bfd_mach_mipsisa64r2
:
9784 val
= E_MIPS_ARCH_64R2
;
9787 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
9788 elf_elfheader (abfd
)->e_flags
|= val
;
9793 /* The final processing done just before writing out a MIPS ELF object
9794 file. This gets the MIPS architecture right based on the machine
9795 number. This is used by both the 32-bit and the 64-bit ABI. */
9798 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
9799 bfd_boolean linker ATTRIBUTE_UNUSED
)
9802 Elf_Internal_Shdr
**hdrpp
;
9806 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
9807 is nonzero. This is for compatibility with old objects, which used
9808 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
9809 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
9810 mips_set_isa_flags (abfd
);
9812 /* Set the sh_info field for .gptab sections and other appropriate
9813 info for each special section. */
9814 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
9815 i
< elf_numsections (abfd
);
9818 switch ((*hdrpp
)->sh_type
)
9821 case SHT_MIPS_LIBLIST
:
9822 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
9824 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9827 case SHT_MIPS_GPTAB
:
9828 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9829 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9830 BFD_ASSERT (name
!= NULL
9831 && CONST_STRNEQ (name
, ".gptab."));
9832 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
9833 BFD_ASSERT (sec
!= NULL
);
9834 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
9837 case SHT_MIPS_CONTENT
:
9838 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9839 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9840 BFD_ASSERT (name
!= NULL
9841 && CONST_STRNEQ (name
, ".MIPS.content"));
9842 sec
= bfd_get_section_by_name (abfd
,
9843 name
+ sizeof ".MIPS.content" - 1);
9844 BFD_ASSERT (sec
!= NULL
);
9845 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9848 case SHT_MIPS_SYMBOL_LIB
:
9849 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
9851 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9852 sec
= bfd_get_section_by_name (abfd
, ".liblist");
9854 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
9857 case SHT_MIPS_EVENTS
:
9858 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9859 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9860 BFD_ASSERT (name
!= NULL
);
9861 if (CONST_STRNEQ (name
, ".MIPS.events"))
9862 sec
= bfd_get_section_by_name (abfd
,
9863 name
+ sizeof ".MIPS.events" - 1);
9866 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
9867 sec
= bfd_get_section_by_name (abfd
,
9869 + sizeof ".MIPS.post_rel" - 1));
9871 BFD_ASSERT (sec
!= NULL
);
9872 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9879 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
9883 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
9884 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
9889 /* See if we need a PT_MIPS_REGINFO segment. */
9890 s
= bfd_get_section_by_name (abfd
, ".reginfo");
9891 if (s
&& (s
->flags
& SEC_LOAD
))
9894 /* See if we need a PT_MIPS_OPTIONS segment. */
9895 if (IRIX_COMPAT (abfd
) == ict_irix6
9896 && bfd_get_section_by_name (abfd
,
9897 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
9900 /* See if we need a PT_MIPS_RTPROC segment. */
9901 if (IRIX_COMPAT (abfd
) == ict_irix5
9902 && bfd_get_section_by_name (abfd
, ".dynamic")
9903 && bfd_get_section_by_name (abfd
, ".mdebug"))
9906 /* Allocate a PT_NULL header in dynamic objects. See
9907 _bfd_mips_elf_modify_segment_map for details. */
9908 if (!SGI_COMPAT (abfd
)
9909 && bfd_get_section_by_name (abfd
, ".dynamic"))
9915 /* Modify the segment map for an IRIX5 executable. */
9918 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
9919 struct bfd_link_info
*info
)
9922 struct elf_segment_map
*m
, **pm
;
9925 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
9927 s
= bfd_get_section_by_name (abfd
, ".reginfo");
9928 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
9930 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
9931 if (m
->p_type
== PT_MIPS_REGINFO
)
9936 m
= bfd_zalloc (abfd
, amt
);
9940 m
->p_type
= PT_MIPS_REGINFO
;
9944 /* We want to put it after the PHDR and INTERP segments. */
9945 pm
= &elf_tdata (abfd
)->segment_map
;
9947 && ((*pm
)->p_type
== PT_PHDR
9948 || (*pm
)->p_type
== PT_INTERP
))
9956 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
9957 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
9958 PT_MIPS_OPTIONS segment immediately following the program header
9961 /* On non-IRIX6 new abi, we'll have already created a segment
9962 for this section, so don't create another. I'm not sure this
9963 is not also the case for IRIX 6, but I can't test it right
9965 && IRIX_COMPAT (abfd
) == ict_irix6
)
9967 for (s
= abfd
->sections
; s
; s
= s
->next
)
9968 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
9973 struct elf_segment_map
*options_segment
;
9975 pm
= &elf_tdata (abfd
)->segment_map
;
9977 && ((*pm
)->p_type
== PT_PHDR
9978 || (*pm
)->p_type
== PT_INTERP
))
9981 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
9983 amt
= sizeof (struct elf_segment_map
);
9984 options_segment
= bfd_zalloc (abfd
, amt
);
9985 options_segment
->next
= *pm
;
9986 options_segment
->p_type
= PT_MIPS_OPTIONS
;
9987 options_segment
->p_flags
= PF_R
;
9988 options_segment
->p_flags_valid
= TRUE
;
9989 options_segment
->count
= 1;
9990 options_segment
->sections
[0] = s
;
9991 *pm
= options_segment
;
9997 if (IRIX_COMPAT (abfd
) == ict_irix5
)
9999 /* If there are .dynamic and .mdebug sections, we make a room
10000 for the RTPROC header. FIXME: Rewrite without section names. */
10001 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
10002 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
10003 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
10005 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
10006 if (m
->p_type
== PT_MIPS_RTPROC
)
10011 m
= bfd_zalloc (abfd
, amt
);
10015 m
->p_type
= PT_MIPS_RTPROC
;
10017 s
= bfd_get_section_by_name (abfd
, ".rtproc");
10022 m
->p_flags_valid
= 1;
10027 m
->sections
[0] = s
;
10030 /* We want to put it after the DYNAMIC segment. */
10031 pm
= &elf_tdata (abfd
)->segment_map
;
10032 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
10042 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
10043 .dynstr, .dynsym, and .hash sections, and everything in
10045 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
10047 if ((*pm
)->p_type
== PT_DYNAMIC
)
10050 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
10052 /* For a normal mips executable the permissions for the PT_DYNAMIC
10053 segment are read, write and execute. We do that here since
10054 the code in elf.c sets only the read permission. This matters
10055 sometimes for the dynamic linker. */
10056 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
10058 m
->p_flags
= PF_R
| PF_W
| PF_X
;
10059 m
->p_flags_valid
= 1;
10062 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
10063 glibc's dynamic linker has traditionally derived the number of
10064 tags from the p_filesz field, and sometimes allocates stack
10065 arrays of that size. An overly-big PT_DYNAMIC segment can
10066 be actively harmful in such cases. Making PT_DYNAMIC contain
10067 other sections can also make life hard for the prelinker,
10068 which might move one of the other sections to a different
10069 PT_LOAD segment. */
10070 if (SGI_COMPAT (abfd
)
10073 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
10075 static const char *sec_names
[] =
10077 ".dynamic", ".dynstr", ".dynsym", ".hash"
10081 struct elf_segment_map
*n
;
10083 low
= ~(bfd_vma
) 0;
10085 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
10087 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
10088 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10095 if (high
< s
->vma
+ sz
)
10096 high
= s
->vma
+ sz
;
10101 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10102 if ((s
->flags
& SEC_LOAD
) != 0
10104 && s
->vma
+ s
->size
<= high
)
10107 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
10108 n
= bfd_zalloc (abfd
, amt
);
10115 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10117 if ((s
->flags
& SEC_LOAD
) != 0
10119 && s
->vma
+ s
->size
<= high
)
10121 n
->sections
[i
] = s
;
10130 /* Allocate a spare program header in dynamic objects so that tools
10131 like the prelinker can add an extra PT_LOAD entry.
10133 If the prelinker needs to make room for a new PT_LOAD entry, its
10134 standard procedure is to move the first (read-only) sections into
10135 the new (writable) segment. However, the MIPS ABI requires
10136 .dynamic to be in a read-only segment, and the section will often
10137 start within sizeof (ElfNN_Phdr) bytes of the last program header.
10139 Although the prelinker could in principle move .dynamic to a
10140 writable segment, it seems better to allocate a spare program
10141 header instead, and avoid the need to move any sections.
10142 There is a long tradition of allocating spare dynamic tags,
10143 so allocating a spare program header seems like a natural
10146 If INFO is NULL, we may be copying an already prelinked binary
10147 with objcopy or strip, so do not add this header. */
10149 && !SGI_COMPAT (abfd
)
10150 && bfd_get_section_by_name (abfd
, ".dynamic"))
10152 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
10153 if ((*pm
)->p_type
== PT_NULL
)
10157 m
= bfd_zalloc (abfd
, sizeof (*m
));
10161 m
->p_type
= PT_NULL
;
10169 /* Return the section that should be marked against GC for a given
10173 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
10174 struct bfd_link_info
*info
,
10175 Elf_Internal_Rela
*rel
,
10176 struct elf_link_hash_entry
*h
,
10177 Elf_Internal_Sym
*sym
)
10179 /* ??? Do mips16 stub sections need to be handled special? */
10182 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
10184 case R_MIPS_GNU_VTINHERIT
:
10185 case R_MIPS_GNU_VTENTRY
:
10189 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
10192 /* Update the got entry reference counts for the section being removed. */
10195 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
10196 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
10197 asection
*sec ATTRIBUTE_UNUSED
,
10198 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
10201 Elf_Internal_Shdr
*symtab_hdr
;
10202 struct elf_link_hash_entry
**sym_hashes
;
10203 bfd_signed_vma
*local_got_refcounts
;
10204 const Elf_Internal_Rela
*rel
, *relend
;
10205 unsigned long r_symndx
;
10206 struct elf_link_hash_entry
*h
;
10208 if (info
->relocatable
)
10211 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
10212 sym_hashes
= elf_sym_hashes (abfd
);
10213 local_got_refcounts
= elf_local_got_refcounts (abfd
);
10215 relend
= relocs
+ sec
->reloc_count
;
10216 for (rel
= relocs
; rel
< relend
; rel
++)
10217 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
10219 case R_MIPS16_GOT16
:
10220 case R_MIPS16_CALL16
:
10222 case R_MIPS_CALL16
:
10223 case R_MIPS_CALL_HI16
:
10224 case R_MIPS_CALL_LO16
:
10225 case R_MIPS_GOT_HI16
:
10226 case R_MIPS_GOT_LO16
:
10227 case R_MIPS_GOT_DISP
:
10228 case R_MIPS_GOT_PAGE
:
10229 case R_MIPS_GOT_OFST
:
10230 /* ??? It would seem that the existing MIPS code does no sort
10231 of reference counting or whatnot on its GOT and PLT entries,
10232 so it is not possible to garbage collect them at this time. */
10243 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
10244 hiding the old indirect symbol. Process additional relocation
10245 information. Also called for weakdefs, in which case we just let
10246 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
10249 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
10250 struct elf_link_hash_entry
*dir
,
10251 struct elf_link_hash_entry
*ind
)
10253 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
10255 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
10257 if (ind
->root
.type
!= bfd_link_hash_indirect
)
10260 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
10261 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
10262 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
10263 if (indmips
->readonly_reloc
)
10264 dirmips
->readonly_reloc
= TRUE
;
10265 if (indmips
->no_fn_stub
)
10266 dirmips
->no_fn_stub
= TRUE
;
10268 if (dirmips
->tls_type
== 0)
10269 dirmips
->tls_type
= indmips
->tls_type
;
10272 #define PDR_SIZE 32
10275 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
10276 struct bfd_link_info
*info
)
10279 bfd_boolean ret
= FALSE
;
10280 unsigned char *tdata
;
10283 o
= bfd_get_section_by_name (abfd
, ".pdr");
10288 if (o
->size
% PDR_SIZE
!= 0)
10290 if (o
->output_section
!= NULL
10291 && bfd_is_abs_section (o
->output_section
))
10294 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
10298 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
10299 info
->keep_memory
);
10306 cookie
->rel
= cookie
->rels
;
10307 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
10309 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
10311 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
10320 mips_elf_section_data (o
)->u
.tdata
= tdata
;
10321 o
->size
-= skip
* PDR_SIZE
;
10327 if (! info
->keep_memory
)
10328 free (cookie
->rels
);
10334 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
10336 if (strcmp (sec
->name
, ".pdr") == 0)
10342 _bfd_mips_elf_write_section (bfd
*output_bfd
,
10343 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
10344 asection
*sec
, bfd_byte
*contents
)
10346 bfd_byte
*to
, *from
, *end
;
10349 if (strcmp (sec
->name
, ".pdr") != 0)
10352 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
10356 end
= contents
+ sec
->size
;
10357 for (from
= contents
, i
= 0;
10359 from
+= PDR_SIZE
, i
++)
10361 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
10364 memcpy (to
, from
, PDR_SIZE
);
10367 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
10368 sec
->output_offset
, sec
->size
);
10372 /* MIPS ELF uses a special find_nearest_line routine in order the
10373 handle the ECOFF debugging information. */
10375 struct mips_elf_find_line
10377 struct ecoff_debug_info d
;
10378 struct ecoff_find_line i
;
10382 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
10383 asymbol
**symbols
, bfd_vma offset
,
10384 const char **filename_ptr
,
10385 const char **functionname_ptr
,
10386 unsigned int *line_ptr
)
10390 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
10391 filename_ptr
, functionname_ptr
,
10395 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
10396 filename_ptr
, functionname_ptr
,
10397 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
10398 &elf_tdata (abfd
)->dwarf2_find_line_info
))
10401 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
10404 flagword origflags
;
10405 struct mips_elf_find_line
*fi
;
10406 const struct ecoff_debug_swap
* const swap
=
10407 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
10409 /* If we are called during a link, mips_elf_final_link may have
10410 cleared the SEC_HAS_CONTENTS field. We force it back on here
10411 if appropriate (which it normally will be). */
10412 origflags
= msec
->flags
;
10413 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
10414 msec
->flags
|= SEC_HAS_CONTENTS
;
10416 fi
= elf_tdata (abfd
)->find_line_info
;
10419 bfd_size_type external_fdr_size
;
10422 struct fdr
*fdr_ptr
;
10423 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
10425 fi
= bfd_zalloc (abfd
, amt
);
10428 msec
->flags
= origflags
;
10432 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
10434 msec
->flags
= origflags
;
10438 /* Swap in the FDR information. */
10439 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
10440 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
10441 if (fi
->d
.fdr
== NULL
)
10443 msec
->flags
= origflags
;
10446 external_fdr_size
= swap
->external_fdr_size
;
10447 fdr_ptr
= fi
->d
.fdr
;
10448 fraw_src
= (char *) fi
->d
.external_fdr
;
10449 fraw_end
= (fraw_src
10450 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
10451 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
10452 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
10454 elf_tdata (abfd
)->find_line_info
= fi
;
10456 /* Note that we don't bother to ever free this information.
10457 find_nearest_line is either called all the time, as in
10458 objdump -l, so the information should be saved, or it is
10459 rarely called, as in ld error messages, so the memory
10460 wasted is unimportant. Still, it would probably be a
10461 good idea for free_cached_info to throw it away. */
10464 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
10465 &fi
->i
, filename_ptr
, functionname_ptr
,
10468 msec
->flags
= origflags
;
10472 msec
->flags
= origflags
;
10475 /* Fall back on the generic ELF find_nearest_line routine. */
10477 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
10478 filename_ptr
, functionname_ptr
,
10483 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
10484 const char **filename_ptr
,
10485 const char **functionname_ptr
,
10486 unsigned int *line_ptr
)
10489 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
10490 functionname_ptr
, line_ptr
,
10491 & elf_tdata (abfd
)->dwarf2_find_line_info
);
10496 /* When are writing out the .options or .MIPS.options section,
10497 remember the bytes we are writing out, so that we can install the
10498 GP value in the section_processing routine. */
10501 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
10502 const void *location
,
10503 file_ptr offset
, bfd_size_type count
)
10505 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
10509 if (elf_section_data (section
) == NULL
)
10511 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
10512 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
10513 if (elf_section_data (section
) == NULL
)
10516 c
= mips_elf_section_data (section
)->u
.tdata
;
10519 c
= bfd_zalloc (abfd
, section
->size
);
10522 mips_elf_section_data (section
)->u
.tdata
= c
;
10525 memcpy (c
+ offset
, location
, count
);
10528 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
10532 /* This is almost identical to bfd_generic_get_... except that some
10533 MIPS relocations need to be handled specially. Sigh. */
10536 _bfd_elf_mips_get_relocated_section_contents
10538 struct bfd_link_info
*link_info
,
10539 struct bfd_link_order
*link_order
,
10541 bfd_boolean relocatable
,
10544 /* Get enough memory to hold the stuff */
10545 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
10546 asection
*input_section
= link_order
->u
.indirect
.section
;
10549 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
10550 arelent
**reloc_vector
= NULL
;
10553 if (reloc_size
< 0)
10556 reloc_vector
= bfd_malloc (reloc_size
);
10557 if (reloc_vector
== NULL
&& reloc_size
!= 0)
10560 /* read in the section */
10561 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
10562 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
10565 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
10569 if (reloc_count
< 0)
10572 if (reloc_count
> 0)
10577 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
10580 struct bfd_hash_entry
*h
;
10581 struct bfd_link_hash_entry
*lh
;
10582 /* Skip all this stuff if we aren't mixing formats. */
10583 if (abfd
&& input_bfd
10584 && abfd
->xvec
== input_bfd
->xvec
)
10588 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
10589 lh
= (struct bfd_link_hash_entry
*) h
;
10596 case bfd_link_hash_undefined
:
10597 case bfd_link_hash_undefweak
:
10598 case bfd_link_hash_common
:
10601 case bfd_link_hash_defined
:
10602 case bfd_link_hash_defweak
:
10604 gp
= lh
->u
.def
.value
;
10606 case bfd_link_hash_indirect
:
10607 case bfd_link_hash_warning
:
10609 /* @@FIXME ignoring warning for now */
10611 case bfd_link_hash_new
:
10620 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
10622 char *error_message
= NULL
;
10623 bfd_reloc_status_type r
;
10625 /* Specific to MIPS: Deal with relocation types that require
10626 knowing the gp of the output bfd. */
10627 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
10629 /* If we've managed to find the gp and have a special
10630 function for the relocation then go ahead, else default
10631 to the generic handling. */
10633 && (*parent
)->howto
->special_function
10634 == _bfd_mips_elf32_gprel16_reloc
)
10635 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
10636 input_section
, relocatable
,
10639 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
10641 relocatable
? abfd
: NULL
,
10646 asection
*os
= input_section
->output_section
;
10648 /* A partial link, so keep the relocs */
10649 os
->orelocation
[os
->reloc_count
] = *parent
;
10653 if (r
!= bfd_reloc_ok
)
10657 case bfd_reloc_undefined
:
10658 if (!((*link_info
->callbacks
->undefined_symbol
)
10659 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
10660 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
10663 case bfd_reloc_dangerous
:
10664 BFD_ASSERT (error_message
!= NULL
);
10665 if (!((*link_info
->callbacks
->reloc_dangerous
)
10666 (link_info
, error_message
, input_bfd
, input_section
,
10667 (*parent
)->address
)))
10670 case bfd_reloc_overflow
:
10671 if (!((*link_info
->callbacks
->reloc_overflow
)
10673 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
10674 (*parent
)->howto
->name
, (*parent
)->addend
,
10675 input_bfd
, input_section
, (*parent
)->address
)))
10678 case bfd_reloc_outofrange
:
10687 if (reloc_vector
!= NULL
)
10688 free (reloc_vector
);
10692 if (reloc_vector
!= NULL
)
10693 free (reloc_vector
);
10697 /* Create a MIPS ELF linker hash table. */
10699 struct bfd_link_hash_table
*
10700 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
10702 struct mips_elf_link_hash_table
*ret
;
10703 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
10705 ret
= bfd_malloc (amt
);
10709 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
10710 mips_elf_link_hash_newfunc
,
10711 sizeof (struct mips_elf_link_hash_entry
)))
10718 /* We no longer use this. */
10719 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
10720 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
10722 ret
->procedure_count
= 0;
10723 ret
->compact_rel_size
= 0;
10724 ret
->use_rld_obj_head
= FALSE
;
10725 ret
->rld_value
= 0;
10726 ret
->mips16_stubs_seen
= FALSE
;
10727 ret
->is_vxworks
= FALSE
;
10728 ret
->small_data_overflow_reported
= FALSE
;
10729 ret
->srelbss
= NULL
;
10730 ret
->sdynbss
= NULL
;
10731 ret
->srelplt
= NULL
;
10732 ret
->srelplt2
= NULL
;
10733 ret
->sgotplt
= NULL
;
10735 ret
->sstubs
= NULL
;
10737 ret
->got_info
= NULL
;
10738 ret
->plt_header_size
= 0;
10739 ret
->plt_entry_size
= 0;
10740 ret
->lazy_stub_count
= 0;
10741 ret
->function_stub_size
= 0;
10743 return &ret
->root
.root
;
10746 /* Likewise, but indicate that the target is VxWorks. */
10748 struct bfd_link_hash_table
*
10749 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
10751 struct bfd_link_hash_table
*ret
;
10753 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
10756 struct mips_elf_link_hash_table
*htab
;
10758 htab
= (struct mips_elf_link_hash_table
*) ret
;
10759 htab
->is_vxworks
= 1;
10764 /* We need to use a special link routine to handle the .reginfo and
10765 the .mdebug sections. We need to merge all instances of these
10766 sections together, not write them all out sequentially. */
10769 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
10772 struct bfd_link_order
*p
;
10773 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
10774 asection
*rtproc_sec
;
10775 Elf32_RegInfo reginfo
;
10776 struct ecoff_debug_info debug
;
10777 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
10778 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
10779 HDRR
*symhdr
= &debug
.symbolic_header
;
10780 void *mdebug_handle
= NULL
;
10785 struct mips_elf_link_hash_table
*htab
;
10787 static const char * const secname
[] =
10789 ".text", ".init", ".fini", ".data",
10790 ".rodata", ".sdata", ".sbss", ".bss"
10792 static const int sc
[] =
10794 scText
, scInit
, scFini
, scData
,
10795 scRData
, scSData
, scSBss
, scBss
10798 /* We'd carefully arranged the dynamic symbol indices, and then the
10799 generic size_dynamic_sections renumbered them out from under us.
10800 Rather than trying somehow to prevent the renumbering, just do
10802 htab
= mips_elf_hash_table (info
);
10803 if (elf_hash_table (info
)->dynamic_sections_created
)
10805 struct mips_got_info
*g
;
10806 bfd_size_type dynsecsymcount
;
10808 /* When we resort, we must tell mips_elf_sort_hash_table what
10809 the lowest index it may use is. That's the number of section
10810 symbols we're going to add. The generic ELF linker only
10811 adds these symbols when building a shared object. Note that
10812 we count the sections after (possibly) removing the .options
10815 dynsecsymcount
= count_section_dynsyms (abfd
, info
);
10816 if (! mips_elf_sort_hash_table (info
, dynsecsymcount
+ 1))
10819 /* Make sure we didn't grow the global .got region. */
10820 g
= htab
->got_info
;
10821 if (g
->global_gotsym
!= NULL
)
10822 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
10823 - g
->global_gotsym
->dynindx
)
10824 <= g
->global_gotno
);
10827 /* Get a value for the GP register. */
10828 if (elf_gp (abfd
) == 0)
10830 struct bfd_link_hash_entry
*h
;
10832 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
10833 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
10834 elf_gp (abfd
) = (h
->u
.def
.value
10835 + h
->u
.def
.section
->output_section
->vma
10836 + h
->u
.def
.section
->output_offset
);
10837 else if (htab
->is_vxworks
10838 && (h
= bfd_link_hash_lookup (info
->hash
,
10839 "_GLOBAL_OFFSET_TABLE_",
10840 FALSE
, FALSE
, TRUE
))
10841 && h
->type
== bfd_link_hash_defined
)
10842 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
10843 + h
->u
.def
.section
->output_offset
10845 else if (info
->relocatable
)
10847 bfd_vma lo
= MINUS_ONE
;
10849 /* Find the GP-relative section with the lowest offset. */
10850 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10852 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
10855 /* And calculate GP relative to that. */
10856 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
10860 /* If the relocate_section function needs to do a reloc
10861 involving the GP value, it should make a reloc_dangerous
10862 callback to warn that GP is not defined. */
10866 /* Go through the sections and collect the .reginfo and .mdebug
10868 reginfo_sec
= NULL
;
10870 gptab_data_sec
= NULL
;
10871 gptab_bss_sec
= NULL
;
10872 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10874 if (strcmp (o
->name
, ".reginfo") == 0)
10876 memset (®info
, 0, sizeof reginfo
);
10878 /* We have found the .reginfo section in the output file.
10879 Look through all the link_orders comprising it and merge
10880 the information together. */
10881 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10883 asection
*input_section
;
10885 Elf32_External_RegInfo ext
;
10888 if (p
->type
!= bfd_indirect_link_order
)
10890 if (p
->type
== bfd_data_link_order
)
10895 input_section
= p
->u
.indirect
.section
;
10896 input_bfd
= input_section
->owner
;
10898 if (! bfd_get_section_contents (input_bfd
, input_section
,
10899 &ext
, 0, sizeof ext
))
10902 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
10904 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
10905 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
10906 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
10907 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
10908 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
10910 /* ri_gp_value is set by the function
10911 mips_elf32_section_processing when the section is
10912 finally written out. */
10914 /* Hack: reset the SEC_HAS_CONTENTS flag so that
10915 elf_link_input_bfd ignores this section. */
10916 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
10919 /* Size has been set in _bfd_mips_elf_always_size_sections. */
10920 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
10922 /* Skip this section later on (I don't think this currently
10923 matters, but someday it might). */
10924 o
->map_head
.link_order
= NULL
;
10929 if (strcmp (o
->name
, ".mdebug") == 0)
10931 struct extsym_info einfo
;
10934 /* We have found the .mdebug section in the output file.
10935 Look through all the link_orders comprising it and merge
10936 the information together. */
10937 symhdr
->magic
= swap
->sym_magic
;
10938 /* FIXME: What should the version stamp be? */
10939 symhdr
->vstamp
= 0;
10940 symhdr
->ilineMax
= 0;
10941 symhdr
->cbLine
= 0;
10942 symhdr
->idnMax
= 0;
10943 symhdr
->ipdMax
= 0;
10944 symhdr
->isymMax
= 0;
10945 symhdr
->ioptMax
= 0;
10946 symhdr
->iauxMax
= 0;
10947 symhdr
->issMax
= 0;
10948 symhdr
->issExtMax
= 0;
10949 symhdr
->ifdMax
= 0;
10951 symhdr
->iextMax
= 0;
10953 /* We accumulate the debugging information itself in the
10954 debug_info structure. */
10956 debug
.external_dnr
= NULL
;
10957 debug
.external_pdr
= NULL
;
10958 debug
.external_sym
= NULL
;
10959 debug
.external_opt
= NULL
;
10960 debug
.external_aux
= NULL
;
10962 debug
.ssext
= debug
.ssext_end
= NULL
;
10963 debug
.external_fdr
= NULL
;
10964 debug
.external_rfd
= NULL
;
10965 debug
.external_ext
= debug
.external_ext_end
= NULL
;
10967 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
10968 if (mdebug_handle
== NULL
)
10972 esym
.cobol_main
= 0;
10976 esym
.asym
.iss
= issNil
;
10977 esym
.asym
.st
= stLocal
;
10978 esym
.asym
.reserved
= 0;
10979 esym
.asym
.index
= indexNil
;
10981 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
10983 esym
.asym
.sc
= sc
[i
];
10984 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
10987 esym
.asym
.value
= s
->vma
;
10988 last
= s
->vma
+ s
->size
;
10991 esym
.asym
.value
= last
;
10992 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
10993 secname
[i
], &esym
))
10997 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10999 asection
*input_section
;
11001 const struct ecoff_debug_swap
*input_swap
;
11002 struct ecoff_debug_info input_debug
;
11006 if (p
->type
!= bfd_indirect_link_order
)
11008 if (p
->type
== bfd_data_link_order
)
11013 input_section
= p
->u
.indirect
.section
;
11014 input_bfd
= input_section
->owner
;
11016 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
11017 || (get_elf_backend_data (input_bfd
)
11018 ->elf_backend_ecoff_debug_swap
) == NULL
)
11020 /* I don't know what a non MIPS ELF bfd would be
11021 doing with a .mdebug section, but I don't really
11022 want to deal with it. */
11026 input_swap
= (get_elf_backend_data (input_bfd
)
11027 ->elf_backend_ecoff_debug_swap
);
11029 BFD_ASSERT (p
->size
== input_section
->size
);
11031 /* The ECOFF linking code expects that we have already
11032 read in the debugging information and set up an
11033 ecoff_debug_info structure, so we do that now. */
11034 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
11038 if (! (bfd_ecoff_debug_accumulate
11039 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
11040 &input_debug
, input_swap
, info
)))
11043 /* Loop through the external symbols. For each one with
11044 interesting information, try to find the symbol in
11045 the linker global hash table and save the information
11046 for the output external symbols. */
11047 eraw_src
= input_debug
.external_ext
;
11048 eraw_end
= (eraw_src
11049 + (input_debug
.symbolic_header
.iextMax
11050 * input_swap
->external_ext_size
));
11052 eraw_src
< eraw_end
;
11053 eraw_src
+= input_swap
->external_ext_size
)
11057 struct mips_elf_link_hash_entry
*h
;
11059 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
11060 if (ext
.asym
.sc
== scNil
11061 || ext
.asym
.sc
== scUndefined
11062 || ext
.asym
.sc
== scSUndefined
)
11065 name
= input_debug
.ssext
+ ext
.asym
.iss
;
11066 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
11067 name
, FALSE
, FALSE
, TRUE
);
11068 if (h
== NULL
|| h
->esym
.ifd
!= -2)
11073 BFD_ASSERT (ext
.ifd
11074 < input_debug
.symbolic_header
.ifdMax
);
11075 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
11081 /* Free up the information we just read. */
11082 free (input_debug
.line
);
11083 free (input_debug
.external_dnr
);
11084 free (input_debug
.external_pdr
);
11085 free (input_debug
.external_sym
);
11086 free (input_debug
.external_opt
);
11087 free (input_debug
.external_aux
);
11088 free (input_debug
.ss
);
11089 free (input_debug
.ssext
);
11090 free (input_debug
.external_fdr
);
11091 free (input_debug
.external_rfd
);
11092 free (input_debug
.external_ext
);
11094 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11095 elf_link_input_bfd ignores this section. */
11096 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11099 if (SGI_COMPAT (abfd
) && info
->shared
)
11101 /* Create .rtproc section. */
11102 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11103 if (rtproc_sec
== NULL
)
11105 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
11106 | SEC_LINKER_CREATED
| SEC_READONLY
);
11108 rtproc_sec
= bfd_make_section_with_flags (abfd
,
11111 if (rtproc_sec
== NULL
11112 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
11116 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
11122 /* Build the external symbol information. */
11125 einfo
.debug
= &debug
;
11127 einfo
.failed
= FALSE
;
11128 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
11129 mips_elf_output_extsym
, &einfo
);
11133 /* Set the size of the .mdebug section. */
11134 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
11136 /* Skip this section later on (I don't think this currently
11137 matters, but someday it might). */
11138 o
->map_head
.link_order
= NULL
;
11143 if (CONST_STRNEQ (o
->name
, ".gptab."))
11145 const char *subname
;
11148 Elf32_External_gptab
*ext_tab
;
11151 /* The .gptab.sdata and .gptab.sbss sections hold
11152 information describing how the small data area would
11153 change depending upon the -G switch. These sections
11154 not used in executables files. */
11155 if (! info
->relocatable
)
11157 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11159 asection
*input_section
;
11161 if (p
->type
!= bfd_indirect_link_order
)
11163 if (p
->type
== bfd_data_link_order
)
11168 input_section
= p
->u
.indirect
.section
;
11170 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11171 elf_link_input_bfd ignores this section. */
11172 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11175 /* Skip this section later on (I don't think this
11176 currently matters, but someday it might). */
11177 o
->map_head
.link_order
= NULL
;
11179 /* Really remove the section. */
11180 bfd_section_list_remove (abfd
, o
);
11181 --abfd
->section_count
;
11186 /* There is one gptab for initialized data, and one for
11187 uninitialized data. */
11188 if (strcmp (o
->name
, ".gptab.sdata") == 0)
11189 gptab_data_sec
= o
;
11190 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
11194 (*_bfd_error_handler
)
11195 (_("%s: illegal section name `%s'"),
11196 bfd_get_filename (abfd
), o
->name
);
11197 bfd_set_error (bfd_error_nonrepresentable_section
);
11201 /* The linker script always combines .gptab.data and
11202 .gptab.sdata into .gptab.sdata, and likewise for
11203 .gptab.bss and .gptab.sbss. It is possible that there is
11204 no .sdata or .sbss section in the output file, in which
11205 case we must change the name of the output section. */
11206 subname
= o
->name
+ sizeof ".gptab" - 1;
11207 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
11209 if (o
== gptab_data_sec
)
11210 o
->name
= ".gptab.data";
11212 o
->name
= ".gptab.bss";
11213 subname
= o
->name
+ sizeof ".gptab" - 1;
11214 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
11217 /* Set up the first entry. */
11219 amt
= c
* sizeof (Elf32_gptab
);
11220 tab
= bfd_malloc (amt
);
11223 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
11224 tab
[0].gt_header
.gt_unused
= 0;
11226 /* Combine the input sections. */
11227 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11229 asection
*input_section
;
11231 bfd_size_type size
;
11232 unsigned long last
;
11233 bfd_size_type gpentry
;
11235 if (p
->type
!= bfd_indirect_link_order
)
11237 if (p
->type
== bfd_data_link_order
)
11242 input_section
= p
->u
.indirect
.section
;
11243 input_bfd
= input_section
->owner
;
11245 /* Combine the gptab entries for this input section one
11246 by one. We know that the input gptab entries are
11247 sorted by ascending -G value. */
11248 size
= input_section
->size
;
11250 for (gpentry
= sizeof (Elf32_External_gptab
);
11252 gpentry
+= sizeof (Elf32_External_gptab
))
11254 Elf32_External_gptab ext_gptab
;
11255 Elf32_gptab int_gptab
;
11261 if (! (bfd_get_section_contents
11262 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
11263 sizeof (Elf32_External_gptab
))))
11269 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
11271 val
= int_gptab
.gt_entry
.gt_g_value
;
11272 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
11275 for (look
= 1; look
< c
; look
++)
11277 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
11278 tab
[look
].gt_entry
.gt_bytes
+= add
;
11280 if (tab
[look
].gt_entry
.gt_g_value
== val
)
11286 Elf32_gptab
*new_tab
;
11289 /* We need a new table entry. */
11290 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
11291 new_tab
= bfd_realloc (tab
, amt
);
11292 if (new_tab
== NULL
)
11298 tab
[c
].gt_entry
.gt_g_value
= val
;
11299 tab
[c
].gt_entry
.gt_bytes
= add
;
11301 /* Merge in the size for the next smallest -G
11302 value, since that will be implied by this new
11305 for (look
= 1; look
< c
; look
++)
11307 if (tab
[look
].gt_entry
.gt_g_value
< val
11309 || (tab
[look
].gt_entry
.gt_g_value
11310 > tab
[max
].gt_entry
.gt_g_value
)))
11314 tab
[c
].gt_entry
.gt_bytes
+=
11315 tab
[max
].gt_entry
.gt_bytes
;
11320 last
= int_gptab
.gt_entry
.gt_bytes
;
11323 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11324 elf_link_input_bfd ignores this section. */
11325 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11328 /* The table must be sorted by -G value. */
11330 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
11332 /* Swap out the table. */
11333 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
11334 ext_tab
= bfd_alloc (abfd
, amt
);
11335 if (ext_tab
== NULL
)
11341 for (j
= 0; j
< c
; j
++)
11342 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
11345 o
->size
= c
* sizeof (Elf32_External_gptab
);
11346 o
->contents
= (bfd_byte
*) ext_tab
;
11348 /* Skip this section later on (I don't think this currently
11349 matters, but someday it might). */
11350 o
->map_head
.link_order
= NULL
;
11354 /* Invoke the regular ELF backend linker to do all the work. */
11355 if (!bfd_elf_final_link (abfd
, info
))
11358 /* Now write out the computed sections. */
11360 if (reginfo_sec
!= NULL
)
11362 Elf32_External_RegInfo ext
;
11364 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
11365 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
11369 if (mdebug_sec
!= NULL
)
11371 BFD_ASSERT (abfd
->output_has_begun
);
11372 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
11374 mdebug_sec
->filepos
))
11377 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
11380 if (gptab_data_sec
!= NULL
)
11382 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
11383 gptab_data_sec
->contents
,
11384 0, gptab_data_sec
->size
))
11388 if (gptab_bss_sec
!= NULL
)
11390 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
11391 gptab_bss_sec
->contents
,
11392 0, gptab_bss_sec
->size
))
11396 if (SGI_COMPAT (abfd
))
11398 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11399 if (rtproc_sec
!= NULL
)
11401 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
11402 rtproc_sec
->contents
,
11403 0, rtproc_sec
->size
))
11411 /* Structure for saying that BFD machine EXTENSION extends BASE. */
11413 struct mips_mach_extension
{
11414 unsigned long extension
, base
;
11418 /* An array describing how BFD machines relate to one another. The entries
11419 are ordered topologically with MIPS I extensions listed last. */
11421 static const struct mips_mach_extension mips_mach_extensions
[] = {
11422 /* MIPS64r2 extensions. */
11423 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
11425 /* MIPS64 extensions. */
11426 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
11427 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
11429 /* MIPS V extensions. */
11430 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
11432 /* R10000 extensions. */
11433 { bfd_mach_mips12000
, bfd_mach_mips10000
},
11435 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
11436 vr5400 ISA, but doesn't include the multimedia stuff. It seems
11437 better to allow vr5400 and vr5500 code to be merged anyway, since
11438 many libraries will just use the core ISA. Perhaps we could add
11439 some sort of ASE flag if this ever proves a problem. */
11440 { bfd_mach_mips5500
, bfd_mach_mips5400
},
11441 { bfd_mach_mips5400
, bfd_mach_mips5000
},
11443 /* MIPS IV extensions. */
11444 { bfd_mach_mips5
, bfd_mach_mips8000
},
11445 { bfd_mach_mips10000
, bfd_mach_mips8000
},
11446 { bfd_mach_mips5000
, bfd_mach_mips8000
},
11447 { bfd_mach_mips7000
, bfd_mach_mips8000
},
11448 { bfd_mach_mips9000
, bfd_mach_mips8000
},
11450 /* VR4100 extensions. */
11451 { bfd_mach_mips4120
, bfd_mach_mips4100
},
11452 { bfd_mach_mips4111
, bfd_mach_mips4100
},
11454 /* MIPS III extensions. */
11455 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
11456 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
11457 { bfd_mach_mips8000
, bfd_mach_mips4000
},
11458 { bfd_mach_mips4650
, bfd_mach_mips4000
},
11459 { bfd_mach_mips4600
, bfd_mach_mips4000
},
11460 { bfd_mach_mips4400
, bfd_mach_mips4000
},
11461 { bfd_mach_mips4300
, bfd_mach_mips4000
},
11462 { bfd_mach_mips4100
, bfd_mach_mips4000
},
11463 { bfd_mach_mips4010
, bfd_mach_mips4000
},
11465 /* MIPS32 extensions. */
11466 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
11468 /* MIPS II extensions. */
11469 { bfd_mach_mips4000
, bfd_mach_mips6000
},
11470 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
11472 /* MIPS I extensions. */
11473 { bfd_mach_mips6000
, bfd_mach_mips3000
},
11474 { bfd_mach_mips3900
, bfd_mach_mips3000
}
11478 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
11481 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
11485 if (extension
== base
)
11488 if (base
== bfd_mach_mipsisa32
11489 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
11492 if (base
== bfd_mach_mipsisa32r2
11493 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
11496 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
11497 if (extension
== mips_mach_extensions
[i
].extension
)
11499 extension
= mips_mach_extensions
[i
].base
;
11500 if (extension
== base
)
11508 /* Return true if the given ELF header flags describe a 32-bit binary. */
11511 mips_32bit_flags_p (flagword flags
)
11513 return ((flags
& EF_MIPS_32BITMODE
) != 0
11514 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
11515 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
11516 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
11517 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
11518 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
11519 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
11523 /* Merge object attributes from IBFD into OBFD. Raise an error if
11524 there are conflicting attributes. */
11526 mips_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
11528 obj_attribute
*in_attr
;
11529 obj_attribute
*out_attr
;
11531 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
11533 /* This is the first object. Copy the attributes. */
11534 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
11536 /* Use the Tag_null value to indicate the attributes have been
11538 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
11543 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
11544 non-conflicting ones. */
11545 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
11546 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
11547 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11549 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
11550 if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
11551 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
11552 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
11554 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
11556 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
11557 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
11558 else if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
11560 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
11561 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
11563 switch (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11566 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11570 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
11576 (_("Warning: %B uses hard float, %B uses soft float"),
11582 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
11592 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11596 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
11602 (_("Warning: %B uses hard float, %B uses soft float"),
11608 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
11618 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11624 (_("Warning: %B uses hard float, %B uses soft float"),
11634 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11638 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
11644 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
11650 (_("Warning: %B uses hard float, %B uses soft float"),
11664 /* Merge Tag_compatibility attributes and any common GNU ones. */
11665 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
11670 /* Merge backend specific data from an object file to the output
11671 object file when linking. */
11674 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
11676 flagword old_flags
;
11677 flagword new_flags
;
11679 bfd_boolean null_input_bfd
= TRUE
;
11682 /* Check if we have the same endianess */
11683 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
11685 (*_bfd_error_handler
)
11686 (_("%B: endianness incompatible with that of the selected emulation"),
11691 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
11692 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
11695 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
11697 (*_bfd_error_handler
)
11698 (_("%B: ABI is incompatible with that of the selected emulation"),
11703 if (!mips_elf_merge_obj_attributes (ibfd
, obfd
))
11706 new_flags
= elf_elfheader (ibfd
)->e_flags
;
11707 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
11708 old_flags
= elf_elfheader (obfd
)->e_flags
;
11710 if (! elf_flags_init (obfd
))
11712 elf_flags_init (obfd
) = TRUE
;
11713 elf_elfheader (obfd
)->e_flags
= new_flags
;
11714 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
11715 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
11717 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
11718 && (bfd_get_arch_info (obfd
)->the_default
11719 || mips_mach_extends_p (bfd_get_mach (obfd
),
11720 bfd_get_mach (ibfd
))))
11722 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
11723 bfd_get_mach (ibfd
)))
11730 /* Check flag compatibility. */
11732 new_flags
&= ~EF_MIPS_NOREORDER
;
11733 old_flags
&= ~EF_MIPS_NOREORDER
;
11735 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
11736 doesn't seem to matter. */
11737 new_flags
&= ~EF_MIPS_XGOT
;
11738 old_flags
&= ~EF_MIPS_XGOT
;
11740 /* MIPSpro generates ucode info in n64 objects. Again, we should
11741 just be able to ignore this. */
11742 new_flags
&= ~EF_MIPS_UCODE
;
11743 old_flags
&= ~EF_MIPS_UCODE
;
11745 /* Don't care about the PIC flags from dynamic objects; they are
11747 if ((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0
11748 && (ibfd
->flags
& DYNAMIC
) != 0)
11749 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11751 if (new_flags
== old_flags
)
11754 /* Check to see if the input BFD actually contains any sections.
11755 If not, its flags may not have been initialised either, but it cannot
11756 actually cause any incompatibility. */
11757 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
11759 /* Ignore synthetic sections and empty .text, .data and .bss sections
11760 which are automatically generated by gas. */
11761 if (strcmp (sec
->name
, ".reginfo")
11762 && strcmp (sec
->name
, ".mdebug")
11764 || (strcmp (sec
->name
, ".text")
11765 && strcmp (sec
->name
, ".data")
11766 && strcmp (sec
->name
, ".bss"))))
11768 null_input_bfd
= FALSE
;
11772 if (null_input_bfd
)
11777 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
11778 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
11780 (*_bfd_error_handler
)
11781 (_("%B: warning: linking PIC files with non-PIC files"),
11786 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
11787 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
11788 if (! (new_flags
& EF_MIPS_PIC
))
11789 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
11791 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11792 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11794 /* Compare the ISAs. */
11795 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
11797 (*_bfd_error_handler
)
11798 (_("%B: linking 32-bit code with 64-bit code"),
11802 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
11804 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
11805 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
11807 /* Copy the architecture info from IBFD to OBFD. Also copy
11808 the 32-bit flag (if set) so that we continue to recognise
11809 OBFD as a 32-bit binary. */
11810 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
11811 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
11812 elf_elfheader (obfd
)->e_flags
11813 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11815 /* Copy across the ABI flags if OBFD doesn't use them
11816 and if that was what caused us to treat IBFD as 32-bit. */
11817 if ((old_flags
& EF_MIPS_ABI
) == 0
11818 && mips_32bit_flags_p (new_flags
)
11819 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
11820 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
11824 /* The ISAs aren't compatible. */
11825 (*_bfd_error_handler
)
11826 (_("%B: linking %s module with previous %s modules"),
11828 bfd_printable_name (ibfd
),
11829 bfd_printable_name (obfd
));
11834 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11835 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11837 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
11838 does set EI_CLASS differently from any 32-bit ABI. */
11839 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
11840 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
11841 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
11843 /* Only error if both are set (to different values). */
11844 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
11845 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
11846 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
11848 (*_bfd_error_handler
)
11849 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
11851 elf_mips_abi_name (ibfd
),
11852 elf_mips_abi_name (obfd
));
11855 new_flags
&= ~EF_MIPS_ABI
;
11856 old_flags
&= ~EF_MIPS_ABI
;
11859 /* For now, allow arbitrary mixing of ASEs (retain the union). */
11860 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
11862 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
11864 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
11865 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
11868 /* Warn about any other mismatches */
11869 if (new_flags
!= old_flags
)
11871 (*_bfd_error_handler
)
11872 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
11873 ibfd
, (unsigned long) new_flags
,
11874 (unsigned long) old_flags
);
11880 bfd_set_error (bfd_error_bad_value
);
11887 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
11890 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
11892 BFD_ASSERT (!elf_flags_init (abfd
)
11893 || elf_elfheader (abfd
)->e_flags
== flags
);
11895 elf_elfheader (abfd
)->e_flags
= flags
;
11896 elf_flags_init (abfd
) = TRUE
;
11901 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
11905 default: return "";
11906 case DT_MIPS_RLD_VERSION
:
11907 return "MIPS_RLD_VERSION";
11908 case DT_MIPS_TIME_STAMP
:
11909 return "MIPS_TIME_STAMP";
11910 case DT_MIPS_ICHECKSUM
:
11911 return "MIPS_ICHECKSUM";
11912 case DT_MIPS_IVERSION
:
11913 return "MIPS_IVERSION";
11914 case DT_MIPS_FLAGS
:
11915 return "MIPS_FLAGS";
11916 case DT_MIPS_BASE_ADDRESS
:
11917 return "MIPS_BASE_ADDRESS";
11919 return "MIPS_MSYM";
11920 case DT_MIPS_CONFLICT
:
11921 return "MIPS_CONFLICT";
11922 case DT_MIPS_LIBLIST
:
11923 return "MIPS_LIBLIST";
11924 case DT_MIPS_LOCAL_GOTNO
:
11925 return "MIPS_LOCAL_GOTNO";
11926 case DT_MIPS_CONFLICTNO
:
11927 return "MIPS_CONFLICTNO";
11928 case DT_MIPS_LIBLISTNO
:
11929 return "MIPS_LIBLISTNO";
11930 case DT_MIPS_SYMTABNO
:
11931 return "MIPS_SYMTABNO";
11932 case DT_MIPS_UNREFEXTNO
:
11933 return "MIPS_UNREFEXTNO";
11934 case DT_MIPS_GOTSYM
:
11935 return "MIPS_GOTSYM";
11936 case DT_MIPS_HIPAGENO
:
11937 return "MIPS_HIPAGENO";
11938 case DT_MIPS_RLD_MAP
:
11939 return "MIPS_RLD_MAP";
11940 case DT_MIPS_DELTA_CLASS
:
11941 return "MIPS_DELTA_CLASS";
11942 case DT_MIPS_DELTA_CLASS_NO
:
11943 return "MIPS_DELTA_CLASS_NO";
11944 case DT_MIPS_DELTA_INSTANCE
:
11945 return "MIPS_DELTA_INSTANCE";
11946 case DT_MIPS_DELTA_INSTANCE_NO
:
11947 return "MIPS_DELTA_INSTANCE_NO";
11948 case DT_MIPS_DELTA_RELOC
:
11949 return "MIPS_DELTA_RELOC";
11950 case DT_MIPS_DELTA_RELOC_NO
:
11951 return "MIPS_DELTA_RELOC_NO";
11952 case DT_MIPS_DELTA_SYM
:
11953 return "MIPS_DELTA_SYM";
11954 case DT_MIPS_DELTA_SYM_NO
:
11955 return "MIPS_DELTA_SYM_NO";
11956 case DT_MIPS_DELTA_CLASSSYM
:
11957 return "MIPS_DELTA_CLASSSYM";
11958 case DT_MIPS_DELTA_CLASSSYM_NO
:
11959 return "MIPS_DELTA_CLASSSYM_NO";
11960 case DT_MIPS_CXX_FLAGS
:
11961 return "MIPS_CXX_FLAGS";
11962 case DT_MIPS_PIXIE_INIT
:
11963 return "MIPS_PIXIE_INIT";
11964 case DT_MIPS_SYMBOL_LIB
:
11965 return "MIPS_SYMBOL_LIB";
11966 case DT_MIPS_LOCALPAGE_GOTIDX
:
11967 return "MIPS_LOCALPAGE_GOTIDX";
11968 case DT_MIPS_LOCAL_GOTIDX
:
11969 return "MIPS_LOCAL_GOTIDX";
11970 case DT_MIPS_HIDDEN_GOTIDX
:
11971 return "MIPS_HIDDEN_GOTIDX";
11972 case DT_MIPS_PROTECTED_GOTIDX
:
11973 return "MIPS_PROTECTED_GOT_IDX";
11974 case DT_MIPS_OPTIONS
:
11975 return "MIPS_OPTIONS";
11976 case DT_MIPS_INTERFACE
:
11977 return "MIPS_INTERFACE";
11978 case DT_MIPS_DYNSTR_ALIGN
:
11979 return "DT_MIPS_DYNSTR_ALIGN";
11980 case DT_MIPS_INTERFACE_SIZE
:
11981 return "DT_MIPS_INTERFACE_SIZE";
11982 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
11983 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
11984 case DT_MIPS_PERF_SUFFIX
:
11985 return "DT_MIPS_PERF_SUFFIX";
11986 case DT_MIPS_COMPACT_SIZE
:
11987 return "DT_MIPS_COMPACT_SIZE";
11988 case DT_MIPS_GP_VALUE
:
11989 return "DT_MIPS_GP_VALUE";
11990 case DT_MIPS_AUX_DYNAMIC
:
11991 return "DT_MIPS_AUX_DYNAMIC";
11996 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
12000 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
12002 /* Print normal ELF private data. */
12003 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
12005 /* xgettext:c-format */
12006 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
12008 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
12009 fprintf (file
, _(" [abi=O32]"));
12010 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
12011 fprintf (file
, _(" [abi=O64]"));
12012 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
12013 fprintf (file
, _(" [abi=EABI32]"));
12014 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
12015 fprintf (file
, _(" [abi=EABI64]"));
12016 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
12017 fprintf (file
, _(" [abi unknown]"));
12018 else if (ABI_N32_P (abfd
))
12019 fprintf (file
, _(" [abi=N32]"));
12020 else if (ABI_64_P (abfd
))
12021 fprintf (file
, _(" [abi=64]"));
12023 fprintf (file
, _(" [no abi set]"));
12025 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
12026 fprintf (file
, " [mips1]");
12027 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
12028 fprintf (file
, " [mips2]");
12029 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
12030 fprintf (file
, " [mips3]");
12031 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
12032 fprintf (file
, " [mips4]");
12033 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
12034 fprintf (file
, " [mips5]");
12035 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
12036 fprintf (file
, " [mips32]");
12037 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
12038 fprintf (file
, " [mips64]");
12039 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
12040 fprintf (file
, " [mips32r2]");
12041 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
12042 fprintf (file
, " [mips64r2]");
12044 fprintf (file
, _(" [unknown ISA]"));
12046 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
12047 fprintf (file
, " [mdmx]");
12049 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
12050 fprintf (file
, " [mips16]");
12052 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
12053 fprintf (file
, " [32bitmode]");
12055 fprintf (file
, _(" [not 32bitmode]"));
12057 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
12058 fprintf (file
, " [noreorder]");
12060 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
12061 fprintf (file
, " [PIC]");
12063 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
12064 fprintf (file
, " [CPIC]");
12066 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
12067 fprintf (file
, " [XGOT]");
12069 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
12070 fprintf (file
, " [UCODE]");
12072 fputc ('\n', file
);
12077 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
12079 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12080 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12081 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
12082 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12083 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12084 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
12085 { NULL
, 0, 0, 0, 0 }
12088 /* Merge non visibility st_other attributes. Ensure that the
12089 STO_OPTIONAL flag is copied into h->other, even if this is not a
12090 definiton of the symbol. */
12092 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
12093 const Elf_Internal_Sym
*isym
,
12094 bfd_boolean definition
,
12095 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
12097 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
12099 unsigned char other
;
12101 other
= (definition
? isym
->st_other
: h
->other
);
12102 other
&= ~ELF_ST_VISIBILITY (-1);
12103 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
12107 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
12108 h
->other
|= STO_OPTIONAL
;
12111 /* Decide whether an undefined symbol is special and can be ignored.
12112 This is the case for OPTIONAL symbols on IRIX. */
12114 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
12116 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
12120 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
12122 return (sym
->st_shndx
== SHN_COMMON
12123 || sym
->st_shndx
== SHN_MIPS_ACOMMON
12124 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);