1 /* MIPS-specific support for ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
8 <mark@codesourcery.com>
9 Traditional MIPS targets support added by Koundinya.K, Dansk Data
10 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
12 This file is part of BFD, the Binary File Descriptor library.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
27 MA 02110-1301, USA. */
30 /* This file handles functionality common to the different MIPS ABI's. */
35 #include "libiberty.h"
37 #include "elfxx-mips.h"
39 #include "elf-vxworks.h"
41 /* Get the ECOFF swapping routines. */
43 #include "coff/symconst.h"
44 #include "coff/ecoff.h"
45 #include "coff/mips.h"
49 /* This structure is used to hold information about one GOT entry.
50 There are three types of entry:
52 (1) absolute addresses
54 (2) SYMBOL + OFFSET addresses, where SYMBOL is local to an input bfd
55 (abfd != NULL, symndx >= 0)
56 (3) global and forced-local symbols
57 (abfd != NULL, symndx == -1)
59 Type (3) entries are treated differently for different types of GOT.
60 In the "master" GOT -- i.e. the one that describes every GOT
61 reference needed in the link -- the mips_got_entry is keyed on both
62 the symbol and the input bfd that references it. If it turns out
63 that we need multiple GOTs, we can then use this information to
64 create separate GOTs for each input bfd.
66 However, we want each of these separate GOTs to have at most one
67 entry for a given symbol, so their type (3) entries are keyed only
68 on the symbol. The input bfd given by the "abfd" field is somewhat
69 arbitrary in this case.
71 This means that when there are multiple GOTs, each GOT has a unique
72 mips_got_entry for every symbol within it. We can therefore use the
73 mips_got_entry fields (tls_type and gotidx) to track the symbol's
76 However, if it turns out that we need only a single GOT, we continue
77 to use the master GOT to describe it. There may therefore be several
78 mips_got_entries for the same symbol, each with a different input bfd.
79 We want to make sure that each symbol gets a unique GOT entry, so when
80 there's a single GOT, we use the symbol's hash entry, not the
81 mips_got_entry fields, to track a symbol's GOT index. */
84 /* The input bfd in which the symbol is defined. */
86 /* The index of the symbol, as stored in the relocation r_info, if
87 we have a local symbol; -1 otherwise. */
91 /* If abfd == NULL, an address that must be stored in the got. */
93 /* If abfd != NULL && symndx != -1, the addend of the relocation
94 that should be added to the symbol value. */
96 /* If abfd != NULL && symndx == -1, the hash table entry
97 corresponding to a global symbol in the got (or, local, if
99 struct mips_elf_link_hash_entry
*h
;
102 /* The TLS types included in this GOT entry (specifically, GD and
103 IE). The GD and IE flags can be added as we encounter new
104 relocations. LDM can also be set; it will always be alone, not
105 combined with any GD or IE flags. An LDM GOT entry will be
106 a local symbol entry with r_symndx == 0. */
107 unsigned char tls_type
;
109 /* The offset from the beginning of the .got section to the entry
110 corresponding to this symbol+addend. If it's a global symbol
111 whose offset is yet to be decided, it's going to be -1. */
115 /* This structure describes a range of addends: [MIN_ADDEND, MAX_ADDEND].
116 The structures form a non-overlapping list that is sorted by increasing
118 struct mips_got_page_range
120 struct mips_got_page_range
*next
;
121 bfd_signed_vma min_addend
;
122 bfd_signed_vma max_addend
;
125 /* This structure describes the range of addends that are applied to page
126 relocations against a given symbol. */
127 struct mips_got_page_entry
129 /* The input bfd in which the symbol is defined. */
131 /* The index of the symbol, as stored in the relocation r_info. */
133 /* The ranges for this page entry. */
134 struct mips_got_page_range
*ranges
;
135 /* The maximum number of page entries needed for RANGES. */
139 /* This structure is used to hold .got information when linking. */
143 /* The global symbol in the GOT with the lowest index in the dynamic
145 struct elf_link_hash_entry
*global_gotsym
;
146 /* The number of global .got entries. */
147 unsigned int global_gotno
;
148 /* The number of global .got entries that are in the GGA_RELOC_ONLY area. */
149 unsigned int reloc_only_gotno
;
150 /* The number of .got slots used for TLS. */
151 unsigned int tls_gotno
;
152 /* The first unused TLS .got entry. Used only during
153 mips_elf_initialize_tls_index. */
154 unsigned int tls_assigned_gotno
;
155 /* The number of local .got entries, eventually including page entries. */
156 unsigned int local_gotno
;
157 /* The maximum number of page entries needed. */
158 unsigned int page_gotno
;
159 /* The number of local .got entries we have used. */
160 unsigned int assigned_gotno
;
161 /* A hash table holding members of the got. */
162 struct htab
*got_entries
;
163 /* A hash table of mips_got_page_entry structures. */
164 struct htab
*got_page_entries
;
165 /* A hash table mapping input bfds to other mips_got_info. NULL
166 unless multi-got was necessary. */
167 struct htab
*bfd2got
;
168 /* In multi-got links, a pointer to the next got (err, rather, most
169 of the time, it points to the previous got). */
170 struct mips_got_info
*next
;
171 /* This is the GOT index of the TLS LDM entry for the GOT, MINUS_ONE
172 for none, or MINUS_TWO for not yet assigned. This is needed
173 because a single-GOT link may have multiple hash table entries
174 for the LDM. It does not get initialized in multi-GOT mode. */
175 bfd_vma tls_ldm_offset
;
178 /* Map an input bfd to a got in a multi-got link. */
180 struct mips_elf_bfd2got_hash
{
182 struct mips_got_info
*g
;
185 /* Structure passed when traversing the bfd2got hash table, used to
186 create and merge bfd's gots. */
188 struct mips_elf_got_per_bfd_arg
190 /* A hashtable that maps bfds to gots. */
192 /* The output bfd. */
194 /* The link information. */
195 struct bfd_link_info
*info
;
196 /* A pointer to the primary got, i.e., the one that's going to get
197 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
199 struct mips_got_info
*primary
;
200 /* A non-primary got we're trying to merge with other input bfd's
202 struct mips_got_info
*current
;
203 /* The maximum number of got entries that can be addressed with a
205 unsigned int max_count
;
206 /* The maximum number of page entries needed by each got. */
207 unsigned int max_pages
;
208 /* The total number of global entries which will live in the
209 primary got and be automatically relocated. This includes
210 those not referenced by the primary GOT but included in
212 unsigned int global_count
;
215 /* Another structure used to pass arguments for got entries traversal. */
217 struct mips_elf_set_global_got_offset_arg
219 struct mips_got_info
*g
;
221 unsigned int needed_relocs
;
222 struct bfd_link_info
*info
;
225 /* A structure used to count TLS relocations or GOT entries, for GOT
226 entry or ELF symbol table traversal. */
228 struct mips_elf_count_tls_arg
230 struct bfd_link_info
*info
;
234 struct _mips_elf_section_data
236 struct bfd_elf_section_data elf
;
243 #define mips_elf_section_data(sec) \
244 ((struct _mips_elf_section_data *) elf_section_data (sec))
246 /* The ABI says that every symbol used by dynamic relocations must have
247 a global GOT entry. Among other things, this provides the dynamic
248 linker with a free, directly-indexed cache. The GOT can therefore
249 contain symbols that are not referenced by GOT relocations themselves
250 (in other words, it may have symbols that are not referenced by things
251 like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
253 GOT relocations are less likely to overflow if we put the associated
254 GOT entries towards the beginning. We therefore divide the global
255 GOT entries into two areas: "normal" and "reloc-only". Entries in
256 the first area can be used for both dynamic relocations and GP-relative
257 accesses, while those in the "reloc-only" area are for dynamic
260 These GGA_* ("Global GOT Area") values are organised so that lower
261 values are more general than higher values. Also, non-GGA_NONE
262 values are ordered by the position of the area in the GOT. */
264 #define GGA_RELOC_ONLY 1
267 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
268 the dynamic symbols. */
270 struct mips_elf_hash_sort_data
272 /* The symbol in the global GOT with the lowest dynamic symbol table
274 struct elf_link_hash_entry
*low
;
275 /* The least dynamic symbol table index corresponding to a non-TLS
276 symbol with a GOT entry. */
277 long min_got_dynindx
;
278 /* The greatest dynamic symbol table index corresponding to a symbol
279 with a GOT entry that is not referenced (e.g., a dynamic symbol
280 with dynamic relocations pointing to it from non-primary GOTs). */
281 long max_unref_got_dynindx
;
282 /* The greatest dynamic symbol table index not corresponding to a
283 symbol without a GOT entry. */
284 long max_non_got_dynindx
;
287 /* The MIPS ELF linker needs additional information for each symbol in
288 the global hash table. */
290 struct mips_elf_link_hash_entry
292 struct elf_link_hash_entry root
;
294 /* External symbol information. */
297 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
299 unsigned int possibly_dynamic_relocs
;
301 /* If there is a stub that 32 bit functions should use to call this
302 16 bit function, this points to the section containing the stub. */
305 /* If there is a stub that 16 bit functions should use to call this
306 32 bit function, this points to the section containing the stub. */
309 /* This is like the call_stub field, but it is used if the function
310 being called returns a floating point value. */
311 asection
*call_fp_stub
;
315 #define GOT_TLS_LDM 2
317 #define GOT_TLS_OFFSET_DONE 0x40
318 #define GOT_TLS_DONE 0x80
319 unsigned char tls_type
;
321 /* This is only used in single-GOT mode; in multi-GOT mode there
322 is one mips_got_entry per GOT entry, so the offset is stored
323 there. In single-GOT mode there may be many mips_got_entry
324 structures all referring to the same GOT slot. It might be
325 possible to use root.got.offset instead, but that field is
326 overloaded already. */
327 bfd_vma tls_got_offset
;
329 /* The highest GGA_* value that satisfies all references to this symbol. */
330 unsigned int global_got_area
: 2;
332 /* True if one of the relocations described by possibly_dynamic_relocs
333 is against a readonly section. */
334 unsigned int readonly_reloc
: 1;
336 /* True if we must not create a .MIPS.stubs entry for this symbol.
337 This is set, for example, if there are relocations related to
338 taking the function's address, i.e. any but R_MIPS_CALL*16 ones.
339 See "MIPS ABI Supplement, 3rd Edition", p. 4-20. */
340 unsigned int no_fn_stub
: 1;
342 /* Whether we need the fn_stub; this is true if this symbol appears
343 in any relocs other than a 16 bit call. */
344 unsigned int need_fn_stub
: 1;
346 /* Are we referenced by some kind of relocation? */
347 unsigned int is_relocation_target
: 1;
349 /* Are we referenced by branch relocations? */
350 unsigned int is_branch_target
: 1;
352 /* Does this symbol need a traditional MIPS lazy-binding stub
353 (as opposed to a PLT entry)? */
354 unsigned int needs_lazy_stub
: 1;
357 /* MIPS ELF linker hash table. */
359 struct mips_elf_link_hash_table
361 struct elf_link_hash_table root
;
363 /* We no longer use this. */
364 /* String section indices for the dynamic section symbols. */
365 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
367 /* The number of .rtproc entries. */
368 bfd_size_type procedure_count
;
369 /* The size of the .compact_rel section (if SGI_COMPAT). */
370 bfd_size_type compact_rel_size
;
371 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
372 entry is set to the address of __rld_obj_head as in IRIX5. */
373 bfd_boolean use_rld_obj_head
;
374 /* This is the value of the __rld_map or __rld_obj_head symbol. */
376 /* This is set if we see any mips16 stub sections. */
377 bfd_boolean mips16_stubs_seen
;
378 /* True if we're generating code for VxWorks. */
379 bfd_boolean is_vxworks
;
380 /* True if we already reported the small-data section overflow. */
381 bfd_boolean small_data_overflow_reported
;
382 /* Shortcuts to some dynamic sections, or NULL if they are not
392 /* The master GOT information. */
393 struct mips_got_info
*got_info
;
394 /* The size of the PLT header in bytes (VxWorks only). */
395 bfd_vma plt_header_size
;
396 /* The size of a PLT entry in bytes (VxWorks only). */
397 bfd_vma plt_entry_size
;
398 /* The number of functions that need a lazy-binding stub. */
399 bfd_vma lazy_stub_count
;
400 /* The size of a function stub entry in bytes. */
401 bfd_vma function_stub_size
;
404 #define TLS_RELOC_P(r_type) \
405 (r_type == R_MIPS_TLS_DTPMOD32 \
406 || r_type == R_MIPS_TLS_DTPMOD64 \
407 || r_type == R_MIPS_TLS_DTPREL32 \
408 || r_type == R_MIPS_TLS_DTPREL64 \
409 || r_type == R_MIPS_TLS_GD \
410 || r_type == R_MIPS_TLS_LDM \
411 || r_type == R_MIPS_TLS_DTPREL_HI16 \
412 || r_type == R_MIPS_TLS_DTPREL_LO16 \
413 || r_type == R_MIPS_TLS_GOTTPREL \
414 || r_type == R_MIPS_TLS_TPREL32 \
415 || r_type == R_MIPS_TLS_TPREL64 \
416 || r_type == R_MIPS_TLS_TPREL_HI16 \
417 || r_type == R_MIPS_TLS_TPREL_LO16)
419 /* Structure used to pass information to mips_elf_output_extsym. */
424 struct bfd_link_info
*info
;
425 struct ecoff_debug_info
*debug
;
426 const struct ecoff_debug_swap
*swap
;
430 /* The names of the runtime procedure table symbols used on IRIX5. */
432 static const char * const mips_elf_dynsym_rtproc_names
[] =
435 "_procedure_string_table",
436 "_procedure_table_size",
440 /* These structures are used to generate the .compact_rel section on
445 unsigned long id1
; /* Always one? */
446 unsigned long num
; /* Number of compact relocation entries. */
447 unsigned long id2
; /* Always two? */
448 unsigned long offset
; /* The file offset of the first relocation. */
449 unsigned long reserved0
; /* Zero? */
450 unsigned long reserved1
; /* Zero? */
459 bfd_byte reserved0
[4];
460 bfd_byte reserved1
[4];
461 } Elf32_External_compact_rel
;
465 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
466 unsigned int rtype
: 4; /* Relocation types. See below. */
467 unsigned int dist2to
: 8;
468 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
469 unsigned long konst
; /* KONST field. See below. */
470 unsigned long vaddr
; /* VADDR to be relocated. */
475 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
476 unsigned int rtype
: 4; /* Relocation types. See below. */
477 unsigned int dist2to
: 8;
478 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
479 unsigned long konst
; /* KONST field. See below. */
487 } Elf32_External_crinfo
;
493 } Elf32_External_crinfo2
;
495 /* These are the constants used to swap the bitfields in a crinfo. */
497 #define CRINFO_CTYPE (0x1)
498 #define CRINFO_CTYPE_SH (31)
499 #define CRINFO_RTYPE (0xf)
500 #define CRINFO_RTYPE_SH (27)
501 #define CRINFO_DIST2TO (0xff)
502 #define CRINFO_DIST2TO_SH (19)
503 #define CRINFO_RELVADDR (0x7ffff)
504 #define CRINFO_RELVADDR_SH (0)
506 /* A compact relocation info has long (3 words) or short (2 words)
507 formats. A short format doesn't have VADDR field and relvaddr
508 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
509 #define CRF_MIPS_LONG 1
510 #define CRF_MIPS_SHORT 0
512 /* There are 4 types of compact relocation at least. The value KONST
513 has different meaning for each type:
516 CT_MIPS_REL32 Address in data
517 CT_MIPS_WORD Address in word (XXX)
518 CT_MIPS_GPHI_LO GP - vaddr
519 CT_MIPS_JMPAD Address to jump
522 #define CRT_MIPS_REL32 0xa
523 #define CRT_MIPS_WORD 0xb
524 #define CRT_MIPS_GPHI_LO 0xc
525 #define CRT_MIPS_JMPAD 0xd
527 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
528 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
529 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
530 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
532 /* The structure of the runtime procedure descriptor created by the
533 loader for use by the static exception system. */
535 typedef struct runtime_pdr
{
536 bfd_vma adr
; /* Memory address of start of procedure. */
537 long regmask
; /* Save register mask. */
538 long regoffset
; /* Save register offset. */
539 long fregmask
; /* Save floating point register mask. */
540 long fregoffset
; /* Save floating point register offset. */
541 long frameoffset
; /* Frame size. */
542 short framereg
; /* Frame pointer register. */
543 short pcreg
; /* Offset or reg of return pc. */
544 long irpss
; /* Index into the runtime string table. */
546 struct exception_info
*exception_info
;/* Pointer to exception array. */
548 #define cbRPDR sizeof (RPDR)
549 #define rpdNil ((pRPDR) 0)
551 static struct mips_got_entry
*mips_elf_create_local_got_entry
552 (bfd
*, struct bfd_link_info
*, bfd
*, bfd_vma
, unsigned long,
553 struct mips_elf_link_hash_entry
*, int);
554 static bfd_boolean mips_elf_sort_hash_table_f
555 (struct mips_elf_link_hash_entry
*, void *);
556 static bfd_vma mips_elf_high
558 static bfd_boolean mips_elf_create_dynamic_relocation
559 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
560 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
561 bfd_vma
*, asection
*);
562 static hashval_t mips_elf_got_entry_hash
564 static bfd_vma mips_elf_adjust_gp
565 (bfd
*, struct mips_got_info
*, bfd
*);
566 static struct mips_got_info
*mips_elf_got_for_ibfd
567 (struct mips_got_info
*, bfd
*);
569 /* This will be used when we sort the dynamic relocation records. */
570 static bfd
*reldyn_sorting_bfd
;
572 /* Nonzero if ABFD is using the N32 ABI. */
573 #define ABI_N32_P(abfd) \
574 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
576 /* Nonzero if ABFD is using the N64 ABI. */
577 #define ABI_64_P(abfd) \
578 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
580 /* Nonzero if ABFD is using NewABI conventions. */
581 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
583 /* The IRIX compatibility level we are striving for. */
584 #define IRIX_COMPAT(abfd) \
585 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
587 /* Whether we are trying to be compatible with IRIX at all. */
588 #define SGI_COMPAT(abfd) \
589 (IRIX_COMPAT (abfd) != ict_none)
591 /* The name of the options section. */
592 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
593 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
595 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
596 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
597 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
598 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
600 /* Whether the section is readonly. */
601 #define MIPS_ELF_READONLY_SECTION(sec) \
602 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
603 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
605 /* The name of the stub section. */
606 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
608 /* The size of an external REL relocation. */
609 #define MIPS_ELF_REL_SIZE(abfd) \
610 (get_elf_backend_data (abfd)->s->sizeof_rel)
612 /* The size of an external RELA relocation. */
613 #define MIPS_ELF_RELA_SIZE(abfd) \
614 (get_elf_backend_data (abfd)->s->sizeof_rela)
616 /* The size of an external dynamic table entry. */
617 #define MIPS_ELF_DYN_SIZE(abfd) \
618 (get_elf_backend_data (abfd)->s->sizeof_dyn)
620 /* The size of a GOT entry. */
621 #define MIPS_ELF_GOT_SIZE(abfd) \
622 (get_elf_backend_data (abfd)->s->arch_size / 8)
624 /* The size of a symbol-table entry. */
625 #define MIPS_ELF_SYM_SIZE(abfd) \
626 (get_elf_backend_data (abfd)->s->sizeof_sym)
628 /* The default alignment for sections, as a power of two. */
629 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
630 (get_elf_backend_data (abfd)->s->log_file_align)
632 /* Get word-sized data. */
633 #define MIPS_ELF_GET_WORD(abfd, ptr) \
634 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
636 /* Put out word-sized data. */
637 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
639 ? bfd_put_64 (abfd, val, ptr) \
640 : bfd_put_32 (abfd, val, ptr))
642 /* Add a dynamic symbol table-entry. */
643 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
644 _bfd_elf_add_dynamic_entry (info, tag, val)
646 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
647 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
649 /* Determine whether the internal relocation of index REL_IDX is REL
650 (zero) or RELA (non-zero). The assumption is that, if there are
651 two relocation sections for this section, one of them is REL and
652 the other is RELA. If the index of the relocation we're testing is
653 in range for the first relocation section, check that the external
654 relocation size is that for RELA. It is also assumed that, if
655 rel_idx is not in range for the first section, and this first
656 section contains REL relocs, then the relocation is in the second
657 section, that is RELA. */
658 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
659 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
660 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
661 > (bfd_vma)(rel_idx)) \
662 == (elf_section_data (sec)->rel_hdr.sh_entsize \
663 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
664 : sizeof (Elf32_External_Rela))))
666 /* The name of the dynamic relocation section. */
667 #define MIPS_ELF_REL_DYN_NAME(INFO) \
668 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
670 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
671 from smaller values. Start with zero, widen, *then* decrement. */
672 #define MINUS_ONE (((bfd_vma)0) - 1)
673 #define MINUS_TWO (((bfd_vma)0) - 2)
675 /* The number of local .got entries we reserve. */
676 #define MIPS_RESERVED_GOTNO(INFO) \
677 (mips_elf_hash_table (INFO)->is_vxworks ? 3 : 2)
679 /* The value to write into got[1] for SVR4 targets, to identify it is
680 a GNU object. The dynamic linker can then use got[1] to store the
682 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
683 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
685 /* The offset of $gp from the beginning of the .got section. */
686 #define ELF_MIPS_GP_OFFSET(INFO) \
687 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
689 /* The maximum size of the GOT for it to be addressable using 16-bit
691 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
693 /* Instructions which appear in a stub. */
694 #define STUB_LW(abfd) \
696 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
697 : 0x8f998010)) /* lw t9,0x8010(gp) */
698 #define STUB_MOVE(abfd) \
700 ? 0x03e0782d /* daddu t7,ra */ \
701 : 0x03e07821)) /* addu t7,ra */
702 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
703 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
704 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
705 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
706 #define STUB_LI16S(abfd, VAL) \
708 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
709 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
711 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
712 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
714 /* The name of the dynamic interpreter. This is put in the .interp
717 #define ELF_DYNAMIC_INTERPRETER(abfd) \
718 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
719 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
720 : "/usr/lib/libc.so.1")
723 #define MNAME(bfd,pre,pos) \
724 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
725 #define ELF_R_SYM(bfd, i) \
726 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
727 #define ELF_R_TYPE(bfd, i) \
728 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
729 #define ELF_R_INFO(bfd, s, t) \
730 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
732 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
733 #define ELF_R_SYM(bfd, i) \
735 #define ELF_R_TYPE(bfd, i) \
737 #define ELF_R_INFO(bfd, s, t) \
738 (ELF32_R_INFO (s, t))
741 /* The mips16 compiler uses a couple of special sections to handle
742 floating point arguments.
744 Section names that look like .mips16.fn.FNNAME contain stubs that
745 copy floating point arguments from the fp regs to the gp regs and
746 then jump to FNNAME. If any 32 bit function calls FNNAME, the
747 call should be redirected to the stub instead. If no 32 bit
748 function calls FNNAME, the stub should be discarded. We need to
749 consider any reference to the function, not just a call, because
750 if the address of the function is taken we will need the stub,
751 since the address might be passed to a 32 bit function.
753 Section names that look like .mips16.call.FNNAME contain stubs
754 that copy floating point arguments from the gp regs to the fp
755 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
756 then any 16 bit function that calls FNNAME should be redirected
757 to the stub instead. If FNNAME is not a 32 bit function, the
758 stub should be discarded.
760 .mips16.call.fp.FNNAME sections are similar, but contain stubs
761 which call FNNAME and then copy the return value from the fp regs
762 to the gp regs. These stubs store the return value in $18 while
763 calling FNNAME; any function which might call one of these stubs
764 must arrange to save $18 around the call. (This case is not
765 needed for 32 bit functions that call 16 bit functions, because
766 16 bit functions always return floating point values in both
769 Note that in all cases FNNAME might be defined statically.
770 Therefore, FNNAME is not used literally. Instead, the relocation
771 information will indicate which symbol the section is for.
773 We record any stubs that we find in the symbol table. */
775 #define FN_STUB ".mips16.fn."
776 #define CALL_STUB ".mips16.call."
777 #define CALL_FP_STUB ".mips16.call.fp."
779 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
780 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
781 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
783 /* The format of the first PLT entry in a VxWorks executable. */
784 static const bfd_vma mips_vxworks_exec_plt0_entry
[] = {
785 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
786 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
787 0x8f390008, /* lw t9, 8(t9) */
788 0x00000000, /* nop */
789 0x03200008, /* jr t9 */
793 /* The format of subsequent PLT entries. */
794 static const bfd_vma mips_vxworks_exec_plt_entry
[] = {
795 0x10000000, /* b .PLT_resolver */
796 0x24180000, /* li t8, <pltindex> */
797 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
798 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
799 0x8f390000, /* lw t9, 0(t9) */
800 0x00000000, /* nop */
801 0x03200008, /* jr t9 */
805 /* The format of the first PLT entry in a VxWorks shared object. */
806 static const bfd_vma mips_vxworks_shared_plt0_entry
[] = {
807 0x8f990008, /* lw t9, 8(gp) */
808 0x00000000, /* nop */
809 0x03200008, /* jr t9 */
810 0x00000000, /* nop */
811 0x00000000, /* nop */
815 /* The format of subsequent PLT entries. */
816 static const bfd_vma mips_vxworks_shared_plt_entry
[] = {
817 0x10000000, /* b .PLT_resolver */
818 0x24180000 /* li t8, <pltindex> */
821 /* Look up an entry in a MIPS ELF linker hash table. */
823 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
824 ((struct mips_elf_link_hash_entry *) \
825 elf_link_hash_lookup (&(table)->root, (string), (create), \
828 /* Traverse a MIPS ELF linker hash table. */
830 #define mips_elf_link_hash_traverse(table, func, info) \
831 (elf_link_hash_traverse \
833 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
836 /* Get the MIPS ELF linker hash table from a link_info structure. */
838 #define mips_elf_hash_table(p) \
839 ((struct mips_elf_link_hash_table *) ((p)->hash))
841 /* Find the base offsets for thread-local storage in this object,
842 for GD/LD and IE/LE respectively. */
844 #define TP_OFFSET 0x7000
845 #define DTP_OFFSET 0x8000
848 dtprel_base (struct bfd_link_info
*info
)
850 /* If tls_sec is NULL, we should have signalled an error already. */
851 if (elf_hash_table (info
)->tls_sec
== NULL
)
853 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
857 tprel_base (struct bfd_link_info
*info
)
859 /* If tls_sec is NULL, we should have signalled an error already. */
860 if (elf_hash_table (info
)->tls_sec
== NULL
)
862 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
865 /* Create an entry in a MIPS ELF linker hash table. */
867 static struct bfd_hash_entry
*
868 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
869 struct bfd_hash_table
*table
, const char *string
)
871 struct mips_elf_link_hash_entry
*ret
=
872 (struct mips_elf_link_hash_entry
*) entry
;
874 /* Allocate the structure if it has not already been allocated by a
877 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
879 return (struct bfd_hash_entry
*) ret
;
881 /* Call the allocation method of the superclass. */
882 ret
= ((struct mips_elf_link_hash_entry
*)
883 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
887 /* Set local fields. */
888 memset (&ret
->esym
, 0, sizeof (EXTR
));
889 /* We use -2 as a marker to indicate that the information has
890 not been set. -1 means there is no associated ifd. */
892 ret
->possibly_dynamic_relocs
= 0;
894 ret
->call_stub
= NULL
;
895 ret
->call_fp_stub
= NULL
;
896 ret
->tls_type
= GOT_NORMAL
;
897 ret
->global_got_area
= GGA_NONE
;
898 ret
->readonly_reloc
= FALSE
;
899 ret
->no_fn_stub
= FALSE
;
900 ret
->need_fn_stub
= FALSE
;
901 ret
->is_relocation_target
= FALSE
;
902 ret
->is_branch_target
= FALSE
;
903 ret
->needs_lazy_stub
= FALSE
;
906 return (struct bfd_hash_entry
*) ret
;
910 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
912 if (!sec
->used_by_bfd
)
914 struct _mips_elf_section_data
*sdata
;
915 bfd_size_type amt
= sizeof (*sdata
);
917 sdata
= bfd_zalloc (abfd
, amt
);
920 sec
->used_by_bfd
= sdata
;
923 return _bfd_elf_new_section_hook (abfd
, sec
);
926 /* Read ECOFF debugging information from a .mdebug section into a
927 ecoff_debug_info structure. */
930 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
931 struct ecoff_debug_info
*debug
)
934 const struct ecoff_debug_swap
*swap
;
937 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
938 memset (debug
, 0, sizeof (*debug
));
940 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
941 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
944 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
945 swap
->external_hdr_size
))
948 symhdr
= &debug
->symbolic_header
;
949 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
951 /* The symbolic header contains absolute file offsets and sizes to
953 #define READ(ptr, offset, count, size, type) \
954 if (symhdr->count == 0) \
958 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
959 debug->ptr = bfd_malloc (amt); \
960 if (debug->ptr == NULL) \
962 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
963 || bfd_bread (debug->ptr, amt, abfd) != amt) \
967 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
968 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
969 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
970 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
971 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
972 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
974 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
975 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
976 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
977 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
978 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
988 if (debug
->line
!= NULL
)
990 if (debug
->external_dnr
!= NULL
)
991 free (debug
->external_dnr
);
992 if (debug
->external_pdr
!= NULL
)
993 free (debug
->external_pdr
);
994 if (debug
->external_sym
!= NULL
)
995 free (debug
->external_sym
);
996 if (debug
->external_opt
!= NULL
)
997 free (debug
->external_opt
);
998 if (debug
->external_aux
!= NULL
)
999 free (debug
->external_aux
);
1000 if (debug
->ss
!= NULL
)
1002 if (debug
->ssext
!= NULL
)
1003 free (debug
->ssext
);
1004 if (debug
->external_fdr
!= NULL
)
1005 free (debug
->external_fdr
);
1006 if (debug
->external_rfd
!= NULL
)
1007 free (debug
->external_rfd
);
1008 if (debug
->external_ext
!= NULL
)
1009 free (debug
->external_ext
);
1013 /* Swap RPDR (runtime procedure table entry) for output. */
1016 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
1018 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
1019 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
1020 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
1021 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
1022 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
1023 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
1025 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
1026 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1028 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1031 /* Create a runtime procedure table from the .mdebug section. */
1034 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1035 struct bfd_link_info
*info
, asection
*s
,
1036 struct ecoff_debug_info
*debug
)
1038 const struct ecoff_debug_swap
*swap
;
1039 HDRR
*hdr
= &debug
->symbolic_header
;
1041 struct rpdr_ext
*erp
;
1043 struct pdr_ext
*epdr
;
1044 struct sym_ext
*esym
;
1048 bfd_size_type count
;
1049 unsigned long sindex
;
1053 const char *no_name_func
= _("static procedure (no name)");
1061 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1063 sindex
= strlen (no_name_func
) + 1;
1064 count
= hdr
->ipdMax
;
1067 size
= swap
->external_pdr_size
;
1069 epdr
= bfd_malloc (size
* count
);
1073 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1076 size
= sizeof (RPDR
);
1077 rp
= rpdr
= bfd_malloc (size
* count
);
1081 size
= sizeof (char *);
1082 sv
= bfd_malloc (size
* count
);
1086 count
= hdr
->isymMax
;
1087 size
= swap
->external_sym_size
;
1088 esym
= bfd_malloc (size
* count
);
1092 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1095 count
= hdr
->issMax
;
1096 ss
= bfd_malloc (count
);
1099 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1102 count
= hdr
->ipdMax
;
1103 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1105 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1106 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1107 rp
->adr
= sym
.value
;
1108 rp
->regmask
= pdr
.regmask
;
1109 rp
->regoffset
= pdr
.regoffset
;
1110 rp
->fregmask
= pdr
.fregmask
;
1111 rp
->fregoffset
= pdr
.fregoffset
;
1112 rp
->frameoffset
= pdr
.frameoffset
;
1113 rp
->framereg
= pdr
.framereg
;
1114 rp
->pcreg
= pdr
.pcreg
;
1116 sv
[i
] = ss
+ sym
.iss
;
1117 sindex
+= strlen (sv
[i
]) + 1;
1121 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1122 size
= BFD_ALIGN (size
, 16);
1123 rtproc
= bfd_alloc (abfd
, size
);
1126 mips_elf_hash_table (info
)->procedure_count
= 0;
1130 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1133 memset (erp
, 0, sizeof (struct rpdr_ext
));
1135 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1136 strcpy (str
, no_name_func
);
1137 str
+= strlen (no_name_func
) + 1;
1138 for (i
= 0; i
< count
; i
++)
1140 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1141 strcpy (str
, sv
[i
]);
1142 str
+= strlen (sv
[i
]) + 1;
1144 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1146 /* Set the size and contents of .rtproc section. */
1148 s
->contents
= rtproc
;
1150 /* Skip this section later on (I don't think this currently
1151 matters, but someday it might). */
1152 s
->map_head
.link_order
= NULL
;
1181 /* We're about to redefine H. Create a symbol to represent H's
1182 current value and size, to help make the disassembly easier
1186 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1187 struct mips_elf_link_hash_entry
*h
,
1190 struct bfd_link_hash_entry
*bh
;
1191 struct elf_link_hash_entry
*elfh
;
1196 /* Read the symbol's value. */
1197 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1198 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1199 s
= h
->root
.root
.u
.def
.section
;
1200 value
= h
->root
.root
.u
.def
.value
;
1202 /* Create a new symbol. */
1203 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1205 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1206 BSF_LOCAL
, s
, value
, NULL
,
1210 /* Make it local and copy the other attributes from H. */
1211 elfh
= (struct elf_link_hash_entry
*) bh
;
1212 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1213 elfh
->other
= h
->root
.other
;
1214 elfh
->size
= h
->root
.size
;
1215 elfh
->forced_local
= 1;
1219 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1220 function rather than to a hard-float stub. */
1223 section_allows_mips16_refs_p (asection
*section
)
1227 name
= bfd_get_section_name (section
->owner
, section
);
1228 return (FN_STUB_P (name
)
1229 || CALL_STUB_P (name
)
1230 || CALL_FP_STUB_P (name
)
1231 || strcmp (name
, ".pdr") == 0);
1234 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1235 stub section of some kind. Return the R_SYMNDX of the target
1236 function, or 0 if we can't decide which function that is. */
1238 static unsigned long
1239 mips16_stub_symndx (asection
*sec
, const Elf_Internal_Rela
*relocs
,
1240 const Elf_Internal_Rela
*relend
)
1242 const Elf_Internal_Rela
*rel
;
1244 /* Trust the first R_MIPS_NONE relocation, if any. */
1245 for (rel
= relocs
; rel
< relend
; rel
++)
1246 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1247 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1249 /* Otherwise trust the first relocation, whatever its kind. This is
1250 the traditional behavior. */
1251 if (relocs
< relend
)
1252 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1257 /* Check the mips16 stubs for a particular symbol, and see if we can
1261 mips_elf_check_mips16_stubs (struct mips_elf_link_hash_entry
*h
, void *data
)
1263 struct bfd_link_info
*info
;
1265 info
= (struct bfd_link_info
*) data
;
1266 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1267 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1269 /* Dynamic symbols must use the standard call interface, in case other
1270 objects try to call them. */
1271 if (h
->fn_stub
!= NULL
1272 && h
->root
.dynindx
!= -1)
1274 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1275 h
->need_fn_stub
= TRUE
;
1278 if (h
->fn_stub
!= NULL
1279 && ! h
->need_fn_stub
)
1281 /* We don't need the fn_stub; the only references to this symbol
1282 are 16 bit calls. Clobber the size to 0 to prevent it from
1283 being included in the link. */
1284 h
->fn_stub
->size
= 0;
1285 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1286 h
->fn_stub
->reloc_count
= 0;
1287 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1290 if (h
->call_stub
!= NULL
1291 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1293 /* We don't need the call_stub; this is a 16 bit function, so
1294 calls from other 16 bit functions are OK. Clobber the size
1295 to 0 to prevent it from being included in the link. */
1296 h
->call_stub
->size
= 0;
1297 h
->call_stub
->flags
&= ~SEC_RELOC
;
1298 h
->call_stub
->reloc_count
= 0;
1299 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1302 if (h
->call_fp_stub
!= NULL
1303 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1305 /* We don't need the call_stub; this is a 16 bit function, so
1306 calls from other 16 bit functions are OK. Clobber the size
1307 to 0 to prevent it from being included in the link. */
1308 h
->call_fp_stub
->size
= 0;
1309 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1310 h
->call_fp_stub
->reloc_count
= 0;
1311 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1317 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1318 Most mips16 instructions are 16 bits, but these instructions
1321 The format of these instructions is:
1323 +--------------+--------------------------------+
1324 | JALX | X| Imm 20:16 | Imm 25:21 |
1325 +--------------+--------------------------------+
1327 +-----------------------------------------------+
1329 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1330 Note that the immediate value in the first word is swapped.
1332 When producing a relocatable object file, R_MIPS16_26 is
1333 handled mostly like R_MIPS_26. In particular, the addend is
1334 stored as a straight 26-bit value in a 32-bit instruction.
1335 (gas makes life simpler for itself by never adjusting a
1336 R_MIPS16_26 reloc to be against a section, so the addend is
1337 always zero). However, the 32 bit instruction is stored as 2
1338 16-bit values, rather than a single 32-bit value. In a
1339 big-endian file, the result is the same; in a little-endian
1340 file, the two 16-bit halves of the 32 bit value are swapped.
1341 This is so that a disassembler can recognize the jal
1344 When doing a final link, R_MIPS16_26 is treated as a 32 bit
1345 instruction stored as two 16-bit values. The addend A is the
1346 contents of the targ26 field. The calculation is the same as
1347 R_MIPS_26. When storing the calculated value, reorder the
1348 immediate value as shown above, and don't forget to store the
1349 value as two 16-bit values.
1351 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
1355 +--------+----------------------+
1359 +--------+----------------------+
1362 +----------+------+-------------+
1366 +----------+--------------------+
1367 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
1368 ((sub1 << 16) | sub2)).
1370 When producing a relocatable object file, the calculation is
1371 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1372 When producing a fully linked file, the calculation is
1373 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1374 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
1376 The table below lists the other MIPS16 instruction relocations.
1377 Each one is calculated in the same way as the non-MIPS16 relocation
1378 given on the right, but using the extended MIPS16 layout of 16-bit
1381 R_MIPS16_GPREL R_MIPS_GPREL16
1382 R_MIPS16_GOT16 R_MIPS_GOT16
1383 R_MIPS16_CALL16 R_MIPS_CALL16
1384 R_MIPS16_HI16 R_MIPS_HI16
1385 R_MIPS16_LO16 R_MIPS_LO16
1387 A typical instruction will have a format like this:
1389 +--------------+--------------------------------+
1390 | EXTEND | Imm 10:5 | Imm 15:11 |
1391 +--------------+--------------------------------+
1392 | Major | rx | ry | Imm 4:0 |
1393 +--------------+--------------------------------+
1395 EXTEND is the five bit value 11110. Major is the instruction
1398 All we need to do here is shuffle the bits appropriately.
1399 As above, the two 16-bit halves must be swapped on a
1400 little-endian system. */
1402 static inline bfd_boolean
1403 mips16_reloc_p (int r_type
)
1408 case R_MIPS16_GPREL
:
1409 case R_MIPS16_GOT16
:
1410 case R_MIPS16_CALL16
:
1420 static inline bfd_boolean
1421 got16_reloc_p (int r_type
)
1423 return r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS16_GOT16
;
1426 static inline bfd_boolean
1427 call16_reloc_p (int r_type
)
1429 return r_type
== R_MIPS_CALL16
|| r_type
== R_MIPS16_CALL16
;
1432 static inline bfd_boolean
1433 hi16_reloc_p (int r_type
)
1435 return r_type
== R_MIPS_HI16
|| r_type
== R_MIPS16_HI16
;
1438 static inline bfd_boolean
1439 lo16_reloc_p (int r_type
)
1441 return r_type
== R_MIPS_LO16
|| r_type
== R_MIPS16_LO16
;
1444 static inline bfd_boolean
1445 mips16_call_reloc_p (int r_type
)
1447 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
1451 _bfd_mips16_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
1452 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1454 bfd_vma extend
, insn
, val
;
1456 if (!mips16_reloc_p (r_type
))
1459 /* Pick up the mips16 extend instruction and the real instruction. */
1460 extend
= bfd_get_16 (abfd
, data
);
1461 insn
= bfd_get_16 (abfd
, data
+ 2);
1462 if (r_type
== R_MIPS16_26
)
1465 val
= ((extend
& 0xfc00) << 16) | ((extend
& 0x3e0) << 11)
1466 | ((extend
& 0x1f) << 21) | insn
;
1468 val
= extend
<< 16 | insn
;
1471 val
= ((extend
& 0xf800) << 16) | ((insn
& 0xffe0) << 11)
1472 | ((extend
& 0x1f) << 11) | (extend
& 0x7e0) | (insn
& 0x1f);
1473 bfd_put_32 (abfd
, val
, data
);
1477 _bfd_mips16_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
1478 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1480 bfd_vma extend
, insn
, val
;
1482 if (!mips16_reloc_p (r_type
))
1485 val
= bfd_get_32 (abfd
, data
);
1486 if (r_type
== R_MIPS16_26
)
1490 insn
= val
& 0xffff;
1491 extend
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
1492 | ((val
>> 21) & 0x1f);
1496 insn
= val
& 0xffff;
1502 insn
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
1503 extend
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
1505 bfd_put_16 (abfd
, insn
, data
+ 2);
1506 bfd_put_16 (abfd
, extend
, data
);
1509 bfd_reloc_status_type
1510 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1511 arelent
*reloc_entry
, asection
*input_section
,
1512 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1516 bfd_reloc_status_type status
;
1518 if (bfd_is_com_section (symbol
->section
))
1521 relocation
= symbol
->value
;
1523 relocation
+= symbol
->section
->output_section
->vma
;
1524 relocation
+= symbol
->section
->output_offset
;
1526 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1527 return bfd_reloc_outofrange
;
1529 /* Set val to the offset into the section or symbol. */
1530 val
= reloc_entry
->addend
;
1532 _bfd_mips_elf_sign_extend (val
, 16);
1534 /* Adjust val for the final section location and GP value. If we
1535 are producing relocatable output, we don't want to do this for
1536 an external symbol. */
1538 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1539 val
+= relocation
- gp
;
1541 if (reloc_entry
->howto
->partial_inplace
)
1543 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1545 + reloc_entry
->address
);
1546 if (status
!= bfd_reloc_ok
)
1550 reloc_entry
->addend
= val
;
1553 reloc_entry
->address
+= input_section
->output_offset
;
1555 return bfd_reloc_ok
;
1558 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
1559 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
1560 that contains the relocation field and DATA points to the start of
1565 struct mips_hi16
*next
;
1567 asection
*input_section
;
1571 /* FIXME: This should not be a static variable. */
1573 static struct mips_hi16
*mips_hi16_list
;
1575 /* A howto special_function for REL *HI16 relocations. We can only
1576 calculate the correct value once we've seen the partnering
1577 *LO16 relocation, so just save the information for later.
1579 The ABI requires that the *LO16 immediately follow the *HI16.
1580 However, as a GNU extension, we permit an arbitrary number of
1581 *HI16s to be associated with a single *LO16. This significantly
1582 simplies the relocation handling in gcc. */
1584 bfd_reloc_status_type
1585 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1586 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
1587 asection
*input_section
, bfd
*output_bfd
,
1588 char **error_message ATTRIBUTE_UNUSED
)
1590 struct mips_hi16
*n
;
1592 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1593 return bfd_reloc_outofrange
;
1595 n
= bfd_malloc (sizeof *n
);
1597 return bfd_reloc_outofrange
;
1599 n
->next
= mips_hi16_list
;
1601 n
->input_section
= input_section
;
1602 n
->rel
= *reloc_entry
;
1605 if (output_bfd
!= NULL
)
1606 reloc_entry
->address
+= input_section
->output_offset
;
1608 return bfd_reloc_ok
;
1611 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
1612 like any other 16-bit relocation when applied to global symbols, but is
1613 treated in the same as R_MIPS_HI16 when applied to local symbols. */
1615 bfd_reloc_status_type
1616 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1617 void *data
, asection
*input_section
,
1618 bfd
*output_bfd
, char **error_message
)
1620 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
1621 || bfd_is_und_section (bfd_get_section (symbol
))
1622 || bfd_is_com_section (bfd_get_section (symbol
)))
1623 /* The relocation is against a global symbol. */
1624 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1625 input_section
, output_bfd
,
1628 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1629 input_section
, output_bfd
, error_message
);
1632 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
1633 is a straightforward 16 bit inplace relocation, but we must deal with
1634 any partnering high-part relocations as well. */
1636 bfd_reloc_status_type
1637 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1638 void *data
, asection
*input_section
,
1639 bfd
*output_bfd
, char **error_message
)
1642 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1644 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1645 return bfd_reloc_outofrange
;
1647 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1649 vallo
= bfd_get_32 (abfd
, location
);
1650 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1653 while (mips_hi16_list
!= NULL
)
1655 bfd_reloc_status_type ret
;
1656 struct mips_hi16
*hi
;
1658 hi
= mips_hi16_list
;
1660 /* R_MIPS*_GOT16 relocations are something of a special case. We
1661 want to install the addend in the same way as for a R_MIPS*_HI16
1662 relocation (with a rightshift of 16). However, since GOT16
1663 relocations can also be used with global symbols, their howto
1664 has a rightshift of 0. */
1665 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
1666 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
1667 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
1668 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
1670 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
1671 carry or borrow will induce a change of +1 or -1 in the high part. */
1672 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
1674 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
1675 hi
->input_section
, output_bfd
,
1677 if (ret
!= bfd_reloc_ok
)
1680 mips_hi16_list
= hi
->next
;
1684 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1685 input_section
, output_bfd
,
1689 /* A generic howto special_function. This calculates and installs the
1690 relocation itself, thus avoiding the oft-discussed problems in
1691 bfd_perform_relocation and bfd_install_relocation. */
1693 bfd_reloc_status_type
1694 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1695 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
1696 asection
*input_section
, bfd
*output_bfd
,
1697 char **error_message ATTRIBUTE_UNUSED
)
1700 bfd_reloc_status_type status
;
1701 bfd_boolean relocatable
;
1703 relocatable
= (output_bfd
!= NULL
);
1705 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1706 return bfd_reloc_outofrange
;
1708 /* Build up the field adjustment in VAL. */
1710 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1712 /* Either we're calculating the final field value or we have a
1713 relocation against a section symbol. Add in the section's
1714 offset or address. */
1715 val
+= symbol
->section
->output_section
->vma
;
1716 val
+= symbol
->section
->output_offset
;
1721 /* We're calculating the final field value. Add in the symbol's value
1722 and, if pc-relative, subtract the address of the field itself. */
1723 val
+= symbol
->value
;
1724 if (reloc_entry
->howto
->pc_relative
)
1726 val
-= input_section
->output_section
->vma
;
1727 val
-= input_section
->output_offset
;
1728 val
-= reloc_entry
->address
;
1732 /* VAL is now the final adjustment. If we're keeping this relocation
1733 in the output file, and if the relocation uses a separate addend,
1734 we just need to add VAL to that addend. Otherwise we need to add
1735 VAL to the relocation field itself. */
1736 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
1737 reloc_entry
->addend
+= val
;
1740 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1742 /* Add in the separate addend, if any. */
1743 val
+= reloc_entry
->addend
;
1745 /* Add VAL to the relocation field. */
1746 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1748 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1750 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1753 if (status
!= bfd_reloc_ok
)
1758 reloc_entry
->address
+= input_section
->output_offset
;
1760 return bfd_reloc_ok
;
1763 /* Swap an entry in a .gptab section. Note that these routines rely
1764 on the equivalence of the two elements of the union. */
1767 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
1770 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1771 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1775 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
1776 Elf32_External_gptab
*ex
)
1778 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
1779 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
1783 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
1784 Elf32_External_compact_rel
*ex
)
1786 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1787 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1788 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1789 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1790 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1791 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1795 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
1796 Elf32_External_crinfo
*ex
)
1800 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1801 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1802 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1803 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1804 H_PUT_32 (abfd
, l
, ex
->info
);
1805 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1806 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1809 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1810 routines swap this structure in and out. They are used outside of
1811 BFD, so they are globally visible. */
1814 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
1817 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1818 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1819 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1820 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1821 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1822 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1826 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
1827 Elf32_External_RegInfo
*ex
)
1829 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1830 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1831 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1832 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1833 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1834 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1837 /* In the 64 bit ABI, the .MIPS.options section holds register
1838 information in an Elf64_Reginfo structure. These routines swap
1839 them in and out. They are globally visible because they are used
1840 outside of BFD. These routines are here so that gas can call them
1841 without worrying about whether the 64 bit ABI has been included. */
1844 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
1845 Elf64_Internal_RegInfo
*in
)
1847 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1848 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1849 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1850 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1851 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1852 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1853 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1857 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
1858 Elf64_External_RegInfo
*ex
)
1860 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1861 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1862 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1863 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1864 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1865 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1866 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1869 /* Swap in an options header. */
1872 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
1873 Elf_Internal_Options
*in
)
1875 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1876 in
->size
= H_GET_8 (abfd
, ex
->size
);
1877 in
->section
= H_GET_16 (abfd
, ex
->section
);
1878 in
->info
= H_GET_32 (abfd
, ex
->info
);
1881 /* Swap out an options header. */
1884 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
1885 Elf_External_Options
*ex
)
1887 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1888 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1889 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1890 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1893 /* This function is called via qsort() to sort the dynamic relocation
1894 entries by increasing r_symndx value. */
1897 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
1899 Elf_Internal_Rela int_reloc1
;
1900 Elf_Internal_Rela int_reloc2
;
1903 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1904 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1906 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
1910 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
1912 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
1917 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
1920 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
1921 const void *arg2 ATTRIBUTE_UNUSED
)
1924 Elf_Internal_Rela int_reloc1
[3];
1925 Elf_Internal_Rela int_reloc2
[3];
1927 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1928 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
1929 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1930 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
1932 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
1934 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
1937 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
1939 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
1948 /* This routine is used to write out ECOFF debugging external symbol
1949 information. It is called via mips_elf_link_hash_traverse. The
1950 ECOFF external symbol information must match the ELF external
1951 symbol information. Unfortunately, at this point we don't know
1952 whether a symbol is required by reloc information, so the two
1953 tables may wind up being different. We must sort out the external
1954 symbol information before we can set the final size of the .mdebug
1955 section, and we must set the size of the .mdebug section before we
1956 can relocate any sections, and we can't know which symbols are
1957 required by relocation until we relocate the sections.
1958 Fortunately, it is relatively unlikely that any symbol will be
1959 stripped but required by a reloc. In particular, it can not happen
1960 when generating a final executable. */
1963 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
1965 struct extsym_info
*einfo
= data
;
1967 asection
*sec
, *output_section
;
1969 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1970 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1972 if (h
->root
.indx
== -2)
1974 else if ((h
->root
.def_dynamic
1975 || h
->root
.ref_dynamic
1976 || h
->root
.type
== bfd_link_hash_new
)
1977 && !h
->root
.def_regular
1978 && !h
->root
.ref_regular
)
1980 else if (einfo
->info
->strip
== strip_all
1981 || (einfo
->info
->strip
== strip_some
1982 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1983 h
->root
.root
.root
.string
,
1984 FALSE
, FALSE
) == NULL
))
1992 if (h
->esym
.ifd
== -2)
1995 h
->esym
.cobol_main
= 0;
1996 h
->esym
.weakext
= 0;
1997 h
->esym
.reserved
= 0;
1998 h
->esym
.ifd
= ifdNil
;
1999 h
->esym
.asym
.value
= 0;
2000 h
->esym
.asym
.st
= stGlobal
;
2002 if (h
->root
.root
.type
== bfd_link_hash_undefined
2003 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
2007 /* Use undefined class. Also, set class and type for some
2009 name
= h
->root
.root
.root
.string
;
2010 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2011 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2013 h
->esym
.asym
.sc
= scData
;
2014 h
->esym
.asym
.st
= stLabel
;
2015 h
->esym
.asym
.value
= 0;
2017 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2019 h
->esym
.asym
.sc
= scAbs
;
2020 h
->esym
.asym
.st
= stLabel
;
2021 h
->esym
.asym
.value
=
2022 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2024 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
2026 h
->esym
.asym
.sc
= scAbs
;
2027 h
->esym
.asym
.st
= stLabel
;
2028 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2031 h
->esym
.asym
.sc
= scUndefined
;
2033 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2034 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2035 h
->esym
.asym
.sc
= scAbs
;
2040 sec
= h
->root
.root
.u
.def
.section
;
2041 output_section
= sec
->output_section
;
2043 /* When making a shared library and symbol h is the one from
2044 the another shared library, OUTPUT_SECTION may be null. */
2045 if (output_section
== NULL
)
2046 h
->esym
.asym
.sc
= scUndefined
;
2049 name
= bfd_section_name (output_section
->owner
, output_section
);
2051 if (strcmp (name
, ".text") == 0)
2052 h
->esym
.asym
.sc
= scText
;
2053 else if (strcmp (name
, ".data") == 0)
2054 h
->esym
.asym
.sc
= scData
;
2055 else if (strcmp (name
, ".sdata") == 0)
2056 h
->esym
.asym
.sc
= scSData
;
2057 else if (strcmp (name
, ".rodata") == 0
2058 || strcmp (name
, ".rdata") == 0)
2059 h
->esym
.asym
.sc
= scRData
;
2060 else if (strcmp (name
, ".bss") == 0)
2061 h
->esym
.asym
.sc
= scBss
;
2062 else if (strcmp (name
, ".sbss") == 0)
2063 h
->esym
.asym
.sc
= scSBss
;
2064 else if (strcmp (name
, ".init") == 0)
2065 h
->esym
.asym
.sc
= scInit
;
2066 else if (strcmp (name
, ".fini") == 0)
2067 h
->esym
.asym
.sc
= scFini
;
2069 h
->esym
.asym
.sc
= scAbs
;
2073 h
->esym
.asym
.reserved
= 0;
2074 h
->esym
.asym
.index
= indexNil
;
2077 if (h
->root
.root
.type
== bfd_link_hash_common
)
2078 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2079 else if (h
->root
.root
.type
== bfd_link_hash_defined
2080 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2082 if (h
->esym
.asym
.sc
== scCommon
)
2083 h
->esym
.asym
.sc
= scBss
;
2084 else if (h
->esym
.asym
.sc
== scSCommon
)
2085 h
->esym
.asym
.sc
= scSBss
;
2087 sec
= h
->root
.root
.u
.def
.section
;
2088 output_section
= sec
->output_section
;
2089 if (output_section
!= NULL
)
2090 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2091 + sec
->output_offset
2092 + output_section
->vma
);
2094 h
->esym
.asym
.value
= 0;
2098 struct mips_elf_link_hash_entry
*hd
= h
;
2100 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
2101 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2103 if (hd
->needs_lazy_stub
)
2105 /* Set type and value for a symbol with a function stub. */
2106 h
->esym
.asym
.st
= stProc
;
2107 sec
= hd
->root
.root
.u
.def
.section
;
2109 h
->esym
.asym
.value
= 0;
2112 output_section
= sec
->output_section
;
2113 if (output_section
!= NULL
)
2114 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
2115 + sec
->output_offset
2116 + output_section
->vma
);
2118 h
->esym
.asym
.value
= 0;
2123 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2124 h
->root
.root
.root
.string
,
2127 einfo
->failed
= TRUE
;
2134 /* A comparison routine used to sort .gptab entries. */
2137 gptab_compare (const void *p1
, const void *p2
)
2139 const Elf32_gptab
*a1
= p1
;
2140 const Elf32_gptab
*a2
= p2
;
2142 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
2145 /* Functions to manage the got entry hash table. */
2147 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
2150 static INLINE hashval_t
2151 mips_elf_hash_bfd_vma (bfd_vma addr
)
2154 return addr
+ (addr
>> 32);
2160 /* got_entries only match if they're identical, except for gotidx, so
2161 use all fields to compute the hash, and compare the appropriate
2165 mips_elf_got_entry_hash (const void *entry_
)
2167 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2169 return entry
->symndx
2170 + ((entry
->tls_type
& GOT_TLS_LDM
) << 17)
2171 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
2173 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
2174 : entry
->d
.h
->root
.root
.root
.hash
));
2178 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
2180 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2181 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2183 /* An LDM entry can only match another LDM entry. */
2184 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2187 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
2188 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
2189 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
2190 : e1
->d
.h
== e2
->d
.h
);
2193 /* multi_got_entries are still a match in the case of global objects,
2194 even if the input bfd in which they're referenced differs, so the
2195 hash computation and compare functions are adjusted
2199 mips_elf_multi_got_entry_hash (const void *entry_
)
2201 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2203 return entry
->symndx
2205 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
2206 : entry
->symndx
>= 0
2207 ? ((entry
->tls_type
& GOT_TLS_LDM
)
2208 ? (GOT_TLS_LDM
<< 17)
2210 + mips_elf_hash_bfd_vma (entry
->d
.addend
)))
2211 : entry
->d
.h
->root
.root
.root
.hash
);
2215 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
2217 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2218 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2220 /* Any two LDM entries match. */
2221 if (e1
->tls_type
& e2
->tls_type
& GOT_TLS_LDM
)
2224 /* Nothing else matches an LDM entry. */
2225 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2228 return e1
->symndx
== e2
->symndx
2229 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
2230 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
2231 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
2232 : e1
->d
.h
== e2
->d
.h
);
2236 mips_got_page_entry_hash (const void *entry_
)
2238 const struct mips_got_page_entry
*entry
;
2240 entry
= (const struct mips_got_page_entry
*) entry_
;
2241 return entry
->abfd
->id
+ entry
->symndx
;
2245 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
2247 const struct mips_got_page_entry
*entry1
, *entry2
;
2249 entry1
= (const struct mips_got_page_entry
*) entry1_
;
2250 entry2
= (const struct mips_got_page_entry
*) entry2_
;
2251 return entry1
->abfd
== entry2
->abfd
&& entry1
->symndx
== entry2
->symndx
;
2254 /* Return the dynamic relocation section. If it doesn't exist, try to
2255 create a new it if CREATE_P, otherwise return NULL. Also return NULL
2256 if creation fails. */
2259 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
2265 dname
= MIPS_ELF_REL_DYN_NAME (info
);
2266 dynobj
= elf_hash_table (info
)->dynobj
;
2267 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
2268 if (sreloc
== NULL
&& create_p
)
2270 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
2275 | SEC_LINKER_CREATED
2278 || ! bfd_set_section_alignment (dynobj
, sreloc
,
2279 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
2285 /* Count the number of relocations needed for a TLS GOT entry, with
2286 access types from TLS_TYPE, and symbol H (or a local symbol if H
2290 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
2291 struct elf_link_hash_entry
*h
)
2295 bfd_boolean need_relocs
= FALSE
;
2296 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2298 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2299 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
2302 if ((info
->shared
|| indx
!= 0)
2304 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2305 || h
->root
.type
!= bfd_link_hash_undefweak
))
2311 if (tls_type
& GOT_TLS_GD
)
2318 if (tls_type
& GOT_TLS_IE
)
2321 if ((tls_type
& GOT_TLS_LDM
) && info
->shared
)
2327 /* Count the number of TLS relocations required for the GOT entry in
2328 ARG1, if it describes a local symbol. */
2331 mips_elf_count_local_tls_relocs (void **arg1
, void *arg2
)
2333 struct mips_got_entry
*entry
= * (struct mips_got_entry
**) arg1
;
2334 struct mips_elf_count_tls_arg
*arg
= arg2
;
2336 if (entry
->abfd
!= NULL
&& entry
->symndx
!= -1)
2337 arg
->needed
+= mips_tls_got_relocs (arg
->info
, entry
->tls_type
, NULL
);
2342 /* Count the number of TLS GOT entries required for the global (or
2343 forced-local) symbol in ARG1. */
2346 mips_elf_count_global_tls_entries (void *arg1
, void *arg2
)
2348 struct mips_elf_link_hash_entry
*hm
2349 = (struct mips_elf_link_hash_entry
*) arg1
;
2350 struct mips_elf_count_tls_arg
*arg
= arg2
;
2352 if (hm
->tls_type
& GOT_TLS_GD
)
2354 if (hm
->tls_type
& GOT_TLS_IE
)
2360 /* Count the number of TLS relocations required for the global (or
2361 forced-local) symbol in ARG1. */
2364 mips_elf_count_global_tls_relocs (void *arg1
, void *arg2
)
2366 struct mips_elf_link_hash_entry
*hm
2367 = (struct mips_elf_link_hash_entry
*) arg1
;
2368 struct mips_elf_count_tls_arg
*arg
= arg2
;
2370 arg
->needed
+= mips_tls_got_relocs (arg
->info
, hm
->tls_type
, &hm
->root
);
2375 /* Output a simple dynamic relocation into SRELOC. */
2378 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
2384 Elf_Internal_Rela rel
[3];
2386 memset (rel
, 0, sizeof (rel
));
2388 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
2389 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
2391 if (ABI_64_P (output_bfd
))
2393 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2394 (output_bfd
, &rel
[0],
2396 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
2399 bfd_elf32_swap_reloc_out
2400 (output_bfd
, &rel
[0],
2402 + sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
2403 ++sreloc
->reloc_count
;
2406 /* Initialize a set of TLS GOT entries for one symbol. */
2409 mips_elf_initialize_tls_slots (bfd
*abfd
, bfd_vma got_offset
,
2410 unsigned char *tls_type_p
,
2411 struct bfd_link_info
*info
,
2412 struct mips_elf_link_hash_entry
*h
,
2415 struct mips_elf_link_hash_table
*htab
;
2417 asection
*sreloc
, *sgot
;
2418 bfd_vma offset
, offset2
;
2419 bfd_boolean need_relocs
= FALSE
;
2421 htab
= mips_elf_hash_table (info
);
2427 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2429 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
2430 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
2431 indx
= h
->root
.dynindx
;
2434 if (*tls_type_p
& GOT_TLS_DONE
)
2437 if ((info
->shared
|| indx
!= 0)
2439 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
2440 || h
->root
.type
!= bfd_link_hash_undefweak
))
2443 /* MINUS_ONE means the symbol is not defined in this object. It may not
2444 be defined at all; assume that the value doesn't matter in that
2445 case. Otherwise complain if we would use the value. */
2446 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
2447 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
2449 /* Emit necessary relocations. */
2450 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
2452 /* General Dynamic. */
2453 if (*tls_type_p
& GOT_TLS_GD
)
2455 offset
= got_offset
;
2456 offset2
= offset
+ MIPS_ELF_GOT_SIZE (abfd
);
2460 mips_elf_output_dynamic_relocation
2461 (abfd
, sreloc
, indx
,
2462 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2463 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2466 mips_elf_output_dynamic_relocation
2467 (abfd
, sreloc
, indx
,
2468 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
2469 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset2
);
2471 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2472 sgot
->contents
+ offset2
);
2476 MIPS_ELF_PUT_WORD (abfd
, 1,
2477 sgot
->contents
+ offset
);
2478 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2479 sgot
->contents
+ offset2
);
2482 got_offset
+= 2 * MIPS_ELF_GOT_SIZE (abfd
);
2485 /* Initial Exec model. */
2486 if (*tls_type_p
& GOT_TLS_IE
)
2488 offset
= got_offset
;
2493 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
2494 sgot
->contents
+ offset
);
2496 MIPS_ELF_PUT_WORD (abfd
, 0,
2497 sgot
->contents
+ offset
);
2499 mips_elf_output_dynamic_relocation
2500 (abfd
, sreloc
, indx
,
2501 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
2502 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2505 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
2506 sgot
->contents
+ offset
);
2509 if (*tls_type_p
& GOT_TLS_LDM
)
2511 /* The initial offset is zero, and the LD offsets will include the
2512 bias by DTP_OFFSET. */
2513 MIPS_ELF_PUT_WORD (abfd
, 0,
2514 sgot
->contents
+ got_offset
2515 + MIPS_ELF_GOT_SIZE (abfd
));
2518 MIPS_ELF_PUT_WORD (abfd
, 1,
2519 sgot
->contents
+ got_offset
);
2521 mips_elf_output_dynamic_relocation
2522 (abfd
, sreloc
, indx
,
2523 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2524 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
2527 *tls_type_p
|= GOT_TLS_DONE
;
2530 /* Return the GOT index to use for a relocation of type R_TYPE against
2531 a symbol accessed using TLS_TYPE models. The GOT entries for this
2532 symbol in this GOT start at GOT_INDEX. This function initializes the
2533 GOT entries and corresponding relocations. */
2536 mips_tls_got_index (bfd
*abfd
, bfd_vma got_index
, unsigned char *tls_type
,
2537 int r_type
, struct bfd_link_info
*info
,
2538 struct mips_elf_link_hash_entry
*h
, bfd_vma symbol
)
2540 BFD_ASSERT (r_type
== R_MIPS_TLS_GOTTPREL
|| r_type
== R_MIPS_TLS_GD
2541 || r_type
== R_MIPS_TLS_LDM
);
2543 mips_elf_initialize_tls_slots (abfd
, got_index
, tls_type
, info
, h
, symbol
);
2545 if (r_type
== R_MIPS_TLS_GOTTPREL
)
2547 BFD_ASSERT (*tls_type
& GOT_TLS_IE
);
2548 if (*tls_type
& GOT_TLS_GD
)
2549 return got_index
+ 2 * MIPS_ELF_GOT_SIZE (abfd
);
2554 if (r_type
== R_MIPS_TLS_GD
)
2556 BFD_ASSERT (*tls_type
& GOT_TLS_GD
);
2560 if (r_type
== R_MIPS_TLS_LDM
)
2562 BFD_ASSERT (*tls_type
& GOT_TLS_LDM
);
2569 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
2570 for global symbol H. .got.plt comes before the GOT, so the offset
2571 will be negative. */
2574 mips_elf_gotplt_index (struct bfd_link_info
*info
,
2575 struct elf_link_hash_entry
*h
)
2577 bfd_vma plt_index
, got_address
, got_value
;
2578 struct mips_elf_link_hash_table
*htab
;
2580 htab
= mips_elf_hash_table (info
);
2581 BFD_ASSERT (h
->plt
.offset
!= (bfd_vma
) -1);
2583 /* Calculate the index of the symbol's PLT entry. */
2584 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
2586 /* Calculate the address of the associated .got.plt entry. */
2587 got_address
= (htab
->sgotplt
->output_section
->vma
2588 + htab
->sgotplt
->output_offset
2591 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
2592 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
2593 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
2594 + htab
->root
.hgot
->root
.u
.def
.value
);
2596 return got_address
- got_value
;
2599 /* Return the GOT offset for address VALUE. If there is not yet a GOT
2600 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
2601 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
2602 offset can be found. */
2605 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2606 bfd_vma value
, unsigned long r_symndx
,
2607 struct mips_elf_link_hash_entry
*h
, int r_type
)
2609 struct mips_elf_link_hash_table
*htab
;
2610 struct mips_got_entry
*entry
;
2612 htab
= mips_elf_hash_table (info
);
2613 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
2614 r_symndx
, h
, r_type
);
2618 if (TLS_RELOC_P (r_type
))
2620 if (entry
->symndx
== -1 && htab
->got_info
->next
== NULL
)
2621 /* A type (3) entry in the single-GOT case. We use the symbol's
2622 hash table entry to track the index. */
2623 return mips_tls_got_index (abfd
, h
->tls_got_offset
, &h
->tls_type
,
2624 r_type
, info
, h
, value
);
2626 return mips_tls_got_index (abfd
, entry
->gotidx
, &entry
->tls_type
,
2627 r_type
, info
, h
, value
);
2630 return entry
->gotidx
;
2633 /* Returns the GOT index for the global symbol indicated by H. */
2636 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
,
2637 int r_type
, struct bfd_link_info
*info
)
2639 struct mips_elf_link_hash_table
*htab
;
2641 struct mips_got_info
*g
, *gg
;
2642 long global_got_dynindx
= 0;
2644 htab
= mips_elf_hash_table (info
);
2645 gg
= g
= htab
->got_info
;
2646 if (g
->bfd2got
&& ibfd
)
2648 struct mips_got_entry e
, *p
;
2650 BFD_ASSERT (h
->dynindx
>= 0);
2652 g
= mips_elf_got_for_ibfd (g
, ibfd
);
2653 if (g
->next
!= gg
|| TLS_RELOC_P (r_type
))
2657 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
2660 p
= htab_find (g
->got_entries
, &e
);
2662 BFD_ASSERT (p
->gotidx
> 0);
2664 if (TLS_RELOC_P (r_type
))
2666 bfd_vma value
= MINUS_ONE
;
2667 if ((h
->root
.type
== bfd_link_hash_defined
2668 || h
->root
.type
== bfd_link_hash_defweak
)
2669 && h
->root
.u
.def
.section
->output_section
)
2670 value
= (h
->root
.u
.def
.value
2671 + h
->root
.u
.def
.section
->output_offset
2672 + h
->root
.u
.def
.section
->output_section
->vma
);
2674 return mips_tls_got_index (abfd
, p
->gotidx
, &p
->tls_type
, r_type
,
2675 info
, e
.d
.h
, value
);
2682 if (gg
->global_gotsym
!= NULL
)
2683 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
2685 if (TLS_RELOC_P (r_type
))
2687 struct mips_elf_link_hash_entry
*hm
2688 = (struct mips_elf_link_hash_entry
*) h
;
2689 bfd_vma value
= MINUS_ONE
;
2691 if ((h
->root
.type
== bfd_link_hash_defined
2692 || h
->root
.type
== bfd_link_hash_defweak
)
2693 && h
->root
.u
.def
.section
->output_section
)
2694 value
= (h
->root
.u
.def
.value
2695 + h
->root
.u
.def
.section
->output_offset
2696 + h
->root
.u
.def
.section
->output_section
->vma
);
2698 index
= mips_tls_got_index (abfd
, hm
->tls_got_offset
, &hm
->tls_type
,
2699 r_type
, info
, hm
, value
);
2703 /* Once we determine the global GOT entry with the lowest dynamic
2704 symbol table index, we must put all dynamic symbols with greater
2705 indices into the GOT. That makes it easy to calculate the GOT
2707 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
2708 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
2709 * MIPS_ELF_GOT_SIZE (abfd
));
2711 BFD_ASSERT (index
< htab
->sgot
->size
);
2716 /* Find a GOT page entry that points to within 32KB of VALUE. These
2717 entries are supposed to be placed at small offsets in the GOT, i.e.,
2718 within 32KB of GP. Return the index of the GOT entry, or -1 if no
2719 entry could be created. If OFFSETP is nonnull, use it to return the
2720 offset of the GOT entry from VALUE. */
2723 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2724 bfd_vma value
, bfd_vma
*offsetp
)
2726 bfd_vma page
, index
;
2727 struct mips_got_entry
*entry
;
2729 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
2730 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
2731 NULL
, R_MIPS_GOT_PAGE
);
2736 index
= entry
->gotidx
;
2739 *offsetp
= value
- entry
->d
.address
;
2744 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
2745 EXTERNAL is true if the relocation was against a global symbol
2746 that has been forced local. */
2749 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2750 bfd_vma value
, bfd_boolean external
)
2752 struct mips_got_entry
*entry
;
2754 /* GOT16 relocations against local symbols are followed by a LO16
2755 relocation; those against global symbols are not. Thus if the
2756 symbol was originally local, the GOT16 relocation should load the
2757 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
2759 value
= mips_elf_high (value
) << 16;
2761 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
2762 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
2763 same in all cases. */
2764 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
2765 NULL
, R_MIPS_GOT16
);
2767 return entry
->gotidx
;
2772 /* Returns the offset for the entry at the INDEXth position
2776 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
2777 bfd
*input_bfd
, bfd_vma index
)
2779 struct mips_elf_link_hash_table
*htab
;
2783 htab
= mips_elf_hash_table (info
);
2785 gp
= _bfd_get_gp_value (output_bfd
)
2786 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
2788 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
2791 /* Create and return a local GOT entry for VALUE, which was calculated
2792 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
2793 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
2796 static struct mips_got_entry
*
2797 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
2798 bfd
*ibfd
, bfd_vma value
,
2799 unsigned long r_symndx
,
2800 struct mips_elf_link_hash_entry
*h
,
2803 struct mips_got_entry entry
, **loc
;
2804 struct mips_got_info
*g
;
2805 struct mips_elf_link_hash_table
*htab
;
2807 htab
= mips_elf_hash_table (info
);
2811 entry
.d
.address
= value
;
2814 g
= mips_elf_got_for_ibfd (htab
->got_info
, ibfd
);
2817 g
= mips_elf_got_for_ibfd (htab
->got_info
, abfd
);
2818 BFD_ASSERT (g
!= NULL
);
2821 /* We might have a symbol, H, if it has been forced local. Use the
2822 global entry then. It doesn't matter whether an entry is local
2823 or global for TLS, since the dynamic linker does not
2824 automatically relocate TLS GOT entries. */
2825 BFD_ASSERT (h
== NULL
|| h
->root
.forced_local
);
2826 if (TLS_RELOC_P (r_type
))
2828 struct mips_got_entry
*p
;
2831 if (r_type
== R_MIPS_TLS_LDM
)
2833 entry
.tls_type
= GOT_TLS_LDM
;
2839 entry
.symndx
= r_symndx
;
2845 p
= (struct mips_got_entry
*)
2846 htab_find (g
->got_entries
, &entry
);
2852 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
2857 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
2860 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2865 memcpy (*loc
, &entry
, sizeof entry
);
2867 if (g
->assigned_gotno
> g
->local_gotno
)
2869 (*loc
)->gotidx
= -1;
2870 /* We didn't allocate enough space in the GOT. */
2871 (*_bfd_error_handler
)
2872 (_("not enough GOT space for local GOT entries"));
2873 bfd_set_error (bfd_error_bad_value
);
2877 MIPS_ELF_PUT_WORD (abfd
, value
,
2878 (htab
->sgot
->contents
+ entry
.gotidx
));
2880 /* These GOT entries need a dynamic relocation on VxWorks. */
2881 if (htab
->is_vxworks
)
2883 Elf_Internal_Rela outrel
;
2886 bfd_vma got_address
;
2888 s
= mips_elf_rel_dyn_section (info
, FALSE
);
2889 got_address
= (htab
->sgot
->output_section
->vma
2890 + htab
->sgot
->output_offset
2893 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
2894 outrel
.r_offset
= got_address
;
2895 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
2896 outrel
.r_addend
= value
;
2897 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
2903 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
2904 The number might be exact or a worst-case estimate, depending on how
2905 much information is available to elf_backend_omit_section_dynsym at
2906 the current linking stage. */
2908 static bfd_size_type
2909 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
2911 bfd_size_type count
;
2914 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
2917 const struct elf_backend_data
*bed
;
2919 bed
= get_elf_backend_data (output_bfd
);
2920 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
2921 if ((p
->flags
& SEC_EXCLUDE
) == 0
2922 && (p
->flags
& SEC_ALLOC
) != 0
2923 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
2929 /* Sort the dynamic symbol table so that symbols that need GOT entries
2930 appear towards the end. */
2933 mips_elf_sort_hash_table (bfd
*abfd
, struct bfd_link_info
*info
)
2935 struct mips_elf_link_hash_table
*htab
;
2936 struct mips_elf_hash_sort_data hsd
;
2937 struct mips_got_info
*g
;
2939 if (elf_hash_table (info
)->dynsymcount
== 0)
2942 htab
= mips_elf_hash_table (info
);
2948 hsd
.max_unref_got_dynindx
2949 = hsd
.min_got_dynindx
2950 = (elf_hash_table (info
)->dynsymcount
- g
->reloc_only_gotno
);
2951 hsd
.max_non_got_dynindx
= count_section_dynsyms (abfd
, info
) + 1;
2952 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
2953 elf_hash_table (info
)),
2954 mips_elf_sort_hash_table_f
,
2957 /* There should have been enough room in the symbol table to
2958 accommodate both the GOT and non-GOT symbols. */
2959 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
2960 BFD_ASSERT ((unsigned long) hsd
.max_unref_got_dynindx
2961 == elf_hash_table (info
)->dynsymcount
);
2962 BFD_ASSERT (elf_hash_table (info
)->dynsymcount
- hsd
.min_got_dynindx
2963 == g
->global_gotno
);
2965 /* Now we know which dynamic symbol has the lowest dynamic symbol
2966 table index in the GOT. */
2967 g
->global_gotsym
= hsd
.low
;
2972 /* If H needs a GOT entry, assign it the highest available dynamic
2973 index. Otherwise, assign it the lowest available dynamic
2977 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
2979 struct mips_elf_hash_sort_data
*hsd
= data
;
2981 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2982 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2984 /* Symbols without dynamic symbol table entries aren't interesting
2986 if (h
->root
.dynindx
== -1)
2989 switch (h
->global_got_area
)
2992 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
2996 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
2998 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
2999 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3002 case GGA_RELOC_ONLY
:
3003 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
3005 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
3006 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3007 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
3014 /* If H is a symbol that needs a global GOT entry, but has a dynamic
3015 symbol table index lower than any we've seen to date, record it for
3019 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
3020 bfd
*abfd
, struct bfd_link_info
*info
,
3021 unsigned char tls_flag
)
3023 struct mips_elf_link_hash_table
*htab
;
3024 struct mips_elf_link_hash_entry
*hmips
;
3025 struct mips_got_entry entry
, **loc
;
3026 struct mips_got_info
*g
;
3028 htab
= mips_elf_hash_table (info
);
3029 hmips
= (struct mips_elf_link_hash_entry
*) h
;
3031 /* A global symbol in the GOT must also be in the dynamic symbol
3033 if (h
->dynindx
== -1)
3035 switch (ELF_ST_VISIBILITY (h
->other
))
3039 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
3042 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3046 /* Make sure we have a GOT to put this entry into. */
3048 BFD_ASSERT (g
!= NULL
);
3052 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3055 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3058 /* If we've already marked this entry as needing GOT space, we don't
3059 need to do it again. */
3062 (*loc
)->tls_type
|= tls_flag
;
3066 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3072 entry
.tls_type
= tls_flag
;
3074 memcpy (*loc
, &entry
, sizeof entry
);
3077 hmips
->global_got_area
= GGA_NORMAL
;
3082 /* Reserve space in G for a GOT entry containing the value of symbol
3083 SYMNDX in input bfd ABDF, plus ADDEND. */
3086 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
3087 struct bfd_link_info
*info
,
3088 unsigned char tls_flag
)
3090 struct mips_elf_link_hash_table
*htab
;
3091 struct mips_got_info
*g
;
3092 struct mips_got_entry entry
, **loc
;
3094 htab
= mips_elf_hash_table (info
);
3096 BFD_ASSERT (g
!= NULL
);
3099 entry
.symndx
= symndx
;
3100 entry
.d
.addend
= addend
;
3101 entry
.tls_type
= tls_flag
;
3102 loc
= (struct mips_got_entry
**)
3103 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
3107 if (tls_flag
== GOT_TLS_GD
&& !((*loc
)->tls_type
& GOT_TLS_GD
))
3110 (*loc
)->tls_type
|= tls_flag
;
3112 else if (tls_flag
== GOT_TLS_IE
&& !((*loc
)->tls_type
& GOT_TLS_IE
))
3115 (*loc
)->tls_type
|= tls_flag
;
3123 entry
.tls_type
= tls_flag
;
3124 if (tls_flag
== GOT_TLS_IE
)
3126 else if (tls_flag
== GOT_TLS_GD
)
3128 else if (g
->tls_ldm_offset
== MINUS_ONE
)
3130 g
->tls_ldm_offset
= MINUS_TWO
;
3136 entry
.gotidx
= g
->local_gotno
++;
3140 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3145 memcpy (*loc
, &entry
, sizeof entry
);
3150 /* Return the maximum number of GOT page entries required for RANGE. */
3153 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
3155 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
3158 /* Record that ABFD has a page relocation against symbol SYMNDX and
3159 that ADDEND is the addend for that relocation.
3161 This function creates an upper bound on the number of GOT slots
3162 required; no attempt is made to combine references to non-overridable
3163 global symbols across multiple input files. */
3166 mips_elf_record_got_page_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3167 long symndx
, bfd_signed_vma addend
)
3169 struct mips_elf_link_hash_table
*htab
;
3170 struct mips_got_info
*g
;
3171 struct mips_got_page_entry lookup
, *entry
;
3172 struct mips_got_page_range
**range_ptr
, *range
;
3173 bfd_vma old_pages
, new_pages
;
3176 htab
= mips_elf_hash_table (info
);
3178 BFD_ASSERT (g
!= NULL
);
3180 /* Find the mips_got_page_entry hash table entry for this symbol. */
3182 lookup
.symndx
= symndx
;
3183 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
3187 /* Create a mips_got_page_entry if this is the first time we've
3189 entry
= (struct mips_got_page_entry
*) *loc
;
3192 entry
= bfd_alloc (abfd
, sizeof (*entry
));
3197 entry
->symndx
= symndx
;
3198 entry
->ranges
= NULL
;
3199 entry
->num_pages
= 0;
3203 /* Skip over ranges whose maximum extent cannot share a page entry
3205 range_ptr
= &entry
->ranges
;
3206 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
3207 range_ptr
= &(*range_ptr
)->next
;
3209 /* If we scanned to the end of the list, or found a range whose
3210 minimum extent cannot share a page entry with ADDEND, create
3211 a new singleton range. */
3213 if (!range
|| addend
< range
->min_addend
- 0xffff)
3215 range
= bfd_alloc (abfd
, sizeof (*range
));
3219 range
->next
= *range_ptr
;
3220 range
->min_addend
= addend
;
3221 range
->max_addend
= addend
;
3229 /* Remember how many pages the old range contributed. */
3230 old_pages
= mips_elf_pages_for_range (range
);
3232 /* Update the ranges. */
3233 if (addend
< range
->min_addend
)
3234 range
->min_addend
= addend
;
3235 else if (addend
> range
->max_addend
)
3237 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
3239 old_pages
+= mips_elf_pages_for_range (range
->next
);
3240 range
->max_addend
= range
->next
->max_addend
;
3241 range
->next
= range
->next
->next
;
3244 range
->max_addend
= addend
;
3247 /* Record any change in the total estimate. */
3248 new_pages
= mips_elf_pages_for_range (range
);
3249 if (old_pages
!= new_pages
)
3251 entry
->num_pages
+= new_pages
- old_pages
;
3252 g
->page_gotno
+= new_pages
- old_pages
;
3258 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
3261 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
3265 struct mips_elf_link_hash_table
*htab
;
3267 htab
= mips_elf_hash_table (info
);
3268 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3269 BFD_ASSERT (s
!= NULL
);
3271 if (htab
->is_vxworks
)
3272 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
3277 /* Make room for a null element. */
3278 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
3281 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
3285 /* A htab_traverse callback for GOT entries. Set boolean *DATA to true
3286 if the GOT entry is for an indirect or warning symbol. */
3289 mips_elf_check_recreate_got (void **entryp
, void *data
)
3291 struct mips_got_entry
*entry
;
3292 bfd_boolean
*must_recreate
;
3294 entry
= (struct mips_got_entry
*) *entryp
;
3295 must_recreate
= (bfd_boolean
*) data
;
3296 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3298 struct mips_elf_link_hash_entry
*h
;
3301 if (h
->root
.root
.type
== bfd_link_hash_indirect
3302 || h
->root
.root
.type
== bfd_link_hash_warning
)
3304 *must_recreate
= TRUE
;
3311 /* A htab_traverse callback for GOT entries. Add all entries to
3312 hash table *DATA, converting entries for indirect and warning
3313 symbols into entries for the target symbol. Set *DATA to null
3317 mips_elf_recreate_got (void **entryp
, void *data
)
3320 struct mips_got_entry
*entry
;
3323 new_got
= (htab_t
*) data
;
3324 entry
= (struct mips_got_entry
*) *entryp
;
3325 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3327 struct mips_elf_link_hash_entry
*h
;
3330 while (h
->root
.root
.type
== bfd_link_hash_indirect
3331 || h
->root
.root
.type
== bfd_link_hash_warning
)
3333 BFD_ASSERT (h
->global_got_area
== GGA_NONE
);
3334 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3338 slot
= htab_find_slot (*new_got
, entry
, INSERT
);
3351 /* If any entries in G->got_entries are for indirect or warning symbols,
3352 replace them with entries for the target symbol. */
3355 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
3357 bfd_boolean must_recreate
;
3360 must_recreate
= FALSE
;
3361 htab_traverse (g
->got_entries
, mips_elf_check_recreate_got
, &must_recreate
);
3364 new_got
= htab_create (htab_size (g
->got_entries
),
3365 mips_elf_got_entry_hash
,
3366 mips_elf_got_entry_eq
, NULL
);
3367 htab_traverse (g
->got_entries
, mips_elf_recreate_got
, &new_got
);
3368 if (new_got
== NULL
)
3371 /* Each entry in g->got_entries has either been copied to new_got
3372 or freed. Now delete the hash table itself. */
3373 htab_delete (g
->got_entries
);
3374 g
->got_entries
= new_got
;
3379 /* A mips_elf_link_hash_traverse callback for which DATA points
3380 to a mips_got_info. Count the number of type (3) entries. */
3383 mips_elf_count_got_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
3385 struct mips_got_info
*g
;
3387 g
= (struct mips_got_info
*) data
;
3388 if (h
->global_got_area
!= GGA_NONE
)
3390 if (h
->root
.forced_local
|| h
->root
.dynindx
== -1)
3392 /* We no longer need this entry if it was only used for
3393 relocations; those relocations will be against the
3394 null or section symbol instead of H. */
3395 if (h
->global_got_area
!= GGA_RELOC_ONLY
)
3397 h
->global_got_area
= GGA_NONE
;
3402 if (h
->global_got_area
== GGA_RELOC_ONLY
)
3403 g
->reloc_only_gotno
++;
3409 /* Compute the hash value of the bfd in a bfd2got hash entry. */
3412 mips_elf_bfd2got_entry_hash (const void *entry_
)
3414 const struct mips_elf_bfd2got_hash
*entry
3415 = (struct mips_elf_bfd2got_hash
*)entry_
;
3417 return entry
->bfd
->id
;
3420 /* Check whether two hash entries have the same bfd. */
3423 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
3425 const struct mips_elf_bfd2got_hash
*e1
3426 = (const struct mips_elf_bfd2got_hash
*)entry1
;
3427 const struct mips_elf_bfd2got_hash
*e2
3428 = (const struct mips_elf_bfd2got_hash
*)entry2
;
3430 return e1
->bfd
== e2
->bfd
;
3433 /* In a multi-got link, determine the GOT to be used for IBFD. G must
3434 be the master GOT data. */
3436 static struct mips_got_info
*
3437 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
3439 struct mips_elf_bfd2got_hash e
, *p
;
3445 p
= htab_find (g
->bfd2got
, &e
);
3446 return p
? p
->g
: NULL
;
3449 /* Use BFD2GOT to find ABFD's got entry, creating one if none exists.
3450 Return NULL if an error occured. */
3452 static struct mips_got_info
*
3453 mips_elf_get_got_for_bfd (struct htab
*bfd2got
, bfd
*output_bfd
,
3456 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
3457 struct mips_got_info
*g
;
3460 bfdgot_entry
.bfd
= input_bfd
;
3461 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
3462 bfdgot
= (struct mips_elf_bfd2got_hash
*) *bfdgotp
;
3466 bfdgot
= ((struct mips_elf_bfd2got_hash
*)
3467 bfd_alloc (output_bfd
, sizeof (struct mips_elf_bfd2got_hash
)));
3473 g
= ((struct mips_got_info
*)
3474 bfd_alloc (output_bfd
, sizeof (struct mips_got_info
)));
3478 bfdgot
->bfd
= input_bfd
;
3481 g
->global_gotsym
= NULL
;
3482 g
->global_gotno
= 0;
3483 g
->reloc_only_gotno
= 0;
3486 g
->assigned_gotno
= -1;
3488 g
->tls_assigned_gotno
= 0;
3489 g
->tls_ldm_offset
= MINUS_ONE
;
3490 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3491 mips_elf_multi_got_entry_eq
, NULL
);
3492 if (g
->got_entries
== NULL
)
3495 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3496 mips_got_page_entry_eq
, NULL
);
3497 if (g
->got_page_entries
== NULL
)
3507 /* A htab_traverse callback for the entries in the master got.
3508 Create one separate got for each bfd that has entries in the global
3509 got, such that we can tell how many local and global entries each
3513 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
3515 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3516 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3517 struct mips_got_info
*g
;
3519 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3526 /* Insert the GOT entry in the bfd's got entry hash table. */
3527 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
3528 if (*entryp
!= NULL
)
3533 if (entry
->tls_type
)
3535 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3537 if (entry
->tls_type
& GOT_TLS_IE
)
3540 else if (entry
->symndx
>= 0 || entry
->d
.h
->root
.forced_local
)
3548 /* A htab_traverse callback for the page entries in the master got.
3549 Associate each page entry with the bfd's got. */
3552 mips_elf_make_got_pages_per_bfd (void **entryp
, void *p
)
3554 struct mips_got_page_entry
*entry
= (struct mips_got_page_entry
*) *entryp
;
3555 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*) p
;
3556 struct mips_got_info
*g
;
3558 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3565 /* Insert the GOT entry in the bfd's got entry hash table. */
3566 entryp
= htab_find_slot (g
->got_page_entries
, entry
, INSERT
);
3567 if (*entryp
!= NULL
)
3571 g
->page_gotno
+= entry
->num_pages
;
3575 /* Consider merging the got described by BFD2GOT with TO, using the
3576 information given by ARG. Return -1 if this would lead to overflow,
3577 1 if they were merged successfully, and 0 if a merge failed due to
3578 lack of memory. (These values are chosen so that nonnegative return
3579 values can be returned by a htab_traverse callback.) */
3582 mips_elf_merge_got_with (struct mips_elf_bfd2got_hash
*bfd2got
,
3583 struct mips_got_info
*to
,
3584 struct mips_elf_got_per_bfd_arg
*arg
)
3586 struct mips_got_info
*from
= bfd2got
->g
;
3587 unsigned int estimate
;
3589 /* Work out how many page entries we would need for the combined GOT. */
3590 estimate
= arg
->max_pages
;
3591 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
3592 estimate
= from
->page_gotno
+ to
->page_gotno
;
3594 /* And conservatively estimate how many local, global and TLS entries
3596 estimate
+= (from
->local_gotno
3597 + from
->global_gotno
3603 /* Bail out if the combined GOT might be too big. */
3604 if (estimate
> arg
->max_count
)
3607 /* Commit to the merge. Record that TO is now the bfd for this got. */
3610 /* Transfer the bfd's got information from FROM to TO. */
3611 htab_traverse (from
->got_entries
, mips_elf_make_got_per_bfd
, arg
);
3612 if (arg
->obfd
== NULL
)
3615 htab_traverse (from
->got_page_entries
, mips_elf_make_got_pages_per_bfd
, arg
);
3616 if (arg
->obfd
== NULL
)
3619 /* We don't have to worry about releasing memory of the actual
3620 got entries, since they're all in the master got_entries hash
3622 htab_delete (from
->got_entries
);
3623 htab_delete (from
->got_page_entries
);
3627 /* Attempt to merge gots of different input bfds. Try to use as much
3628 as possible of the primary got, since it doesn't require explicit
3629 dynamic relocations, but don't use bfds that would reference global
3630 symbols out of the addressable range. Failing the primary got,
3631 attempt to merge with the current got, or finish the current got
3632 and then make make the new got current. */
3635 mips_elf_merge_gots (void **bfd2got_
, void *p
)
3637 struct mips_elf_bfd2got_hash
*bfd2got
3638 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
3639 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3640 struct mips_got_info
*g
;
3641 unsigned int estimate
;
3646 /* Work out the number of page, local and TLS entries. */
3647 estimate
= arg
->max_pages
;
3648 if (estimate
> g
->page_gotno
)
3649 estimate
= g
->page_gotno
;
3650 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
3652 /* We place TLS GOT entries after both locals and globals. The globals
3653 for the primary GOT may overflow the normal GOT size limit, so be
3654 sure not to merge a GOT which requires TLS with the primary GOT in that
3655 case. This doesn't affect non-primary GOTs. */
3656 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
3658 if (estimate
<= arg
->max_count
)
3660 /* If we don't have a primary GOT, use it as
3661 a starting point for the primary GOT. */
3664 arg
->primary
= bfd2got
->g
;
3668 /* Try merging with the primary GOT. */
3669 result
= mips_elf_merge_got_with (bfd2got
, arg
->primary
, arg
);
3674 /* If we can merge with the last-created got, do it. */
3677 result
= mips_elf_merge_got_with (bfd2got
, arg
->current
, arg
);
3682 /* Well, we couldn't merge, so create a new GOT. Don't check if it
3683 fits; if it turns out that it doesn't, we'll get relocation
3684 overflows anyway. */
3685 g
->next
= arg
->current
;
3691 /* Set the TLS GOT index for the GOT entry in ENTRYP. ENTRYP's NEXT field
3692 is null iff there is just a single GOT. */
3695 mips_elf_initialize_tls_index (void **entryp
, void *p
)
3697 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3698 struct mips_got_info
*g
= p
;
3700 unsigned char tls_type
;
3702 /* We're only interested in TLS symbols. */
3703 if (entry
->tls_type
== 0)
3706 next_index
= MIPS_ELF_GOT_SIZE (entry
->abfd
) * (long) g
->tls_assigned_gotno
;
3708 if (entry
->symndx
== -1 && g
->next
== NULL
)
3710 /* A type (3) got entry in the single-GOT case. We use the symbol's
3711 hash table entry to track its index. */
3712 if (entry
->d
.h
->tls_type
& GOT_TLS_OFFSET_DONE
)
3714 entry
->d
.h
->tls_type
|= GOT_TLS_OFFSET_DONE
;
3715 entry
->d
.h
->tls_got_offset
= next_index
;
3716 tls_type
= entry
->d
.h
->tls_type
;
3720 if (entry
->tls_type
& GOT_TLS_LDM
)
3722 /* There are separate mips_got_entry objects for each input bfd
3723 that requires an LDM entry. Make sure that all LDM entries in
3724 a GOT resolve to the same index. */
3725 if (g
->tls_ldm_offset
!= MINUS_TWO
&& g
->tls_ldm_offset
!= MINUS_ONE
)
3727 entry
->gotidx
= g
->tls_ldm_offset
;
3730 g
->tls_ldm_offset
= next_index
;
3732 entry
->gotidx
= next_index
;
3733 tls_type
= entry
->tls_type
;
3736 /* Account for the entries we've just allocated. */
3737 if (tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3738 g
->tls_assigned_gotno
+= 2;
3739 if (tls_type
& GOT_TLS_IE
)
3740 g
->tls_assigned_gotno
+= 1;
3745 /* If passed a NULL mips_got_info in the argument, set the marker used
3746 to tell whether a global symbol needs a got entry (in the primary
3747 got) to the given VALUE.
3749 If passed a pointer G to a mips_got_info in the argument (it must
3750 not be the primary GOT), compute the offset from the beginning of
3751 the (primary) GOT section to the entry in G corresponding to the
3752 global symbol. G's assigned_gotno must contain the index of the
3753 first available global GOT entry in G. VALUE must contain the size
3754 of a GOT entry in bytes. For each global GOT entry that requires a
3755 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
3756 marked as not eligible for lazy resolution through a function
3759 mips_elf_set_global_got_offset (void **entryp
, void *p
)
3761 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3762 struct mips_elf_set_global_got_offset_arg
*arg
3763 = (struct mips_elf_set_global_got_offset_arg
*)p
;
3764 struct mips_got_info
*g
= arg
->g
;
3766 if (g
&& entry
->tls_type
!= GOT_NORMAL
)
3767 arg
->needed_relocs
+=
3768 mips_tls_got_relocs (arg
->info
, entry
->tls_type
,
3769 entry
->symndx
== -1 ? &entry
->d
.h
->root
: NULL
);
3771 if (entry
->abfd
!= NULL
3772 && entry
->symndx
== -1
3773 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
3777 BFD_ASSERT (g
->global_gotsym
== NULL
);
3779 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
3780 if (arg
->info
->shared
3781 || (elf_hash_table (arg
->info
)->dynamic_sections_created
3782 && entry
->d
.h
->root
.def_dynamic
3783 && !entry
->d
.h
->root
.def_regular
))
3784 ++arg
->needed_relocs
;
3787 entry
->d
.h
->global_got_area
= arg
->value
;
3793 /* A htab_traverse callback for GOT entries for which DATA is the
3794 bfd_link_info. Forbid any global symbols from having traditional
3795 lazy-binding stubs. */
3798 mips_elf_forbid_lazy_stubs (void **entryp
, void *data
)
3800 struct bfd_link_info
*info
;
3801 struct mips_elf_link_hash_table
*htab
;
3802 struct mips_got_entry
*entry
;
3804 entry
= (struct mips_got_entry
*) *entryp
;
3805 info
= (struct bfd_link_info
*) data
;
3806 htab
= mips_elf_hash_table (info
);
3807 if (entry
->abfd
!= NULL
3808 && entry
->symndx
== -1
3809 && entry
->d
.h
->needs_lazy_stub
)
3811 entry
->d
.h
->needs_lazy_stub
= FALSE
;
3812 htab
->lazy_stub_count
--;
3818 /* Return the offset of an input bfd IBFD's GOT from the beginning of
3821 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
3823 if (g
->bfd2got
== NULL
)
3826 g
= mips_elf_got_for_ibfd (g
, ibfd
);
3830 BFD_ASSERT (g
->next
);
3834 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
3835 * MIPS_ELF_GOT_SIZE (abfd
);
3838 /* Turn a single GOT that is too big for 16-bit addressing into
3839 a sequence of GOTs, each one 16-bit addressable. */
3842 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
3843 asection
*got
, bfd_size_type pages
)
3845 struct mips_elf_link_hash_table
*htab
;
3846 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
3847 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
3848 struct mips_got_info
*g
, *gg
;
3849 unsigned int assign
, needed_relocs
;
3852 dynobj
= elf_hash_table (info
)->dynobj
;
3853 htab
= mips_elf_hash_table (info
);
3855 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
3856 mips_elf_bfd2got_entry_eq
, NULL
);
3857 if (g
->bfd2got
== NULL
)
3860 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
3861 got_per_bfd_arg
.obfd
= abfd
;
3862 got_per_bfd_arg
.info
= info
;
3864 /* Count how many GOT entries each input bfd requires, creating a
3865 map from bfd to got info while at that. */
3866 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
3867 if (got_per_bfd_arg
.obfd
== NULL
)
3870 /* Also count how many page entries each input bfd requires. */
3871 htab_traverse (g
->got_page_entries
, mips_elf_make_got_pages_per_bfd
,
3873 if (got_per_bfd_arg
.obfd
== NULL
)
3876 got_per_bfd_arg
.current
= NULL
;
3877 got_per_bfd_arg
.primary
= NULL
;
3878 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
3879 / MIPS_ELF_GOT_SIZE (abfd
))
3880 - MIPS_RESERVED_GOTNO (info
));
3881 got_per_bfd_arg
.max_pages
= pages
;
3882 /* The number of globals that will be included in the primary GOT.
3883 See the calls to mips_elf_set_global_got_offset below for more
3885 got_per_bfd_arg
.global_count
= g
->global_gotno
;
3887 /* Try to merge the GOTs of input bfds together, as long as they
3888 don't seem to exceed the maximum GOT size, choosing one of them
3889 to be the primary GOT. */
3890 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
3891 if (got_per_bfd_arg
.obfd
== NULL
)
3894 /* If we do not find any suitable primary GOT, create an empty one. */
3895 if (got_per_bfd_arg
.primary
== NULL
)
3897 g
->next
= (struct mips_got_info
*)
3898 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
3899 if (g
->next
== NULL
)
3902 g
->next
->global_gotsym
= NULL
;
3903 g
->next
->global_gotno
= 0;
3904 g
->next
->reloc_only_gotno
= 0;
3905 g
->next
->local_gotno
= 0;
3906 g
->next
->page_gotno
= 0;
3907 g
->next
->tls_gotno
= 0;
3908 g
->next
->assigned_gotno
= 0;
3909 g
->next
->tls_assigned_gotno
= 0;
3910 g
->next
->tls_ldm_offset
= MINUS_ONE
;
3911 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3912 mips_elf_multi_got_entry_eq
,
3914 if (g
->next
->got_entries
== NULL
)
3916 g
->next
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3917 mips_got_page_entry_eq
,
3919 if (g
->next
->got_page_entries
== NULL
)
3921 g
->next
->bfd2got
= NULL
;
3924 g
->next
= got_per_bfd_arg
.primary
;
3925 g
->next
->next
= got_per_bfd_arg
.current
;
3927 /* GG is now the master GOT, and G is the primary GOT. */
3931 /* Map the output bfd to the primary got. That's what we're going
3932 to use for bfds that use GOT16 or GOT_PAGE relocations that we
3933 didn't mark in check_relocs, and we want a quick way to find it.
3934 We can't just use gg->next because we're going to reverse the
3937 struct mips_elf_bfd2got_hash
*bfdgot
;
3940 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
3941 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
3948 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
3950 BFD_ASSERT (*bfdgotp
== NULL
);
3954 /* Every symbol that is referenced in a dynamic relocation must be
3955 present in the primary GOT, so arrange for them to appear after
3956 those that are actually referenced. */
3957 gg
->reloc_only_gotno
= gg
->global_gotno
- g
->global_gotno
;
3958 g
->global_gotno
= gg
->global_gotno
;
3960 set_got_offset_arg
.g
= NULL
;
3961 set_got_offset_arg
.value
= GGA_RELOC_ONLY
;
3962 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
3963 &set_got_offset_arg
);
3964 set_got_offset_arg
.value
= GGA_NORMAL
;
3965 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
3966 &set_got_offset_arg
);
3968 /* Now go through the GOTs assigning them offset ranges.
3969 [assigned_gotno, local_gotno[ will be set to the range of local
3970 entries in each GOT. We can then compute the end of a GOT by
3971 adding local_gotno to global_gotno. We reverse the list and make
3972 it circular since then we'll be able to quickly compute the
3973 beginning of a GOT, by computing the end of its predecessor. To
3974 avoid special cases for the primary GOT, while still preserving
3975 assertions that are valid for both single- and multi-got links,
3976 we arrange for the main got struct to have the right number of
3977 global entries, but set its local_gotno such that the initial
3978 offset of the primary GOT is zero. Remember that the primary GOT
3979 will become the last item in the circular linked list, so it
3980 points back to the master GOT. */
3981 gg
->local_gotno
= -g
->global_gotno
;
3982 gg
->global_gotno
= g
->global_gotno
;
3989 struct mips_got_info
*gn
;
3991 assign
+= MIPS_RESERVED_GOTNO (info
);
3992 g
->assigned_gotno
= assign
;
3993 g
->local_gotno
+= assign
;
3994 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
3995 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
3997 /* Take g out of the direct list, and push it onto the reversed
3998 list that gg points to. g->next is guaranteed to be nonnull after
3999 this operation, as required by mips_elf_initialize_tls_index. */
4004 /* Set up any TLS entries. We always place the TLS entries after
4005 all non-TLS entries. */
4006 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
4007 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
4009 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
4012 /* Forbid global symbols in every non-primary GOT from having
4013 lazy-binding stubs. */
4015 htab_traverse (g
->got_entries
, mips_elf_forbid_lazy_stubs
, info
);
4019 got
->size
= (gg
->next
->local_gotno
4020 + gg
->next
->global_gotno
4021 + gg
->next
->tls_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
4024 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4025 set_got_offset_arg
.info
= info
;
4026 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
4028 unsigned int save_assign
;
4030 /* Assign offsets to global GOT entries. */
4031 save_assign
= g
->assigned_gotno
;
4032 g
->assigned_gotno
= g
->local_gotno
;
4033 set_got_offset_arg
.g
= g
;
4034 set_got_offset_arg
.needed_relocs
= 0;
4035 htab_traverse (g
->got_entries
,
4036 mips_elf_set_global_got_offset
,
4037 &set_got_offset_arg
);
4038 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
4039 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
<= g
->global_gotno
);
4041 g
->assigned_gotno
= save_assign
;
4044 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
4045 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
4046 + g
->next
->global_gotno
4047 + g
->next
->tls_gotno
4048 + MIPS_RESERVED_GOTNO (info
));
4053 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
4060 /* Returns the first relocation of type r_type found, beginning with
4061 RELOCATION. RELEND is one-past-the-end of the relocation table. */
4063 static const Elf_Internal_Rela
*
4064 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
4065 const Elf_Internal_Rela
*relocation
,
4066 const Elf_Internal_Rela
*relend
)
4068 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
4070 while (relocation
< relend
)
4072 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
4073 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
4079 /* We didn't find it. */
4083 /* Return whether a relocation is against a local symbol. */
4086 mips_elf_local_relocation_p (bfd
*input_bfd
,
4087 const Elf_Internal_Rela
*relocation
,
4088 asection
**local_sections
,
4089 bfd_boolean check_forced
)
4091 unsigned long r_symndx
;
4092 Elf_Internal_Shdr
*symtab_hdr
;
4093 struct mips_elf_link_hash_entry
*h
;
4096 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4097 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4098 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
4100 if (r_symndx
< extsymoff
)
4102 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
4107 /* Look up the hash table to check whether the symbol
4108 was forced local. */
4109 h
= (struct mips_elf_link_hash_entry
*)
4110 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
4111 /* Find the real hash-table entry for this symbol. */
4112 while (h
->root
.root
.type
== bfd_link_hash_indirect
4113 || h
->root
.root
.type
== bfd_link_hash_warning
)
4114 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4115 if (h
->root
.forced_local
)
4122 /* Sign-extend VALUE, which has the indicated number of BITS. */
4125 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
4127 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
4128 /* VALUE is negative. */
4129 value
|= ((bfd_vma
) - 1) << bits
;
4134 /* Return non-zero if the indicated VALUE has overflowed the maximum
4135 range expressible by a signed number with the indicated number of
4139 mips_elf_overflow_p (bfd_vma value
, int bits
)
4141 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
4143 if (svalue
> (1 << (bits
- 1)) - 1)
4144 /* The value is too big. */
4146 else if (svalue
< -(1 << (bits
- 1)))
4147 /* The value is too small. */
4154 /* Calculate the %high function. */
4157 mips_elf_high (bfd_vma value
)
4159 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
4162 /* Calculate the %higher function. */
4165 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
4168 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
4175 /* Calculate the %highest function. */
4178 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
4181 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
4188 /* Create the .compact_rel section. */
4191 mips_elf_create_compact_rel_section
4192 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4195 register asection
*s
;
4197 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4199 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
4202 s
= bfd_make_section_with_flags (abfd
, ".compact_rel", flags
);
4204 || ! bfd_set_section_alignment (abfd
, s
,
4205 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4208 s
->size
= sizeof (Elf32_External_compact_rel
);
4214 /* Create the .got section to hold the global offset table. */
4217 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4220 register asection
*s
;
4221 struct elf_link_hash_entry
*h
;
4222 struct bfd_link_hash_entry
*bh
;
4223 struct mips_got_info
*g
;
4225 struct mips_elf_link_hash_table
*htab
;
4227 htab
= mips_elf_hash_table (info
);
4229 /* This function may be called more than once. */
4233 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4234 | SEC_LINKER_CREATED
);
4236 /* We have to use an alignment of 2**4 here because this is hardcoded
4237 in the function stub generation and in the linker script. */
4238 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4240 || ! bfd_set_section_alignment (abfd
, s
, 4))
4244 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4245 linker script because we don't want to define the symbol if we
4246 are not creating a global offset table. */
4248 if (! (_bfd_generic_link_add_one_symbol
4249 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4250 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4253 h
= (struct elf_link_hash_entry
*) bh
;
4256 h
->type
= STT_OBJECT
;
4257 elf_hash_table (info
)->hgot
= h
;
4260 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4263 amt
= sizeof (struct mips_got_info
);
4264 g
= bfd_alloc (abfd
, amt
);
4267 g
->global_gotsym
= NULL
;
4268 g
->global_gotno
= 0;
4269 g
->reloc_only_gotno
= 0;
4271 g
->local_gotno
= MIPS_RESERVED_GOTNO (info
);
4273 g
->assigned_gotno
= MIPS_RESERVED_GOTNO (info
);
4276 g
->tls_ldm_offset
= MINUS_ONE
;
4277 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
4278 mips_elf_got_entry_eq
, NULL
);
4279 if (g
->got_entries
== NULL
)
4281 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4282 mips_got_page_entry_eq
, NULL
);
4283 if (g
->got_page_entries
== NULL
)
4286 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
4287 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
4289 /* VxWorks also needs a .got.plt section. */
4290 if (htab
->is_vxworks
)
4292 s
= bfd_make_section_with_flags (abfd
, ".got.plt",
4293 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4294 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4295 if (s
== NULL
|| !bfd_set_section_alignment (abfd
, s
, 4))
4303 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
4304 __GOTT_INDEX__ symbols. These symbols are only special for
4305 shared objects; they are not used in executables. */
4308 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
4310 return (mips_elf_hash_table (info
)->is_vxworks
4312 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
4313 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
4316 /* Calculate the value produced by the RELOCATION (which comes from
4317 the INPUT_BFD). The ADDEND is the addend to use for this
4318 RELOCATION; RELOCATION->R_ADDEND is ignored.
4320 The result of the relocation calculation is stored in VALUEP.
4321 REQUIRE_JALXP indicates whether or not the opcode used with this
4322 relocation must be JALX.
4324 This function returns bfd_reloc_continue if the caller need take no
4325 further action regarding this relocation, bfd_reloc_notsupported if
4326 something goes dramatically wrong, bfd_reloc_overflow if an
4327 overflow occurs, and bfd_reloc_ok to indicate success. */
4329 static bfd_reloc_status_type
4330 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
4331 asection
*input_section
,
4332 struct bfd_link_info
*info
,
4333 const Elf_Internal_Rela
*relocation
,
4334 bfd_vma addend
, reloc_howto_type
*howto
,
4335 Elf_Internal_Sym
*local_syms
,
4336 asection
**local_sections
, bfd_vma
*valuep
,
4337 const char **namep
, bfd_boolean
*require_jalxp
,
4338 bfd_boolean save_addend
)
4340 /* The eventual value we will return. */
4342 /* The address of the symbol against which the relocation is
4345 /* The final GP value to be used for the relocatable, executable, or
4346 shared object file being produced. */
4348 /* The place (section offset or address) of the storage unit being
4351 /* The value of GP used to create the relocatable object. */
4353 /* The offset into the global offset table at which the address of
4354 the relocation entry symbol, adjusted by the addend, resides
4355 during execution. */
4356 bfd_vma g
= MINUS_ONE
;
4357 /* The section in which the symbol referenced by the relocation is
4359 asection
*sec
= NULL
;
4360 struct mips_elf_link_hash_entry
*h
= NULL
;
4361 /* TRUE if the symbol referred to by this relocation is a local
4363 bfd_boolean local_p
, was_local_p
;
4364 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
4365 bfd_boolean gp_disp_p
= FALSE
;
4366 /* TRUE if the symbol referred to by this relocation is
4367 "__gnu_local_gp". */
4368 bfd_boolean gnu_local_gp_p
= FALSE
;
4369 Elf_Internal_Shdr
*symtab_hdr
;
4371 unsigned long r_symndx
;
4373 /* TRUE if overflow occurred during the calculation of the
4374 relocation value. */
4375 bfd_boolean overflowed_p
;
4376 /* TRUE if this relocation refers to a MIPS16 function. */
4377 bfd_boolean target_is_16_bit_code_p
= FALSE
;
4378 struct mips_elf_link_hash_table
*htab
;
4381 dynobj
= elf_hash_table (info
)->dynobj
;
4382 htab
= mips_elf_hash_table (info
);
4384 /* Parse the relocation. */
4385 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4386 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4387 p
= (input_section
->output_section
->vma
4388 + input_section
->output_offset
4389 + relocation
->r_offset
);
4391 /* Assume that there will be no overflow. */
4392 overflowed_p
= FALSE
;
4394 /* Figure out whether or not the symbol is local, and get the offset
4395 used in the array of hash table entries. */
4396 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4397 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4398 local_sections
, FALSE
);
4399 was_local_p
= local_p
;
4400 if (! elf_bad_symtab (input_bfd
))
4401 extsymoff
= symtab_hdr
->sh_info
;
4404 /* The symbol table does not follow the rule that local symbols
4405 must come before globals. */
4409 /* Figure out the value of the symbol. */
4412 Elf_Internal_Sym
*sym
;
4414 sym
= local_syms
+ r_symndx
;
4415 sec
= local_sections
[r_symndx
];
4417 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4418 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
4419 || (sec
->flags
& SEC_MERGE
))
4420 symbol
+= sym
->st_value
;
4421 if ((sec
->flags
& SEC_MERGE
)
4422 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4424 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
4426 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
4429 /* MIPS16 text labels should be treated as odd. */
4430 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
4433 /* Record the name of this symbol, for our caller. */
4434 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
4435 symtab_hdr
->sh_link
,
4438 *namep
= bfd_section_name (input_bfd
, sec
);
4440 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
4444 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
4446 /* For global symbols we look up the symbol in the hash-table. */
4447 h
= ((struct mips_elf_link_hash_entry
*)
4448 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
4449 /* Find the real hash-table entry for this symbol. */
4450 while (h
->root
.root
.type
== bfd_link_hash_indirect
4451 || h
->root
.root
.type
== bfd_link_hash_warning
)
4452 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4454 /* Record the name of this symbol, for our caller. */
4455 *namep
= h
->root
.root
.root
.string
;
4457 /* See if this is the special _gp_disp symbol. Note that such a
4458 symbol must always be a global symbol. */
4459 if (strcmp (*namep
, "_gp_disp") == 0
4460 && ! NEWABI_P (input_bfd
))
4462 /* Relocations against _gp_disp are permitted only with
4463 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
4464 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
4465 return bfd_reloc_notsupported
;
4469 /* See if this is the special _gp symbol. Note that such a
4470 symbol must always be a global symbol. */
4471 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
4472 gnu_local_gp_p
= TRUE
;
4475 /* If this symbol is defined, calculate its address. Note that
4476 _gp_disp is a magic symbol, always implicitly defined by the
4477 linker, so it's inappropriate to check to see whether or not
4479 else if ((h
->root
.root
.type
== bfd_link_hash_defined
4480 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4481 && h
->root
.root
.u
.def
.section
)
4483 sec
= h
->root
.root
.u
.def
.section
;
4484 if (sec
->output_section
)
4485 symbol
= (h
->root
.root
.u
.def
.value
4486 + sec
->output_section
->vma
4487 + sec
->output_offset
);
4489 symbol
= h
->root
.root
.u
.def
.value
;
4491 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
4492 /* We allow relocations against undefined weak symbols, giving
4493 it the value zero, so that you can undefined weak functions
4494 and check to see if they exist by looking at their
4497 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4498 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4500 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
4501 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
4503 /* If this is a dynamic link, we should have created a
4504 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
4505 in in _bfd_mips_elf_create_dynamic_sections.
4506 Otherwise, we should define the symbol with a value of 0.
4507 FIXME: It should probably get into the symbol table
4509 BFD_ASSERT (! info
->shared
);
4510 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
4513 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
4515 /* This is an optional symbol - an Irix specific extension to the
4516 ELF spec. Ignore it for now.
4517 XXX - FIXME - there is more to the spec for OPTIONAL symbols
4518 than simply ignoring them, but we do not handle this for now.
4519 For information see the "64-bit ELF Object File Specification"
4520 which is available from here:
4521 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
4526 if (! ((*info
->callbacks
->undefined_symbol
)
4527 (info
, h
->root
.root
.root
.string
, input_bfd
,
4528 input_section
, relocation
->r_offset
,
4529 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
4530 || ELF_ST_VISIBILITY (h
->root
.other
))))
4531 return bfd_reloc_undefined
;
4535 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
4538 /* If this is a reference to a 16-bit function with a stub, we need
4539 to redirect the relocation to the stub unless:
4541 (a) the relocation is for a MIPS16 JAL;
4543 (b) the relocation is for a MIPS16 PIC call, and there are no
4544 non-MIPS16 uses of the GOT slot; or
4546 (c) the section allows direct references to MIPS16 functions. */
4547 if (r_type
!= R_MIPS16_26
4548 && !info
->relocatable
4550 && h
->fn_stub
!= NULL
4551 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
4553 && elf_tdata (input_bfd
)->local_stubs
!= NULL
4554 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
4555 && !section_allows_mips16_refs_p (input_section
))
4557 /* This is a 32- or 64-bit call to a 16-bit function. We should
4558 have already noticed that we were going to need the
4561 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
4564 BFD_ASSERT (h
->need_fn_stub
);
4568 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4569 /* The target is 16-bit, but the stub isn't. */
4570 target_is_16_bit_code_p
= FALSE
;
4572 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
4573 need to redirect the call to the stub. Note that we specifically
4574 exclude R_MIPS16_CALL16 from this behavior; indirect calls should
4575 use an indirect stub instead. */
4576 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
4577 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
4579 && elf_tdata (input_bfd
)->local_call_stubs
!= NULL
4580 && elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
4581 && !target_is_16_bit_code_p
)
4584 sec
= elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
4587 /* If both call_stub and call_fp_stub are defined, we can figure
4588 out which one to use by checking which one appears in the input
4590 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
4595 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4597 if (CALL_FP_STUB_P (bfd_get_section_name (input_bfd
, o
)))
4599 sec
= h
->call_fp_stub
;
4606 else if (h
->call_stub
!= NULL
)
4609 sec
= h
->call_fp_stub
;
4612 BFD_ASSERT (sec
->size
> 0);
4613 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4616 /* Calls from 16-bit code to 32-bit code and vice versa require the
4617 special jalx instruction. */
4618 *require_jalxp
= (!info
->relocatable
4619 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
4620 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
4622 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4623 local_sections
, TRUE
);
4625 gp0
= _bfd_get_gp_value (input_bfd
);
4626 gp
= _bfd_get_gp_value (abfd
);
4628 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
4633 /* If we haven't already determined the GOT offset, oand we're going
4634 to need it, get it now. */
4637 case R_MIPS_GOT_PAGE
:
4638 case R_MIPS_GOT_OFST
:
4639 /* We need to decay to GOT_DISP/addend if the symbol doesn't
4641 local_p
= local_p
|| _bfd_elf_symbol_refs_local_p (&h
->root
, info
, 1);
4642 if (local_p
|| r_type
== R_MIPS_GOT_OFST
)
4646 case R_MIPS16_CALL16
:
4647 case R_MIPS16_GOT16
:
4650 case R_MIPS_GOT_DISP
:
4651 case R_MIPS_GOT_HI16
:
4652 case R_MIPS_CALL_HI16
:
4653 case R_MIPS_GOT_LO16
:
4654 case R_MIPS_CALL_LO16
:
4656 case R_MIPS_TLS_GOTTPREL
:
4657 case R_MIPS_TLS_LDM
:
4658 /* Find the index into the GOT where this value is located. */
4659 if (r_type
== R_MIPS_TLS_LDM
)
4661 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
4662 0, 0, NULL
, r_type
);
4664 return bfd_reloc_outofrange
;
4668 /* On VxWorks, CALL relocations should refer to the .got.plt
4669 entry, which is initialized to point at the PLT stub. */
4670 if (htab
->is_vxworks
4671 && (r_type
== R_MIPS_CALL_HI16
4672 || r_type
== R_MIPS_CALL_LO16
4673 || call16_reloc_p (r_type
)))
4675 BFD_ASSERT (addend
== 0);
4676 BFD_ASSERT (h
->root
.needs_plt
);
4677 g
= mips_elf_gotplt_index (info
, &h
->root
);
4681 /* GOT_PAGE may take a non-zero addend, that is ignored in a
4682 GOT_PAGE relocation that decays to GOT_DISP because the
4683 symbol turns out to be global. The addend is then added
4685 BFD_ASSERT (addend
== 0 || r_type
== R_MIPS_GOT_PAGE
);
4686 g
= mips_elf_global_got_index (dynobj
, input_bfd
,
4687 &h
->root
, r_type
, info
);
4688 if (h
->tls_type
== GOT_NORMAL
4689 && (! elf_hash_table(info
)->dynamic_sections_created
4691 && (info
->symbolic
|| h
->root
.forced_local
)
4692 && h
->root
.def_regular
)))
4693 /* This is a static link or a -Bsymbolic link. The
4694 symbol is defined locally, or was forced to be local.
4695 We must initialize this entry in the GOT. */
4696 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->sgot
->contents
+ g
);
4699 else if (!htab
->is_vxworks
4700 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
4701 /* The calculation below does not involve "g". */
4705 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
4706 symbol
+ addend
, r_symndx
, h
, r_type
);
4708 return bfd_reloc_outofrange
;
4711 /* Convert GOT indices to actual offsets. */
4712 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
4716 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
4717 symbols are resolved by the loader. Add them to .rela.dyn. */
4718 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
4720 Elf_Internal_Rela outrel
;
4724 s
= mips_elf_rel_dyn_section (info
, FALSE
);
4725 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4727 outrel
.r_offset
= (input_section
->output_section
->vma
4728 + input_section
->output_offset
4729 + relocation
->r_offset
);
4730 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
4731 outrel
.r_addend
= addend
;
4732 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
4734 /* If we've written this relocation for a readonly section,
4735 we need to set DF_TEXTREL again, so that we do not delete the
4737 if (MIPS_ELF_READONLY_SECTION (input_section
))
4738 info
->flags
|= DF_TEXTREL
;
4741 return bfd_reloc_ok
;
4744 /* Figure out what kind of relocation is being performed. */
4748 return bfd_reloc_continue
;
4751 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
4752 overflowed_p
= mips_elf_overflow_p (value
, 16);
4759 || (!htab
->is_vxworks
4760 && htab
->root
.dynamic_sections_created
4762 && h
->root
.def_dynamic
4763 && !h
->root
.def_regular
))
4766 || h
->root
.root
.type
!= bfd_link_hash_undefweak
4767 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4768 && (input_section
->flags
& SEC_ALLOC
) != 0)
4770 /* If we're creating a shared library, or this relocation is
4771 against a symbol in a shared library, then we can't know
4772 where the symbol will end up. So, we create a relocation
4773 record in the output, and leave the job up to the dynamic
4776 In VxWorks executables, references to external symbols
4777 are handled using copy relocs or PLT stubs, so there's
4778 no need to add a dynamic relocation here. */
4780 if (!mips_elf_create_dynamic_relocation (abfd
,
4788 return bfd_reloc_undefined
;
4792 if (r_type
!= R_MIPS_REL32
)
4793 value
= symbol
+ addend
;
4797 value
&= howto
->dst_mask
;
4801 value
= symbol
+ addend
- p
;
4802 value
&= howto
->dst_mask
;
4806 /* The calculation for R_MIPS16_26 is just the same as for an
4807 R_MIPS_26. It's only the storage of the relocated field into
4808 the output file that's different. That's handled in
4809 mips_elf_perform_relocation. So, we just fall through to the
4810 R_MIPS_26 case here. */
4813 value
= ((addend
| ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
4816 value
= (_bfd_mips_elf_sign_extend (addend
, 28) + symbol
) >> 2;
4817 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
)
4818 overflowed_p
= (value
>> 26) != ((p
+ 4) >> 28);
4820 value
&= howto
->dst_mask
;
4823 case R_MIPS_TLS_DTPREL_HI16
:
4824 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
4828 case R_MIPS_TLS_DTPREL_LO16
:
4829 case R_MIPS_TLS_DTPREL32
:
4830 case R_MIPS_TLS_DTPREL64
:
4831 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
4834 case R_MIPS_TLS_TPREL_HI16
:
4835 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
4839 case R_MIPS_TLS_TPREL_LO16
:
4840 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
4847 value
= mips_elf_high (addend
+ symbol
);
4848 value
&= howto
->dst_mask
;
4852 /* For MIPS16 ABI code we generate this sequence
4853 0: li $v0,%hi(_gp_disp)
4854 4: addiupc $v1,%lo(_gp_disp)
4858 So the offsets of hi and lo relocs are the same, but the
4859 $pc is four higher than $t9 would be, so reduce
4860 both reloc addends by 4. */
4861 if (r_type
== R_MIPS16_HI16
)
4862 value
= mips_elf_high (addend
+ gp
- p
- 4);
4864 value
= mips_elf_high (addend
+ gp
- p
);
4865 overflowed_p
= mips_elf_overflow_p (value
, 16);
4872 value
= (symbol
+ addend
) & howto
->dst_mask
;
4875 /* See the comment for R_MIPS16_HI16 above for the reason
4876 for this conditional. */
4877 if (r_type
== R_MIPS16_LO16
)
4878 value
= addend
+ gp
- p
;
4880 value
= addend
+ gp
- p
+ 4;
4881 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
4882 for overflow. But, on, say, IRIX5, relocations against
4883 _gp_disp are normally generated from the .cpload
4884 pseudo-op. It generates code that normally looks like
4887 lui $gp,%hi(_gp_disp)
4888 addiu $gp,$gp,%lo(_gp_disp)
4891 Here $t9 holds the address of the function being called,
4892 as required by the MIPS ELF ABI. The R_MIPS_LO16
4893 relocation can easily overflow in this situation, but the
4894 R_MIPS_HI16 relocation will handle the overflow.
4895 Therefore, we consider this a bug in the MIPS ABI, and do
4896 not check for overflow here. */
4900 case R_MIPS_LITERAL
:
4901 /* Because we don't merge literal sections, we can handle this
4902 just like R_MIPS_GPREL16. In the long run, we should merge
4903 shared literals, and then we will need to additional work
4908 case R_MIPS16_GPREL
:
4909 /* The R_MIPS16_GPREL performs the same calculation as
4910 R_MIPS_GPREL16, but stores the relocated bits in a different
4911 order. We don't need to do anything special here; the
4912 differences are handled in mips_elf_perform_relocation. */
4913 case R_MIPS_GPREL16
:
4914 /* Only sign-extend the addend if it was extracted from the
4915 instruction. If the addend was separate, leave it alone,
4916 otherwise we may lose significant bits. */
4917 if (howto
->partial_inplace
)
4918 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
4919 value
= symbol
+ addend
- gp
;
4920 /* If the symbol was local, any earlier relocatable links will
4921 have adjusted its addend with the gp offset, so compensate
4922 for that now. Don't do it for symbols forced local in this
4923 link, though, since they won't have had the gp offset applied
4927 overflowed_p
= mips_elf_overflow_p (value
, 16);
4930 case R_MIPS16_GOT16
:
4931 case R_MIPS16_CALL16
:
4934 /* VxWorks does not have separate local and global semantics for
4935 R_MIPS*_GOT16; every relocation evaluates to "G". */
4936 if (!htab
->is_vxworks
&& local_p
)
4940 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
4941 local_sections
, FALSE
);
4942 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
4943 symbol
+ addend
, forced
);
4944 if (value
== MINUS_ONE
)
4945 return bfd_reloc_outofrange
;
4947 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
4948 overflowed_p
= mips_elf_overflow_p (value
, 16);
4955 case R_MIPS_TLS_GOTTPREL
:
4956 case R_MIPS_TLS_LDM
:
4957 case R_MIPS_GOT_DISP
:
4960 overflowed_p
= mips_elf_overflow_p (value
, 16);
4963 case R_MIPS_GPREL32
:
4964 value
= (addend
+ symbol
+ gp0
- gp
);
4966 value
&= howto
->dst_mask
;
4970 case R_MIPS_GNU_REL16_S2
:
4971 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
4972 overflowed_p
= mips_elf_overflow_p (value
, 18);
4973 value
>>= howto
->rightshift
;
4974 value
&= howto
->dst_mask
;
4977 case R_MIPS_GOT_HI16
:
4978 case R_MIPS_CALL_HI16
:
4979 /* We're allowed to handle these two relocations identically.
4980 The dynamic linker is allowed to handle the CALL relocations
4981 differently by creating a lazy evaluation stub. */
4983 value
= mips_elf_high (value
);
4984 value
&= howto
->dst_mask
;
4987 case R_MIPS_GOT_LO16
:
4988 case R_MIPS_CALL_LO16
:
4989 value
= g
& howto
->dst_mask
;
4992 case R_MIPS_GOT_PAGE
:
4993 /* GOT_PAGE relocations that reference non-local symbols decay
4994 to GOT_DISP. The corresponding GOT_OFST relocation decays to
4998 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
4999 if (value
== MINUS_ONE
)
5000 return bfd_reloc_outofrange
;
5001 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5002 overflowed_p
= mips_elf_overflow_p (value
, 16);
5005 case R_MIPS_GOT_OFST
:
5007 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
5010 overflowed_p
= mips_elf_overflow_p (value
, 16);
5014 value
= symbol
- addend
;
5015 value
&= howto
->dst_mask
;
5019 value
= mips_elf_higher (addend
+ symbol
);
5020 value
&= howto
->dst_mask
;
5023 case R_MIPS_HIGHEST
:
5024 value
= mips_elf_highest (addend
+ symbol
);
5025 value
&= howto
->dst_mask
;
5028 case R_MIPS_SCN_DISP
:
5029 value
= symbol
+ addend
- sec
->output_offset
;
5030 value
&= howto
->dst_mask
;
5034 /* This relocation is only a hint. In some cases, we optimize
5035 it into a bal instruction. But we don't try to optimize
5036 branches to the PLT; that will wind up wasting time. */
5037 if (h
!= NULL
&& h
->root
.plt
.offset
!= (bfd_vma
) -1)
5038 return bfd_reloc_continue
;
5039 value
= symbol
+ addend
;
5043 case R_MIPS_GNU_VTINHERIT
:
5044 case R_MIPS_GNU_VTENTRY
:
5045 /* We don't do anything with these at present. */
5046 return bfd_reloc_continue
;
5049 /* An unrecognized relocation type. */
5050 return bfd_reloc_notsupported
;
5053 /* Store the VALUE for our caller. */
5055 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
5058 /* Obtain the field relocated by RELOCATION. */
5061 mips_elf_obtain_contents (reloc_howto_type
*howto
,
5062 const Elf_Internal_Rela
*relocation
,
5063 bfd
*input_bfd
, bfd_byte
*contents
)
5066 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5068 /* Obtain the bytes. */
5069 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
5074 /* It has been determined that the result of the RELOCATION is the
5075 VALUE. Use HOWTO to place VALUE into the output file at the
5076 appropriate position. The SECTION is the section to which the
5077 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
5078 for the relocation must be either JAL or JALX, and it is
5079 unconditionally converted to JALX.
5081 Returns FALSE if anything goes wrong. */
5084 mips_elf_perform_relocation (struct bfd_link_info
*info
,
5085 reloc_howto_type
*howto
,
5086 const Elf_Internal_Rela
*relocation
,
5087 bfd_vma value
, bfd
*input_bfd
,
5088 asection
*input_section
, bfd_byte
*contents
,
5089 bfd_boolean require_jalx
)
5093 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5095 /* Figure out where the relocation is occurring. */
5096 location
= contents
+ relocation
->r_offset
;
5098 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
5100 /* Obtain the current value. */
5101 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
5103 /* Clear the field we are setting. */
5104 x
&= ~howto
->dst_mask
;
5106 /* Set the field. */
5107 x
|= (value
& howto
->dst_mask
);
5109 /* If required, turn JAL into JALX. */
5113 bfd_vma opcode
= x
>> 26;
5114 bfd_vma jalx_opcode
;
5116 /* Check to see if the opcode is already JAL or JALX. */
5117 if (r_type
== R_MIPS16_26
)
5119 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
5124 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
5128 /* If the opcode is not JAL or JALX, there's a problem. */
5131 (*_bfd_error_handler
)
5132 (_("%B: %A+0x%lx: jump to stub routine which is not jal"),
5135 (unsigned long) relocation
->r_offset
);
5136 bfd_set_error (bfd_error_bad_value
);
5140 /* Make this the JALX opcode. */
5141 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
5144 /* On the RM9000, bal is faster than jal, because bal uses branch
5145 prediction hardware. If we are linking for the RM9000, and we
5146 see jal, and bal fits, use it instead. Note that this
5147 transformation should be safe for all architectures. */
5148 if (bfd_get_mach (input_bfd
) == bfd_mach_mips9000
5149 && !info
->relocatable
5151 && ((r_type
== R_MIPS_26
&& (x
>> 26) == 0x3) /* jal addr */
5152 || (r_type
== R_MIPS_JALR
&& x
== 0x0320f809))) /* jalr t9 */
5158 addr
= (input_section
->output_section
->vma
5159 + input_section
->output_offset
5160 + relocation
->r_offset
5162 if (r_type
== R_MIPS_26
)
5163 dest
= (value
<< 2) | ((addr
>> 28) << 28);
5167 if (off
<= 0x1ffff && off
>= -0x20000)
5168 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
5171 /* Put the value into the output. */
5172 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
5174 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, !info
->relocatable
,
5180 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5181 is the original relocation, which is now being transformed into a
5182 dynamic relocation. The ADDENDP is adjusted if necessary; the
5183 caller should store the result in place of the original addend. */
5186 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
5187 struct bfd_link_info
*info
,
5188 const Elf_Internal_Rela
*rel
,
5189 struct mips_elf_link_hash_entry
*h
,
5190 asection
*sec
, bfd_vma symbol
,
5191 bfd_vma
*addendp
, asection
*input_section
)
5193 Elf_Internal_Rela outrel
[3];
5198 bfd_boolean defined_p
;
5199 struct mips_elf_link_hash_table
*htab
;
5201 htab
= mips_elf_hash_table (info
);
5202 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5203 dynobj
= elf_hash_table (info
)->dynobj
;
5204 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
5205 BFD_ASSERT (sreloc
!= NULL
);
5206 BFD_ASSERT (sreloc
->contents
!= NULL
);
5207 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
5210 outrel
[0].r_offset
=
5211 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
5212 if (ABI_64_P (output_bfd
))
5214 outrel
[1].r_offset
=
5215 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
5216 outrel
[2].r_offset
=
5217 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
5220 if (outrel
[0].r_offset
== MINUS_ONE
)
5221 /* The relocation field has been deleted. */
5224 if (outrel
[0].r_offset
== MINUS_TWO
)
5226 /* The relocation field has been converted into a relative value of
5227 some sort. Functions like _bfd_elf_write_section_eh_frame expect
5228 the field to be fully relocated, so add in the symbol's value. */
5233 /* We must now calculate the dynamic symbol table index to use
5234 in the relocation. */
5236 && (!h
->root
.def_regular
5237 || (info
->shared
&& !info
->symbolic
&& !h
->root
.forced_local
)))
5239 indx
= h
->root
.dynindx
;
5240 if (SGI_COMPAT (output_bfd
))
5241 defined_p
= h
->root
.def_regular
;
5243 /* ??? glibc's ld.so just adds the final GOT entry to the
5244 relocation field. It therefore treats relocs against
5245 defined symbols in the same way as relocs against
5246 undefined symbols. */
5251 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5253 else if (sec
== NULL
|| sec
->owner
== NULL
)
5255 bfd_set_error (bfd_error_bad_value
);
5260 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5263 asection
*osec
= htab
->root
.text_index_section
;
5264 indx
= elf_section_data (osec
)->dynindx
;
5270 /* Instead of generating a relocation using the section
5271 symbol, we may as well make it a fully relative
5272 relocation. We want to avoid generating relocations to
5273 local symbols because we used to generate them
5274 incorrectly, without adding the original symbol value,
5275 which is mandated by the ABI for section symbols. In
5276 order to give dynamic loaders and applications time to
5277 phase out the incorrect use, we refrain from emitting
5278 section-relative relocations. It's not like they're
5279 useful, after all. This should be a bit more efficient
5281 /* ??? Although this behavior is compatible with glibc's ld.so,
5282 the ABI says that relocations against STN_UNDEF should have
5283 a symbol value of 0. Irix rld honors this, so relocations
5284 against STN_UNDEF have no effect. */
5285 if (!SGI_COMPAT (output_bfd
))
5290 /* If the relocation was previously an absolute relocation and
5291 this symbol will not be referred to by the relocation, we must
5292 adjust it by the value we give it in the dynamic symbol table.
5293 Otherwise leave the job up to the dynamic linker. */
5294 if (defined_p
&& r_type
!= R_MIPS_REL32
)
5297 if (htab
->is_vxworks
)
5298 /* VxWorks uses non-relative relocations for this. */
5299 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
5301 /* The relocation is always an REL32 relocation because we don't
5302 know where the shared library will wind up at load-time. */
5303 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
5306 /* For strict adherence to the ABI specification, we should
5307 generate a R_MIPS_64 relocation record by itself before the
5308 _REL32/_64 record as well, such that the addend is read in as
5309 a 64-bit value (REL32 is a 32-bit relocation, after all).
5310 However, since none of the existing ELF64 MIPS dynamic
5311 loaders seems to care, we don't waste space with these
5312 artificial relocations. If this turns out to not be true,
5313 mips_elf_allocate_dynamic_relocation() should be tweaked so
5314 as to make room for a pair of dynamic relocations per
5315 invocation if ABI_64_P, and here we should generate an
5316 additional relocation record with R_MIPS_64 by itself for a
5317 NULL symbol before this relocation record. */
5318 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
5319 ABI_64_P (output_bfd
)
5322 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
5324 /* Adjust the output offset of the relocation to reference the
5325 correct location in the output file. */
5326 outrel
[0].r_offset
+= (input_section
->output_section
->vma
5327 + input_section
->output_offset
);
5328 outrel
[1].r_offset
+= (input_section
->output_section
->vma
5329 + input_section
->output_offset
);
5330 outrel
[2].r_offset
+= (input_section
->output_section
->vma
5331 + input_section
->output_offset
);
5333 /* Put the relocation back out. We have to use the special
5334 relocation outputter in the 64-bit case since the 64-bit
5335 relocation format is non-standard. */
5336 if (ABI_64_P (output_bfd
))
5338 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5339 (output_bfd
, &outrel
[0],
5341 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5343 else if (htab
->is_vxworks
)
5345 /* VxWorks uses RELA rather than REL dynamic relocations. */
5346 outrel
[0].r_addend
= *addendp
;
5347 bfd_elf32_swap_reloca_out
5348 (output_bfd
, &outrel
[0],
5350 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
5353 bfd_elf32_swap_reloc_out
5354 (output_bfd
, &outrel
[0],
5355 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
5357 /* We've now added another relocation. */
5358 ++sreloc
->reloc_count
;
5360 /* Make sure the output section is writable. The dynamic linker
5361 will be writing to it. */
5362 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5365 /* On IRIX5, make an entry of compact relocation info. */
5366 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
5368 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5373 Elf32_crinfo cptrel
;
5375 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5376 cptrel
.vaddr
= (rel
->r_offset
5377 + input_section
->output_section
->vma
5378 + input_section
->output_offset
);
5379 if (r_type
== R_MIPS_REL32
)
5380 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5382 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5383 mips_elf_set_cr_dist2to (cptrel
, 0);
5384 cptrel
.konst
= *addendp
;
5386 cr
= (scpt
->contents
5387 + sizeof (Elf32_External_compact_rel
));
5388 mips_elf_set_cr_relvaddr (cptrel
, 0);
5389 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5390 ((Elf32_External_crinfo
*) cr
5391 + scpt
->reloc_count
));
5392 ++scpt
->reloc_count
;
5396 /* If we've written this relocation for a readonly section,
5397 we need to set DF_TEXTREL again, so that we do not delete the
5399 if (MIPS_ELF_READONLY_SECTION (input_section
))
5400 info
->flags
|= DF_TEXTREL
;
5405 /* Return the MACH for a MIPS e_flags value. */
5408 _bfd_elf_mips_mach (flagword flags
)
5410 switch (flags
& EF_MIPS_MACH
)
5412 case E_MIPS_MACH_3900
:
5413 return bfd_mach_mips3900
;
5415 case E_MIPS_MACH_4010
:
5416 return bfd_mach_mips4010
;
5418 case E_MIPS_MACH_4100
:
5419 return bfd_mach_mips4100
;
5421 case E_MIPS_MACH_4111
:
5422 return bfd_mach_mips4111
;
5424 case E_MIPS_MACH_4120
:
5425 return bfd_mach_mips4120
;
5427 case E_MIPS_MACH_4650
:
5428 return bfd_mach_mips4650
;
5430 case E_MIPS_MACH_5400
:
5431 return bfd_mach_mips5400
;
5433 case E_MIPS_MACH_5500
:
5434 return bfd_mach_mips5500
;
5436 case E_MIPS_MACH_9000
:
5437 return bfd_mach_mips9000
;
5439 case E_MIPS_MACH_SB1
:
5440 return bfd_mach_mips_sb1
;
5442 case E_MIPS_MACH_LS2E
:
5443 return bfd_mach_mips_loongson_2e
;
5445 case E_MIPS_MACH_LS2F
:
5446 return bfd_mach_mips_loongson_2f
;
5448 case E_MIPS_MACH_OCTEON
:
5449 return bfd_mach_mips_octeon
;
5452 switch (flags
& EF_MIPS_ARCH
)
5456 return bfd_mach_mips3000
;
5459 return bfd_mach_mips6000
;
5462 return bfd_mach_mips4000
;
5465 return bfd_mach_mips8000
;
5468 return bfd_mach_mips5
;
5470 case E_MIPS_ARCH_32
:
5471 return bfd_mach_mipsisa32
;
5473 case E_MIPS_ARCH_64
:
5474 return bfd_mach_mipsisa64
;
5476 case E_MIPS_ARCH_32R2
:
5477 return bfd_mach_mipsisa32r2
;
5479 case E_MIPS_ARCH_64R2
:
5480 return bfd_mach_mipsisa64r2
;
5487 /* Return printable name for ABI. */
5489 static INLINE
char *
5490 elf_mips_abi_name (bfd
*abfd
)
5494 flags
= elf_elfheader (abfd
)->e_flags
;
5495 switch (flags
& EF_MIPS_ABI
)
5498 if (ABI_N32_P (abfd
))
5500 else if (ABI_64_P (abfd
))
5504 case E_MIPS_ABI_O32
:
5506 case E_MIPS_ABI_O64
:
5508 case E_MIPS_ABI_EABI32
:
5510 case E_MIPS_ABI_EABI64
:
5513 return "unknown abi";
5517 /* MIPS ELF uses two common sections. One is the usual one, and the
5518 other is for small objects. All the small objects are kept
5519 together, and then referenced via the gp pointer, which yields
5520 faster assembler code. This is what we use for the small common
5521 section. This approach is copied from ecoff.c. */
5522 static asection mips_elf_scom_section
;
5523 static asymbol mips_elf_scom_symbol
;
5524 static asymbol
*mips_elf_scom_symbol_ptr
;
5526 /* MIPS ELF also uses an acommon section, which represents an
5527 allocated common symbol which may be overridden by a
5528 definition in a shared library. */
5529 static asection mips_elf_acom_section
;
5530 static asymbol mips_elf_acom_symbol
;
5531 static asymbol
*mips_elf_acom_symbol_ptr
;
5533 /* This is used for both the 32-bit and the 64-bit ABI. */
5536 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
5538 elf_symbol_type
*elfsym
;
5540 /* Handle the special MIPS section numbers that a symbol may use. */
5541 elfsym
= (elf_symbol_type
*) asym
;
5542 switch (elfsym
->internal_elf_sym
.st_shndx
)
5544 case SHN_MIPS_ACOMMON
:
5545 /* This section is used in a dynamically linked executable file.
5546 It is an allocated common section. The dynamic linker can
5547 either resolve these symbols to something in a shared
5548 library, or it can just leave them here. For our purposes,
5549 we can consider these symbols to be in a new section. */
5550 if (mips_elf_acom_section
.name
== NULL
)
5552 /* Initialize the acommon section. */
5553 mips_elf_acom_section
.name
= ".acommon";
5554 mips_elf_acom_section
.flags
= SEC_ALLOC
;
5555 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
5556 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
5557 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
5558 mips_elf_acom_symbol
.name
= ".acommon";
5559 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
5560 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
5561 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
5563 asym
->section
= &mips_elf_acom_section
;
5567 /* Common symbols less than the GP size are automatically
5568 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
5569 if (asym
->value
> elf_gp_size (abfd
)
5570 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
5571 || IRIX_COMPAT (abfd
) == ict_irix6
)
5574 case SHN_MIPS_SCOMMON
:
5575 if (mips_elf_scom_section
.name
== NULL
)
5577 /* Initialize the small common section. */
5578 mips_elf_scom_section
.name
= ".scommon";
5579 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
5580 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
5581 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
5582 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
5583 mips_elf_scom_symbol
.name
= ".scommon";
5584 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
5585 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
5586 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
5588 asym
->section
= &mips_elf_scom_section
;
5589 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
5592 case SHN_MIPS_SUNDEFINED
:
5593 asym
->section
= bfd_und_section_ptr
;
5598 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
5600 BFD_ASSERT (SGI_COMPAT (abfd
));
5601 if (section
!= NULL
)
5603 asym
->section
= section
;
5604 /* MIPS_TEXT is a bit special, the address is not an offset
5605 to the base of the .text section. So substract the section
5606 base address to make it an offset. */
5607 asym
->value
-= section
->vma
;
5614 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
5616 BFD_ASSERT (SGI_COMPAT (abfd
));
5617 if (section
!= NULL
)
5619 asym
->section
= section
;
5620 /* MIPS_DATA is a bit special, the address is not an offset
5621 to the base of the .data section. So substract the section
5622 base address to make it an offset. */
5623 asym
->value
-= section
->vma
;
5629 /* If this is an odd-valued function symbol, assume it's a MIPS16 one. */
5630 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
5631 && (asym
->value
& 1) != 0)
5634 elfsym
->internal_elf_sym
.st_other
5635 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
5639 /* Implement elf_backend_eh_frame_address_size. This differs from
5640 the default in the way it handles EABI64.
5642 EABI64 was originally specified as an LP64 ABI, and that is what
5643 -mabi=eabi normally gives on a 64-bit target. However, gcc has
5644 historically accepted the combination of -mabi=eabi and -mlong32,
5645 and this ILP32 variation has become semi-official over time.
5646 Both forms use elf32 and have pointer-sized FDE addresses.
5648 If an EABI object was generated by GCC 4.0 or above, it will have
5649 an empty .gcc_compiled_longXX section, where XX is the size of longs
5650 in bits. Unfortunately, ILP32 objects generated by earlier compilers
5651 have no special marking to distinguish them from LP64 objects.
5653 We don't want users of the official LP64 ABI to be punished for the
5654 existence of the ILP32 variant, but at the same time, we don't want
5655 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
5656 We therefore take the following approach:
5658 - If ABFD contains a .gcc_compiled_longXX section, use it to
5659 determine the pointer size.
5661 - Otherwise check the type of the first relocation. Assume that
5662 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
5666 The second check is enough to detect LP64 objects generated by pre-4.0
5667 compilers because, in the kind of output generated by those compilers,
5668 the first relocation will be associated with either a CIE personality
5669 routine or an FDE start address. Furthermore, the compilers never
5670 used a special (non-pointer) encoding for this ABI.
5672 Checking the relocation type should also be safe because there is no
5673 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
5677 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
5679 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
5681 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
5683 bfd_boolean long32_p
, long64_p
;
5685 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
5686 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
5687 if (long32_p
&& long64_p
)
5694 if (sec
->reloc_count
> 0
5695 && elf_section_data (sec
)->relocs
!= NULL
5696 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
5705 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
5706 relocations against two unnamed section symbols to resolve to the
5707 same address. For example, if we have code like:
5709 lw $4,%got_disp(.data)($gp)
5710 lw $25,%got_disp(.text)($gp)
5713 then the linker will resolve both relocations to .data and the program
5714 will jump there rather than to .text.
5716 We can work around this problem by giving names to local section symbols.
5717 This is also what the MIPSpro tools do. */
5720 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
5722 return SGI_COMPAT (abfd
);
5725 /* Work over a section just before writing it out. This routine is
5726 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
5727 sections that need the SHF_MIPS_GPREL flag by name; there has to be
5731 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
5733 if (hdr
->sh_type
== SHT_MIPS_REGINFO
5734 && hdr
->sh_size
> 0)
5738 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
5739 BFD_ASSERT (hdr
->contents
== NULL
);
5742 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
5745 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5746 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5750 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
5751 && hdr
->bfd_section
!= NULL
5752 && mips_elf_section_data (hdr
->bfd_section
) != NULL
5753 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
5755 bfd_byte
*contents
, *l
, *lend
;
5757 /* We stored the section contents in the tdata field in the
5758 set_section_contents routine. We save the section contents
5759 so that we don't have to read them again.
5760 At this point we know that elf_gp is set, so we can look
5761 through the section contents to see if there is an
5762 ODK_REGINFO structure. */
5764 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
5766 lend
= contents
+ hdr
->sh_size
;
5767 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5769 Elf_Internal_Options intopt
;
5771 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5773 if (intopt
.size
< sizeof (Elf_External_Options
))
5775 (*_bfd_error_handler
)
5776 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5777 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
5780 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
5787 + sizeof (Elf_External_Options
)
5788 + (sizeof (Elf64_External_RegInfo
) - 8)),
5791 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
5792 if (bfd_bwrite (buf
, 8, abfd
) != 8)
5795 else if (intopt
.kind
== ODK_REGINFO
)
5802 + sizeof (Elf_External_Options
)
5803 + (sizeof (Elf32_External_RegInfo
) - 4)),
5806 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5807 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5814 if (hdr
->bfd_section
!= NULL
)
5816 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
5818 if (strcmp (name
, ".sdata") == 0
5819 || strcmp (name
, ".lit8") == 0
5820 || strcmp (name
, ".lit4") == 0)
5822 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5823 hdr
->sh_type
= SHT_PROGBITS
;
5825 else if (strcmp (name
, ".sbss") == 0)
5827 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5828 hdr
->sh_type
= SHT_NOBITS
;
5830 else if (strcmp (name
, ".srdata") == 0)
5832 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
5833 hdr
->sh_type
= SHT_PROGBITS
;
5835 else if (strcmp (name
, ".compact_rel") == 0)
5838 hdr
->sh_type
= SHT_PROGBITS
;
5840 else if (strcmp (name
, ".rtproc") == 0)
5842 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
5844 unsigned int adjust
;
5846 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
5848 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
5856 /* Handle a MIPS specific section when reading an object file. This
5857 is called when elfcode.h finds a section with an unknown type.
5858 This routine supports both the 32-bit and 64-bit ELF ABI.
5860 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
5864 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
5865 Elf_Internal_Shdr
*hdr
,
5871 /* There ought to be a place to keep ELF backend specific flags, but
5872 at the moment there isn't one. We just keep track of the
5873 sections by their name, instead. Fortunately, the ABI gives
5874 suggested names for all the MIPS specific sections, so we will
5875 probably get away with this. */
5876 switch (hdr
->sh_type
)
5878 case SHT_MIPS_LIBLIST
:
5879 if (strcmp (name
, ".liblist") != 0)
5883 if (strcmp (name
, ".msym") != 0)
5886 case SHT_MIPS_CONFLICT
:
5887 if (strcmp (name
, ".conflict") != 0)
5890 case SHT_MIPS_GPTAB
:
5891 if (! CONST_STRNEQ (name
, ".gptab."))
5894 case SHT_MIPS_UCODE
:
5895 if (strcmp (name
, ".ucode") != 0)
5898 case SHT_MIPS_DEBUG
:
5899 if (strcmp (name
, ".mdebug") != 0)
5901 flags
= SEC_DEBUGGING
;
5903 case SHT_MIPS_REGINFO
:
5904 if (strcmp (name
, ".reginfo") != 0
5905 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
5907 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
5909 case SHT_MIPS_IFACE
:
5910 if (strcmp (name
, ".MIPS.interfaces") != 0)
5913 case SHT_MIPS_CONTENT
:
5914 if (! CONST_STRNEQ (name
, ".MIPS.content"))
5917 case SHT_MIPS_OPTIONS
:
5918 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
5921 case SHT_MIPS_DWARF
:
5922 if (! CONST_STRNEQ (name
, ".debug_")
5923 && ! CONST_STRNEQ (name
, ".zdebug_"))
5926 case SHT_MIPS_SYMBOL_LIB
:
5927 if (strcmp (name
, ".MIPS.symlib") != 0)
5930 case SHT_MIPS_EVENTS
:
5931 if (! CONST_STRNEQ (name
, ".MIPS.events")
5932 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
5939 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
5944 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
5945 (bfd_get_section_flags (abfd
,
5951 /* FIXME: We should record sh_info for a .gptab section. */
5953 /* For a .reginfo section, set the gp value in the tdata information
5954 from the contents of this section. We need the gp value while
5955 processing relocs, so we just get it now. The .reginfo section
5956 is not used in the 64-bit MIPS ELF ABI. */
5957 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
5959 Elf32_External_RegInfo ext
;
5962 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
5963 &ext
, 0, sizeof ext
))
5965 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
5966 elf_gp (abfd
) = s
.ri_gp_value
;
5969 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
5970 set the gp value based on what we find. We may see both
5971 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
5972 they should agree. */
5973 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
5975 bfd_byte
*contents
, *l
, *lend
;
5977 contents
= bfd_malloc (hdr
->sh_size
);
5978 if (contents
== NULL
)
5980 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
5987 lend
= contents
+ hdr
->sh_size
;
5988 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5990 Elf_Internal_Options intopt
;
5992 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5994 if (intopt
.size
< sizeof (Elf_External_Options
))
5996 (*_bfd_error_handler
)
5997 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5998 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6001 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6003 Elf64_Internal_RegInfo intreg
;
6005 bfd_mips_elf64_swap_reginfo_in
6007 ((Elf64_External_RegInfo
*)
6008 (l
+ sizeof (Elf_External_Options
))),
6010 elf_gp (abfd
) = intreg
.ri_gp_value
;
6012 else if (intopt
.kind
== ODK_REGINFO
)
6014 Elf32_RegInfo intreg
;
6016 bfd_mips_elf32_swap_reginfo_in
6018 ((Elf32_External_RegInfo
*)
6019 (l
+ sizeof (Elf_External_Options
))),
6021 elf_gp (abfd
) = intreg
.ri_gp_value
;
6031 /* Set the correct type for a MIPS ELF section. We do this by the
6032 section name, which is a hack, but ought to work. This routine is
6033 used by both the 32-bit and the 64-bit ABI. */
6036 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
6038 const char *name
= bfd_get_section_name (abfd
, sec
);
6040 if (strcmp (name
, ".liblist") == 0)
6042 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
6043 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
6044 /* The sh_link field is set in final_write_processing. */
6046 else if (strcmp (name
, ".conflict") == 0)
6047 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
6048 else if (CONST_STRNEQ (name
, ".gptab."))
6050 hdr
->sh_type
= SHT_MIPS_GPTAB
;
6051 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
6052 /* The sh_info field is set in final_write_processing. */
6054 else if (strcmp (name
, ".ucode") == 0)
6055 hdr
->sh_type
= SHT_MIPS_UCODE
;
6056 else if (strcmp (name
, ".mdebug") == 0)
6058 hdr
->sh_type
= SHT_MIPS_DEBUG
;
6059 /* In a shared object on IRIX 5.3, the .mdebug section has an
6060 entsize of 0. FIXME: Does this matter? */
6061 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
6062 hdr
->sh_entsize
= 0;
6064 hdr
->sh_entsize
= 1;
6066 else if (strcmp (name
, ".reginfo") == 0)
6068 hdr
->sh_type
= SHT_MIPS_REGINFO
;
6069 /* In a shared object on IRIX 5.3, the .reginfo section has an
6070 entsize of 0x18. FIXME: Does this matter? */
6071 if (SGI_COMPAT (abfd
))
6073 if ((abfd
->flags
& DYNAMIC
) != 0)
6074 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6076 hdr
->sh_entsize
= 1;
6079 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6081 else if (SGI_COMPAT (abfd
)
6082 && (strcmp (name
, ".hash") == 0
6083 || strcmp (name
, ".dynamic") == 0
6084 || strcmp (name
, ".dynstr") == 0))
6086 if (SGI_COMPAT (abfd
))
6087 hdr
->sh_entsize
= 0;
6089 /* This isn't how the IRIX6 linker behaves. */
6090 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6093 else if (strcmp (name
, ".got") == 0
6094 || strcmp (name
, ".srdata") == 0
6095 || strcmp (name
, ".sdata") == 0
6096 || strcmp (name
, ".sbss") == 0
6097 || strcmp (name
, ".lit4") == 0
6098 || strcmp (name
, ".lit8") == 0)
6099 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
6100 else if (strcmp (name
, ".MIPS.interfaces") == 0)
6102 hdr
->sh_type
= SHT_MIPS_IFACE
;
6103 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6105 else if (CONST_STRNEQ (name
, ".MIPS.content"))
6107 hdr
->sh_type
= SHT_MIPS_CONTENT
;
6108 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6109 /* The sh_info field is set in final_write_processing. */
6111 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6113 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
6114 hdr
->sh_entsize
= 1;
6115 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6117 else if (CONST_STRNEQ (name
, ".debug_")
6118 || CONST_STRNEQ (name
, ".zdebug_"))
6120 hdr
->sh_type
= SHT_MIPS_DWARF
;
6122 /* Irix facilities such as libexc expect a single .debug_frame
6123 per executable, the system ones have NOSTRIP set and the linker
6124 doesn't merge sections with different flags so ... */
6125 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
6126 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6128 else if (strcmp (name
, ".MIPS.symlib") == 0)
6130 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
6131 /* The sh_link and sh_info fields are set in
6132 final_write_processing. */
6134 else if (CONST_STRNEQ (name
, ".MIPS.events")
6135 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
6137 hdr
->sh_type
= SHT_MIPS_EVENTS
;
6138 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6139 /* The sh_link field is set in final_write_processing. */
6141 else if (strcmp (name
, ".msym") == 0)
6143 hdr
->sh_type
= SHT_MIPS_MSYM
;
6144 hdr
->sh_flags
|= SHF_ALLOC
;
6145 hdr
->sh_entsize
= 8;
6148 /* The generic elf_fake_sections will set up REL_HDR using the default
6149 kind of relocations. We used to set up a second header for the
6150 non-default kind of relocations here, but only NewABI would use
6151 these, and the IRIX ld doesn't like resulting empty RELA sections.
6152 Thus we create those header only on demand now. */
6157 /* Given a BFD section, try to locate the corresponding ELF section
6158 index. This is used by both the 32-bit and the 64-bit ABI.
6159 Actually, it's not clear to me that the 64-bit ABI supports these,
6160 but for non-PIC objects we will certainly want support for at least
6161 the .scommon section. */
6164 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6165 asection
*sec
, int *retval
)
6167 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
6169 *retval
= SHN_MIPS_SCOMMON
;
6172 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
6174 *retval
= SHN_MIPS_ACOMMON
;
6180 /* Hook called by the linker routine which adds symbols from an object
6181 file. We must handle the special MIPS section numbers here. */
6184 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6185 Elf_Internal_Sym
*sym
, const char **namep
,
6186 flagword
*flagsp ATTRIBUTE_UNUSED
,
6187 asection
**secp
, bfd_vma
*valp
)
6189 if (SGI_COMPAT (abfd
)
6190 && (abfd
->flags
& DYNAMIC
) != 0
6191 && strcmp (*namep
, "_rld_new_interface") == 0)
6193 /* Skip IRIX5 rld entry name. */
6198 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
6199 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
6200 by setting a DT_NEEDED for the shared object. Since _gp_disp is
6201 a magic symbol resolved by the linker, we ignore this bogus definition
6202 of _gp_disp. New ABI objects do not suffer from this problem so this
6203 is not done for them. */
6205 && (sym
->st_shndx
== SHN_ABS
)
6206 && (strcmp (*namep
, "_gp_disp") == 0))
6212 switch (sym
->st_shndx
)
6215 /* Common symbols less than the GP size are automatically
6216 treated as SHN_MIPS_SCOMMON symbols. */
6217 if (sym
->st_size
> elf_gp_size (abfd
)
6218 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
6219 || IRIX_COMPAT (abfd
) == ict_irix6
)
6222 case SHN_MIPS_SCOMMON
:
6223 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
6224 (*secp
)->flags
|= SEC_IS_COMMON
;
6225 *valp
= sym
->st_size
;
6229 /* This section is used in a shared object. */
6230 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
6232 asymbol
*elf_text_symbol
;
6233 asection
*elf_text_section
;
6234 bfd_size_type amt
= sizeof (asection
);
6236 elf_text_section
= bfd_zalloc (abfd
, amt
);
6237 if (elf_text_section
== NULL
)
6240 amt
= sizeof (asymbol
);
6241 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
6242 if (elf_text_symbol
== NULL
)
6245 /* Initialize the section. */
6247 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
6248 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
6250 elf_text_section
->symbol
= elf_text_symbol
;
6251 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
6253 elf_text_section
->name
= ".text";
6254 elf_text_section
->flags
= SEC_NO_FLAGS
;
6255 elf_text_section
->output_section
= NULL
;
6256 elf_text_section
->owner
= abfd
;
6257 elf_text_symbol
->name
= ".text";
6258 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6259 elf_text_symbol
->section
= elf_text_section
;
6261 /* This code used to do *secp = bfd_und_section_ptr if
6262 info->shared. I don't know why, and that doesn't make sense,
6263 so I took it out. */
6264 *secp
= elf_tdata (abfd
)->elf_text_section
;
6267 case SHN_MIPS_ACOMMON
:
6268 /* Fall through. XXX Can we treat this as allocated data? */
6270 /* This section is used in a shared object. */
6271 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
6273 asymbol
*elf_data_symbol
;
6274 asection
*elf_data_section
;
6275 bfd_size_type amt
= sizeof (asection
);
6277 elf_data_section
= bfd_zalloc (abfd
, amt
);
6278 if (elf_data_section
== NULL
)
6281 amt
= sizeof (asymbol
);
6282 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
6283 if (elf_data_symbol
== NULL
)
6286 /* Initialize the section. */
6288 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
6289 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
6291 elf_data_section
->symbol
= elf_data_symbol
;
6292 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
6294 elf_data_section
->name
= ".data";
6295 elf_data_section
->flags
= SEC_NO_FLAGS
;
6296 elf_data_section
->output_section
= NULL
;
6297 elf_data_section
->owner
= abfd
;
6298 elf_data_symbol
->name
= ".data";
6299 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6300 elf_data_symbol
->section
= elf_data_section
;
6302 /* This code used to do *secp = bfd_und_section_ptr if
6303 info->shared. I don't know why, and that doesn't make sense,
6304 so I took it out. */
6305 *secp
= elf_tdata (abfd
)->elf_data_section
;
6308 case SHN_MIPS_SUNDEFINED
:
6309 *secp
= bfd_und_section_ptr
;
6313 if (SGI_COMPAT (abfd
)
6315 && info
->output_bfd
->xvec
== abfd
->xvec
6316 && strcmp (*namep
, "__rld_obj_head") == 0)
6318 struct elf_link_hash_entry
*h
;
6319 struct bfd_link_hash_entry
*bh
;
6321 /* Mark __rld_obj_head as dynamic. */
6323 if (! (_bfd_generic_link_add_one_symbol
6324 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
6325 get_elf_backend_data (abfd
)->collect
, &bh
)))
6328 h
= (struct elf_link_hash_entry
*) bh
;
6331 h
->type
= STT_OBJECT
;
6333 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6336 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
6339 /* If this is a mips16 text symbol, add 1 to the value to make it
6340 odd. This will cause something like .word SYM to come up with
6341 the right value when it is loaded into the PC. */
6342 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6348 /* This hook function is called before the linker writes out a global
6349 symbol. We mark symbols as small common if appropriate. This is
6350 also where we undo the increment of the value for a mips16 symbol. */
6353 _bfd_mips_elf_link_output_symbol_hook
6354 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6355 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
6356 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
6358 /* If we see a common symbol, which implies a relocatable link, then
6359 if a symbol was small common in an input file, mark it as small
6360 common in the output file. */
6361 if (sym
->st_shndx
== SHN_COMMON
6362 && strcmp (input_sec
->name
, ".scommon") == 0)
6363 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6365 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6366 sym
->st_value
&= ~1;
6371 /* Functions for the dynamic linker. */
6373 /* Create dynamic sections when linking against a dynamic object. */
6376 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6378 struct elf_link_hash_entry
*h
;
6379 struct bfd_link_hash_entry
*bh
;
6381 register asection
*s
;
6382 const char * const *namep
;
6383 struct mips_elf_link_hash_table
*htab
;
6385 htab
= mips_elf_hash_table (info
);
6386 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6387 | SEC_LINKER_CREATED
| SEC_READONLY
);
6389 /* The psABI requires a read-only .dynamic section, but the VxWorks
6391 if (!htab
->is_vxworks
)
6393 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6396 if (! bfd_set_section_flags (abfd
, s
, flags
))
6401 /* We need to create .got section. */
6402 if (!mips_elf_create_got_section (abfd
, info
))
6405 if (! mips_elf_rel_dyn_section (info
, TRUE
))
6408 /* Create .stub section. */
6409 s
= bfd_make_section_with_flags (abfd
,
6410 MIPS_ELF_STUB_SECTION_NAME (abfd
),
6413 || ! bfd_set_section_alignment (abfd
, s
,
6414 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6418 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
6420 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6422 s
= bfd_make_section_with_flags (abfd
, ".rld_map",
6423 flags
&~ (flagword
) SEC_READONLY
);
6425 || ! bfd_set_section_alignment (abfd
, s
,
6426 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6430 /* On IRIX5, we adjust add some additional symbols and change the
6431 alignments of several sections. There is no ABI documentation
6432 indicating that this is necessary on IRIX6, nor any evidence that
6433 the linker takes such action. */
6434 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6436 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6439 if (! (_bfd_generic_link_add_one_symbol
6440 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
6441 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6444 h
= (struct elf_link_hash_entry
*) bh
;
6447 h
->type
= STT_SECTION
;
6449 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6453 /* We need to create a .compact_rel section. */
6454 if (SGI_COMPAT (abfd
))
6456 if (!mips_elf_create_compact_rel_section (abfd
, info
))
6460 /* Change alignments of some sections. */
6461 s
= bfd_get_section_by_name (abfd
, ".hash");
6463 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6464 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6466 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6467 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6469 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6470 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6472 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6473 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6475 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6482 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
6484 if (!(_bfd_generic_link_add_one_symbol
6485 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
6486 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6489 h
= (struct elf_link_hash_entry
*) bh
;
6492 h
->type
= STT_SECTION
;
6494 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6497 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
6499 /* __rld_map is a four byte word located in the .data section
6500 and is filled in by the rtld to contain a pointer to
6501 the _r_debug structure. Its symbol value will be set in
6502 _bfd_mips_elf_finish_dynamic_symbol. */
6503 s
= bfd_get_section_by_name (abfd
, ".rld_map");
6504 BFD_ASSERT (s
!= NULL
);
6506 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
6508 if (!(_bfd_generic_link_add_one_symbol
6509 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
6510 get_elf_backend_data (abfd
)->collect
, &bh
)))
6513 h
= (struct elf_link_hash_entry
*) bh
;
6516 h
->type
= STT_OBJECT
;
6518 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6523 if (htab
->is_vxworks
)
6525 /* Create the .plt, .rela.plt, .dynbss and .rela.bss sections.
6526 Also create the _PROCEDURE_LINKAGE_TABLE symbol. */
6527 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
6530 /* Cache the sections created above. */
6531 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
6532 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
6533 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
6534 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
6536 || (!htab
->srelbss
&& !info
->shared
)
6541 /* Do the usual VxWorks handling. */
6542 if (!elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
6545 /* Work out the PLT sizes. */
6548 htab
->plt_header_size
6549 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
6550 htab
->plt_entry_size
6551 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
6555 htab
->plt_header_size
6556 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
6557 htab
->plt_entry_size
6558 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
6565 /* Return true if relocation REL against section SEC is a REL rather than
6566 RELA relocation. RELOCS is the first relocation in the section and
6567 ABFD is the bfd that contains SEC. */
6570 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
6571 const Elf_Internal_Rela
*relocs
,
6572 const Elf_Internal_Rela
*rel
)
6574 Elf_Internal_Shdr
*rel_hdr
;
6575 const struct elf_backend_data
*bed
;
6577 /* To determine which flavor or relocation this is, we depend on the
6578 fact that the INPUT_SECTION's REL_HDR is read before its REL_HDR2. */
6579 rel_hdr
= &elf_section_data (sec
)->rel_hdr
;
6580 bed
= get_elf_backend_data (abfd
);
6581 if ((size_t) (rel
- relocs
)
6582 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
6583 rel_hdr
= elf_section_data (sec
)->rel_hdr2
;
6584 return rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (abfd
);
6587 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
6588 HOWTO is the relocation's howto and CONTENTS points to the contents
6589 of the section that REL is against. */
6592 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
6593 reloc_howto_type
*howto
, bfd_byte
*contents
)
6596 unsigned int r_type
;
6599 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6600 location
= contents
+ rel
->r_offset
;
6602 /* Get the addend, which is stored in the input file. */
6603 _bfd_mips16_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
6604 addend
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
6605 _bfd_mips16_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
6607 return addend
& howto
->src_mask
;
6610 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
6611 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
6612 and update *ADDEND with the final addend. Return true on success
6613 or false if the LO16 could not be found. RELEND is the exclusive
6614 upper bound on the relocations for REL's section. */
6617 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
6618 const Elf_Internal_Rela
*rel
,
6619 const Elf_Internal_Rela
*relend
,
6620 bfd_byte
*contents
, bfd_vma
*addend
)
6622 unsigned int r_type
, lo16_type
;
6623 const Elf_Internal_Rela
*lo16_relocation
;
6624 reloc_howto_type
*lo16_howto
;
6627 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6628 if (mips16_reloc_p (r_type
))
6629 lo16_type
= R_MIPS16_LO16
;
6631 lo16_type
= R_MIPS_LO16
;
6633 /* The combined value is the sum of the HI16 addend, left-shifted by
6634 sixteen bits, and the LO16 addend, sign extended. (Usually, the
6635 code does a `lui' of the HI16 value, and then an `addiu' of the
6638 Scan ahead to find a matching LO16 relocation.
6640 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
6641 be immediately following. However, for the IRIX6 ABI, the next
6642 relocation may be a composed relocation consisting of several
6643 relocations for the same address. In that case, the R_MIPS_LO16
6644 relocation may occur as one of these. We permit a similar
6645 extension in general, as that is useful for GCC.
6647 In some cases GCC dead code elimination removes the LO16 but keeps
6648 the corresponding HI16. This is strictly speaking a violation of
6649 the ABI but not immediately harmful. */
6650 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
6651 if (lo16_relocation
== NULL
)
6654 /* Obtain the addend kept there. */
6655 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
6656 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
6658 l
<<= lo16_howto
->rightshift
;
6659 l
= _bfd_mips_elf_sign_extend (l
, 16);
6666 /* Try to read the contents of section SEC in bfd ABFD. Return true and
6667 store the contents in *CONTENTS on success. Assume that *CONTENTS
6668 already holds the contents if it is nonull on entry. */
6671 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
6676 /* Get cached copy if it exists. */
6677 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6679 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
6683 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
6686 /* Look through the relocs for a section during the first phase, and
6687 allocate space in the global offset table. */
6690 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6691 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6695 Elf_Internal_Shdr
*symtab_hdr
;
6696 struct elf_link_hash_entry
**sym_hashes
;
6698 const Elf_Internal_Rela
*rel
;
6699 const Elf_Internal_Rela
*rel_end
;
6701 const struct elf_backend_data
*bed
;
6702 struct mips_elf_link_hash_table
*htab
;
6705 reloc_howto_type
*howto
;
6707 if (info
->relocatable
)
6710 htab
= mips_elf_hash_table (info
);
6711 dynobj
= elf_hash_table (info
)->dynobj
;
6712 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6713 sym_hashes
= elf_sym_hashes (abfd
);
6714 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6716 bed
= get_elf_backend_data (abfd
);
6717 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6719 /* Check for the mips16 stub sections. */
6721 name
= bfd_get_section_name (abfd
, sec
);
6722 if (FN_STUB_P (name
))
6724 unsigned long r_symndx
;
6726 /* Look at the relocation information to figure out which symbol
6729 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
6732 (*_bfd_error_handler
)
6733 (_("%B: Warning: cannot determine the target function for"
6734 " stub section `%s'"),
6736 bfd_set_error (bfd_error_bad_value
);
6740 if (r_symndx
< extsymoff
6741 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6745 /* This stub is for a local symbol. This stub will only be
6746 needed if there is some relocation in this BFD, other
6747 than a 16 bit function call, which refers to this symbol. */
6748 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6750 Elf_Internal_Rela
*sec_relocs
;
6751 const Elf_Internal_Rela
*r
, *rend
;
6753 /* We can ignore stub sections when looking for relocs. */
6754 if ((o
->flags
& SEC_RELOC
) == 0
6755 || o
->reloc_count
== 0
6756 || section_allows_mips16_refs_p (o
))
6760 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
6762 if (sec_relocs
== NULL
)
6765 rend
= sec_relocs
+ o
->reloc_count
;
6766 for (r
= sec_relocs
; r
< rend
; r
++)
6767 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
6768 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
6771 if (elf_section_data (o
)->relocs
!= sec_relocs
)
6780 /* There is no non-call reloc for this stub, so we do
6781 not need it. Since this function is called before
6782 the linker maps input sections to output sections, we
6783 can easily discard it by setting the SEC_EXCLUDE
6785 sec
->flags
|= SEC_EXCLUDE
;
6789 /* Record this stub in an array of local symbol stubs for
6791 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6793 unsigned long symcount
;
6797 if (elf_bad_symtab (abfd
))
6798 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
6800 symcount
= symtab_hdr
->sh_info
;
6801 amt
= symcount
* sizeof (asection
*);
6802 n
= bfd_zalloc (abfd
, amt
);
6805 elf_tdata (abfd
)->local_stubs
= n
;
6808 sec
->flags
|= SEC_KEEP
;
6809 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6811 /* We don't need to set mips16_stubs_seen in this case.
6812 That flag is used to see whether we need to look through
6813 the global symbol table for stubs. We don't need to set
6814 it here, because we just have a local stub. */
6818 struct mips_elf_link_hash_entry
*h
;
6820 h
= ((struct mips_elf_link_hash_entry
*)
6821 sym_hashes
[r_symndx
- extsymoff
]);
6823 while (h
->root
.root
.type
== bfd_link_hash_indirect
6824 || h
->root
.root
.type
== bfd_link_hash_warning
)
6825 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
6827 /* H is the symbol this stub is for. */
6829 /* If we already have an appropriate stub for this function, we
6830 don't need another one, so we can discard this one. Since
6831 this function is called before the linker maps input sections
6832 to output sections, we can easily discard it by setting the
6833 SEC_EXCLUDE flag. */
6834 if (h
->fn_stub
!= NULL
)
6836 sec
->flags
|= SEC_EXCLUDE
;
6840 sec
->flags
|= SEC_KEEP
;
6842 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
6845 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
6847 unsigned long r_symndx
;
6848 struct mips_elf_link_hash_entry
*h
;
6851 /* Look at the relocation information to figure out which symbol
6854 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
6857 (*_bfd_error_handler
)
6858 (_("%B: Warning: cannot determine the target function for"
6859 " stub section `%s'"),
6861 bfd_set_error (bfd_error_bad_value
);
6865 if (r_symndx
< extsymoff
6866 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6870 /* This stub is for a local symbol. This stub will only be
6871 needed if there is some relocation (R_MIPS16_26) in this BFD
6872 that refers to this symbol. */
6873 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6875 Elf_Internal_Rela
*sec_relocs
;
6876 const Elf_Internal_Rela
*r
, *rend
;
6878 /* We can ignore stub sections when looking for relocs. */
6879 if ((o
->flags
& SEC_RELOC
) == 0
6880 || o
->reloc_count
== 0
6881 || section_allows_mips16_refs_p (o
))
6885 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
6887 if (sec_relocs
== NULL
)
6890 rend
= sec_relocs
+ o
->reloc_count
;
6891 for (r
= sec_relocs
; r
< rend
; r
++)
6892 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
6893 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
6896 if (elf_section_data (o
)->relocs
!= sec_relocs
)
6905 /* There is no non-call reloc for this stub, so we do
6906 not need it. Since this function is called before
6907 the linker maps input sections to output sections, we
6908 can easily discard it by setting the SEC_EXCLUDE
6910 sec
->flags
|= SEC_EXCLUDE
;
6914 /* Record this stub in an array of local symbol call_stubs for
6916 if (elf_tdata (abfd
)->local_call_stubs
== NULL
)
6918 unsigned long symcount
;
6922 if (elf_bad_symtab (abfd
))
6923 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
6925 symcount
= symtab_hdr
->sh_info
;
6926 amt
= symcount
* sizeof (asection
*);
6927 n
= bfd_zalloc (abfd
, amt
);
6930 elf_tdata (abfd
)->local_call_stubs
= n
;
6933 sec
->flags
|= SEC_KEEP
;
6934 elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
6936 /* We don't need to set mips16_stubs_seen in this case.
6937 That flag is used to see whether we need to look through
6938 the global symbol table for stubs. We don't need to set
6939 it here, because we just have a local stub. */
6943 h
= ((struct mips_elf_link_hash_entry
*)
6944 sym_hashes
[r_symndx
- extsymoff
]);
6946 /* H is the symbol this stub is for. */
6948 if (CALL_FP_STUB_P (name
))
6949 loc
= &h
->call_fp_stub
;
6951 loc
= &h
->call_stub
;
6953 /* If we already have an appropriate stub for this function, we
6954 don't need another one, so we can discard this one. Since
6955 this function is called before the linker maps input sections
6956 to output sections, we can easily discard it by setting the
6957 SEC_EXCLUDE flag. */
6960 sec
->flags
|= SEC_EXCLUDE
;
6964 sec
->flags
|= SEC_KEEP
;
6966 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
6972 for (rel
= relocs
; rel
< rel_end
; ++rel
)
6974 unsigned long r_symndx
;
6975 unsigned int r_type
;
6976 struct elf_link_hash_entry
*h
;
6978 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
6979 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6981 if (r_symndx
< extsymoff
)
6983 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
6985 (*_bfd_error_handler
)
6986 (_("%B: Malformed reloc detected for section %s"),
6988 bfd_set_error (bfd_error_bad_value
);
6993 h
= sym_hashes
[r_symndx
- extsymoff
];
6995 /* This may be an indirect symbol created because of a version. */
6998 while (h
->root
.type
== bfd_link_hash_indirect
)
6999 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7003 /* Some relocs require a global offset table. */
7004 if (dynobj
== NULL
|| htab
->sgot
== NULL
)
7008 case R_MIPS16_GOT16
:
7009 case R_MIPS16_CALL16
:
7012 case R_MIPS_CALL_HI16
:
7013 case R_MIPS_CALL_LO16
:
7014 case R_MIPS_GOT_HI16
:
7015 case R_MIPS_GOT_LO16
:
7016 case R_MIPS_GOT_PAGE
:
7017 case R_MIPS_GOT_OFST
:
7018 case R_MIPS_GOT_DISP
:
7019 case R_MIPS_TLS_GOTTPREL
:
7021 case R_MIPS_TLS_LDM
:
7023 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7024 if (!mips_elf_create_got_section (dynobj
, info
))
7026 if (htab
->is_vxworks
&& !info
->shared
)
7028 (*_bfd_error_handler
)
7029 (_("%B: GOT reloc at 0x%lx not expected in executables"),
7030 abfd
, (unsigned long) rel
->r_offset
);
7031 bfd_set_error (bfd_error_bad_value
);
7039 /* In VxWorks executables, references to external symbols
7040 are handled using copy relocs or PLT stubs, so there's
7041 no need to add a dynamic relocation here. */
7043 && (info
->shared
|| (h
!= NULL
&& !htab
->is_vxworks
))
7044 && (sec
->flags
& SEC_ALLOC
) != 0)
7045 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7055 ((struct mips_elf_link_hash_entry
*) h
)->is_relocation_target
= TRUE
;
7057 /* Relocations against the special VxWorks __GOTT_BASE__ and
7058 __GOTT_INDEX__ symbols must be left to the loader. Allocate
7059 room for them in .rela.dyn. */
7060 if (is_gott_symbol (info
, h
))
7064 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7068 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7069 if (MIPS_ELF_READONLY_SECTION (sec
))
7070 /* We tell the dynamic linker that there are
7071 relocations against the text segment. */
7072 info
->flags
|= DF_TEXTREL
;
7075 else if (r_type
== R_MIPS_CALL_LO16
7076 || r_type
== R_MIPS_GOT_LO16
7077 || r_type
== R_MIPS_GOT_DISP
7078 || (got16_reloc_p (r_type
) && htab
->is_vxworks
))
7080 /* We may need a local GOT entry for this relocation. We
7081 don't count R_MIPS_GOT_PAGE because we can estimate the
7082 maximum number of pages needed by looking at the size of
7083 the segment. Similar comments apply to R_MIPS*_GOT16 and
7084 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
7085 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
7086 R_MIPS_CALL_HI16 because these are always followed by an
7087 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
7088 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7089 rel
->r_addend
, info
, 0))
7096 case R_MIPS16_CALL16
:
7099 (*_bfd_error_handler
)
7100 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
7101 abfd
, (unsigned long) rel
->r_offset
);
7102 bfd_set_error (bfd_error_bad_value
);
7107 case R_MIPS_CALL_HI16
:
7108 case R_MIPS_CALL_LO16
:
7111 /* VxWorks call relocations point the function's .got.plt
7112 entry, which will be allocated by adjust_dynamic_symbol.
7113 Otherwise, this symbol requires a global GOT entry. */
7114 if ((!htab
->is_vxworks
|| h
->forced_local
)
7115 && !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7118 /* We need a stub, not a plt entry for the undefined
7119 function. But we record it as if it needs plt. See
7120 _bfd_elf_adjust_dynamic_symbol. */
7126 case R_MIPS_GOT_PAGE
:
7127 /* If this is a global, overridable symbol, GOT_PAGE will
7128 decay to GOT_DISP, so we'll need a GOT entry for it. */
7131 struct mips_elf_link_hash_entry
*hmips
=
7132 (struct mips_elf_link_hash_entry
*) h
;
7134 while (hmips
->root
.root
.type
== bfd_link_hash_indirect
7135 || hmips
->root
.root
.type
== bfd_link_hash_warning
)
7136 hmips
= (struct mips_elf_link_hash_entry
*)
7137 hmips
->root
.root
.u
.i
.link
;
7139 /* This symbol is definitely not overridable. */
7140 if (hmips
->root
.def_regular
7141 && ! (info
->shared
&& ! info
->symbolic
7142 && ! hmips
->root
.forced_local
))
7147 case R_MIPS16_GOT16
:
7149 case R_MIPS_GOT_HI16
:
7150 case R_MIPS_GOT_LO16
:
7151 if (!h
|| r_type
== R_MIPS_GOT_PAGE
)
7153 /* This relocation needs (or may need, if h != NULL) a
7154 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
7155 know for sure until we know whether the symbol is
7157 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
7159 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7161 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7162 addend
= mips_elf_read_rel_addend (abfd
, rel
,
7164 if (r_type
== R_MIPS_GOT16
)
7165 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
7168 addend
<<= howto
->rightshift
;
7171 addend
= rel
->r_addend
;
7172 if (!mips_elf_record_got_page_entry (info
, abfd
, r_symndx
,
7179 case R_MIPS_GOT_DISP
:
7180 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7184 case R_MIPS_TLS_GOTTPREL
:
7186 info
->flags
|= DF_STATIC_TLS
;
7189 case R_MIPS_TLS_LDM
:
7190 if (r_type
== R_MIPS_TLS_LDM
)
7198 /* This symbol requires a global offset table entry, or two
7199 for TLS GD relocations. */
7201 unsigned char flag
= (r_type
== R_MIPS_TLS_GD
7203 : r_type
== R_MIPS_TLS_LDM
7208 struct mips_elf_link_hash_entry
*hmips
=
7209 (struct mips_elf_link_hash_entry
*) h
;
7210 hmips
->tls_type
|= flag
;
7212 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
,
7218 BFD_ASSERT (flag
== GOT_TLS_LDM
|| r_symndx
!= 0);
7220 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7231 /* In VxWorks executables, references to external symbols
7232 are handled using copy relocs or PLT stubs, so there's
7233 no need to add a .rela.dyn entry for this relocation. */
7234 if ((info
->shared
|| (h
!= NULL
&& !htab
->is_vxworks
))
7235 && !(h
&& strcmp (h
->root
.root
.string
, "__gnu_local_gp") == 0)
7236 && (sec
->flags
& SEC_ALLOC
) != 0)
7240 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7244 if (info
->shared
&& h
== NULL
)
7246 /* When creating a shared object, we must copy these
7247 reloc types into the output file as R_MIPS_REL32
7248 relocs. Make room for this reloc in .rel(a).dyn. */
7249 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7250 if (MIPS_ELF_READONLY_SECTION (sec
))
7251 /* We tell the dynamic linker that there are
7252 relocations against the text segment. */
7253 info
->flags
|= DF_TEXTREL
;
7257 struct mips_elf_link_hash_entry
*hmips
;
7259 /* For a shared object, we must copy this relocation
7260 unless the symbol turns out to be undefined and
7261 weak with non-default visibility, in which case
7262 it will be left as zero.
7264 We could elide R_MIPS_REL32 for locally binding symbols
7265 in shared libraries, but do not yet do so.
7267 For an executable, we only need to copy this
7268 reloc if the symbol is defined in a dynamic
7270 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7271 ++hmips
->possibly_dynamic_relocs
;
7272 if (MIPS_ELF_READONLY_SECTION (sec
))
7273 /* We need it to tell the dynamic linker if there
7274 are relocations against the text segment. */
7275 hmips
->readonly_reloc
= TRUE
;
7278 /* Even though we don't directly need a GOT entry for
7279 this symbol, a symbol must have a dynamic symbol
7280 table index greater that DT_MIPS_GOTSYM if there are
7281 dynamic relocations against it. This does not apply
7282 to VxWorks, which does not have the usual coupling
7283 between global GOT entries and .dynsym entries. */
7284 if (h
!= NULL
&& !htab
->is_vxworks
)
7286 struct mips_elf_link_hash_entry
*hmips
;
7288 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7289 if (hmips
->global_got_area
> GGA_RELOC_ONLY
)
7290 hmips
->global_got_area
= GGA_RELOC_ONLY
;
7294 if (SGI_COMPAT (abfd
))
7295 mips_elf_hash_table (info
)->compact_rel_size
+=
7296 sizeof (Elf32_External_crinfo
);
7301 ((struct mips_elf_link_hash_entry
*) h
)->is_branch_target
= TRUE
;
7306 ((struct mips_elf_link_hash_entry
*) h
)->is_branch_target
= TRUE
;
7309 case R_MIPS_GPREL16
:
7310 case R_MIPS_LITERAL
:
7311 case R_MIPS_GPREL32
:
7312 if (SGI_COMPAT (abfd
))
7313 mips_elf_hash_table (info
)->compact_rel_size
+=
7314 sizeof (Elf32_External_crinfo
);
7317 /* This relocation describes the C++ object vtable hierarchy.
7318 Reconstruct it for later use during GC. */
7319 case R_MIPS_GNU_VTINHERIT
:
7320 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7324 /* This relocation describes which C++ vtable entries are actually
7325 used. Record for later use during GC. */
7326 case R_MIPS_GNU_VTENTRY
:
7327 BFD_ASSERT (h
!= NULL
);
7329 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7337 /* We must not create a stub for a symbol that has relocations
7338 related to taking the function's address. This doesn't apply to
7339 VxWorks, where CALL relocs refer to a .got.plt entry instead of
7340 a normal .got entry. */
7341 if (!htab
->is_vxworks
&& h
!= NULL
)
7345 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
7347 case R_MIPS16_CALL16
:
7349 case R_MIPS_CALL_HI16
:
7350 case R_MIPS_CALL_LO16
:
7355 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
7356 if there is one. We only need to handle global symbols here;
7357 we decide whether to keep or delete stubs for local symbols
7358 when processing the stub's relocations. */
7360 && !mips16_call_reloc_p (r_type
)
7361 && !section_allows_mips16_refs_p (sec
))
7363 struct mips_elf_link_hash_entry
*mh
;
7365 mh
= (struct mips_elf_link_hash_entry
*) h
;
7366 mh
->need_fn_stub
= TRUE
;
7374 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
7375 struct bfd_link_info
*link_info
,
7378 Elf_Internal_Rela
*internal_relocs
;
7379 Elf_Internal_Rela
*irel
, *irelend
;
7380 Elf_Internal_Shdr
*symtab_hdr
;
7381 bfd_byte
*contents
= NULL
;
7383 bfd_boolean changed_contents
= FALSE
;
7384 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
7385 Elf_Internal_Sym
*isymbuf
= NULL
;
7387 /* We are not currently changing any sizes, so only one pass. */
7390 if (link_info
->relocatable
)
7393 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
7394 link_info
->keep_memory
);
7395 if (internal_relocs
== NULL
)
7398 irelend
= internal_relocs
+ sec
->reloc_count
7399 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
7400 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7401 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7403 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
7406 bfd_signed_vma sym_offset
;
7407 unsigned int r_type
;
7408 unsigned long r_symndx
;
7410 unsigned long instruction
;
7412 /* Turn jalr into bgezal, and jr into beq, if they're marked
7413 with a JALR relocation, that indicate where they jump to.
7414 This saves some pipeline bubbles. */
7415 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
7416 if (r_type
!= R_MIPS_JALR
)
7419 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
7420 /* Compute the address of the jump target. */
7421 if (r_symndx
>= extsymoff
)
7423 struct mips_elf_link_hash_entry
*h
7424 = ((struct mips_elf_link_hash_entry
*)
7425 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
7427 while (h
->root
.root
.type
== bfd_link_hash_indirect
7428 || h
->root
.root
.type
== bfd_link_hash_warning
)
7429 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7431 /* If a symbol is undefined, or if it may be overridden,
7433 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
7434 || h
->root
.root
.type
== bfd_link_hash_defweak
)
7435 && h
->root
.root
.u
.def
.section
)
7436 || (link_info
->shared
&& ! link_info
->symbolic
7437 && !h
->root
.forced_local
))
7440 sym_sec
= h
->root
.root
.u
.def
.section
;
7441 if (sym_sec
->output_section
)
7442 symval
= (h
->root
.root
.u
.def
.value
7443 + sym_sec
->output_section
->vma
7444 + sym_sec
->output_offset
);
7446 symval
= h
->root
.root
.u
.def
.value
;
7450 Elf_Internal_Sym
*isym
;
7452 /* Read this BFD's symbols if we haven't done so already. */
7453 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
7455 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7456 if (isymbuf
== NULL
)
7457 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
7458 symtab_hdr
->sh_info
, 0,
7460 if (isymbuf
== NULL
)
7464 isym
= isymbuf
+ r_symndx
;
7465 if (isym
->st_shndx
== SHN_UNDEF
)
7467 else if (isym
->st_shndx
== SHN_ABS
)
7468 sym_sec
= bfd_abs_section_ptr
;
7469 else if (isym
->st_shndx
== SHN_COMMON
)
7470 sym_sec
= bfd_com_section_ptr
;
7473 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7474 symval
= isym
->st_value
7475 + sym_sec
->output_section
->vma
7476 + sym_sec
->output_offset
;
7479 /* Compute branch offset, from delay slot of the jump to the
7481 sym_offset
= (symval
+ irel
->r_addend
)
7482 - (sec_start
+ irel
->r_offset
+ 4);
7484 /* Branch offset must be properly aligned. */
7485 if ((sym_offset
& 3) != 0)
7490 /* Check that it's in range. */
7491 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
7494 /* Get the section contents if we haven't done so already. */
7495 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7498 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
7500 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
7501 if ((instruction
& 0xfc1fffff) == 0x0000f809)
7502 instruction
= 0x04110000;
7503 /* If it was jr <reg>, turn it into b <target>. */
7504 else if ((instruction
& 0xfc1fffff) == 0x00000008)
7505 instruction
= 0x10000000;
7509 instruction
|= (sym_offset
& 0xffff);
7510 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
7511 changed_contents
= TRUE
;
7514 if (contents
!= NULL
7515 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7517 if (!changed_contents
&& !link_info
->keep_memory
)
7521 /* Cache the section contents for elf_link_input_bfd. */
7522 elf_section_data (sec
)->this_hdr
.contents
= contents
;
7528 if (contents
!= NULL
7529 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7534 /* Allocate space for global sym dynamic relocs. */
7537 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7539 struct bfd_link_info
*info
= inf
;
7541 struct mips_elf_link_hash_entry
*hmips
;
7542 struct mips_elf_link_hash_table
*htab
;
7544 htab
= mips_elf_hash_table (info
);
7545 dynobj
= elf_hash_table (info
)->dynobj
;
7546 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7548 /* VxWorks executables are handled elsewhere; we only need to
7549 allocate relocations in shared objects. */
7550 if (htab
->is_vxworks
&& !info
->shared
)
7553 /* Ignore indirect and warning symbols. All relocations against
7554 such symbols will be redirected to the target symbol. */
7555 if (h
->root
.type
== bfd_link_hash_indirect
7556 || h
->root
.type
== bfd_link_hash_warning
)
7559 /* If this symbol is defined in a dynamic object, or we are creating
7560 a shared library, we will need to copy any R_MIPS_32 or
7561 R_MIPS_REL32 relocs against it into the output file. */
7562 if (! info
->relocatable
7563 && hmips
->possibly_dynamic_relocs
!= 0
7564 && (h
->root
.type
== bfd_link_hash_defweak
7568 bfd_boolean do_copy
= TRUE
;
7570 if (h
->root
.type
== bfd_link_hash_undefweak
)
7572 /* Do not copy relocations for undefined weak symbols with
7573 non-default visibility. */
7574 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7577 /* Make sure undefined weak symbols are output as a dynamic
7579 else if (h
->dynindx
== -1 && !h
->forced_local
)
7581 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7588 mips_elf_allocate_dynamic_relocations
7589 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
7590 if (hmips
->readonly_reloc
)
7591 /* We tell the dynamic linker that there are relocations
7592 against the text segment. */
7593 info
->flags
|= DF_TEXTREL
;
7600 /* Adjust a symbol defined by a dynamic object and referenced by a
7601 regular object. The current definition is in some section of the
7602 dynamic object, but we're not including those sections. We have to
7603 change the definition to something the rest of the link can
7607 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7608 struct elf_link_hash_entry
*h
)
7611 struct mips_elf_link_hash_entry
*hmips
;
7612 struct mips_elf_link_hash_table
*htab
;
7614 htab
= mips_elf_hash_table (info
);
7615 dynobj
= elf_hash_table (info
)->dynobj
;
7617 /* Make sure we know what is going on here. */
7618 BFD_ASSERT (dynobj
!= NULL
7620 || h
->u
.weakdef
!= NULL
7623 && !h
->def_regular
)));
7625 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7627 /* For a function, create a stub, if allowed. */
7628 if (! hmips
->no_fn_stub
7631 if (! elf_hash_table (info
)->dynamic_sections_created
)
7634 /* If this symbol is not defined in a regular file, then set
7635 the symbol to the stub location. This is required to make
7636 function pointers compare as equal between the normal
7637 executable and the shared library. */
7638 if (!h
->def_regular
)
7640 hmips
->needs_lazy_stub
= TRUE
;
7641 htab
->lazy_stub_count
++;
7645 else if ((h
->type
== STT_FUNC
)
7648 /* This will set the entry for this symbol in the GOT to 0, and
7649 the dynamic linker will take care of this. */
7650 h
->root
.u
.def
.value
= 0;
7654 /* If this is a weak symbol, and there is a real definition, the
7655 processor independent code will have arranged for us to see the
7656 real definition first, and we can just use the same value. */
7657 if (h
->u
.weakdef
!= NULL
)
7659 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7660 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7661 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7662 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7666 /* This is a reference to a symbol defined by a dynamic object which
7667 is not a function. */
7672 /* Likewise, for VxWorks. */
7675 _bfd_mips_vxworks_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7676 struct elf_link_hash_entry
*h
)
7679 struct mips_elf_link_hash_entry
*hmips
;
7680 struct mips_elf_link_hash_table
*htab
;
7682 htab
= mips_elf_hash_table (info
);
7683 dynobj
= elf_hash_table (info
)->dynobj
;
7684 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7686 /* Make sure we know what is going on here. */
7687 BFD_ASSERT (dynobj
!= NULL
7690 || h
->u
.weakdef
!= NULL
7693 && !h
->def_regular
)));
7695 /* If the symbol is defined by a dynamic object, we need a PLT stub if
7696 either (a) we want to branch to the symbol or (b) we're linking an
7697 executable that needs a canonical function address. In the latter
7698 case, the canonical address will be the address of the executable's
7700 if ((hmips
->is_branch_target
7702 && h
->type
== STT_FUNC
7703 && hmips
->is_relocation_target
))
7707 && !h
->forced_local
)
7710 /* Locally-binding symbols do not need a PLT stub; we can refer to
7711 the functions directly. */
7712 else if (h
->needs_plt
7713 && (SYMBOL_CALLS_LOCAL (info
, h
)
7714 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
7715 && h
->root
.type
== bfd_link_hash_undefweak
)))
7723 /* If this is the first symbol to need a PLT entry, allocate room
7724 for the header, and for the header's .rela.plt.unloaded entries. */
7725 if (htab
->splt
->size
== 0)
7727 htab
->splt
->size
+= htab
->plt_header_size
;
7729 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
7732 /* Assign the next .plt entry to this symbol. */
7733 h
->plt
.offset
= htab
->splt
->size
;
7734 htab
->splt
->size
+= htab
->plt_entry_size
;
7736 /* If the output file has no definition of the symbol, set the
7737 symbol's value to the address of the stub. Point at the PLT
7738 load stub rather than the lazy resolution stub; this stub
7739 will become the canonical function address. */
7740 if (!info
->shared
&& !h
->def_regular
)
7742 h
->root
.u
.def
.section
= htab
->splt
;
7743 h
->root
.u
.def
.value
= h
->plt
.offset
;
7744 h
->root
.u
.def
.value
+= 8;
7747 /* Make room for the .got.plt entry and the R_JUMP_SLOT relocation. */
7748 htab
->sgotplt
->size
+= 4;
7749 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
7751 /* Make room for the .rela.plt.unloaded relocations. */
7753 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
7758 /* If a function symbol is defined by a dynamic object, and we do not
7759 need a PLT stub for it, the symbol's value should be zero. */
7760 if (h
->type
== STT_FUNC
7765 h
->root
.u
.def
.value
= 0;
7769 /* If this is a weak symbol, and there is a real definition, the
7770 processor independent code will have arranged for us to see the
7771 real definition first, and we can just use the same value. */
7772 if (h
->u
.weakdef
!= NULL
)
7774 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7775 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7776 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7777 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7781 /* This is a reference to a symbol defined by a dynamic object which
7782 is not a function. */
7786 /* We must allocate the symbol in our .dynbss section, which will
7787 become part of the .bss section of the executable. There will be
7788 an entry for this symbol in the .dynsym section. The dynamic
7789 object will contain position independent code, so all references
7790 from the dynamic object to this symbol will go through the global
7791 offset table. The dynamic linker will use the .dynsym entry to
7792 determine the address it must put in the global offset table, so
7793 both the dynamic object and the regular object will refer to the
7794 same memory location for the variable. */
7796 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
7798 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
7802 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
7805 /* This function is called after all the input files have been read,
7806 and the input sections have been assigned to output sections. We
7807 check for any mips16 stub sections that we can discard. */
7810 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
7811 struct bfd_link_info
*info
)
7814 struct mips_elf_link_hash_table
*htab
;
7816 htab
= mips_elf_hash_table (info
);
7818 /* The .reginfo section has a fixed size. */
7819 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
7821 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
7823 if (! (info
->relocatable
7824 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
))
7825 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7826 mips_elf_check_mips16_stubs
, info
);
7831 /* If the link uses a GOT, lay it out and work out its size. */
7834 mips_elf_lay_out_got (bfd
*output_bfd
, struct bfd_link_info
*info
)
7838 struct mips_got_info
*g
;
7839 bfd_size_type loadable_size
= 0;
7840 bfd_size_type page_gotno
;
7842 struct mips_elf_count_tls_arg count_tls_arg
;
7843 struct mips_elf_link_hash_table
*htab
;
7845 htab
= mips_elf_hash_table (info
);
7850 dynobj
= elf_hash_table (info
)->dynobj
;
7853 /* Replace entries for indirect and warning symbols with entries for
7854 the target symbol. */
7855 if (!mips_elf_resolve_final_got_entries (g
))
7858 /* Count the number of GOT symbols. */
7859 mips_elf_link_hash_traverse (htab
, mips_elf_count_got_symbols
, g
);
7861 /* Calculate the total loadable size of the output. That
7862 will give us the maximum number of GOT_PAGE entries
7864 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
7866 asection
*subsection
;
7868 for (subsection
= sub
->sections
;
7870 subsection
= subsection
->next
)
7872 if ((subsection
->flags
& SEC_ALLOC
) == 0)
7874 loadable_size
+= ((subsection
->size
+ 0xf)
7875 &~ (bfd_size_type
) 0xf);
7879 if (htab
->is_vxworks
)
7880 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
7881 relocations against local symbols evaluate to "G", and the EABI does
7882 not include R_MIPS_GOT_PAGE. */
7885 /* Assume there are two loadable segments consisting of contiguous
7886 sections. Is 5 enough? */
7887 page_gotno
= (loadable_size
>> 16) + 5;
7889 /* Choose the smaller of the two estimates; both are intended to be
7891 if (page_gotno
> g
->page_gotno
)
7892 page_gotno
= g
->page_gotno
;
7894 g
->local_gotno
+= page_gotno
;
7895 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7896 s
->size
+= g
->global_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7898 /* We need to calculate tls_gotno for global symbols at this point
7899 instead of building it up earlier, to avoid doublecounting
7900 entries for one global symbol from multiple input files. */
7901 count_tls_arg
.info
= info
;
7902 count_tls_arg
.needed
= 0;
7903 elf_link_hash_traverse (elf_hash_table (info
),
7904 mips_elf_count_global_tls_entries
,
7906 g
->tls_gotno
+= count_tls_arg
.needed
;
7907 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7909 /* VxWorks does not support multiple GOTs. It initializes $gp to
7910 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
7912 if (htab
->is_vxworks
)
7914 /* VxWorks executables do not need a GOT. */
7917 /* Each VxWorks GOT entry needs an explicit relocation. */
7920 count
= g
->global_gotno
+ g
->local_gotno
- MIPS_RESERVED_GOTNO (info
);
7922 mips_elf_allocate_dynamic_relocations (dynobj
, info
, count
);
7925 else if (s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
7927 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
7932 struct mips_elf_count_tls_arg arg
;
7934 /* Set up TLS entries. */
7935 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
7936 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
7938 /* Allocate room for the TLS relocations. */
7941 htab_traverse (g
->got_entries
, mips_elf_count_local_tls_relocs
, &arg
);
7942 elf_link_hash_traverse (elf_hash_table (info
),
7943 mips_elf_count_global_tls_relocs
,
7946 mips_elf_allocate_dynamic_relocations (dynobj
, info
, arg
.needed
);
7952 /* Estimate the size of the .MIPS.stubs section. */
7955 mips_elf_estimate_stub_size (bfd
*output_bfd
, struct bfd_link_info
*info
)
7957 struct mips_elf_link_hash_table
*htab
;
7958 bfd_size_type dynsymcount
;
7960 htab
= mips_elf_hash_table (info
);
7961 if (htab
->lazy_stub_count
== 0)
7964 /* IRIX rld assumes that a function stub isn't at the end of the .text
7965 section, so add a dummy entry to the end. */
7966 htab
->lazy_stub_count
++;
7968 /* Get a worst-case estimate of the number of dynamic symbols needed.
7969 At this point, dynsymcount does not account for section symbols
7970 and count_section_dynsyms may overestimate the number that will
7972 dynsymcount
= (elf_hash_table (info
)->dynsymcount
7973 + count_section_dynsyms (output_bfd
, info
));
7975 /* Determine the size of one stub entry. */
7976 htab
->function_stub_size
= (dynsymcount
> 0x10000
7977 ? MIPS_FUNCTION_STUB_BIG_SIZE
7978 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
7980 htab
->sstubs
->size
= htab
->lazy_stub_count
* htab
->function_stub_size
;
7983 /* A mips_elf_link_hash_traverse callback for which DATA points to the
7984 MIPS hash table. If H needs a traditional MIPS lazy-binding stub,
7985 allocate an entry in the stubs section. */
7988 mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry
*h
, void **data
)
7990 struct mips_elf_link_hash_table
*htab
;
7992 htab
= (struct mips_elf_link_hash_table
*) data
;
7993 if (h
->needs_lazy_stub
)
7995 h
->root
.root
.u
.def
.section
= htab
->sstubs
;
7996 h
->root
.root
.u
.def
.value
= htab
->sstubs
->size
;
7997 h
->root
.plt
.offset
= htab
->sstubs
->size
;
7998 htab
->sstubs
->size
+= htab
->function_stub_size
;
8003 /* Allocate offsets in the stubs section to each symbol that needs one.
8004 Set the final size of the .MIPS.stub section. */
8007 mips_elf_lay_out_lazy_stubs (struct bfd_link_info
*info
)
8009 struct mips_elf_link_hash_table
*htab
;
8011 htab
= mips_elf_hash_table (info
);
8012 if (htab
->lazy_stub_count
== 0)
8015 htab
->sstubs
->size
= 0;
8016 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8017 mips_elf_allocate_lazy_stub
, htab
);
8018 htab
->sstubs
->size
+= htab
->function_stub_size
;
8019 BFD_ASSERT (htab
->sstubs
->size
8020 == htab
->lazy_stub_count
* htab
->function_stub_size
);
8023 /* Set the sizes of the dynamic sections. */
8026 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
8027 struct bfd_link_info
*info
)
8031 bfd_boolean reltext
;
8032 struct mips_elf_link_hash_table
*htab
;
8034 htab
= mips_elf_hash_table (info
);
8035 dynobj
= elf_hash_table (info
)->dynobj
;
8036 BFD_ASSERT (dynobj
!= NULL
);
8038 if (elf_hash_table (info
)->dynamic_sections_created
)
8040 /* Set the contents of the .interp section to the interpreter. */
8041 if (info
->executable
)
8043 s
= bfd_get_section_by_name (dynobj
, ".interp");
8044 BFD_ASSERT (s
!= NULL
);
8046 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8048 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8052 /* Allocate space for global sym dynamic relocs. */
8053 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
8055 mips_elf_estimate_stub_size (output_bfd
, info
);
8057 if (!mips_elf_lay_out_got (output_bfd
, info
))
8060 mips_elf_lay_out_lazy_stubs (info
);
8062 /* The check_relocs and adjust_dynamic_symbol entry points have
8063 determined the sizes of the various dynamic sections. Allocate
8066 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8070 /* It's OK to base decisions on the section name, because none
8071 of the dynobj section names depend upon the input files. */
8072 name
= bfd_get_section_name (dynobj
, s
);
8074 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8077 if (CONST_STRNEQ (name
, ".rel"))
8081 const char *outname
;
8084 /* If this relocation section applies to a read only
8085 section, then we probably need a DT_TEXTREL entry.
8086 If the relocation section is .rel(a).dyn, we always
8087 assert a DT_TEXTREL entry rather than testing whether
8088 there exists a relocation to a read only section or
8090 outname
= bfd_get_section_name (output_bfd
,
8092 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8094 && (target
->flags
& SEC_READONLY
) != 0
8095 && (target
->flags
& SEC_ALLOC
) != 0)
8096 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
8099 /* We use the reloc_count field as a counter if we need
8100 to copy relocs into the output file. */
8101 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
8104 /* If combreloc is enabled, elf_link_sort_relocs() will
8105 sort relocations, but in a different way than we do,
8106 and before we're done creating relocations. Also, it
8107 will move them around between input sections'
8108 relocation's contents, so our sorting would be
8109 broken, so don't let it run. */
8110 info
->combreloc
= 0;
8113 else if (! info
->shared
8114 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8115 && CONST_STRNEQ (name
, ".rld_map"))
8117 /* We add a room for __rld_map. It will be filled in by the
8118 rtld to contain a pointer to the _r_debug structure. */
8121 else if (SGI_COMPAT (output_bfd
)
8122 && CONST_STRNEQ (name
, ".compact_rel"))
8123 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8124 else if (! CONST_STRNEQ (name
, ".init")
8126 && s
!= htab
->sgotplt
8128 && s
!= htab
->sstubs
)
8130 /* It's not one of our sections, so don't allocate space. */
8136 s
->flags
|= SEC_EXCLUDE
;
8140 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8143 /* Allocate memory for the section contents. */
8144 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
8145 if (s
->contents
== NULL
)
8147 bfd_set_error (bfd_error_no_memory
);
8152 if (elf_hash_table (info
)->dynamic_sections_created
)
8154 /* Add some entries to the .dynamic section. We fill in the
8155 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
8156 must add the entries now so that we get the correct size for
8157 the .dynamic section. */
8159 /* SGI object has the equivalence of DT_DEBUG in the
8160 DT_MIPS_RLD_MAP entry. This must come first because glibc
8161 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and GDB only
8162 looks at the first one it sees. */
8164 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8167 /* The DT_DEBUG entry may be filled in by the dynamic linker and
8168 used by the debugger. */
8169 if (info
->executable
8170 && !SGI_COMPAT (output_bfd
)
8171 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8174 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
8175 info
->flags
|= DF_TEXTREL
;
8177 if ((info
->flags
& DF_TEXTREL
) != 0)
8179 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8182 /* Clear the DF_TEXTREL flag. It will be set again if we
8183 write out an actual text relocation; we may not, because
8184 at this point we do not know whether e.g. any .eh_frame
8185 absolute relocations have been converted to PC-relative. */
8186 info
->flags
&= ~DF_TEXTREL
;
8189 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8192 if (htab
->is_vxworks
)
8194 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
8195 use any of the DT_MIPS_* tags. */
8196 if (mips_elf_rel_dyn_section (info
, FALSE
))
8198 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
8201 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
8204 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
8207 if (htab
->splt
->size
> 0)
8209 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
8212 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
8215 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
8221 if (mips_elf_rel_dyn_section (info
, FALSE
))
8223 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8226 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8229 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8233 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8236 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8239 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8242 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8245 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8248 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8251 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8254 if (IRIX_COMPAT (dynobj
) == ict_irix5
8255 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8258 if (IRIX_COMPAT (dynobj
) == ict_irix6
8259 && (bfd_get_section_by_name
8260 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8261 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8264 if (htab
->is_vxworks
8265 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
8272 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
8273 Adjust its R_ADDEND field so that it is correct for the output file.
8274 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
8275 and sections respectively; both use symbol indexes. */
8278 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
8279 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
8280 asection
**local_sections
, Elf_Internal_Rela
*rel
)
8282 unsigned int r_type
, r_symndx
;
8283 Elf_Internal_Sym
*sym
;
8286 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8288 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8289 if (r_type
== R_MIPS16_GPREL
8290 || r_type
== R_MIPS_GPREL16
8291 || r_type
== R_MIPS_GPREL32
8292 || r_type
== R_MIPS_LITERAL
)
8294 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
8295 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
8298 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
8299 sym
= local_syms
+ r_symndx
;
8301 /* Adjust REL's addend to account for section merging. */
8302 if (!info
->relocatable
)
8304 sec
= local_sections
[r_symndx
];
8305 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
8308 /* This would normally be done by the rela_normal code in elflink.c. */
8309 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8310 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
8314 /* Relocate a MIPS ELF section. */
8317 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
8318 bfd
*input_bfd
, asection
*input_section
,
8319 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
8320 Elf_Internal_Sym
*local_syms
,
8321 asection
**local_sections
)
8323 Elf_Internal_Rela
*rel
;
8324 const Elf_Internal_Rela
*relend
;
8326 bfd_boolean use_saved_addend_p
= FALSE
;
8327 const struct elf_backend_data
*bed
;
8329 bed
= get_elf_backend_data (output_bfd
);
8330 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8331 for (rel
= relocs
; rel
< relend
; ++rel
)
8335 reloc_howto_type
*howto
;
8336 bfd_boolean require_jalx
;
8337 /* TRUE if the relocation is a RELA relocation, rather than a
8339 bfd_boolean rela_relocation_p
= TRUE
;
8340 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8342 unsigned long r_symndx
;
8344 Elf_Internal_Shdr
*symtab_hdr
;
8345 struct elf_link_hash_entry
*h
;
8347 /* Find the relocation howto for this relocation. */
8348 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
8349 NEWABI_P (input_bfd
)
8350 && (MIPS_RELOC_RELA_P
8351 (input_bfd
, input_section
,
8354 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
8355 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
8356 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8358 sec
= local_sections
[r_symndx
];
8363 unsigned long extsymoff
;
8366 if (!elf_bad_symtab (input_bfd
))
8367 extsymoff
= symtab_hdr
->sh_info
;
8368 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
8369 while (h
->root
.type
== bfd_link_hash_indirect
8370 || h
->root
.type
== bfd_link_hash_warning
)
8371 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8374 if (h
->root
.type
== bfd_link_hash_defined
8375 || h
->root
.type
== bfd_link_hash_defweak
)
8376 sec
= h
->root
.u
.def
.section
;
8379 if (sec
!= NULL
&& elf_discarded_section (sec
))
8381 /* For relocs against symbols from removed linkonce sections,
8382 or sections discarded by a linker script, we just want the
8383 section contents zeroed. Avoid any special processing. */
8384 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
8390 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
8392 /* Some 32-bit code uses R_MIPS_64. In particular, people use
8393 64-bit code, but make sure all their addresses are in the
8394 lowermost or uppermost 32-bit section of the 64-bit address
8395 space. Thus, when they use an R_MIPS_64 they mean what is
8396 usually meant by R_MIPS_32, with the exception that the
8397 stored value is sign-extended to 64 bits. */
8398 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
8400 /* On big-endian systems, we need to lie about the position
8402 if (bfd_big_endian (input_bfd
))
8406 if (!use_saved_addend_p
)
8408 /* If these relocations were originally of the REL variety,
8409 we must pull the addend out of the field that will be
8410 relocated. Otherwise, we simply use the contents of the
8412 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
8415 rela_relocation_p
= FALSE
;
8416 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
8418 if (hi16_reloc_p (r_type
)
8419 || (got16_reloc_p (r_type
)
8420 && mips_elf_local_relocation_p (input_bfd
, rel
,
8421 local_sections
, FALSE
)))
8423 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
8429 name
= h
->root
.root
.string
;
8431 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
8432 local_syms
+ r_symndx
,
8434 (*_bfd_error_handler
)
8435 (_("%B: Can't find matching LO16 reloc against `%s' for %s at 0x%lx in section `%A'"),
8436 input_bfd
, input_section
, name
, howto
->name
,
8441 addend
<<= howto
->rightshift
;
8444 addend
= rel
->r_addend
;
8445 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
8446 local_syms
, local_sections
, rel
);
8449 if (info
->relocatable
)
8451 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
8452 && bfd_big_endian (input_bfd
))
8455 if (!rela_relocation_p
&& rel
->r_addend
)
8457 addend
+= rel
->r_addend
;
8458 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
8459 addend
= mips_elf_high (addend
);
8460 else if (r_type
== R_MIPS_HIGHER
)
8461 addend
= mips_elf_higher (addend
);
8462 else if (r_type
== R_MIPS_HIGHEST
)
8463 addend
= mips_elf_highest (addend
);
8465 addend
>>= howto
->rightshift
;
8467 /* We use the source mask, rather than the destination
8468 mask because the place to which we are writing will be
8469 source of the addend in the final link. */
8470 addend
&= howto
->src_mask
;
8472 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
8473 /* See the comment above about using R_MIPS_64 in the 32-bit
8474 ABI. Here, we need to update the addend. It would be
8475 possible to get away with just using the R_MIPS_32 reloc
8476 but for endianness. */
8482 if (addend
& ((bfd_vma
) 1 << 31))
8484 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
8491 /* If we don't know that we have a 64-bit type,
8492 do two separate stores. */
8493 if (bfd_big_endian (input_bfd
))
8495 /* Store the sign-bits (which are most significant)
8497 low_bits
= sign_bits
;
8503 high_bits
= sign_bits
;
8505 bfd_put_32 (input_bfd
, low_bits
,
8506 contents
+ rel
->r_offset
);
8507 bfd_put_32 (input_bfd
, high_bits
,
8508 contents
+ rel
->r_offset
+ 4);
8512 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
8513 input_bfd
, input_section
,
8518 /* Go on to the next relocation. */
8522 /* In the N32 and 64-bit ABIs there may be multiple consecutive
8523 relocations for the same offset. In that case we are
8524 supposed to treat the output of each relocation as the addend
8526 if (rel
+ 1 < relend
8527 && rel
->r_offset
== rel
[1].r_offset
8528 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
8529 use_saved_addend_p
= TRUE
;
8531 use_saved_addend_p
= FALSE
;
8533 /* Figure out what value we are supposed to relocate. */
8534 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
8535 input_section
, info
, rel
,
8536 addend
, howto
, local_syms
,
8537 local_sections
, &value
,
8538 &name
, &require_jalx
,
8539 use_saved_addend_p
))
8541 case bfd_reloc_continue
:
8542 /* There's nothing to do. */
8545 case bfd_reloc_undefined
:
8546 /* mips_elf_calculate_relocation already called the
8547 undefined_symbol callback. There's no real point in
8548 trying to perform the relocation at this point, so we
8549 just skip ahead to the next relocation. */
8552 case bfd_reloc_notsupported
:
8553 msg
= _("internal error: unsupported relocation error");
8554 info
->callbacks
->warning
8555 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
8558 case bfd_reloc_overflow
:
8559 if (use_saved_addend_p
)
8560 /* Ignore overflow until we reach the last relocation for
8561 a given location. */
8565 struct mips_elf_link_hash_table
*htab
;
8567 htab
= mips_elf_hash_table (info
);
8568 BFD_ASSERT (name
!= NULL
);
8569 if (!htab
->small_data_overflow_reported
8570 && (howto
->type
== R_MIPS_GPREL16
8571 || howto
->type
== R_MIPS_LITERAL
))
8574 _("small-data section exceeds 64KB;"
8575 " lower small-data size limit (see option -G)");
8577 htab
->small_data_overflow_reported
= TRUE
;
8578 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
8580 if (! ((*info
->callbacks
->reloc_overflow
)
8581 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
8582 input_bfd
, input_section
, rel
->r_offset
)))
8595 /* If we've got another relocation for the address, keep going
8596 until we reach the last one. */
8597 if (use_saved_addend_p
)
8603 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
8604 /* See the comment above about using R_MIPS_64 in the 32-bit
8605 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
8606 that calculated the right value. Now, however, we
8607 sign-extend the 32-bit result to 64-bits, and store it as a
8608 64-bit value. We are especially generous here in that we
8609 go to extreme lengths to support this usage on systems with
8610 only a 32-bit VMA. */
8616 if (value
& ((bfd_vma
) 1 << 31))
8618 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
8625 /* If we don't know that we have a 64-bit type,
8626 do two separate stores. */
8627 if (bfd_big_endian (input_bfd
))
8629 /* Undo what we did above. */
8631 /* Store the sign-bits (which are most significant)
8633 low_bits
= sign_bits
;
8639 high_bits
= sign_bits
;
8641 bfd_put_32 (input_bfd
, low_bits
,
8642 contents
+ rel
->r_offset
);
8643 bfd_put_32 (input_bfd
, high_bits
,
8644 contents
+ rel
->r_offset
+ 4);
8648 /* Actually perform the relocation. */
8649 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
8650 input_bfd
, input_section
,
8651 contents
, require_jalx
))
8658 /* If NAME is one of the special IRIX6 symbols defined by the linker,
8659 adjust it appropriately now. */
8662 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
8663 const char *name
, Elf_Internal_Sym
*sym
)
8665 /* The linker script takes care of providing names and values for
8666 these, but we must place them into the right sections. */
8667 static const char* const text_section_symbols
[] = {
8670 "__dso_displacement",
8672 "__program_header_table",
8676 static const char* const data_section_symbols
[] = {
8684 const char* const *p
;
8687 for (i
= 0; i
< 2; ++i
)
8688 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
8691 if (strcmp (*p
, name
) == 0)
8693 /* All of these symbols are given type STT_SECTION by the
8695 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8696 sym
->st_other
= STO_PROTECTED
;
8698 /* The IRIX linker puts these symbols in special sections. */
8700 sym
->st_shndx
= SHN_MIPS_TEXT
;
8702 sym
->st_shndx
= SHN_MIPS_DATA
;
8708 /* Finish up dynamic symbol handling. We set the contents of various
8709 dynamic sections here. */
8712 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
8713 struct bfd_link_info
*info
,
8714 struct elf_link_hash_entry
*h
,
8715 Elf_Internal_Sym
*sym
)
8719 struct mips_got_info
*g
, *gg
;
8722 struct mips_elf_link_hash_table
*htab
;
8723 struct mips_elf_link_hash_entry
*hmips
;
8725 htab
= mips_elf_hash_table (info
);
8726 dynobj
= elf_hash_table (info
)->dynobj
;
8727 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8729 if (h
->plt
.offset
!= MINUS_ONE
)
8731 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
8733 /* This symbol has a stub. Set it up. */
8735 BFD_ASSERT (h
->dynindx
!= -1);
8737 BFD_ASSERT ((htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8738 || (h
->dynindx
<= 0xffff));
8740 /* Values up to 2^31 - 1 are allowed. Larger values would cause
8741 sign extension at runtime in the stub, resulting in a negative
8743 if (h
->dynindx
& ~0x7fffffff)
8746 /* Fill the stub. */
8748 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
8750 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ idx
);
8752 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8754 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
8758 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
8761 /* If a large stub is not required and sign extension is not a
8762 problem, then use legacy code in the stub. */
8763 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
8764 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff), stub
+ idx
);
8765 else if (h
->dynindx
& ~0x7fff)
8766 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff), stub
+ idx
);
8768 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
8771 BFD_ASSERT (h
->plt
.offset
<= htab
->sstubs
->size
);
8772 memcpy (htab
->sstubs
->contents
+ h
->plt
.offset
,
8773 stub
, htab
->function_stub_size
);
8775 /* Mark the symbol as undefined. plt.offset != -1 occurs
8776 only for the referenced symbol. */
8777 sym
->st_shndx
= SHN_UNDEF
;
8779 /* The run-time linker uses the st_value field of the symbol
8780 to reset the global offset table entry for this external
8781 to its stub address when unlinking a shared object. */
8782 sym
->st_value
= (htab
->sstubs
->output_section
->vma
8783 + htab
->sstubs
->output_offset
8787 /* If we have a MIPS16 function with a stub, the dynamic symbol must
8788 refer to the stub, since only the stub uses the standard calling
8790 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
8792 BFD_ASSERT (hmips
->need_fn_stub
);
8793 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
8794 + hmips
->fn_stub
->output_offset
);
8795 sym
->st_size
= hmips
->fn_stub
->size
;
8796 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
8799 BFD_ASSERT (h
->dynindx
!= -1
8800 || h
->forced_local
);
8804 BFD_ASSERT (g
!= NULL
);
8806 /* Run through the global symbol table, creating GOT entries for all
8807 the symbols that need them. */
8808 if (g
->global_gotsym
!= NULL
8809 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
8814 value
= sym
->st_value
;
8815 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
8816 R_MIPS_GOT16
, info
);
8817 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
8820 if (g
->next
&& h
->dynindx
!= -1 && h
->type
!= STT_TLS
)
8822 struct mips_got_entry e
, *p
;
8828 e
.abfd
= output_bfd
;
8833 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
8836 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
8841 || (elf_hash_table (info
)->dynamic_sections_created
8843 && p
->d
.h
->root
.def_dynamic
8844 && !p
->d
.h
->root
.def_regular
))
8846 /* Create an R_MIPS_REL32 relocation for this entry. Due to
8847 the various compatibility problems, it's easier to mock
8848 up an R_MIPS_32 or R_MIPS_64 relocation and leave
8849 mips_elf_create_dynamic_relocation to calculate the
8850 appropriate addend. */
8851 Elf_Internal_Rela rel
[3];
8853 memset (rel
, 0, sizeof (rel
));
8854 if (ABI_64_P (output_bfd
))
8855 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
8857 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
8858 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
8861 if (! (mips_elf_create_dynamic_relocation
8862 (output_bfd
, info
, rel
,
8863 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
8867 entry
= sym
->st_value
;
8868 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
8873 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
8874 name
= h
->root
.root
.string
;
8875 if (strcmp (name
, "_DYNAMIC") == 0
8876 || h
== elf_hash_table (info
)->hgot
)
8877 sym
->st_shndx
= SHN_ABS
;
8878 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
8879 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
8881 sym
->st_shndx
= SHN_ABS
;
8882 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8885 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
8887 sym
->st_shndx
= SHN_ABS
;
8888 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8889 sym
->st_value
= elf_gp (output_bfd
);
8891 else if (SGI_COMPAT (output_bfd
))
8893 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
8894 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
8896 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8897 sym
->st_other
= STO_PROTECTED
;
8899 sym
->st_shndx
= SHN_MIPS_DATA
;
8901 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
8903 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8904 sym
->st_other
= STO_PROTECTED
;
8905 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
8906 sym
->st_shndx
= SHN_ABS
;
8908 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
8910 if (h
->type
== STT_FUNC
)
8911 sym
->st_shndx
= SHN_MIPS_TEXT
;
8912 else if (h
->type
== STT_OBJECT
)
8913 sym
->st_shndx
= SHN_MIPS_DATA
;
8917 /* Handle the IRIX6-specific symbols. */
8918 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8919 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
8923 if (! mips_elf_hash_table (info
)->use_rld_obj_head
8924 && (strcmp (name
, "__rld_map") == 0
8925 || strcmp (name
, "__RLD_MAP") == 0))
8927 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
8928 BFD_ASSERT (s
!= NULL
);
8929 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
8930 bfd_put_32 (output_bfd
, 0, s
->contents
);
8931 if (mips_elf_hash_table (info
)->rld_value
== 0)
8932 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8934 else if (mips_elf_hash_table (info
)->use_rld_obj_head
8935 && strcmp (name
, "__rld_obj_head") == 0)
8937 /* IRIX6 does not use a .rld_map section. */
8938 if (IRIX_COMPAT (output_bfd
) == ict_irix5
8939 || IRIX_COMPAT (output_bfd
) == ict_none
)
8940 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
8942 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8946 /* Keep dynamic MIPS16 symbols odd. This allows the dynamic linker to
8947 treat MIPS16 symbols like any other. */
8948 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
8950 BFD_ASSERT (sym
->st_value
& 1);
8951 sym
->st_other
-= STO_MIPS16
;
8957 /* Likewise, for VxWorks. */
8960 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
8961 struct bfd_link_info
*info
,
8962 struct elf_link_hash_entry
*h
,
8963 Elf_Internal_Sym
*sym
)
8967 struct mips_got_info
*g
;
8968 struct mips_elf_link_hash_table
*htab
;
8970 htab
= mips_elf_hash_table (info
);
8971 dynobj
= elf_hash_table (info
)->dynobj
;
8973 if (h
->plt
.offset
!= (bfd_vma
) -1)
8976 bfd_vma plt_address
, plt_index
, got_address
, got_offset
, branch_offset
;
8977 Elf_Internal_Rela rel
;
8978 static const bfd_vma
*plt_entry
;
8980 BFD_ASSERT (h
->dynindx
!= -1);
8981 BFD_ASSERT (htab
->splt
!= NULL
);
8982 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
8984 /* Calculate the address of the .plt entry. */
8985 plt_address
= (htab
->splt
->output_section
->vma
8986 + htab
->splt
->output_offset
8989 /* Calculate the index of the entry. */
8990 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
8991 / htab
->plt_entry_size
);
8993 /* Calculate the address of the .got.plt entry. */
8994 got_address
= (htab
->sgotplt
->output_section
->vma
8995 + htab
->sgotplt
->output_offset
8998 /* Calculate the offset of the .got.plt entry from
8999 _GLOBAL_OFFSET_TABLE_. */
9000 got_offset
= mips_elf_gotplt_index (info
, h
);
9002 /* Calculate the offset for the branch at the start of the PLT
9003 entry. The branch jumps to the beginning of .plt. */
9004 branch_offset
= -(h
->plt
.offset
/ 4 + 1) & 0xffff;
9006 /* Fill in the initial value of the .got.plt entry. */
9007 bfd_put_32 (output_bfd
, plt_address
,
9008 htab
->sgotplt
->contents
+ plt_index
* 4);
9010 /* Find out where the .plt entry should go. */
9011 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9015 plt_entry
= mips_vxworks_shared_plt_entry
;
9016 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9017 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9021 bfd_vma got_address_high
, got_address_low
;
9023 plt_entry
= mips_vxworks_exec_plt_entry
;
9024 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9025 got_address_low
= got_address
& 0xffff;
9027 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9028 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9029 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
9030 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
9031 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9032 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9033 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9034 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9036 loc
= (htab
->srelplt2
->contents
9037 + (plt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
9039 /* Emit a relocation for the .got.plt entry. */
9040 rel
.r_offset
= got_address
;
9041 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9042 rel
.r_addend
= h
->plt
.offset
;
9043 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9045 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
9046 loc
+= sizeof (Elf32_External_Rela
);
9047 rel
.r_offset
= plt_address
+ 8;
9048 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9049 rel
.r_addend
= got_offset
;
9050 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9052 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
9053 loc
+= sizeof (Elf32_External_Rela
);
9055 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9056 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9059 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9060 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
9061 rel
.r_offset
= got_address
;
9062 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
9064 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9066 if (!h
->def_regular
)
9067 sym
->st_shndx
= SHN_UNDEF
;
9070 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
9074 BFD_ASSERT (g
!= NULL
);
9076 /* See if this symbol has an entry in the GOT. */
9077 if (g
->global_gotsym
!= NULL
9078 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
9081 Elf_Internal_Rela outrel
;
9085 /* Install the symbol value in the GOT. */
9086 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9087 R_MIPS_GOT16
, info
);
9088 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
9090 /* Add a dynamic relocation for it. */
9091 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9092 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
9093 outrel
.r_offset
= (sgot
->output_section
->vma
9094 + sgot
->output_offset
9096 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
9097 outrel
.r_addend
= 0;
9098 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
9101 /* Emit a copy reloc, if needed. */
9104 Elf_Internal_Rela rel
;
9106 BFD_ASSERT (h
->dynindx
!= -1);
9108 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
9109 + h
->root
.u
.def
.section
->output_offset
9110 + h
->root
.u
.def
.value
);
9111 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
9113 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
9114 htab
->srelbss
->contents
9115 + (htab
->srelbss
->reloc_count
9116 * sizeof (Elf32_External_Rela
)));
9117 ++htab
->srelbss
->reloc_count
;
9120 /* If this is a mips16 symbol, force the value to be even. */
9121 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9122 sym
->st_value
&= ~1;
9127 /* Install the PLT header for a VxWorks executable and finalize the
9128 contents of .rela.plt.unloaded. */
9131 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9133 Elf_Internal_Rela rela
;
9135 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
9136 static const bfd_vma
*plt_entry
;
9137 struct mips_elf_link_hash_table
*htab
;
9139 htab
= mips_elf_hash_table (info
);
9140 plt_entry
= mips_vxworks_exec_plt0_entry
;
9142 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
9143 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
9144 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
9145 + htab
->root
.hgot
->root
.u
.def
.value
);
9147 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
9148 got_value_low
= got_value
& 0xffff;
9150 /* Calculate the address of the PLT header. */
9151 plt_address
= htab
->splt
->output_section
->vma
+ htab
->splt
->output_offset
;
9153 /* Install the PLT header. */
9154 loc
= htab
->splt
->contents
;
9155 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
9156 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
9157 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
9158 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9159 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9160 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9162 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
9163 loc
= htab
->srelplt2
->contents
;
9164 rela
.r_offset
= plt_address
;
9165 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9167 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9168 loc
+= sizeof (Elf32_External_Rela
);
9170 /* Output the relocation for the following addiu of
9171 %lo(_GLOBAL_OFFSET_TABLE_). */
9173 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9174 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9175 loc
+= sizeof (Elf32_External_Rela
);
9177 /* Fix up the remaining relocations. They may have the wrong
9178 symbol index for _G_O_T_ or _P_L_T_ depending on the order
9179 in which symbols were output. */
9180 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
9182 Elf_Internal_Rela rel
;
9184 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9185 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9186 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9187 loc
+= sizeof (Elf32_External_Rela
);
9189 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9190 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9191 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9192 loc
+= sizeof (Elf32_External_Rela
);
9194 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9195 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9196 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9197 loc
+= sizeof (Elf32_External_Rela
);
9201 /* Install the PLT header for a VxWorks shared library. */
9204 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9207 struct mips_elf_link_hash_table
*htab
;
9209 htab
= mips_elf_hash_table (info
);
9211 /* We just need to copy the entry byte-by-byte. */
9212 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
9213 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
9214 htab
->splt
->contents
+ i
* 4);
9217 /* Finish up the dynamic sections. */
9220 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
9221 struct bfd_link_info
*info
)
9226 struct mips_got_info
*gg
, *g
;
9227 struct mips_elf_link_hash_table
*htab
;
9229 htab
= mips_elf_hash_table (info
);
9230 dynobj
= elf_hash_table (info
)->dynobj
;
9232 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
9235 gg
= htab
->got_info
;
9237 if (elf_hash_table (info
)->dynamic_sections_created
)
9240 int dyn_to_skip
= 0, dyn_skipped
= 0;
9242 BFD_ASSERT (sdyn
!= NULL
);
9243 BFD_ASSERT (gg
!= NULL
);
9245 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
9246 BFD_ASSERT (g
!= NULL
);
9248 for (b
= sdyn
->contents
;
9249 b
< sdyn
->contents
+ sdyn
->size
;
9250 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9252 Elf_Internal_Dyn dyn
;
9256 bfd_boolean swap_out_p
;
9258 /* Read in the current dynamic entry. */
9259 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9261 /* Assume that we're going to modify it and write it out. */
9267 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
9271 BFD_ASSERT (htab
->is_vxworks
);
9272 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
9276 /* Rewrite DT_STRSZ. */
9278 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
9283 if (htab
->is_vxworks
)
9285 /* _GLOBAL_OFFSET_TABLE_ is defined to be the beginning
9286 of the ".got" section in DYNOBJ. */
9287 s
= bfd_get_section_by_name (dynobj
, name
);
9288 BFD_ASSERT (s
!= NULL
);
9289 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9293 s
= bfd_get_section_by_name (output_bfd
, name
);
9294 BFD_ASSERT (s
!= NULL
);
9295 dyn
.d_un
.d_ptr
= s
->vma
;
9299 case DT_MIPS_RLD_VERSION
:
9300 dyn
.d_un
.d_val
= 1; /* XXX */
9304 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
9307 case DT_MIPS_TIME_STAMP
:
9315 case DT_MIPS_ICHECKSUM
:
9320 case DT_MIPS_IVERSION
:
9325 case DT_MIPS_BASE_ADDRESS
:
9326 s
= output_bfd
->sections
;
9327 BFD_ASSERT (s
!= NULL
);
9328 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
9331 case DT_MIPS_LOCAL_GOTNO
:
9332 dyn
.d_un
.d_val
= g
->local_gotno
;
9335 case DT_MIPS_UNREFEXTNO
:
9336 /* The index into the dynamic symbol table which is the
9337 entry of the first external symbol that is not
9338 referenced within the same object. */
9339 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
9342 case DT_MIPS_GOTSYM
:
9343 if (gg
->global_gotsym
)
9345 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
9348 /* In case if we don't have global got symbols we default
9349 to setting DT_MIPS_GOTSYM to the same value as
9350 DT_MIPS_SYMTABNO, so we just fall through. */
9352 case DT_MIPS_SYMTABNO
:
9354 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
9355 s
= bfd_get_section_by_name (output_bfd
, name
);
9356 BFD_ASSERT (s
!= NULL
);
9358 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
9361 case DT_MIPS_HIPAGENO
:
9362 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO (info
);
9365 case DT_MIPS_RLD_MAP
:
9366 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
9369 case DT_MIPS_OPTIONS
:
9370 s
= (bfd_get_section_by_name
9371 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
9372 dyn
.d_un
.d_ptr
= s
->vma
;
9376 BFD_ASSERT (htab
->is_vxworks
);
9377 /* The count does not include the JUMP_SLOT relocations. */
9379 dyn
.d_un
.d_val
-= htab
->srelplt
->size
;
9383 BFD_ASSERT (htab
->is_vxworks
);
9384 dyn
.d_un
.d_val
= DT_RELA
;
9388 BFD_ASSERT (htab
->is_vxworks
);
9389 dyn
.d_un
.d_val
= htab
->srelplt
->size
;
9393 BFD_ASSERT (htab
->is_vxworks
);
9394 dyn
.d_un
.d_val
= (htab
->srelplt
->output_section
->vma
9395 + htab
->srelplt
->output_offset
);
9399 /* If we didn't need any text relocations after all, delete
9401 if (!(info
->flags
& DF_TEXTREL
))
9403 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
9409 /* If we didn't need any text relocations after all, clear
9410 DF_TEXTREL from DT_FLAGS. */
9411 if (!(info
->flags
& DF_TEXTREL
))
9412 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
9419 if (htab
->is_vxworks
9420 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
9425 if (swap_out_p
|| dyn_skipped
)
9426 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
9427 (dynobj
, &dyn
, b
- dyn_skipped
);
9431 dyn_skipped
+= dyn_to_skip
;
9436 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
9437 if (dyn_skipped
> 0)
9438 memset (b
- dyn_skipped
, 0, dyn_skipped
);
9441 if (sgot
!= NULL
&& sgot
->size
> 0
9442 && !bfd_is_abs_section (sgot
->output_section
))
9444 if (htab
->is_vxworks
)
9446 /* The first entry of the global offset table points to the
9447 ".dynamic" section. The second is initialized by the
9448 loader and contains the shared library identifier.
9449 The third is also initialized by the loader and points
9450 to the lazy resolution stub. */
9451 MIPS_ELF_PUT_WORD (output_bfd
,
9452 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
9454 MIPS_ELF_PUT_WORD (output_bfd
, 0,
9455 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
9456 MIPS_ELF_PUT_WORD (output_bfd
, 0,
9458 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
9462 /* The first entry of the global offset table will be filled at
9463 runtime. The second entry will be used by some runtime loaders.
9464 This isn't the case of IRIX rld. */
9465 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
9466 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
9467 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
9470 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
9471 = MIPS_ELF_GOT_SIZE (output_bfd
);
9474 /* Generate dynamic relocations for the non-primary gots. */
9475 if (gg
!= NULL
&& gg
->next
)
9477 Elf_Internal_Rela rel
[3];
9480 memset (rel
, 0, sizeof (rel
));
9481 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
9483 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
9485 bfd_vma index
= g
->next
->local_gotno
+ g
->next
->global_gotno
9486 + g
->next
->tls_gotno
;
9488 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
9489 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
9490 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
9492 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
9497 while (index
< g
->assigned_gotno
)
9499 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
9500 = index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
9501 if (!(mips_elf_create_dynamic_relocation
9502 (output_bfd
, info
, rel
, NULL
,
9503 bfd_abs_section_ptr
,
9506 BFD_ASSERT (addend
== 0);
9511 /* The generation of dynamic relocations for the non-primary gots
9512 adds more dynamic relocations. We cannot count them until
9515 if (elf_hash_table (info
)->dynamic_sections_created
)
9518 bfd_boolean swap_out_p
;
9520 BFD_ASSERT (sdyn
!= NULL
);
9522 for (b
= sdyn
->contents
;
9523 b
< sdyn
->contents
+ sdyn
->size
;
9524 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9526 Elf_Internal_Dyn dyn
;
9529 /* Read in the current dynamic entry. */
9530 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9532 /* Assume that we're going to modify it and write it out. */
9538 /* Reduce DT_RELSZ to account for any relocations we
9539 decided not to make. This is for the n64 irix rld,
9540 which doesn't seem to apply any relocations if there
9541 are trailing null entries. */
9542 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9543 dyn
.d_un
.d_val
= (s
->reloc_count
9544 * (ABI_64_P (output_bfd
)
9545 ? sizeof (Elf64_Mips_External_Rel
)
9546 : sizeof (Elf32_External_Rel
)));
9547 /* Adjust the section size too. Tools like the prelinker
9548 can reasonably expect the values to the same. */
9549 elf_section_data (s
->output_section
)->this_hdr
.sh_size
9559 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
9566 Elf32_compact_rel cpt
;
9568 if (SGI_COMPAT (output_bfd
))
9570 /* Write .compact_rel section out. */
9571 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
9575 cpt
.num
= s
->reloc_count
;
9577 cpt
.offset
= (s
->output_section
->filepos
9578 + sizeof (Elf32_External_compact_rel
));
9581 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
9582 ((Elf32_External_compact_rel
*)
9585 /* Clean up a dummy stub function entry in .text. */
9586 if (htab
->sstubs
!= NULL
)
9588 file_ptr dummy_offset
;
9590 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
9591 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
9592 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
9593 htab
->function_stub_size
);
9598 /* The psABI says that the dynamic relocations must be sorted in
9599 increasing order of r_symndx. The VxWorks EABI doesn't require
9600 this, and because the code below handles REL rather than RELA
9601 relocations, using it for VxWorks would be outright harmful. */
9602 if (!htab
->is_vxworks
)
9604 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9606 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
9608 reldyn_sorting_bfd
= output_bfd
;
9610 if (ABI_64_P (output_bfd
))
9611 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
9612 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
9613 sort_dynamic_relocs_64
);
9615 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
9616 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
9617 sort_dynamic_relocs
);
9622 if (htab
->is_vxworks
&& htab
->splt
->size
> 0)
9625 mips_vxworks_finish_shared_plt (output_bfd
, info
);
9627 mips_vxworks_finish_exec_plt (output_bfd
, info
);
9633 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
9636 mips_set_isa_flags (bfd
*abfd
)
9640 switch (bfd_get_mach (abfd
))
9643 case bfd_mach_mips3000
:
9644 val
= E_MIPS_ARCH_1
;
9647 case bfd_mach_mips3900
:
9648 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
9651 case bfd_mach_mips6000
:
9652 val
= E_MIPS_ARCH_2
;
9655 case bfd_mach_mips4000
:
9656 case bfd_mach_mips4300
:
9657 case bfd_mach_mips4400
:
9658 case bfd_mach_mips4600
:
9659 val
= E_MIPS_ARCH_3
;
9662 case bfd_mach_mips4010
:
9663 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
9666 case bfd_mach_mips4100
:
9667 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
9670 case bfd_mach_mips4111
:
9671 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
9674 case bfd_mach_mips4120
:
9675 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
9678 case bfd_mach_mips4650
:
9679 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
9682 case bfd_mach_mips5400
:
9683 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
9686 case bfd_mach_mips5500
:
9687 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
9690 case bfd_mach_mips9000
:
9691 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
9694 case bfd_mach_mips5000
:
9695 case bfd_mach_mips7000
:
9696 case bfd_mach_mips8000
:
9697 case bfd_mach_mips10000
:
9698 case bfd_mach_mips12000
:
9699 val
= E_MIPS_ARCH_4
;
9702 case bfd_mach_mips5
:
9703 val
= E_MIPS_ARCH_5
;
9706 case bfd_mach_mips_loongson_2e
:
9707 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
9710 case bfd_mach_mips_loongson_2f
:
9711 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
9714 case bfd_mach_mips_sb1
:
9715 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
9718 case bfd_mach_mips_octeon
:
9719 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
9722 case bfd_mach_mipsisa32
:
9723 val
= E_MIPS_ARCH_32
;
9726 case bfd_mach_mipsisa64
:
9727 val
= E_MIPS_ARCH_64
;
9730 case bfd_mach_mipsisa32r2
:
9731 val
= E_MIPS_ARCH_32R2
;
9734 case bfd_mach_mipsisa64r2
:
9735 val
= E_MIPS_ARCH_64R2
;
9738 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
9739 elf_elfheader (abfd
)->e_flags
|= val
;
9744 /* The final processing done just before writing out a MIPS ELF object
9745 file. This gets the MIPS architecture right based on the machine
9746 number. This is used by both the 32-bit and the 64-bit ABI. */
9749 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
9750 bfd_boolean linker ATTRIBUTE_UNUSED
)
9753 Elf_Internal_Shdr
**hdrpp
;
9757 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
9758 is nonzero. This is for compatibility with old objects, which used
9759 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
9760 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
9761 mips_set_isa_flags (abfd
);
9763 /* Set the sh_info field for .gptab sections and other appropriate
9764 info for each special section. */
9765 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
9766 i
< elf_numsections (abfd
);
9769 switch ((*hdrpp
)->sh_type
)
9772 case SHT_MIPS_LIBLIST
:
9773 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
9775 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9778 case SHT_MIPS_GPTAB
:
9779 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9780 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9781 BFD_ASSERT (name
!= NULL
9782 && CONST_STRNEQ (name
, ".gptab."));
9783 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
9784 BFD_ASSERT (sec
!= NULL
);
9785 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
9788 case SHT_MIPS_CONTENT
:
9789 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9790 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9791 BFD_ASSERT (name
!= NULL
9792 && CONST_STRNEQ (name
, ".MIPS.content"));
9793 sec
= bfd_get_section_by_name (abfd
,
9794 name
+ sizeof ".MIPS.content" - 1);
9795 BFD_ASSERT (sec
!= NULL
);
9796 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9799 case SHT_MIPS_SYMBOL_LIB
:
9800 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
9802 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9803 sec
= bfd_get_section_by_name (abfd
, ".liblist");
9805 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
9808 case SHT_MIPS_EVENTS
:
9809 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
9810 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
9811 BFD_ASSERT (name
!= NULL
);
9812 if (CONST_STRNEQ (name
, ".MIPS.events"))
9813 sec
= bfd_get_section_by_name (abfd
,
9814 name
+ sizeof ".MIPS.events" - 1);
9817 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
9818 sec
= bfd_get_section_by_name (abfd
,
9820 + sizeof ".MIPS.post_rel" - 1));
9822 BFD_ASSERT (sec
!= NULL
);
9823 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
9830 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
9834 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
9835 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
9840 /* See if we need a PT_MIPS_REGINFO segment. */
9841 s
= bfd_get_section_by_name (abfd
, ".reginfo");
9842 if (s
&& (s
->flags
& SEC_LOAD
))
9845 /* See if we need a PT_MIPS_OPTIONS segment. */
9846 if (IRIX_COMPAT (abfd
) == ict_irix6
9847 && bfd_get_section_by_name (abfd
,
9848 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
9851 /* See if we need a PT_MIPS_RTPROC segment. */
9852 if (IRIX_COMPAT (abfd
) == ict_irix5
9853 && bfd_get_section_by_name (abfd
, ".dynamic")
9854 && bfd_get_section_by_name (abfd
, ".mdebug"))
9857 /* Allocate a PT_NULL header in dynamic objects. See
9858 _bfd_mips_elf_modify_segment_map for details. */
9859 if (!SGI_COMPAT (abfd
)
9860 && bfd_get_section_by_name (abfd
, ".dynamic"))
9866 /* Modify the segment map for an IRIX5 executable. */
9869 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
9870 struct bfd_link_info
*info
)
9873 struct elf_segment_map
*m
, **pm
;
9876 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
9878 s
= bfd_get_section_by_name (abfd
, ".reginfo");
9879 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
9881 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
9882 if (m
->p_type
== PT_MIPS_REGINFO
)
9887 m
= bfd_zalloc (abfd
, amt
);
9891 m
->p_type
= PT_MIPS_REGINFO
;
9895 /* We want to put it after the PHDR and INTERP segments. */
9896 pm
= &elf_tdata (abfd
)->segment_map
;
9898 && ((*pm
)->p_type
== PT_PHDR
9899 || (*pm
)->p_type
== PT_INTERP
))
9907 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
9908 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
9909 PT_MIPS_OPTIONS segment immediately following the program header
9912 /* On non-IRIX6 new abi, we'll have already created a segment
9913 for this section, so don't create another. I'm not sure this
9914 is not also the case for IRIX 6, but I can't test it right
9916 && IRIX_COMPAT (abfd
) == ict_irix6
)
9918 for (s
= abfd
->sections
; s
; s
= s
->next
)
9919 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
9924 struct elf_segment_map
*options_segment
;
9926 pm
= &elf_tdata (abfd
)->segment_map
;
9928 && ((*pm
)->p_type
== PT_PHDR
9929 || (*pm
)->p_type
== PT_INTERP
))
9932 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
9934 amt
= sizeof (struct elf_segment_map
);
9935 options_segment
= bfd_zalloc (abfd
, amt
);
9936 options_segment
->next
= *pm
;
9937 options_segment
->p_type
= PT_MIPS_OPTIONS
;
9938 options_segment
->p_flags
= PF_R
;
9939 options_segment
->p_flags_valid
= TRUE
;
9940 options_segment
->count
= 1;
9941 options_segment
->sections
[0] = s
;
9942 *pm
= options_segment
;
9948 if (IRIX_COMPAT (abfd
) == ict_irix5
)
9950 /* If there are .dynamic and .mdebug sections, we make a room
9951 for the RTPROC header. FIXME: Rewrite without section names. */
9952 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
9953 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
9954 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
9956 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
9957 if (m
->p_type
== PT_MIPS_RTPROC
)
9962 m
= bfd_zalloc (abfd
, amt
);
9966 m
->p_type
= PT_MIPS_RTPROC
;
9968 s
= bfd_get_section_by_name (abfd
, ".rtproc");
9973 m
->p_flags_valid
= 1;
9981 /* We want to put it after the DYNAMIC segment. */
9982 pm
= &elf_tdata (abfd
)->segment_map
;
9983 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
9993 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
9994 .dynstr, .dynsym, and .hash sections, and everything in
9996 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
9998 if ((*pm
)->p_type
== PT_DYNAMIC
)
10001 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
10003 /* For a normal mips executable the permissions for the PT_DYNAMIC
10004 segment are read, write and execute. We do that here since
10005 the code in elf.c sets only the read permission. This matters
10006 sometimes for the dynamic linker. */
10007 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
10009 m
->p_flags
= PF_R
| PF_W
| PF_X
;
10010 m
->p_flags_valid
= 1;
10013 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
10014 glibc's dynamic linker has traditionally derived the number of
10015 tags from the p_filesz field, and sometimes allocates stack
10016 arrays of that size. An overly-big PT_DYNAMIC segment can
10017 be actively harmful in such cases. Making PT_DYNAMIC contain
10018 other sections can also make life hard for the prelinker,
10019 which might move one of the other sections to a different
10020 PT_LOAD segment. */
10021 if (SGI_COMPAT (abfd
)
10024 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
10026 static const char *sec_names
[] =
10028 ".dynamic", ".dynstr", ".dynsym", ".hash"
10032 struct elf_segment_map
*n
;
10034 low
= ~(bfd_vma
) 0;
10036 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
10038 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
10039 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10046 if (high
< s
->vma
+ sz
)
10047 high
= s
->vma
+ sz
;
10052 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10053 if ((s
->flags
& SEC_LOAD
) != 0
10055 && s
->vma
+ s
->size
<= high
)
10058 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
10059 n
= bfd_zalloc (abfd
, amt
);
10066 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10068 if ((s
->flags
& SEC_LOAD
) != 0
10070 && s
->vma
+ s
->size
<= high
)
10072 n
->sections
[i
] = s
;
10081 /* Allocate a spare program header in dynamic objects so that tools
10082 like the prelinker can add an extra PT_LOAD entry.
10084 If the prelinker needs to make room for a new PT_LOAD entry, its
10085 standard procedure is to move the first (read-only) sections into
10086 the new (writable) segment. However, the MIPS ABI requires
10087 .dynamic to be in a read-only segment, and the section will often
10088 start within sizeof (ElfNN_Phdr) bytes of the last program header.
10090 Although the prelinker could in principle move .dynamic to a
10091 writable segment, it seems better to allocate a spare program
10092 header instead, and avoid the need to move any sections.
10093 There is a long tradition of allocating spare dynamic tags,
10094 so allocating a spare program header seems like a natural
10097 If INFO is NULL, we may be copying an already prelinked binary
10098 with objcopy or strip, so do not add this header. */
10100 && !SGI_COMPAT (abfd
)
10101 && bfd_get_section_by_name (abfd
, ".dynamic"))
10103 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
10104 if ((*pm
)->p_type
== PT_NULL
)
10108 m
= bfd_zalloc (abfd
, sizeof (*m
));
10112 m
->p_type
= PT_NULL
;
10120 /* Return the section that should be marked against GC for a given
10124 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
10125 struct bfd_link_info
*info
,
10126 Elf_Internal_Rela
*rel
,
10127 struct elf_link_hash_entry
*h
,
10128 Elf_Internal_Sym
*sym
)
10130 /* ??? Do mips16 stub sections need to be handled special? */
10133 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
10135 case R_MIPS_GNU_VTINHERIT
:
10136 case R_MIPS_GNU_VTENTRY
:
10140 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
10143 /* Update the got entry reference counts for the section being removed. */
10146 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
10147 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
10148 asection
*sec ATTRIBUTE_UNUSED
,
10149 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
10152 Elf_Internal_Shdr
*symtab_hdr
;
10153 struct elf_link_hash_entry
**sym_hashes
;
10154 bfd_signed_vma
*local_got_refcounts
;
10155 const Elf_Internal_Rela
*rel
, *relend
;
10156 unsigned long r_symndx
;
10157 struct elf_link_hash_entry
*h
;
10159 if (info
->relocatable
)
10162 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
10163 sym_hashes
= elf_sym_hashes (abfd
);
10164 local_got_refcounts
= elf_local_got_refcounts (abfd
);
10166 relend
= relocs
+ sec
->reloc_count
;
10167 for (rel
= relocs
; rel
< relend
; rel
++)
10168 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
10170 case R_MIPS16_GOT16
:
10171 case R_MIPS16_CALL16
:
10173 case R_MIPS_CALL16
:
10174 case R_MIPS_CALL_HI16
:
10175 case R_MIPS_CALL_LO16
:
10176 case R_MIPS_GOT_HI16
:
10177 case R_MIPS_GOT_LO16
:
10178 case R_MIPS_GOT_DISP
:
10179 case R_MIPS_GOT_PAGE
:
10180 case R_MIPS_GOT_OFST
:
10181 /* ??? It would seem that the existing MIPS code does no sort
10182 of reference counting or whatnot on its GOT and PLT entries,
10183 so it is not possible to garbage collect them at this time. */
10194 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
10195 hiding the old indirect symbol. Process additional relocation
10196 information. Also called for weakdefs, in which case we just let
10197 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
10200 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
10201 struct elf_link_hash_entry
*dir
,
10202 struct elf_link_hash_entry
*ind
)
10204 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
10206 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
10208 if (ind
->root
.type
!= bfd_link_hash_indirect
)
10211 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
10212 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
10213 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
10214 if (indmips
->readonly_reloc
)
10215 dirmips
->readonly_reloc
= TRUE
;
10216 if (indmips
->no_fn_stub
)
10217 dirmips
->no_fn_stub
= TRUE
;
10218 if (indmips
->global_got_area
< dirmips
->global_got_area
)
10219 dirmips
->global_got_area
= indmips
->global_got_area
;
10220 if (indmips
->global_got_area
< GGA_NONE
)
10221 indmips
->global_got_area
= GGA_NONE
;
10223 if (dirmips
->tls_type
== 0)
10224 dirmips
->tls_type
= indmips
->tls_type
;
10227 #define PDR_SIZE 32
10230 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
10231 struct bfd_link_info
*info
)
10234 bfd_boolean ret
= FALSE
;
10235 unsigned char *tdata
;
10238 o
= bfd_get_section_by_name (abfd
, ".pdr");
10243 if (o
->size
% PDR_SIZE
!= 0)
10245 if (o
->output_section
!= NULL
10246 && bfd_is_abs_section (o
->output_section
))
10249 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
10253 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
10254 info
->keep_memory
);
10261 cookie
->rel
= cookie
->rels
;
10262 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
10264 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
10266 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
10275 mips_elf_section_data (o
)->u
.tdata
= tdata
;
10276 o
->size
-= skip
* PDR_SIZE
;
10282 if (! info
->keep_memory
)
10283 free (cookie
->rels
);
10289 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
10291 if (strcmp (sec
->name
, ".pdr") == 0)
10297 _bfd_mips_elf_write_section (bfd
*output_bfd
,
10298 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
10299 asection
*sec
, bfd_byte
*contents
)
10301 bfd_byte
*to
, *from
, *end
;
10304 if (strcmp (sec
->name
, ".pdr") != 0)
10307 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
10311 end
= contents
+ sec
->size
;
10312 for (from
= contents
, i
= 0;
10314 from
+= PDR_SIZE
, i
++)
10316 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
10319 memcpy (to
, from
, PDR_SIZE
);
10322 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
10323 sec
->output_offset
, sec
->size
);
10327 /* MIPS ELF uses a special find_nearest_line routine in order the
10328 handle the ECOFF debugging information. */
10330 struct mips_elf_find_line
10332 struct ecoff_debug_info d
;
10333 struct ecoff_find_line i
;
10337 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
10338 asymbol
**symbols
, bfd_vma offset
,
10339 const char **filename_ptr
,
10340 const char **functionname_ptr
,
10341 unsigned int *line_ptr
)
10345 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
10346 filename_ptr
, functionname_ptr
,
10350 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
10351 filename_ptr
, functionname_ptr
,
10352 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
10353 &elf_tdata (abfd
)->dwarf2_find_line_info
))
10356 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
10359 flagword origflags
;
10360 struct mips_elf_find_line
*fi
;
10361 const struct ecoff_debug_swap
* const swap
=
10362 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
10364 /* If we are called during a link, mips_elf_final_link may have
10365 cleared the SEC_HAS_CONTENTS field. We force it back on here
10366 if appropriate (which it normally will be). */
10367 origflags
= msec
->flags
;
10368 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
10369 msec
->flags
|= SEC_HAS_CONTENTS
;
10371 fi
= elf_tdata (abfd
)->find_line_info
;
10374 bfd_size_type external_fdr_size
;
10377 struct fdr
*fdr_ptr
;
10378 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
10380 fi
= bfd_zalloc (abfd
, amt
);
10383 msec
->flags
= origflags
;
10387 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
10389 msec
->flags
= origflags
;
10393 /* Swap in the FDR information. */
10394 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
10395 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
10396 if (fi
->d
.fdr
== NULL
)
10398 msec
->flags
= origflags
;
10401 external_fdr_size
= swap
->external_fdr_size
;
10402 fdr_ptr
= fi
->d
.fdr
;
10403 fraw_src
= (char *) fi
->d
.external_fdr
;
10404 fraw_end
= (fraw_src
10405 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
10406 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
10407 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
10409 elf_tdata (abfd
)->find_line_info
= fi
;
10411 /* Note that we don't bother to ever free this information.
10412 find_nearest_line is either called all the time, as in
10413 objdump -l, so the information should be saved, or it is
10414 rarely called, as in ld error messages, so the memory
10415 wasted is unimportant. Still, it would probably be a
10416 good idea for free_cached_info to throw it away. */
10419 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
10420 &fi
->i
, filename_ptr
, functionname_ptr
,
10423 msec
->flags
= origflags
;
10427 msec
->flags
= origflags
;
10430 /* Fall back on the generic ELF find_nearest_line routine. */
10432 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
10433 filename_ptr
, functionname_ptr
,
10438 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
10439 const char **filename_ptr
,
10440 const char **functionname_ptr
,
10441 unsigned int *line_ptr
)
10444 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
10445 functionname_ptr
, line_ptr
,
10446 & elf_tdata (abfd
)->dwarf2_find_line_info
);
10451 /* When are writing out the .options or .MIPS.options section,
10452 remember the bytes we are writing out, so that we can install the
10453 GP value in the section_processing routine. */
10456 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
10457 const void *location
,
10458 file_ptr offset
, bfd_size_type count
)
10460 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
10464 if (elf_section_data (section
) == NULL
)
10466 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
10467 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
10468 if (elf_section_data (section
) == NULL
)
10471 c
= mips_elf_section_data (section
)->u
.tdata
;
10474 c
= bfd_zalloc (abfd
, section
->size
);
10477 mips_elf_section_data (section
)->u
.tdata
= c
;
10480 memcpy (c
+ offset
, location
, count
);
10483 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
10487 /* This is almost identical to bfd_generic_get_... except that some
10488 MIPS relocations need to be handled specially. Sigh. */
10491 _bfd_elf_mips_get_relocated_section_contents
10493 struct bfd_link_info
*link_info
,
10494 struct bfd_link_order
*link_order
,
10496 bfd_boolean relocatable
,
10499 /* Get enough memory to hold the stuff */
10500 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
10501 asection
*input_section
= link_order
->u
.indirect
.section
;
10504 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
10505 arelent
**reloc_vector
= NULL
;
10508 if (reloc_size
< 0)
10511 reloc_vector
= bfd_malloc (reloc_size
);
10512 if (reloc_vector
== NULL
&& reloc_size
!= 0)
10515 /* read in the section */
10516 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
10517 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
10520 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
10524 if (reloc_count
< 0)
10527 if (reloc_count
> 0)
10532 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
10535 struct bfd_hash_entry
*h
;
10536 struct bfd_link_hash_entry
*lh
;
10537 /* Skip all this stuff if we aren't mixing formats. */
10538 if (abfd
&& input_bfd
10539 && abfd
->xvec
== input_bfd
->xvec
)
10543 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
10544 lh
= (struct bfd_link_hash_entry
*) h
;
10551 case bfd_link_hash_undefined
:
10552 case bfd_link_hash_undefweak
:
10553 case bfd_link_hash_common
:
10556 case bfd_link_hash_defined
:
10557 case bfd_link_hash_defweak
:
10559 gp
= lh
->u
.def
.value
;
10561 case bfd_link_hash_indirect
:
10562 case bfd_link_hash_warning
:
10564 /* @@FIXME ignoring warning for now */
10566 case bfd_link_hash_new
:
10575 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
10577 char *error_message
= NULL
;
10578 bfd_reloc_status_type r
;
10580 /* Specific to MIPS: Deal with relocation types that require
10581 knowing the gp of the output bfd. */
10582 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
10584 /* If we've managed to find the gp and have a special
10585 function for the relocation then go ahead, else default
10586 to the generic handling. */
10588 && (*parent
)->howto
->special_function
10589 == _bfd_mips_elf32_gprel16_reloc
)
10590 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
10591 input_section
, relocatable
,
10594 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
10596 relocatable
? abfd
: NULL
,
10601 asection
*os
= input_section
->output_section
;
10603 /* A partial link, so keep the relocs */
10604 os
->orelocation
[os
->reloc_count
] = *parent
;
10608 if (r
!= bfd_reloc_ok
)
10612 case bfd_reloc_undefined
:
10613 if (!((*link_info
->callbacks
->undefined_symbol
)
10614 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
10615 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
10618 case bfd_reloc_dangerous
:
10619 BFD_ASSERT (error_message
!= NULL
);
10620 if (!((*link_info
->callbacks
->reloc_dangerous
)
10621 (link_info
, error_message
, input_bfd
, input_section
,
10622 (*parent
)->address
)))
10625 case bfd_reloc_overflow
:
10626 if (!((*link_info
->callbacks
->reloc_overflow
)
10628 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
10629 (*parent
)->howto
->name
, (*parent
)->addend
,
10630 input_bfd
, input_section
, (*parent
)->address
)))
10633 case bfd_reloc_outofrange
:
10642 if (reloc_vector
!= NULL
)
10643 free (reloc_vector
);
10647 if (reloc_vector
!= NULL
)
10648 free (reloc_vector
);
10652 /* Create a MIPS ELF linker hash table. */
10654 struct bfd_link_hash_table
*
10655 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
10657 struct mips_elf_link_hash_table
*ret
;
10658 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
10660 ret
= bfd_malloc (amt
);
10664 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
10665 mips_elf_link_hash_newfunc
,
10666 sizeof (struct mips_elf_link_hash_entry
)))
10673 /* We no longer use this. */
10674 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
10675 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
10677 ret
->procedure_count
= 0;
10678 ret
->compact_rel_size
= 0;
10679 ret
->use_rld_obj_head
= FALSE
;
10680 ret
->rld_value
= 0;
10681 ret
->mips16_stubs_seen
= FALSE
;
10682 ret
->is_vxworks
= FALSE
;
10683 ret
->small_data_overflow_reported
= FALSE
;
10684 ret
->srelbss
= NULL
;
10685 ret
->sdynbss
= NULL
;
10686 ret
->srelplt
= NULL
;
10687 ret
->srelplt2
= NULL
;
10688 ret
->sgotplt
= NULL
;
10690 ret
->sstubs
= NULL
;
10692 ret
->got_info
= NULL
;
10693 ret
->plt_header_size
= 0;
10694 ret
->plt_entry_size
= 0;
10695 ret
->lazy_stub_count
= 0;
10696 ret
->function_stub_size
= 0;
10698 return &ret
->root
.root
;
10701 /* Likewise, but indicate that the target is VxWorks. */
10703 struct bfd_link_hash_table
*
10704 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
10706 struct bfd_link_hash_table
*ret
;
10708 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
10711 struct mips_elf_link_hash_table
*htab
;
10713 htab
= (struct mips_elf_link_hash_table
*) ret
;
10714 htab
->is_vxworks
= 1;
10719 /* We need to use a special link routine to handle the .reginfo and
10720 the .mdebug sections. We need to merge all instances of these
10721 sections together, not write them all out sequentially. */
10724 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
10727 struct bfd_link_order
*p
;
10728 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
10729 asection
*rtproc_sec
;
10730 Elf32_RegInfo reginfo
;
10731 struct ecoff_debug_info debug
;
10732 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
10733 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
10734 HDRR
*symhdr
= &debug
.symbolic_header
;
10735 void *mdebug_handle
= NULL
;
10740 struct mips_elf_link_hash_table
*htab
;
10742 static const char * const secname
[] =
10744 ".text", ".init", ".fini", ".data",
10745 ".rodata", ".sdata", ".sbss", ".bss"
10747 static const int sc
[] =
10749 scText
, scInit
, scFini
, scData
,
10750 scRData
, scSData
, scSBss
, scBss
10753 /* Sort the dynamic symbols so that those with GOT entries come after
10755 htab
= mips_elf_hash_table (info
);
10756 if (!mips_elf_sort_hash_table (abfd
, info
))
10759 /* Get a value for the GP register. */
10760 if (elf_gp (abfd
) == 0)
10762 struct bfd_link_hash_entry
*h
;
10764 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
10765 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
10766 elf_gp (abfd
) = (h
->u
.def
.value
10767 + h
->u
.def
.section
->output_section
->vma
10768 + h
->u
.def
.section
->output_offset
);
10769 else if (htab
->is_vxworks
10770 && (h
= bfd_link_hash_lookup (info
->hash
,
10771 "_GLOBAL_OFFSET_TABLE_",
10772 FALSE
, FALSE
, TRUE
))
10773 && h
->type
== bfd_link_hash_defined
)
10774 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
10775 + h
->u
.def
.section
->output_offset
10777 else if (info
->relocatable
)
10779 bfd_vma lo
= MINUS_ONE
;
10781 /* Find the GP-relative section with the lowest offset. */
10782 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10784 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
10787 /* And calculate GP relative to that. */
10788 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
10792 /* If the relocate_section function needs to do a reloc
10793 involving the GP value, it should make a reloc_dangerous
10794 callback to warn that GP is not defined. */
10798 /* Go through the sections and collect the .reginfo and .mdebug
10800 reginfo_sec
= NULL
;
10802 gptab_data_sec
= NULL
;
10803 gptab_bss_sec
= NULL
;
10804 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10806 if (strcmp (o
->name
, ".reginfo") == 0)
10808 memset (®info
, 0, sizeof reginfo
);
10810 /* We have found the .reginfo section in the output file.
10811 Look through all the link_orders comprising it and merge
10812 the information together. */
10813 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10815 asection
*input_section
;
10817 Elf32_External_RegInfo ext
;
10820 if (p
->type
!= bfd_indirect_link_order
)
10822 if (p
->type
== bfd_data_link_order
)
10827 input_section
= p
->u
.indirect
.section
;
10828 input_bfd
= input_section
->owner
;
10830 if (! bfd_get_section_contents (input_bfd
, input_section
,
10831 &ext
, 0, sizeof ext
))
10834 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
10836 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
10837 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
10838 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
10839 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
10840 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
10842 /* ri_gp_value is set by the function
10843 mips_elf32_section_processing when the section is
10844 finally written out. */
10846 /* Hack: reset the SEC_HAS_CONTENTS flag so that
10847 elf_link_input_bfd ignores this section. */
10848 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
10851 /* Size has been set in _bfd_mips_elf_always_size_sections. */
10852 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
10854 /* Skip this section later on (I don't think this currently
10855 matters, but someday it might). */
10856 o
->map_head
.link_order
= NULL
;
10861 if (strcmp (o
->name
, ".mdebug") == 0)
10863 struct extsym_info einfo
;
10866 /* We have found the .mdebug section in the output file.
10867 Look through all the link_orders comprising it and merge
10868 the information together. */
10869 symhdr
->magic
= swap
->sym_magic
;
10870 /* FIXME: What should the version stamp be? */
10871 symhdr
->vstamp
= 0;
10872 symhdr
->ilineMax
= 0;
10873 symhdr
->cbLine
= 0;
10874 symhdr
->idnMax
= 0;
10875 symhdr
->ipdMax
= 0;
10876 symhdr
->isymMax
= 0;
10877 symhdr
->ioptMax
= 0;
10878 symhdr
->iauxMax
= 0;
10879 symhdr
->issMax
= 0;
10880 symhdr
->issExtMax
= 0;
10881 symhdr
->ifdMax
= 0;
10883 symhdr
->iextMax
= 0;
10885 /* We accumulate the debugging information itself in the
10886 debug_info structure. */
10888 debug
.external_dnr
= NULL
;
10889 debug
.external_pdr
= NULL
;
10890 debug
.external_sym
= NULL
;
10891 debug
.external_opt
= NULL
;
10892 debug
.external_aux
= NULL
;
10894 debug
.ssext
= debug
.ssext_end
= NULL
;
10895 debug
.external_fdr
= NULL
;
10896 debug
.external_rfd
= NULL
;
10897 debug
.external_ext
= debug
.external_ext_end
= NULL
;
10899 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
10900 if (mdebug_handle
== NULL
)
10904 esym
.cobol_main
= 0;
10908 esym
.asym
.iss
= issNil
;
10909 esym
.asym
.st
= stLocal
;
10910 esym
.asym
.reserved
= 0;
10911 esym
.asym
.index
= indexNil
;
10913 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
10915 esym
.asym
.sc
= sc
[i
];
10916 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
10919 esym
.asym
.value
= s
->vma
;
10920 last
= s
->vma
+ s
->size
;
10923 esym
.asym
.value
= last
;
10924 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
10925 secname
[i
], &esym
))
10929 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10931 asection
*input_section
;
10933 const struct ecoff_debug_swap
*input_swap
;
10934 struct ecoff_debug_info input_debug
;
10938 if (p
->type
!= bfd_indirect_link_order
)
10940 if (p
->type
== bfd_data_link_order
)
10945 input_section
= p
->u
.indirect
.section
;
10946 input_bfd
= input_section
->owner
;
10948 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
10949 || (get_elf_backend_data (input_bfd
)
10950 ->elf_backend_ecoff_debug_swap
) == NULL
)
10952 /* I don't know what a non MIPS ELF bfd would be
10953 doing with a .mdebug section, but I don't really
10954 want to deal with it. */
10958 input_swap
= (get_elf_backend_data (input_bfd
)
10959 ->elf_backend_ecoff_debug_swap
);
10961 BFD_ASSERT (p
->size
== input_section
->size
);
10963 /* The ECOFF linking code expects that we have already
10964 read in the debugging information and set up an
10965 ecoff_debug_info structure, so we do that now. */
10966 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
10970 if (! (bfd_ecoff_debug_accumulate
10971 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
10972 &input_debug
, input_swap
, info
)))
10975 /* Loop through the external symbols. For each one with
10976 interesting information, try to find the symbol in
10977 the linker global hash table and save the information
10978 for the output external symbols. */
10979 eraw_src
= input_debug
.external_ext
;
10980 eraw_end
= (eraw_src
10981 + (input_debug
.symbolic_header
.iextMax
10982 * input_swap
->external_ext_size
));
10984 eraw_src
< eraw_end
;
10985 eraw_src
+= input_swap
->external_ext_size
)
10989 struct mips_elf_link_hash_entry
*h
;
10991 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
10992 if (ext
.asym
.sc
== scNil
10993 || ext
.asym
.sc
== scUndefined
10994 || ext
.asym
.sc
== scSUndefined
)
10997 name
= input_debug
.ssext
+ ext
.asym
.iss
;
10998 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
10999 name
, FALSE
, FALSE
, TRUE
);
11000 if (h
== NULL
|| h
->esym
.ifd
!= -2)
11005 BFD_ASSERT (ext
.ifd
11006 < input_debug
.symbolic_header
.ifdMax
);
11007 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
11013 /* Free up the information we just read. */
11014 free (input_debug
.line
);
11015 free (input_debug
.external_dnr
);
11016 free (input_debug
.external_pdr
);
11017 free (input_debug
.external_sym
);
11018 free (input_debug
.external_opt
);
11019 free (input_debug
.external_aux
);
11020 free (input_debug
.ss
);
11021 free (input_debug
.ssext
);
11022 free (input_debug
.external_fdr
);
11023 free (input_debug
.external_rfd
);
11024 free (input_debug
.external_ext
);
11026 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11027 elf_link_input_bfd ignores this section. */
11028 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11031 if (SGI_COMPAT (abfd
) && info
->shared
)
11033 /* Create .rtproc section. */
11034 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11035 if (rtproc_sec
== NULL
)
11037 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
11038 | SEC_LINKER_CREATED
| SEC_READONLY
);
11040 rtproc_sec
= bfd_make_section_with_flags (abfd
,
11043 if (rtproc_sec
== NULL
11044 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
11048 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
11054 /* Build the external symbol information. */
11057 einfo
.debug
= &debug
;
11059 einfo
.failed
= FALSE
;
11060 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
11061 mips_elf_output_extsym
, &einfo
);
11065 /* Set the size of the .mdebug section. */
11066 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
11068 /* Skip this section later on (I don't think this currently
11069 matters, but someday it might). */
11070 o
->map_head
.link_order
= NULL
;
11075 if (CONST_STRNEQ (o
->name
, ".gptab."))
11077 const char *subname
;
11080 Elf32_External_gptab
*ext_tab
;
11083 /* The .gptab.sdata and .gptab.sbss sections hold
11084 information describing how the small data area would
11085 change depending upon the -G switch. These sections
11086 not used in executables files. */
11087 if (! info
->relocatable
)
11089 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11091 asection
*input_section
;
11093 if (p
->type
!= bfd_indirect_link_order
)
11095 if (p
->type
== bfd_data_link_order
)
11100 input_section
= p
->u
.indirect
.section
;
11102 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11103 elf_link_input_bfd ignores this section. */
11104 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11107 /* Skip this section later on (I don't think this
11108 currently matters, but someday it might). */
11109 o
->map_head
.link_order
= NULL
;
11111 /* Really remove the section. */
11112 bfd_section_list_remove (abfd
, o
);
11113 --abfd
->section_count
;
11118 /* There is one gptab for initialized data, and one for
11119 uninitialized data. */
11120 if (strcmp (o
->name
, ".gptab.sdata") == 0)
11121 gptab_data_sec
= o
;
11122 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
11126 (*_bfd_error_handler
)
11127 (_("%s: illegal section name `%s'"),
11128 bfd_get_filename (abfd
), o
->name
);
11129 bfd_set_error (bfd_error_nonrepresentable_section
);
11133 /* The linker script always combines .gptab.data and
11134 .gptab.sdata into .gptab.sdata, and likewise for
11135 .gptab.bss and .gptab.sbss. It is possible that there is
11136 no .sdata or .sbss section in the output file, in which
11137 case we must change the name of the output section. */
11138 subname
= o
->name
+ sizeof ".gptab" - 1;
11139 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
11141 if (o
== gptab_data_sec
)
11142 o
->name
= ".gptab.data";
11144 o
->name
= ".gptab.bss";
11145 subname
= o
->name
+ sizeof ".gptab" - 1;
11146 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
11149 /* Set up the first entry. */
11151 amt
= c
* sizeof (Elf32_gptab
);
11152 tab
= bfd_malloc (amt
);
11155 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
11156 tab
[0].gt_header
.gt_unused
= 0;
11158 /* Combine the input sections. */
11159 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11161 asection
*input_section
;
11163 bfd_size_type size
;
11164 unsigned long last
;
11165 bfd_size_type gpentry
;
11167 if (p
->type
!= bfd_indirect_link_order
)
11169 if (p
->type
== bfd_data_link_order
)
11174 input_section
= p
->u
.indirect
.section
;
11175 input_bfd
= input_section
->owner
;
11177 /* Combine the gptab entries for this input section one
11178 by one. We know that the input gptab entries are
11179 sorted by ascending -G value. */
11180 size
= input_section
->size
;
11182 for (gpentry
= sizeof (Elf32_External_gptab
);
11184 gpentry
+= sizeof (Elf32_External_gptab
))
11186 Elf32_External_gptab ext_gptab
;
11187 Elf32_gptab int_gptab
;
11193 if (! (bfd_get_section_contents
11194 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
11195 sizeof (Elf32_External_gptab
))))
11201 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
11203 val
= int_gptab
.gt_entry
.gt_g_value
;
11204 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
11207 for (look
= 1; look
< c
; look
++)
11209 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
11210 tab
[look
].gt_entry
.gt_bytes
+= add
;
11212 if (tab
[look
].gt_entry
.gt_g_value
== val
)
11218 Elf32_gptab
*new_tab
;
11221 /* We need a new table entry. */
11222 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
11223 new_tab
= bfd_realloc (tab
, amt
);
11224 if (new_tab
== NULL
)
11230 tab
[c
].gt_entry
.gt_g_value
= val
;
11231 tab
[c
].gt_entry
.gt_bytes
= add
;
11233 /* Merge in the size for the next smallest -G
11234 value, since that will be implied by this new
11237 for (look
= 1; look
< c
; look
++)
11239 if (tab
[look
].gt_entry
.gt_g_value
< val
11241 || (tab
[look
].gt_entry
.gt_g_value
11242 > tab
[max
].gt_entry
.gt_g_value
)))
11246 tab
[c
].gt_entry
.gt_bytes
+=
11247 tab
[max
].gt_entry
.gt_bytes
;
11252 last
= int_gptab
.gt_entry
.gt_bytes
;
11255 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11256 elf_link_input_bfd ignores this section. */
11257 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11260 /* The table must be sorted by -G value. */
11262 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
11264 /* Swap out the table. */
11265 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
11266 ext_tab
= bfd_alloc (abfd
, amt
);
11267 if (ext_tab
== NULL
)
11273 for (j
= 0; j
< c
; j
++)
11274 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
11277 o
->size
= c
* sizeof (Elf32_External_gptab
);
11278 o
->contents
= (bfd_byte
*) ext_tab
;
11280 /* Skip this section later on (I don't think this currently
11281 matters, but someday it might). */
11282 o
->map_head
.link_order
= NULL
;
11286 /* Invoke the regular ELF backend linker to do all the work. */
11287 if (!bfd_elf_final_link (abfd
, info
))
11290 /* Now write out the computed sections. */
11292 if (reginfo_sec
!= NULL
)
11294 Elf32_External_RegInfo ext
;
11296 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
11297 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
11301 if (mdebug_sec
!= NULL
)
11303 BFD_ASSERT (abfd
->output_has_begun
);
11304 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
11306 mdebug_sec
->filepos
))
11309 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
11312 if (gptab_data_sec
!= NULL
)
11314 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
11315 gptab_data_sec
->contents
,
11316 0, gptab_data_sec
->size
))
11320 if (gptab_bss_sec
!= NULL
)
11322 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
11323 gptab_bss_sec
->contents
,
11324 0, gptab_bss_sec
->size
))
11328 if (SGI_COMPAT (abfd
))
11330 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11331 if (rtproc_sec
!= NULL
)
11333 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
11334 rtproc_sec
->contents
,
11335 0, rtproc_sec
->size
))
11343 /* Structure for saying that BFD machine EXTENSION extends BASE. */
11345 struct mips_mach_extension
{
11346 unsigned long extension
, base
;
11350 /* An array describing how BFD machines relate to one another. The entries
11351 are ordered topologically with MIPS I extensions listed last. */
11353 static const struct mips_mach_extension mips_mach_extensions
[] = {
11354 /* MIPS64r2 extensions. */
11355 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
11357 /* MIPS64 extensions. */
11358 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
11359 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
11361 /* MIPS V extensions. */
11362 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
11364 /* R10000 extensions. */
11365 { bfd_mach_mips12000
, bfd_mach_mips10000
},
11367 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
11368 vr5400 ISA, but doesn't include the multimedia stuff. It seems
11369 better to allow vr5400 and vr5500 code to be merged anyway, since
11370 many libraries will just use the core ISA. Perhaps we could add
11371 some sort of ASE flag if this ever proves a problem. */
11372 { bfd_mach_mips5500
, bfd_mach_mips5400
},
11373 { bfd_mach_mips5400
, bfd_mach_mips5000
},
11375 /* MIPS IV extensions. */
11376 { bfd_mach_mips5
, bfd_mach_mips8000
},
11377 { bfd_mach_mips10000
, bfd_mach_mips8000
},
11378 { bfd_mach_mips5000
, bfd_mach_mips8000
},
11379 { bfd_mach_mips7000
, bfd_mach_mips8000
},
11380 { bfd_mach_mips9000
, bfd_mach_mips8000
},
11382 /* VR4100 extensions. */
11383 { bfd_mach_mips4120
, bfd_mach_mips4100
},
11384 { bfd_mach_mips4111
, bfd_mach_mips4100
},
11386 /* MIPS III extensions. */
11387 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
11388 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
11389 { bfd_mach_mips8000
, bfd_mach_mips4000
},
11390 { bfd_mach_mips4650
, bfd_mach_mips4000
},
11391 { bfd_mach_mips4600
, bfd_mach_mips4000
},
11392 { bfd_mach_mips4400
, bfd_mach_mips4000
},
11393 { bfd_mach_mips4300
, bfd_mach_mips4000
},
11394 { bfd_mach_mips4100
, bfd_mach_mips4000
},
11395 { bfd_mach_mips4010
, bfd_mach_mips4000
},
11397 /* MIPS32 extensions. */
11398 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
11400 /* MIPS II extensions. */
11401 { bfd_mach_mips4000
, bfd_mach_mips6000
},
11402 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
11404 /* MIPS I extensions. */
11405 { bfd_mach_mips6000
, bfd_mach_mips3000
},
11406 { bfd_mach_mips3900
, bfd_mach_mips3000
}
11410 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
11413 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
11417 if (extension
== base
)
11420 if (base
== bfd_mach_mipsisa32
11421 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
11424 if (base
== bfd_mach_mipsisa32r2
11425 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
11428 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
11429 if (extension
== mips_mach_extensions
[i
].extension
)
11431 extension
= mips_mach_extensions
[i
].base
;
11432 if (extension
== base
)
11440 /* Return true if the given ELF header flags describe a 32-bit binary. */
11443 mips_32bit_flags_p (flagword flags
)
11445 return ((flags
& EF_MIPS_32BITMODE
) != 0
11446 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
11447 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
11448 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
11449 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
11450 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
11451 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
11455 /* Merge object attributes from IBFD into OBFD. Raise an error if
11456 there are conflicting attributes. */
11458 mips_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
11460 obj_attribute
*in_attr
;
11461 obj_attribute
*out_attr
;
11463 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
11465 /* This is the first object. Copy the attributes. */
11466 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
11468 /* Use the Tag_null value to indicate the attributes have been
11470 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
11475 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
11476 non-conflicting ones. */
11477 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
11478 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
11479 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11481 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
11482 if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
11483 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
11484 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
11486 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
11488 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
11489 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
11490 else if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
11492 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
11493 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
11495 switch (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11498 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11502 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
11508 (_("Warning: %B uses hard float, %B uses soft float"),
11514 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
11524 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11528 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
11534 (_("Warning: %B uses hard float, %B uses soft float"),
11540 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
11550 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11556 (_("Warning: %B uses hard float, %B uses soft float"),
11566 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
11570 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
11576 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
11582 (_("Warning: %B uses hard float, %B uses soft float"),
11596 /* Merge Tag_compatibility attributes and any common GNU ones. */
11597 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
11602 /* Merge backend specific data from an object file to the output
11603 object file when linking. */
11606 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
11608 flagword old_flags
;
11609 flagword new_flags
;
11611 bfd_boolean null_input_bfd
= TRUE
;
11614 /* Check if we have the same endianess */
11615 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
11617 (*_bfd_error_handler
)
11618 (_("%B: endianness incompatible with that of the selected emulation"),
11623 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
11624 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
11627 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
11629 (*_bfd_error_handler
)
11630 (_("%B: ABI is incompatible with that of the selected emulation"),
11635 if (!mips_elf_merge_obj_attributes (ibfd
, obfd
))
11638 new_flags
= elf_elfheader (ibfd
)->e_flags
;
11639 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
11640 old_flags
= elf_elfheader (obfd
)->e_flags
;
11642 if (! elf_flags_init (obfd
))
11644 elf_flags_init (obfd
) = TRUE
;
11645 elf_elfheader (obfd
)->e_flags
= new_flags
;
11646 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
11647 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
11649 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
11650 && (bfd_get_arch_info (obfd
)->the_default
11651 || mips_mach_extends_p (bfd_get_mach (obfd
),
11652 bfd_get_mach (ibfd
))))
11654 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
11655 bfd_get_mach (ibfd
)))
11662 /* Check flag compatibility. */
11664 new_flags
&= ~EF_MIPS_NOREORDER
;
11665 old_flags
&= ~EF_MIPS_NOREORDER
;
11667 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
11668 doesn't seem to matter. */
11669 new_flags
&= ~EF_MIPS_XGOT
;
11670 old_flags
&= ~EF_MIPS_XGOT
;
11672 /* MIPSpro generates ucode info in n64 objects. Again, we should
11673 just be able to ignore this. */
11674 new_flags
&= ~EF_MIPS_UCODE
;
11675 old_flags
&= ~EF_MIPS_UCODE
;
11677 /* Don't care about the PIC flags from dynamic objects; they are
11679 if ((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0
11680 && (ibfd
->flags
& DYNAMIC
) != 0)
11681 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11683 if (new_flags
== old_flags
)
11686 /* Check to see if the input BFD actually contains any sections.
11687 If not, its flags may not have been initialised either, but it cannot
11688 actually cause any incompatibility. */
11689 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
11691 /* Ignore synthetic sections and empty .text, .data and .bss sections
11692 which are automatically generated by gas. */
11693 if (strcmp (sec
->name
, ".reginfo")
11694 && strcmp (sec
->name
, ".mdebug")
11696 || (strcmp (sec
->name
, ".text")
11697 && strcmp (sec
->name
, ".data")
11698 && strcmp (sec
->name
, ".bss"))))
11700 null_input_bfd
= FALSE
;
11704 if (null_input_bfd
)
11709 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
11710 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
11712 (*_bfd_error_handler
)
11713 (_("%B: warning: linking PIC files with non-PIC files"),
11718 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
11719 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
11720 if (! (new_flags
& EF_MIPS_PIC
))
11721 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
11723 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11724 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
11726 /* Compare the ISAs. */
11727 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
11729 (*_bfd_error_handler
)
11730 (_("%B: linking 32-bit code with 64-bit code"),
11734 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
11736 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
11737 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
11739 /* Copy the architecture info from IBFD to OBFD. Also copy
11740 the 32-bit flag (if set) so that we continue to recognise
11741 OBFD as a 32-bit binary. */
11742 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
11743 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
11744 elf_elfheader (obfd
)->e_flags
11745 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11747 /* Copy across the ABI flags if OBFD doesn't use them
11748 and if that was what caused us to treat IBFD as 32-bit. */
11749 if ((old_flags
& EF_MIPS_ABI
) == 0
11750 && mips_32bit_flags_p (new_flags
)
11751 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
11752 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
11756 /* The ISAs aren't compatible. */
11757 (*_bfd_error_handler
)
11758 (_("%B: linking %s module with previous %s modules"),
11760 bfd_printable_name (ibfd
),
11761 bfd_printable_name (obfd
));
11766 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11767 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
11769 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
11770 does set EI_CLASS differently from any 32-bit ABI. */
11771 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
11772 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
11773 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
11775 /* Only error if both are set (to different values). */
11776 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
11777 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
11778 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
11780 (*_bfd_error_handler
)
11781 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
11783 elf_mips_abi_name (ibfd
),
11784 elf_mips_abi_name (obfd
));
11787 new_flags
&= ~EF_MIPS_ABI
;
11788 old_flags
&= ~EF_MIPS_ABI
;
11791 /* For now, allow arbitrary mixing of ASEs (retain the union). */
11792 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
11794 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
11796 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
11797 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
11800 /* Warn about any other mismatches */
11801 if (new_flags
!= old_flags
)
11803 (*_bfd_error_handler
)
11804 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
11805 ibfd
, (unsigned long) new_flags
,
11806 (unsigned long) old_flags
);
11812 bfd_set_error (bfd_error_bad_value
);
11819 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
11822 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
11824 BFD_ASSERT (!elf_flags_init (abfd
)
11825 || elf_elfheader (abfd
)->e_flags
== flags
);
11827 elf_elfheader (abfd
)->e_flags
= flags
;
11828 elf_flags_init (abfd
) = TRUE
;
11833 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
11837 default: return "";
11838 case DT_MIPS_RLD_VERSION
:
11839 return "MIPS_RLD_VERSION";
11840 case DT_MIPS_TIME_STAMP
:
11841 return "MIPS_TIME_STAMP";
11842 case DT_MIPS_ICHECKSUM
:
11843 return "MIPS_ICHECKSUM";
11844 case DT_MIPS_IVERSION
:
11845 return "MIPS_IVERSION";
11846 case DT_MIPS_FLAGS
:
11847 return "MIPS_FLAGS";
11848 case DT_MIPS_BASE_ADDRESS
:
11849 return "MIPS_BASE_ADDRESS";
11851 return "MIPS_MSYM";
11852 case DT_MIPS_CONFLICT
:
11853 return "MIPS_CONFLICT";
11854 case DT_MIPS_LIBLIST
:
11855 return "MIPS_LIBLIST";
11856 case DT_MIPS_LOCAL_GOTNO
:
11857 return "MIPS_LOCAL_GOTNO";
11858 case DT_MIPS_CONFLICTNO
:
11859 return "MIPS_CONFLICTNO";
11860 case DT_MIPS_LIBLISTNO
:
11861 return "MIPS_LIBLISTNO";
11862 case DT_MIPS_SYMTABNO
:
11863 return "MIPS_SYMTABNO";
11864 case DT_MIPS_UNREFEXTNO
:
11865 return "MIPS_UNREFEXTNO";
11866 case DT_MIPS_GOTSYM
:
11867 return "MIPS_GOTSYM";
11868 case DT_MIPS_HIPAGENO
:
11869 return "MIPS_HIPAGENO";
11870 case DT_MIPS_RLD_MAP
:
11871 return "MIPS_RLD_MAP";
11872 case DT_MIPS_DELTA_CLASS
:
11873 return "MIPS_DELTA_CLASS";
11874 case DT_MIPS_DELTA_CLASS_NO
:
11875 return "MIPS_DELTA_CLASS_NO";
11876 case DT_MIPS_DELTA_INSTANCE
:
11877 return "MIPS_DELTA_INSTANCE";
11878 case DT_MIPS_DELTA_INSTANCE_NO
:
11879 return "MIPS_DELTA_INSTANCE_NO";
11880 case DT_MIPS_DELTA_RELOC
:
11881 return "MIPS_DELTA_RELOC";
11882 case DT_MIPS_DELTA_RELOC_NO
:
11883 return "MIPS_DELTA_RELOC_NO";
11884 case DT_MIPS_DELTA_SYM
:
11885 return "MIPS_DELTA_SYM";
11886 case DT_MIPS_DELTA_SYM_NO
:
11887 return "MIPS_DELTA_SYM_NO";
11888 case DT_MIPS_DELTA_CLASSSYM
:
11889 return "MIPS_DELTA_CLASSSYM";
11890 case DT_MIPS_DELTA_CLASSSYM_NO
:
11891 return "MIPS_DELTA_CLASSSYM_NO";
11892 case DT_MIPS_CXX_FLAGS
:
11893 return "MIPS_CXX_FLAGS";
11894 case DT_MIPS_PIXIE_INIT
:
11895 return "MIPS_PIXIE_INIT";
11896 case DT_MIPS_SYMBOL_LIB
:
11897 return "MIPS_SYMBOL_LIB";
11898 case DT_MIPS_LOCALPAGE_GOTIDX
:
11899 return "MIPS_LOCALPAGE_GOTIDX";
11900 case DT_MIPS_LOCAL_GOTIDX
:
11901 return "MIPS_LOCAL_GOTIDX";
11902 case DT_MIPS_HIDDEN_GOTIDX
:
11903 return "MIPS_HIDDEN_GOTIDX";
11904 case DT_MIPS_PROTECTED_GOTIDX
:
11905 return "MIPS_PROTECTED_GOT_IDX";
11906 case DT_MIPS_OPTIONS
:
11907 return "MIPS_OPTIONS";
11908 case DT_MIPS_INTERFACE
:
11909 return "MIPS_INTERFACE";
11910 case DT_MIPS_DYNSTR_ALIGN
:
11911 return "DT_MIPS_DYNSTR_ALIGN";
11912 case DT_MIPS_INTERFACE_SIZE
:
11913 return "DT_MIPS_INTERFACE_SIZE";
11914 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
11915 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
11916 case DT_MIPS_PERF_SUFFIX
:
11917 return "DT_MIPS_PERF_SUFFIX";
11918 case DT_MIPS_COMPACT_SIZE
:
11919 return "DT_MIPS_COMPACT_SIZE";
11920 case DT_MIPS_GP_VALUE
:
11921 return "DT_MIPS_GP_VALUE";
11922 case DT_MIPS_AUX_DYNAMIC
:
11923 return "DT_MIPS_AUX_DYNAMIC";
11928 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
11932 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
11934 /* Print normal ELF private data. */
11935 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
11937 /* xgettext:c-format */
11938 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
11940 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
11941 fprintf (file
, _(" [abi=O32]"));
11942 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
11943 fprintf (file
, _(" [abi=O64]"));
11944 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
11945 fprintf (file
, _(" [abi=EABI32]"));
11946 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
11947 fprintf (file
, _(" [abi=EABI64]"));
11948 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
11949 fprintf (file
, _(" [abi unknown]"));
11950 else if (ABI_N32_P (abfd
))
11951 fprintf (file
, _(" [abi=N32]"));
11952 else if (ABI_64_P (abfd
))
11953 fprintf (file
, _(" [abi=64]"));
11955 fprintf (file
, _(" [no abi set]"));
11957 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
11958 fprintf (file
, " [mips1]");
11959 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
11960 fprintf (file
, " [mips2]");
11961 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
11962 fprintf (file
, " [mips3]");
11963 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
11964 fprintf (file
, " [mips4]");
11965 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
11966 fprintf (file
, " [mips5]");
11967 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
11968 fprintf (file
, " [mips32]");
11969 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
11970 fprintf (file
, " [mips64]");
11971 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
11972 fprintf (file
, " [mips32r2]");
11973 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
11974 fprintf (file
, " [mips64r2]");
11976 fprintf (file
, _(" [unknown ISA]"));
11978 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
11979 fprintf (file
, " [mdmx]");
11981 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
11982 fprintf (file
, " [mips16]");
11984 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
11985 fprintf (file
, " [32bitmode]");
11987 fprintf (file
, _(" [not 32bitmode]"));
11989 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
11990 fprintf (file
, " [noreorder]");
11992 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
11993 fprintf (file
, " [PIC]");
11995 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
11996 fprintf (file
, " [CPIC]");
11998 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
11999 fprintf (file
, " [XGOT]");
12001 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
12002 fprintf (file
, " [UCODE]");
12004 fputc ('\n', file
);
12009 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
12011 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12012 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12013 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
12014 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12015 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12016 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
12017 { NULL
, 0, 0, 0, 0 }
12020 /* Merge non visibility st_other attributes. Ensure that the
12021 STO_OPTIONAL flag is copied into h->other, even if this is not a
12022 definiton of the symbol. */
12024 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
12025 const Elf_Internal_Sym
*isym
,
12026 bfd_boolean definition
,
12027 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
12029 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
12031 unsigned char other
;
12033 other
= (definition
? isym
->st_other
: h
->other
);
12034 other
&= ~ELF_ST_VISIBILITY (-1);
12035 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
12039 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
12040 h
->other
|= STO_OPTIONAL
;
12043 /* Decide whether an undefined symbol is special and can be ignored.
12044 This is the case for OPTIONAL symbols on IRIX. */
12046 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
12048 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
12052 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
12054 return (sym
->st_shndx
== SHN_COMMON
12055 || sym
->st_shndx
== SHN_MIPS_ACOMMON
12056 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);