1 /* MIPS-specific support for ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006 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 2 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, MA 02110-1301, USA. */
28 /* This file handles functionality common to the different MIPS ABI's. */
33 #include "libiberty.h"
35 #include "elfxx-mips.h"
37 #include "elf-vxworks.h"
39 /* Get the ECOFF swapping routines. */
41 #include "coff/symconst.h"
42 #include "coff/ecoff.h"
43 #include "coff/mips.h"
47 /* This structure is used to hold .got entries while estimating got
51 /* The input bfd in which the symbol is defined. */
53 /* The index of the symbol, as stored in the relocation r_info, if
54 we have a local symbol; -1 otherwise. */
58 /* If abfd == NULL, an address that must be stored in the got. */
60 /* If abfd != NULL && symndx != -1, the addend of the relocation
61 that should be added to the symbol value. */
63 /* If abfd != NULL && symndx == -1, the hash table entry
64 corresponding to a global symbol in the got (or, local, if
66 struct mips_elf_link_hash_entry
*h
;
69 /* The TLS types included in this GOT entry (specifically, GD and
70 IE). The GD and IE flags can be added as we encounter new
71 relocations. LDM can also be set; it will always be alone, not
72 combined with any GD or IE flags. An LDM GOT entry will be
73 a local symbol entry with r_symndx == 0. */
74 unsigned char tls_type
;
76 /* The offset from the beginning of the .got section to the entry
77 corresponding to this symbol+addend. If it's a global symbol
78 whose offset is yet to be decided, it's going to be -1. */
82 /* This structure is used to hold .got information when linking. */
86 /* The global symbol in the GOT with the lowest index in the dynamic
88 struct elf_link_hash_entry
*global_gotsym
;
89 /* The number of global .got entries. */
90 unsigned int global_gotno
;
91 /* The number of .got slots used for TLS. */
92 unsigned int tls_gotno
;
93 /* The first unused TLS .got entry. Used only during
94 mips_elf_initialize_tls_index. */
95 unsigned int tls_assigned_gotno
;
96 /* The number of local .got entries. */
97 unsigned int local_gotno
;
98 /* The number of local .got entries we have used. */
99 unsigned int assigned_gotno
;
100 /* A hash table holding members of the got. */
101 struct htab
*got_entries
;
102 /* A hash table mapping input bfds to other mips_got_info. NULL
103 unless multi-got was necessary. */
104 struct htab
*bfd2got
;
105 /* In multi-got links, a pointer to the next got (err, rather, most
106 of the time, it points to the previous got). */
107 struct mips_got_info
*next
;
108 /* This is the GOT index of the TLS LDM entry for the GOT, MINUS_ONE
109 for none, or MINUS_TWO for not yet assigned. This is needed
110 because a single-GOT link may have multiple hash table entries
111 for the LDM. It does not get initialized in multi-GOT mode. */
112 bfd_vma tls_ldm_offset
;
115 /* Map an input bfd to a got in a multi-got link. */
117 struct mips_elf_bfd2got_hash
{
119 struct mips_got_info
*g
;
122 /* Structure passed when traversing the bfd2got hash table, used to
123 create and merge bfd's gots. */
125 struct mips_elf_got_per_bfd_arg
127 /* A hashtable that maps bfds to gots. */
129 /* The output bfd. */
131 /* The link information. */
132 struct bfd_link_info
*info
;
133 /* A pointer to the primary got, i.e., the one that's going to get
134 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
136 struct mips_got_info
*primary
;
137 /* A non-primary got we're trying to merge with other input bfd's
139 struct mips_got_info
*current
;
140 /* The maximum number of got entries that can be addressed with a
142 unsigned int max_count
;
143 /* The number of local and global entries in the primary got. */
144 unsigned int primary_count
;
145 /* The number of local and global entries in the current got. */
146 unsigned int current_count
;
147 /* The total number of global entries which will live in the
148 primary got and be automatically relocated. This includes
149 those not referenced by the primary GOT but included in
151 unsigned int global_count
;
154 /* Another structure used to pass arguments for got entries traversal. */
156 struct mips_elf_set_global_got_offset_arg
158 struct mips_got_info
*g
;
160 unsigned int needed_relocs
;
161 struct bfd_link_info
*info
;
164 /* A structure used to count TLS relocations or GOT entries, for GOT
165 entry or ELF symbol table traversal. */
167 struct mips_elf_count_tls_arg
169 struct bfd_link_info
*info
;
173 struct _mips_elf_section_data
175 struct bfd_elf_section_data elf
;
178 struct mips_got_info
*got_info
;
183 #define mips_elf_section_data(sec) \
184 ((struct _mips_elf_section_data *) elf_section_data (sec))
186 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
187 the dynamic symbols. */
189 struct mips_elf_hash_sort_data
191 /* The symbol in the global GOT with the lowest dynamic symbol table
193 struct elf_link_hash_entry
*low
;
194 /* The least dynamic symbol table index corresponding to a non-TLS
195 symbol with a GOT entry. */
196 long min_got_dynindx
;
197 /* The greatest dynamic symbol table index corresponding to a symbol
198 with a GOT entry that is not referenced (e.g., a dynamic symbol
199 with dynamic relocations pointing to it from non-primary GOTs). */
200 long max_unref_got_dynindx
;
201 /* The greatest dynamic symbol table index not corresponding to a
202 symbol without a GOT entry. */
203 long max_non_got_dynindx
;
206 /* The MIPS ELF linker needs additional information for each symbol in
207 the global hash table. */
209 struct mips_elf_link_hash_entry
211 struct elf_link_hash_entry root
;
213 /* External symbol information. */
216 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
218 unsigned int possibly_dynamic_relocs
;
220 /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
221 a readonly section. */
222 bfd_boolean readonly_reloc
;
224 /* We must not create a stub for a symbol that has relocations
225 related to taking the function's address, i.e. any but
226 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
228 bfd_boolean no_fn_stub
;
230 /* If there is a stub that 32 bit functions should use to call this
231 16 bit function, this points to the section containing the stub. */
234 /* Whether we need the fn_stub; this is set if this symbol appears
235 in any relocs other than a 16 bit call. */
236 bfd_boolean need_fn_stub
;
238 /* If there is a stub that 16 bit functions should use to call this
239 32 bit function, this points to the section containing the stub. */
242 /* This is like the call_stub field, but it is used if the function
243 being called returns a floating point value. */
244 asection
*call_fp_stub
;
246 /* Are we forced local? This will only be set if we have converted
247 the initial global GOT entry to a local GOT entry. */
248 bfd_boolean forced_local
;
250 /* Are we referenced by some kind of relocation? */
251 bfd_boolean is_relocation_target
;
253 /* Are we referenced by branch relocations? */
254 bfd_boolean is_branch_target
;
258 #define GOT_TLS_LDM 2
260 #define GOT_TLS_OFFSET_DONE 0x40
261 #define GOT_TLS_DONE 0x80
262 unsigned char tls_type
;
263 /* This is only used in single-GOT mode; in multi-GOT mode there
264 is one mips_got_entry per GOT entry, so the offset is stored
265 there. In single-GOT mode there may be many mips_got_entry
266 structures all referring to the same GOT slot. It might be
267 possible to use root.got.offset instead, but that field is
268 overloaded already. */
269 bfd_vma tls_got_offset
;
272 /* MIPS ELF linker hash table. */
274 struct mips_elf_link_hash_table
276 struct elf_link_hash_table root
;
278 /* We no longer use this. */
279 /* String section indices for the dynamic section symbols. */
280 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
282 /* The number of .rtproc entries. */
283 bfd_size_type procedure_count
;
284 /* The size of the .compact_rel section (if SGI_COMPAT). */
285 bfd_size_type compact_rel_size
;
286 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
287 entry is set to the address of __rld_obj_head as in IRIX5. */
288 bfd_boolean use_rld_obj_head
;
289 /* This is the value of the __rld_map or __rld_obj_head symbol. */
291 /* This is set if we see any mips16 stub sections. */
292 bfd_boolean mips16_stubs_seen
;
293 /* True if we're generating code for VxWorks. */
294 bfd_boolean is_vxworks
;
295 /* Shortcuts to some dynamic sections, or NULL if they are not
303 /* The size of the PLT header in bytes (VxWorks only). */
304 bfd_vma plt_header_size
;
305 /* The size of a PLT entry in bytes (VxWorks only). */
306 bfd_vma plt_entry_size
;
309 #define TLS_RELOC_P(r_type) \
310 (r_type == R_MIPS_TLS_DTPMOD32 \
311 || r_type == R_MIPS_TLS_DTPMOD64 \
312 || r_type == R_MIPS_TLS_DTPREL32 \
313 || r_type == R_MIPS_TLS_DTPREL64 \
314 || r_type == R_MIPS_TLS_GD \
315 || r_type == R_MIPS_TLS_LDM \
316 || r_type == R_MIPS_TLS_DTPREL_HI16 \
317 || r_type == R_MIPS_TLS_DTPREL_LO16 \
318 || r_type == R_MIPS_TLS_GOTTPREL \
319 || r_type == R_MIPS_TLS_TPREL32 \
320 || r_type == R_MIPS_TLS_TPREL64 \
321 || r_type == R_MIPS_TLS_TPREL_HI16 \
322 || r_type == R_MIPS_TLS_TPREL_LO16)
324 /* Structure used to pass information to mips_elf_output_extsym. */
329 struct bfd_link_info
*info
;
330 struct ecoff_debug_info
*debug
;
331 const struct ecoff_debug_swap
*swap
;
335 /* The names of the runtime procedure table symbols used on IRIX5. */
337 static const char * const mips_elf_dynsym_rtproc_names
[] =
340 "_procedure_string_table",
341 "_procedure_table_size",
345 /* These structures are used to generate the .compact_rel section on
350 unsigned long id1
; /* Always one? */
351 unsigned long num
; /* Number of compact relocation entries. */
352 unsigned long id2
; /* Always two? */
353 unsigned long offset
; /* The file offset of the first relocation. */
354 unsigned long reserved0
; /* Zero? */
355 unsigned long reserved1
; /* Zero? */
364 bfd_byte reserved0
[4];
365 bfd_byte reserved1
[4];
366 } Elf32_External_compact_rel
;
370 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
371 unsigned int rtype
: 4; /* Relocation types. See below. */
372 unsigned int dist2to
: 8;
373 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
374 unsigned long konst
; /* KONST field. See below. */
375 unsigned long vaddr
; /* VADDR to be relocated. */
380 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
381 unsigned int rtype
: 4; /* Relocation types. See below. */
382 unsigned int dist2to
: 8;
383 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
384 unsigned long konst
; /* KONST field. See below. */
392 } Elf32_External_crinfo
;
398 } Elf32_External_crinfo2
;
400 /* These are the constants used to swap the bitfields in a crinfo. */
402 #define CRINFO_CTYPE (0x1)
403 #define CRINFO_CTYPE_SH (31)
404 #define CRINFO_RTYPE (0xf)
405 #define CRINFO_RTYPE_SH (27)
406 #define CRINFO_DIST2TO (0xff)
407 #define CRINFO_DIST2TO_SH (19)
408 #define CRINFO_RELVADDR (0x7ffff)
409 #define CRINFO_RELVADDR_SH (0)
411 /* A compact relocation info has long (3 words) or short (2 words)
412 formats. A short format doesn't have VADDR field and relvaddr
413 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
414 #define CRF_MIPS_LONG 1
415 #define CRF_MIPS_SHORT 0
417 /* There are 4 types of compact relocation at least. The value KONST
418 has different meaning for each type:
421 CT_MIPS_REL32 Address in data
422 CT_MIPS_WORD Address in word (XXX)
423 CT_MIPS_GPHI_LO GP - vaddr
424 CT_MIPS_JMPAD Address to jump
427 #define CRT_MIPS_REL32 0xa
428 #define CRT_MIPS_WORD 0xb
429 #define CRT_MIPS_GPHI_LO 0xc
430 #define CRT_MIPS_JMPAD 0xd
432 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
433 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
434 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
435 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
437 /* The structure of the runtime procedure descriptor created by the
438 loader for use by the static exception system. */
440 typedef struct runtime_pdr
{
441 bfd_vma adr
; /* Memory address of start of procedure. */
442 long regmask
; /* Save register mask. */
443 long regoffset
; /* Save register offset. */
444 long fregmask
; /* Save floating point register mask. */
445 long fregoffset
; /* Save floating point register offset. */
446 long frameoffset
; /* Frame size. */
447 short framereg
; /* Frame pointer register. */
448 short pcreg
; /* Offset or reg of return pc. */
449 long irpss
; /* Index into the runtime string table. */
451 struct exception_info
*exception_info
;/* Pointer to exception array. */
453 #define cbRPDR sizeof (RPDR)
454 #define rpdNil ((pRPDR) 0)
456 static struct mips_got_entry
*mips_elf_create_local_got_entry
457 (bfd
*, struct bfd_link_info
*, bfd
*, struct mips_got_info
*, asection
*,
458 asection
*, bfd_vma
, unsigned long, struct mips_elf_link_hash_entry
*, int);
459 static bfd_boolean mips_elf_sort_hash_table_f
460 (struct mips_elf_link_hash_entry
*, void *);
461 static bfd_vma mips_elf_high
463 static bfd_boolean mips_elf_stub_section_p
465 static bfd_boolean mips_elf_create_dynamic_relocation
466 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
467 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
468 bfd_vma
*, asection
*);
469 static hashval_t mips_elf_got_entry_hash
471 static bfd_vma mips_elf_adjust_gp
472 (bfd
*, struct mips_got_info
*, bfd
*);
473 static struct mips_got_info
*mips_elf_got_for_ibfd
474 (struct mips_got_info
*, bfd
*);
476 /* This will be used when we sort the dynamic relocation records. */
477 static bfd
*reldyn_sorting_bfd
;
479 /* Nonzero if ABFD is using the N32 ABI. */
480 #define ABI_N32_P(abfd) \
481 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
483 /* Nonzero if ABFD is using the N64 ABI. */
484 #define ABI_64_P(abfd) \
485 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
487 /* Nonzero if ABFD is using NewABI conventions. */
488 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
490 /* The IRIX compatibility level we are striving for. */
491 #define IRIX_COMPAT(abfd) \
492 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
494 /* Whether we are trying to be compatible with IRIX at all. */
495 #define SGI_COMPAT(abfd) \
496 (IRIX_COMPAT (abfd) != ict_none)
498 /* The name of the options section. */
499 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
500 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
502 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
503 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
504 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
505 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
507 /* The name of the stub section. */
508 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
510 /* The size of an external REL relocation. */
511 #define MIPS_ELF_REL_SIZE(abfd) \
512 (get_elf_backend_data (abfd)->s->sizeof_rel)
514 /* The size of an external RELA relocation. */
515 #define MIPS_ELF_RELA_SIZE(abfd) \
516 (get_elf_backend_data (abfd)->s->sizeof_rela)
518 /* The size of an external dynamic table entry. */
519 #define MIPS_ELF_DYN_SIZE(abfd) \
520 (get_elf_backend_data (abfd)->s->sizeof_dyn)
522 /* The size of a GOT entry. */
523 #define MIPS_ELF_GOT_SIZE(abfd) \
524 (get_elf_backend_data (abfd)->s->arch_size / 8)
526 /* The size of a symbol-table entry. */
527 #define MIPS_ELF_SYM_SIZE(abfd) \
528 (get_elf_backend_data (abfd)->s->sizeof_sym)
530 /* The default alignment for sections, as a power of two. */
531 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
532 (get_elf_backend_data (abfd)->s->log_file_align)
534 /* Get word-sized data. */
535 #define MIPS_ELF_GET_WORD(abfd, ptr) \
536 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
538 /* Put out word-sized data. */
539 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
541 ? bfd_put_64 (abfd, val, ptr) \
542 : bfd_put_32 (abfd, val, ptr))
544 /* Add a dynamic symbol table-entry. */
545 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
546 _bfd_elf_add_dynamic_entry (info, tag, val)
548 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
549 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
551 /* Determine whether the internal relocation of index REL_IDX is REL
552 (zero) or RELA (non-zero). The assumption is that, if there are
553 two relocation sections for this section, one of them is REL and
554 the other is RELA. If the index of the relocation we're testing is
555 in range for the first relocation section, check that the external
556 relocation size is that for RELA. It is also assumed that, if
557 rel_idx is not in range for the first section, and this first
558 section contains REL relocs, then the relocation is in the second
559 section, that is RELA. */
560 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
561 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
562 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
563 > (bfd_vma)(rel_idx)) \
564 == (elf_section_data (sec)->rel_hdr.sh_entsize \
565 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
566 : sizeof (Elf32_External_Rela))))
568 /* The name of the dynamic relocation section. */
569 #define MIPS_ELF_REL_DYN_NAME(INFO) \
570 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
572 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
573 from smaller values. Start with zero, widen, *then* decrement. */
574 #define MINUS_ONE (((bfd_vma)0) - 1)
575 #define MINUS_TWO (((bfd_vma)0) - 2)
577 /* The number of local .got entries we reserve. */
578 #define MIPS_RESERVED_GOTNO(INFO) \
579 (mips_elf_hash_table (INFO)->is_vxworks ? 3 : 2)
581 /* The offset of $gp from the beginning of the .got section. */
582 #define ELF_MIPS_GP_OFFSET(INFO) \
583 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
585 /* The maximum size of the GOT for it to be addressable using 16-bit
587 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
589 /* Instructions which appear in a stub. */
590 #define STUB_LW(abfd) \
592 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
593 : 0x8f998010)) /* lw t9,0x8010(gp) */
594 #define STUB_MOVE(abfd) \
596 ? 0x03e0782d /* daddu t7,ra */ \
597 : 0x03e07821)) /* addu t7,ra */
598 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
599 #define STUB_LI16(abfd) \
601 ? 0x64180000 /* daddiu t8,zero,0 */ \
602 : 0x24180000)) /* addiu t8,zero,0 */
603 #define MIPS_FUNCTION_STUB_SIZE (16)
605 /* The name of the dynamic interpreter. This is put in the .interp
608 #define ELF_DYNAMIC_INTERPRETER(abfd) \
609 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
610 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
611 : "/usr/lib/libc.so.1")
614 #define MNAME(bfd,pre,pos) \
615 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
616 #define ELF_R_SYM(bfd, i) \
617 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
618 #define ELF_R_TYPE(bfd, i) \
619 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
620 #define ELF_R_INFO(bfd, s, t) \
621 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
623 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
624 #define ELF_R_SYM(bfd, i) \
626 #define ELF_R_TYPE(bfd, i) \
628 #define ELF_R_INFO(bfd, s, t) \
629 (ELF32_R_INFO (s, t))
632 /* The mips16 compiler uses a couple of special sections to handle
633 floating point arguments.
635 Section names that look like .mips16.fn.FNNAME contain stubs that
636 copy floating point arguments from the fp regs to the gp regs and
637 then jump to FNNAME. If any 32 bit function calls FNNAME, the
638 call should be redirected to the stub instead. If no 32 bit
639 function calls FNNAME, the stub should be discarded. We need to
640 consider any reference to the function, not just a call, because
641 if the address of the function is taken we will need the stub,
642 since the address might be passed to a 32 bit function.
644 Section names that look like .mips16.call.FNNAME contain stubs
645 that copy floating point arguments from the gp regs to the fp
646 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
647 then any 16 bit function that calls FNNAME should be redirected
648 to the stub instead. If FNNAME is not a 32 bit function, the
649 stub should be discarded.
651 .mips16.call.fp.FNNAME sections are similar, but contain stubs
652 which call FNNAME and then copy the return value from the fp regs
653 to the gp regs. These stubs store the return value in $18 while
654 calling FNNAME; any function which might call one of these stubs
655 must arrange to save $18 around the call. (This case is not
656 needed for 32 bit functions that call 16 bit functions, because
657 16 bit functions always return floating point values in both
660 Note that in all cases FNNAME might be defined statically.
661 Therefore, FNNAME is not used literally. Instead, the relocation
662 information will indicate which symbol the section is for.
664 We record any stubs that we find in the symbol table. */
666 #define FN_STUB ".mips16.fn."
667 #define CALL_STUB ".mips16.call."
668 #define CALL_FP_STUB ".mips16.call.fp."
670 /* The format of the first PLT entry in a VxWorks executable. */
671 static const bfd_vma mips_vxworks_exec_plt0_entry
[] = {
672 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
673 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
674 0x8f390008, /* lw t9, 8(t9) */
675 0x00000000, /* nop */
676 0x03200008, /* jr t9 */
680 /* The format of subsequent PLT entries. */
681 static const bfd_vma mips_vxworks_exec_plt_entry
[] = {
682 0x10000000, /* b .PLT_resolver */
683 0x24180000, /* li t8, <pltindex> */
684 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
685 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
686 0x8f390000, /* lw t9, 0(t9) */
687 0x00000000, /* nop */
688 0x03200008, /* jr t9 */
692 /* The format of the first PLT entry in a VxWorks shared object. */
693 static const bfd_vma mips_vxworks_shared_plt0_entry
[] = {
694 0x8f990008, /* lw t9, 8(gp) */
695 0x00000000, /* nop */
696 0x03200008, /* jr t9 */
697 0x00000000, /* nop */
698 0x00000000, /* nop */
702 /* The format of subsequent PLT entries. */
703 static const bfd_vma mips_vxworks_shared_plt_entry
[] = {
704 0x10000000, /* b .PLT_resolver */
705 0x24180000 /* li t8, <pltindex> */
708 /* Look up an entry in a MIPS ELF linker hash table. */
710 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
711 ((struct mips_elf_link_hash_entry *) \
712 elf_link_hash_lookup (&(table)->root, (string), (create), \
715 /* Traverse a MIPS ELF linker hash table. */
717 #define mips_elf_link_hash_traverse(table, func, info) \
718 (elf_link_hash_traverse \
720 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
723 /* Get the MIPS ELF linker hash table from a link_info structure. */
725 #define mips_elf_hash_table(p) \
726 ((struct mips_elf_link_hash_table *) ((p)->hash))
728 /* Find the base offsets for thread-local storage in this object,
729 for GD/LD and IE/LE respectively. */
731 #define TP_OFFSET 0x7000
732 #define DTP_OFFSET 0x8000
735 dtprel_base (struct bfd_link_info
*info
)
737 /* If tls_sec is NULL, we should have signalled an error already. */
738 if (elf_hash_table (info
)->tls_sec
== NULL
)
740 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
744 tprel_base (struct bfd_link_info
*info
)
746 /* If tls_sec is NULL, we should have signalled an error already. */
747 if (elf_hash_table (info
)->tls_sec
== NULL
)
749 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
752 /* Create an entry in a MIPS ELF linker hash table. */
754 static struct bfd_hash_entry
*
755 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
756 struct bfd_hash_table
*table
, const char *string
)
758 struct mips_elf_link_hash_entry
*ret
=
759 (struct mips_elf_link_hash_entry
*) entry
;
761 /* Allocate the structure if it has not already been allocated by a
764 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
766 return (struct bfd_hash_entry
*) ret
;
768 /* Call the allocation method of the superclass. */
769 ret
= ((struct mips_elf_link_hash_entry
*)
770 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
774 /* Set local fields. */
775 memset (&ret
->esym
, 0, sizeof (EXTR
));
776 /* We use -2 as a marker to indicate that the information has
777 not been set. -1 means there is no associated ifd. */
779 ret
->possibly_dynamic_relocs
= 0;
780 ret
->readonly_reloc
= FALSE
;
781 ret
->no_fn_stub
= FALSE
;
783 ret
->need_fn_stub
= FALSE
;
784 ret
->call_stub
= NULL
;
785 ret
->call_fp_stub
= NULL
;
786 ret
->forced_local
= FALSE
;
787 ret
->is_branch_target
= FALSE
;
788 ret
->is_relocation_target
= FALSE
;
789 ret
->tls_type
= GOT_NORMAL
;
792 return (struct bfd_hash_entry
*) ret
;
796 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
798 struct _mips_elf_section_data
*sdata
;
799 bfd_size_type amt
= sizeof (*sdata
);
801 sdata
= bfd_zalloc (abfd
, amt
);
804 sec
->used_by_bfd
= sdata
;
806 return _bfd_elf_new_section_hook (abfd
, sec
);
809 /* Read ECOFF debugging information from a .mdebug section into a
810 ecoff_debug_info structure. */
813 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
814 struct ecoff_debug_info
*debug
)
817 const struct ecoff_debug_swap
*swap
;
820 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
821 memset (debug
, 0, sizeof (*debug
));
823 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
824 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
827 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
828 swap
->external_hdr_size
))
831 symhdr
= &debug
->symbolic_header
;
832 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
834 /* The symbolic header contains absolute file offsets and sizes to
836 #define READ(ptr, offset, count, size, type) \
837 if (symhdr->count == 0) \
841 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
842 debug->ptr = bfd_malloc (amt); \
843 if (debug->ptr == NULL) \
845 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
846 || bfd_bread (debug->ptr, amt, abfd) != amt) \
850 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
851 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
852 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
853 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
854 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
855 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
857 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
858 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
859 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
860 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
861 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
871 if (debug
->line
!= NULL
)
873 if (debug
->external_dnr
!= NULL
)
874 free (debug
->external_dnr
);
875 if (debug
->external_pdr
!= NULL
)
876 free (debug
->external_pdr
);
877 if (debug
->external_sym
!= NULL
)
878 free (debug
->external_sym
);
879 if (debug
->external_opt
!= NULL
)
880 free (debug
->external_opt
);
881 if (debug
->external_aux
!= NULL
)
882 free (debug
->external_aux
);
883 if (debug
->ss
!= NULL
)
885 if (debug
->ssext
!= NULL
)
887 if (debug
->external_fdr
!= NULL
)
888 free (debug
->external_fdr
);
889 if (debug
->external_rfd
!= NULL
)
890 free (debug
->external_rfd
);
891 if (debug
->external_ext
!= NULL
)
892 free (debug
->external_ext
);
896 /* Swap RPDR (runtime procedure table entry) for output. */
899 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
901 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
902 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
903 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
904 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
905 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
906 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
908 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
909 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
911 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
914 /* Create a runtime procedure table from the .mdebug section. */
917 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
918 struct bfd_link_info
*info
, asection
*s
,
919 struct ecoff_debug_info
*debug
)
921 const struct ecoff_debug_swap
*swap
;
922 HDRR
*hdr
= &debug
->symbolic_header
;
924 struct rpdr_ext
*erp
;
926 struct pdr_ext
*epdr
;
927 struct sym_ext
*esym
;
932 unsigned long sindex
;
936 const char *no_name_func
= _("static procedure (no name)");
944 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
946 sindex
= strlen (no_name_func
) + 1;
950 size
= swap
->external_pdr_size
;
952 epdr
= bfd_malloc (size
* count
);
956 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
959 size
= sizeof (RPDR
);
960 rp
= rpdr
= bfd_malloc (size
* count
);
964 size
= sizeof (char *);
965 sv
= bfd_malloc (size
* count
);
969 count
= hdr
->isymMax
;
970 size
= swap
->external_sym_size
;
971 esym
= bfd_malloc (size
* count
);
975 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
979 ss
= bfd_malloc (count
);
982 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
986 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
988 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
989 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
991 rp
->regmask
= pdr
.regmask
;
992 rp
->regoffset
= pdr
.regoffset
;
993 rp
->fregmask
= pdr
.fregmask
;
994 rp
->fregoffset
= pdr
.fregoffset
;
995 rp
->frameoffset
= pdr
.frameoffset
;
996 rp
->framereg
= pdr
.framereg
;
997 rp
->pcreg
= pdr
.pcreg
;
999 sv
[i
] = ss
+ sym
.iss
;
1000 sindex
+= strlen (sv
[i
]) + 1;
1004 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1005 size
= BFD_ALIGN (size
, 16);
1006 rtproc
= bfd_alloc (abfd
, size
);
1009 mips_elf_hash_table (info
)->procedure_count
= 0;
1013 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1016 memset (erp
, 0, sizeof (struct rpdr_ext
));
1018 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1019 strcpy (str
, no_name_func
);
1020 str
+= strlen (no_name_func
) + 1;
1021 for (i
= 0; i
< count
; i
++)
1023 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1024 strcpy (str
, sv
[i
]);
1025 str
+= strlen (sv
[i
]) + 1;
1027 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1029 /* Set the size and contents of .rtproc section. */
1031 s
->contents
= rtproc
;
1033 /* Skip this section later on (I don't think this currently
1034 matters, but someday it might). */
1035 s
->map_head
.link_order
= NULL
;
1064 /* Check the mips16 stubs for a particular symbol, and see if we can
1068 mips_elf_check_mips16_stubs (struct mips_elf_link_hash_entry
*h
,
1069 void *data ATTRIBUTE_UNUSED
)
1071 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1072 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1074 if (h
->fn_stub
!= NULL
1075 && ! h
->need_fn_stub
)
1077 /* We don't need the fn_stub; the only references to this symbol
1078 are 16 bit calls. Clobber the size to 0 to prevent it from
1079 being included in the link. */
1080 h
->fn_stub
->size
= 0;
1081 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1082 h
->fn_stub
->reloc_count
= 0;
1083 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1086 if (h
->call_stub
!= NULL
1087 && h
->root
.other
== STO_MIPS16
)
1089 /* We don't need the call_stub; this is a 16 bit function, so
1090 calls from other 16 bit functions are OK. Clobber the size
1091 to 0 to prevent it from being included in the link. */
1092 h
->call_stub
->size
= 0;
1093 h
->call_stub
->flags
&= ~SEC_RELOC
;
1094 h
->call_stub
->reloc_count
= 0;
1095 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1098 if (h
->call_fp_stub
!= NULL
1099 && h
->root
.other
== STO_MIPS16
)
1101 /* We don't need the call_stub; this is a 16 bit function, so
1102 calls from other 16 bit functions are OK. Clobber the size
1103 to 0 to prevent it from being included in the link. */
1104 h
->call_fp_stub
->size
= 0;
1105 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1106 h
->call_fp_stub
->reloc_count
= 0;
1107 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1113 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1114 Most mips16 instructions are 16 bits, but these instructions
1117 The format of these instructions is:
1119 +--------------+--------------------------------+
1120 | JALX | X| Imm 20:16 | Imm 25:21 |
1121 +--------------+--------------------------------+
1123 +-----------------------------------------------+
1125 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1126 Note that the immediate value in the first word is swapped.
1128 When producing a relocatable object file, R_MIPS16_26 is
1129 handled mostly like R_MIPS_26. In particular, the addend is
1130 stored as a straight 26-bit value in a 32-bit instruction.
1131 (gas makes life simpler for itself by never adjusting a
1132 R_MIPS16_26 reloc to be against a section, so the addend is
1133 always zero). However, the 32 bit instruction is stored as 2
1134 16-bit values, rather than a single 32-bit value. In a
1135 big-endian file, the result is the same; in a little-endian
1136 file, the two 16-bit halves of the 32 bit value are swapped.
1137 This is so that a disassembler can recognize the jal
1140 When doing a final link, R_MIPS16_26 is treated as a 32 bit
1141 instruction stored as two 16-bit values. The addend A is the
1142 contents of the targ26 field. The calculation is the same as
1143 R_MIPS_26. When storing the calculated value, reorder the
1144 immediate value as shown above, and don't forget to store the
1145 value as two 16-bit values.
1147 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
1151 +--------+----------------------+
1155 +--------+----------------------+
1158 +----------+------+-------------+
1162 +----------+--------------------+
1163 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
1164 ((sub1 << 16) | sub2)).
1166 When producing a relocatable object file, the calculation is
1167 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1168 When producing a fully linked file, the calculation is
1169 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1170 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
1172 R_MIPS16_GPREL is used for GP-relative addressing in mips16
1173 mode. A typical instruction will have a format like this:
1175 +--------------+--------------------------------+
1176 | EXTEND | Imm 10:5 | Imm 15:11 |
1177 +--------------+--------------------------------+
1178 | Major | rx | ry | Imm 4:0 |
1179 +--------------+--------------------------------+
1181 EXTEND is the five bit value 11110. Major is the instruction
1184 This is handled exactly like R_MIPS_GPREL16, except that the
1185 addend is retrieved and stored as shown in this diagram; that
1186 is, the Imm fields above replace the V-rel16 field.
1188 All we need to do here is shuffle the bits appropriately. As
1189 above, the two 16-bit halves must be swapped on a
1190 little-endian system.
1192 R_MIPS16_HI16 and R_MIPS16_LO16 are used in mips16 mode to
1193 access data when neither GP-relative nor PC-relative addressing
1194 can be used. They are handled like R_MIPS_HI16 and R_MIPS_LO16,
1195 except that the addend is retrieved and stored as shown above
1199 _bfd_mips16_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
1200 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1202 bfd_vma extend
, insn
, val
;
1204 if (r_type
!= R_MIPS16_26
&& r_type
!= R_MIPS16_GPREL
1205 && r_type
!= R_MIPS16_HI16
&& r_type
!= R_MIPS16_LO16
)
1208 /* Pick up the mips16 extend instruction and the real instruction. */
1209 extend
= bfd_get_16 (abfd
, data
);
1210 insn
= bfd_get_16 (abfd
, data
+ 2);
1211 if (r_type
== R_MIPS16_26
)
1214 val
= ((extend
& 0xfc00) << 16) | ((extend
& 0x3e0) << 11)
1215 | ((extend
& 0x1f) << 21) | insn
;
1217 val
= extend
<< 16 | insn
;
1220 val
= ((extend
& 0xf800) << 16) | ((insn
& 0xffe0) << 11)
1221 | ((extend
& 0x1f) << 11) | (extend
& 0x7e0) | (insn
& 0x1f);
1222 bfd_put_32 (abfd
, val
, data
);
1226 _bfd_mips16_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
1227 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1229 bfd_vma extend
, insn
, val
;
1231 if (r_type
!= R_MIPS16_26
&& r_type
!= R_MIPS16_GPREL
1232 && r_type
!= R_MIPS16_HI16
&& r_type
!= R_MIPS16_LO16
)
1235 val
= bfd_get_32 (abfd
, data
);
1236 if (r_type
== R_MIPS16_26
)
1240 insn
= val
& 0xffff;
1241 extend
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
1242 | ((val
>> 21) & 0x1f);
1246 insn
= val
& 0xffff;
1252 insn
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
1253 extend
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
1255 bfd_put_16 (abfd
, insn
, data
+ 2);
1256 bfd_put_16 (abfd
, extend
, data
);
1259 bfd_reloc_status_type
1260 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1261 arelent
*reloc_entry
, asection
*input_section
,
1262 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1266 bfd_reloc_status_type status
;
1268 if (bfd_is_com_section (symbol
->section
))
1271 relocation
= symbol
->value
;
1273 relocation
+= symbol
->section
->output_section
->vma
;
1274 relocation
+= symbol
->section
->output_offset
;
1276 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1277 return bfd_reloc_outofrange
;
1279 /* Set val to the offset into the section or symbol. */
1280 val
= reloc_entry
->addend
;
1282 _bfd_mips_elf_sign_extend (val
, 16);
1284 /* Adjust val for the final section location and GP value. If we
1285 are producing relocatable output, we don't want to do this for
1286 an external symbol. */
1288 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1289 val
+= relocation
- gp
;
1291 if (reloc_entry
->howto
->partial_inplace
)
1293 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1295 + reloc_entry
->address
);
1296 if (status
!= bfd_reloc_ok
)
1300 reloc_entry
->addend
= val
;
1303 reloc_entry
->address
+= input_section
->output_offset
;
1305 return bfd_reloc_ok
;
1308 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
1309 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
1310 that contains the relocation field and DATA points to the start of
1315 struct mips_hi16
*next
;
1317 asection
*input_section
;
1321 /* FIXME: This should not be a static variable. */
1323 static struct mips_hi16
*mips_hi16_list
;
1325 /* A howto special_function for REL *HI16 relocations. We can only
1326 calculate the correct value once we've seen the partnering
1327 *LO16 relocation, so just save the information for later.
1329 The ABI requires that the *LO16 immediately follow the *HI16.
1330 However, as a GNU extension, we permit an arbitrary number of
1331 *HI16s to be associated with a single *LO16. This significantly
1332 simplies the relocation handling in gcc. */
1334 bfd_reloc_status_type
1335 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1336 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
1337 asection
*input_section
, bfd
*output_bfd
,
1338 char **error_message ATTRIBUTE_UNUSED
)
1340 struct mips_hi16
*n
;
1342 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1343 return bfd_reloc_outofrange
;
1345 n
= bfd_malloc (sizeof *n
);
1347 return bfd_reloc_outofrange
;
1349 n
->next
= mips_hi16_list
;
1351 n
->input_section
= input_section
;
1352 n
->rel
= *reloc_entry
;
1355 if (output_bfd
!= NULL
)
1356 reloc_entry
->address
+= input_section
->output_offset
;
1358 return bfd_reloc_ok
;
1361 /* A howto special_function for REL R_MIPS_GOT16 relocations. This is just
1362 like any other 16-bit relocation when applied to global symbols, but is
1363 treated in the same as R_MIPS_HI16 when applied to local symbols. */
1365 bfd_reloc_status_type
1366 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1367 void *data
, asection
*input_section
,
1368 bfd
*output_bfd
, char **error_message
)
1370 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
1371 || bfd_is_und_section (bfd_get_section (symbol
))
1372 || bfd_is_com_section (bfd_get_section (symbol
)))
1373 /* The relocation is against a global symbol. */
1374 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1375 input_section
, output_bfd
,
1378 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1379 input_section
, output_bfd
, error_message
);
1382 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
1383 is a straightforward 16 bit inplace relocation, but we must deal with
1384 any partnering high-part relocations as well. */
1386 bfd_reloc_status_type
1387 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1388 void *data
, asection
*input_section
,
1389 bfd
*output_bfd
, char **error_message
)
1392 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1394 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1395 return bfd_reloc_outofrange
;
1397 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1399 vallo
= bfd_get_32 (abfd
, location
);
1400 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1403 while (mips_hi16_list
!= NULL
)
1405 bfd_reloc_status_type ret
;
1406 struct mips_hi16
*hi
;
1408 hi
= mips_hi16_list
;
1410 /* R_MIPS_GOT16 relocations are something of a special case. We
1411 want to install the addend in the same way as for a R_MIPS_HI16
1412 relocation (with a rightshift of 16). However, since GOT16
1413 relocations can also be used with global symbols, their howto
1414 has a rightshift of 0. */
1415 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
1416 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
1418 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
1419 carry or borrow will induce a change of +1 or -1 in the high part. */
1420 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
1422 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
1423 hi
->input_section
, output_bfd
,
1425 if (ret
!= bfd_reloc_ok
)
1428 mips_hi16_list
= hi
->next
;
1432 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1433 input_section
, output_bfd
,
1437 /* A generic howto special_function. This calculates and installs the
1438 relocation itself, thus avoiding the oft-discussed problems in
1439 bfd_perform_relocation and bfd_install_relocation. */
1441 bfd_reloc_status_type
1442 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1443 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
1444 asection
*input_section
, bfd
*output_bfd
,
1445 char **error_message ATTRIBUTE_UNUSED
)
1448 bfd_reloc_status_type status
;
1449 bfd_boolean relocatable
;
1451 relocatable
= (output_bfd
!= NULL
);
1453 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1454 return bfd_reloc_outofrange
;
1456 /* Build up the field adjustment in VAL. */
1458 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1460 /* Either we're calculating the final field value or we have a
1461 relocation against a section symbol. Add in the section's
1462 offset or address. */
1463 val
+= symbol
->section
->output_section
->vma
;
1464 val
+= symbol
->section
->output_offset
;
1469 /* We're calculating the final field value. Add in the symbol's value
1470 and, if pc-relative, subtract the address of the field itself. */
1471 val
+= symbol
->value
;
1472 if (reloc_entry
->howto
->pc_relative
)
1474 val
-= input_section
->output_section
->vma
;
1475 val
-= input_section
->output_offset
;
1476 val
-= reloc_entry
->address
;
1480 /* VAL is now the final adjustment. If we're keeping this relocation
1481 in the output file, and if the relocation uses a separate addend,
1482 we just need to add VAL to that addend. Otherwise we need to add
1483 VAL to the relocation field itself. */
1484 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
1485 reloc_entry
->addend
+= val
;
1488 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1490 /* Add in the separate addend, if any. */
1491 val
+= reloc_entry
->addend
;
1493 /* Add VAL to the relocation field. */
1494 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1496 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1498 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1501 if (status
!= bfd_reloc_ok
)
1506 reloc_entry
->address
+= input_section
->output_offset
;
1508 return bfd_reloc_ok
;
1511 /* Swap an entry in a .gptab section. Note that these routines rely
1512 on the equivalence of the two elements of the union. */
1515 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
1518 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1519 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1523 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
1524 Elf32_External_gptab
*ex
)
1526 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
1527 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
1531 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
1532 Elf32_External_compact_rel
*ex
)
1534 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1535 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1536 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1537 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1538 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1539 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1543 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
1544 Elf32_External_crinfo
*ex
)
1548 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1549 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1550 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1551 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1552 H_PUT_32 (abfd
, l
, ex
->info
);
1553 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1554 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1557 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1558 routines swap this structure in and out. They are used outside of
1559 BFD, so they are globally visible. */
1562 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
1565 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1566 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1567 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1568 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1569 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1570 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1574 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
1575 Elf32_External_RegInfo
*ex
)
1577 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1578 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1579 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1580 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1581 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1582 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1585 /* In the 64 bit ABI, the .MIPS.options section holds register
1586 information in an Elf64_Reginfo structure. These routines swap
1587 them in and out. They are globally visible because they are used
1588 outside of BFD. These routines are here so that gas can call them
1589 without worrying about whether the 64 bit ABI has been included. */
1592 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
1593 Elf64_Internal_RegInfo
*in
)
1595 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1596 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1597 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1598 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1599 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1600 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1601 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1605 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
1606 Elf64_External_RegInfo
*ex
)
1608 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1609 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1610 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1611 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1612 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1613 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1614 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1617 /* Swap in an options header. */
1620 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
1621 Elf_Internal_Options
*in
)
1623 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1624 in
->size
= H_GET_8 (abfd
, ex
->size
);
1625 in
->section
= H_GET_16 (abfd
, ex
->section
);
1626 in
->info
= H_GET_32 (abfd
, ex
->info
);
1629 /* Swap out an options header. */
1632 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
1633 Elf_External_Options
*ex
)
1635 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1636 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1637 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1638 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1641 /* This function is called via qsort() to sort the dynamic relocation
1642 entries by increasing r_symndx value. */
1645 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
1647 Elf_Internal_Rela int_reloc1
;
1648 Elf_Internal_Rela int_reloc2
;
1650 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1651 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1653 return ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
1656 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
1659 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
1660 const void *arg2 ATTRIBUTE_UNUSED
)
1663 Elf_Internal_Rela int_reloc1
[3];
1664 Elf_Internal_Rela int_reloc2
[3];
1666 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1667 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
1668 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1669 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
1671 return (ELF64_R_SYM (int_reloc1
[0].r_info
)
1672 - ELF64_R_SYM (int_reloc2
[0].r_info
));
1679 /* This routine is used to write out ECOFF debugging external symbol
1680 information. It is called via mips_elf_link_hash_traverse. The
1681 ECOFF external symbol information must match the ELF external
1682 symbol information. Unfortunately, at this point we don't know
1683 whether a symbol is required by reloc information, so the two
1684 tables may wind up being different. We must sort out the external
1685 symbol information before we can set the final size of the .mdebug
1686 section, and we must set the size of the .mdebug section before we
1687 can relocate any sections, and we can't know which symbols are
1688 required by relocation until we relocate the sections.
1689 Fortunately, it is relatively unlikely that any symbol will be
1690 stripped but required by a reloc. In particular, it can not happen
1691 when generating a final executable. */
1694 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
1696 struct extsym_info
*einfo
= data
;
1698 asection
*sec
, *output_section
;
1700 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1701 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1703 if (h
->root
.indx
== -2)
1705 else if ((h
->root
.def_dynamic
1706 || h
->root
.ref_dynamic
1707 || h
->root
.type
== bfd_link_hash_new
)
1708 && !h
->root
.def_regular
1709 && !h
->root
.ref_regular
)
1711 else if (einfo
->info
->strip
== strip_all
1712 || (einfo
->info
->strip
== strip_some
1713 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1714 h
->root
.root
.root
.string
,
1715 FALSE
, FALSE
) == NULL
))
1723 if (h
->esym
.ifd
== -2)
1726 h
->esym
.cobol_main
= 0;
1727 h
->esym
.weakext
= 0;
1728 h
->esym
.reserved
= 0;
1729 h
->esym
.ifd
= ifdNil
;
1730 h
->esym
.asym
.value
= 0;
1731 h
->esym
.asym
.st
= stGlobal
;
1733 if (h
->root
.root
.type
== bfd_link_hash_undefined
1734 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
1738 /* Use undefined class. Also, set class and type for some
1740 name
= h
->root
.root
.root
.string
;
1741 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
1742 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
1744 h
->esym
.asym
.sc
= scData
;
1745 h
->esym
.asym
.st
= stLabel
;
1746 h
->esym
.asym
.value
= 0;
1748 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
1750 h
->esym
.asym
.sc
= scAbs
;
1751 h
->esym
.asym
.st
= stLabel
;
1752 h
->esym
.asym
.value
=
1753 mips_elf_hash_table (einfo
->info
)->procedure_count
;
1755 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
1757 h
->esym
.asym
.sc
= scAbs
;
1758 h
->esym
.asym
.st
= stLabel
;
1759 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
1762 h
->esym
.asym
.sc
= scUndefined
;
1764 else if (h
->root
.root
.type
!= bfd_link_hash_defined
1765 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1766 h
->esym
.asym
.sc
= scAbs
;
1771 sec
= h
->root
.root
.u
.def
.section
;
1772 output_section
= sec
->output_section
;
1774 /* When making a shared library and symbol h is the one from
1775 the another shared library, OUTPUT_SECTION may be null. */
1776 if (output_section
== NULL
)
1777 h
->esym
.asym
.sc
= scUndefined
;
1780 name
= bfd_section_name (output_section
->owner
, output_section
);
1782 if (strcmp (name
, ".text") == 0)
1783 h
->esym
.asym
.sc
= scText
;
1784 else if (strcmp (name
, ".data") == 0)
1785 h
->esym
.asym
.sc
= scData
;
1786 else if (strcmp (name
, ".sdata") == 0)
1787 h
->esym
.asym
.sc
= scSData
;
1788 else if (strcmp (name
, ".rodata") == 0
1789 || strcmp (name
, ".rdata") == 0)
1790 h
->esym
.asym
.sc
= scRData
;
1791 else if (strcmp (name
, ".bss") == 0)
1792 h
->esym
.asym
.sc
= scBss
;
1793 else if (strcmp (name
, ".sbss") == 0)
1794 h
->esym
.asym
.sc
= scSBss
;
1795 else if (strcmp (name
, ".init") == 0)
1796 h
->esym
.asym
.sc
= scInit
;
1797 else if (strcmp (name
, ".fini") == 0)
1798 h
->esym
.asym
.sc
= scFini
;
1800 h
->esym
.asym
.sc
= scAbs
;
1804 h
->esym
.asym
.reserved
= 0;
1805 h
->esym
.asym
.index
= indexNil
;
1808 if (h
->root
.root
.type
== bfd_link_hash_common
)
1809 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1810 else if (h
->root
.root
.type
== bfd_link_hash_defined
1811 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1813 if (h
->esym
.asym
.sc
== scCommon
)
1814 h
->esym
.asym
.sc
= scBss
;
1815 else if (h
->esym
.asym
.sc
== scSCommon
)
1816 h
->esym
.asym
.sc
= scSBss
;
1818 sec
= h
->root
.root
.u
.def
.section
;
1819 output_section
= sec
->output_section
;
1820 if (output_section
!= NULL
)
1821 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1822 + sec
->output_offset
1823 + output_section
->vma
);
1825 h
->esym
.asym
.value
= 0;
1827 else if (h
->root
.needs_plt
)
1829 struct mips_elf_link_hash_entry
*hd
= h
;
1830 bfd_boolean no_fn_stub
= h
->no_fn_stub
;
1832 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
1834 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
1835 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
1840 /* Set type and value for a symbol with a function stub. */
1841 h
->esym
.asym
.st
= stProc
;
1842 sec
= hd
->root
.root
.u
.def
.section
;
1844 h
->esym
.asym
.value
= 0;
1847 output_section
= sec
->output_section
;
1848 if (output_section
!= NULL
)
1849 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
1850 + sec
->output_offset
1851 + output_section
->vma
);
1853 h
->esym
.asym
.value
= 0;
1858 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1859 h
->root
.root
.root
.string
,
1862 einfo
->failed
= TRUE
;
1869 /* A comparison routine used to sort .gptab entries. */
1872 gptab_compare (const void *p1
, const void *p2
)
1874 const Elf32_gptab
*a1
= p1
;
1875 const Elf32_gptab
*a2
= p2
;
1877 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
1880 /* Functions to manage the got entry hash table. */
1882 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
1885 static INLINE hashval_t
1886 mips_elf_hash_bfd_vma (bfd_vma addr
)
1889 return addr
+ (addr
>> 32);
1895 /* got_entries only match if they're identical, except for gotidx, so
1896 use all fields to compute the hash, and compare the appropriate
1900 mips_elf_got_entry_hash (const void *entry_
)
1902 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
1904 return entry
->symndx
1905 + ((entry
->tls_type
& GOT_TLS_LDM
) << 17)
1906 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
1908 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
1909 : entry
->d
.h
->root
.root
.root
.hash
));
1913 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
1915 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
1916 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
1918 /* An LDM entry can only match another LDM entry. */
1919 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
1922 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
1923 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
1924 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
1925 : e1
->d
.h
== e2
->d
.h
);
1928 /* multi_got_entries are still a match in the case of global objects,
1929 even if the input bfd in which they're referenced differs, so the
1930 hash computation and compare functions are adjusted
1934 mips_elf_multi_got_entry_hash (const void *entry_
)
1936 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
1938 return entry
->symndx
1940 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
1941 : entry
->symndx
>= 0
1942 ? ((entry
->tls_type
& GOT_TLS_LDM
)
1943 ? (GOT_TLS_LDM
<< 17)
1945 + mips_elf_hash_bfd_vma (entry
->d
.addend
)))
1946 : entry
->d
.h
->root
.root
.root
.hash
);
1950 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
1952 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
1953 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
1955 /* Any two LDM entries match. */
1956 if (e1
->tls_type
& e2
->tls_type
& GOT_TLS_LDM
)
1959 /* Nothing else matches an LDM entry. */
1960 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
1963 return e1
->symndx
== e2
->symndx
1964 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
1965 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
1966 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
1967 : e1
->d
.h
== e2
->d
.h
);
1970 /* Return the dynamic relocation section. If it doesn't exist, try to
1971 create a new it if CREATE_P, otherwise return NULL. Also return NULL
1972 if creation fails. */
1975 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
1981 dname
= MIPS_ELF_REL_DYN_NAME (info
);
1982 dynobj
= elf_hash_table (info
)->dynobj
;
1983 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
1984 if (sreloc
== NULL
&& create_p
)
1986 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
1991 | SEC_LINKER_CREATED
1994 || ! bfd_set_section_alignment (dynobj
, sreloc
,
1995 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
2001 /* Returns the GOT section for ABFD. */
2004 mips_elf_got_section (bfd
*abfd
, bfd_boolean maybe_excluded
)
2006 asection
*sgot
= bfd_get_section_by_name (abfd
, ".got");
2008 || (! maybe_excluded
&& (sgot
->flags
& SEC_EXCLUDE
) != 0))
2013 /* Returns the GOT information associated with the link indicated by
2014 INFO. If SGOTP is non-NULL, it is filled in with the GOT
2017 static struct mips_got_info
*
2018 mips_elf_got_info (bfd
*abfd
, asection
**sgotp
)
2021 struct mips_got_info
*g
;
2023 sgot
= mips_elf_got_section (abfd
, TRUE
);
2024 BFD_ASSERT (sgot
!= NULL
);
2025 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
2026 g
= mips_elf_section_data (sgot
)->u
.got_info
;
2027 BFD_ASSERT (g
!= NULL
);
2030 *sgotp
= (sgot
->flags
& SEC_EXCLUDE
) == 0 ? sgot
: NULL
;
2035 /* Count the number of relocations needed for a TLS GOT entry, with
2036 access types from TLS_TYPE, and symbol H (or a local symbol if H
2040 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
2041 struct elf_link_hash_entry
*h
)
2045 bfd_boolean need_relocs
= FALSE
;
2046 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2048 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2049 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
2052 if ((info
->shared
|| indx
!= 0)
2054 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2055 || h
->root
.type
!= bfd_link_hash_undefweak
))
2061 if (tls_type
& GOT_TLS_GD
)
2068 if (tls_type
& GOT_TLS_IE
)
2071 if ((tls_type
& GOT_TLS_LDM
) && info
->shared
)
2077 /* Count the number of TLS relocations required for the GOT entry in
2078 ARG1, if it describes a local symbol. */
2081 mips_elf_count_local_tls_relocs (void **arg1
, void *arg2
)
2083 struct mips_got_entry
*entry
= * (struct mips_got_entry
**) arg1
;
2084 struct mips_elf_count_tls_arg
*arg
= arg2
;
2086 if (entry
->abfd
!= NULL
&& entry
->symndx
!= -1)
2087 arg
->needed
+= mips_tls_got_relocs (arg
->info
, entry
->tls_type
, NULL
);
2092 /* Count the number of TLS GOT entries required for the global (or
2093 forced-local) symbol in ARG1. */
2096 mips_elf_count_global_tls_entries (void *arg1
, void *arg2
)
2098 struct mips_elf_link_hash_entry
*hm
2099 = (struct mips_elf_link_hash_entry
*) arg1
;
2100 struct mips_elf_count_tls_arg
*arg
= arg2
;
2102 if (hm
->tls_type
& GOT_TLS_GD
)
2104 if (hm
->tls_type
& GOT_TLS_IE
)
2110 /* Count the number of TLS relocations required for the global (or
2111 forced-local) symbol in ARG1. */
2114 mips_elf_count_global_tls_relocs (void *arg1
, void *arg2
)
2116 struct mips_elf_link_hash_entry
*hm
2117 = (struct mips_elf_link_hash_entry
*) arg1
;
2118 struct mips_elf_count_tls_arg
*arg
= arg2
;
2120 arg
->needed
+= mips_tls_got_relocs (arg
->info
, hm
->tls_type
, &hm
->root
);
2125 /* Output a simple dynamic relocation into SRELOC. */
2128 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
2134 Elf_Internal_Rela rel
[3];
2136 memset (rel
, 0, sizeof (rel
));
2138 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
2139 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
2141 if (ABI_64_P (output_bfd
))
2143 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2144 (output_bfd
, &rel
[0],
2146 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
2149 bfd_elf32_swap_reloc_out
2150 (output_bfd
, &rel
[0],
2152 + sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
2153 ++sreloc
->reloc_count
;
2156 /* Initialize a set of TLS GOT entries for one symbol. */
2159 mips_elf_initialize_tls_slots (bfd
*abfd
, bfd_vma got_offset
,
2160 unsigned char *tls_type_p
,
2161 struct bfd_link_info
*info
,
2162 struct mips_elf_link_hash_entry
*h
,
2166 asection
*sreloc
, *sgot
;
2167 bfd_vma offset
, offset2
;
2169 bfd_boolean need_relocs
= FALSE
;
2171 dynobj
= elf_hash_table (info
)->dynobj
;
2172 sgot
= mips_elf_got_section (dynobj
, FALSE
);
2177 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2179 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
2180 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
2181 indx
= h
->root
.dynindx
;
2184 if (*tls_type_p
& GOT_TLS_DONE
)
2187 if ((info
->shared
|| indx
!= 0)
2189 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
2190 || h
->root
.type
!= bfd_link_hash_undefweak
))
2193 /* MINUS_ONE means the symbol is not defined in this object. It may not
2194 be defined at all; assume that the value doesn't matter in that
2195 case. Otherwise complain if we would use the value. */
2196 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
2197 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
2199 /* Emit necessary relocations. */
2200 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
2202 /* General Dynamic. */
2203 if (*tls_type_p
& GOT_TLS_GD
)
2205 offset
= got_offset
;
2206 offset2
= offset
+ MIPS_ELF_GOT_SIZE (abfd
);
2210 mips_elf_output_dynamic_relocation
2211 (abfd
, sreloc
, indx
,
2212 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2213 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2216 mips_elf_output_dynamic_relocation
2217 (abfd
, sreloc
, indx
,
2218 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
2219 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset2
);
2221 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2222 sgot
->contents
+ offset2
);
2226 MIPS_ELF_PUT_WORD (abfd
, 1,
2227 sgot
->contents
+ offset
);
2228 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2229 sgot
->contents
+ offset2
);
2232 got_offset
+= 2 * MIPS_ELF_GOT_SIZE (abfd
);
2235 /* Initial Exec model. */
2236 if (*tls_type_p
& GOT_TLS_IE
)
2238 offset
= got_offset
;
2243 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
2244 sgot
->contents
+ offset
);
2246 MIPS_ELF_PUT_WORD (abfd
, 0,
2247 sgot
->contents
+ offset
);
2249 mips_elf_output_dynamic_relocation
2250 (abfd
, sreloc
, indx
,
2251 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
2252 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2255 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
2256 sgot
->contents
+ offset
);
2259 if (*tls_type_p
& GOT_TLS_LDM
)
2261 /* The initial offset is zero, and the LD offsets will include the
2262 bias by DTP_OFFSET. */
2263 MIPS_ELF_PUT_WORD (abfd
, 0,
2264 sgot
->contents
+ got_offset
2265 + MIPS_ELF_GOT_SIZE (abfd
));
2268 MIPS_ELF_PUT_WORD (abfd
, 1,
2269 sgot
->contents
+ got_offset
);
2271 mips_elf_output_dynamic_relocation
2272 (abfd
, sreloc
, indx
,
2273 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2274 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
2277 *tls_type_p
|= GOT_TLS_DONE
;
2280 /* Return the GOT index to use for a relocation of type R_TYPE against
2281 a symbol accessed using TLS_TYPE models. The GOT entries for this
2282 symbol in this GOT start at GOT_INDEX. This function initializes the
2283 GOT entries and corresponding relocations. */
2286 mips_tls_got_index (bfd
*abfd
, bfd_vma got_index
, unsigned char *tls_type
,
2287 int r_type
, struct bfd_link_info
*info
,
2288 struct mips_elf_link_hash_entry
*h
, bfd_vma symbol
)
2290 BFD_ASSERT (r_type
== R_MIPS_TLS_GOTTPREL
|| r_type
== R_MIPS_TLS_GD
2291 || r_type
== R_MIPS_TLS_LDM
);
2293 mips_elf_initialize_tls_slots (abfd
, got_index
, tls_type
, info
, h
, symbol
);
2295 if (r_type
== R_MIPS_TLS_GOTTPREL
)
2297 BFD_ASSERT (*tls_type
& GOT_TLS_IE
);
2298 if (*tls_type
& GOT_TLS_GD
)
2299 return got_index
+ 2 * MIPS_ELF_GOT_SIZE (abfd
);
2304 if (r_type
== R_MIPS_TLS_GD
)
2306 BFD_ASSERT (*tls_type
& GOT_TLS_GD
);
2310 if (r_type
== R_MIPS_TLS_LDM
)
2312 BFD_ASSERT (*tls_type
& GOT_TLS_LDM
);
2319 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
2320 for global symbol H. .got.plt comes before the GOT, so the offset
2321 will be negative. */
2324 mips_elf_gotplt_index (struct bfd_link_info
*info
,
2325 struct elf_link_hash_entry
*h
)
2327 bfd_vma plt_index
, got_address
, got_value
;
2328 struct mips_elf_link_hash_table
*htab
;
2330 htab
= mips_elf_hash_table (info
);
2331 BFD_ASSERT (h
->plt
.offset
!= (bfd_vma
) -1);
2333 /* Calculate the index of the symbol's PLT entry. */
2334 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
2336 /* Calculate the address of the associated .got.plt entry. */
2337 got_address
= (htab
->sgotplt
->output_section
->vma
2338 + htab
->sgotplt
->output_offset
2341 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
2342 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
2343 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
2344 + htab
->root
.hgot
->root
.u
.def
.value
);
2346 return got_address
- got_value
;
2349 /* Return the GOT offset for address VALUE, which was derived from
2350 a symbol belonging to INPUT_SECTION. If there is not yet a GOT
2351 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
2352 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
2353 offset can be found. */
2356 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2357 asection
*input_section
, bfd_vma value
,
2358 unsigned long r_symndx
,
2359 struct mips_elf_link_hash_entry
*h
, int r_type
)
2362 struct mips_got_info
*g
;
2363 struct mips_got_entry
*entry
;
2365 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
2367 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, g
, sgot
,
2368 input_section
, value
,
2369 r_symndx
, h
, r_type
);
2373 if (TLS_RELOC_P (r_type
))
2374 return mips_tls_got_index (abfd
, entry
->gotidx
, &entry
->tls_type
, r_type
,
2377 return entry
->gotidx
;
2380 /* Returns the GOT index for the global symbol indicated by H. */
2383 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
,
2384 int r_type
, struct bfd_link_info
*info
)
2388 struct mips_got_info
*g
, *gg
;
2389 long global_got_dynindx
= 0;
2391 gg
= g
= mips_elf_got_info (abfd
, &sgot
);
2392 if (g
->bfd2got
&& ibfd
)
2394 struct mips_got_entry e
, *p
;
2396 BFD_ASSERT (h
->dynindx
>= 0);
2398 g
= mips_elf_got_for_ibfd (g
, ibfd
);
2399 if (g
->next
!= gg
|| TLS_RELOC_P (r_type
))
2403 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
2406 p
= htab_find (g
->got_entries
, &e
);
2408 BFD_ASSERT (p
->gotidx
> 0);
2410 if (TLS_RELOC_P (r_type
))
2412 bfd_vma value
= MINUS_ONE
;
2413 if ((h
->root
.type
== bfd_link_hash_defined
2414 || h
->root
.type
== bfd_link_hash_defweak
)
2415 && h
->root
.u
.def
.section
->output_section
)
2416 value
= (h
->root
.u
.def
.value
2417 + h
->root
.u
.def
.section
->output_offset
2418 + h
->root
.u
.def
.section
->output_section
->vma
);
2420 return mips_tls_got_index (abfd
, p
->gotidx
, &p
->tls_type
, r_type
,
2421 info
, e
.d
.h
, value
);
2428 if (gg
->global_gotsym
!= NULL
)
2429 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
2431 if (TLS_RELOC_P (r_type
))
2433 struct mips_elf_link_hash_entry
*hm
2434 = (struct mips_elf_link_hash_entry
*) h
;
2435 bfd_vma value
= MINUS_ONE
;
2437 if ((h
->root
.type
== bfd_link_hash_defined
2438 || h
->root
.type
== bfd_link_hash_defweak
)
2439 && h
->root
.u
.def
.section
->output_section
)
2440 value
= (h
->root
.u
.def
.value
2441 + h
->root
.u
.def
.section
->output_offset
2442 + h
->root
.u
.def
.section
->output_section
->vma
);
2444 index
= mips_tls_got_index (abfd
, hm
->tls_got_offset
, &hm
->tls_type
,
2445 r_type
, info
, hm
, value
);
2449 /* Once we determine the global GOT entry with the lowest dynamic
2450 symbol table index, we must put all dynamic symbols with greater
2451 indices into the GOT. That makes it easy to calculate the GOT
2453 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
2454 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
2455 * MIPS_ELF_GOT_SIZE (abfd
));
2457 BFD_ASSERT (index
< sgot
->size
);
2462 /* Find a GOT page entry that points to within 32KB of VALUE, which was
2463 calculated from a symbol belonging to INPUT_SECTION. These entries
2464 are supposed to be placed at small offsets in the GOT, i.e., within
2465 32KB of GP. Return the index of the GOT entry, or -1 if no entry
2466 could be created. If OFFSETP is nonnull, use it to return the
2467 offset of the GOT entry from VALUE. */
2470 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2471 asection
*input_section
, bfd_vma value
, bfd_vma
*offsetp
)
2474 struct mips_got_info
*g
;
2475 bfd_vma page
, index
;
2476 struct mips_got_entry
*entry
;
2478 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
2480 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
2481 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, g
, sgot
,
2482 input_section
, page
, 0,
2483 NULL
, R_MIPS_GOT_PAGE
);
2488 index
= entry
->gotidx
;
2491 *offsetp
= value
- entry
->d
.address
;
2496 /* Find a local GOT entry for an R_MIPS_GOT16 relocation against VALUE,
2497 which was calculated from a symbol belonging to INPUT_SECTION.
2498 EXTERNAL is true if the relocation was against a global symbol
2499 that has been forced local. */
2502 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2503 asection
*input_section
, bfd_vma value
,
2504 bfd_boolean external
)
2507 struct mips_got_info
*g
;
2508 struct mips_got_entry
*entry
;
2510 /* GOT16 relocations against local symbols are followed by a LO16
2511 relocation; those against global symbols are not. Thus if the
2512 symbol was originally local, the GOT16 relocation should load the
2513 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
2515 value
= mips_elf_high (value
) << 16;
2517 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
2519 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, g
, sgot
,
2520 input_section
, value
, 0,
2521 NULL
, R_MIPS_GOT16
);
2523 return entry
->gotidx
;
2528 /* Returns the offset for the entry at the INDEXth position
2532 mips_elf_got_offset_from_index (bfd
*dynobj
, bfd
*output_bfd
,
2533 bfd
*input_bfd
, bfd_vma index
)
2537 struct mips_got_info
*g
;
2539 g
= mips_elf_got_info (dynobj
, &sgot
);
2540 gp
= _bfd_get_gp_value (output_bfd
)
2541 + mips_elf_adjust_gp (output_bfd
, g
, input_bfd
);
2543 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
2546 /* Create and return a local GOT entry for VALUE, which was calculated
2547 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
2548 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
2551 static struct mips_got_entry
*
2552 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
2553 bfd
*ibfd
, struct mips_got_info
*gg
,
2554 asection
*sgot
, asection
*input_section
,
2555 bfd_vma value
, unsigned long r_symndx
,
2556 struct mips_elf_link_hash_entry
*h
,
2559 struct mips_got_entry entry
, **loc
;
2560 struct mips_got_info
*g
;
2561 struct mips_elf_link_hash_table
*htab
;
2563 htab
= mips_elf_hash_table (info
);
2567 entry
.d
.address
= value
;
2570 g
= mips_elf_got_for_ibfd (gg
, ibfd
);
2573 g
= mips_elf_got_for_ibfd (gg
, abfd
);
2574 BFD_ASSERT (g
!= NULL
);
2577 /* We might have a symbol, H, if it has been forced local. Use the
2578 global entry then. It doesn't matter whether an entry is local
2579 or global for TLS, since the dynamic linker does not
2580 automatically relocate TLS GOT entries. */
2581 BFD_ASSERT (h
== NULL
|| h
->root
.forced_local
);
2582 if (TLS_RELOC_P (r_type
))
2584 struct mips_got_entry
*p
;
2587 if (r_type
== R_MIPS_TLS_LDM
)
2589 entry
.tls_type
= GOT_TLS_LDM
;
2595 entry
.symndx
= r_symndx
;
2601 p
= (struct mips_got_entry
*)
2602 htab_find (g
->got_entries
, &entry
);
2608 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
2613 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
2616 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2621 memcpy (*loc
, &entry
, sizeof entry
);
2623 if (g
->assigned_gotno
>= g
->local_gotno
)
2625 (*loc
)->gotidx
= -1;
2626 /* We didn't allocate enough space in the GOT. */
2627 (*_bfd_error_handler
)
2628 (_("not enough GOT space for local GOT entries"));
2629 bfd_set_error (bfd_error_bad_value
);
2633 MIPS_ELF_PUT_WORD (abfd
, value
,
2634 (sgot
->contents
+ entry
.gotidx
));
2636 /* These GOT entries need a dynamic relocation on VxWorks. Because
2637 the offset between segments is not fixed, the relocation must be
2638 against a symbol in the same segment as the original symbol.
2639 The easiest way to do this is to take INPUT_SECTION's output
2640 section and emit a relocation against its section symbol. */
2641 if (htab
->is_vxworks
)
2643 Elf_Internal_Rela outrel
;
2644 asection
*s
, *output_section
;
2646 bfd_vma got_address
;
2649 s
= mips_elf_rel_dyn_section (info
, FALSE
);
2650 output_section
= input_section
->output_section
;
2651 dynindx
= elf_section_data (output_section
)->dynindx
;
2652 got_address
= (sgot
->output_section
->vma
2653 + sgot
->output_offset
2656 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
2657 outrel
.r_offset
= got_address
;
2658 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_MIPS_32
);
2659 outrel
.r_addend
= value
- output_section
->vma
;
2660 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
2666 /* Sort the dynamic symbol table so that symbols that need GOT entries
2667 appear towards the end. This reduces the amount of GOT space
2668 required. MAX_LOCAL is used to set the number of local symbols
2669 known to be in the dynamic symbol table. During
2670 _bfd_mips_elf_size_dynamic_sections, this value is 1. Afterward, the
2671 section symbols are added and the count is higher. */
2674 mips_elf_sort_hash_table (struct bfd_link_info
*info
, unsigned long max_local
)
2676 struct mips_elf_hash_sort_data hsd
;
2677 struct mips_got_info
*g
;
2680 dynobj
= elf_hash_table (info
)->dynobj
;
2682 g
= mips_elf_got_info (dynobj
, NULL
);
2685 hsd
.max_unref_got_dynindx
=
2686 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
2687 /* In the multi-got case, assigned_gotno of the master got_info
2688 indicate the number of entries that aren't referenced in the
2689 primary GOT, but that must have entries because there are
2690 dynamic relocations that reference it. Since they aren't
2691 referenced, we move them to the end of the GOT, so that they
2692 don't prevent other entries that are referenced from getting
2693 too large offsets. */
2694 - (g
->next
? g
->assigned_gotno
: 0);
2695 hsd
.max_non_got_dynindx
= max_local
;
2696 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
2697 elf_hash_table (info
)),
2698 mips_elf_sort_hash_table_f
,
2701 /* There should have been enough room in the symbol table to
2702 accommodate both the GOT and non-GOT symbols. */
2703 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
2704 BFD_ASSERT ((unsigned long)hsd
.max_unref_got_dynindx
2705 <= elf_hash_table (info
)->dynsymcount
);
2707 /* Now we know which dynamic symbol has the lowest dynamic symbol
2708 table index in the GOT. */
2709 g
->global_gotsym
= hsd
.low
;
2714 /* If H needs a GOT entry, assign it the highest available dynamic
2715 index. Otherwise, assign it the lowest available dynamic
2719 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
2721 struct mips_elf_hash_sort_data
*hsd
= data
;
2723 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2724 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2726 /* Symbols without dynamic symbol table entries aren't interesting
2728 if (h
->root
.dynindx
== -1)
2731 /* Global symbols that need GOT entries that are not explicitly
2732 referenced are marked with got offset 2. Those that are
2733 referenced get a 1, and those that don't need GOT entries get
2735 if (h
->root
.got
.offset
== 2)
2737 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
2739 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
2740 hsd
->low
= (struct elf_link_hash_entry
*) h
;
2741 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
2743 else if (h
->root
.got
.offset
!= 1)
2744 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
2747 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
2749 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
2750 hsd
->low
= (struct elf_link_hash_entry
*) h
;
2756 /* If H is a symbol that needs a global GOT entry, but has a dynamic
2757 symbol table index lower than any we've seen to date, record it for
2761 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
2762 bfd
*abfd
, struct bfd_link_info
*info
,
2763 struct mips_got_info
*g
,
2764 unsigned char tls_flag
)
2766 struct mips_got_entry entry
, **loc
;
2768 /* A global symbol in the GOT must also be in the dynamic symbol
2770 if (h
->dynindx
== -1)
2772 switch (ELF_ST_VISIBILITY (h
->other
))
2776 _bfd_mips_elf_hide_symbol (info
, h
, TRUE
);
2779 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
2783 /* Make sure we have a GOT to put this entry into. */
2784 BFD_ASSERT (g
!= NULL
);
2788 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
2791 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
2794 /* If we've already marked this entry as needing GOT space, we don't
2795 need to do it again. */
2798 (*loc
)->tls_type
|= tls_flag
;
2802 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2808 entry
.tls_type
= tls_flag
;
2810 memcpy (*loc
, &entry
, sizeof entry
);
2812 if (h
->got
.offset
!= MINUS_ONE
)
2815 /* By setting this to a value other than -1, we are indicating that
2816 there needs to be a GOT entry for H. Avoid using zero, as the
2817 generic ELF copy_indirect_symbol tests for <= 0. */
2824 /* Reserve space in G for a GOT entry containing the value of symbol
2825 SYMNDX in input bfd ABDF, plus ADDEND. */
2828 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
2829 struct mips_got_info
*g
,
2830 unsigned char tls_flag
)
2832 struct mips_got_entry entry
, **loc
;
2835 entry
.symndx
= symndx
;
2836 entry
.d
.addend
= addend
;
2837 entry
.tls_type
= tls_flag
;
2838 loc
= (struct mips_got_entry
**)
2839 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
2843 if (tls_flag
== GOT_TLS_GD
&& !((*loc
)->tls_type
& GOT_TLS_GD
))
2846 (*loc
)->tls_type
|= tls_flag
;
2848 else if (tls_flag
== GOT_TLS_IE
&& !((*loc
)->tls_type
& GOT_TLS_IE
))
2851 (*loc
)->tls_type
|= tls_flag
;
2859 entry
.tls_type
= tls_flag
;
2860 if (tls_flag
== GOT_TLS_IE
)
2862 else if (tls_flag
== GOT_TLS_GD
)
2864 else if (g
->tls_ldm_offset
== MINUS_ONE
)
2866 g
->tls_ldm_offset
= MINUS_TWO
;
2872 entry
.gotidx
= g
->local_gotno
++;
2876 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2881 memcpy (*loc
, &entry
, sizeof entry
);
2886 /* Compute the hash value of the bfd in a bfd2got hash entry. */
2889 mips_elf_bfd2got_entry_hash (const void *entry_
)
2891 const struct mips_elf_bfd2got_hash
*entry
2892 = (struct mips_elf_bfd2got_hash
*)entry_
;
2894 return entry
->bfd
->id
;
2897 /* Check whether two hash entries have the same bfd. */
2900 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
2902 const struct mips_elf_bfd2got_hash
*e1
2903 = (const struct mips_elf_bfd2got_hash
*)entry1
;
2904 const struct mips_elf_bfd2got_hash
*e2
2905 = (const struct mips_elf_bfd2got_hash
*)entry2
;
2907 return e1
->bfd
== e2
->bfd
;
2910 /* In a multi-got link, determine the GOT to be used for IBFD. G must
2911 be the master GOT data. */
2913 static struct mips_got_info
*
2914 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
2916 struct mips_elf_bfd2got_hash e
, *p
;
2922 p
= htab_find (g
->bfd2got
, &e
);
2923 return p
? p
->g
: NULL
;
2926 /* Create one separate got for each bfd that has entries in the global
2927 got, such that we can tell how many local and global entries each
2931 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
2933 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
2934 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
2935 htab_t bfd2got
= arg
->bfd2got
;
2936 struct mips_got_info
*g
;
2937 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
2940 /* Find the got_info for this GOT entry's input bfd. Create one if
2942 bfdgot_entry
.bfd
= entry
->abfd
;
2943 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
2944 bfdgot
= (struct mips_elf_bfd2got_hash
*)*bfdgotp
;
2950 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
2951 (arg
->obfd
, sizeof (struct mips_elf_bfd2got_hash
));
2961 bfdgot
->bfd
= entry
->abfd
;
2962 bfdgot
->g
= g
= (struct mips_got_info
*)
2963 bfd_alloc (arg
->obfd
, sizeof (struct mips_got_info
));
2970 g
->global_gotsym
= NULL
;
2971 g
->global_gotno
= 0;
2973 g
->assigned_gotno
= -1;
2975 g
->tls_assigned_gotno
= 0;
2976 g
->tls_ldm_offset
= MINUS_ONE
;
2977 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
2978 mips_elf_multi_got_entry_eq
, NULL
);
2979 if (g
->got_entries
== NULL
)
2989 /* Insert the GOT entry in the bfd's got entry hash table. */
2990 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
2991 if (*entryp
!= NULL
)
2996 if (entry
->tls_type
)
2998 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3000 if (entry
->tls_type
& GOT_TLS_IE
)
3003 else if (entry
->symndx
>= 0 || entry
->d
.h
->forced_local
)
3011 /* Attempt to merge gots of different input bfds. Try to use as much
3012 as possible of the primary got, since it doesn't require explicit
3013 dynamic relocations, but don't use bfds that would reference global
3014 symbols out of the addressable range. Failing the primary got,
3015 attempt to merge with the current got, or finish the current got
3016 and then make make the new got current. */
3019 mips_elf_merge_gots (void **bfd2got_
, void *p
)
3021 struct mips_elf_bfd2got_hash
*bfd2got
3022 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
3023 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3024 unsigned int lcount
= bfd2got
->g
->local_gotno
;
3025 unsigned int gcount
= bfd2got
->g
->global_gotno
;
3026 unsigned int tcount
= bfd2got
->g
->tls_gotno
;
3027 unsigned int maxcnt
= arg
->max_count
;
3028 bfd_boolean too_many_for_tls
= FALSE
;
3030 /* We place TLS GOT entries after both locals and globals. The globals
3031 for the primary GOT may overflow the normal GOT size limit, so be
3032 sure not to merge a GOT which requires TLS with the primary GOT in that
3033 case. This doesn't affect non-primary GOTs. */
3036 unsigned int primary_total
= lcount
+ tcount
+ arg
->global_count
;
3037 if (primary_total
* MIPS_ELF_GOT_SIZE (bfd2got
->bfd
)
3038 >= MIPS_ELF_GOT_MAX_SIZE (arg
->info
))
3039 too_many_for_tls
= TRUE
;
3042 /* If we don't have a primary GOT and this is not too big, use it as
3043 a starting point for the primary GOT. */
3044 if (! arg
->primary
&& lcount
+ gcount
+ tcount
<= maxcnt
3045 && ! too_many_for_tls
)
3047 arg
->primary
= bfd2got
->g
;
3048 arg
->primary_count
= lcount
+ gcount
;
3050 /* If it looks like we can merge this bfd's entries with those of
3051 the primary, merge them. The heuristics is conservative, but we
3052 don't have to squeeze it too hard. */
3053 else if (arg
->primary
&& ! too_many_for_tls
3054 && (arg
->primary_count
+ lcount
+ gcount
+ tcount
) <= maxcnt
)
3056 struct mips_got_info
*g
= bfd2got
->g
;
3057 int old_lcount
= arg
->primary
->local_gotno
;
3058 int old_gcount
= arg
->primary
->global_gotno
;
3059 int old_tcount
= arg
->primary
->tls_gotno
;
3061 bfd2got
->g
= arg
->primary
;
3063 htab_traverse (g
->got_entries
,
3064 mips_elf_make_got_per_bfd
,
3066 if (arg
->obfd
== NULL
)
3069 htab_delete (g
->got_entries
);
3070 /* We don't have to worry about releasing memory of the actual
3071 got entries, since they're all in the master got_entries hash
3074 BFD_ASSERT (old_lcount
+ lcount
>= arg
->primary
->local_gotno
);
3075 BFD_ASSERT (old_gcount
+ gcount
>= arg
->primary
->global_gotno
);
3076 BFD_ASSERT (old_tcount
+ tcount
>= arg
->primary
->tls_gotno
);
3078 arg
->primary_count
= arg
->primary
->local_gotno
3079 + arg
->primary
->global_gotno
+ arg
->primary
->tls_gotno
;
3081 /* If we can merge with the last-created got, do it. */
3082 else if (arg
->current
3083 && arg
->current_count
+ lcount
+ gcount
+ tcount
<= maxcnt
)
3085 struct mips_got_info
*g
= bfd2got
->g
;
3086 int old_lcount
= arg
->current
->local_gotno
;
3087 int old_gcount
= arg
->current
->global_gotno
;
3088 int old_tcount
= arg
->current
->tls_gotno
;
3090 bfd2got
->g
= arg
->current
;
3092 htab_traverse (g
->got_entries
,
3093 mips_elf_make_got_per_bfd
,
3095 if (arg
->obfd
== NULL
)
3098 htab_delete (g
->got_entries
);
3100 BFD_ASSERT (old_lcount
+ lcount
>= arg
->current
->local_gotno
);
3101 BFD_ASSERT (old_gcount
+ gcount
>= arg
->current
->global_gotno
);
3102 BFD_ASSERT (old_tcount
+ tcount
>= arg
->current
->tls_gotno
);
3104 arg
->current_count
= arg
->current
->local_gotno
3105 + arg
->current
->global_gotno
+ arg
->current
->tls_gotno
;
3107 /* Well, we couldn't merge, so create a new GOT. Don't check if it
3108 fits; if it turns out that it doesn't, we'll get relocation
3109 overflows anyway. */
3112 bfd2got
->g
->next
= arg
->current
;
3113 arg
->current
= bfd2got
->g
;
3115 arg
->current_count
= lcount
+ gcount
+ 2 * tcount
;
3121 /* Set the TLS GOT index for the GOT entry in ENTRYP. */
3124 mips_elf_initialize_tls_index (void **entryp
, void *p
)
3126 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3127 struct mips_got_info
*g
= p
;
3129 /* We're only interested in TLS symbols. */
3130 if (entry
->tls_type
== 0)
3133 if (entry
->symndx
== -1)
3135 /* There may be multiple mips_got_entry structs for a global variable
3136 if there is just one GOT. Just do this once. */
3137 if (g
->next
== NULL
)
3139 if (entry
->d
.h
->tls_type
& GOT_TLS_OFFSET_DONE
)
3141 entry
->gotidx
= entry
->d
.h
->tls_got_offset
;
3144 entry
->d
.h
->tls_type
|= GOT_TLS_OFFSET_DONE
;
3147 else if (entry
->tls_type
& GOT_TLS_LDM
)
3149 /* Similarly, there may be multiple structs for the LDM entry. */
3150 if (g
->tls_ldm_offset
!= MINUS_TWO
&& g
->tls_ldm_offset
!= MINUS_ONE
)
3152 entry
->gotidx
= g
->tls_ldm_offset
;
3157 /* Initialize the GOT offset. */
3158 entry
->gotidx
= MIPS_ELF_GOT_SIZE (entry
->abfd
) * (long) g
->tls_assigned_gotno
;
3159 if (g
->next
== NULL
&& entry
->symndx
== -1)
3160 entry
->d
.h
->tls_got_offset
= entry
->gotidx
;
3162 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3163 g
->tls_assigned_gotno
+= 2;
3164 if (entry
->tls_type
& GOT_TLS_IE
)
3165 g
->tls_assigned_gotno
+= 1;
3167 if (entry
->tls_type
& GOT_TLS_LDM
)
3168 g
->tls_ldm_offset
= entry
->gotidx
;
3173 /* If passed a NULL mips_got_info in the argument, set the marker used
3174 to tell whether a global symbol needs a got entry (in the primary
3175 got) to the given VALUE.
3177 If passed a pointer G to a mips_got_info in the argument (it must
3178 not be the primary GOT), compute the offset from the beginning of
3179 the (primary) GOT section to the entry in G corresponding to the
3180 global symbol. G's assigned_gotno must contain the index of the
3181 first available global GOT entry in G. VALUE must contain the size
3182 of a GOT entry in bytes. For each global GOT entry that requires a
3183 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
3184 marked as not eligible for lazy resolution through a function
3187 mips_elf_set_global_got_offset (void **entryp
, void *p
)
3189 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3190 struct mips_elf_set_global_got_offset_arg
*arg
3191 = (struct mips_elf_set_global_got_offset_arg
*)p
;
3192 struct mips_got_info
*g
= arg
->g
;
3194 if (g
&& entry
->tls_type
!= GOT_NORMAL
)
3195 arg
->needed_relocs
+=
3196 mips_tls_got_relocs (arg
->info
, entry
->tls_type
,
3197 entry
->symndx
== -1 ? &entry
->d
.h
->root
: NULL
);
3199 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1
3200 && entry
->d
.h
->root
.dynindx
!= -1
3201 && entry
->d
.h
->tls_type
== GOT_NORMAL
)
3205 BFD_ASSERT (g
->global_gotsym
== NULL
);
3207 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
3208 if (arg
->info
->shared
3209 || (elf_hash_table (arg
->info
)->dynamic_sections_created
3210 && entry
->d
.h
->root
.def_dynamic
3211 && !entry
->d
.h
->root
.def_regular
))
3212 ++arg
->needed_relocs
;
3215 entry
->d
.h
->root
.got
.offset
= arg
->value
;
3221 /* Mark any global symbols referenced in the GOT we are iterating over
3222 as inelligible for lazy resolution stubs. */
3224 mips_elf_set_no_stub (void **entryp
, void *p ATTRIBUTE_UNUSED
)
3226 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3228 if (entry
->abfd
!= NULL
3229 && entry
->symndx
== -1
3230 && entry
->d
.h
->root
.dynindx
!= -1)
3231 entry
->d
.h
->no_fn_stub
= TRUE
;
3236 /* Follow indirect and warning hash entries so that each got entry
3237 points to the final symbol definition. P must point to a pointer
3238 to the hash table we're traversing. Since this traversal may
3239 modify the hash table, we set this pointer to NULL to indicate
3240 we've made a potentially-destructive change to the hash table, so
3241 the traversal must be restarted. */
3243 mips_elf_resolve_final_got_entry (void **entryp
, void *p
)
3245 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3246 htab_t got_entries
= *(htab_t
*)p
;
3248 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3250 struct mips_elf_link_hash_entry
*h
= entry
->d
.h
;
3252 while (h
->root
.root
.type
== bfd_link_hash_indirect
3253 || h
->root
.root
.type
== bfd_link_hash_warning
)
3254 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3256 if (entry
->d
.h
== h
)
3261 /* If we can't find this entry with the new bfd hash, re-insert
3262 it, and get the traversal restarted. */
3263 if (! htab_find (got_entries
, entry
))
3265 htab_clear_slot (got_entries
, entryp
);
3266 entryp
= htab_find_slot (got_entries
, entry
, INSERT
);
3269 /* Abort the traversal, since the whole table may have
3270 moved, and leave it up to the parent to restart the
3272 *(htab_t
*)p
= NULL
;
3275 /* We might want to decrement the global_gotno count, but it's
3276 either too early or too late for that at this point. */
3282 /* Turn indirect got entries in a got_entries table into their final
3285 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
3291 got_entries
= g
->got_entries
;
3293 htab_traverse (got_entries
,
3294 mips_elf_resolve_final_got_entry
,
3297 while (got_entries
== NULL
);
3300 /* Return the offset of an input bfd IBFD's GOT from the beginning of
3303 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
3305 if (g
->bfd2got
== NULL
)
3308 g
= mips_elf_got_for_ibfd (g
, ibfd
);
3312 BFD_ASSERT (g
->next
);
3316 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
3317 * MIPS_ELF_GOT_SIZE (abfd
);
3320 /* Turn a single GOT that is too big for 16-bit addressing into
3321 a sequence of GOTs, each one 16-bit addressable. */
3324 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
3325 struct mips_got_info
*g
, asection
*got
,
3326 bfd_size_type pages
)
3328 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
3329 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
3330 struct mips_got_info
*gg
;
3331 unsigned int assign
;
3333 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
3334 mips_elf_bfd2got_entry_eq
, NULL
);
3335 if (g
->bfd2got
== NULL
)
3338 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
3339 got_per_bfd_arg
.obfd
= abfd
;
3340 got_per_bfd_arg
.info
= info
;
3342 /* Count how many GOT entries each input bfd requires, creating a
3343 map from bfd to got info while at that. */
3344 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
3345 if (got_per_bfd_arg
.obfd
== NULL
)
3348 got_per_bfd_arg
.current
= NULL
;
3349 got_per_bfd_arg
.primary
= NULL
;
3350 /* Taking out PAGES entries is a worst-case estimate. We could
3351 compute the maximum number of pages that each separate input bfd
3352 uses, but it's probably not worth it. */
3353 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
3354 / MIPS_ELF_GOT_SIZE (abfd
))
3355 - MIPS_RESERVED_GOTNO (info
) - pages
);
3356 /* The number of globals that will be included in the primary GOT.
3357 See the calls to mips_elf_set_global_got_offset below for more
3359 got_per_bfd_arg
.global_count
= g
->global_gotno
;
3361 /* Try to merge the GOTs of input bfds together, as long as they
3362 don't seem to exceed the maximum GOT size, choosing one of them
3363 to be the primary GOT. */
3364 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
3365 if (got_per_bfd_arg
.obfd
== NULL
)
3368 /* If we do not find any suitable primary GOT, create an empty one. */
3369 if (got_per_bfd_arg
.primary
== NULL
)
3371 g
->next
= (struct mips_got_info
*)
3372 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
3373 if (g
->next
== NULL
)
3376 g
->next
->global_gotsym
= NULL
;
3377 g
->next
->global_gotno
= 0;
3378 g
->next
->local_gotno
= 0;
3379 g
->next
->tls_gotno
= 0;
3380 g
->next
->assigned_gotno
= 0;
3381 g
->next
->tls_assigned_gotno
= 0;
3382 g
->next
->tls_ldm_offset
= MINUS_ONE
;
3383 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3384 mips_elf_multi_got_entry_eq
,
3386 if (g
->next
->got_entries
== NULL
)
3388 g
->next
->bfd2got
= NULL
;
3391 g
->next
= got_per_bfd_arg
.primary
;
3392 g
->next
->next
= got_per_bfd_arg
.current
;
3394 /* GG is now the master GOT, and G is the primary GOT. */
3398 /* Map the output bfd to the primary got. That's what we're going
3399 to use for bfds that use GOT16 or GOT_PAGE relocations that we
3400 didn't mark in check_relocs, and we want a quick way to find it.
3401 We can't just use gg->next because we're going to reverse the
3404 struct mips_elf_bfd2got_hash
*bfdgot
;
3407 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
3408 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
3415 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
3417 BFD_ASSERT (*bfdgotp
== NULL
);
3421 /* The IRIX dynamic linker requires every symbol that is referenced
3422 in a dynamic relocation to be present in the primary GOT, so
3423 arrange for them to appear after those that are actually
3426 GNU/Linux could very well do without it, but it would slow down
3427 the dynamic linker, since it would have to resolve every dynamic
3428 symbol referenced in other GOTs more than once, without help from
3429 the cache. Also, knowing that every external symbol has a GOT
3430 helps speed up the resolution of local symbols too, so GNU/Linux
3431 follows IRIX's practice.
3433 The number 2 is used by mips_elf_sort_hash_table_f to count
3434 global GOT symbols that are unreferenced in the primary GOT, with
3435 an initial dynamic index computed from gg->assigned_gotno, where
3436 the number of unreferenced global entries in the primary GOT is
3440 gg
->assigned_gotno
= gg
->global_gotno
- g
->global_gotno
;
3441 g
->global_gotno
= gg
->global_gotno
;
3442 set_got_offset_arg
.value
= 2;
3446 /* This could be used for dynamic linkers that don't optimize
3447 symbol resolution while applying relocations so as to use
3448 primary GOT entries or assuming the symbol is locally-defined.
3449 With this code, we assign lower dynamic indices to global
3450 symbols that are not referenced in the primary GOT, so that
3451 their entries can be omitted. */
3452 gg
->assigned_gotno
= 0;
3453 set_got_offset_arg
.value
= -1;
3456 /* Reorder dynamic symbols as described above (which behavior
3457 depends on the setting of VALUE). */
3458 set_got_offset_arg
.g
= NULL
;
3459 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
3460 &set_got_offset_arg
);
3461 set_got_offset_arg
.value
= 1;
3462 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
3463 &set_got_offset_arg
);
3464 if (! mips_elf_sort_hash_table (info
, 1))
3467 /* Now go through the GOTs assigning them offset ranges.
3468 [assigned_gotno, local_gotno[ will be set to the range of local
3469 entries in each GOT. We can then compute the end of a GOT by
3470 adding local_gotno to global_gotno. We reverse the list and make
3471 it circular since then we'll be able to quickly compute the
3472 beginning of a GOT, by computing the end of its predecessor. To
3473 avoid special cases for the primary GOT, while still preserving
3474 assertions that are valid for both single- and multi-got links,
3475 we arrange for the main got struct to have the right number of
3476 global entries, but set its local_gotno such that the initial
3477 offset of the primary GOT is zero. Remember that the primary GOT
3478 will become the last item in the circular linked list, so it
3479 points back to the master GOT. */
3480 gg
->local_gotno
= -g
->global_gotno
;
3481 gg
->global_gotno
= g
->global_gotno
;
3488 struct mips_got_info
*gn
;
3490 assign
+= MIPS_RESERVED_GOTNO (info
);
3491 g
->assigned_gotno
= assign
;
3492 g
->local_gotno
+= assign
+ pages
;
3493 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
3495 /* Set up any TLS entries. We always place the TLS entries after
3496 all non-TLS entries. */
3497 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
3498 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
3500 /* Take g out of the direct list, and push it onto the reversed
3501 list that gg points to. */
3507 /* Mark global symbols in every non-primary GOT as ineligible for
3510 htab_traverse (g
->got_entries
, mips_elf_set_no_stub
, NULL
);
3514 got
->size
= (gg
->next
->local_gotno
3515 + gg
->next
->global_gotno
3516 + gg
->next
->tls_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
3522 /* Returns the first relocation of type r_type found, beginning with
3523 RELOCATION. RELEND is one-past-the-end of the relocation table. */
3525 static const Elf_Internal_Rela
*
3526 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
3527 const Elf_Internal_Rela
*relocation
,
3528 const Elf_Internal_Rela
*relend
)
3530 while (relocation
< relend
)
3532 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
)
3538 /* We didn't find it. */
3539 bfd_set_error (bfd_error_bad_value
);
3543 /* Return whether a relocation is against a local symbol. */
3546 mips_elf_local_relocation_p (bfd
*input_bfd
,
3547 const Elf_Internal_Rela
*relocation
,
3548 asection
**local_sections
,
3549 bfd_boolean check_forced
)
3551 unsigned long r_symndx
;
3552 Elf_Internal_Shdr
*symtab_hdr
;
3553 struct mips_elf_link_hash_entry
*h
;
3556 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
3557 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3558 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
3560 if (r_symndx
< extsymoff
)
3562 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
3567 /* Look up the hash table to check whether the symbol
3568 was forced local. */
3569 h
= (struct mips_elf_link_hash_entry
*)
3570 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
3571 /* Find the real hash-table entry for this symbol. */
3572 while (h
->root
.root
.type
== bfd_link_hash_indirect
3573 || h
->root
.root
.type
== bfd_link_hash_warning
)
3574 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3575 if (h
->root
.forced_local
)
3582 /* Sign-extend VALUE, which has the indicated number of BITS. */
3585 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
3587 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
3588 /* VALUE is negative. */
3589 value
|= ((bfd_vma
) - 1) << bits
;
3594 /* Return non-zero if the indicated VALUE has overflowed the maximum
3595 range expressible by a signed number with the indicated number of
3599 mips_elf_overflow_p (bfd_vma value
, int bits
)
3601 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
3603 if (svalue
> (1 << (bits
- 1)) - 1)
3604 /* The value is too big. */
3606 else if (svalue
< -(1 << (bits
- 1)))
3607 /* The value is too small. */
3614 /* Calculate the %high function. */
3617 mips_elf_high (bfd_vma value
)
3619 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
3622 /* Calculate the %higher function. */
3625 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
3628 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
3635 /* Calculate the %highest function. */
3638 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
3641 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
3648 /* Create the .compact_rel section. */
3651 mips_elf_create_compact_rel_section
3652 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3655 register asection
*s
;
3657 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
3659 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
3662 s
= bfd_make_section_with_flags (abfd
, ".compact_rel", flags
);
3664 || ! bfd_set_section_alignment (abfd
, s
,
3665 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
3668 s
->size
= sizeof (Elf32_External_compact_rel
);
3674 /* Create the .got section to hold the global offset table. */
3677 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
,
3678 bfd_boolean maybe_exclude
)
3681 register asection
*s
;
3682 struct elf_link_hash_entry
*h
;
3683 struct bfd_link_hash_entry
*bh
;
3684 struct mips_got_info
*g
;
3686 struct mips_elf_link_hash_table
*htab
;
3688 htab
= mips_elf_hash_table (info
);
3690 /* This function may be called more than once. */
3691 s
= mips_elf_got_section (abfd
, TRUE
);
3694 if (! maybe_exclude
)
3695 s
->flags
&= ~SEC_EXCLUDE
;
3699 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3700 | SEC_LINKER_CREATED
);
3703 flags
|= SEC_EXCLUDE
;
3705 /* We have to use an alignment of 2**4 here because this is hardcoded
3706 in the function stub generation and in the linker script. */
3707 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
3709 || ! bfd_set_section_alignment (abfd
, s
, 4))
3712 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
3713 linker script because we don't want to define the symbol if we
3714 are not creating a global offset table. */
3716 if (! (_bfd_generic_link_add_one_symbol
3717 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
3718 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
3721 h
= (struct elf_link_hash_entry
*) bh
;
3724 h
->type
= STT_OBJECT
;
3725 elf_hash_table (info
)->hgot
= h
;
3728 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3731 amt
= sizeof (struct mips_got_info
);
3732 g
= bfd_alloc (abfd
, amt
);
3735 g
->global_gotsym
= NULL
;
3736 g
->global_gotno
= 0;
3738 g
->local_gotno
= MIPS_RESERVED_GOTNO (info
);
3739 g
->assigned_gotno
= MIPS_RESERVED_GOTNO (info
);
3742 g
->tls_ldm_offset
= MINUS_ONE
;
3743 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
3744 mips_elf_got_entry_eq
, NULL
);
3745 if (g
->got_entries
== NULL
)
3747 mips_elf_section_data (s
)->u
.got_info
= g
;
3748 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
3749 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3751 /* VxWorks also needs a .got.plt section. */
3752 if (htab
->is_vxworks
)
3754 s
= bfd_make_section_with_flags (abfd
, ".got.plt",
3755 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
3756 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3757 if (s
== NULL
|| !bfd_set_section_alignment (abfd
, s
, 4))
3765 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
3766 __GOTT_INDEX__ symbols. These symbols are only special for
3767 shared objects; they are not used in executables. */
3770 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
3772 return (mips_elf_hash_table (info
)->is_vxworks
3774 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
3775 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
3778 /* Calculate the value produced by the RELOCATION (which comes from
3779 the INPUT_BFD). The ADDEND is the addend to use for this
3780 RELOCATION; RELOCATION->R_ADDEND is ignored.
3782 The result of the relocation calculation is stored in VALUEP.
3783 REQUIRE_JALXP indicates whether or not the opcode used with this
3784 relocation must be JALX.
3786 This function returns bfd_reloc_continue if the caller need take no
3787 further action regarding this relocation, bfd_reloc_notsupported if
3788 something goes dramatically wrong, bfd_reloc_overflow if an
3789 overflow occurs, and bfd_reloc_ok to indicate success. */
3791 static bfd_reloc_status_type
3792 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
3793 asection
*input_section
,
3794 struct bfd_link_info
*info
,
3795 const Elf_Internal_Rela
*relocation
,
3796 bfd_vma addend
, reloc_howto_type
*howto
,
3797 Elf_Internal_Sym
*local_syms
,
3798 asection
**local_sections
, bfd_vma
*valuep
,
3799 const char **namep
, bfd_boolean
*require_jalxp
,
3800 bfd_boolean save_addend
)
3802 /* The eventual value we will return. */
3804 /* The address of the symbol against which the relocation is
3807 /* The final GP value to be used for the relocatable, executable, or
3808 shared object file being produced. */
3809 bfd_vma gp
= MINUS_ONE
;
3810 /* The place (section offset or address) of the storage unit being
3813 /* The value of GP used to create the relocatable object. */
3814 bfd_vma gp0
= MINUS_ONE
;
3815 /* The offset into the global offset table at which the address of
3816 the relocation entry symbol, adjusted by the addend, resides
3817 during execution. */
3818 bfd_vma g
= MINUS_ONE
;
3819 /* The section in which the symbol referenced by the relocation is
3821 asection
*sec
= NULL
;
3822 struct mips_elf_link_hash_entry
*h
= NULL
;
3823 /* TRUE if the symbol referred to by this relocation is a local
3825 bfd_boolean local_p
, was_local_p
;
3826 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
3827 bfd_boolean gp_disp_p
= FALSE
;
3828 /* TRUE if the symbol referred to by this relocation is
3829 "__gnu_local_gp". */
3830 bfd_boolean gnu_local_gp_p
= FALSE
;
3831 Elf_Internal_Shdr
*symtab_hdr
;
3833 unsigned long r_symndx
;
3835 /* TRUE if overflow occurred during the calculation of the
3836 relocation value. */
3837 bfd_boolean overflowed_p
;
3838 /* TRUE if this relocation refers to a MIPS16 function. */
3839 bfd_boolean target_is_16_bit_code_p
= FALSE
;
3840 struct mips_elf_link_hash_table
*htab
;
3843 dynobj
= elf_hash_table (info
)->dynobj
;
3844 htab
= mips_elf_hash_table (info
);
3846 /* Parse the relocation. */
3847 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
3848 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
3849 p
= (input_section
->output_section
->vma
3850 + input_section
->output_offset
3851 + relocation
->r_offset
);
3853 /* Assume that there will be no overflow. */
3854 overflowed_p
= FALSE
;
3856 /* Figure out whether or not the symbol is local, and get the offset
3857 used in the array of hash table entries. */
3858 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3859 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
3860 local_sections
, FALSE
);
3861 was_local_p
= local_p
;
3862 if (! elf_bad_symtab (input_bfd
))
3863 extsymoff
= symtab_hdr
->sh_info
;
3866 /* The symbol table does not follow the rule that local symbols
3867 must come before globals. */
3871 /* Figure out the value of the symbol. */
3874 Elf_Internal_Sym
*sym
;
3876 sym
= local_syms
+ r_symndx
;
3877 sec
= local_sections
[r_symndx
];
3879 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
3880 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
3881 || (sec
->flags
& SEC_MERGE
))
3882 symbol
+= sym
->st_value
;
3883 if ((sec
->flags
& SEC_MERGE
)
3884 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3886 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
3888 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
3891 /* MIPS16 text labels should be treated as odd. */
3892 if (sym
->st_other
== STO_MIPS16
)
3895 /* Record the name of this symbol, for our caller. */
3896 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
3897 symtab_hdr
->sh_link
,
3900 *namep
= bfd_section_name (input_bfd
, sec
);
3902 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
3906 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
3908 /* For global symbols we look up the symbol in the hash-table. */
3909 h
= ((struct mips_elf_link_hash_entry
*)
3910 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
3911 /* Find the real hash-table entry for this symbol. */
3912 while (h
->root
.root
.type
== bfd_link_hash_indirect
3913 || h
->root
.root
.type
== bfd_link_hash_warning
)
3914 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3916 /* Record the name of this symbol, for our caller. */
3917 *namep
= h
->root
.root
.root
.string
;
3919 /* See if this is the special _gp_disp symbol. Note that such a
3920 symbol must always be a global symbol. */
3921 if (strcmp (*namep
, "_gp_disp") == 0
3922 && ! NEWABI_P (input_bfd
))
3924 /* Relocations against _gp_disp are permitted only with
3925 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
3926 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
3927 && r_type
!= R_MIPS16_HI16
&& r_type
!= R_MIPS16_LO16
)
3928 return bfd_reloc_notsupported
;
3932 /* See if this is the special _gp symbol. Note that such a
3933 symbol must always be a global symbol. */
3934 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
3935 gnu_local_gp_p
= TRUE
;
3938 /* If this symbol is defined, calculate its address. Note that
3939 _gp_disp is a magic symbol, always implicitly defined by the
3940 linker, so it's inappropriate to check to see whether or not
3942 else if ((h
->root
.root
.type
== bfd_link_hash_defined
3943 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3944 && h
->root
.root
.u
.def
.section
)
3946 sec
= h
->root
.root
.u
.def
.section
;
3947 if (sec
->output_section
)
3948 symbol
= (h
->root
.root
.u
.def
.value
3949 + sec
->output_section
->vma
3950 + sec
->output_offset
);
3952 symbol
= h
->root
.root
.u
.def
.value
;
3954 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
3955 /* We allow relocations against undefined weak symbols, giving
3956 it the value zero, so that you can undefined weak functions
3957 and check to see if they exist by looking at their
3960 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
3961 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
3963 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
3964 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
3966 /* If this is a dynamic link, we should have created a
3967 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
3968 in in _bfd_mips_elf_create_dynamic_sections.
3969 Otherwise, we should define the symbol with a value of 0.
3970 FIXME: It should probably get into the symbol table
3972 BFD_ASSERT (! info
->shared
);
3973 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
3976 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
3978 /* This is an optional symbol - an Irix specific extension to the
3979 ELF spec. Ignore it for now.
3980 XXX - FIXME - there is more to the spec for OPTIONAL symbols
3981 than simply ignoring them, but we do not handle this for now.
3982 For information see the "64-bit ELF Object File Specification"
3983 which is available from here:
3984 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
3989 if (! ((*info
->callbacks
->undefined_symbol
)
3990 (info
, h
->root
.root
.root
.string
, input_bfd
,
3991 input_section
, relocation
->r_offset
,
3992 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
3993 || ELF_ST_VISIBILITY (h
->root
.other
))))
3994 return bfd_reloc_undefined
;
3998 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
4001 /* If this is a 32- or 64-bit call to a 16-bit function with a stub, we
4002 need to redirect the call to the stub, unless we're already *in*
4004 if (r_type
!= R_MIPS16_26
&& !info
->relocatable
4005 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
4006 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
4007 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
4008 && !mips_elf_stub_section_p (input_bfd
, input_section
))
4010 /* This is a 32- or 64-bit call to a 16-bit function. We should
4011 have already noticed that we were going to need the
4014 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
4017 BFD_ASSERT (h
->need_fn_stub
);
4021 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4023 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
4024 need to redirect the call to the stub. */
4025 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
4027 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
4028 && !target_is_16_bit_code_p
)
4030 /* If both call_stub and call_fp_stub are defined, we can figure
4031 out which one to use by seeing which one appears in the input
4033 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
4038 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4040 if (strncmp (bfd_get_section_name (input_bfd
, o
),
4041 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4043 sec
= h
->call_fp_stub
;
4050 else if (h
->call_stub
!= NULL
)
4053 sec
= h
->call_fp_stub
;
4055 BFD_ASSERT (sec
->size
> 0);
4056 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4059 /* Calls from 16-bit code to 32-bit code and vice versa require the
4060 special jalx instruction. */
4061 *require_jalxp
= (!info
->relocatable
4062 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
4063 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
4065 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4066 local_sections
, TRUE
);
4068 /* If we haven't already determined the GOT offset, or the GP value,
4069 and we're going to need it, get it now. */
4072 case R_MIPS_GOT_PAGE
:
4073 case R_MIPS_GOT_OFST
:
4074 /* We need to decay to GOT_DISP/addend if the symbol doesn't
4076 local_p
= local_p
|| _bfd_elf_symbol_refs_local_p (&h
->root
, info
, 1);
4077 if (local_p
|| r_type
== R_MIPS_GOT_OFST
)
4083 case R_MIPS_GOT_DISP
:
4084 case R_MIPS_GOT_HI16
:
4085 case R_MIPS_CALL_HI16
:
4086 case R_MIPS_GOT_LO16
:
4087 case R_MIPS_CALL_LO16
:
4089 case R_MIPS_TLS_GOTTPREL
:
4090 case R_MIPS_TLS_LDM
:
4091 /* Find the index into the GOT where this value is located. */
4092 if (r_type
== R_MIPS_TLS_LDM
)
4094 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
4095 sec
, 0, 0, NULL
, r_type
);
4097 return bfd_reloc_outofrange
;
4101 /* On VxWorks, CALL relocations should refer to the .got.plt
4102 entry, which is initialized to point at the PLT stub. */
4103 if (htab
->is_vxworks
4104 && (r_type
== R_MIPS_CALL_HI16
4105 || r_type
== R_MIPS_CALL_LO16
4106 || r_type
== R_MIPS_CALL16
))
4108 BFD_ASSERT (addend
== 0);
4109 BFD_ASSERT (h
->root
.needs_plt
);
4110 g
= mips_elf_gotplt_index (info
, &h
->root
);
4114 /* GOT_PAGE may take a non-zero addend, that is ignored in a
4115 GOT_PAGE relocation that decays to GOT_DISP because the
4116 symbol turns out to be global. The addend is then added
4118 BFD_ASSERT (addend
== 0 || r_type
== R_MIPS_GOT_PAGE
);
4119 g
= mips_elf_global_got_index (dynobj
, input_bfd
,
4120 &h
->root
, r_type
, info
);
4121 if (h
->tls_type
== GOT_NORMAL
4122 && (! elf_hash_table(info
)->dynamic_sections_created
4124 && (info
->symbolic
|| h
->root
.forced_local
)
4125 && h
->root
.def_regular
)))
4127 /* This is a static link or a -Bsymbolic link. The
4128 symbol is defined locally, or was forced to be local.
4129 We must initialize this entry in the GOT. */
4130 asection
*sgot
= mips_elf_got_section (dynobj
, FALSE
);
4131 MIPS_ELF_PUT_WORD (dynobj
, symbol
, sgot
->contents
+ g
);
4135 else if (!htab
->is_vxworks
4136 && (r_type
== R_MIPS_CALL16
|| (r_type
== R_MIPS_GOT16
)))
4137 /* The calculation below does not involve "g". */
4141 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
, sec
,
4142 symbol
+ addend
, r_symndx
, h
, r_type
);
4144 return bfd_reloc_outofrange
;
4147 /* Convert GOT indices to actual offsets. */
4148 g
= mips_elf_got_offset_from_index (dynobj
, abfd
, input_bfd
, g
);
4153 case R_MIPS_GPREL16
:
4154 case R_MIPS_GPREL32
:
4155 case R_MIPS_LITERAL
:
4158 case R_MIPS16_GPREL
:
4159 gp0
= _bfd_get_gp_value (input_bfd
);
4160 gp
= _bfd_get_gp_value (abfd
);
4162 gp
+= mips_elf_adjust_gp (abfd
, mips_elf_got_info (dynobj
, NULL
),
4173 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
4174 symbols are resolved by the loader. Add them to .rela.dyn. */
4175 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
4177 Elf_Internal_Rela outrel
;
4181 s
= mips_elf_rel_dyn_section (info
, FALSE
);
4182 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4184 outrel
.r_offset
= (input_section
->output_section
->vma
4185 + input_section
->output_offset
4186 + relocation
->r_offset
);
4187 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
4188 outrel
.r_addend
= addend
;
4189 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
4191 return bfd_reloc_ok
;
4194 /* Figure out what kind of relocation is being performed. */
4198 return bfd_reloc_continue
;
4201 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
4202 overflowed_p
= mips_elf_overflow_p (value
, 16);
4209 || (!htab
->is_vxworks
4210 && htab
->root
.dynamic_sections_created
4212 && h
->root
.def_dynamic
4213 && !h
->root
.def_regular
))
4215 && (input_section
->flags
& SEC_ALLOC
) != 0)
4217 /* If we're creating a shared library, or this relocation is
4218 against a symbol in a shared library, then we can't know
4219 where the symbol will end up. So, we create a relocation
4220 record in the output, and leave the job up to the dynamic
4223 In VxWorks executables, references to external symbols
4224 are handled using copy relocs or PLT stubs, so there's
4225 no need to add a dynamic relocation here. */
4227 if (!mips_elf_create_dynamic_relocation (abfd
,
4235 return bfd_reloc_undefined
;
4239 if (r_type
!= R_MIPS_REL32
)
4240 value
= symbol
+ addend
;
4244 value
&= howto
->dst_mask
;
4248 value
= symbol
+ addend
- p
;
4249 value
&= howto
->dst_mask
;
4253 /* The calculation for R_MIPS16_26 is just the same as for an
4254 R_MIPS_26. It's only the storage of the relocated field into
4255 the output file that's different. That's handled in
4256 mips_elf_perform_relocation. So, we just fall through to the
4257 R_MIPS_26 case here. */
4260 value
= ((addend
| ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
4263 value
= (_bfd_mips_elf_sign_extend (addend
, 28) + symbol
) >> 2;
4264 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
)
4265 overflowed_p
= (value
>> 26) != ((p
+ 4) >> 28);
4267 value
&= howto
->dst_mask
;
4270 case R_MIPS_TLS_DTPREL_HI16
:
4271 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
4275 case R_MIPS_TLS_DTPREL_LO16
:
4276 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
4279 case R_MIPS_TLS_TPREL_HI16
:
4280 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
4284 case R_MIPS_TLS_TPREL_LO16
:
4285 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
4292 value
= mips_elf_high (addend
+ symbol
);
4293 value
&= howto
->dst_mask
;
4297 /* For MIPS16 ABI code we generate this sequence
4298 0: li $v0,%hi(_gp_disp)
4299 4: addiupc $v1,%lo(_gp_disp)
4303 So the offsets of hi and lo relocs are the same, but the
4304 $pc is four higher than $t9 would be, so reduce
4305 both reloc addends by 4. */
4306 if (r_type
== R_MIPS16_HI16
)
4307 value
= mips_elf_high (addend
+ gp
- p
- 4);
4309 value
= mips_elf_high (addend
+ gp
- p
);
4310 overflowed_p
= mips_elf_overflow_p (value
, 16);
4317 value
= (symbol
+ addend
) & howto
->dst_mask
;
4320 /* See the comment for R_MIPS16_HI16 above for the reason
4321 for this conditional. */
4322 if (r_type
== R_MIPS16_LO16
)
4323 value
= addend
+ gp
- p
;
4325 value
= addend
+ gp
- p
+ 4;
4326 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
4327 for overflow. But, on, say, IRIX5, relocations against
4328 _gp_disp are normally generated from the .cpload
4329 pseudo-op. It generates code that normally looks like
4332 lui $gp,%hi(_gp_disp)
4333 addiu $gp,$gp,%lo(_gp_disp)
4336 Here $t9 holds the address of the function being called,
4337 as required by the MIPS ELF ABI. The R_MIPS_LO16
4338 relocation can easily overflow in this situation, but the
4339 R_MIPS_HI16 relocation will handle the overflow.
4340 Therefore, we consider this a bug in the MIPS ABI, and do
4341 not check for overflow here. */
4345 case R_MIPS_LITERAL
:
4346 /* Because we don't merge literal sections, we can handle this
4347 just like R_MIPS_GPREL16. In the long run, we should merge
4348 shared literals, and then we will need to additional work
4353 case R_MIPS16_GPREL
:
4354 /* The R_MIPS16_GPREL performs the same calculation as
4355 R_MIPS_GPREL16, but stores the relocated bits in a different
4356 order. We don't need to do anything special here; the
4357 differences are handled in mips_elf_perform_relocation. */
4358 case R_MIPS_GPREL16
:
4359 /* Only sign-extend the addend if it was extracted from the
4360 instruction. If the addend was separate, leave it alone,
4361 otherwise we may lose significant bits. */
4362 if (howto
->partial_inplace
)
4363 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
4364 value
= symbol
+ addend
- gp
;
4365 /* If the symbol was local, any earlier relocatable links will
4366 have adjusted its addend with the gp offset, so compensate
4367 for that now. Don't do it for symbols forced local in this
4368 link, though, since they won't have had the gp offset applied
4372 overflowed_p
= mips_elf_overflow_p (value
, 16);
4377 /* VxWorks does not have separate local and global semantics for
4378 R_MIPS_GOT16; every relocation evaluates to "G". */
4379 if (!htab
->is_vxworks
&& local_p
)
4383 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
4384 local_sections
, FALSE
);
4385 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
, sec
,
4386 symbol
+ addend
, forced
);
4387 if (value
== MINUS_ONE
)
4388 return bfd_reloc_outofrange
;
4390 = mips_elf_got_offset_from_index (dynobj
, abfd
, input_bfd
, value
);
4391 overflowed_p
= mips_elf_overflow_p (value
, 16);
4398 case R_MIPS_TLS_GOTTPREL
:
4399 case R_MIPS_TLS_LDM
:
4400 case R_MIPS_GOT_DISP
:
4403 overflowed_p
= mips_elf_overflow_p (value
, 16);
4406 case R_MIPS_GPREL32
:
4407 value
= (addend
+ symbol
+ gp0
- gp
);
4409 value
&= howto
->dst_mask
;
4413 case R_MIPS_GNU_REL16_S2
:
4414 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
4415 overflowed_p
= mips_elf_overflow_p (value
, 18);
4416 value
= (value
>> 2) & howto
->dst_mask
;
4419 case R_MIPS_GOT_HI16
:
4420 case R_MIPS_CALL_HI16
:
4421 /* We're allowed to handle these two relocations identically.
4422 The dynamic linker is allowed to handle the CALL relocations
4423 differently by creating a lazy evaluation stub. */
4425 value
= mips_elf_high (value
);
4426 value
&= howto
->dst_mask
;
4429 case R_MIPS_GOT_LO16
:
4430 case R_MIPS_CALL_LO16
:
4431 value
= g
& howto
->dst_mask
;
4434 case R_MIPS_GOT_PAGE
:
4435 /* GOT_PAGE relocations that reference non-local symbols decay
4436 to GOT_DISP. The corresponding GOT_OFST relocation decays to
4440 value
= mips_elf_got_page (abfd
, input_bfd
, info
, sec
,
4441 symbol
+ addend
, NULL
);
4442 if (value
== MINUS_ONE
)
4443 return bfd_reloc_outofrange
;
4444 value
= mips_elf_got_offset_from_index (dynobj
, abfd
, input_bfd
, value
);
4445 overflowed_p
= mips_elf_overflow_p (value
, 16);
4448 case R_MIPS_GOT_OFST
:
4450 mips_elf_got_page (abfd
, input_bfd
, info
, sec
,
4451 symbol
+ addend
, &value
);
4454 overflowed_p
= mips_elf_overflow_p (value
, 16);
4458 value
= symbol
- addend
;
4459 value
&= howto
->dst_mask
;
4463 value
= mips_elf_higher (addend
+ symbol
);
4464 value
&= howto
->dst_mask
;
4467 case R_MIPS_HIGHEST
:
4468 value
= mips_elf_highest (addend
+ symbol
);
4469 value
&= howto
->dst_mask
;
4472 case R_MIPS_SCN_DISP
:
4473 value
= symbol
+ addend
- sec
->output_offset
;
4474 value
&= howto
->dst_mask
;
4478 /* This relocation is only a hint. In some cases, we optimize
4479 it into a bal instruction. But we don't try to optimize
4480 branches to the PLT; that will wind up wasting time. */
4481 if (h
!= NULL
&& h
->root
.plt
.offset
!= (bfd_vma
) -1)
4482 return bfd_reloc_continue
;
4483 value
= symbol
+ addend
;
4487 case R_MIPS_GNU_VTINHERIT
:
4488 case R_MIPS_GNU_VTENTRY
:
4489 /* We don't do anything with these at present. */
4490 return bfd_reloc_continue
;
4493 /* An unrecognized relocation type. */
4494 return bfd_reloc_notsupported
;
4497 /* Store the VALUE for our caller. */
4499 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
4502 /* Obtain the field relocated by RELOCATION. */
4505 mips_elf_obtain_contents (reloc_howto_type
*howto
,
4506 const Elf_Internal_Rela
*relocation
,
4507 bfd
*input_bfd
, bfd_byte
*contents
)
4510 bfd_byte
*location
= contents
+ relocation
->r_offset
;
4512 /* Obtain the bytes. */
4513 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
4518 /* It has been determined that the result of the RELOCATION is the
4519 VALUE. Use HOWTO to place VALUE into the output file at the
4520 appropriate position. The SECTION is the section to which the
4521 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
4522 for the relocation must be either JAL or JALX, and it is
4523 unconditionally converted to JALX.
4525 Returns FALSE if anything goes wrong. */
4528 mips_elf_perform_relocation (struct bfd_link_info
*info
,
4529 reloc_howto_type
*howto
,
4530 const Elf_Internal_Rela
*relocation
,
4531 bfd_vma value
, bfd
*input_bfd
,
4532 asection
*input_section
, bfd_byte
*contents
,
4533 bfd_boolean require_jalx
)
4537 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4539 /* Figure out where the relocation is occurring. */
4540 location
= contents
+ relocation
->r_offset
;
4542 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
4544 /* Obtain the current value. */
4545 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
4547 /* Clear the field we are setting. */
4548 x
&= ~howto
->dst_mask
;
4550 /* Set the field. */
4551 x
|= (value
& howto
->dst_mask
);
4553 /* If required, turn JAL into JALX. */
4557 bfd_vma opcode
= x
>> 26;
4558 bfd_vma jalx_opcode
;
4560 /* Check to see if the opcode is already JAL or JALX. */
4561 if (r_type
== R_MIPS16_26
)
4563 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
4568 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
4572 /* If the opcode is not JAL or JALX, there's a problem. */
4575 (*_bfd_error_handler
)
4576 (_("%B: %A+0x%lx: jump to stub routine which is not jal"),
4579 (unsigned long) relocation
->r_offset
);
4580 bfd_set_error (bfd_error_bad_value
);
4584 /* Make this the JALX opcode. */
4585 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4588 /* On the RM9000, bal is faster than jal, because bal uses branch
4589 prediction hardware. If we are linking for the RM9000, and we
4590 see jal, and bal fits, use it instead. Note that this
4591 transformation should be safe for all architectures. */
4592 if (bfd_get_mach (input_bfd
) == bfd_mach_mips9000
4593 && !info
->relocatable
4595 && ((r_type
== R_MIPS_26
&& (x
>> 26) == 0x3) /* jal addr */
4596 || (r_type
== R_MIPS_JALR
&& x
== 0x0320f809))) /* jalr t9 */
4602 addr
= (input_section
->output_section
->vma
4603 + input_section
->output_offset
4604 + relocation
->r_offset
4606 if (r_type
== R_MIPS_26
)
4607 dest
= (value
<< 2) | ((addr
>> 28) << 28);
4611 if (off
<= 0x1ffff && off
>= -0x20000)
4612 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
4615 /* Put the value into the output. */
4616 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
4618 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, !info
->relocatable
,
4624 /* Returns TRUE if SECTION is a MIPS16 stub section. */
4627 mips_elf_stub_section_p (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
)
4629 const char *name
= bfd_get_section_name (abfd
, section
);
4631 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
4632 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
4633 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
4636 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
4639 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
4643 struct mips_elf_link_hash_table
*htab
;
4645 htab
= mips_elf_hash_table (info
);
4646 s
= mips_elf_rel_dyn_section (info
, FALSE
);
4647 BFD_ASSERT (s
!= NULL
);
4649 if (htab
->is_vxworks
)
4650 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
4655 /* Make room for a null element. */
4656 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
4659 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
4663 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
4664 is the original relocation, which is now being transformed into a
4665 dynamic relocation. The ADDENDP is adjusted if necessary; the
4666 caller should store the result in place of the original addend. */
4669 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
4670 struct bfd_link_info
*info
,
4671 const Elf_Internal_Rela
*rel
,
4672 struct mips_elf_link_hash_entry
*h
,
4673 asection
*sec
, bfd_vma symbol
,
4674 bfd_vma
*addendp
, asection
*input_section
)
4676 Elf_Internal_Rela outrel
[3];
4681 bfd_boolean defined_p
;
4682 struct mips_elf_link_hash_table
*htab
;
4684 htab
= mips_elf_hash_table (info
);
4685 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
4686 dynobj
= elf_hash_table (info
)->dynobj
;
4687 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
4688 BFD_ASSERT (sreloc
!= NULL
);
4689 BFD_ASSERT (sreloc
->contents
!= NULL
);
4690 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
4693 outrel
[0].r_offset
=
4694 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
4695 outrel
[1].r_offset
=
4696 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
4697 outrel
[2].r_offset
=
4698 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
4700 if (outrel
[0].r_offset
== MINUS_ONE
)
4701 /* The relocation field has been deleted. */
4704 if (outrel
[0].r_offset
== MINUS_TWO
)
4706 /* The relocation field has been converted into a relative value of
4707 some sort. Functions like _bfd_elf_write_section_eh_frame expect
4708 the field to be fully relocated, so add in the symbol's value. */
4713 /* We must now calculate the dynamic symbol table index to use
4714 in the relocation. */
4716 && (!h
->root
.def_regular
4717 || (info
->shared
&& !info
->symbolic
&& !h
->root
.forced_local
)))
4719 indx
= h
->root
.dynindx
;
4720 if (SGI_COMPAT (output_bfd
))
4721 defined_p
= h
->root
.def_regular
;
4723 /* ??? glibc's ld.so just adds the final GOT entry to the
4724 relocation field. It therefore treats relocs against
4725 defined symbols in the same way as relocs against
4726 undefined symbols. */
4731 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
4733 else if (sec
== NULL
|| sec
->owner
== NULL
)
4735 bfd_set_error (bfd_error_bad_value
);
4740 indx
= elf_section_data (sec
->output_section
)->dynindx
;
4745 /* Instead of generating a relocation using the section
4746 symbol, we may as well make it a fully relative
4747 relocation. We want to avoid generating relocations to
4748 local symbols because we used to generate them
4749 incorrectly, without adding the original symbol value,
4750 which is mandated by the ABI for section symbols. In
4751 order to give dynamic loaders and applications time to
4752 phase out the incorrect use, we refrain from emitting
4753 section-relative relocations. It's not like they're
4754 useful, after all. This should be a bit more efficient
4756 /* ??? Although this behavior is compatible with glibc's ld.so,
4757 the ABI says that relocations against STN_UNDEF should have
4758 a symbol value of 0. Irix rld honors this, so relocations
4759 against STN_UNDEF have no effect. */
4760 if (!SGI_COMPAT (output_bfd
))
4765 /* If the relocation was previously an absolute relocation and
4766 this symbol will not be referred to by the relocation, we must
4767 adjust it by the value we give it in the dynamic symbol table.
4768 Otherwise leave the job up to the dynamic linker. */
4769 if (defined_p
&& r_type
!= R_MIPS_REL32
)
4772 if (htab
->is_vxworks
)
4773 /* VxWorks uses non-relative relocations for this. */
4774 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
4776 /* The relocation is always an REL32 relocation because we don't
4777 know where the shared library will wind up at load-time. */
4778 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
4781 /* For strict adherence to the ABI specification, we should
4782 generate a R_MIPS_64 relocation record by itself before the
4783 _REL32/_64 record as well, such that the addend is read in as
4784 a 64-bit value (REL32 is a 32-bit relocation, after all).
4785 However, since none of the existing ELF64 MIPS dynamic
4786 loaders seems to care, we don't waste space with these
4787 artificial relocations. If this turns out to not be true,
4788 mips_elf_allocate_dynamic_relocation() should be tweaked so
4789 as to make room for a pair of dynamic relocations per
4790 invocation if ABI_64_P, and here we should generate an
4791 additional relocation record with R_MIPS_64 by itself for a
4792 NULL symbol before this relocation record. */
4793 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
4794 ABI_64_P (output_bfd
)
4797 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
4799 /* Adjust the output offset of the relocation to reference the
4800 correct location in the output file. */
4801 outrel
[0].r_offset
+= (input_section
->output_section
->vma
4802 + input_section
->output_offset
);
4803 outrel
[1].r_offset
+= (input_section
->output_section
->vma
4804 + input_section
->output_offset
);
4805 outrel
[2].r_offset
+= (input_section
->output_section
->vma
4806 + input_section
->output_offset
);
4808 /* Put the relocation back out. We have to use the special
4809 relocation outputter in the 64-bit case since the 64-bit
4810 relocation format is non-standard. */
4811 if (ABI_64_P (output_bfd
))
4813 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
4814 (output_bfd
, &outrel
[0],
4816 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
4818 else if (htab
->is_vxworks
)
4820 /* VxWorks uses RELA rather than REL dynamic relocations. */
4821 outrel
[0].r_addend
= *addendp
;
4822 bfd_elf32_swap_reloca_out
4823 (output_bfd
, &outrel
[0],
4825 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
4828 bfd_elf32_swap_reloc_out
4829 (output_bfd
, &outrel
[0],
4830 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
4832 /* We've now added another relocation. */
4833 ++sreloc
->reloc_count
;
4835 /* Make sure the output section is writable. The dynamic linker
4836 will be writing to it. */
4837 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
4840 /* On IRIX5, make an entry of compact relocation info. */
4841 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
4843 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4848 Elf32_crinfo cptrel
;
4850 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4851 cptrel
.vaddr
= (rel
->r_offset
4852 + input_section
->output_section
->vma
4853 + input_section
->output_offset
);
4854 if (r_type
== R_MIPS_REL32
)
4855 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
4857 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
4858 mips_elf_set_cr_dist2to (cptrel
, 0);
4859 cptrel
.konst
= *addendp
;
4861 cr
= (scpt
->contents
4862 + sizeof (Elf32_External_compact_rel
));
4863 mips_elf_set_cr_relvaddr (cptrel
, 0);
4864 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4865 ((Elf32_External_crinfo
*) cr
4866 + scpt
->reloc_count
));
4867 ++scpt
->reloc_count
;
4874 /* Return the MACH for a MIPS e_flags value. */
4877 _bfd_elf_mips_mach (flagword flags
)
4879 switch (flags
& EF_MIPS_MACH
)
4881 case E_MIPS_MACH_3900
:
4882 return bfd_mach_mips3900
;
4884 case E_MIPS_MACH_4010
:
4885 return bfd_mach_mips4010
;
4887 case E_MIPS_MACH_4100
:
4888 return bfd_mach_mips4100
;
4890 case E_MIPS_MACH_4111
:
4891 return bfd_mach_mips4111
;
4893 case E_MIPS_MACH_4120
:
4894 return bfd_mach_mips4120
;
4896 case E_MIPS_MACH_4650
:
4897 return bfd_mach_mips4650
;
4899 case E_MIPS_MACH_5400
:
4900 return bfd_mach_mips5400
;
4902 case E_MIPS_MACH_5500
:
4903 return bfd_mach_mips5500
;
4905 case E_MIPS_MACH_9000
:
4906 return bfd_mach_mips9000
;
4908 case E_MIPS_MACH_SB1
:
4909 return bfd_mach_mips_sb1
;
4912 switch (flags
& EF_MIPS_ARCH
)
4916 return bfd_mach_mips3000
;
4920 return bfd_mach_mips6000
;
4924 return bfd_mach_mips4000
;
4928 return bfd_mach_mips8000
;
4932 return bfd_mach_mips5
;
4935 case E_MIPS_ARCH_32
:
4936 return bfd_mach_mipsisa32
;
4939 case E_MIPS_ARCH_64
:
4940 return bfd_mach_mipsisa64
;
4943 case E_MIPS_ARCH_32R2
:
4944 return bfd_mach_mipsisa32r2
;
4947 case E_MIPS_ARCH_64R2
:
4948 return bfd_mach_mipsisa64r2
;
4956 /* Return printable name for ABI. */
4958 static INLINE
char *
4959 elf_mips_abi_name (bfd
*abfd
)
4963 flags
= elf_elfheader (abfd
)->e_flags
;
4964 switch (flags
& EF_MIPS_ABI
)
4967 if (ABI_N32_P (abfd
))
4969 else if (ABI_64_P (abfd
))
4973 case E_MIPS_ABI_O32
:
4975 case E_MIPS_ABI_O64
:
4977 case E_MIPS_ABI_EABI32
:
4979 case E_MIPS_ABI_EABI64
:
4982 return "unknown abi";
4986 /* MIPS ELF uses two common sections. One is the usual one, and the
4987 other is for small objects. All the small objects are kept
4988 together, and then referenced via the gp pointer, which yields
4989 faster assembler code. This is what we use for the small common
4990 section. This approach is copied from ecoff.c. */
4991 static asection mips_elf_scom_section
;
4992 static asymbol mips_elf_scom_symbol
;
4993 static asymbol
*mips_elf_scom_symbol_ptr
;
4995 /* MIPS ELF also uses an acommon section, which represents an
4996 allocated common symbol which may be overridden by a
4997 definition in a shared library. */
4998 static asection mips_elf_acom_section
;
4999 static asymbol mips_elf_acom_symbol
;
5000 static asymbol
*mips_elf_acom_symbol_ptr
;
5002 /* Handle the special MIPS section numbers that a symbol may use.
5003 This is used for both the 32-bit and the 64-bit ABI. */
5006 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
5008 elf_symbol_type
*elfsym
;
5010 elfsym
= (elf_symbol_type
*) asym
;
5011 switch (elfsym
->internal_elf_sym
.st_shndx
)
5013 case SHN_MIPS_ACOMMON
:
5014 /* This section is used in a dynamically linked executable file.
5015 It is an allocated common section. The dynamic linker can
5016 either resolve these symbols to something in a shared
5017 library, or it can just leave them here. For our purposes,
5018 we can consider these symbols to be in a new section. */
5019 if (mips_elf_acom_section
.name
== NULL
)
5021 /* Initialize the acommon section. */
5022 mips_elf_acom_section
.name
= ".acommon";
5023 mips_elf_acom_section
.flags
= SEC_ALLOC
;
5024 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
5025 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
5026 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
5027 mips_elf_acom_symbol
.name
= ".acommon";
5028 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
5029 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
5030 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
5032 asym
->section
= &mips_elf_acom_section
;
5036 /* Common symbols less than the GP size are automatically
5037 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
5038 if (asym
->value
> elf_gp_size (abfd
)
5039 || IRIX_COMPAT (abfd
) == ict_irix6
)
5042 case SHN_MIPS_SCOMMON
:
5043 if (mips_elf_scom_section
.name
== NULL
)
5045 /* Initialize the small common section. */
5046 mips_elf_scom_section
.name
= ".scommon";
5047 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
5048 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
5049 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
5050 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
5051 mips_elf_scom_symbol
.name
= ".scommon";
5052 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
5053 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
5054 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
5056 asym
->section
= &mips_elf_scom_section
;
5057 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
5060 case SHN_MIPS_SUNDEFINED
:
5061 asym
->section
= bfd_und_section_ptr
;
5066 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
5068 BFD_ASSERT (SGI_COMPAT (abfd
));
5069 if (section
!= NULL
)
5071 asym
->section
= section
;
5072 /* MIPS_TEXT is a bit special, the address is not an offset
5073 to the base of the .text section. So substract the section
5074 base address to make it an offset. */
5075 asym
->value
-= section
->vma
;
5082 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
5084 BFD_ASSERT (SGI_COMPAT (abfd
));
5085 if (section
!= NULL
)
5087 asym
->section
= section
;
5088 /* MIPS_DATA is a bit special, the address is not an offset
5089 to the base of the .data section. So substract the section
5090 base address to make it an offset. */
5091 asym
->value
-= section
->vma
;
5098 /* Implement elf_backend_eh_frame_address_size. This differs from
5099 the default in the way it handles EABI64.
5101 EABI64 was originally specified as an LP64 ABI, and that is what
5102 -mabi=eabi normally gives on a 64-bit target. However, gcc has
5103 historically accepted the combination of -mabi=eabi and -mlong32,
5104 and this ILP32 variation has become semi-official over time.
5105 Both forms use elf32 and have pointer-sized FDE addresses.
5107 If an EABI object was generated by GCC 4.0 or above, it will have
5108 an empty .gcc_compiled_longXX section, where XX is the size of longs
5109 in bits. Unfortunately, ILP32 objects generated by earlier compilers
5110 have no special marking to distinguish them from LP64 objects.
5112 We don't want users of the official LP64 ABI to be punished for the
5113 existence of the ILP32 variant, but at the same time, we don't want
5114 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
5115 We therefore take the following approach:
5117 - If ABFD contains a .gcc_compiled_longXX section, use it to
5118 determine the pointer size.
5120 - Otherwise check the type of the first relocation. Assume that
5121 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
5125 The second check is enough to detect LP64 objects generated by pre-4.0
5126 compilers because, in the kind of output generated by those compilers,
5127 the first relocation will be associated with either a CIE personality
5128 routine or an FDE start address. Furthermore, the compilers never
5129 used a special (non-pointer) encoding for this ABI.
5131 Checking the relocation type should also be safe because there is no
5132 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
5136 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
5138 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
5140 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
5142 bfd_boolean long32_p
, long64_p
;
5144 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
5145 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
5146 if (long32_p
&& long64_p
)
5153 if (sec
->reloc_count
> 0
5154 && elf_section_data (sec
)->relocs
!= NULL
5155 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
5164 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
5165 relocations against two unnamed section symbols to resolve to the
5166 same address. For example, if we have code like:
5168 lw $4,%got_disp(.data)($gp)
5169 lw $25,%got_disp(.text)($gp)
5172 then the linker will resolve both relocations to .data and the program
5173 will jump there rather than to .text.
5175 We can work around this problem by giving names to local section symbols.
5176 This is also what the MIPSpro tools do. */
5179 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
5181 return SGI_COMPAT (abfd
);
5184 /* Work over a section just before writing it out. This routine is
5185 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
5186 sections that need the SHF_MIPS_GPREL flag by name; there has to be
5190 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
5192 if (hdr
->sh_type
== SHT_MIPS_REGINFO
5193 && hdr
->sh_size
> 0)
5197 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
5198 BFD_ASSERT (hdr
->contents
== NULL
);
5201 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
5204 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5205 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5209 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
5210 && hdr
->bfd_section
!= NULL
5211 && mips_elf_section_data (hdr
->bfd_section
) != NULL
5212 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
5214 bfd_byte
*contents
, *l
, *lend
;
5216 /* We stored the section contents in the tdata field in the
5217 set_section_contents routine. We save the section contents
5218 so that we don't have to read them again.
5219 At this point we know that elf_gp is set, so we can look
5220 through the section contents to see if there is an
5221 ODK_REGINFO structure. */
5223 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
5225 lend
= contents
+ hdr
->sh_size
;
5226 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5228 Elf_Internal_Options intopt
;
5230 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5232 if (intopt
.size
< sizeof (Elf_External_Options
))
5234 (*_bfd_error_handler
)
5235 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5236 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
5239 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
5246 + sizeof (Elf_External_Options
)
5247 + (sizeof (Elf64_External_RegInfo
) - 8)),
5250 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
5251 if (bfd_bwrite (buf
, 8, abfd
) != 8)
5254 else if (intopt
.kind
== ODK_REGINFO
)
5261 + sizeof (Elf_External_Options
)
5262 + (sizeof (Elf32_External_RegInfo
) - 4)),
5265 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5266 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5273 if (hdr
->bfd_section
!= NULL
)
5275 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
5277 if (strcmp (name
, ".sdata") == 0
5278 || strcmp (name
, ".lit8") == 0
5279 || strcmp (name
, ".lit4") == 0)
5281 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5282 hdr
->sh_type
= SHT_PROGBITS
;
5284 else if (strcmp (name
, ".sbss") == 0)
5286 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5287 hdr
->sh_type
= SHT_NOBITS
;
5289 else if (strcmp (name
, ".srdata") == 0)
5291 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
5292 hdr
->sh_type
= SHT_PROGBITS
;
5294 else if (strcmp (name
, ".compact_rel") == 0)
5297 hdr
->sh_type
= SHT_PROGBITS
;
5299 else if (strcmp (name
, ".rtproc") == 0)
5301 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
5303 unsigned int adjust
;
5305 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
5307 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
5315 /* Handle a MIPS specific section when reading an object file. This
5316 is called when elfcode.h finds a section with an unknown type.
5317 This routine supports both the 32-bit and 64-bit ELF ABI.
5319 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
5323 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
5324 Elf_Internal_Shdr
*hdr
,
5330 /* There ought to be a place to keep ELF backend specific flags, but
5331 at the moment there isn't one. We just keep track of the
5332 sections by their name, instead. Fortunately, the ABI gives
5333 suggested names for all the MIPS specific sections, so we will
5334 probably get away with this. */
5335 switch (hdr
->sh_type
)
5337 case SHT_MIPS_LIBLIST
:
5338 if (strcmp (name
, ".liblist") != 0)
5342 if (strcmp (name
, ".msym") != 0)
5345 case SHT_MIPS_CONFLICT
:
5346 if (strcmp (name
, ".conflict") != 0)
5349 case SHT_MIPS_GPTAB
:
5350 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
5353 case SHT_MIPS_UCODE
:
5354 if (strcmp (name
, ".ucode") != 0)
5357 case SHT_MIPS_DEBUG
:
5358 if (strcmp (name
, ".mdebug") != 0)
5360 flags
= SEC_DEBUGGING
;
5362 case SHT_MIPS_REGINFO
:
5363 if (strcmp (name
, ".reginfo") != 0
5364 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
5366 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
5368 case SHT_MIPS_IFACE
:
5369 if (strcmp (name
, ".MIPS.interfaces") != 0)
5372 case SHT_MIPS_CONTENT
:
5373 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
5376 case SHT_MIPS_OPTIONS
:
5377 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
5380 case SHT_MIPS_DWARF
:
5381 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
5384 case SHT_MIPS_SYMBOL_LIB
:
5385 if (strcmp (name
, ".MIPS.symlib") != 0)
5388 case SHT_MIPS_EVENTS
:
5389 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
5390 && strncmp (name
, ".MIPS.post_rel",
5391 sizeof ".MIPS.post_rel" - 1) != 0)
5398 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
5403 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
5404 (bfd_get_section_flags (abfd
,
5410 /* FIXME: We should record sh_info for a .gptab section. */
5412 /* For a .reginfo section, set the gp value in the tdata information
5413 from the contents of this section. We need the gp value while
5414 processing relocs, so we just get it now. The .reginfo section
5415 is not used in the 64-bit MIPS ELF ABI. */
5416 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
5418 Elf32_External_RegInfo ext
;
5421 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
5422 &ext
, 0, sizeof ext
))
5424 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
5425 elf_gp (abfd
) = s
.ri_gp_value
;
5428 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
5429 set the gp value based on what we find. We may see both
5430 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
5431 they should agree. */
5432 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
5434 bfd_byte
*contents
, *l
, *lend
;
5436 contents
= bfd_malloc (hdr
->sh_size
);
5437 if (contents
== NULL
)
5439 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
5446 lend
= contents
+ hdr
->sh_size
;
5447 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5449 Elf_Internal_Options intopt
;
5451 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5453 if (intopt
.size
< sizeof (Elf_External_Options
))
5455 (*_bfd_error_handler
)
5456 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5457 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
5460 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
5462 Elf64_Internal_RegInfo intreg
;
5464 bfd_mips_elf64_swap_reginfo_in
5466 ((Elf64_External_RegInfo
*)
5467 (l
+ sizeof (Elf_External_Options
))),
5469 elf_gp (abfd
) = intreg
.ri_gp_value
;
5471 else if (intopt
.kind
== ODK_REGINFO
)
5473 Elf32_RegInfo intreg
;
5475 bfd_mips_elf32_swap_reginfo_in
5477 ((Elf32_External_RegInfo
*)
5478 (l
+ sizeof (Elf_External_Options
))),
5480 elf_gp (abfd
) = intreg
.ri_gp_value
;
5490 /* Set the correct type for a MIPS ELF section. We do this by the
5491 section name, which is a hack, but ought to work. This routine is
5492 used by both the 32-bit and the 64-bit ABI. */
5495 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
5497 register const char *name
;
5498 unsigned int sh_type
;
5500 name
= bfd_get_section_name (abfd
, sec
);
5501 sh_type
= hdr
->sh_type
;
5503 if (strcmp (name
, ".liblist") == 0)
5505 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
5506 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
5507 /* The sh_link field is set in final_write_processing. */
5509 else if (strcmp (name
, ".conflict") == 0)
5510 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
5511 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
5513 hdr
->sh_type
= SHT_MIPS_GPTAB
;
5514 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
5515 /* The sh_info field is set in final_write_processing. */
5517 else if (strcmp (name
, ".ucode") == 0)
5518 hdr
->sh_type
= SHT_MIPS_UCODE
;
5519 else if (strcmp (name
, ".mdebug") == 0)
5521 hdr
->sh_type
= SHT_MIPS_DEBUG
;
5522 /* In a shared object on IRIX 5.3, the .mdebug section has an
5523 entsize of 0. FIXME: Does this matter? */
5524 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
5525 hdr
->sh_entsize
= 0;
5527 hdr
->sh_entsize
= 1;
5529 else if (strcmp (name
, ".reginfo") == 0)
5531 hdr
->sh_type
= SHT_MIPS_REGINFO
;
5532 /* In a shared object on IRIX 5.3, the .reginfo section has an
5533 entsize of 0x18. FIXME: Does this matter? */
5534 if (SGI_COMPAT (abfd
))
5536 if ((abfd
->flags
& DYNAMIC
) != 0)
5537 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
5539 hdr
->sh_entsize
= 1;
5542 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
5544 else if (SGI_COMPAT (abfd
)
5545 && (strcmp (name
, ".hash") == 0
5546 || strcmp (name
, ".dynamic") == 0
5547 || strcmp (name
, ".dynstr") == 0))
5549 if (SGI_COMPAT (abfd
))
5550 hdr
->sh_entsize
= 0;
5552 /* This isn't how the IRIX6 linker behaves. */
5553 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
5556 else if (strcmp (name
, ".got") == 0
5557 || strcmp (name
, ".srdata") == 0
5558 || strcmp (name
, ".sdata") == 0
5559 || strcmp (name
, ".sbss") == 0
5560 || strcmp (name
, ".lit4") == 0
5561 || strcmp (name
, ".lit8") == 0)
5562 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
5563 else if (strcmp (name
, ".MIPS.interfaces") == 0)
5565 hdr
->sh_type
= SHT_MIPS_IFACE
;
5566 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
5568 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
5570 hdr
->sh_type
= SHT_MIPS_CONTENT
;
5571 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
5572 /* The sh_info field is set in final_write_processing. */
5574 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
5576 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
5577 hdr
->sh_entsize
= 1;
5578 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
5580 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
5581 hdr
->sh_type
= SHT_MIPS_DWARF
;
5582 else if (strcmp (name
, ".MIPS.symlib") == 0)
5584 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
5585 /* The sh_link and sh_info fields are set in
5586 final_write_processing. */
5588 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
5589 || strncmp (name
, ".MIPS.post_rel",
5590 sizeof ".MIPS.post_rel" - 1) == 0)
5592 hdr
->sh_type
= SHT_MIPS_EVENTS
;
5593 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
5594 /* The sh_link field is set in final_write_processing. */
5596 else if (strcmp (name
, ".msym") == 0)
5598 hdr
->sh_type
= SHT_MIPS_MSYM
;
5599 hdr
->sh_flags
|= SHF_ALLOC
;
5600 hdr
->sh_entsize
= 8;
5603 /* In the unlikely event a special section is empty it has to lose its
5604 special meaning. This may happen e.g. when using `strip' with the
5605 "--only-keep-debug" option. */
5606 if (sec
->size
> 0 && !(sec
->flags
& SEC_HAS_CONTENTS
))
5607 hdr
->sh_type
= sh_type
;
5609 /* The generic elf_fake_sections will set up REL_HDR using the default
5610 kind of relocations. We used to set up a second header for the
5611 non-default kind of relocations here, but only NewABI would use
5612 these, and the IRIX ld doesn't like resulting empty RELA sections.
5613 Thus we create those header only on demand now. */
5618 /* Given a BFD section, try to locate the corresponding ELF section
5619 index. This is used by both the 32-bit and the 64-bit ABI.
5620 Actually, it's not clear to me that the 64-bit ABI supports these,
5621 but for non-PIC objects we will certainly want support for at least
5622 the .scommon section. */
5625 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
5626 asection
*sec
, int *retval
)
5628 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
5630 *retval
= SHN_MIPS_SCOMMON
;
5633 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
5635 *retval
= SHN_MIPS_ACOMMON
;
5641 /* Hook called by the linker routine which adds symbols from an object
5642 file. We must handle the special MIPS section numbers here. */
5645 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5646 Elf_Internal_Sym
*sym
, const char **namep
,
5647 flagword
*flagsp ATTRIBUTE_UNUSED
,
5648 asection
**secp
, bfd_vma
*valp
)
5650 if (SGI_COMPAT (abfd
)
5651 && (abfd
->flags
& DYNAMIC
) != 0
5652 && strcmp (*namep
, "_rld_new_interface") == 0)
5654 /* Skip IRIX5 rld entry name. */
5659 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
5660 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
5661 by setting a DT_NEEDED for the shared object. Since _gp_disp is
5662 a magic symbol resolved by the linker, we ignore this bogus definition
5663 of _gp_disp. New ABI objects do not suffer from this problem so this
5664 is not done for them. */
5666 && (sym
->st_shndx
== SHN_ABS
)
5667 && (strcmp (*namep
, "_gp_disp") == 0))
5673 switch (sym
->st_shndx
)
5676 /* Common symbols less than the GP size are automatically
5677 treated as SHN_MIPS_SCOMMON symbols. */
5678 if (sym
->st_size
> elf_gp_size (abfd
)
5679 || IRIX_COMPAT (abfd
) == ict_irix6
)
5682 case SHN_MIPS_SCOMMON
:
5683 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
5684 (*secp
)->flags
|= SEC_IS_COMMON
;
5685 *valp
= sym
->st_size
;
5689 /* This section is used in a shared object. */
5690 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
5692 asymbol
*elf_text_symbol
;
5693 asection
*elf_text_section
;
5694 bfd_size_type amt
= sizeof (asection
);
5696 elf_text_section
= bfd_zalloc (abfd
, amt
);
5697 if (elf_text_section
== NULL
)
5700 amt
= sizeof (asymbol
);
5701 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
5702 if (elf_text_symbol
== NULL
)
5705 /* Initialize the section. */
5707 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
5708 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
5710 elf_text_section
->symbol
= elf_text_symbol
;
5711 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
5713 elf_text_section
->name
= ".text";
5714 elf_text_section
->flags
= SEC_NO_FLAGS
;
5715 elf_text_section
->output_section
= NULL
;
5716 elf_text_section
->owner
= abfd
;
5717 elf_text_symbol
->name
= ".text";
5718 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
5719 elf_text_symbol
->section
= elf_text_section
;
5721 /* This code used to do *secp = bfd_und_section_ptr if
5722 info->shared. I don't know why, and that doesn't make sense,
5723 so I took it out. */
5724 *secp
= elf_tdata (abfd
)->elf_text_section
;
5727 case SHN_MIPS_ACOMMON
:
5728 /* Fall through. XXX Can we treat this as allocated data? */
5730 /* This section is used in a shared object. */
5731 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
5733 asymbol
*elf_data_symbol
;
5734 asection
*elf_data_section
;
5735 bfd_size_type amt
= sizeof (asection
);
5737 elf_data_section
= bfd_zalloc (abfd
, amt
);
5738 if (elf_data_section
== NULL
)
5741 amt
= sizeof (asymbol
);
5742 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
5743 if (elf_data_symbol
== NULL
)
5746 /* Initialize the section. */
5748 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
5749 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
5751 elf_data_section
->symbol
= elf_data_symbol
;
5752 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
5754 elf_data_section
->name
= ".data";
5755 elf_data_section
->flags
= SEC_NO_FLAGS
;
5756 elf_data_section
->output_section
= NULL
;
5757 elf_data_section
->owner
= abfd
;
5758 elf_data_symbol
->name
= ".data";
5759 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
5760 elf_data_symbol
->section
= elf_data_section
;
5762 /* This code used to do *secp = bfd_und_section_ptr if
5763 info->shared. I don't know why, and that doesn't make sense,
5764 so I took it out. */
5765 *secp
= elf_tdata (abfd
)->elf_data_section
;
5768 case SHN_MIPS_SUNDEFINED
:
5769 *secp
= bfd_und_section_ptr
;
5773 if (SGI_COMPAT (abfd
)
5775 && info
->hash
->creator
== abfd
->xvec
5776 && strcmp (*namep
, "__rld_obj_head") == 0)
5778 struct elf_link_hash_entry
*h
;
5779 struct bfd_link_hash_entry
*bh
;
5781 /* Mark __rld_obj_head as dynamic. */
5783 if (! (_bfd_generic_link_add_one_symbol
5784 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
5785 get_elf_backend_data (abfd
)->collect
, &bh
)))
5788 h
= (struct elf_link_hash_entry
*) bh
;
5791 h
->type
= STT_OBJECT
;
5793 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5796 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
5799 /* If this is a mips16 text symbol, add 1 to the value to make it
5800 odd. This will cause something like .word SYM to come up with
5801 the right value when it is loaded into the PC. */
5802 if (sym
->st_other
== STO_MIPS16
)
5808 /* This hook function is called before the linker writes out a global
5809 symbol. We mark symbols as small common if appropriate. This is
5810 also where we undo the increment of the value for a mips16 symbol. */
5813 _bfd_mips_elf_link_output_symbol_hook
5814 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5815 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
5816 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5818 /* If we see a common symbol, which implies a relocatable link, then
5819 if a symbol was small common in an input file, mark it as small
5820 common in the output file. */
5821 if (sym
->st_shndx
== SHN_COMMON
5822 && strcmp (input_sec
->name
, ".scommon") == 0)
5823 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5825 if (sym
->st_other
== STO_MIPS16
)
5826 sym
->st_value
&= ~1;
5831 /* Functions for the dynamic linker. */
5833 /* Create dynamic sections when linking against a dynamic object. */
5836 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5838 struct elf_link_hash_entry
*h
;
5839 struct bfd_link_hash_entry
*bh
;
5841 register asection
*s
;
5842 const char * const *namep
;
5843 struct mips_elf_link_hash_table
*htab
;
5845 htab
= mips_elf_hash_table (info
);
5846 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5847 | SEC_LINKER_CREATED
| SEC_READONLY
);
5849 /* The psABI requires a read-only .dynamic section, but the VxWorks
5851 if (!htab
->is_vxworks
)
5853 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5856 if (! bfd_set_section_flags (abfd
, s
, flags
))
5861 /* We need to create .got section. */
5862 if (! mips_elf_create_got_section (abfd
, info
, FALSE
))
5865 if (! mips_elf_rel_dyn_section (info
, TRUE
))
5868 /* Create .stub section. */
5869 if (bfd_get_section_by_name (abfd
,
5870 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
5872 s
= bfd_make_section_with_flags (abfd
,
5873 MIPS_ELF_STUB_SECTION_NAME (abfd
),
5876 || ! bfd_set_section_alignment (abfd
, s
,
5877 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
5881 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
5883 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5885 s
= bfd_make_section_with_flags (abfd
, ".rld_map",
5886 flags
&~ (flagword
) SEC_READONLY
);
5888 || ! bfd_set_section_alignment (abfd
, s
,
5889 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
5893 /* On IRIX5, we adjust add some additional symbols and change the
5894 alignments of several sections. There is no ABI documentation
5895 indicating that this is necessary on IRIX6, nor any evidence that
5896 the linker takes such action. */
5897 if (IRIX_COMPAT (abfd
) == ict_irix5
)
5899 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5902 if (! (_bfd_generic_link_add_one_symbol
5903 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
5904 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
5907 h
= (struct elf_link_hash_entry
*) bh
;
5910 h
->type
= STT_SECTION
;
5912 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5916 /* We need to create a .compact_rel section. */
5917 if (SGI_COMPAT (abfd
))
5919 if (!mips_elf_create_compact_rel_section (abfd
, info
))
5923 /* Change alignments of some sections. */
5924 s
= bfd_get_section_by_name (abfd
, ".hash");
5926 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
5927 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5929 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
5930 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5932 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
5933 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5935 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
5936 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5938 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
5945 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
5947 if (!(_bfd_generic_link_add_one_symbol
5948 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
5949 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
5952 h
= (struct elf_link_hash_entry
*) bh
;
5955 h
->type
= STT_SECTION
;
5957 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5960 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5962 /* __rld_map is a four byte word located in the .data section
5963 and is filled in by the rtld to contain a pointer to
5964 the _r_debug structure. Its symbol value will be set in
5965 _bfd_mips_elf_finish_dynamic_symbol. */
5966 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5967 BFD_ASSERT (s
!= NULL
);
5969 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
5971 if (!(_bfd_generic_link_add_one_symbol
5972 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
5973 get_elf_backend_data (abfd
)->collect
, &bh
)))
5976 h
= (struct elf_link_hash_entry
*) bh
;
5979 h
->type
= STT_OBJECT
;
5981 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5986 if (htab
->is_vxworks
)
5988 /* Create the .plt, .rela.plt, .dynbss and .rela.bss sections.
5989 Also create the _PROCEDURE_LINKAGE_TABLE symbol. */
5990 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
5993 /* Cache the sections created above. */
5994 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
5995 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
5996 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
5997 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
5999 || (!htab
->srelbss
&& !info
->shared
)
6004 /* Do the usual VxWorks handling. */
6005 if (!elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
6008 /* Work out the PLT sizes. */
6011 htab
->plt_header_size
6012 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
6013 htab
->plt_entry_size
6014 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
6018 htab
->plt_header_size
6019 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
6020 htab
->plt_entry_size
6021 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
6028 /* Look through the relocs for a section during the first phase, and
6029 allocate space in the global offset table. */
6032 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6033 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6037 Elf_Internal_Shdr
*symtab_hdr
;
6038 struct elf_link_hash_entry
**sym_hashes
;
6039 struct mips_got_info
*g
;
6041 const Elf_Internal_Rela
*rel
;
6042 const Elf_Internal_Rela
*rel_end
;
6045 const struct elf_backend_data
*bed
;
6046 struct mips_elf_link_hash_table
*htab
;
6048 if (info
->relocatable
)
6051 htab
= mips_elf_hash_table (info
);
6052 dynobj
= elf_hash_table (info
)->dynobj
;
6053 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6054 sym_hashes
= elf_sym_hashes (abfd
);
6055 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6057 /* Check for the mips16 stub sections. */
6059 name
= bfd_get_section_name (abfd
, sec
);
6060 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
6062 unsigned long r_symndx
;
6064 /* Look at the relocation information to figure out which symbol
6067 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
6069 if (r_symndx
< extsymoff
6070 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6074 /* This stub is for a local symbol. This stub will only be
6075 needed if there is some relocation in this BFD, other
6076 than a 16 bit function call, which refers to this symbol. */
6077 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
6079 Elf_Internal_Rela
*sec_relocs
;
6080 const Elf_Internal_Rela
*r
, *rend
;
6082 /* We can ignore stub sections when looking for relocs. */
6083 if ((o
->flags
& SEC_RELOC
) == 0
6084 || o
->reloc_count
== 0
6085 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
6086 sizeof FN_STUB
- 1) == 0
6087 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
6088 sizeof CALL_STUB
- 1) == 0
6089 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
6090 sizeof CALL_FP_STUB
- 1) == 0)
6094 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
6096 if (sec_relocs
== NULL
)
6099 rend
= sec_relocs
+ o
->reloc_count
;
6100 for (r
= sec_relocs
; r
< rend
; r
++)
6101 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
6102 && ELF_R_TYPE (abfd
, r
->r_info
) != R_MIPS16_26
)
6105 if (elf_section_data (o
)->relocs
!= sec_relocs
)
6114 /* There is no non-call reloc for this stub, so we do
6115 not need it. Since this function is called before
6116 the linker maps input sections to output sections, we
6117 can easily discard it by setting the SEC_EXCLUDE
6119 sec
->flags
|= SEC_EXCLUDE
;
6123 /* Record this stub in an array of local symbol stubs for
6125 if (elf_tdata (abfd
)->local_stubs
== NULL
)
6127 unsigned long symcount
;
6131 if (elf_bad_symtab (abfd
))
6132 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
6134 symcount
= symtab_hdr
->sh_info
;
6135 amt
= symcount
* sizeof (asection
*);
6136 n
= bfd_zalloc (abfd
, amt
);
6139 elf_tdata (abfd
)->local_stubs
= n
;
6142 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
6144 /* We don't need to set mips16_stubs_seen in this case.
6145 That flag is used to see whether we need to look through
6146 the global symbol table for stubs. We don't need to set
6147 it here, because we just have a local stub. */
6151 struct mips_elf_link_hash_entry
*h
;
6153 h
= ((struct mips_elf_link_hash_entry
*)
6154 sym_hashes
[r_symndx
- extsymoff
]);
6156 while (h
->root
.root
.type
== bfd_link_hash_indirect
6157 || h
->root
.root
.type
== bfd_link_hash_warning
)
6158 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
6160 /* H is the symbol this stub is for. */
6163 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
6166 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
6167 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6169 unsigned long r_symndx
;
6170 struct mips_elf_link_hash_entry
*h
;
6173 /* Look at the relocation information to figure out which symbol
6176 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
6178 if (r_symndx
< extsymoff
6179 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
6181 /* This stub was actually built for a static symbol defined
6182 in the same file. We assume that all static symbols in
6183 mips16 code are themselves mips16, so we can simply
6184 discard this stub. Since this function is called before
6185 the linker maps input sections to output sections, we can
6186 easily discard it by setting the SEC_EXCLUDE flag. */
6187 sec
->flags
|= SEC_EXCLUDE
;
6191 h
= ((struct mips_elf_link_hash_entry
*)
6192 sym_hashes
[r_symndx
- extsymoff
]);
6194 /* H is the symbol this stub is for. */
6196 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
6197 loc
= &h
->call_fp_stub
;
6199 loc
= &h
->call_stub
;
6201 /* If we already have an appropriate stub for this function, we
6202 don't need another one, so we can discard this one. Since
6203 this function is called before the linker maps input sections
6204 to output sections, we can easily discard it by setting the
6205 SEC_EXCLUDE flag. We can also discard this section if we
6206 happen to already know that this is a mips16 function; it is
6207 not necessary to check this here, as it is checked later, but
6208 it is slightly faster to check now. */
6209 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
6211 sec
->flags
|= SEC_EXCLUDE
;
6216 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
6226 sgot
= mips_elf_got_section (dynobj
, FALSE
);
6231 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
6232 g
= mips_elf_section_data (sgot
)->u
.got_info
;
6233 BFD_ASSERT (g
!= NULL
);
6238 bed
= get_elf_backend_data (abfd
);
6239 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6240 for (rel
= relocs
; rel
< rel_end
; ++rel
)
6242 unsigned long r_symndx
;
6243 unsigned int r_type
;
6244 struct elf_link_hash_entry
*h
;
6246 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
6247 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
6249 if (r_symndx
< extsymoff
)
6251 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
6253 (*_bfd_error_handler
)
6254 (_("%B: Malformed reloc detected for section %s"),
6256 bfd_set_error (bfd_error_bad_value
);
6261 h
= sym_hashes
[r_symndx
- extsymoff
];
6263 /* This may be an indirect symbol created because of a version. */
6266 while (h
->root
.type
== bfd_link_hash_indirect
)
6267 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6271 /* Some relocs require a global offset table. */
6272 if (dynobj
== NULL
|| sgot
== NULL
)
6278 case R_MIPS_CALL_HI16
:
6279 case R_MIPS_CALL_LO16
:
6280 case R_MIPS_GOT_HI16
:
6281 case R_MIPS_GOT_LO16
:
6282 case R_MIPS_GOT_PAGE
:
6283 case R_MIPS_GOT_OFST
:
6284 case R_MIPS_GOT_DISP
:
6285 case R_MIPS_TLS_GOTTPREL
:
6287 case R_MIPS_TLS_LDM
:
6289 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6290 if (! mips_elf_create_got_section (dynobj
, info
, FALSE
))
6292 g
= mips_elf_got_info (dynobj
, &sgot
);
6293 if (htab
->is_vxworks
&& !info
->shared
)
6295 (*_bfd_error_handler
)
6296 (_("%B: GOT reloc at 0x%lx not expected in executables"),
6297 abfd
, (unsigned long) rel
->r_offset
);
6298 bfd_set_error (bfd_error_bad_value
);
6306 /* In VxWorks executables, references to external symbols
6307 are handled using copy relocs or PLT stubs, so there's
6308 no need to add a dynamic relocation here. */
6310 && (info
->shared
|| (h
!= NULL
&& !htab
->is_vxworks
))
6311 && (sec
->flags
& SEC_ALLOC
) != 0)
6312 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6322 ((struct mips_elf_link_hash_entry
*) h
)->is_relocation_target
= TRUE
;
6324 /* Relocations against the special VxWorks __GOTT_BASE__ and
6325 __GOTT_INDEX__ symbols must be left to the loader. Allocate
6326 room for them in .rela.dyn. */
6327 if (is_gott_symbol (info
, h
))
6331 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
6335 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
6338 else if (r_type
== R_MIPS_CALL_LO16
6339 || r_type
== R_MIPS_GOT_LO16
6340 || r_type
== R_MIPS_GOT_DISP
6341 || (r_type
== R_MIPS_GOT16
&& htab
->is_vxworks
))
6343 /* We may need a local GOT entry for this relocation. We
6344 don't count R_MIPS_GOT_PAGE because we can estimate the
6345 maximum number of pages needed by looking at the size of
6346 the segment. Similar comments apply to R_MIPS_GOT16 and
6347 R_MIPS_CALL16, except on VxWorks, where GOT relocations
6348 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
6349 R_MIPS_CALL_HI16 because these are always followed by an
6350 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
6351 if (! mips_elf_record_local_got_symbol (abfd
, r_symndx
,
6352 rel
->r_addend
, g
, 0))
6361 (*_bfd_error_handler
)
6362 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
6363 abfd
, (unsigned long) rel
->r_offset
);
6364 bfd_set_error (bfd_error_bad_value
);
6369 case R_MIPS_CALL_HI16
:
6370 case R_MIPS_CALL_LO16
:
6373 /* VxWorks call relocations point the function's .got.plt
6374 entry, which will be allocated by adjust_dynamic_symbol.
6375 Otherwise, this symbol requires a global GOT entry. */
6376 if (!htab
->is_vxworks
6377 && !mips_elf_record_global_got_symbol (h
, abfd
, info
, g
, 0))
6380 /* We need a stub, not a plt entry for the undefined
6381 function. But we record it as if it needs plt. See
6382 _bfd_elf_adjust_dynamic_symbol. */
6388 case R_MIPS_GOT_PAGE
:
6389 /* If this is a global, overridable symbol, GOT_PAGE will
6390 decay to GOT_DISP, so we'll need a GOT entry for it. */
6395 struct mips_elf_link_hash_entry
*hmips
=
6396 (struct mips_elf_link_hash_entry
*) h
;
6398 while (hmips
->root
.root
.type
== bfd_link_hash_indirect
6399 || hmips
->root
.root
.type
== bfd_link_hash_warning
)
6400 hmips
= (struct mips_elf_link_hash_entry
*)
6401 hmips
->root
.root
.u
.i
.link
;
6403 if (hmips
->root
.def_regular
6404 && ! (info
->shared
&& ! info
->symbolic
6405 && ! hmips
->root
.forced_local
))
6411 case R_MIPS_GOT_HI16
:
6412 case R_MIPS_GOT_LO16
:
6413 case R_MIPS_GOT_DISP
:
6414 if (h
&& ! mips_elf_record_global_got_symbol (h
, abfd
, info
, g
, 0))
6418 case R_MIPS_TLS_GOTTPREL
:
6420 info
->flags
|= DF_STATIC_TLS
;
6423 case R_MIPS_TLS_LDM
:
6424 if (r_type
== R_MIPS_TLS_LDM
)
6432 /* This symbol requires a global offset table entry, or two
6433 for TLS GD relocations. */
6435 unsigned char flag
= (r_type
== R_MIPS_TLS_GD
6437 : r_type
== R_MIPS_TLS_LDM
6442 struct mips_elf_link_hash_entry
*hmips
=
6443 (struct mips_elf_link_hash_entry
*) h
;
6444 hmips
->tls_type
|= flag
;
6446 if (h
&& ! mips_elf_record_global_got_symbol (h
, abfd
, info
, g
, flag
))
6451 BFD_ASSERT (flag
== GOT_TLS_LDM
|| r_symndx
!= 0);
6453 if (! mips_elf_record_local_got_symbol (abfd
, r_symndx
,
6454 rel
->r_addend
, g
, flag
))
6463 /* In VxWorks executables, references to external symbols
6464 are handled using copy relocs or PLT stubs, so there's
6465 no need to add a .rela.dyn entry for this relocation. */
6466 if ((info
->shared
|| (h
!= NULL
&& !htab
->is_vxworks
))
6467 && (sec
->flags
& SEC_ALLOC
) != 0)
6471 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
6475 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
6478 /* When creating a shared object, we must copy these
6479 reloc types into the output file as R_MIPS_REL32
6480 relocs. Make room for this reloc in .rel(a).dyn. */
6481 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
6482 if ((sec
->flags
& MIPS_READONLY_SECTION
)
6483 == MIPS_READONLY_SECTION
)
6484 /* We tell the dynamic linker that there are
6485 relocations against the text segment. */
6486 info
->flags
|= DF_TEXTREL
;
6490 struct mips_elf_link_hash_entry
*hmips
;
6492 /* We only need to copy this reloc if the symbol is
6493 defined in a dynamic object. */
6494 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6495 ++hmips
->possibly_dynamic_relocs
;
6496 if ((sec
->flags
& MIPS_READONLY_SECTION
)
6497 == MIPS_READONLY_SECTION
)
6498 /* We need it to tell the dynamic linker if there
6499 are relocations against the text segment. */
6500 hmips
->readonly_reloc
= TRUE
;
6503 /* Even though we don't directly need a GOT entry for
6504 this symbol, a symbol must have a dynamic symbol
6505 table index greater that DT_MIPS_GOTSYM if there are
6506 dynamic relocations against it. This does not apply
6507 to VxWorks, which does not have the usual coupling
6508 between global GOT entries and .dynsym entries. */
6509 if (h
!= NULL
&& !htab
->is_vxworks
)
6512 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6513 if (! mips_elf_create_got_section (dynobj
, info
, TRUE
))
6515 g
= mips_elf_got_info (dynobj
, &sgot
);
6516 if (! mips_elf_record_global_got_symbol (h
, abfd
, info
, g
, 0))
6521 if (SGI_COMPAT (abfd
))
6522 mips_elf_hash_table (info
)->compact_rel_size
+=
6523 sizeof (Elf32_External_crinfo
);
6528 ((struct mips_elf_link_hash_entry
*) h
)->is_branch_target
= TRUE
;
6533 ((struct mips_elf_link_hash_entry
*) h
)->is_branch_target
= TRUE
;
6536 case R_MIPS_GPREL16
:
6537 case R_MIPS_LITERAL
:
6538 case R_MIPS_GPREL32
:
6539 if (SGI_COMPAT (abfd
))
6540 mips_elf_hash_table (info
)->compact_rel_size
+=
6541 sizeof (Elf32_External_crinfo
);
6544 /* This relocation describes the C++ object vtable hierarchy.
6545 Reconstruct it for later use during GC. */
6546 case R_MIPS_GNU_VTINHERIT
:
6547 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6551 /* This relocation describes which C++ vtable entries are actually
6552 used. Record for later use during GC. */
6553 case R_MIPS_GNU_VTENTRY
:
6554 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6562 /* We must not create a stub for a symbol that has relocations
6563 related to taking the function's address. This doesn't apply to
6564 VxWorks, where CALL relocs refer to a .got.plt entry instead of
6565 a normal .got entry. */
6566 if (!htab
->is_vxworks
&& h
!= NULL
)
6570 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
6573 case R_MIPS_CALL_HI16
:
6574 case R_MIPS_CALL_LO16
:
6579 /* If this reloc is not a 16 bit call, and it has a global
6580 symbol, then we will need the fn_stub if there is one.
6581 References from a stub section do not count. */
6583 && r_type
!= R_MIPS16_26
6584 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6585 sizeof FN_STUB
- 1) != 0
6586 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6587 sizeof CALL_STUB
- 1) != 0
6588 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6589 sizeof CALL_FP_STUB
- 1) != 0)
6591 struct mips_elf_link_hash_entry
*mh
;
6593 mh
= (struct mips_elf_link_hash_entry
*) h
;
6594 mh
->need_fn_stub
= TRUE
;
6602 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
6603 struct bfd_link_info
*link_info
,
6606 Elf_Internal_Rela
*internal_relocs
;
6607 Elf_Internal_Rela
*irel
, *irelend
;
6608 Elf_Internal_Shdr
*symtab_hdr
;
6609 bfd_byte
*contents
= NULL
;
6611 bfd_boolean changed_contents
= FALSE
;
6612 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
6613 Elf_Internal_Sym
*isymbuf
= NULL
;
6615 /* We are not currently changing any sizes, so only one pass. */
6618 if (link_info
->relocatable
)
6621 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
6622 link_info
->keep_memory
);
6623 if (internal_relocs
== NULL
)
6626 irelend
= internal_relocs
+ sec
->reloc_count
6627 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
6628 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6629 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6631 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6634 bfd_signed_vma sym_offset
;
6635 unsigned int r_type
;
6636 unsigned long r_symndx
;
6638 unsigned long instruction
;
6640 /* Turn jalr into bgezal, and jr into beq, if they're marked
6641 with a JALR relocation, that indicate where they jump to.
6642 This saves some pipeline bubbles. */
6643 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
6644 if (r_type
!= R_MIPS_JALR
)
6647 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
6648 /* Compute the address of the jump target. */
6649 if (r_symndx
>= extsymoff
)
6651 struct mips_elf_link_hash_entry
*h
6652 = ((struct mips_elf_link_hash_entry
*)
6653 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
6655 while (h
->root
.root
.type
== bfd_link_hash_indirect
6656 || h
->root
.root
.type
== bfd_link_hash_warning
)
6657 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
6659 /* If a symbol is undefined, or if it may be overridden,
6661 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
6662 || h
->root
.root
.type
== bfd_link_hash_defweak
)
6663 && h
->root
.root
.u
.def
.section
)
6664 || (link_info
->shared
&& ! link_info
->symbolic
6665 && !h
->root
.forced_local
))
6668 sym_sec
= h
->root
.root
.u
.def
.section
;
6669 if (sym_sec
->output_section
)
6670 symval
= (h
->root
.root
.u
.def
.value
6671 + sym_sec
->output_section
->vma
6672 + sym_sec
->output_offset
);
6674 symval
= h
->root
.root
.u
.def
.value
;
6678 Elf_Internal_Sym
*isym
;
6680 /* Read this BFD's symbols if we haven't done so already. */
6681 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
6683 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6684 if (isymbuf
== NULL
)
6685 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
6686 symtab_hdr
->sh_info
, 0,
6688 if (isymbuf
== NULL
)
6692 isym
= isymbuf
+ r_symndx
;
6693 if (isym
->st_shndx
== SHN_UNDEF
)
6695 else if (isym
->st_shndx
== SHN_ABS
)
6696 sym_sec
= bfd_abs_section_ptr
;
6697 else if (isym
->st_shndx
== SHN_COMMON
)
6698 sym_sec
= bfd_com_section_ptr
;
6701 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6702 symval
= isym
->st_value
6703 + sym_sec
->output_section
->vma
6704 + sym_sec
->output_offset
;
6707 /* Compute branch offset, from delay slot of the jump to the
6709 sym_offset
= (symval
+ irel
->r_addend
)
6710 - (sec_start
+ irel
->r_offset
+ 4);
6712 /* Branch offset must be properly aligned. */
6713 if ((sym_offset
& 3) != 0)
6718 /* Check that it's in range. */
6719 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
6722 /* Get the section contents if we haven't done so already. */
6723 if (contents
== NULL
)
6725 /* Get cached copy if it exists. */
6726 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6727 contents
= elf_section_data (sec
)->this_hdr
.contents
;
6730 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
6735 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
6737 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
6738 if ((instruction
& 0xfc1fffff) == 0x0000f809)
6739 instruction
= 0x04110000;
6740 /* If it was jr <reg>, turn it into b <target>. */
6741 else if ((instruction
& 0xfc1fffff) == 0x00000008)
6742 instruction
= 0x10000000;
6746 instruction
|= (sym_offset
& 0xffff);
6747 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
6748 changed_contents
= TRUE
;
6751 if (contents
!= NULL
6752 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6754 if (!changed_contents
&& !link_info
->keep_memory
)
6758 /* Cache the section contents for elf_link_input_bfd. */
6759 elf_section_data (sec
)->this_hdr
.contents
= contents
;
6765 if (contents
!= NULL
6766 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6771 /* Adjust a symbol defined by a dynamic object and referenced by a
6772 regular object. The current definition is in some section of the
6773 dynamic object, but we're not including those sections. We have to
6774 change the definition to something the rest of the link can
6778 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6779 struct elf_link_hash_entry
*h
)
6782 struct mips_elf_link_hash_entry
*hmips
;
6785 dynobj
= elf_hash_table (info
)->dynobj
;
6787 /* Make sure we know what is going on here. */
6788 BFD_ASSERT (dynobj
!= NULL
6790 || h
->u
.weakdef
!= NULL
6793 && !h
->def_regular
)));
6795 /* If this symbol is defined in a dynamic object, we need to copy
6796 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6798 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6799 if (! info
->relocatable
6800 && hmips
->possibly_dynamic_relocs
!= 0
6801 && (h
->root
.type
== bfd_link_hash_defweak
6802 || !h
->def_regular
))
6804 mips_elf_allocate_dynamic_relocations
6805 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
6806 if (hmips
->readonly_reloc
)
6807 /* We tell the dynamic linker that there are relocations
6808 against the text segment. */
6809 info
->flags
|= DF_TEXTREL
;
6812 /* For a function, create a stub, if allowed. */
6813 if (! hmips
->no_fn_stub
6816 if (! elf_hash_table (info
)->dynamic_sections_created
)
6819 /* If this symbol is not defined in a regular file, then set
6820 the symbol to the stub location. This is required to make
6821 function pointers compare as equal between the normal
6822 executable and the shared library. */
6823 if (!h
->def_regular
)
6825 /* We need .stub section. */
6826 s
= bfd_get_section_by_name (dynobj
,
6827 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
6828 BFD_ASSERT (s
!= NULL
);
6830 h
->root
.u
.def
.section
= s
;
6831 h
->root
.u
.def
.value
= s
->size
;
6833 /* XXX Write this stub address somewhere. */
6834 h
->plt
.offset
= s
->size
;
6836 /* Make room for this stub code. */
6837 s
->size
+= MIPS_FUNCTION_STUB_SIZE
;
6839 /* The last half word of the stub will be filled with the index
6840 of this symbol in .dynsym section. */
6844 else if ((h
->type
== STT_FUNC
)
6847 /* This will set the entry for this symbol in the GOT to 0, and
6848 the dynamic linker will take care of this. */
6849 h
->root
.u
.def
.value
= 0;
6853 /* If this is a weak symbol, and there is a real definition, the
6854 processor independent code will have arranged for us to see the
6855 real definition first, and we can just use the same value. */
6856 if (h
->u
.weakdef
!= NULL
)
6858 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6859 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6860 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6861 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6865 /* This is a reference to a symbol defined by a dynamic object which
6866 is not a function. */
6871 /* Likewise, for VxWorks. */
6874 _bfd_mips_vxworks_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6875 struct elf_link_hash_entry
*h
)
6878 struct mips_elf_link_hash_entry
*hmips
;
6879 struct mips_elf_link_hash_table
*htab
;
6880 unsigned int power_of_two
;
6882 htab
= mips_elf_hash_table (info
);
6883 dynobj
= elf_hash_table (info
)->dynobj
;
6884 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6886 /* Make sure we know what is going on here. */
6887 BFD_ASSERT (dynobj
!= NULL
6890 || h
->u
.weakdef
!= NULL
6893 && !h
->def_regular
)));
6895 /* If the symbol is defined by a dynamic object, we need a PLT stub if
6896 either (a) we want to branch to the symbol or (b) we're linking an
6897 executable that needs a canonical function address. In the latter
6898 case, the canonical address will be the address of the executable's
6900 if ((hmips
->is_branch_target
6902 && h
->type
== STT_FUNC
6903 && hmips
->is_relocation_target
))
6907 && !h
->forced_local
)
6910 /* Locally-binding symbols do not need a PLT stub; we can refer to
6911 the functions directly. */
6912 else if (h
->needs_plt
6913 && (SYMBOL_CALLS_LOCAL (info
, h
)
6914 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6915 && h
->root
.type
== bfd_link_hash_undefweak
)))
6923 /* If this is the first symbol to need a PLT entry, allocate room
6924 for the header, and for the header's .rela.plt.unloaded entries. */
6925 if (htab
->splt
->size
== 0)
6927 htab
->splt
->size
+= htab
->plt_header_size
;
6929 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
6932 /* Assign the next .plt entry to this symbol. */
6933 h
->plt
.offset
= htab
->splt
->size
;
6934 htab
->splt
->size
+= htab
->plt_entry_size
;
6936 /* If the output file has no definition of the symbol, set the
6937 symbol's value to the address of the stub. For executables,
6938 point at the PLT load stub rather than the lazy resolution stub;
6939 this stub will become the canonical function address. */
6940 if (!h
->def_regular
)
6942 h
->root
.u
.def
.section
= htab
->splt
;
6943 h
->root
.u
.def
.value
= h
->plt
.offset
;
6945 h
->root
.u
.def
.value
+= 8;
6948 /* Make room for the .got.plt entry and the R_JUMP_SLOT relocation. */
6949 htab
->sgotplt
->size
+= 4;
6950 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
6952 /* Make room for the .rela.plt.unloaded relocations. */
6954 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
6959 /* If a function symbol is defined by a dynamic object, and we do not
6960 need a PLT stub for it, the symbol's value should be zero. */
6961 if (h
->type
== STT_FUNC
6966 h
->root
.u
.def
.value
= 0;
6970 /* If this is a weak symbol, and there is a real definition, the
6971 processor independent code will have arranged for us to see the
6972 real definition first, and we can just use the same value. */
6973 if (h
->u
.weakdef
!= NULL
)
6975 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6976 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6977 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6978 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6982 /* This is a reference to a symbol defined by a dynamic object which
6983 is not a function. */
6987 /* We must allocate the symbol in our .dynbss section, which will
6988 become part of the .bss section of the executable. There will be
6989 an entry for this symbol in the .dynsym section. The dynamic
6990 object will contain position independent code, so all references
6991 from the dynamic object to this symbol will go through the global
6992 offset table. The dynamic linker will use the .dynsym entry to
6993 determine the address it must put in the global offset table, so
6994 both the dynamic object and the regular object will refer to the
6995 same memory location for the variable. */
6997 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
6999 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
7003 /* We need to figure out the alignment required for this symbol. */
7004 power_of_two
= bfd_log2 (h
->size
);
7005 if (power_of_two
> 4)
7008 /* Apply the required alignment. */
7009 htab
->sdynbss
->size
= BFD_ALIGN (htab
->sdynbss
->size
,
7010 (bfd_size_type
) 1 << power_of_two
);
7011 if (power_of_two
> bfd_get_section_alignment (dynobj
, htab
->sdynbss
)
7012 && !bfd_set_section_alignment (dynobj
, htab
->sdynbss
, power_of_two
))
7015 /* Define the symbol as being at this point in the section. */
7016 h
->root
.u
.def
.section
= htab
->sdynbss
;
7017 h
->root
.u
.def
.value
= htab
->sdynbss
->size
;
7019 /* Increment the section size to make room for the symbol. */
7020 htab
->sdynbss
->size
+= h
->size
;
7025 /* This function is called after all the input files have been read,
7026 and the input sections have been assigned to output sections. We
7027 check for any mips16 stub sections that we can discard. */
7030 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
7031 struct bfd_link_info
*info
)
7037 struct mips_got_info
*g
;
7039 bfd_size_type loadable_size
= 0;
7040 bfd_size_type local_gotno
;
7042 struct mips_elf_count_tls_arg count_tls_arg
;
7043 struct mips_elf_link_hash_table
*htab
;
7045 htab
= mips_elf_hash_table (info
);
7047 /* The .reginfo section has a fixed size. */
7048 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
7050 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
7052 if (! (info
->relocatable
7053 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
))
7054 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7055 mips_elf_check_mips16_stubs
, NULL
);
7057 dynobj
= elf_hash_table (info
)->dynobj
;
7059 /* Relocatable links don't have it. */
7062 g
= mips_elf_got_info (dynobj
, &s
);
7066 /* Calculate the total loadable size of the output. That
7067 will give us the maximum number of GOT_PAGE entries
7069 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
7071 asection
*subsection
;
7073 for (subsection
= sub
->sections
;
7075 subsection
= subsection
->next
)
7077 if ((subsection
->flags
& SEC_ALLOC
) == 0)
7079 loadable_size
+= ((subsection
->size
+ 0xf)
7080 &~ (bfd_size_type
) 0xf);
7084 /* There has to be a global GOT entry for every symbol with
7085 a dynamic symbol table index of DT_MIPS_GOTSYM or
7086 higher. Therefore, it make sense to put those symbols
7087 that need GOT entries at the end of the symbol table. We
7089 if (! mips_elf_sort_hash_table (info
, 1))
7092 if (g
->global_gotsym
!= NULL
)
7093 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
7095 /* If there are no global symbols, or none requiring
7096 relocations, then GLOBAL_GOTSYM will be NULL. */
7099 /* In the worst case, we'll get one stub per dynamic symbol, plus
7100 one to account for the dummy entry at the end required by IRIX
7102 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
* (i
+ 1);
7104 if (htab
->is_vxworks
)
7105 /* There's no need to allocate page entries for VxWorks; R_MIPS_GOT16
7106 relocations against local symbols evaluate to "G", and the EABI does
7107 not include R_MIPS_GOT_PAGE. */
7110 /* Assume there are two loadable segments consisting of contiguous
7111 sections. Is 5 enough? */
7112 local_gotno
= (loadable_size
>> 16) + 5;
7114 g
->local_gotno
+= local_gotno
;
7115 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7117 g
->global_gotno
= i
;
7118 s
->size
+= i
* MIPS_ELF_GOT_SIZE (output_bfd
);
7120 /* We need to calculate tls_gotno for global symbols at this point
7121 instead of building it up earlier, to avoid doublecounting
7122 entries for one global symbol from multiple input files. */
7123 count_tls_arg
.info
= info
;
7124 count_tls_arg
.needed
= 0;
7125 elf_link_hash_traverse (elf_hash_table (info
),
7126 mips_elf_count_global_tls_entries
,
7128 g
->tls_gotno
+= count_tls_arg
.needed
;
7129 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
7131 mips_elf_resolve_final_got_entries (g
);
7133 /* VxWorks does not support multiple GOTs. It initializes $gp to
7134 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
7136 if (!htab
->is_vxworks
&& s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
7138 if (! mips_elf_multi_got (output_bfd
, info
, g
, s
, local_gotno
))
7143 /* Set up TLS entries for the first GOT. */
7144 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
7145 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
7151 /* Set the sizes of the dynamic sections. */
7154 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
7155 struct bfd_link_info
*info
)
7158 asection
*s
, *sreldyn
;
7159 bfd_boolean reltext
;
7160 struct mips_elf_link_hash_table
*htab
;
7162 htab
= mips_elf_hash_table (info
);
7163 dynobj
= elf_hash_table (info
)->dynobj
;
7164 BFD_ASSERT (dynobj
!= NULL
);
7166 if (elf_hash_table (info
)->dynamic_sections_created
)
7168 /* Set the contents of the .interp section to the interpreter. */
7169 if (info
->executable
)
7171 s
= bfd_get_section_by_name (dynobj
, ".interp");
7172 BFD_ASSERT (s
!= NULL
);
7174 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
7176 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
7180 /* The check_relocs and adjust_dynamic_symbol entry points have
7181 determined the sizes of the various dynamic sections. Allocate
7185 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7189 /* It's OK to base decisions on the section name, because none
7190 of the dynobj section names depend upon the input files. */
7191 name
= bfd_get_section_name (dynobj
, s
);
7193 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7196 if (strncmp (name
, ".rel", 4) == 0)
7200 const char *outname
;
7203 /* If this relocation section applies to a read only
7204 section, then we probably need a DT_TEXTREL entry.
7205 If the relocation section is .rel(a).dyn, we always
7206 assert a DT_TEXTREL entry rather than testing whether
7207 there exists a relocation to a read only section or
7209 outname
= bfd_get_section_name (output_bfd
,
7211 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
7213 && (target
->flags
& SEC_READONLY
) != 0
7214 && (target
->flags
& SEC_ALLOC
) != 0)
7215 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
7218 /* We use the reloc_count field as a counter if we need
7219 to copy relocs into the output file. */
7220 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
7223 /* If combreloc is enabled, elf_link_sort_relocs() will
7224 sort relocations, but in a different way than we do,
7225 and before we're done creating relocations. Also, it
7226 will move them around between input sections'
7227 relocation's contents, so our sorting would be
7228 broken, so don't let it run. */
7229 info
->combreloc
= 0;
7232 else if (htab
->is_vxworks
&& strcmp (name
, ".got") == 0)
7234 /* Executables do not need a GOT. */
7237 /* Allocate relocations for all but the reserved entries. */
7238 struct mips_got_info
*g
;
7241 g
= mips_elf_got_info (dynobj
, NULL
);
7242 count
= (g
->global_gotno
7244 - MIPS_RESERVED_GOTNO (info
));
7245 mips_elf_allocate_dynamic_relocations (dynobj
, info
, count
);
7248 else if (!htab
->is_vxworks
&& strncmp (name
, ".got", 4) == 0)
7250 /* _bfd_mips_elf_always_size_sections() has already done
7251 most of the work, but some symbols may have been mapped
7252 to versions that we must now resolve in the got_entries
7254 struct mips_got_info
*gg
= mips_elf_got_info (dynobj
, NULL
);
7255 struct mips_got_info
*g
= gg
;
7256 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
7257 unsigned int needed_relocs
= 0;
7261 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (output_bfd
);
7262 set_got_offset_arg
.info
= info
;
7264 /* NOTE 2005-02-03: How can this call, or the next, ever
7265 find any indirect entries to resolve? They were all
7266 resolved in mips_elf_multi_got. */
7267 mips_elf_resolve_final_got_entries (gg
);
7268 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
7270 unsigned int save_assign
;
7272 mips_elf_resolve_final_got_entries (g
);
7274 /* Assign offsets to global GOT entries. */
7275 save_assign
= g
->assigned_gotno
;
7276 g
->assigned_gotno
= g
->local_gotno
;
7277 set_got_offset_arg
.g
= g
;
7278 set_got_offset_arg
.needed_relocs
= 0;
7279 htab_traverse (g
->got_entries
,
7280 mips_elf_set_global_got_offset
,
7281 &set_got_offset_arg
);
7282 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
7283 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
7284 <= g
->global_gotno
);
7286 g
->assigned_gotno
= save_assign
;
7289 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
7290 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
7291 + g
->next
->global_gotno
7292 + g
->next
->tls_gotno
7293 + MIPS_RESERVED_GOTNO (info
));
7299 struct mips_elf_count_tls_arg arg
;
7303 htab_traverse (gg
->got_entries
, mips_elf_count_local_tls_relocs
,
7305 elf_link_hash_traverse (elf_hash_table (info
),
7306 mips_elf_count_global_tls_relocs
,
7309 needed_relocs
+= arg
.needed
;
7313 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
7316 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
7318 /* IRIX rld assumes that the function stub isn't at the end
7319 of .text section. So put a dummy. XXX */
7320 s
->size
+= MIPS_FUNCTION_STUB_SIZE
;
7322 else if (! info
->shared
7323 && ! mips_elf_hash_table (info
)->use_rld_obj_head
7324 && strncmp (name
, ".rld_map", 8) == 0)
7326 /* We add a room for __rld_map. It will be filled in by the
7327 rtld to contain a pointer to the _r_debug structure. */
7330 else if (SGI_COMPAT (output_bfd
)
7331 && strncmp (name
, ".compact_rel", 12) == 0)
7332 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
7333 else if (strncmp (name
, ".init", 5) != 0
7334 && s
!= htab
->sgotplt
7337 /* It's not one of our sections, so don't allocate space. */
7343 s
->flags
|= SEC_EXCLUDE
;
7347 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
7350 /* Allocate memory for this section last, since we may increase its
7352 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
7358 /* Allocate memory for the section contents. */
7359 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
7360 if (s
->contents
== NULL
)
7362 bfd_set_error (bfd_error_no_memory
);
7367 /* Allocate memory for the .rel(a).dyn section. */
7368 if (sreldyn
!= NULL
)
7370 sreldyn
->contents
= bfd_zalloc (dynobj
, sreldyn
->size
);
7371 if (sreldyn
->contents
== NULL
)
7373 bfd_set_error (bfd_error_no_memory
);
7378 if (elf_hash_table (info
)->dynamic_sections_created
)
7380 /* Add some entries to the .dynamic section. We fill in the
7381 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
7382 must add the entries now so that we get the correct size for
7383 the .dynamic section. The DT_DEBUG entry is filled in by the
7384 dynamic linker and used by the debugger. */
7387 /* SGI object has the equivalence of DT_DEBUG in the
7388 DT_MIPS_RLD_MAP entry. */
7389 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
7391 if (!SGI_COMPAT (output_bfd
))
7393 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
7399 /* Shared libraries on traditional mips have DT_DEBUG. */
7400 if (!SGI_COMPAT (output_bfd
))
7402 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
7407 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
7408 info
->flags
|= DF_TEXTREL
;
7410 if ((info
->flags
& DF_TEXTREL
) != 0)
7412 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
7416 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
7419 if (htab
->is_vxworks
)
7421 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
7422 use any of the DT_MIPS_* tags. */
7423 if (mips_elf_rel_dyn_section (info
, FALSE
))
7425 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
7428 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
7431 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
7434 if (htab
->splt
->size
> 0)
7436 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
7439 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
7442 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
7448 if (mips_elf_rel_dyn_section (info
, FALSE
))
7450 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
7453 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
7456 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
7460 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
7463 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
7466 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
7469 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
7472 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
7475 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
7478 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
7481 if (IRIX_COMPAT (dynobj
) == ict_irix5
7482 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
7485 if (IRIX_COMPAT (dynobj
) == ict_irix6
7486 && (bfd_get_section_by_name
7487 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
7488 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
7496 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
7497 Adjust its R_ADDEND field so that it is correct for the output file.
7498 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
7499 and sections respectively; both use symbol indexes. */
7502 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
7503 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
7504 asection
**local_sections
, Elf_Internal_Rela
*rel
)
7506 unsigned int r_type
, r_symndx
;
7507 Elf_Internal_Sym
*sym
;
7510 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
7512 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
7513 if (r_type
== R_MIPS16_GPREL
7514 || r_type
== R_MIPS_GPREL16
7515 || r_type
== R_MIPS_GPREL32
7516 || r_type
== R_MIPS_LITERAL
)
7518 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
7519 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
7522 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
7523 sym
= local_syms
+ r_symndx
;
7525 /* Adjust REL's addend to account for section merging. */
7526 if (!info
->relocatable
)
7528 sec
= local_sections
[r_symndx
];
7529 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
7532 /* This would normally be done by the rela_normal code in elflink.c. */
7533 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7534 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
7538 /* Relocate a MIPS ELF section. */
7541 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
7542 bfd
*input_bfd
, asection
*input_section
,
7543 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
7544 Elf_Internal_Sym
*local_syms
,
7545 asection
**local_sections
)
7547 Elf_Internal_Rela
*rel
;
7548 const Elf_Internal_Rela
*relend
;
7550 bfd_boolean use_saved_addend_p
= FALSE
;
7551 const struct elf_backend_data
*bed
;
7553 bed
= get_elf_backend_data (output_bfd
);
7554 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7555 for (rel
= relocs
; rel
< relend
; ++rel
)
7559 reloc_howto_type
*howto
;
7560 bfd_boolean require_jalx
;
7561 /* TRUE if the relocation is a RELA relocation, rather than a
7563 bfd_boolean rela_relocation_p
= TRUE
;
7564 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
7567 /* Find the relocation howto for this relocation. */
7568 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
7570 /* Some 32-bit code uses R_MIPS_64. In particular, people use
7571 64-bit code, but make sure all their addresses are in the
7572 lowermost or uppermost 32-bit section of the 64-bit address
7573 space. Thus, when they use an R_MIPS_64 they mean what is
7574 usually meant by R_MIPS_32, with the exception that the
7575 stored value is sign-extended to 64 bits. */
7576 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
7578 /* On big-endian systems, we need to lie about the position
7580 if (bfd_big_endian (input_bfd
))
7584 /* NewABI defaults to RELA relocations. */
7585 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
7586 NEWABI_P (input_bfd
)
7587 && (MIPS_RELOC_RELA_P
7588 (input_bfd
, input_section
,
7591 if (!use_saved_addend_p
)
7593 Elf_Internal_Shdr
*rel_hdr
;
7595 /* If these relocations were originally of the REL variety,
7596 we must pull the addend out of the field that will be
7597 relocated. Otherwise, we simply use the contents of the
7598 RELA relocation. To determine which flavor or relocation
7599 this is, we depend on the fact that the INPUT_SECTION's
7600 REL_HDR is read before its REL_HDR2. */
7601 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
7602 if ((size_t) (rel
- relocs
)
7603 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
7604 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
7605 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
7607 bfd_byte
*location
= contents
+ rel
->r_offset
;
7609 /* Note that this is a REL relocation. */
7610 rela_relocation_p
= FALSE
;
7612 /* Get the addend, which is stored in the input file. */
7613 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
,
7615 addend
= mips_elf_obtain_contents (howto
, rel
, input_bfd
,
7617 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, FALSE
,
7620 addend
&= howto
->src_mask
;
7622 /* For some kinds of relocations, the ADDEND is a
7623 combination of the addend stored in two different
7625 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS16_HI16
7626 || (r_type
== R_MIPS_GOT16
7627 && mips_elf_local_relocation_p (input_bfd
, rel
,
7628 local_sections
, FALSE
)))
7631 const Elf_Internal_Rela
*lo16_relocation
;
7632 reloc_howto_type
*lo16_howto
;
7633 bfd_byte
*lo16_location
;
7636 if (r_type
== R_MIPS16_HI16
)
7637 lo16_type
= R_MIPS16_LO16
;
7639 lo16_type
= R_MIPS_LO16
;
7641 /* The combined value is the sum of the HI16 addend,
7642 left-shifted by sixteen bits, and the LO16
7643 addend, sign extended. (Usually, the code does
7644 a `lui' of the HI16 value, and then an `addiu' of
7647 Scan ahead to find a matching LO16 relocation.
7649 According to the MIPS ELF ABI, the R_MIPS_LO16
7650 relocation must be immediately following.
7651 However, for the IRIX6 ABI, the next relocation
7652 may be a composed relocation consisting of
7653 several relocations for the same address. In
7654 that case, the R_MIPS_LO16 relocation may occur
7655 as one of these. We permit a similar extension
7656 in general, as that is useful for GCC. */
7657 lo16_relocation
= mips_elf_next_relocation (input_bfd
,
7660 if (lo16_relocation
== NULL
)
7663 lo16_location
= contents
+ lo16_relocation
->r_offset
;
7665 /* Obtain the addend kept there. */
7666 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
,
7668 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, lo16_type
, FALSE
,
7670 l
= mips_elf_obtain_contents (lo16_howto
, lo16_relocation
,
7671 input_bfd
, contents
);
7672 _bfd_mips16_elf_reloc_shuffle (input_bfd
, lo16_type
, FALSE
,
7674 l
&= lo16_howto
->src_mask
;
7675 l
<<= lo16_howto
->rightshift
;
7676 l
= _bfd_mips_elf_sign_extend (l
, 16);
7680 /* Compute the combined addend. */
7684 addend
<<= howto
->rightshift
;
7687 addend
= rel
->r_addend
;
7688 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
7689 local_syms
, local_sections
, rel
);
7692 if (info
->relocatable
)
7694 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
7695 && bfd_big_endian (input_bfd
))
7698 if (!rela_relocation_p
&& rel
->r_addend
)
7700 addend
+= rel
->r_addend
;
7701 if (r_type
== R_MIPS_HI16
7702 || r_type
== R_MIPS_GOT16
)
7703 addend
= mips_elf_high (addend
);
7704 else if (r_type
== R_MIPS_HIGHER
)
7705 addend
= mips_elf_higher (addend
);
7706 else if (r_type
== R_MIPS_HIGHEST
)
7707 addend
= mips_elf_highest (addend
);
7709 addend
>>= howto
->rightshift
;
7711 /* We use the source mask, rather than the destination
7712 mask because the place to which we are writing will be
7713 source of the addend in the final link. */
7714 addend
&= howto
->src_mask
;
7716 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
7717 /* See the comment above about using R_MIPS_64 in the 32-bit
7718 ABI. Here, we need to update the addend. It would be
7719 possible to get away with just using the R_MIPS_32 reloc
7720 but for endianness. */
7726 if (addend
& ((bfd_vma
) 1 << 31))
7728 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
7735 /* If we don't know that we have a 64-bit type,
7736 do two separate stores. */
7737 if (bfd_big_endian (input_bfd
))
7739 /* Store the sign-bits (which are most significant)
7741 low_bits
= sign_bits
;
7747 high_bits
= sign_bits
;
7749 bfd_put_32 (input_bfd
, low_bits
,
7750 contents
+ rel
->r_offset
);
7751 bfd_put_32 (input_bfd
, high_bits
,
7752 contents
+ rel
->r_offset
+ 4);
7756 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
7757 input_bfd
, input_section
,
7762 /* Go on to the next relocation. */
7766 /* In the N32 and 64-bit ABIs there may be multiple consecutive
7767 relocations for the same offset. In that case we are
7768 supposed to treat the output of each relocation as the addend
7770 if (rel
+ 1 < relend
7771 && rel
->r_offset
== rel
[1].r_offset
7772 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
7773 use_saved_addend_p
= TRUE
;
7775 use_saved_addend_p
= FALSE
;
7777 /* Figure out what value we are supposed to relocate. */
7778 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
7779 input_section
, info
, rel
,
7780 addend
, howto
, local_syms
,
7781 local_sections
, &value
,
7782 &name
, &require_jalx
,
7783 use_saved_addend_p
))
7785 case bfd_reloc_continue
:
7786 /* There's nothing to do. */
7789 case bfd_reloc_undefined
:
7790 /* mips_elf_calculate_relocation already called the
7791 undefined_symbol callback. There's no real point in
7792 trying to perform the relocation at this point, so we
7793 just skip ahead to the next relocation. */
7796 case bfd_reloc_notsupported
:
7797 msg
= _("internal error: unsupported relocation error");
7798 info
->callbacks
->warning
7799 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
7802 case bfd_reloc_overflow
:
7803 if (use_saved_addend_p
)
7804 /* Ignore overflow until we reach the last relocation for
7805 a given location. */
7809 BFD_ASSERT (name
!= NULL
);
7810 if (! ((*info
->callbacks
->reloc_overflow
)
7811 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
7812 input_bfd
, input_section
, rel
->r_offset
)))
7825 /* If we've got another relocation for the address, keep going
7826 until we reach the last one. */
7827 if (use_saved_addend_p
)
7833 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
7834 /* See the comment above about using R_MIPS_64 in the 32-bit
7835 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
7836 that calculated the right value. Now, however, we
7837 sign-extend the 32-bit result to 64-bits, and store it as a
7838 64-bit value. We are especially generous here in that we
7839 go to extreme lengths to support this usage on systems with
7840 only a 32-bit VMA. */
7846 if (value
& ((bfd_vma
) 1 << 31))
7848 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
7855 /* If we don't know that we have a 64-bit type,
7856 do two separate stores. */
7857 if (bfd_big_endian (input_bfd
))
7859 /* Undo what we did above. */
7861 /* Store the sign-bits (which are most significant)
7863 low_bits
= sign_bits
;
7869 high_bits
= sign_bits
;
7871 bfd_put_32 (input_bfd
, low_bits
,
7872 contents
+ rel
->r_offset
);
7873 bfd_put_32 (input_bfd
, high_bits
,
7874 contents
+ rel
->r_offset
+ 4);
7878 /* Actually perform the relocation. */
7879 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
7880 input_bfd
, input_section
,
7881 contents
, require_jalx
))
7888 /* If NAME is one of the special IRIX6 symbols defined by the linker,
7889 adjust it appropriately now. */
7892 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7893 const char *name
, Elf_Internal_Sym
*sym
)
7895 /* The linker script takes care of providing names and values for
7896 these, but we must place them into the right sections. */
7897 static const char* const text_section_symbols
[] = {
7900 "__dso_displacement",
7902 "__program_header_table",
7906 static const char* const data_section_symbols
[] = {
7914 const char* const *p
;
7917 for (i
= 0; i
< 2; ++i
)
7918 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
7921 if (strcmp (*p
, name
) == 0)
7923 /* All of these symbols are given type STT_SECTION by the
7925 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7926 sym
->st_other
= STO_PROTECTED
;
7928 /* The IRIX linker puts these symbols in special sections. */
7930 sym
->st_shndx
= SHN_MIPS_TEXT
;
7932 sym
->st_shndx
= SHN_MIPS_DATA
;
7938 /* Finish up dynamic symbol handling. We set the contents of various
7939 dynamic sections here. */
7942 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
7943 struct bfd_link_info
*info
,
7944 struct elf_link_hash_entry
*h
,
7945 Elf_Internal_Sym
*sym
)
7949 struct mips_got_info
*g
, *gg
;
7952 dynobj
= elf_hash_table (info
)->dynobj
;
7954 if (h
->plt
.offset
!= MINUS_ONE
)
7957 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7959 /* This symbol has a stub. Set it up. */
7961 BFD_ASSERT (h
->dynindx
!= -1);
7963 s
= bfd_get_section_by_name (dynobj
,
7964 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7965 BFD_ASSERT (s
!= NULL
);
7967 /* FIXME: Can h->dynindx be more than 64K? */
7968 if (h
->dynindx
& 0xffff0000)
7971 /* Fill the stub. */
7972 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
);
7973 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ 4);
7974 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ 8);
7975 bfd_put_32 (output_bfd
, STUB_LI16 (output_bfd
) + h
->dynindx
, stub
+ 12);
7977 BFD_ASSERT (h
->plt
.offset
<= s
->size
);
7978 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7980 /* Mark the symbol as undefined. plt.offset != -1 occurs
7981 only for the referenced symbol. */
7982 sym
->st_shndx
= SHN_UNDEF
;
7984 /* The run-time linker uses the st_value field of the symbol
7985 to reset the global offset table entry for this external
7986 to its stub address when unlinking a shared object. */
7987 sym
->st_value
= (s
->output_section
->vma
+ s
->output_offset
7991 BFD_ASSERT (h
->dynindx
!= -1
7992 || h
->forced_local
);
7994 sgot
= mips_elf_got_section (dynobj
, FALSE
);
7995 BFD_ASSERT (sgot
!= NULL
);
7996 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
7997 g
= mips_elf_section_data (sgot
)->u
.got_info
;
7998 BFD_ASSERT (g
!= NULL
);
8000 /* Run through the global symbol table, creating GOT entries for all
8001 the symbols that need them. */
8002 if (g
->global_gotsym
!= NULL
8003 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
8008 value
= sym
->st_value
;
8009 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
, R_MIPS_GOT16
, info
);
8010 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
8013 if (g
->next
&& h
->dynindx
!= -1 && h
->type
!= STT_TLS
)
8015 struct mips_got_entry e
, *p
;
8021 e
.abfd
= output_bfd
;
8023 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
8026 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
8029 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
8034 || (elf_hash_table (info
)->dynamic_sections_created
8036 && p
->d
.h
->root
.def_dynamic
8037 && !p
->d
.h
->root
.def_regular
))
8039 /* Create an R_MIPS_REL32 relocation for this entry. Due to
8040 the various compatibility problems, it's easier to mock
8041 up an R_MIPS_32 or R_MIPS_64 relocation and leave
8042 mips_elf_create_dynamic_relocation to calculate the
8043 appropriate addend. */
8044 Elf_Internal_Rela rel
[3];
8046 memset (rel
, 0, sizeof (rel
));
8047 if (ABI_64_P (output_bfd
))
8048 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
8050 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
8051 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
8054 if (! (mips_elf_create_dynamic_relocation
8055 (output_bfd
, info
, rel
,
8056 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
8060 entry
= sym
->st_value
;
8061 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
8066 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
8067 name
= h
->root
.root
.string
;
8068 if (strcmp (name
, "_DYNAMIC") == 0
8069 || h
== elf_hash_table (info
)->hgot
)
8070 sym
->st_shndx
= SHN_ABS
;
8071 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
8072 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
8074 sym
->st_shndx
= SHN_ABS
;
8075 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8078 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
8080 sym
->st_shndx
= SHN_ABS
;
8081 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8082 sym
->st_value
= elf_gp (output_bfd
);
8084 else if (SGI_COMPAT (output_bfd
))
8086 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
8087 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
8089 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8090 sym
->st_other
= STO_PROTECTED
;
8092 sym
->st_shndx
= SHN_MIPS_DATA
;
8094 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
8096 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
8097 sym
->st_other
= STO_PROTECTED
;
8098 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
8099 sym
->st_shndx
= SHN_ABS
;
8101 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
8103 if (h
->type
== STT_FUNC
)
8104 sym
->st_shndx
= SHN_MIPS_TEXT
;
8105 else if (h
->type
== STT_OBJECT
)
8106 sym
->st_shndx
= SHN_MIPS_DATA
;
8110 /* Handle the IRIX6-specific symbols. */
8111 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
8112 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
8116 if (! mips_elf_hash_table (info
)->use_rld_obj_head
8117 && (strcmp (name
, "__rld_map") == 0
8118 || strcmp (name
, "__RLD_MAP") == 0))
8120 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
8121 BFD_ASSERT (s
!= NULL
);
8122 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
8123 bfd_put_32 (output_bfd
, 0, s
->contents
);
8124 if (mips_elf_hash_table (info
)->rld_value
== 0)
8125 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8127 else if (mips_elf_hash_table (info
)->use_rld_obj_head
8128 && strcmp (name
, "__rld_obj_head") == 0)
8130 /* IRIX6 does not use a .rld_map section. */
8131 if (IRIX_COMPAT (output_bfd
) == ict_irix5
8132 || IRIX_COMPAT (output_bfd
) == ict_none
)
8133 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
8135 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
8139 /* If this is a mips16 symbol, force the value to be even. */
8140 if (sym
->st_other
== STO_MIPS16
)
8141 sym
->st_value
&= ~1;
8146 /* Likewise, for VxWorks. */
8149 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
8150 struct bfd_link_info
*info
,
8151 struct elf_link_hash_entry
*h
,
8152 Elf_Internal_Sym
*sym
)
8156 struct mips_got_info
*g
;
8157 struct mips_elf_link_hash_table
*htab
;
8159 htab
= mips_elf_hash_table (info
);
8160 dynobj
= elf_hash_table (info
)->dynobj
;
8162 if (h
->plt
.offset
!= (bfd_vma
) -1)
8165 bfd_vma plt_address
, plt_index
, got_address
, got_offset
, branch_offset
;
8166 Elf_Internal_Rela rel
;
8167 static const bfd_vma
*plt_entry
;
8169 BFD_ASSERT (h
->dynindx
!= -1);
8170 BFD_ASSERT (htab
->splt
!= NULL
);
8171 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
8173 /* Calculate the address of the .plt entry. */
8174 plt_address
= (htab
->splt
->output_section
->vma
8175 + htab
->splt
->output_offset
8178 /* Calculate the index of the entry. */
8179 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
8180 / htab
->plt_entry_size
);
8182 /* Calculate the address of the .got.plt entry. */
8183 got_address
= (htab
->sgotplt
->output_section
->vma
8184 + htab
->sgotplt
->output_offset
8187 /* Calculate the offset of the .got.plt entry from
8188 _GLOBAL_OFFSET_TABLE_. */
8189 got_offset
= mips_elf_gotplt_index (info
, h
);
8191 /* Calculate the offset for the branch at the start of the PLT
8192 entry. The branch jumps to the beginning of .plt. */
8193 branch_offset
= -(h
->plt
.offset
/ 4 + 1) & 0xffff;
8195 /* Fill in the initial value of the .got.plt entry. */
8196 bfd_put_32 (output_bfd
, plt_address
,
8197 htab
->sgotplt
->contents
+ plt_index
* 4);
8199 /* Find out where the .plt entry should go. */
8200 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
8204 plt_entry
= mips_vxworks_shared_plt_entry
;
8205 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
8206 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
8210 bfd_vma got_address_high
, got_address_low
;
8212 plt_entry
= mips_vxworks_exec_plt_entry
;
8213 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
8214 got_address_low
= got_address
& 0xffff;
8216 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
8217 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
8218 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
8219 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
8220 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
8221 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
8222 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
8223 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
8225 loc
= (htab
->srelplt2
->contents
8226 + (plt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
8228 /* Emit a relocation for the .got.plt entry. */
8229 rel
.r_offset
= got_address
;
8230 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
8231 rel
.r_addend
= h
->plt
.offset
;
8232 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
8234 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
8235 loc
+= sizeof (Elf32_External_Rela
);
8236 rel
.r_offset
= plt_address
+ 8;
8237 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
8238 rel
.r_addend
= got_offset
;
8239 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
8241 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
8242 loc
+= sizeof (Elf32_External_Rela
);
8244 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
8245 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
8248 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
8249 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
8250 rel
.r_offset
= got_address
;
8251 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
8253 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
8255 if (!h
->def_regular
)
8256 sym
->st_shndx
= SHN_UNDEF
;
8259 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
8261 sgot
= mips_elf_got_section (dynobj
, FALSE
);
8262 BFD_ASSERT (sgot
!= NULL
);
8263 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
8264 g
= mips_elf_section_data (sgot
)->u
.got_info
;
8265 BFD_ASSERT (g
!= NULL
);
8267 /* See if this symbol has an entry in the GOT. */
8268 if (g
->global_gotsym
!= NULL
8269 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
8272 Elf_Internal_Rela outrel
;
8276 /* Install the symbol value in the GOT. */
8277 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
8278 R_MIPS_GOT16
, info
);
8279 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
8281 /* Add a dynamic relocation for it. */
8282 s
= mips_elf_rel_dyn_section (info
, FALSE
);
8283 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
8284 outrel
.r_offset
= (sgot
->output_section
->vma
8285 + sgot
->output_offset
8287 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
8288 outrel
.r_addend
= 0;
8289 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
8292 /* Emit a copy reloc, if needed. */
8295 Elf_Internal_Rela rel
;
8297 BFD_ASSERT (h
->dynindx
!= -1);
8299 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
8300 + h
->root
.u
.def
.section
->output_offset
8301 + h
->root
.u
.def
.value
);
8302 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
8304 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
8305 htab
->srelbss
->contents
8306 + (htab
->srelbss
->reloc_count
8307 * sizeof (Elf32_External_Rela
)));
8308 ++htab
->srelbss
->reloc_count
;
8311 /* If this is a mips16 symbol, force the value to be even. */
8312 if (sym
->st_other
== STO_MIPS16
)
8313 sym
->st_value
&= ~1;
8318 /* Install the PLT header for a VxWorks executable and finalize the
8319 contents of .rela.plt.unloaded. */
8322 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
8324 Elf_Internal_Rela rela
;
8326 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
8327 static const bfd_vma
*plt_entry
;
8328 struct mips_elf_link_hash_table
*htab
;
8330 htab
= mips_elf_hash_table (info
);
8331 plt_entry
= mips_vxworks_exec_plt0_entry
;
8333 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
8334 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
8335 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
8336 + htab
->root
.hgot
->root
.u
.def
.value
);
8338 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
8339 got_value_low
= got_value
& 0xffff;
8341 /* Calculate the address of the PLT header. */
8342 plt_address
= htab
->splt
->output_section
->vma
+ htab
->splt
->output_offset
;
8344 /* Install the PLT header. */
8345 loc
= htab
->splt
->contents
;
8346 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
8347 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
8348 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
8349 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
8350 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
8351 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
8353 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
8354 loc
= htab
->srelplt2
->contents
;
8355 rela
.r_offset
= plt_address
;
8356 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
8358 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8359 loc
+= sizeof (Elf32_External_Rela
);
8361 /* Output the relocation for the following addiu of
8362 %lo(_GLOBAL_OFFSET_TABLE_). */
8364 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
8365 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8366 loc
+= sizeof (Elf32_External_Rela
);
8368 /* Fix up the remaining relocations. They may have the wrong
8369 symbol index for _G_O_T_ or _P_L_T_ depending on the order
8370 in which symbols were output. */
8371 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
8373 Elf_Internal_Rela rel
;
8375 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
8376 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
8377 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
8378 loc
+= sizeof (Elf32_External_Rela
);
8380 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
8381 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
8382 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
8383 loc
+= sizeof (Elf32_External_Rela
);
8385 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
8386 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
8387 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
8388 loc
+= sizeof (Elf32_External_Rela
);
8392 /* Install the PLT header for a VxWorks shared library. */
8395 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
8398 struct mips_elf_link_hash_table
*htab
;
8400 htab
= mips_elf_hash_table (info
);
8402 /* We just need to copy the entry byte-by-byte. */
8403 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
8404 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
8405 htab
->splt
->contents
+ i
* 4);
8408 /* Finish up the dynamic sections. */
8411 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
8412 struct bfd_link_info
*info
)
8417 struct mips_got_info
*gg
, *g
;
8418 struct mips_elf_link_hash_table
*htab
;
8420 htab
= mips_elf_hash_table (info
);
8421 dynobj
= elf_hash_table (info
)->dynobj
;
8423 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8425 sgot
= mips_elf_got_section (dynobj
, FALSE
);
8430 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
8431 gg
= mips_elf_section_data (sgot
)->u
.got_info
;
8432 BFD_ASSERT (gg
!= NULL
);
8433 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
8434 BFD_ASSERT (g
!= NULL
);
8437 if (elf_hash_table (info
)->dynamic_sections_created
)
8441 BFD_ASSERT (sdyn
!= NULL
);
8442 BFD_ASSERT (g
!= NULL
);
8444 for (b
= sdyn
->contents
;
8445 b
< sdyn
->contents
+ sdyn
->size
;
8446 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
8448 Elf_Internal_Dyn dyn
;
8452 bfd_boolean swap_out_p
;
8454 /* Read in the current dynamic entry. */
8455 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
8457 /* Assume that we're going to modify it and write it out. */
8463 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
8467 BFD_ASSERT (htab
->is_vxworks
);
8468 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
8472 /* Rewrite DT_STRSZ. */
8474 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
8479 if (htab
->is_vxworks
)
8481 /* _GLOBAL_OFFSET_TABLE_ is defined to be the beginning
8482 of the ".got" section in DYNOBJ. */
8483 s
= bfd_get_section_by_name (dynobj
, name
);
8484 BFD_ASSERT (s
!= NULL
);
8485 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8489 s
= bfd_get_section_by_name (output_bfd
, name
);
8490 BFD_ASSERT (s
!= NULL
);
8491 dyn
.d_un
.d_ptr
= s
->vma
;
8495 case DT_MIPS_RLD_VERSION
:
8496 dyn
.d_un
.d_val
= 1; /* XXX */
8500 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
8503 case DT_MIPS_TIME_STAMP
:
8511 case DT_MIPS_ICHECKSUM
:
8516 case DT_MIPS_IVERSION
:
8521 case DT_MIPS_BASE_ADDRESS
:
8522 s
= output_bfd
->sections
;
8523 BFD_ASSERT (s
!= NULL
);
8524 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
8527 case DT_MIPS_LOCAL_GOTNO
:
8528 dyn
.d_un
.d_val
= g
->local_gotno
;
8531 case DT_MIPS_UNREFEXTNO
:
8532 /* The index into the dynamic symbol table which is the
8533 entry of the first external symbol that is not
8534 referenced within the same object. */
8535 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
8538 case DT_MIPS_GOTSYM
:
8539 if (gg
->global_gotsym
)
8541 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
8544 /* In case if we don't have global got symbols we default
8545 to setting DT_MIPS_GOTSYM to the same value as
8546 DT_MIPS_SYMTABNO, so we just fall through. */
8548 case DT_MIPS_SYMTABNO
:
8550 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
8551 s
= bfd_get_section_by_name (output_bfd
, name
);
8552 BFD_ASSERT (s
!= NULL
);
8554 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
8557 case DT_MIPS_HIPAGENO
:
8558 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO (info
);
8561 case DT_MIPS_RLD_MAP
:
8562 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
8565 case DT_MIPS_OPTIONS
:
8566 s
= (bfd_get_section_by_name
8567 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
8568 dyn
.d_un
.d_ptr
= s
->vma
;
8572 BFD_ASSERT (htab
->is_vxworks
);
8573 /* The count does not include the JUMP_SLOT relocations. */
8575 dyn
.d_un
.d_val
-= htab
->srelplt
->size
;
8579 BFD_ASSERT (htab
->is_vxworks
);
8580 dyn
.d_un
.d_val
= DT_RELA
;
8584 BFD_ASSERT (htab
->is_vxworks
);
8585 dyn
.d_un
.d_val
= htab
->srelplt
->size
;
8589 BFD_ASSERT (htab
->is_vxworks
);
8590 dyn
.d_un
.d_val
= (htab
->srelplt
->output_section
->vma
8591 + htab
->srelplt
->output_offset
);
8600 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
8605 if (sgot
!= NULL
&& sgot
->size
> 0)
8607 if (htab
->is_vxworks
)
8609 /* The first entry of the global offset table points to the
8610 ".dynamic" section. The second is initialized by the
8611 loader and contains the shared library identifier.
8612 The third is also initialized by the loader and points
8613 to the lazy resolution stub. */
8614 MIPS_ELF_PUT_WORD (output_bfd
,
8615 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
8617 MIPS_ELF_PUT_WORD (output_bfd
, 0,
8618 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
8619 MIPS_ELF_PUT_WORD (output_bfd
, 0,
8621 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
8625 /* The first entry of the global offset table will be filled at
8626 runtime. The second entry will be used by some runtime loaders.
8627 This isn't the case of IRIX rld. */
8628 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
8629 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
8630 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
8635 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
8636 = MIPS_ELF_GOT_SIZE (output_bfd
);
8638 /* Generate dynamic relocations for the non-primary gots. */
8639 if (gg
!= NULL
&& gg
->next
)
8641 Elf_Internal_Rela rel
[3];
8644 memset (rel
, 0, sizeof (rel
));
8645 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
8647 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
8649 bfd_vma index
= g
->next
->local_gotno
+ g
->next
->global_gotno
8650 + g
->next
->tls_gotno
;
8652 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
8653 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
8654 MIPS_ELF_PUT_WORD (output_bfd
, 0x80000000, sgot
->contents
8655 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
8660 while (index
< g
->assigned_gotno
)
8662 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
8663 = index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
8664 if (!(mips_elf_create_dynamic_relocation
8665 (output_bfd
, info
, rel
, NULL
,
8666 bfd_abs_section_ptr
,
8669 BFD_ASSERT (addend
== 0);
8674 /* The generation of dynamic relocations for the non-primary gots
8675 adds more dynamic relocations. We cannot count them until
8678 if (elf_hash_table (info
)->dynamic_sections_created
)
8681 bfd_boolean swap_out_p
;
8683 BFD_ASSERT (sdyn
!= NULL
);
8685 for (b
= sdyn
->contents
;
8686 b
< sdyn
->contents
+ sdyn
->size
;
8687 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
8689 Elf_Internal_Dyn dyn
;
8692 /* Read in the current dynamic entry. */
8693 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
8695 /* Assume that we're going to modify it and write it out. */
8701 /* Reduce DT_RELSZ to account for any relocations we
8702 decided not to make. This is for the n64 irix rld,
8703 which doesn't seem to apply any relocations if there
8704 are trailing null entries. */
8705 s
= mips_elf_rel_dyn_section (info
, FALSE
);
8706 dyn
.d_un
.d_val
= (s
->reloc_count
8707 * (ABI_64_P (output_bfd
)
8708 ? sizeof (Elf64_Mips_External_Rel
)
8709 : sizeof (Elf32_External_Rel
)));
8718 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
8725 Elf32_compact_rel cpt
;
8727 if (SGI_COMPAT (output_bfd
))
8729 /* Write .compact_rel section out. */
8730 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
8734 cpt
.num
= s
->reloc_count
;
8736 cpt
.offset
= (s
->output_section
->filepos
8737 + sizeof (Elf32_External_compact_rel
));
8740 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
8741 ((Elf32_External_compact_rel
*)
8744 /* Clean up a dummy stub function entry in .text. */
8745 s
= bfd_get_section_by_name (dynobj
,
8746 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
8749 file_ptr dummy_offset
;
8751 BFD_ASSERT (s
->size
>= MIPS_FUNCTION_STUB_SIZE
);
8752 dummy_offset
= s
->size
- MIPS_FUNCTION_STUB_SIZE
;
8753 memset (s
->contents
+ dummy_offset
, 0,
8754 MIPS_FUNCTION_STUB_SIZE
);
8759 /* The psABI says that the dynamic relocations must be sorted in
8760 increasing order of r_symndx. The VxWorks EABI doesn't require
8761 this, and because the code below handles REL rather than RELA
8762 relocations, using it for VxWorks would be outright harmful. */
8763 if (!htab
->is_vxworks
)
8765 s
= mips_elf_rel_dyn_section (info
, FALSE
);
8767 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
8769 reldyn_sorting_bfd
= output_bfd
;
8771 if (ABI_64_P (output_bfd
))
8772 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
8773 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
8774 sort_dynamic_relocs_64
);
8776 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
8777 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
8778 sort_dynamic_relocs
);
8783 if (htab
->is_vxworks
&& htab
->splt
->size
> 0)
8786 mips_vxworks_finish_shared_plt (output_bfd
, info
);
8788 mips_vxworks_finish_exec_plt (output_bfd
, info
);
8794 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
8797 mips_set_isa_flags (bfd
*abfd
)
8801 switch (bfd_get_mach (abfd
))
8804 case bfd_mach_mips3000
:
8805 val
= E_MIPS_ARCH_1
;
8808 case bfd_mach_mips3900
:
8809 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
8812 case bfd_mach_mips6000
:
8813 val
= E_MIPS_ARCH_2
;
8816 case bfd_mach_mips4000
:
8817 case bfd_mach_mips4300
:
8818 case bfd_mach_mips4400
:
8819 case bfd_mach_mips4600
:
8820 val
= E_MIPS_ARCH_3
;
8823 case bfd_mach_mips4010
:
8824 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
8827 case bfd_mach_mips4100
:
8828 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
8831 case bfd_mach_mips4111
:
8832 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
8835 case bfd_mach_mips4120
:
8836 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
8839 case bfd_mach_mips4650
:
8840 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
8843 case bfd_mach_mips5400
:
8844 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
8847 case bfd_mach_mips5500
:
8848 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
8851 case bfd_mach_mips9000
:
8852 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
8855 case bfd_mach_mips5000
:
8856 case bfd_mach_mips7000
:
8857 case bfd_mach_mips8000
:
8858 case bfd_mach_mips10000
:
8859 case bfd_mach_mips12000
:
8860 val
= E_MIPS_ARCH_4
;
8863 case bfd_mach_mips5
:
8864 val
= E_MIPS_ARCH_5
;
8867 case bfd_mach_mips_sb1
:
8868 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
8871 case bfd_mach_mipsisa32
:
8872 val
= E_MIPS_ARCH_32
;
8875 case bfd_mach_mipsisa64
:
8876 val
= E_MIPS_ARCH_64
;
8879 case bfd_mach_mipsisa32r2
:
8880 val
= E_MIPS_ARCH_32R2
;
8883 case bfd_mach_mipsisa64r2
:
8884 val
= E_MIPS_ARCH_64R2
;
8887 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
8888 elf_elfheader (abfd
)->e_flags
|= val
;
8893 /* The final processing done just before writing out a MIPS ELF object
8894 file. This gets the MIPS architecture right based on the machine
8895 number. This is used by both the 32-bit and the 64-bit ABI. */
8898 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
8899 bfd_boolean linker ATTRIBUTE_UNUSED
)
8902 Elf_Internal_Shdr
**hdrpp
;
8906 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
8907 is nonzero. This is for compatibility with old objects, which used
8908 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
8909 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
8910 mips_set_isa_flags (abfd
);
8912 /* Set the sh_info field for .gptab sections and other appropriate
8913 info for each special section. */
8914 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
8915 i
< elf_numsections (abfd
);
8918 switch ((*hdrpp
)->sh_type
)
8921 case SHT_MIPS_LIBLIST
:
8922 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
8924 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
8927 case SHT_MIPS_GPTAB
:
8928 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
8929 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
8930 BFD_ASSERT (name
!= NULL
8931 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
8932 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
8933 BFD_ASSERT (sec
!= NULL
);
8934 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
8937 case SHT_MIPS_CONTENT
:
8938 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
8939 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
8940 BFD_ASSERT (name
!= NULL
8941 && strncmp (name
, ".MIPS.content",
8942 sizeof ".MIPS.content" - 1) == 0);
8943 sec
= bfd_get_section_by_name (abfd
,
8944 name
+ sizeof ".MIPS.content" - 1);
8945 BFD_ASSERT (sec
!= NULL
);
8946 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
8949 case SHT_MIPS_SYMBOL_LIB
:
8950 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
8952 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
8953 sec
= bfd_get_section_by_name (abfd
, ".liblist");
8955 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
8958 case SHT_MIPS_EVENTS
:
8959 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
8960 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
8961 BFD_ASSERT (name
!= NULL
);
8962 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
8963 sec
= bfd_get_section_by_name (abfd
,
8964 name
+ sizeof ".MIPS.events" - 1);
8967 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
8968 sizeof ".MIPS.post_rel" - 1) == 0);
8969 sec
= bfd_get_section_by_name (abfd
,
8971 + sizeof ".MIPS.post_rel" - 1));
8973 BFD_ASSERT (sec
!= NULL
);
8974 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
8981 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
8985 _bfd_mips_elf_additional_program_headers (bfd
*abfd
)
8990 /* See if we need a PT_MIPS_REGINFO segment. */
8991 s
= bfd_get_section_by_name (abfd
, ".reginfo");
8992 if (s
&& (s
->flags
& SEC_LOAD
))
8995 /* See if we need a PT_MIPS_OPTIONS segment. */
8996 if (IRIX_COMPAT (abfd
) == ict_irix6
8997 && bfd_get_section_by_name (abfd
,
8998 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
9001 /* See if we need a PT_MIPS_RTPROC segment. */
9002 if (IRIX_COMPAT (abfd
) == ict_irix5
9003 && bfd_get_section_by_name (abfd
, ".dynamic")
9004 && bfd_get_section_by_name (abfd
, ".mdebug"))
9010 /* Modify the segment map for an IRIX5 executable. */
9013 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
9014 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
9017 struct elf_segment_map
*m
, **pm
;
9020 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
9022 s
= bfd_get_section_by_name (abfd
, ".reginfo");
9023 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
9025 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
9026 if (m
->p_type
== PT_MIPS_REGINFO
)
9031 m
= bfd_zalloc (abfd
, amt
);
9035 m
->p_type
= PT_MIPS_REGINFO
;
9039 /* We want to put it after the PHDR and INTERP segments. */
9040 pm
= &elf_tdata (abfd
)->segment_map
;
9042 && ((*pm
)->p_type
== PT_PHDR
9043 || (*pm
)->p_type
== PT_INTERP
))
9051 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
9052 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
9053 PT_MIPS_OPTIONS segment immediately following the program header
9056 /* On non-IRIX6 new abi, we'll have already created a segment
9057 for this section, so don't create another. I'm not sure this
9058 is not also the case for IRIX 6, but I can't test it right
9060 && IRIX_COMPAT (abfd
) == ict_irix6
)
9062 for (s
= abfd
->sections
; s
; s
= s
->next
)
9063 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
9068 struct elf_segment_map
*options_segment
;
9070 pm
= &elf_tdata (abfd
)->segment_map
;
9072 && ((*pm
)->p_type
== PT_PHDR
9073 || (*pm
)->p_type
== PT_INTERP
))
9076 amt
= sizeof (struct elf_segment_map
);
9077 options_segment
= bfd_zalloc (abfd
, amt
);
9078 options_segment
->next
= *pm
;
9079 options_segment
->p_type
= PT_MIPS_OPTIONS
;
9080 options_segment
->p_flags
= PF_R
;
9081 options_segment
->p_flags_valid
= TRUE
;
9082 options_segment
->count
= 1;
9083 options_segment
->sections
[0] = s
;
9084 *pm
= options_segment
;
9089 if (IRIX_COMPAT (abfd
) == ict_irix5
)
9091 /* If there are .dynamic and .mdebug sections, we make a room
9092 for the RTPROC header. FIXME: Rewrite without section names. */
9093 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
9094 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
9095 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
9097 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
9098 if (m
->p_type
== PT_MIPS_RTPROC
)
9103 m
= bfd_zalloc (abfd
, amt
);
9107 m
->p_type
= PT_MIPS_RTPROC
;
9109 s
= bfd_get_section_by_name (abfd
, ".rtproc");
9114 m
->p_flags_valid
= 1;
9122 /* We want to put it after the DYNAMIC segment. */
9123 pm
= &elf_tdata (abfd
)->segment_map
;
9124 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
9134 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
9135 .dynstr, .dynsym, and .hash sections, and everything in
9137 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
9139 if ((*pm
)->p_type
== PT_DYNAMIC
)
9142 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
9144 /* For a normal mips executable the permissions for the PT_DYNAMIC
9145 segment are read, write and execute. We do that here since
9146 the code in elf.c sets only the read permission. This matters
9147 sometimes for the dynamic linker. */
9148 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
9150 m
->p_flags
= PF_R
| PF_W
| PF_X
;
9151 m
->p_flags_valid
= 1;
9155 && m
->count
== 1 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
9157 static const char *sec_names
[] =
9159 ".dynamic", ".dynstr", ".dynsym", ".hash"
9163 struct elf_segment_map
*n
;
9167 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
9169 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
9170 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
9177 if (high
< s
->vma
+ sz
)
9183 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
9184 if ((s
->flags
& SEC_LOAD
) != 0
9186 && s
->vma
+ s
->size
<= high
)
9189 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
9190 n
= bfd_zalloc (abfd
, amt
);
9197 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
9199 if ((s
->flags
& SEC_LOAD
) != 0
9201 && s
->vma
+ s
->size
<= high
)
9215 /* Return the section that should be marked against GC for a given
9219 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
9220 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
9221 Elf_Internal_Rela
*rel
,
9222 struct elf_link_hash_entry
*h
,
9223 Elf_Internal_Sym
*sym
)
9225 /* ??? Do mips16 stub sections need to be handled special? */
9229 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
9231 case R_MIPS_GNU_VTINHERIT
:
9232 case R_MIPS_GNU_VTENTRY
:
9236 switch (h
->root
.type
)
9238 case bfd_link_hash_defined
:
9239 case bfd_link_hash_defweak
:
9240 return h
->root
.u
.def
.section
;
9242 case bfd_link_hash_common
:
9243 return h
->root
.u
.c
.p
->section
;
9251 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
9256 /* Update the got entry reference counts for the section being removed. */
9259 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
9260 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
9261 asection
*sec ATTRIBUTE_UNUSED
,
9262 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
9265 Elf_Internal_Shdr
*symtab_hdr
;
9266 struct elf_link_hash_entry
**sym_hashes
;
9267 bfd_signed_vma
*local_got_refcounts
;
9268 const Elf_Internal_Rela
*rel
, *relend
;
9269 unsigned long r_symndx
;
9270 struct elf_link_hash_entry
*h
;
9272 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
9273 sym_hashes
= elf_sym_hashes (abfd
);
9274 local_got_refcounts
= elf_local_got_refcounts (abfd
);
9276 relend
= relocs
+ sec
->reloc_count
;
9277 for (rel
= relocs
; rel
< relend
; rel
++)
9278 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
9282 case R_MIPS_CALL_HI16
:
9283 case R_MIPS_CALL_LO16
:
9284 case R_MIPS_GOT_HI16
:
9285 case R_MIPS_GOT_LO16
:
9286 case R_MIPS_GOT_DISP
:
9287 case R_MIPS_GOT_PAGE
:
9288 case R_MIPS_GOT_OFST
:
9289 /* ??? It would seem that the existing MIPS code does no sort
9290 of reference counting or whatnot on its GOT and PLT entries,
9291 so it is not possible to garbage collect them at this time. */
9302 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
9303 hiding the old indirect symbol. Process additional relocation
9304 information. Also called for weakdefs, in which case we just let
9305 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
9308 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
9309 struct elf_link_hash_entry
*dir
,
9310 struct elf_link_hash_entry
*ind
)
9312 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
9314 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
9316 if (ind
->root
.type
!= bfd_link_hash_indirect
)
9319 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
9320 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
9321 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
9322 if (indmips
->readonly_reloc
)
9323 dirmips
->readonly_reloc
= TRUE
;
9324 if (indmips
->no_fn_stub
)
9325 dirmips
->no_fn_stub
= TRUE
;
9327 if (dirmips
->tls_type
== 0)
9328 dirmips
->tls_type
= indmips
->tls_type
;
9332 _bfd_mips_elf_hide_symbol (struct bfd_link_info
*info
,
9333 struct elf_link_hash_entry
*entry
,
9334 bfd_boolean force_local
)
9338 struct mips_got_info
*g
;
9339 struct mips_elf_link_hash_entry
*h
;
9341 h
= (struct mips_elf_link_hash_entry
*) entry
;
9342 if (h
->forced_local
)
9344 h
->forced_local
= force_local
;
9346 dynobj
= elf_hash_table (info
)->dynobj
;
9347 if (dynobj
!= NULL
&& force_local
&& h
->root
.type
!= STT_TLS
9348 && (got
= mips_elf_got_section (dynobj
, FALSE
)) != NULL
9349 && (g
= mips_elf_section_data (got
)->u
.got_info
) != NULL
)
9353 struct mips_got_entry e
;
9354 struct mips_got_info
*gg
= g
;
9356 /* Since we're turning what used to be a global symbol into a
9357 local one, bump up the number of local entries of each GOT
9358 that had an entry for it. This will automatically decrease
9359 the number of global entries, since global_gotno is actually
9360 the upper limit of global entries. */
9366 for (g
= g
->next
; g
!= gg
; g
= g
->next
)
9367 if (htab_find (g
->got_entries
, &e
))
9369 BFD_ASSERT (g
->global_gotno
> 0);
9374 /* If this was a global symbol forced into the primary GOT, we
9375 no longer need an entry for it. We can't release the entry
9376 at this point, but we must at least stop counting it as one
9377 of the symbols that required a forced got entry. */
9378 if (h
->root
.got
.offset
== 2)
9380 BFD_ASSERT (gg
->assigned_gotno
> 0);
9381 gg
->assigned_gotno
--;
9384 else if (g
->global_gotno
== 0 && g
->global_gotsym
== NULL
)
9385 /* If we haven't got through GOT allocation yet, just bump up the
9386 number of local entries, as this symbol won't be counted as
9389 else if (h
->root
.got
.offset
== 1)
9391 /* If we're past non-multi-GOT allocation and this symbol had
9392 been marked for a global got entry, give it a local entry
9394 BFD_ASSERT (g
->global_gotno
> 0);
9400 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
9406 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
9407 struct bfd_link_info
*info
)
9410 bfd_boolean ret
= FALSE
;
9411 unsigned char *tdata
;
9414 o
= bfd_get_section_by_name (abfd
, ".pdr");
9419 if (o
->size
% PDR_SIZE
!= 0)
9421 if (o
->output_section
!= NULL
9422 && bfd_is_abs_section (o
->output_section
))
9425 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
9429 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
9437 cookie
->rel
= cookie
->rels
;
9438 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
9440 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
9442 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
9451 mips_elf_section_data (o
)->u
.tdata
= tdata
;
9452 o
->size
-= skip
* PDR_SIZE
;
9458 if (! info
->keep_memory
)
9459 free (cookie
->rels
);
9465 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
9467 if (strcmp (sec
->name
, ".pdr") == 0)
9473 _bfd_mips_elf_write_section (bfd
*output_bfd
, asection
*sec
,
9476 bfd_byte
*to
, *from
, *end
;
9479 if (strcmp (sec
->name
, ".pdr") != 0)
9482 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
9486 end
= contents
+ sec
->size
;
9487 for (from
= contents
, i
= 0;
9489 from
+= PDR_SIZE
, i
++)
9491 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
9494 memcpy (to
, from
, PDR_SIZE
);
9497 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
9498 sec
->output_offset
, sec
->size
);
9502 /* MIPS ELF uses a special find_nearest_line routine in order the
9503 handle the ECOFF debugging information. */
9505 struct mips_elf_find_line
9507 struct ecoff_debug_info d
;
9508 struct ecoff_find_line i
;
9512 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
9513 asymbol
**symbols
, bfd_vma offset
,
9514 const char **filename_ptr
,
9515 const char **functionname_ptr
,
9516 unsigned int *line_ptr
)
9520 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
9521 filename_ptr
, functionname_ptr
,
9525 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
9526 filename_ptr
, functionname_ptr
,
9527 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
9528 &elf_tdata (abfd
)->dwarf2_find_line_info
))
9531 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
9535 struct mips_elf_find_line
*fi
;
9536 const struct ecoff_debug_swap
* const swap
=
9537 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
9539 /* If we are called during a link, mips_elf_final_link may have
9540 cleared the SEC_HAS_CONTENTS field. We force it back on here
9541 if appropriate (which it normally will be). */
9542 origflags
= msec
->flags
;
9543 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
9544 msec
->flags
|= SEC_HAS_CONTENTS
;
9546 fi
= elf_tdata (abfd
)->find_line_info
;
9549 bfd_size_type external_fdr_size
;
9552 struct fdr
*fdr_ptr
;
9553 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
9555 fi
= bfd_zalloc (abfd
, amt
);
9558 msec
->flags
= origflags
;
9562 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
9564 msec
->flags
= origflags
;
9568 /* Swap in the FDR information. */
9569 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
9570 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
9571 if (fi
->d
.fdr
== NULL
)
9573 msec
->flags
= origflags
;
9576 external_fdr_size
= swap
->external_fdr_size
;
9577 fdr_ptr
= fi
->d
.fdr
;
9578 fraw_src
= (char *) fi
->d
.external_fdr
;
9579 fraw_end
= (fraw_src
9580 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
9581 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
9582 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
9584 elf_tdata (abfd
)->find_line_info
= fi
;
9586 /* Note that we don't bother to ever free this information.
9587 find_nearest_line is either called all the time, as in
9588 objdump -l, so the information should be saved, or it is
9589 rarely called, as in ld error messages, so the memory
9590 wasted is unimportant. Still, it would probably be a
9591 good idea for free_cached_info to throw it away. */
9594 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
9595 &fi
->i
, filename_ptr
, functionname_ptr
,
9598 msec
->flags
= origflags
;
9602 msec
->flags
= origflags
;
9605 /* Fall back on the generic ELF find_nearest_line routine. */
9607 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
9608 filename_ptr
, functionname_ptr
,
9613 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
9614 const char **filename_ptr
,
9615 const char **functionname_ptr
,
9616 unsigned int *line_ptr
)
9619 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
9620 functionname_ptr
, line_ptr
,
9621 & elf_tdata (abfd
)->dwarf2_find_line_info
);
9626 /* When are writing out the .options or .MIPS.options section,
9627 remember the bytes we are writing out, so that we can install the
9628 GP value in the section_processing routine. */
9631 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
9632 const void *location
,
9633 file_ptr offset
, bfd_size_type count
)
9635 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
9639 if (elf_section_data (section
) == NULL
)
9641 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
9642 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
9643 if (elf_section_data (section
) == NULL
)
9646 c
= mips_elf_section_data (section
)->u
.tdata
;
9649 c
= bfd_zalloc (abfd
, section
->size
);
9652 mips_elf_section_data (section
)->u
.tdata
= c
;
9655 memcpy (c
+ offset
, location
, count
);
9658 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
9662 /* This is almost identical to bfd_generic_get_... except that some
9663 MIPS relocations need to be handled specially. Sigh. */
9666 _bfd_elf_mips_get_relocated_section_contents
9668 struct bfd_link_info
*link_info
,
9669 struct bfd_link_order
*link_order
,
9671 bfd_boolean relocatable
,
9674 /* Get enough memory to hold the stuff */
9675 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
9676 asection
*input_section
= link_order
->u
.indirect
.section
;
9679 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
9680 arelent
**reloc_vector
= NULL
;
9686 reloc_vector
= bfd_malloc (reloc_size
);
9687 if (reloc_vector
== NULL
&& reloc_size
!= 0)
9690 /* read in the section */
9691 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
9692 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
9695 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
9699 if (reloc_count
< 0)
9702 if (reloc_count
> 0)
9707 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
9710 struct bfd_hash_entry
*h
;
9711 struct bfd_link_hash_entry
*lh
;
9712 /* Skip all this stuff if we aren't mixing formats. */
9713 if (abfd
&& input_bfd
9714 && abfd
->xvec
== input_bfd
->xvec
)
9718 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
9719 lh
= (struct bfd_link_hash_entry
*) h
;
9726 case bfd_link_hash_undefined
:
9727 case bfd_link_hash_undefweak
:
9728 case bfd_link_hash_common
:
9731 case bfd_link_hash_defined
:
9732 case bfd_link_hash_defweak
:
9734 gp
= lh
->u
.def
.value
;
9736 case bfd_link_hash_indirect
:
9737 case bfd_link_hash_warning
:
9739 /* @@FIXME ignoring warning for now */
9741 case bfd_link_hash_new
:
9750 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
9752 char *error_message
= NULL
;
9753 bfd_reloc_status_type r
;
9755 /* Specific to MIPS: Deal with relocation types that require
9756 knowing the gp of the output bfd. */
9757 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
9759 /* If we've managed to find the gp and have a special
9760 function for the relocation then go ahead, else default
9761 to the generic handling. */
9763 && (*parent
)->howto
->special_function
9764 == _bfd_mips_elf32_gprel16_reloc
)
9765 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
9766 input_section
, relocatable
,
9769 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
9771 relocatable
? abfd
: NULL
,
9776 asection
*os
= input_section
->output_section
;
9778 /* A partial link, so keep the relocs */
9779 os
->orelocation
[os
->reloc_count
] = *parent
;
9783 if (r
!= bfd_reloc_ok
)
9787 case bfd_reloc_undefined
:
9788 if (!((*link_info
->callbacks
->undefined_symbol
)
9789 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
9790 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
9793 case bfd_reloc_dangerous
:
9794 BFD_ASSERT (error_message
!= NULL
);
9795 if (!((*link_info
->callbacks
->reloc_dangerous
)
9796 (link_info
, error_message
, input_bfd
, input_section
,
9797 (*parent
)->address
)))
9800 case bfd_reloc_overflow
:
9801 if (!((*link_info
->callbacks
->reloc_overflow
)
9803 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
9804 (*parent
)->howto
->name
, (*parent
)->addend
,
9805 input_bfd
, input_section
, (*parent
)->address
)))
9808 case bfd_reloc_outofrange
:
9817 if (reloc_vector
!= NULL
)
9818 free (reloc_vector
);
9822 if (reloc_vector
!= NULL
)
9823 free (reloc_vector
);
9827 /* Create a MIPS ELF linker hash table. */
9829 struct bfd_link_hash_table
*
9830 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
9832 struct mips_elf_link_hash_table
*ret
;
9833 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
9835 ret
= bfd_malloc (amt
);
9839 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
9840 mips_elf_link_hash_newfunc
,
9841 sizeof (struct mips_elf_link_hash_entry
)))
9848 /* We no longer use this. */
9849 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
9850 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
9852 ret
->procedure_count
= 0;
9853 ret
->compact_rel_size
= 0;
9854 ret
->use_rld_obj_head
= FALSE
;
9856 ret
->mips16_stubs_seen
= FALSE
;
9857 ret
->is_vxworks
= FALSE
;
9858 ret
->srelbss
= NULL
;
9859 ret
->sdynbss
= NULL
;
9860 ret
->srelplt
= NULL
;
9861 ret
->srelplt2
= NULL
;
9862 ret
->sgotplt
= NULL
;
9864 ret
->plt_header_size
= 0;
9865 ret
->plt_entry_size
= 0;
9867 return &ret
->root
.root
;
9870 /* Likewise, but indicate that the target is VxWorks. */
9872 struct bfd_link_hash_table
*
9873 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
9875 struct bfd_link_hash_table
*ret
;
9877 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
9880 struct mips_elf_link_hash_table
*htab
;
9882 htab
= (struct mips_elf_link_hash_table
*) ret
;
9883 htab
->is_vxworks
= 1;
9888 /* We need to use a special link routine to handle the .reginfo and
9889 the .mdebug sections. We need to merge all instances of these
9890 sections together, not write them all out sequentially. */
9893 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
9896 struct bfd_link_order
*p
;
9897 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
9898 asection
*rtproc_sec
;
9899 Elf32_RegInfo reginfo
;
9900 struct ecoff_debug_info debug
;
9901 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
9902 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
9903 HDRR
*symhdr
= &debug
.symbolic_header
;
9904 void *mdebug_handle
= NULL
;
9909 struct mips_elf_link_hash_table
*htab
;
9911 static const char * const secname
[] =
9913 ".text", ".init", ".fini", ".data",
9914 ".rodata", ".sdata", ".sbss", ".bss"
9916 static const int sc
[] =
9918 scText
, scInit
, scFini
, scData
,
9919 scRData
, scSData
, scSBss
, scBss
9922 /* We'd carefully arranged the dynamic symbol indices, and then the
9923 generic size_dynamic_sections renumbered them out from under us.
9924 Rather than trying somehow to prevent the renumbering, just do
9926 htab
= mips_elf_hash_table (info
);
9927 if (elf_hash_table (info
)->dynamic_sections_created
)
9931 struct mips_got_info
*g
;
9932 bfd_size_type dynsecsymcount
;
9934 /* When we resort, we must tell mips_elf_sort_hash_table what
9935 the lowest index it may use is. That's the number of section
9936 symbols we're going to add. The generic ELF linker only
9937 adds these symbols when building a shared object. Note that
9938 we count the sections after (possibly) removing the .options
9946 for (p
= abfd
->sections
; p
; p
= p
->next
)
9947 if ((p
->flags
& SEC_EXCLUDE
) == 0
9948 && (p
->flags
& SEC_ALLOC
) != 0
9949 && !(*bed
->elf_backend_omit_section_dynsym
) (abfd
, info
, p
))
9953 if (! mips_elf_sort_hash_table (info
, dynsecsymcount
+ 1))
9956 /* Make sure we didn't grow the global .got region. */
9957 dynobj
= elf_hash_table (info
)->dynobj
;
9958 got
= mips_elf_got_section (dynobj
, FALSE
);
9959 g
= mips_elf_section_data (got
)->u
.got_info
;
9961 if (g
->global_gotsym
!= NULL
)
9962 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
9963 - g
->global_gotsym
->dynindx
)
9964 <= g
->global_gotno
);
9967 /* Get a value for the GP register. */
9968 if (elf_gp (abfd
) == 0)
9970 struct bfd_link_hash_entry
*h
;
9972 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
9973 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
9974 elf_gp (abfd
) = (h
->u
.def
.value
9975 + h
->u
.def
.section
->output_section
->vma
9976 + h
->u
.def
.section
->output_offset
);
9977 else if (htab
->is_vxworks
9978 && (h
= bfd_link_hash_lookup (info
->hash
,
9979 "_GLOBAL_OFFSET_TABLE_",
9980 FALSE
, FALSE
, TRUE
))
9981 && h
->type
== bfd_link_hash_defined
)
9982 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
9983 + h
->u
.def
.section
->output_offset
9985 else if (info
->relocatable
)
9987 bfd_vma lo
= MINUS_ONE
;
9989 /* Find the GP-relative section with the lowest offset. */
9990 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
9992 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
9995 /* And calculate GP relative to that. */
9996 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
10000 /* If the relocate_section function needs to do a reloc
10001 involving the GP value, it should make a reloc_dangerous
10002 callback to warn that GP is not defined. */
10006 /* Go through the sections and collect the .reginfo and .mdebug
10008 reginfo_sec
= NULL
;
10010 gptab_data_sec
= NULL
;
10011 gptab_bss_sec
= NULL
;
10012 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10014 if (strcmp (o
->name
, ".reginfo") == 0)
10016 memset (®info
, 0, sizeof reginfo
);
10018 /* We have found the .reginfo section in the output file.
10019 Look through all the link_orders comprising it and merge
10020 the information together. */
10021 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10023 asection
*input_section
;
10025 Elf32_External_RegInfo ext
;
10028 if (p
->type
!= bfd_indirect_link_order
)
10030 if (p
->type
== bfd_data_link_order
)
10035 input_section
= p
->u
.indirect
.section
;
10036 input_bfd
= input_section
->owner
;
10038 if (! bfd_get_section_contents (input_bfd
, input_section
,
10039 &ext
, 0, sizeof ext
))
10042 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
10044 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
10045 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
10046 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
10047 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
10048 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
10050 /* ri_gp_value is set by the function
10051 mips_elf32_section_processing when the section is
10052 finally written out. */
10054 /* Hack: reset the SEC_HAS_CONTENTS flag so that
10055 elf_link_input_bfd ignores this section. */
10056 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
10059 /* Size has been set in _bfd_mips_elf_always_size_sections. */
10060 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
10062 /* Skip this section later on (I don't think this currently
10063 matters, but someday it might). */
10064 o
->map_head
.link_order
= NULL
;
10069 if (strcmp (o
->name
, ".mdebug") == 0)
10071 struct extsym_info einfo
;
10074 /* We have found the .mdebug section in the output file.
10075 Look through all the link_orders comprising it and merge
10076 the information together. */
10077 symhdr
->magic
= swap
->sym_magic
;
10078 /* FIXME: What should the version stamp be? */
10079 symhdr
->vstamp
= 0;
10080 symhdr
->ilineMax
= 0;
10081 symhdr
->cbLine
= 0;
10082 symhdr
->idnMax
= 0;
10083 symhdr
->ipdMax
= 0;
10084 symhdr
->isymMax
= 0;
10085 symhdr
->ioptMax
= 0;
10086 symhdr
->iauxMax
= 0;
10087 symhdr
->issMax
= 0;
10088 symhdr
->issExtMax
= 0;
10089 symhdr
->ifdMax
= 0;
10091 symhdr
->iextMax
= 0;
10093 /* We accumulate the debugging information itself in the
10094 debug_info structure. */
10096 debug
.external_dnr
= NULL
;
10097 debug
.external_pdr
= NULL
;
10098 debug
.external_sym
= NULL
;
10099 debug
.external_opt
= NULL
;
10100 debug
.external_aux
= NULL
;
10102 debug
.ssext
= debug
.ssext_end
= NULL
;
10103 debug
.external_fdr
= NULL
;
10104 debug
.external_rfd
= NULL
;
10105 debug
.external_ext
= debug
.external_ext_end
= NULL
;
10107 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
10108 if (mdebug_handle
== NULL
)
10112 esym
.cobol_main
= 0;
10116 esym
.asym
.iss
= issNil
;
10117 esym
.asym
.st
= stLocal
;
10118 esym
.asym
.reserved
= 0;
10119 esym
.asym
.index
= indexNil
;
10121 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
10123 esym
.asym
.sc
= sc
[i
];
10124 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
10127 esym
.asym
.value
= s
->vma
;
10128 last
= s
->vma
+ s
->size
;
10131 esym
.asym
.value
= last
;
10132 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
10133 secname
[i
], &esym
))
10137 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10139 asection
*input_section
;
10141 const struct ecoff_debug_swap
*input_swap
;
10142 struct ecoff_debug_info input_debug
;
10146 if (p
->type
!= bfd_indirect_link_order
)
10148 if (p
->type
== bfd_data_link_order
)
10153 input_section
= p
->u
.indirect
.section
;
10154 input_bfd
= input_section
->owner
;
10156 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
10157 || (get_elf_backend_data (input_bfd
)
10158 ->elf_backend_ecoff_debug_swap
) == NULL
)
10160 /* I don't know what a non MIPS ELF bfd would be
10161 doing with a .mdebug section, but I don't really
10162 want to deal with it. */
10166 input_swap
= (get_elf_backend_data (input_bfd
)
10167 ->elf_backend_ecoff_debug_swap
);
10169 BFD_ASSERT (p
->size
== input_section
->size
);
10171 /* The ECOFF linking code expects that we have already
10172 read in the debugging information and set up an
10173 ecoff_debug_info structure, so we do that now. */
10174 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
10178 if (! (bfd_ecoff_debug_accumulate
10179 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
10180 &input_debug
, input_swap
, info
)))
10183 /* Loop through the external symbols. For each one with
10184 interesting information, try to find the symbol in
10185 the linker global hash table and save the information
10186 for the output external symbols. */
10187 eraw_src
= input_debug
.external_ext
;
10188 eraw_end
= (eraw_src
10189 + (input_debug
.symbolic_header
.iextMax
10190 * input_swap
->external_ext_size
));
10192 eraw_src
< eraw_end
;
10193 eraw_src
+= input_swap
->external_ext_size
)
10197 struct mips_elf_link_hash_entry
*h
;
10199 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
10200 if (ext
.asym
.sc
== scNil
10201 || ext
.asym
.sc
== scUndefined
10202 || ext
.asym
.sc
== scSUndefined
)
10205 name
= input_debug
.ssext
+ ext
.asym
.iss
;
10206 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
10207 name
, FALSE
, FALSE
, TRUE
);
10208 if (h
== NULL
|| h
->esym
.ifd
!= -2)
10213 BFD_ASSERT (ext
.ifd
10214 < input_debug
.symbolic_header
.ifdMax
);
10215 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
10221 /* Free up the information we just read. */
10222 free (input_debug
.line
);
10223 free (input_debug
.external_dnr
);
10224 free (input_debug
.external_pdr
);
10225 free (input_debug
.external_sym
);
10226 free (input_debug
.external_opt
);
10227 free (input_debug
.external_aux
);
10228 free (input_debug
.ss
);
10229 free (input_debug
.ssext
);
10230 free (input_debug
.external_fdr
);
10231 free (input_debug
.external_rfd
);
10232 free (input_debug
.external_ext
);
10234 /* Hack: reset the SEC_HAS_CONTENTS flag so that
10235 elf_link_input_bfd ignores this section. */
10236 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
10239 if (SGI_COMPAT (abfd
) && info
->shared
)
10241 /* Create .rtproc section. */
10242 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
10243 if (rtproc_sec
== NULL
)
10245 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
10246 | SEC_LINKER_CREATED
| SEC_READONLY
);
10248 rtproc_sec
= bfd_make_section_with_flags (abfd
,
10251 if (rtproc_sec
== NULL
10252 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
10256 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
10262 /* Build the external symbol information. */
10265 einfo
.debug
= &debug
;
10267 einfo
.failed
= FALSE
;
10268 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
10269 mips_elf_output_extsym
, &einfo
);
10273 /* Set the size of the .mdebug section. */
10274 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
10276 /* Skip this section later on (I don't think this currently
10277 matters, but someday it might). */
10278 o
->map_head
.link_order
= NULL
;
10283 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
10285 const char *subname
;
10288 Elf32_External_gptab
*ext_tab
;
10291 /* The .gptab.sdata and .gptab.sbss sections hold
10292 information describing how the small data area would
10293 change depending upon the -G switch. These sections
10294 not used in executables files. */
10295 if (! info
->relocatable
)
10297 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10299 asection
*input_section
;
10301 if (p
->type
!= bfd_indirect_link_order
)
10303 if (p
->type
== bfd_data_link_order
)
10308 input_section
= p
->u
.indirect
.section
;
10310 /* Hack: reset the SEC_HAS_CONTENTS flag so that
10311 elf_link_input_bfd ignores this section. */
10312 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
10315 /* Skip this section later on (I don't think this
10316 currently matters, but someday it might). */
10317 o
->map_head
.link_order
= NULL
;
10319 /* Really remove the section. */
10320 bfd_section_list_remove (abfd
, o
);
10321 --abfd
->section_count
;
10326 /* There is one gptab for initialized data, and one for
10327 uninitialized data. */
10328 if (strcmp (o
->name
, ".gptab.sdata") == 0)
10329 gptab_data_sec
= o
;
10330 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
10334 (*_bfd_error_handler
)
10335 (_("%s: illegal section name `%s'"),
10336 bfd_get_filename (abfd
), o
->name
);
10337 bfd_set_error (bfd_error_nonrepresentable_section
);
10341 /* The linker script always combines .gptab.data and
10342 .gptab.sdata into .gptab.sdata, and likewise for
10343 .gptab.bss and .gptab.sbss. It is possible that there is
10344 no .sdata or .sbss section in the output file, in which
10345 case we must change the name of the output section. */
10346 subname
= o
->name
+ sizeof ".gptab" - 1;
10347 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
10349 if (o
== gptab_data_sec
)
10350 o
->name
= ".gptab.data";
10352 o
->name
= ".gptab.bss";
10353 subname
= o
->name
+ sizeof ".gptab" - 1;
10354 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
10357 /* Set up the first entry. */
10359 amt
= c
* sizeof (Elf32_gptab
);
10360 tab
= bfd_malloc (amt
);
10363 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
10364 tab
[0].gt_header
.gt_unused
= 0;
10366 /* Combine the input sections. */
10367 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10369 asection
*input_section
;
10371 bfd_size_type size
;
10372 unsigned long last
;
10373 bfd_size_type gpentry
;
10375 if (p
->type
!= bfd_indirect_link_order
)
10377 if (p
->type
== bfd_data_link_order
)
10382 input_section
= p
->u
.indirect
.section
;
10383 input_bfd
= input_section
->owner
;
10385 /* Combine the gptab entries for this input section one
10386 by one. We know that the input gptab entries are
10387 sorted by ascending -G value. */
10388 size
= input_section
->size
;
10390 for (gpentry
= sizeof (Elf32_External_gptab
);
10392 gpentry
+= sizeof (Elf32_External_gptab
))
10394 Elf32_External_gptab ext_gptab
;
10395 Elf32_gptab int_gptab
;
10401 if (! (bfd_get_section_contents
10402 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
10403 sizeof (Elf32_External_gptab
))))
10409 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
10411 val
= int_gptab
.gt_entry
.gt_g_value
;
10412 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
10415 for (look
= 1; look
< c
; look
++)
10417 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
10418 tab
[look
].gt_entry
.gt_bytes
+= add
;
10420 if (tab
[look
].gt_entry
.gt_g_value
== val
)
10426 Elf32_gptab
*new_tab
;
10429 /* We need a new table entry. */
10430 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
10431 new_tab
= bfd_realloc (tab
, amt
);
10432 if (new_tab
== NULL
)
10438 tab
[c
].gt_entry
.gt_g_value
= val
;
10439 tab
[c
].gt_entry
.gt_bytes
= add
;
10441 /* Merge in the size for the next smallest -G
10442 value, since that will be implied by this new
10445 for (look
= 1; look
< c
; look
++)
10447 if (tab
[look
].gt_entry
.gt_g_value
< val
10449 || (tab
[look
].gt_entry
.gt_g_value
10450 > tab
[max
].gt_entry
.gt_g_value
)))
10454 tab
[c
].gt_entry
.gt_bytes
+=
10455 tab
[max
].gt_entry
.gt_bytes
;
10460 last
= int_gptab
.gt_entry
.gt_bytes
;
10463 /* Hack: reset the SEC_HAS_CONTENTS flag so that
10464 elf_link_input_bfd ignores this section. */
10465 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
10468 /* The table must be sorted by -G value. */
10470 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
10472 /* Swap out the table. */
10473 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
10474 ext_tab
= bfd_alloc (abfd
, amt
);
10475 if (ext_tab
== NULL
)
10481 for (j
= 0; j
< c
; j
++)
10482 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
10485 o
->size
= c
* sizeof (Elf32_External_gptab
);
10486 o
->contents
= (bfd_byte
*) ext_tab
;
10488 /* Skip this section later on (I don't think this currently
10489 matters, but someday it might). */
10490 o
->map_head
.link_order
= NULL
;
10494 /* Invoke the regular ELF backend linker to do all the work. */
10495 if (!bfd_elf_final_link (abfd
, info
))
10498 /* Now write out the computed sections. */
10500 if (reginfo_sec
!= NULL
)
10502 Elf32_External_RegInfo ext
;
10504 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
10505 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
10509 if (mdebug_sec
!= NULL
)
10511 BFD_ASSERT (abfd
->output_has_begun
);
10512 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
10514 mdebug_sec
->filepos
))
10517 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
10520 if (gptab_data_sec
!= NULL
)
10522 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
10523 gptab_data_sec
->contents
,
10524 0, gptab_data_sec
->size
))
10528 if (gptab_bss_sec
!= NULL
)
10530 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
10531 gptab_bss_sec
->contents
,
10532 0, gptab_bss_sec
->size
))
10536 if (SGI_COMPAT (abfd
))
10538 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
10539 if (rtproc_sec
!= NULL
)
10541 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
10542 rtproc_sec
->contents
,
10543 0, rtproc_sec
->size
))
10551 /* Structure for saying that BFD machine EXTENSION extends BASE. */
10553 struct mips_mach_extension
{
10554 unsigned long extension
, base
;
10558 /* An array describing how BFD machines relate to one another. The entries
10559 are ordered topologically with MIPS I extensions listed last. */
10561 static const struct mips_mach_extension mips_mach_extensions
[] = {
10562 /* MIPS64 extensions. */
10563 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
10564 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
10566 /* MIPS V extensions. */
10567 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
10569 /* R10000 extensions. */
10570 { bfd_mach_mips12000
, bfd_mach_mips10000
},
10572 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
10573 vr5400 ISA, but doesn't include the multimedia stuff. It seems
10574 better to allow vr5400 and vr5500 code to be merged anyway, since
10575 many libraries will just use the core ISA. Perhaps we could add
10576 some sort of ASE flag if this ever proves a problem. */
10577 { bfd_mach_mips5500
, bfd_mach_mips5400
},
10578 { bfd_mach_mips5400
, bfd_mach_mips5000
},
10580 /* MIPS IV extensions. */
10581 { bfd_mach_mips5
, bfd_mach_mips8000
},
10582 { bfd_mach_mips10000
, bfd_mach_mips8000
},
10583 { bfd_mach_mips5000
, bfd_mach_mips8000
},
10584 { bfd_mach_mips7000
, bfd_mach_mips8000
},
10585 { bfd_mach_mips9000
, bfd_mach_mips8000
},
10587 /* VR4100 extensions. */
10588 { bfd_mach_mips4120
, bfd_mach_mips4100
},
10589 { bfd_mach_mips4111
, bfd_mach_mips4100
},
10591 /* MIPS III extensions. */
10592 { bfd_mach_mips8000
, bfd_mach_mips4000
},
10593 { bfd_mach_mips4650
, bfd_mach_mips4000
},
10594 { bfd_mach_mips4600
, bfd_mach_mips4000
},
10595 { bfd_mach_mips4400
, bfd_mach_mips4000
},
10596 { bfd_mach_mips4300
, bfd_mach_mips4000
},
10597 { bfd_mach_mips4100
, bfd_mach_mips4000
},
10598 { bfd_mach_mips4010
, bfd_mach_mips4000
},
10600 /* MIPS32 extensions. */
10601 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
10603 /* MIPS II extensions. */
10604 { bfd_mach_mips4000
, bfd_mach_mips6000
},
10605 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
10607 /* MIPS I extensions. */
10608 { bfd_mach_mips6000
, bfd_mach_mips3000
},
10609 { bfd_mach_mips3900
, bfd_mach_mips3000
}
10613 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
10616 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
10620 if (extension
== base
)
10623 if (base
== bfd_mach_mipsisa32
10624 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
10627 if (base
== bfd_mach_mipsisa32r2
10628 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
10631 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
10632 if (extension
== mips_mach_extensions
[i
].extension
)
10634 extension
= mips_mach_extensions
[i
].base
;
10635 if (extension
== base
)
10643 /* Return true if the given ELF header flags describe a 32-bit binary. */
10646 mips_32bit_flags_p (flagword flags
)
10648 return ((flags
& EF_MIPS_32BITMODE
) != 0
10649 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
10650 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
10651 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
10652 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
10653 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
10654 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
10658 /* Merge backend specific data from an object file to the output
10659 object file when linking. */
10662 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
10664 flagword old_flags
;
10665 flagword new_flags
;
10667 bfd_boolean null_input_bfd
= TRUE
;
10670 /* Check if we have the same endianess */
10671 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
10673 (*_bfd_error_handler
)
10674 (_("%B: endianness incompatible with that of the selected emulation"),
10679 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
10680 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
10683 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
10685 (*_bfd_error_handler
)
10686 (_("%B: ABI is incompatible with that of the selected emulation"),
10691 new_flags
= elf_elfheader (ibfd
)->e_flags
;
10692 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
10693 old_flags
= elf_elfheader (obfd
)->e_flags
;
10695 if (! elf_flags_init (obfd
))
10697 elf_flags_init (obfd
) = TRUE
;
10698 elf_elfheader (obfd
)->e_flags
= new_flags
;
10699 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
10700 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
10702 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
10703 && bfd_get_arch_info (obfd
)->the_default
)
10705 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
10706 bfd_get_mach (ibfd
)))
10713 /* Check flag compatibility. */
10715 new_flags
&= ~EF_MIPS_NOREORDER
;
10716 old_flags
&= ~EF_MIPS_NOREORDER
;
10718 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
10719 doesn't seem to matter. */
10720 new_flags
&= ~EF_MIPS_XGOT
;
10721 old_flags
&= ~EF_MIPS_XGOT
;
10723 /* MIPSpro generates ucode info in n64 objects. Again, we should
10724 just be able to ignore this. */
10725 new_flags
&= ~EF_MIPS_UCODE
;
10726 old_flags
&= ~EF_MIPS_UCODE
;
10728 /* Don't care about the PIC flags from dynamic objects; they are
10730 if ((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0
10731 && (ibfd
->flags
& DYNAMIC
) != 0)
10732 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
10734 if (new_flags
== old_flags
)
10737 /* Check to see if the input BFD actually contains any sections.
10738 If not, its flags may not have been initialised either, but it cannot
10739 actually cause any incompatibility. */
10740 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
10742 /* Ignore synthetic sections and empty .text, .data and .bss sections
10743 which are automatically generated by gas. */
10744 if (strcmp (sec
->name
, ".reginfo")
10745 && strcmp (sec
->name
, ".mdebug")
10747 || (strcmp (sec
->name
, ".text")
10748 && strcmp (sec
->name
, ".data")
10749 && strcmp (sec
->name
, ".bss"))))
10751 null_input_bfd
= FALSE
;
10755 if (null_input_bfd
)
10760 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
10761 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
10763 (*_bfd_error_handler
)
10764 (_("%B: warning: linking PIC files with non-PIC files"),
10769 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
10770 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
10771 if (! (new_flags
& EF_MIPS_PIC
))
10772 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
10774 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
10775 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
10777 /* Compare the ISAs. */
10778 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
10780 (*_bfd_error_handler
)
10781 (_("%B: linking 32-bit code with 64-bit code"),
10785 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
10787 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
10788 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
10790 /* Copy the architecture info from IBFD to OBFD. Also copy
10791 the 32-bit flag (if set) so that we continue to recognise
10792 OBFD as a 32-bit binary. */
10793 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
10794 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
10795 elf_elfheader (obfd
)->e_flags
10796 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
10798 /* Copy across the ABI flags if OBFD doesn't use them
10799 and if that was what caused us to treat IBFD as 32-bit. */
10800 if ((old_flags
& EF_MIPS_ABI
) == 0
10801 && mips_32bit_flags_p (new_flags
)
10802 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
10803 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
10807 /* The ISAs aren't compatible. */
10808 (*_bfd_error_handler
)
10809 (_("%B: linking %s module with previous %s modules"),
10811 bfd_printable_name (ibfd
),
10812 bfd_printable_name (obfd
));
10817 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
10818 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
10820 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
10821 does set EI_CLASS differently from any 32-bit ABI. */
10822 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
10823 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
10824 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
10826 /* Only error if both are set (to different values). */
10827 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
10828 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
10829 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
10831 (*_bfd_error_handler
)
10832 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
10834 elf_mips_abi_name (ibfd
),
10835 elf_mips_abi_name (obfd
));
10838 new_flags
&= ~EF_MIPS_ABI
;
10839 old_flags
&= ~EF_MIPS_ABI
;
10842 /* For now, allow arbitrary mixing of ASEs (retain the union). */
10843 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
10845 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
10847 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
10848 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
10851 /* Warn about any other mismatches */
10852 if (new_flags
!= old_flags
)
10854 (*_bfd_error_handler
)
10855 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
10856 ibfd
, (unsigned long) new_flags
,
10857 (unsigned long) old_flags
);
10863 bfd_set_error (bfd_error_bad_value
);
10870 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
10873 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
10875 BFD_ASSERT (!elf_flags_init (abfd
)
10876 || elf_elfheader (abfd
)->e_flags
== flags
);
10878 elf_elfheader (abfd
)->e_flags
= flags
;
10879 elf_flags_init (abfd
) = TRUE
;
10884 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
10888 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
10890 /* Print normal ELF private data. */
10891 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
10893 /* xgettext:c-format */
10894 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
10896 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
10897 fprintf (file
, _(" [abi=O32]"));
10898 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
10899 fprintf (file
, _(" [abi=O64]"));
10900 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
10901 fprintf (file
, _(" [abi=EABI32]"));
10902 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
10903 fprintf (file
, _(" [abi=EABI64]"));
10904 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
10905 fprintf (file
, _(" [abi unknown]"));
10906 else if (ABI_N32_P (abfd
))
10907 fprintf (file
, _(" [abi=N32]"));
10908 else if (ABI_64_P (abfd
))
10909 fprintf (file
, _(" [abi=64]"));
10911 fprintf (file
, _(" [no abi set]"));
10913 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
10914 fprintf (file
, _(" [mips1]"));
10915 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
10916 fprintf (file
, _(" [mips2]"));
10917 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
10918 fprintf (file
, _(" [mips3]"));
10919 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
10920 fprintf (file
, _(" [mips4]"));
10921 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
10922 fprintf (file
, _(" [mips5]"));
10923 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
10924 fprintf (file
, _(" [mips32]"));
10925 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
10926 fprintf (file
, _(" [mips64]"));
10927 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
10928 fprintf (file
, _(" [mips32r2]"));
10929 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
10930 fprintf (file
, _(" [mips64r2]"));
10932 fprintf (file
, _(" [unknown ISA]"));
10934 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
10935 fprintf (file
, _(" [mdmx]"));
10937 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
10938 fprintf (file
, _(" [mips16]"));
10940 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
10941 fprintf (file
, _(" [32bitmode]"));
10943 fprintf (file
, _(" [not 32bitmode]"));
10945 fputc ('\n', file
);
10950 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
10952 { ".lit4", 5, 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
10953 { ".lit8", 5, 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
10954 { ".mdebug", 7, 0, SHT_MIPS_DEBUG
, 0 },
10955 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
10956 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
10957 { ".ucode", 6, 0, SHT_MIPS_UCODE
, 0 },
10958 { NULL
, 0, 0, 0, 0 }
10961 /* Ensure that the STO_OPTIONAL flag is copied into h->other,
10962 even if this is not a defintion of the symbol. */
10964 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
10965 const Elf_Internal_Sym
*isym
,
10966 bfd_boolean definition
,
10967 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
10970 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
10971 h
->other
|= STO_OPTIONAL
;
10974 /* Decide whether an undefined symbol is special and can be ignored.
10975 This is the case for OPTIONAL symbols on IRIX. */
10977 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
10979 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;