1 /* MIPS-specific support for ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005 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"
38 /* Get the ECOFF swapping routines. */
40 #include "coff/symconst.h"
41 #include "coff/ecoff.h"
42 #include "coff/mips.h"
46 /* This structure is used to hold .got entries while estimating got
50 /* The input bfd in which the symbol is defined. */
52 /* The index of the symbol, as stored in the relocation r_info, if
53 we have a local symbol; -1 otherwise. */
57 /* If abfd == NULL, an address that must be stored in the got. */
59 /* If abfd != NULL && symndx != -1, the addend of the relocation
60 that should be added to the symbol value. */
62 /* If abfd != NULL && symndx == -1, the hash table entry
63 corresponding to a global symbol in the got (or, local, if
65 struct mips_elf_link_hash_entry
*h
;
68 /* The TLS types included in this GOT entry (specifically, GD and
69 IE). The GD and IE flags can be added as we encounter new
70 relocations. LDM can also be set; it will always be alone, not
71 combined with any GD or IE flags. An LDM GOT entry will be
72 a local symbol entry with r_symndx == 0. */
73 unsigned char tls_type
;
75 /* The offset from the beginning of the .got section to the entry
76 corresponding to this symbol+addend. If it's a global symbol
77 whose offset is yet to be decided, it's going to be -1. */
81 /* This structure is used to hold .got information when linking. */
85 /* The global symbol in the GOT with the lowest index in the dynamic
87 struct elf_link_hash_entry
*global_gotsym
;
88 /* The number of global .got entries. */
89 unsigned int global_gotno
;
90 /* The number of .got slots used for TLS. */
91 unsigned int tls_gotno
;
92 /* The first unused TLS .got entry. Used only during
93 mips_elf_initialize_tls_index. */
94 unsigned int tls_assigned_gotno
;
95 /* The number of local .got entries. */
96 unsigned int local_gotno
;
97 /* The number of local .got entries we have used. */
98 unsigned int assigned_gotno
;
99 /* A hash table holding members of the got. */
100 struct htab
*got_entries
;
101 /* A hash table mapping input bfds to other mips_got_info. NULL
102 unless multi-got was necessary. */
103 struct htab
*bfd2got
;
104 /* In multi-got links, a pointer to the next got (err, rather, most
105 of the time, it points to the previous got). */
106 struct mips_got_info
*next
;
107 /* This is the GOT index of the TLS LDM entry for the GOT, MINUS_ONE
108 for none, or MINUS_TWO for not yet assigned. This is needed
109 because a single-GOT link may have multiple hash table entries
110 for the LDM. It does not get initialized in multi-GOT mode. */
111 bfd_vma tls_ldm_offset
;
114 /* Map an input bfd to a got in a multi-got link. */
116 struct mips_elf_bfd2got_hash
{
118 struct mips_got_info
*g
;
121 /* Structure passed when traversing the bfd2got hash table, used to
122 create and merge bfd's gots. */
124 struct mips_elf_got_per_bfd_arg
126 /* A hashtable that maps bfds to gots. */
128 /* The output bfd. */
130 /* The link information. */
131 struct bfd_link_info
*info
;
132 /* A pointer to the primary got, i.e., the one that's going to get
133 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
135 struct mips_got_info
*primary
;
136 /* A non-primary got we're trying to merge with other input bfd's
138 struct mips_got_info
*current
;
139 /* The maximum number of got entries that can be addressed with a
141 unsigned int max_count
;
142 /* The number of local and global entries in the primary got. */
143 unsigned int primary_count
;
144 /* The number of local and global entries in the current got. */
145 unsigned int current_count
;
146 /* The total number of global entries which will live in the
147 primary got and be automatically relocated. This includes
148 those not referenced by the primary GOT but included in
150 unsigned int global_count
;
153 /* Another structure used to pass arguments for got entries traversal. */
155 struct mips_elf_set_global_got_offset_arg
157 struct mips_got_info
*g
;
159 unsigned int needed_relocs
;
160 struct bfd_link_info
*info
;
163 /* A structure used to count TLS relocations or GOT entries, for GOT
164 entry or ELF symbol table traversal. */
166 struct mips_elf_count_tls_arg
168 struct bfd_link_info
*info
;
172 struct _mips_elf_section_data
174 struct bfd_elf_section_data elf
;
177 struct mips_got_info
*got_info
;
182 #define mips_elf_section_data(sec) \
183 ((struct _mips_elf_section_data *) elf_section_data (sec))
185 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
186 the dynamic symbols. */
188 struct mips_elf_hash_sort_data
190 /* The symbol in the global GOT with the lowest dynamic symbol table
192 struct elf_link_hash_entry
*low
;
193 /* The least dynamic symbol table index corresponding to a non-TLS
194 symbol with a GOT entry. */
195 long min_got_dynindx
;
196 /* The greatest dynamic symbol table index corresponding to a symbol
197 with a GOT entry that is not referenced (e.g., a dynamic symbol
198 with dynamic relocations pointing to it from non-primary GOTs). */
199 long max_unref_got_dynindx
;
200 /* The greatest dynamic symbol table index not corresponding to a
201 symbol without a GOT entry. */
202 long max_non_got_dynindx
;
205 /* The MIPS ELF linker needs additional information for each symbol in
206 the global hash table. */
208 struct mips_elf_link_hash_entry
210 struct elf_link_hash_entry root
;
212 /* External symbol information. */
215 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
217 unsigned int possibly_dynamic_relocs
;
219 /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
220 a readonly section. */
221 bfd_boolean readonly_reloc
;
223 /* We must not create a stub for a symbol that has relocations
224 related to taking the function's address, i.e. any but
225 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
227 bfd_boolean no_fn_stub
;
229 /* If there is a stub that 32 bit functions should use to call this
230 16 bit function, this points to the section containing the stub. */
233 /* Whether we need the fn_stub; this is set if this symbol appears
234 in any relocs other than a 16 bit call. */
235 bfd_boolean need_fn_stub
;
237 /* If there is a stub that 16 bit functions should use to call this
238 32 bit function, this points to the section containing the stub. */
241 /* This is like the call_stub field, but it is used if the function
242 being called returns a floating point value. */
243 asection
*call_fp_stub
;
245 /* Are we forced local? This will only be set if we have converted
246 the initial global GOT entry to a local GOT entry. */
247 bfd_boolean forced_local
;
251 #define GOT_TLS_LDM 2
253 #define GOT_TLS_OFFSET_DONE 0x40
254 #define GOT_TLS_DONE 0x80
255 unsigned char tls_type
;
256 /* This is only used in single-GOT mode; in multi-GOT mode there
257 is one mips_got_entry per GOT entry, so the offset is stored
258 there. In single-GOT mode there may be many mips_got_entry
259 structures all referring to the same GOT slot. It might be
260 possible to use root.got.offset instead, but that field is
261 overloaded already. */
262 bfd_vma tls_got_offset
;
265 /* MIPS ELF linker hash table. */
267 struct mips_elf_link_hash_table
269 struct elf_link_hash_table root
;
271 /* We no longer use this. */
272 /* String section indices for the dynamic section symbols. */
273 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
275 /* The number of .rtproc entries. */
276 bfd_size_type procedure_count
;
277 /* The size of the .compact_rel section (if SGI_COMPAT). */
278 bfd_size_type compact_rel_size
;
279 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
280 entry is set to the address of __rld_obj_head as in IRIX5. */
281 bfd_boolean use_rld_obj_head
;
282 /* This is the value of the __rld_map or __rld_obj_head symbol. */
284 /* This is set if we see any mips16 stub sections. */
285 bfd_boolean mips16_stubs_seen
;
288 #define TLS_RELOC_P(r_type) \
289 (r_type == R_MIPS_TLS_DTPMOD32 \
290 || r_type == R_MIPS_TLS_DTPMOD64 \
291 || r_type == R_MIPS_TLS_DTPREL32 \
292 || r_type == R_MIPS_TLS_DTPREL64 \
293 || r_type == R_MIPS_TLS_GD \
294 || r_type == R_MIPS_TLS_LDM \
295 || r_type == R_MIPS_TLS_DTPREL_HI16 \
296 || r_type == R_MIPS_TLS_DTPREL_LO16 \
297 || r_type == R_MIPS_TLS_GOTTPREL \
298 || r_type == R_MIPS_TLS_TPREL32 \
299 || r_type == R_MIPS_TLS_TPREL64 \
300 || r_type == R_MIPS_TLS_TPREL_HI16 \
301 || r_type == R_MIPS_TLS_TPREL_LO16)
303 /* Structure used to pass information to mips_elf_output_extsym. */
308 struct bfd_link_info
*info
;
309 struct ecoff_debug_info
*debug
;
310 const struct ecoff_debug_swap
*swap
;
314 /* The names of the runtime procedure table symbols used on IRIX5. */
316 static const char * const mips_elf_dynsym_rtproc_names
[] =
319 "_procedure_string_table",
320 "_procedure_table_size",
324 /* These structures are used to generate the .compact_rel section on
329 unsigned long id1
; /* Always one? */
330 unsigned long num
; /* Number of compact relocation entries. */
331 unsigned long id2
; /* Always two? */
332 unsigned long offset
; /* The file offset of the first relocation. */
333 unsigned long reserved0
; /* Zero? */
334 unsigned long reserved1
; /* Zero? */
343 bfd_byte reserved0
[4];
344 bfd_byte reserved1
[4];
345 } Elf32_External_compact_rel
;
349 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
350 unsigned int rtype
: 4; /* Relocation types. See below. */
351 unsigned int dist2to
: 8;
352 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
353 unsigned long konst
; /* KONST field. See below. */
354 unsigned long vaddr
; /* VADDR to be relocated. */
359 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
360 unsigned int rtype
: 4; /* Relocation types. See below. */
361 unsigned int dist2to
: 8;
362 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
363 unsigned long konst
; /* KONST field. See below. */
371 } Elf32_External_crinfo
;
377 } Elf32_External_crinfo2
;
379 /* These are the constants used to swap the bitfields in a crinfo. */
381 #define CRINFO_CTYPE (0x1)
382 #define CRINFO_CTYPE_SH (31)
383 #define CRINFO_RTYPE (0xf)
384 #define CRINFO_RTYPE_SH (27)
385 #define CRINFO_DIST2TO (0xff)
386 #define CRINFO_DIST2TO_SH (19)
387 #define CRINFO_RELVADDR (0x7ffff)
388 #define CRINFO_RELVADDR_SH (0)
390 /* A compact relocation info has long (3 words) or short (2 words)
391 formats. A short format doesn't have VADDR field and relvaddr
392 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
393 #define CRF_MIPS_LONG 1
394 #define CRF_MIPS_SHORT 0
396 /* There are 4 types of compact relocation at least. The value KONST
397 has different meaning for each type:
400 CT_MIPS_REL32 Address in data
401 CT_MIPS_WORD Address in word (XXX)
402 CT_MIPS_GPHI_LO GP - vaddr
403 CT_MIPS_JMPAD Address to jump
406 #define CRT_MIPS_REL32 0xa
407 #define CRT_MIPS_WORD 0xb
408 #define CRT_MIPS_GPHI_LO 0xc
409 #define CRT_MIPS_JMPAD 0xd
411 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
412 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
413 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
414 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
416 /* The structure of the runtime procedure descriptor created by the
417 loader for use by the static exception system. */
419 typedef struct runtime_pdr
{
420 bfd_vma adr
; /* Memory address of start of procedure. */
421 long regmask
; /* Save register mask. */
422 long regoffset
; /* Save register offset. */
423 long fregmask
; /* Save floating point register mask. */
424 long fregoffset
; /* Save floating point register offset. */
425 long frameoffset
; /* Frame size. */
426 short framereg
; /* Frame pointer register. */
427 short pcreg
; /* Offset or reg of return pc. */
428 long irpss
; /* Index into the runtime string table. */
430 struct exception_info
*exception_info
;/* Pointer to exception array. */
432 #define cbRPDR sizeof (RPDR)
433 #define rpdNil ((pRPDR) 0)
435 static struct mips_got_entry
*mips_elf_create_local_got_entry
436 (bfd
*, bfd
*, struct mips_got_info
*, asection
*, bfd_vma
, unsigned long,
437 struct mips_elf_link_hash_entry
*, int);
438 static bfd_boolean mips_elf_sort_hash_table_f
439 (struct mips_elf_link_hash_entry
*, void *);
440 static bfd_vma mips_elf_high
442 static bfd_boolean mips_elf_stub_section_p
444 static bfd_boolean mips_elf_create_dynamic_relocation
445 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
446 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
447 bfd_vma
*, asection
*);
448 static hashval_t mips_elf_got_entry_hash
450 static bfd_vma mips_elf_adjust_gp
451 (bfd
*, struct mips_got_info
*, bfd
*);
452 static struct mips_got_info
*mips_elf_got_for_ibfd
453 (struct mips_got_info
*, bfd
*);
455 /* This will be used when we sort the dynamic relocation records. */
456 static bfd
*reldyn_sorting_bfd
;
458 /* Nonzero if ABFD is using the N32 ABI. */
459 #define ABI_N32_P(abfd) \
460 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
462 /* Nonzero if ABFD is using the N64 ABI. */
463 #define ABI_64_P(abfd) \
464 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
466 /* Nonzero if ABFD is using NewABI conventions. */
467 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
469 /* The IRIX compatibility level we are striving for. */
470 #define IRIX_COMPAT(abfd) \
471 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
473 /* Whether we are trying to be compatible with IRIX at all. */
474 #define SGI_COMPAT(abfd) \
475 (IRIX_COMPAT (abfd) != ict_none)
477 /* The name of the options section. */
478 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
479 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
481 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
482 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
483 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
484 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
486 /* The name of the stub section. */
487 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
489 /* The size of an external REL relocation. */
490 #define MIPS_ELF_REL_SIZE(abfd) \
491 (get_elf_backend_data (abfd)->s->sizeof_rel)
493 /* The size of an external dynamic table entry. */
494 #define MIPS_ELF_DYN_SIZE(abfd) \
495 (get_elf_backend_data (abfd)->s->sizeof_dyn)
497 /* The size of a GOT entry. */
498 #define MIPS_ELF_GOT_SIZE(abfd) \
499 (get_elf_backend_data (abfd)->s->arch_size / 8)
501 /* The size of a symbol-table entry. */
502 #define MIPS_ELF_SYM_SIZE(abfd) \
503 (get_elf_backend_data (abfd)->s->sizeof_sym)
505 /* The default alignment for sections, as a power of two. */
506 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
507 (get_elf_backend_data (abfd)->s->log_file_align)
509 /* Get word-sized data. */
510 #define MIPS_ELF_GET_WORD(abfd, ptr) \
511 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
513 /* Put out word-sized data. */
514 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
516 ? bfd_put_64 (abfd, val, ptr) \
517 : bfd_put_32 (abfd, val, ptr))
519 /* Add a dynamic symbol table-entry. */
520 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
521 _bfd_elf_add_dynamic_entry (info, tag, val)
523 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
524 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
526 /* Determine whether the internal relocation of index REL_IDX is REL
527 (zero) or RELA (non-zero). The assumption is that, if there are
528 two relocation sections for this section, one of them is REL and
529 the other is RELA. If the index of the relocation we're testing is
530 in range for the first relocation section, check that the external
531 relocation size is that for RELA. It is also assumed that, if
532 rel_idx is not in range for the first section, and this first
533 section contains REL relocs, then the relocation is in the second
534 section, that is RELA. */
535 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
536 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
537 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
538 > (bfd_vma)(rel_idx)) \
539 == (elf_section_data (sec)->rel_hdr.sh_entsize \
540 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
541 : sizeof (Elf32_External_Rela))))
543 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
544 from smaller values. Start with zero, widen, *then* decrement. */
545 #define MINUS_ONE (((bfd_vma)0) - 1)
546 #define MINUS_TWO (((bfd_vma)0) - 2)
548 /* The number of local .got entries we reserve. */
549 #define MIPS_RESERVED_GOTNO (2)
551 /* The offset of $gp from the beginning of the .got section. */
552 #define ELF_MIPS_GP_OFFSET(abfd) (0x7ff0)
554 /* The maximum size of the GOT for it to be addressable using 16-bit
556 #define MIPS_ELF_GOT_MAX_SIZE(abfd) (ELF_MIPS_GP_OFFSET(abfd) + 0x7fff)
558 /* Instructions which appear in a stub. */
559 #define STUB_LW(abfd) \
561 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
562 : 0x8f998010)) /* lw t9,0x8010(gp) */
563 #define STUB_MOVE(abfd) \
565 ? 0x03e0782d /* daddu t7,ra */ \
566 : 0x03e07821)) /* addu t7,ra */
567 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
568 #define STUB_LI16(abfd) \
570 ? 0x64180000 /* daddiu t8,zero,0 */ \
571 : 0x24180000)) /* addiu t8,zero,0 */
572 #define MIPS_FUNCTION_STUB_SIZE (16)
574 /* The name of the dynamic interpreter. This is put in the .interp
577 #define ELF_DYNAMIC_INTERPRETER(abfd) \
578 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
579 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
580 : "/usr/lib/libc.so.1")
583 #define MNAME(bfd,pre,pos) \
584 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
585 #define ELF_R_SYM(bfd, i) \
586 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
587 #define ELF_R_TYPE(bfd, i) \
588 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
589 #define ELF_R_INFO(bfd, s, t) \
590 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
592 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
593 #define ELF_R_SYM(bfd, i) \
595 #define ELF_R_TYPE(bfd, i) \
597 #define ELF_R_INFO(bfd, s, t) \
598 (ELF32_R_INFO (s, t))
601 /* The mips16 compiler uses a couple of special sections to handle
602 floating point arguments.
604 Section names that look like .mips16.fn.FNNAME contain stubs that
605 copy floating point arguments from the fp regs to the gp regs and
606 then jump to FNNAME. If any 32 bit function calls FNNAME, the
607 call should be redirected to the stub instead. If no 32 bit
608 function calls FNNAME, the stub should be discarded. We need to
609 consider any reference to the function, not just a call, because
610 if the address of the function is taken we will need the stub,
611 since the address might be passed to a 32 bit function.
613 Section names that look like .mips16.call.FNNAME contain stubs
614 that copy floating point arguments from the gp regs to the fp
615 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
616 then any 16 bit function that calls FNNAME should be redirected
617 to the stub instead. If FNNAME is not a 32 bit function, the
618 stub should be discarded.
620 .mips16.call.fp.FNNAME sections are similar, but contain stubs
621 which call FNNAME and then copy the return value from the fp regs
622 to the gp regs. These stubs store the return value in $18 while
623 calling FNNAME; any function which might call one of these stubs
624 must arrange to save $18 around the call. (This case is not
625 needed for 32 bit functions that call 16 bit functions, because
626 16 bit functions always return floating point values in both
629 Note that in all cases FNNAME might be defined statically.
630 Therefore, FNNAME is not used literally. Instead, the relocation
631 information will indicate which symbol the section is for.
633 We record any stubs that we find in the symbol table. */
635 #define FN_STUB ".mips16.fn."
636 #define CALL_STUB ".mips16.call."
637 #define CALL_FP_STUB ".mips16.call.fp."
639 /* Look up an entry in a MIPS ELF linker hash table. */
641 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
642 ((struct mips_elf_link_hash_entry *) \
643 elf_link_hash_lookup (&(table)->root, (string), (create), \
646 /* Traverse a MIPS ELF linker hash table. */
648 #define mips_elf_link_hash_traverse(table, func, info) \
649 (elf_link_hash_traverse \
651 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
654 /* Get the MIPS ELF linker hash table from a link_info structure. */
656 #define mips_elf_hash_table(p) \
657 ((struct mips_elf_link_hash_table *) ((p)->hash))
659 /* Find the base offsets for thread-local storage in this object,
660 for GD/LD and IE/LE respectively. */
662 #define TP_OFFSET 0x7000
663 #define DTP_OFFSET 0x8000
666 dtprel_base (struct bfd_link_info
*info
)
668 /* If tls_sec is NULL, we should have signalled an error already. */
669 if (elf_hash_table (info
)->tls_sec
== NULL
)
671 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
675 tprel_base (struct bfd_link_info
*info
)
677 /* If tls_sec is NULL, we should have signalled an error already. */
678 if (elf_hash_table (info
)->tls_sec
== NULL
)
680 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
683 /* Create an entry in a MIPS ELF linker hash table. */
685 static struct bfd_hash_entry
*
686 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
687 struct bfd_hash_table
*table
, const char *string
)
689 struct mips_elf_link_hash_entry
*ret
=
690 (struct mips_elf_link_hash_entry
*) entry
;
692 /* Allocate the structure if it has not already been allocated by a
695 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
697 return (struct bfd_hash_entry
*) ret
;
699 /* Call the allocation method of the superclass. */
700 ret
= ((struct mips_elf_link_hash_entry
*)
701 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
705 /* Set local fields. */
706 memset (&ret
->esym
, 0, sizeof (EXTR
));
707 /* We use -2 as a marker to indicate that the information has
708 not been set. -1 means there is no associated ifd. */
710 ret
->possibly_dynamic_relocs
= 0;
711 ret
->readonly_reloc
= FALSE
;
712 ret
->no_fn_stub
= FALSE
;
714 ret
->need_fn_stub
= FALSE
;
715 ret
->call_stub
= NULL
;
716 ret
->call_fp_stub
= NULL
;
717 ret
->forced_local
= FALSE
;
718 ret
->tls_type
= GOT_NORMAL
;
721 return (struct bfd_hash_entry
*) ret
;
725 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
727 struct _mips_elf_section_data
*sdata
;
728 bfd_size_type amt
= sizeof (*sdata
);
730 sdata
= bfd_zalloc (abfd
, amt
);
733 sec
->used_by_bfd
= sdata
;
735 return _bfd_elf_new_section_hook (abfd
, sec
);
738 /* Read ECOFF debugging information from a .mdebug section into a
739 ecoff_debug_info structure. */
742 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
743 struct ecoff_debug_info
*debug
)
746 const struct ecoff_debug_swap
*swap
;
749 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
750 memset (debug
, 0, sizeof (*debug
));
752 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
753 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
756 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
757 swap
->external_hdr_size
))
760 symhdr
= &debug
->symbolic_header
;
761 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
763 /* The symbolic header contains absolute file offsets and sizes to
765 #define READ(ptr, offset, count, size, type) \
766 if (symhdr->count == 0) \
770 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
771 debug->ptr = bfd_malloc (amt); \
772 if (debug->ptr == NULL) \
774 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
775 || bfd_bread (debug->ptr, amt, abfd) != amt) \
779 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
780 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
781 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
782 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
783 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
784 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
786 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
787 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
788 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
789 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
790 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
800 if (debug
->line
!= NULL
)
802 if (debug
->external_dnr
!= NULL
)
803 free (debug
->external_dnr
);
804 if (debug
->external_pdr
!= NULL
)
805 free (debug
->external_pdr
);
806 if (debug
->external_sym
!= NULL
)
807 free (debug
->external_sym
);
808 if (debug
->external_opt
!= NULL
)
809 free (debug
->external_opt
);
810 if (debug
->external_aux
!= NULL
)
811 free (debug
->external_aux
);
812 if (debug
->ss
!= NULL
)
814 if (debug
->ssext
!= NULL
)
816 if (debug
->external_fdr
!= NULL
)
817 free (debug
->external_fdr
);
818 if (debug
->external_rfd
!= NULL
)
819 free (debug
->external_rfd
);
820 if (debug
->external_ext
!= NULL
)
821 free (debug
->external_ext
);
825 /* Swap RPDR (runtime procedure table entry) for output. */
828 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
830 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
831 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
832 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
833 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
834 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
835 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
837 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
838 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
840 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
843 /* Create a runtime procedure table from the .mdebug section. */
846 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
847 struct bfd_link_info
*info
, asection
*s
,
848 struct ecoff_debug_info
*debug
)
850 const struct ecoff_debug_swap
*swap
;
851 HDRR
*hdr
= &debug
->symbolic_header
;
853 struct rpdr_ext
*erp
;
855 struct pdr_ext
*epdr
;
856 struct sym_ext
*esym
;
861 unsigned long sindex
;
865 const char *no_name_func
= _("static procedure (no name)");
873 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
875 sindex
= strlen (no_name_func
) + 1;
879 size
= swap
->external_pdr_size
;
881 epdr
= bfd_malloc (size
* count
);
885 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
888 size
= sizeof (RPDR
);
889 rp
= rpdr
= bfd_malloc (size
* count
);
893 size
= sizeof (char *);
894 sv
= bfd_malloc (size
* count
);
898 count
= hdr
->isymMax
;
899 size
= swap
->external_sym_size
;
900 esym
= bfd_malloc (size
* count
);
904 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
908 ss
= bfd_malloc (count
);
911 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
915 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
917 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
918 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
920 rp
->regmask
= pdr
.regmask
;
921 rp
->regoffset
= pdr
.regoffset
;
922 rp
->fregmask
= pdr
.fregmask
;
923 rp
->fregoffset
= pdr
.fregoffset
;
924 rp
->frameoffset
= pdr
.frameoffset
;
925 rp
->framereg
= pdr
.framereg
;
926 rp
->pcreg
= pdr
.pcreg
;
928 sv
[i
] = ss
+ sym
.iss
;
929 sindex
+= strlen (sv
[i
]) + 1;
933 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
934 size
= BFD_ALIGN (size
, 16);
935 rtproc
= bfd_alloc (abfd
, size
);
938 mips_elf_hash_table (info
)->procedure_count
= 0;
942 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
945 memset (erp
, 0, sizeof (struct rpdr_ext
));
947 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
948 strcpy (str
, no_name_func
);
949 str
+= strlen (no_name_func
) + 1;
950 for (i
= 0; i
< count
; i
++)
952 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
954 str
+= strlen (sv
[i
]) + 1;
956 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
958 /* Set the size and contents of .rtproc section. */
960 s
->contents
= rtproc
;
962 /* Skip this section later on (I don't think this currently
963 matters, but someday it might). */
964 s
->map_head
.link_order
= NULL
;
993 /* Check the mips16 stubs for a particular symbol, and see if we can
997 mips_elf_check_mips16_stubs (struct mips_elf_link_hash_entry
*h
,
998 void *data ATTRIBUTE_UNUSED
)
1000 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1001 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1003 if (h
->fn_stub
!= NULL
1004 && ! h
->need_fn_stub
)
1006 /* We don't need the fn_stub; the only references to this symbol
1007 are 16 bit calls. Clobber the size to 0 to prevent it from
1008 being included in the link. */
1009 h
->fn_stub
->size
= 0;
1010 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1011 h
->fn_stub
->reloc_count
= 0;
1012 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1015 if (h
->call_stub
!= NULL
1016 && h
->root
.other
== STO_MIPS16
)
1018 /* We don't need the call_stub; this is a 16 bit function, so
1019 calls from other 16 bit functions are OK. Clobber the size
1020 to 0 to prevent it from being included in the link. */
1021 h
->call_stub
->size
= 0;
1022 h
->call_stub
->flags
&= ~SEC_RELOC
;
1023 h
->call_stub
->reloc_count
= 0;
1024 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1027 if (h
->call_fp_stub
!= NULL
1028 && h
->root
.other
== STO_MIPS16
)
1030 /* We don't need the call_stub; this is a 16 bit function, so
1031 calls from other 16 bit functions are OK. Clobber the size
1032 to 0 to prevent it from being included in the link. */
1033 h
->call_fp_stub
->size
= 0;
1034 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1035 h
->call_fp_stub
->reloc_count
= 0;
1036 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1042 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1043 Most mips16 instructions are 16 bits, but these instructions
1046 The format of these instructions is:
1048 +--------------+--------------------------------+
1049 | JALX | X| Imm 20:16 | Imm 25:21 |
1050 +--------------+--------------------------------+
1052 +-----------------------------------------------+
1054 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1055 Note that the immediate value in the first word is swapped.
1057 When producing a relocatable object file, R_MIPS16_26 is
1058 handled mostly like R_MIPS_26. In particular, the addend is
1059 stored as a straight 26-bit value in a 32-bit instruction.
1060 (gas makes life simpler for itself by never adjusting a
1061 R_MIPS16_26 reloc to be against a section, so the addend is
1062 always zero). However, the 32 bit instruction is stored as 2
1063 16-bit values, rather than a single 32-bit value. In a
1064 big-endian file, the result is the same; in a little-endian
1065 file, the two 16-bit halves of the 32 bit value are swapped.
1066 This is so that a disassembler can recognize the jal
1069 When doing a final link, R_MIPS16_26 is treated as a 32 bit
1070 instruction stored as two 16-bit values. The addend A is the
1071 contents of the targ26 field. The calculation is the same as
1072 R_MIPS_26. When storing the calculated value, reorder the
1073 immediate value as shown above, and don't forget to store the
1074 value as two 16-bit values.
1076 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
1080 +--------+----------------------+
1084 +--------+----------------------+
1087 +----------+------+-------------+
1091 +----------+--------------------+
1092 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
1093 ((sub1 << 16) | sub2)).
1095 When producing a relocatable object file, the calculation is
1096 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1097 When producing a fully linked file, the calculation is
1098 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1099 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
1101 R_MIPS16_GPREL is used for GP-relative addressing in mips16
1102 mode. A typical instruction will have a format like this:
1104 +--------------+--------------------------------+
1105 | EXTEND | Imm 10:5 | Imm 15:11 |
1106 +--------------+--------------------------------+
1107 | Major | rx | ry | Imm 4:0 |
1108 +--------------+--------------------------------+
1110 EXTEND is the five bit value 11110. Major is the instruction
1113 This is handled exactly like R_MIPS_GPREL16, except that the
1114 addend is retrieved and stored as shown in this diagram; that
1115 is, the Imm fields above replace the V-rel16 field.
1117 All we need to do here is shuffle the bits appropriately. As
1118 above, the two 16-bit halves must be swapped on a
1119 little-endian system.
1121 R_MIPS16_HI16 and R_MIPS16_LO16 are used in mips16 mode to
1122 access data when neither GP-relative nor PC-relative addressing
1123 can be used. They are handled like R_MIPS_HI16 and R_MIPS_LO16,
1124 except that the addend is retrieved and stored as shown above
1128 _bfd_mips16_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
1129 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1131 bfd_vma extend
, insn
, val
;
1133 if (r_type
!= R_MIPS16_26
&& r_type
!= R_MIPS16_GPREL
1134 && r_type
!= R_MIPS16_HI16
&& r_type
!= R_MIPS16_LO16
)
1137 /* Pick up the mips16 extend instruction and the real instruction. */
1138 extend
= bfd_get_16 (abfd
, data
);
1139 insn
= bfd_get_16 (abfd
, data
+ 2);
1140 if (r_type
== R_MIPS16_26
)
1143 val
= ((extend
& 0xfc00) << 16) | ((extend
& 0x3e0) << 11)
1144 | ((extend
& 0x1f) << 21) | insn
;
1146 val
= extend
<< 16 | insn
;
1149 val
= ((extend
& 0xf800) << 16) | ((insn
& 0xffe0) << 11)
1150 | ((extend
& 0x1f) << 11) | (extend
& 0x7e0) | (insn
& 0x1f);
1151 bfd_put_32 (abfd
, val
, data
);
1155 _bfd_mips16_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
1156 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1158 bfd_vma extend
, insn
, val
;
1160 if (r_type
!= R_MIPS16_26
&& r_type
!= R_MIPS16_GPREL
1161 && r_type
!= R_MIPS16_HI16
&& r_type
!= R_MIPS16_LO16
)
1164 val
= bfd_get_32 (abfd
, data
);
1165 if (r_type
== R_MIPS16_26
)
1169 insn
= val
& 0xffff;
1170 extend
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
1171 | ((val
>> 21) & 0x1f);
1175 insn
= val
& 0xffff;
1181 insn
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
1182 extend
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
1184 bfd_put_16 (abfd
, insn
, data
+ 2);
1185 bfd_put_16 (abfd
, extend
, data
);
1188 bfd_reloc_status_type
1189 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1190 arelent
*reloc_entry
, asection
*input_section
,
1191 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1195 bfd_reloc_status_type status
;
1197 if (bfd_is_com_section (symbol
->section
))
1200 relocation
= symbol
->value
;
1202 relocation
+= symbol
->section
->output_section
->vma
;
1203 relocation
+= symbol
->section
->output_offset
;
1205 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1206 return bfd_reloc_outofrange
;
1208 /* Set val to the offset into the section or symbol. */
1209 val
= reloc_entry
->addend
;
1211 _bfd_mips_elf_sign_extend (val
, 16);
1213 /* Adjust val for the final section location and GP value. If we
1214 are producing relocatable output, we don't want to do this for
1215 an external symbol. */
1217 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1218 val
+= relocation
- gp
;
1220 if (reloc_entry
->howto
->partial_inplace
)
1222 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1224 + reloc_entry
->address
);
1225 if (status
!= bfd_reloc_ok
)
1229 reloc_entry
->addend
= val
;
1232 reloc_entry
->address
+= input_section
->output_offset
;
1234 return bfd_reloc_ok
;
1237 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
1238 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
1239 that contains the relocation field and DATA points to the start of
1244 struct mips_hi16
*next
;
1246 asection
*input_section
;
1250 /* FIXME: This should not be a static variable. */
1252 static struct mips_hi16
*mips_hi16_list
;
1254 /* A howto special_function for REL *HI16 relocations. We can only
1255 calculate the correct value once we've seen the partnering
1256 *LO16 relocation, so just save the information for later.
1258 The ABI requires that the *LO16 immediately follow the *HI16.
1259 However, as a GNU extension, we permit an arbitrary number of
1260 *HI16s to be associated with a single *LO16. This significantly
1261 simplies the relocation handling in gcc. */
1263 bfd_reloc_status_type
1264 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1265 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
1266 asection
*input_section
, bfd
*output_bfd
,
1267 char **error_message ATTRIBUTE_UNUSED
)
1269 struct mips_hi16
*n
;
1271 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1272 return bfd_reloc_outofrange
;
1274 n
= bfd_malloc (sizeof *n
);
1276 return bfd_reloc_outofrange
;
1278 n
->next
= mips_hi16_list
;
1280 n
->input_section
= input_section
;
1281 n
->rel
= *reloc_entry
;
1284 if (output_bfd
!= NULL
)
1285 reloc_entry
->address
+= input_section
->output_offset
;
1287 return bfd_reloc_ok
;
1290 /* A howto special_function for REL R_MIPS_GOT16 relocations. This is just
1291 like any other 16-bit relocation when applied to global symbols, but is
1292 treated in the same as R_MIPS_HI16 when applied to local symbols. */
1294 bfd_reloc_status_type
1295 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1296 void *data
, asection
*input_section
,
1297 bfd
*output_bfd
, char **error_message
)
1299 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
1300 || bfd_is_und_section (bfd_get_section (symbol
))
1301 || bfd_is_com_section (bfd_get_section (symbol
)))
1302 /* The relocation is against a global symbol. */
1303 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1304 input_section
, output_bfd
,
1307 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
1308 input_section
, output_bfd
, error_message
);
1311 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
1312 is a straightforward 16 bit inplace relocation, but we must deal with
1313 any partnering high-part relocations as well. */
1315 bfd_reloc_status_type
1316 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1317 void *data
, asection
*input_section
,
1318 bfd
*output_bfd
, char **error_message
)
1321 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1323 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1324 return bfd_reloc_outofrange
;
1326 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1328 vallo
= bfd_get_32 (abfd
, location
);
1329 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1332 while (mips_hi16_list
!= NULL
)
1334 bfd_reloc_status_type ret
;
1335 struct mips_hi16
*hi
;
1337 hi
= mips_hi16_list
;
1339 /* R_MIPS_GOT16 relocations are something of a special case. We
1340 want to install the addend in the same way as for a R_MIPS_HI16
1341 relocation (with a rightshift of 16). However, since GOT16
1342 relocations can also be used with global symbols, their howto
1343 has a rightshift of 0. */
1344 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
1345 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
1347 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
1348 carry or borrow will induce a change of +1 or -1 in the high part. */
1349 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
1351 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
1352 hi
->input_section
, output_bfd
,
1354 if (ret
!= bfd_reloc_ok
)
1357 mips_hi16_list
= hi
->next
;
1361 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1362 input_section
, output_bfd
,
1366 /* A generic howto special_function. This calculates and installs the
1367 relocation itself, thus avoiding the oft-discussed problems in
1368 bfd_perform_relocation and bfd_install_relocation. */
1370 bfd_reloc_status_type
1371 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1372 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
1373 asection
*input_section
, bfd
*output_bfd
,
1374 char **error_message ATTRIBUTE_UNUSED
)
1377 bfd_reloc_status_type status
;
1378 bfd_boolean relocatable
;
1380 relocatable
= (output_bfd
!= NULL
);
1382 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1383 return bfd_reloc_outofrange
;
1385 /* Build up the field adjustment in VAL. */
1387 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1389 /* Either we're calculating the final field value or we have a
1390 relocation against a section symbol. Add in the section's
1391 offset or address. */
1392 val
+= symbol
->section
->output_section
->vma
;
1393 val
+= symbol
->section
->output_offset
;
1398 /* We're calculating the final field value. Add in the symbol's value
1399 and, if pc-relative, subtract the address of the field itself. */
1400 val
+= symbol
->value
;
1401 if (reloc_entry
->howto
->pc_relative
)
1403 val
-= input_section
->output_section
->vma
;
1404 val
-= input_section
->output_offset
;
1405 val
-= reloc_entry
->address
;
1409 /* VAL is now the final adjustment. If we're keeping this relocation
1410 in the output file, and if the relocation uses a separate addend,
1411 we just need to add VAL to that addend. Otherwise we need to add
1412 VAL to the relocation field itself. */
1413 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
1414 reloc_entry
->addend
+= val
;
1417 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
1419 /* Add in the separate addend, if any. */
1420 val
+= reloc_entry
->addend
;
1422 /* Add VAL to the relocation field. */
1423 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1425 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1427 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
1430 if (status
!= bfd_reloc_ok
)
1435 reloc_entry
->address
+= input_section
->output_offset
;
1437 return bfd_reloc_ok
;
1440 /* Swap an entry in a .gptab section. Note that these routines rely
1441 on the equivalence of the two elements of the union. */
1444 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
1447 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1448 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1452 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
1453 Elf32_External_gptab
*ex
)
1455 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
1456 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
1460 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
1461 Elf32_External_compact_rel
*ex
)
1463 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1464 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1465 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1466 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1467 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1468 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1472 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
1473 Elf32_External_crinfo
*ex
)
1477 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1478 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1479 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1480 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1481 H_PUT_32 (abfd
, l
, ex
->info
);
1482 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1483 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1486 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1487 routines swap this structure in and out. They are used outside of
1488 BFD, so they are globally visible. */
1491 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
1494 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1495 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1496 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1497 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1498 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1499 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1503 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
1504 Elf32_External_RegInfo
*ex
)
1506 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1507 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1508 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1509 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1510 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1511 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1514 /* In the 64 bit ABI, the .MIPS.options section holds register
1515 information in an Elf64_Reginfo structure. These routines swap
1516 them in and out. They are globally visible because they are used
1517 outside of BFD. These routines are here so that gas can call them
1518 without worrying about whether the 64 bit ABI has been included. */
1521 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
1522 Elf64_Internal_RegInfo
*in
)
1524 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1525 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1526 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1527 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1528 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1529 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1530 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1534 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
1535 Elf64_External_RegInfo
*ex
)
1537 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1538 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1539 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1540 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1541 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1542 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1543 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1546 /* Swap in an options header. */
1549 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
1550 Elf_Internal_Options
*in
)
1552 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1553 in
->size
= H_GET_8 (abfd
, ex
->size
);
1554 in
->section
= H_GET_16 (abfd
, ex
->section
);
1555 in
->info
= H_GET_32 (abfd
, ex
->info
);
1558 /* Swap out an options header. */
1561 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
1562 Elf_External_Options
*ex
)
1564 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1565 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1566 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1567 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1570 /* This function is called via qsort() to sort the dynamic relocation
1571 entries by increasing r_symndx value. */
1574 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
1576 Elf_Internal_Rela int_reloc1
;
1577 Elf_Internal_Rela int_reloc2
;
1579 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1580 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1582 return ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
1585 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
1588 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
1589 const void *arg2 ATTRIBUTE_UNUSED
)
1592 Elf_Internal_Rela int_reloc1
[3];
1593 Elf_Internal_Rela int_reloc2
[3];
1595 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1596 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
1597 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1598 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
1600 return (ELF64_R_SYM (int_reloc1
[0].r_info
)
1601 - ELF64_R_SYM (int_reloc2
[0].r_info
));
1608 /* This routine is used to write out ECOFF debugging external symbol
1609 information. It is called via mips_elf_link_hash_traverse. The
1610 ECOFF external symbol information must match the ELF external
1611 symbol information. Unfortunately, at this point we don't know
1612 whether a symbol is required by reloc information, so the two
1613 tables may wind up being different. We must sort out the external
1614 symbol information before we can set the final size of the .mdebug
1615 section, and we must set the size of the .mdebug section before we
1616 can relocate any sections, and we can't know which symbols are
1617 required by relocation until we relocate the sections.
1618 Fortunately, it is relatively unlikely that any symbol will be
1619 stripped but required by a reloc. In particular, it can not happen
1620 when generating a final executable. */
1623 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
1625 struct extsym_info
*einfo
= data
;
1627 asection
*sec
, *output_section
;
1629 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1630 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1632 if (h
->root
.indx
== -2)
1634 else if ((h
->root
.def_dynamic
1635 || h
->root
.ref_dynamic
1636 || h
->root
.type
== bfd_link_hash_new
)
1637 && !h
->root
.def_regular
1638 && !h
->root
.ref_regular
)
1640 else if (einfo
->info
->strip
== strip_all
1641 || (einfo
->info
->strip
== strip_some
1642 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1643 h
->root
.root
.root
.string
,
1644 FALSE
, FALSE
) == NULL
))
1652 if (h
->esym
.ifd
== -2)
1655 h
->esym
.cobol_main
= 0;
1656 h
->esym
.weakext
= 0;
1657 h
->esym
.reserved
= 0;
1658 h
->esym
.ifd
= ifdNil
;
1659 h
->esym
.asym
.value
= 0;
1660 h
->esym
.asym
.st
= stGlobal
;
1662 if (h
->root
.root
.type
== bfd_link_hash_undefined
1663 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
1667 /* Use undefined class. Also, set class and type for some
1669 name
= h
->root
.root
.root
.string
;
1670 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
1671 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
1673 h
->esym
.asym
.sc
= scData
;
1674 h
->esym
.asym
.st
= stLabel
;
1675 h
->esym
.asym
.value
= 0;
1677 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
1679 h
->esym
.asym
.sc
= scAbs
;
1680 h
->esym
.asym
.st
= stLabel
;
1681 h
->esym
.asym
.value
=
1682 mips_elf_hash_table (einfo
->info
)->procedure_count
;
1684 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
1686 h
->esym
.asym
.sc
= scAbs
;
1687 h
->esym
.asym
.st
= stLabel
;
1688 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
1691 h
->esym
.asym
.sc
= scUndefined
;
1693 else if (h
->root
.root
.type
!= bfd_link_hash_defined
1694 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1695 h
->esym
.asym
.sc
= scAbs
;
1700 sec
= h
->root
.root
.u
.def
.section
;
1701 output_section
= sec
->output_section
;
1703 /* When making a shared library and symbol h is the one from
1704 the another shared library, OUTPUT_SECTION may be null. */
1705 if (output_section
== NULL
)
1706 h
->esym
.asym
.sc
= scUndefined
;
1709 name
= bfd_section_name (output_section
->owner
, output_section
);
1711 if (strcmp (name
, ".text") == 0)
1712 h
->esym
.asym
.sc
= scText
;
1713 else if (strcmp (name
, ".data") == 0)
1714 h
->esym
.asym
.sc
= scData
;
1715 else if (strcmp (name
, ".sdata") == 0)
1716 h
->esym
.asym
.sc
= scSData
;
1717 else if (strcmp (name
, ".rodata") == 0
1718 || strcmp (name
, ".rdata") == 0)
1719 h
->esym
.asym
.sc
= scRData
;
1720 else if (strcmp (name
, ".bss") == 0)
1721 h
->esym
.asym
.sc
= scBss
;
1722 else if (strcmp (name
, ".sbss") == 0)
1723 h
->esym
.asym
.sc
= scSBss
;
1724 else if (strcmp (name
, ".init") == 0)
1725 h
->esym
.asym
.sc
= scInit
;
1726 else if (strcmp (name
, ".fini") == 0)
1727 h
->esym
.asym
.sc
= scFini
;
1729 h
->esym
.asym
.sc
= scAbs
;
1733 h
->esym
.asym
.reserved
= 0;
1734 h
->esym
.asym
.index
= indexNil
;
1737 if (h
->root
.root
.type
== bfd_link_hash_common
)
1738 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1739 else if (h
->root
.root
.type
== bfd_link_hash_defined
1740 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1742 if (h
->esym
.asym
.sc
== scCommon
)
1743 h
->esym
.asym
.sc
= scBss
;
1744 else if (h
->esym
.asym
.sc
== scSCommon
)
1745 h
->esym
.asym
.sc
= scSBss
;
1747 sec
= h
->root
.root
.u
.def
.section
;
1748 output_section
= sec
->output_section
;
1749 if (output_section
!= NULL
)
1750 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1751 + sec
->output_offset
1752 + output_section
->vma
);
1754 h
->esym
.asym
.value
= 0;
1756 else if (h
->root
.needs_plt
)
1758 struct mips_elf_link_hash_entry
*hd
= h
;
1759 bfd_boolean no_fn_stub
= h
->no_fn_stub
;
1761 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
1763 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
1764 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
1769 /* Set type and value for a symbol with a function stub. */
1770 h
->esym
.asym
.st
= stProc
;
1771 sec
= hd
->root
.root
.u
.def
.section
;
1773 h
->esym
.asym
.value
= 0;
1776 output_section
= sec
->output_section
;
1777 if (output_section
!= NULL
)
1778 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
1779 + sec
->output_offset
1780 + output_section
->vma
);
1782 h
->esym
.asym
.value
= 0;
1787 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1788 h
->root
.root
.root
.string
,
1791 einfo
->failed
= TRUE
;
1798 /* A comparison routine used to sort .gptab entries. */
1801 gptab_compare (const void *p1
, const void *p2
)
1803 const Elf32_gptab
*a1
= p1
;
1804 const Elf32_gptab
*a2
= p2
;
1806 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
1809 /* Functions to manage the got entry hash table. */
1811 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
1814 static INLINE hashval_t
1815 mips_elf_hash_bfd_vma (bfd_vma addr
)
1818 return addr
+ (addr
>> 32);
1824 /* got_entries only match if they're identical, except for gotidx, so
1825 use all fields to compute the hash, and compare the appropriate
1829 mips_elf_got_entry_hash (const void *entry_
)
1831 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
1833 return entry
->symndx
1834 + ((entry
->tls_type
& GOT_TLS_LDM
) << 17)
1835 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
1837 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
1838 : entry
->d
.h
->root
.root
.root
.hash
));
1842 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
1844 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
1845 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
1847 /* An LDM entry can only match another LDM entry. */
1848 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
1851 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
1852 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
1853 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
1854 : e1
->d
.h
== e2
->d
.h
);
1857 /* multi_got_entries are still a match in the case of global objects,
1858 even if the input bfd in which they're referenced differs, so the
1859 hash computation and compare functions are adjusted
1863 mips_elf_multi_got_entry_hash (const void *entry_
)
1865 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
1867 return entry
->symndx
1869 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
1870 : entry
->symndx
>= 0
1871 ? ((entry
->tls_type
& GOT_TLS_LDM
)
1872 ? (GOT_TLS_LDM
<< 17)
1874 + mips_elf_hash_bfd_vma (entry
->d
.addend
)))
1875 : entry
->d
.h
->root
.root
.root
.hash
);
1879 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
1881 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
1882 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
1884 /* Any two LDM entries match. */
1885 if (e1
->tls_type
& e2
->tls_type
& GOT_TLS_LDM
)
1888 /* Nothing else matches an LDM entry. */
1889 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
1892 return e1
->symndx
== e2
->symndx
1893 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
1894 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
1895 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
1896 : e1
->d
.h
== e2
->d
.h
);
1899 /* Returns the dynamic relocation section for DYNOBJ. */
1902 mips_elf_rel_dyn_section (bfd
*dynobj
, bfd_boolean create_p
)
1904 static const char dname
[] = ".rel.dyn";
1907 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
1908 if (sreloc
== NULL
&& create_p
)
1910 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
1915 | SEC_LINKER_CREATED
1918 || ! bfd_set_section_alignment (dynobj
, sreloc
,
1919 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
1925 /* Returns the GOT section for ABFD. */
1928 mips_elf_got_section (bfd
*abfd
, bfd_boolean maybe_excluded
)
1930 asection
*sgot
= bfd_get_section_by_name (abfd
, ".got");
1932 || (! maybe_excluded
&& (sgot
->flags
& SEC_EXCLUDE
) != 0))
1937 /* Returns the GOT information associated with the link indicated by
1938 INFO. If SGOTP is non-NULL, it is filled in with the GOT
1941 static struct mips_got_info
*
1942 mips_elf_got_info (bfd
*abfd
, asection
**sgotp
)
1945 struct mips_got_info
*g
;
1947 sgot
= mips_elf_got_section (abfd
, TRUE
);
1948 BFD_ASSERT (sgot
!= NULL
);
1949 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
1950 g
= mips_elf_section_data (sgot
)->u
.got_info
;
1951 BFD_ASSERT (g
!= NULL
);
1954 *sgotp
= (sgot
->flags
& SEC_EXCLUDE
) == 0 ? sgot
: NULL
;
1959 /* Count the number of relocations needed for a TLS GOT entry, with
1960 access types from TLS_TYPE, and symbol H (or a local symbol if H
1964 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
1965 struct elf_link_hash_entry
*h
)
1969 bfd_boolean need_relocs
= FALSE
;
1970 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
1972 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
1973 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
1976 if ((info
->shared
|| indx
!= 0)
1978 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1979 || h
->root
.type
!= bfd_link_hash_undefweak
))
1985 if (tls_type
& GOT_TLS_GD
)
1992 if (tls_type
& GOT_TLS_IE
)
1995 if ((tls_type
& GOT_TLS_LDM
) && info
->shared
)
2001 /* Count the number of TLS relocations required for the GOT entry in
2002 ARG1, if it describes a local symbol. */
2005 mips_elf_count_local_tls_relocs (void **arg1
, void *arg2
)
2007 struct mips_got_entry
*entry
= * (struct mips_got_entry
**) arg1
;
2008 struct mips_elf_count_tls_arg
*arg
= arg2
;
2010 if (entry
->abfd
!= NULL
&& entry
->symndx
!= -1)
2011 arg
->needed
+= mips_tls_got_relocs (arg
->info
, entry
->tls_type
, NULL
);
2016 /* Count the number of TLS GOT entries required for the global (or
2017 forced-local) symbol in ARG1. */
2020 mips_elf_count_global_tls_entries (void *arg1
, void *arg2
)
2022 struct mips_elf_link_hash_entry
*hm
2023 = (struct mips_elf_link_hash_entry
*) arg1
;
2024 struct mips_elf_count_tls_arg
*arg
= arg2
;
2026 if (hm
->tls_type
& GOT_TLS_GD
)
2028 if (hm
->tls_type
& GOT_TLS_IE
)
2034 /* Count the number of TLS relocations required for the global (or
2035 forced-local) symbol in ARG1. */
2038 mips_elf_count_global_tls_relocs (void *arg1
, void *arg2
)
2040 struct mips_elf_link_hash_entry
*hm
2041 = (struct mips_elf_link_hash_entry
*) arg1
;
2042 struct mips_elf_count_tls_arg
*arg
= arg2
;
2044 arg
->needed
+= mips_tls_got_relocs (arg
->info
, hm
->tls_type
, &hm
->root
);
2049 /* Output a simple dynamic relocation into SRELOC. */
2052 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
2058 Elf_Internal_Rela rel
[3];
2060 memset (rel
, 0, sizeof (rel
));
2062 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
2063 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
2065 if (ABI_64_P (output_bfd
))
2067 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2068 (output_bfd
, &rel
[0],
2070 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
2073 bfd_elf32_swap_reloc_out
2074 (output_bfd
, &rel
[0],
2076 + sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
2077 ++sreloc
->reloc_count
;
2080 /* Initialize a set of TLS GOT entries for one symbol. */
2083 mips_elf_initialize_tls_slots (bfd
*abfd
, bfd_vma got_offset
,
2084 unsigned char *tls_type_p
,
2085 struct bfd_link_info
*info
,
2086 struct mips_elf_link_hash_entry
*h
,
2090 asection
*sreloc
, *sgot
;
2091 bfd_vma offset
, offset2
;
2093 bfd_boolean need_relocs
= FALSE
;
2095 dynobj
= elf_hash_table (info
)->dynobj
;
2096 sgot
= mips_elf_got_section (dynobj
, FALSE
);
2101 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2103 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
2104 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
2105 indx
= h
->root
.dynindx
;
2108 if (*tls_type_p
& GOT_TLS_DONE
)
2111 if ((info
->shared
|| indx
!= 0)
2113 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
2114 || h
->root
.type
!= bfd_link_hash_undefweak
))
2117 /* MINUS_ONE means the symbol is not defined in this object. It may not
2118 be defined at all; assume that the value doesn't matter in that
2119 case. Otherwise complain if we would use the value. */
2120 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
2121 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
2123 /* Emit necessary relocations. */
2124 sreloc
= mips_elf_rel_dyn_section (dynobj
, FALSE
);
2126 /* General Dynamic. */
2127 if (*tls_type_p
& GOT_TLS_GD
)
2129 offset
= got_offset
;
2130 offset2
= offset
+ MIPS_ELF_GOT_SIZE (abfd
);
2134 mips_elf_output_dynamic_relocation
2135 (abfd
, sreloc
, indx
,
2136 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2137 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2140 mips_elf_output_dynamic_relocation
2141 (abfd
, sreloc
, indx
,
2142 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
2143 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset2
);
2145 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2146 sgot
->contents
+ offset2
);
2150 MIPS_ELF_PUT_WORD (abfd
, 1,
2151 sgot
->contents
+ offset
);
2152 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2153 sgot
->contents
+ offset2
);
2156 got_offset
+= 2 * MIPS_ELF_GOT_SIZE (abfd
);
2159 /* Initial Exec model. */
2160 if (*tls_type_p
& GOT_TLS_IE
)
2162 offset
= got_offset
;
2167 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
2168 sgot
->contents
+ offset
);
2170 MIPS_ELF_PUT_WORD (abfd
, 0,
2171 sgot
->contents
+ offset
);
2173 mips_elf_output_dynamic_relocation
2174 (abfd
, sreloc
, indx
,
2175 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
2176 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2179 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
2180 sgot
->contents
+ offset
);
2183 if (*tls_type_p
& GOT_TLS_LDM
)
2185 /* The initial offset is zero, and the LD offsets will include the
2186 bias by DTP_OFFSET. */
2187 MIPS_ELF_PUT_WORD (abfd
, 0,
2188 sgot
->contents
+ got_offset
2189 + MIPS_ELF_GOT_SIZE (abfd
));
2192 MIPS_ELF_PUT_WORD (abfd
, 1,
2193 sgot
->contents
+ got_offset
);
2195 mips_elf_output_dynamic_relocation
2196 (abfd
, sreloc
, indx
,
2197 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2198 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
2201 *tls_type_p
|= GOT_TLS_DONE
;
2204 /* Return the GOT index to use for a relocation of type R_TYPE against
2205 a symbol accessed using TLS_TYPE models. The GOT entries for this
2206 symbol in this GOT start at GOT_INDEX. This function initializes the
2207 GOT entries and corresponding relocations. */
2210 mips_tls_got_index (bfd
*abfd
, bfd_vma got_index
, unsigned char *tls_type
,
2211 int r_type
, struct bfd_link_info
*info
,
2212 struct mips_elf_link_hash_entry
*h
, bfd_vma symbol
)
2214 BFD_ASSERT (r_type
== R_MIPS_TLS_GOTTPREL
|| r_type
== R_MIPS_TLS_GD
2215 || r_type
== R_MIPS_TLS_LDM
);
2217 mips_elf_initialize_tls_slots (abfd
, got_index
, tls_type
, info
, h
, symbol
);
2219 if (r_type
== R_MIPS_TLS_GOTTPREL
)
2221 BFD_ASSERT (*tls_type
& GOT_TLS_IE
);
2222 if (*tls_type
& GOT_TLS_GD
)
2223 return got_index
+ 2 * MIPS_ELF_GOT_SIZE (abfd
);
2228 if (r_type
== R_MIPS_TLS_GD
)
2230 BFD_ASSERT (*tls_type
& GOT_TLS_GD
);
2234 if (r_type
== R_MIPS_TLS_LDM
)
2236 BFD_ASSERT (*tls_type
& GOT_TLS_LDM
);
2243 /* Returns the GOT offset at which the indicated address can be found.
2244 If there is not yet a GOT entry for this value, create one. If
2245 R_SYMNDX refers to a TLS symbol, create a TLS GOT entry instead.
2246 Returns -1 if no satisfactory GOT offset can be found. */
2249 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2250 bfd_vma value
, unsigned long r_symndx
,
2251 struct mips_elf_link_hash_entry
*h
, int r_type
)
2254 struct mips_got_info
*g
;
2255 struct mips_got_entry
*entry
;
2257 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
2259 entry
= mips_elf_create_local_got_entry (abfd
, ibfd
, g
, sgot
, value
,
2260 r_symndx
, h
, r_type
);
2264 if (TLS_RELOC_P (r_type
))
2265 return mips_tls_got_index (abfd
, entry
->gotidx
, &entry
->tls_type
, r_type
,
2268 return entry
->gotidx
;
2271 /* Returns the GOT index for the global symbol indicated by H. */
2274 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
,
2275 int r_type
, struct bfd_link_info
*info
)
2279 struct mips_got_info
*g
, *gg
;
2280 long global_got_dynindx
= 0;
2282 gg
= g
= mips_elf_got_info (abfd
, &sgot
);
2283 if (g
->bfd2got
&& ibfd
)
2285 struct mips_got_entry e
, *p
;
2287 BFD_ASSERT (h
->dynindx
>= 0);
2289 g
= mips_elf_got_for_ibfd (g
, ibfd
);
2290 if (g
->next
!= gg
|| TLS_RELOC_P (r_type
))
2294 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
2297 p
= htab_find (g
->got_entries
, &e
);
2299 BFD_ASSERT (p
->gotidx
> 0);
2301 if (TLS_RELOC_P (r_type
))
2303 bfd_vma value
= MINUS_ONE
;
2304 if ((h
->root
.type
== bfd_link_hash_defined
2305 || h
->root
.type
== bfd_link_hash_defweak
)
2306 && h
->root
.u
.def
.section
->output_section
)
2307 value
= (h
->root
.u
.def
.value
2308 + h
->root
.u
.def
.section
->output_offset
2309 + h
->root
.u
.def
.section
->output_section
->vma
);
2311 return mips_tls_got_index (abfd
, p
->gotidx
, &p
->tls_type
, r_type
,
2312 info
, e
.d
.h
, value
);
2319 if (gg
->global_gotsym
!= NULL
)
2320 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
2322 if (TLS_RELOC_P (r_type
))
2324 struct mips_elf_link_hash_entry
*hm
2325 = (struct mips_elf_link_hash_entry
*) h
;
2326 bfd_vma value
= MINUS_ONE
;
2328 if ((h
->root
.type
== bfd_link_hash_defined
2329 || h
->root
.type
== bfd_link_hash_defweak
)
2330 && h
->root
.u
.def
.section
->output_section
)
2331 value
= (h
->root
.u
.def
.value
2332 + h
->root
.u
.def
.section
->output_offset
2333 + h
->root
.u
.def
.section
->output_section
->vma
);
2335 index
= mips_tls_got_index (abfd
, hm
->tls_got_offset
, &hm
->tls_type
,
2336 r_type
, info
, hm
, value
);
2340 /* Once we determine the global GOT entry with the lowest dynamic
2341 symbol table index, we must put all dynamic symbols with greater
2342 indices into the GOT. That makes it easy to calculate the GOT
2344 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
2345 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
2346 * MIPS_ELF_GOT_SIZE (abfd
));
2348 BFD_ASSERT (index
< sgot
->size
);
2353 /* Find a GOT entry that is within 32KB of the VALUE. These entries
2354 are supposed to be placed at small offsets in the GOT, i.e.,
2355 within 32KB of GP. Return the index into the GOT for this page,
2356 and store the offset from this entry to the desired address in
2357 OFFSETP, if it is non-NULL. */
2360 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2361 bfd_vma value
, bfd_vma
*offsetp
)
2364 struct mips_got_info
*g
;
2366 struct mips_got_entry
*entry
;
2368 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
2370 entry
= mips_elf_create_local_got_entry (abfd
, ibfd
, g
, sgot
,
2372 & (~(bfd_vma
)0xffff), 0,
2373 NULL
, R_MIPS_GOT_PAGE
);
2378 index
= entry
->gotidx
;
2381 *offsetp
= value
- entry
->d
.address
;
2386 /* Find a GOT entry whose higher-order 16 bits are the same as those
2387 for value. Return the index into the GOT for this entry. */
2390 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
2391 bfd_vma value
, bfd_boolean external
)
2394 struct mips_got_info
*g
;
2395 struct mips_got_entry
*entry
;
2399 /* Although the ABI says that it is "the high-order 16 bits" that we
2400 want, it is really the %high value. The complete value is
2401 calculated with a `addiu' of a LO16 relocation, just as with a
2403 value
= mips_elf_high (value
) << 16;
2406 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
2408 entry
= mips_elf_create_local_got_entry (abfd
, ibfd
, g
, sgot
, value
, 0, NULL
,
2411 return entry
->gotidx
;
2416 /* Returns the offset for the entry at the INDEXth position
2420 mips_elf_got_offset_from_index (bfd
*dynobj
, bfd
*output_bfd
,
2421 bfd
*input_bfd
, bfd_vma index
)
2425 struct mips_got_info
*g
;
2427 g
= mips_elf_got_info (dynobj
, &sgot
);
2428 gp
= _bfd_get_gp_value (output_bfd
)
2429 + mips_elf_adjust_gp (output_bfd
, g
, input_bfd
);
2431 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
2434 /* Create a local GOT entry for VALUE. Return the index of the entry,
2435 or -1 if it could not be created. If R_SYMNDX refers to a TLS symbol,
2436 create a TLS entry instead. */
2438 static struct mips_got_entry
*
2439 mips_elf_create_local_got_entry (bfd
*abfd
, bfd
*ibfd
,
2440 struct mips_got_info
*gg
,
2441 asection
*sgot
, bfd_vma value
,
2442 unsigned long r_symndx
,
2443 struct mips_elf_link_hash_entry
*h
,
2446 struct mips_got_entry entry
, **loc
;
2447 struct mips_got_info
*g
;
2451 entry
.d
.address
= value
;
2454 g
= mips_elf_got_for_ibfd (gg
, ibfd
);
2457 g
= mips_elf_got_for_ibfd (gg
, abfd
);
2458 BFD_ASSERT (g
!= NULL
);
2461 /* We might have a symbol, H, if it has been forced local. Use the
2462 global entry then. It doesn't matter whether an entry is local
2463 or global for TLS, since the dynamic linker does not
2464 automatically relocate TLS GOT entries. */
2465 BFD_ASSERT (h
== NULL
|| h
->root
.forced_local
);
2466 if (TLS_RELOC_P (r_type
))
2468 struct mips_got_entry
*p
;
2471 if (r_type
== R_MIPS_TLS_LDM
)
2473 entry
.tls_type
= GOT_TLS_LDM
;
2479 entry
.symndx
= r_symndx
;
2485 p
= (struct mips_got_entry
*)
2486 htab_find (g
->got_entries
, &entry
);
2492 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
2497 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
2500 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2505 memcpy (*loc
, &entry
, sizeof entry
);
2507 if (g
->assigned_gotno
>= g
->local_gotno
)
2509 (*loc
)->gotidx
= -1;
2510 /* We didn't allocate enough space in the GOT. */
2511 (*_bfd_error_handler
)
2512 (_("not enough GOT space for local GOT entries"));
2513 bfd_set_error (bfd_error_bad_value
);
2517 MIPS_ELF_PUT_WORD (abfd
, value
,
2518 (sgot
->contents
+ entry
.gotidx
));
2523 /* Sort the dynamic symbol table so that symbols that need GOT entries
2524 appear towards the end. This reduces the amount of GOT space
2525 required. MAX_LOCAL is used to set the number of local symbols
2526 known to be in the dynamic symbol table. During
2527 _bfd_mips_elf_size_dynamic_sections, this value is 1. Afterward, the
2528 section symbols are added and the count is higher. */
2531 mips_elf_sort_hash_table (struct bfd_link_info
*info
, unsigned long max_local
)
2533 struct mips_elf_hash_sort_data hsd
;
2534 struct mips_got_info
*g
;
2537 dynobj
= elf_hash_table (info
)->dynobj
;
2539 g
= mips_elf_got_info (dynobj
, NULL
);
2542 hsd
.max_unref_got_dynindx
=
2543 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
2544 /* In the multi-got case, assigned_gotno of the master got_info
2545 indicate the number of entries that aren't referenced in the
2546 primary GOT, but that must have entries because there are
2547 dynamic relocations that reference it. Since they aren't
2548 referenced, we move them to the end of the GOT, so that they
2549 don't prevent other entries that are referenced from getting
2550 too large offsets. */
2551 - (g
->next
? g
->assigned_gotno
: 0);
2552 hsd
.max_non_got_dynindx
= max_local
;
2553 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
2554 elf_hash_table (info
)),
2555 mips_elf_sort_hash_table_f
,
2558 /* There should have been enough room in the symbol table to
2559 accommodate both the GOT and non-GOT symbols. */
2560 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
2561 BFD_ASSERT ((unsigned long)hsd
.max_unref_got_dynindx
2562 <= elf_hash_table (info
)->dynsymcount
);
2564 /* Now we know which dynamic symbol has the lowest dynamic symbol
2565 table index in the GOT. */
2566 g
->global_gotsym
= hsd
.low
;
2571 /* If H needs a GOT entry, assign it the highest available dynamic
2572 index. Otherwise, assign it the lowest available dynamic
2576 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
2578 struct mips_elf_hash_sort_data
*hsd
= data
;
2580 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2581 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2583 /* Symbols without dynamic symbol table entries aren't interesting
2585 if (h
->root
.dynindx
== -1)
2588 /* Global symbols that need GOT entries that are not explicitly
2589 referenced are marked with got offset 2. Those that are
2590 referenced get a 1, and those that don't need GOT entries get
2592 if (h
->root
.got
.offset
== 2)
2594 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
2596 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
2597 hsd
->low
= (struct elf_link_hash_entry
*) h
;
2598 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
2600 else if (h
->root
.got
.offset
!= 1)
2601 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
2604 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
2606 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
2607 hsd
->low
= (struct elf_link_hash_entry
*) h
;
2613 /* If H is a symbol that needs a global GOT entry, but has a dynamic
2614 symbol table index lower than any we've seen to date, record it for
2618 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
2619 bfd
*abfd
, struct bfd_link_info
*info
,
2620 struct mips_got_info
*g
,
2621 unsigned char tls_flag
)
2623 struct mips_got_entry entry
, **loc
;
2625 /* A global symbol in the GOT must also be in the dynamic symbol
2627 if (h
->dynindx
== -1)
2629 switch (ELF_ST_VISIBILITY (h
->other
))
2633 _bfd_mips_elf_hide_symbol (info
, h
, TRUE
);
2636 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
2642 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
2645 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
2648 /* If we've already marked this entry as needing GOT space, we don't
2649 need to do it again. */
2652 (*loc
)->tls_type
|= tls_flag
;
2656 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2662 entry
.tls_type
= tls_flag
;
2664 memcpy (*loc
, &entry
, sizeof entry
);
2666 if (h
->got
.offset
!= MINUS_ONE
)
2669 /* By setting this to a value other than -1, we are indicating that
2670 there needs to be a GOT entry for H. Avoid using zero, as the
2671 generic ELF copy_indirect_symbol tests for <= 0. */
2678 /* Reserve space in G for a GOT entry containing the value of symbol
2679 SYMNDX in input bfd ABDF, plus ADDEND. */
2682 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
2683 struct mips_got_info
*g
,
2684 unsigned char tls_flag
)
2686 struct mips_got_entry entry
, **loc
;
2689 entry
.symndx
= symndx
;
2690 entry
.d
.addend
= addend
;
2691 entry
.tls_type
= tls_flag
;
2692 loc
= (struct mips_got_entry
**)
2693 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
2697 if (tls_flag
== GOT_TLS_GD
&& !((*loc
)->tls_type
& GOT_TLS_GD
))
2700 (*loc
)->tls_type
|= tls_flag
;
2702 else if (tls_flag
== GOT_TLS_IE
&& !((*loc
)->tls_type
& GOT_TLS_IE
))
2705 (*loc
)->tls_type
|= tls_flag
;
2713 entry
.tls_type
= tls_flag
;
2714 if (tls_flag
== GOT_TLS_IE
)
2716 else if (tls_flag
== GOT_TLS_GD
)
2718 else if (g
->tls_ldm_offset
== MINUS_ONE
)
2720 g
->tls_ldm_offset
= MINUS_TWO
;
2726 entry
.gotidx
= g
->local_gotno
++;
2730 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2735 memcpy (*loc
, &entry
, sizeof entry
);
2740 /* Compute the hash value of the bfd in a bfd2got hash entry. */
2743 mips_elf_bfd2got_entry_hash (const void *entry_
)
2745 const struct mips_elf_bfd2got_hash
*entry
2746 = (struct mips_elf_bfd2got_hash
*)entry_
;
2748 return entry
->bfd
->id
;
2751 /* Check whether two hash entries have the same bfd. */
2754 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
2756 const struct mips_elf_bfd2got_hash
*e1
2757 = (const struct mips_elf_bfd2got_hash
*)entry1
;
2758 const struct mips_elf_bfd2got_hash
*e2
2759 = (const struct mips_elf_bfd2got_hash
*)entry2
;
2761 return e1
->bfd
== e2
->bfd
;
2764 /* In a multi-got link, determine the GOT to be used for IBFD. G must
2765 be the master GOT data. */
2767 static struct mips_got_info
*
2768 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
2770 struct mips_elf_bfd2got_hash e
, *p
;
2776 p
= htab_find (g
->bfd2got
, &e
);
2777 return p
? p
->g
: NULL
;
2780 /* Create one separate got for each bfd that has entries in the global
2781 got, such that we can tell how many local and global entries each
2785 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
2787 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
2788 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
2789 htab_t bfd2got
= arg
->bfd2got
;
2790 struct mips_got_info
*g
;
2791 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
2794 /* Find the got_info for this GOT entry's input bfd. Create one if
2796 bfdgot_entry
.bfd
= entry
->abfd
;
2797 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
2798 bfdgot
= (struct mips_elf_bfd2got_hash
*)*bfdgotp
;
2804 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
2805 (arg
->obfd
, sizeof (struct mips_elf_bfd2got_hash
));
2815 bfdgot
->bfd
= entry
->abfd
;
2816 bfdgot
->g
= g
= (struct mips_got_info
*)
2817 bfd_alloc (arg
->obfd
, sizeof (struct mips_got_info
));
2824 g
->global_gotsym
= NULL
;
2825 g
->global_gotno
= 0;
2827 g
->assigned_gotno
= -1;
2829 g
->tls_assigned_gotno
= 0;
2830 g
->tls_ldm_offset
= MINUS_ONE
;
2831 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
2832 mips_elf_multi_got_entry_eq
, NULL
);
2833 if (g
->got_entries
== NULL
)
2843 /* Insert the GOT entry in the bfd's got entry hash table. */
2844 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
2845 if (*entryp
!= NULL
)
2850 if (entry
->tls_type
)
2852 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
2854 if (entry
->tls_type
& GOT_TLS_IE
)
2857 else if (entry
->symndx
>= 0 || entry
->d
.h
->forced_local
)
2865 /* Attempt to merge gots of different input bfds. Try to use as much
2866 as possible of the primary got, since it doesn't require explicit
2867 dynamic relocations, but don't use bfds that would reference global
2868 symbols out of the addressable range. Failing the primary got,
2869 attempt to merge with the current got, or finish the current got
2870 and then make make the new got current. */
2873 mips_elf_merge_gots (void **bfd2got_
, void *p
)
2875 struct mips_elf_bfd2got_hash
*bfd2got
2876 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
2877 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
2878 unsigned int lcount
= bfd2got
->g
->local_gotno
;
2879 unsigned int gcount
= bfd2got
->g
->global_gotno
;
2880 unsigned int tcount
= bfd2got
->g
->tls_gotno
;
2881 unsigned int maxcnt
= arg
->max_count
;
2882 bfd_boolean too_many_for_tls
= FALSE
;
2884 /* We place TLS GOT entries after both locals and globals. The globals
2885 for the primary GOT may overflow the normal GOT size limit, so be
2886 sure not to merge a GOT which requires TLS with the primary GOT in that
2887 case. This doesn't affect non-primary GOTs. */
2890 unsigned int primary_total
= lcount
+ tcount
+ arg
->global_count
;
2891 if (primary_total
* MIPS_ELF_GOT_SIZE (bfd2got
->bfd
)
2892 >= MIPS_ELF_GOT_MAX_SIZE (bfd2got
->bfd
))
2893 too_many_for_tls
= TRUE
;
2896 /* If we don't have a primary GOT and this is not too big, use it as
2897 a starting point for the primary GOT. */
2898 if (! arg
->primary
&& lcount
+ gcount
+ tcount
<= maxcnt
2899 && ! too_many_for_tls
)
2901 arg
->primary
= bfd2got
->g
;
2902 arg
->primary_count
= lcount
+ gcount
;
2904 /* If it looks like we can merge this bfd's entries with those of
2905 the primary, merge them. The heuristics is conservative, but we
2906 don't have to squeeze it too hard. */
2907 else if (arg
->primary
&& ! too_many_for_tls
2908 && (arg
->primary_count
+ lcount
+ gcount
+ tcount
) <= maxcnt
)
2910 struct mips_got_info
*g
= bfd2got
->g
;
2911 int old_lcount
= arg
->primary
->local_gotno
;
2912 int old_gcount
= arg
->primary
->global_gotno
;
2913 int old_tcount
= arg
->primary
->tls_gotno
;
2915 bfd2got
->g
= arg
->primary
;
2917 htab_traverse (g
->got_entries
,
2918 mips_elf_make_got_per_bfd
,
2920 if (arg
->obfd
== NULL
)
2923 htab_delete (g
->got_entries
);
2924 /* We don't have to worry about releasing memory of the actual
2925 got entries, since they're all in the master got_entries hash
2928 BFD_ASSERT (old_lcount
+ lcount
>= arg
->primary
->local_gotno
);
2929 BFD_ASSERT (old_gcount
+ gcount
>= arg
->primary
->global_gotno
);
2930 BFD_ASSERT (old_tcount
+ tcount
>= arg
->primary
->tls_gotno
);
2932 arg
->primary_count
= arg
->primary
->local_gotno
2933 + arg
->primary
->global_gotno
+ arg
->primary
->tls_gotno
;
2935 /* If we can merge with the last-created got, do it. */
2936 else if (arg
->current
2937 && arg
->current_count
+ lcount
+ gcount
+ tcount
<= maxcnt
)
2939 struct mips_got_info
*g
= bfd2got
->g
;
2940 int old_lcount
= arg
->current
->local_gotno
;
2941 int old_gcount
= arg
->current
->global_gotno
;
2942 int old_tcount
= arg
->current
->tls_gotno
;
2944 bfd2got
->g
= arg
->current
;
2946 htab_traverse (g
->got_entries
,
2947 mips_elf_make_got_per_bfd
,
2949 if (arg
->obfd
== NULL
)
2952 htab_delete (g
->got_entries
);
2954 BFD_ASSERT (old_lcount
+ lcount
>= arg
->current
->local_gotno
);
2955 BFD_ASSERT (old_gcount
+ gcount
>= arg
->current
->global_gotno
);
2956 BFD_ASSERT (old_tcount
+ tcount
>= arg
->current
->tls_gotno
);
2958 arg
->current_count
= arg
->current
->local_gotno
2959 + arg
->current
->global_gotno
+ arg
->current
->tls_gotno
;
2961 /* Well, we couldn't merge, so create a new GOT. Don't check if it
2962 fits; if it turns out that it doesn't, we'll get relocation
2963 overflows anyway. */
2966 bfd2got
->g
->next
= arg
->current
;
2967 arg
->current
= bfd2got
->g
;
2969 arg
->current_count
= lcount
+ gcount
+ 2 * tcount
;
2975 /* Set the TLS GOT index for the GOT entry in ENTRYP. */
2978 mips_elf_initialize_tls_index (void **entryp
, void *p
)
2980 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
2981 struct mips_got_info
*g
= p
;
2983 /* We're only interested in TLS symbols. */
2984 if (entry
->tls_type
== 0)
2987 if (entry
->symndx
== -1)
2989 /* There may be multiple mips_got_entry structs for a global variable
2990 if there is just one GOT. Just do this once. */
2991 if (g
->next
== NULL
)
2993 if (entry
->d
.h
->tls_type
& GOT_TLS_OFFSET_DONE
)
2995 entry
->d
.h
->tls_type
|= GOT_TLS_OFFSET_DONE
;
2998 else if (entry
->tls_type
& GOT_TLS_LDM
)
3000 /* Similarly, there may be multiple structs for the LDM entry. */
3001 if (g
->tls_ldm_offset
!= MINUS_TWO
&& g
->tls_ldm_offset
!= MINUS_ONE
)
3003 entry
->gotidx
= g
->tls_ldm_offset
;
3008 /* Initialize the GOT offset. */
3009 entry
->gotidx
= MIPS_ELF_GOT_SIZE (entry
->abfd
) * (long) g
->tls_assigned_gotno
;
3010 if (g
->next
== NULL
&& entry
->symndx
== -1)
3011 entry
->d
.h
->tls_got_offset
= entry
->gotidx
;
3013 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3014 g
->tls_assigned_gotno
+= 2;
3015 if (entry
->tls_type
& GOT_TLS_IE
)
3016 g
->tls_assigned_gotno
+= 1;
3018 if (entry
->tls_type
& GOT_TLS_LDM
)
3019 g
->tls_ldm_offset
= entry
->gotidx
;
3024 /* If passed a NULL mips_got_info in the argument, set the marker used
3025 to tell whether a global symbol needs a got entry (in the primary
3026 got) to the given VALUE.
3028 If passed a pointer G to a mips_got_info in the argument (it must
3029 not be the primary GOT), compute the offset from the beginning of
3030 the (primary) GOT section to the entry in G corresponding to the
3031 global symbol. G's assigned_gotno must contain the index of the
3032 first available global GOT entry in G. VALUE must contain the size
3033 of a GOT entry in bytes. For each global GOT entry that requires a
3034 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
3035 marked as not eligible for lazy resolution through a function
3038 mips_elf_set_global_got_offset (void **entryp
, void *p
)
3040 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3041 struct mips_elf_set_global_got_offset_arg
*arg
3042 = (struct mips_elf_set_global_got_offset_arg
*)p
;
3043 struct mips_got_info
*g
= arg
->g
;
3045 if (g
&& entry
->tls_type
!= GOT_NORMAL
)
3046 arg
->needed_relocs
+=
3047 mips_tls_got_relocs (arg
->info
, entry
->tls_type
,
3048 entry
->symndx
== -1 ? &entry
->d
.h
->root
: NULL
);
3050 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1
3051 && entry
->d
.h
->root
.dynindx
!= -1
3052 && entry
->d
.h
->tls_type
== GOT_NORMAL
)
3056 BFD_ASSERT (g
->global_gotsym
== NULL
);
3058 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
3059 if (arg
->info
->shared
3060 || (elf_hash_table (arg
->info
)->dynamic_sections_created
3061 && entry
->d
.h
->root
.def_dynamic
3062 && !entry
->d
.h
->root
.def_regular
))
3063 ++arg
->needed_relocs
;
3066 entry
->d
.h
->root
.got
.offset
= arg
->value
;
3072 /* Mark any global symbols referenced in the GOT we are iterating over
3073 as inelligible for lazy resolution stubs. */
3075 mips_elf_set_no_stub (void **entryp
, void *p ATTRIBUTE_UNUSED
)
3077 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3079 if (entry
->abfd
!= NULL
3080 && entry
->symndx
== -1
3081 && entry
->d
.h
->root
.dynindx
!= -1)
3082 entry
->d
.h
->no_fn_stub
= TRUE
;
3087 /* Follow indirect and warning hash entries so that each got entry
3088 points to the final symbol definition. P must point to a pointer
3089 to the hash table we're traversing. Since this traversal may
3090 modify the hash table, we set this pointer to NULL to indicate
3091 we've made a potentially-destructive change to the hash table, so
3092 the traversal must be restarted. */
3094 mips_elf_resolve_final_got_entry (void **entryp
, void *p
)
3096 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3097 htab_t got_entries
= *(htab_t
*)p
;
3099 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3101 struct mips_elf_link_hash_entry
*h
= entry
->d
.h
;
3103 while (h
->root
.root
.type
== bfd_link_hash_indirect
3104 || h
->root
.root
.type
== bfd_link_hash_warning
)
3105 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3107 if (entry
->d
.h
== h
)
3112 /* If we can't find this entry with the new bfd hash, re-insert
3113 it, and get the traversal restarted. */
3114 if (! htab_find (got_entries
, entry
))
3116 htab_clear_slot (got_entries
, entryp
);
3117 entryp
= htab_find_slot (got_entries
, entry
, INSERT
);
3120 /* Abort the traversal, since the whole table may have
3121 moved, and leave it up to the parent to restart the
3123 *(htab_t
*)p
= NULL
;
3126 /* We might want to decrement the global_gotno count, but it's
3127 either too early or too late for that at this point. */
3133 /* Turn indirect got entries in a got_entries table into their final
3136 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
3142 got_entries
= g
->got_entries
;
3144 htab_traverse (got_entries
,
3145 mips_elf_resolve_final_got_entry
,
3148 while (got_entries
== NULL
);
3151 /* Return the offset of an input bfd IBFD's GOT from the beginning of
3154 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
3156 if (g
->bfd2got
== NULL
)
3159 g
= mips_elf_got_for_ibfd (g
, ibfd
);
3163 BFD_ASSERT (g
->next
);
3167 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
3168 * MIPS_ELF_GOT_SIZE (abfd
);
3171 /* Turn a single GOT that is too big for 16-bit addressing into
3172 a sequence of GOTs, each one 16-bit addressable. */
3175 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
3176 struct mips_got_info
*g
, asection
*got
,
3177 bfd_size_type pages
)
3179 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
3180 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
3181 struct mips_got_info
*gg
;
3182 unsigned int assign
;
3184 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
3185 mips_elf_bfd2got_entry_eq
, NULL
);
3186 if (g
->bfd2got
== NULL
)
3189 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
3190 got_per_bfd_arg
.obfd
= abfd
;
3191 got_per_bfd_arg
.info
= info
;
3193 /* Count how many GOT entries each input bfd requires, creating a
3194 map from bfd to got info while at that. */
3195 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
3196 if (got_per_bfd_arg
.obfd
== NULL
)
3199 got_per_bfd_arg
.current
= NULL
;
3200 got_per_bfd_arg
.primary
= NULL
;
3201 /* Taking out PAGES entries is a worst-case estimate. We could
3202 compute the maximum number of pages that each separate input bfd
3203 uses, but it's probably not worth it. */
3204 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (abfd
)
3205 / MIPS_ELF_GOT_SIZE (abfd
))
3206 - MIPS_RESERVED_GOTNO
- pages
);
3207 /* The number of globals that will be included in the primary GOT.
3208 See the calls to mips_elf_set_global_got_offset below for more
3210 got_per_bfd_arg
.global_count
= g
->global_gotno
;
3212 /* Try to merge the GOTs of input bfds together, as long as they
3213 don't seem to exceed the maximum GOT size, choosing one of them
3214 to be the primary GOT. */
3215 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
3216 if (got_per_bfd_arg
.obfd
== NULL
)
3219 /* If we do not find any suitable primary GOT, create an empty one. */
3220 if (got_per_bfd_arg
.primary
== NULL
)
3222 g
->next
= (struct mips_got_info
*)
3223 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
3224 if (g
->next
== NULL
)
3227 g
->next
->global_gotsym
= NULL
;
3228 g
->next
->global_gotno
= 0;
3229 g
->next
->local_gotno
= 0;
3230 g
->next
->tls_gotno
= 0;
3231 g
->next
->assigned_gotno
= 0;
3232 g
->next
->tls_assigned_gotno
= 0;
3233 g
->next
->tls_ldm_offset
= MINUS_ONE
;
3234 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3235 mips_elf_multi_got_entry_eq
,
3237 if (g
->next
->got_entries
== NULL
)
3239 g
->next
->bfd2got
= NULL
;
3242 g
->next
= got_per_bfd_arg
.primary
;
3243 g
->next
->next
= got_per_bfd_arg
.current
;
3245 /* GG is now the master GOT, and G is the primary GOT. */
3249 /* Map the output bfd to the primary got. That's what we're going
3250 to use for bfds that use GOT16 or GOT_PAGE relocations that we
3251 didn't mark in check_relocs, and we want a quick way to find it.
3252 We can't just use gg->next because we're going to reverse the
3255 struct mips_elf_bfd2got_hash
*bfdgot
;
3258 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
3259 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
3266 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
3268 BFD_ASSERT (*bfdgotp
== NULL
);
3272 /* The IRIX dynamic linker requires every symbol that is referenced
3273 in a dynamic relocation to be present in the primary GOT, so
3274 arrange for them to appear after those that are actually
3277 GNU/Linux could very well do without it, but it would slow down
3278 the dynamic linker, since it would have to resolve every dynamic
3279 symbol referenced in other GOTs more than once, without help from
3280 the cache. Also, knowing that every external symbol has a GOT
3281 helps speed up the resolution of local symbols too, so GNU/Linux
3282 follows IRIX's practice.
3284 The number 2 is used by mips_elf_sort_hash_table_f to count
3285 global GOT symbols that are unreferenced in the primary GOT, with
3286 an initial dynamic index computed from gg->assigned_gotno, where
3287 the number of unreferenced global entries in the primary GOT is
3291 gg
->assigned_gotno
= gg
->global_gotno
- g
->global_gotno
;
3292 g
->global_gotno
= gg
->global_gotno
;
3293 set_got_offset_arg
.value
= 2;
3297 /* This could be used for dynamic linkers that don't optimize
3298 symbol resolution while applying relocations so as to use
3299 primary GOT entries or assuming the symbol is locally-defined.
3300 With this code, we assign lower dynamic indices to global
3301 symbols that are not referenced in the primary GOT, so that
3302 their entries can be omitted. */
3303 gg
->assigned_gotno
= 0;
3304 set_got_offset_arg
.value
= -1;
3307 /* Reorder dynamic symbols as described above (which behavior
3308 depends on the setting of VALUE). */
3309 set_got_offset_arg
.g
= NULL
;
3310 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
3311 &set_got_offset_arg
);
3312 set_got_offset_arg
.value
= 1;
3313 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
3314 &set_got_offset_arg
);
3315 if (! mips_elf_sort_hash_table (info
, 1))
3318 /* Now go through the GOTs assigning them offset ranges.
3319 [assigned_gotno, local_gotno[ will be set to the range of local
3320 entries in each GOT. We can then compute the end of a GOT by
3321 adding local_gotno to global_gotno. We reverse the list and make
3322 it circular since then we'll be able to quickly compute the
3323 beginning of a GOT, by computing the end of its predecessor. To
3324 avoid special cases for the primary GOT, while still preserving
3325 assertions that are valid for both single- and multi-got links,
3326 we arrange for the main got struct to have the right number of
3327 global entries, but set its local_gotno such that the initial
3328 offset of the primary GOT is zero. Remember that the primary GOT
3329 will become the last item in the circular linked list, so it
3330 points back to the master GOT. */
3331 gg
->local_gotno
= -g
->global_gotno
;
3332 gg
->global_gotno
= g
->global_gotno
;
3339 struct mips_got_info
*gn
;
3341 assign
+= MIPS_RESERVED_GOTNO
;
3342 g
->assigned_gotno
= assign
;
3343 g
->local_gotno
+= assign
+ pages
;
3344 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
3346 /* Set up any TLS entries. We always place the TLS entries after
3347 all non-TLS entries. */
3348 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
3349 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
3351 /* Take g out of the direct list, and push it onto the reversed
3352 list that gg points to. */
3358 /* Mark global symbols in every non-primary GOT as ineligible for
3361 htab_traverse (g
->got_entries
, mips_elf_set_no_stub
, NULL
);
3365 got
->size
= (gg
->next
->local_gotno
3366 + gg
->next
->global_gotno
3367 + gg
->next
->tls_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
3373 /* Returns the first relocation of type r_type found, beginning with
3374 RELOCATION. RELEND is one-past-the-end of the relocation table. */
3376 static const Elf_Internal_Rela
*
3377 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
3378 const Elf_Internal_Rela
*relocation
,
3379 const Elf_Internal_Rela
*relend
)
3381 while (relocation
< relend
)
3383 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
)
3389 /* We didn't find it. */
3390 bfd_set_error (bfd_error_bad_value
);
3394 /* Return whether a relocation is against a local symbol. */
3397 mips_elf_local_relocation_p (bfd
*input_bfd
,
3398 const Elf_Internal_Rela
*relocation
,
3399 asection
**local_sections
,
3400 bfd_boolean check_forced
)
3402 unsigned long r_symndx
;
3403 Elf_Internal_Shdr
*symtab_hdr
;
3404 struct mips_elf_link_hash_entry
*h
;
3407 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
3408 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3409 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
3411 if (r_symndx
< extsymoff
)
3413 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
3418 /* Look up the hash table to check whether the symbol
3419 was forced local. */
3420 h
= (struct mips_elf_link_hash_entry
*)
3421 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
3422 /* Find the real hash-table entry for this symbol. */
3423 while (h
->root
.root
.type
== bfd_link_hash_indirect
3424 || h
->root
.root
.type
== bfd_link_hash_warning
)
3425 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3426 if (h
->root
.forced_local
)
3433 /* Sign-extend VALUE, which has the indicated number of BITS. */
3436 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
3438 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
3439 /* VALUE is negative. */
3440 value
|= ((bfd_vma
) - 1) << bits
;
3445 /* Return non-zero if the indicated VALUE has overflowed the maximum
3446 range expressible by a signed number with the indicated number of
3450 mips_elf_overflow_p (bfd_vma value
, int bits
)
3452 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
3454 if (svalue
> (1 << (bits
- 1)) - 1)
3455 /* The value is too big. */
3457 else if (svalue
< -(1 << (bits
- 1)))
3458 /* The value is too small. */
3465 /* Calculate the %high function. */
3468 mips_elf_high (bfd_vma value
)
3470 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
3473 /* Calculate the %higher function. */
3476 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
3479 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
3486 /* Calculate the %highest function. */
3489 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
3492 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
3499 /* Create the .compact_rel section. */
3502 mips_elf_create_compact_rel_section
3503 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3506 register asection
*s
;
3508 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
3510 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
3513 s
= bfd_make_section_with_flags (abfd
, ".compact_rel", flags
);
3515 || ! bfd_set_section_alignment (abfd
, s
,
3516 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
3519 s
->size
= sizeof (Elf32_External_compact_rel
);
3525 /* Create the .got section to hold the global offset table. */
3528 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
,
3529 bfd_boolean maybe_exclude
)
3532 register asection
*s
;
3533 struct elf_link_hash_entry
*h
;
3534 struct bfd_link_hash_entry
*bh
;
3535 struct mips_got_info
*g
;
3538 /* This function may be called more than once. */
3539 s
= mips_elf_got_section (abfd
, TRUE
);
3542 if (! maybe_exclude
)
3543 s
->flags
&= ~SEC_EXCLUDE
;
3547 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3548 | SEC_LINKER_CREATED
);
3551 flags
|= SEC_EXCLUDE
;
3553 /* We have to use an alignment of 2**4 here because this is hardcoded
3554 in the function stub generation and in the linker script. */
3555 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
3557 || ! bfd_set_section_alignment (abfd
, s
, 4))
3560 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
3561 linker script because we don't want to define the symbol if we
3562 are not creating a global offset table. */
3564 if (! (_bfd_generic_link_add_one_symbol
3565 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
3566 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
3569 h
= (struct elf_link_hash_entry
*) bh
;
3572 h
->type
= STT_OBJECT
;
3575 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3578 amt
= sizeof (struct mips_got_info
);
3579 g
= bfd_alloc (abfd
, amt
);
3582 g
->global_gotsym
= NULL
;
3583 g
->global_gotno
= 0;
3585 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
3586 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
3589 g
->tls_ldm_offset
= MINUS_ONE
;
3590 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
3591 mips_elf_got_entry_eq
, NULL
);
3592 if (g
->got_entries
== NULL
)
3594 mips_elf_section_data (s
)->u
.got_info
= g
;
3595 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
3596 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3601 /* Calculate the value produced by the RELOCATION (which comes from
3602 the INPUT_BFD). The ADDEND is the addend to use for this
3603 RELOCATION; RELOCATION->R_ADDEND is ignored.
3605 The result of the relocation calculation is stored in VALUEP.
3606 REQUIRE_JALXP indicates whether or not the opcode used with this
3607 relocation must be JALX.
3609 This function returns bfd_reloc_continue if the caller need take no
3610 further action regarding this relocation, bfd_reloc_notsupported if
3611 something goes dramatically wrong, bfd_reloc_overflow if an
3612 overflow occurs, and bfd_reloc_ok to indicate success. */
3614 static bfd_reloc_status_type
3615 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
3616 asection
*input_section
,
3617 struct bfd_link_info
*info
,
3618 const Elf_Internal_Rela
*relocation
,
3619 bfd_vma addend
, reloc_howto_type
*howto
,
3620 Elf_Internal_Sym
*local_syms
,
3621 asection
**local_sections
, bfd_vma
*valuep
,
3622 const char **namep
, bfd_boolean
*require_jalxp
,
3623 bfd_boolean save_addend
)
3625 /* The eventual value we will return. */
3627 /* The address of the symbol against which the relocation is
3630 /* The final GP value to be used for the relocatable, executable, or
3631 shared object file being produced. */
3632 bfd_vma gp
= MINUS_ONE
;
3633 /* The place (section offset or address) of the storage unit being
3636 /* The value of GP used to create the relocatable object. */
3637 bfd_vma gp0
= MINUS_ONE
;
3638 /* The offset into the global offset table at which the address of
3639 the relocation entry symbol, adjusted by the addend, resides
3640 during execution. */
3641 bfd_vma g
= MINUS_ONE
;
3642 /* The section in which the symbol referenced by the relocation is
3644 asection
*sec
= NULL
;
3645 struct mips_elf_link_hash_entry
*h
= NULL
;
3646 /* TRUE if the symbol referred to by this relocation is a local
3648 bfd_boolean local_p
, was_local_p
;
3649 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
3650 bfd_boolean gp_disp_p
= FALSE
;
3651 /* TRUE if the symbol referred to by this relocation is
3652 "__gnu_local_gp". */
3653 bfd_boolean gnu_local_gp_p
= FALSE
;
3654 Elf_Internal_Shdr
*symtab_hdr
;
3656 unsigned long r_symndx
;
3658 /* TRUE if overflow occurred during the calculation of the
3659 relocation value. */
3660 bfd_boolean overflowed_p
;
3661 /* TRUE if this relocation refers to a MIPS16 function. */
3662 bfd_boolean target_is_16_bit_code_p
= FALSE
;
3664 /* Parse the relocation. */
3665 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
3666 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
3667 p
= (input_section
->output_section
->vma
3668 + input_section
->output_offset
3669 + relocation
->r_offset
);
3671 /* Assume that there will be no overflow. */
3672 overflowed_p
= FALSE
;
3674 /* Figure out whether or not the symbol is local, and get the offset
3675 used in the array of hash table entries. */
3676 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3677 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
3678 local_sections
, FALSE
);
3679 was_local_p
= local_p
;
3680 if (! elf_bad_symtab (input_bfd
))
3681 extsymoff
= symtab_hdr
->sh_info
;
3684 /* The symbol table does not follow the rule that local symbols
3685 must come before globals. */
3689 /* Figure out the value of the symbol. */
3692 Elf_Internal_Sym
*sym
;
3694 sym
= local_syms
+ r_symndx
;
3695 sec
= local_sections
[r_symndx
];
3697 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
3698 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
3699 || (sec
->flags
& SEC_MERGE
))
3700 symbol
+= sym
->st_value
;
3701 if ((sec
->flags
& SEC_MERGE
)
3702 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3704 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
3706 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
3709 /* MIPS16 text labels should be treated as odd. */
3710 if (sym
->st_other
== STO_MIPS16
)
3713 /* Record the name of this symbol, for our caller. */
3714 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
3715 symtab_hdr
->sh_link
,
3718 *namep
= bfd_section_name (input_bfd
, sec
);
3720 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
3724 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
3726 /* For global symbols we look up the symbol in the hash-table. */
3727 h
= ((struct mips_elf_link_hash_entry
*)
3728 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
3729 /* Find the real hash-table entry for this symbol. */
3730 while (h
->root
.root
.type
== bfd_link_hash_indirect
3731 || h
->root
.root
.type
== bfd_link_hash_warning
)
3732 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3734 /* Record the name of this symbol, for our caller. */
3735 *namep
= h
->root
.root
.root
.string
;
3737 /* See if this is the special _gp_disp symbol. Note that such a
3738 symbol must always be a global symbol. */
3739 if (strcmp (*namep
, "_gp_disp") == 0
3740 && ! NEWABI_P (input_bfd
))
3742 /* Relocations against _gp_disp are permitted only with
3743 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
3744 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
3745 && r_type
!= R_MIPS16_HI16
&& r_type
!= R_MIPS16_LO16
)
3746 return bfd_reloc_notsupported
;
3750 /* See if this is the special _gp symbol. Note that such a
3751 symbol must always be a global symbol. */
3752 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
3753 gnu_local_gp_p
= TRUE
;
3756 /* If this symbol is defined, calculate its address. Note that
3757 _gp_disp is a magic symbol, always implicitly defined by the
3758 linker, so it's inappropriate to check to see whether or not
3760 else if ((h
->root
.root
.type
== bfd_link_hash_defined
3761 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3762 && h
->root
.root
.u
.def
.section
)
3764 sec
= h
->root
.root
.u
.def
.section
;
3765 if (sec
->output_section
)
3766 symbol
= (h
->root
.root
.u
.def
.value
3767 + sec
->output_section
->vma
3768 + sec
->output_offset
);
3770 symbol
= h
->root
.root
.u
.def
.value
;
3772 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
3773 /* We allow relocations against undefined weak symbols, giving
3774 it the value zero, so that you can undefined weak functions
3775 and check to see if they exist by looking at their
3778 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
3779 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
3781 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
3782 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
3784 /* If this is a dynamic link, we should have created a
3785 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
3786 in in _bfd_mips_elf_create_dynamic_sections.
3787 Otherwise, we should define the symbol with a value of 0.
3788 FIXME: It should probably get into the symbol table
3790 BFD_ASSERT (! info
->shared
);
3791 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
3794 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
3796 /* This is an optional symbol - an Irix specific extension to the
3797 ELF spec. Ignore it for now.
3798 XXX - FIXME - there is more to the spec for OPTIONAL symbols
3799 than simply ignoring them, but we do not handle this for now.
3800 For information see the "64-bit ELF Object File Specification"
3801 which is available from here:
3802 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
3807 if (! ((*info
->callbacks
->undefined_symbol
)
3808 (info
, h
->root
.root
.root
.string
, input_bfd
,
3809 input_section
, relocation
->r_offset
,
3810 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
3811 || ELF_ST_VISIBILITY (h
->root
.other
))))
3812 return bfd_reloc_undefined
;
3816 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
3819 /* If this is a 32- or 64-bit call to a 16-bit function with a stub, we
3820 need to redirect the call to the stub, unless we're already *in*
3822 if (r_type
!= R_MIPS16_26
&& !info
->relocatable
3823 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
3824 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
3825 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
3826 && !mips_elf_stub_section_p (input_bfd
, input_section
))
3828 /* This is a 32- or 64-bit call to a 16-bit function. We should
3829 have already noticed that we were going to need the
3832 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
3835 BFD_ASSERT (h
->need_fn_stub
);
3839 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
3841 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
3842 need to redirect the call to the stub. */
3843 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
3845 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
3846 && !target_is_16_bit_code_p
)
3848 /* If both call_stub and call_fp_stub are defined, we can figure
3849 out which one to use by seeing which one appears in the input
3851 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
3856 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
3858 if (strncmp (bfd_get_section_name (input_bfd
, o
),
3859 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
3861 sec
= h
->call_fp_stub
;
3868 else if (h
->call_stub
!= NULL
)
3871 sec
= h
->call_fp_stub
;
3873 BFD_ASSERT (sec
->size
> 0);
3874 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
3877 /* Calls from 16-bit code to 32-bit code and vice versa require the
3878 special jalx instruction. */
3879 *require_jalxp
= (!info
->relocatable
3880 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
3881 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
3883 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
3884 local_sections
, TRUE
);
3886 /* If we haven't already determined the GOT offset, or the GP value,
3887 and we're going to need it, get it now. */
3890 case R_MIPS_GOT_PAGE
:
3891 case R_MIPS_GOT_OFST
:
3892 /* We need to decay to GOT_DISP/addend if the symbol doesn't
3894 local_p
= local_p
|| _bfd_elf_symbol_refs_local_p (&h
->root
, info
, 1);
3895 if (local_p
|| r_type
== R_MIPS_GOT_OFST
)
3901 case R_MIPS_GOT_DISP
:
3902 case R_MIPS_GOT_HI16
:
3903 case R_MIPS_CALL_HI16
:
3904 case R_MIPS_GOT_LO16
:
3905 case R_MIPS_CALL_LO16
:
3907 case R_MIPS_TLS_GOTTPREL
:
3908 case R_MIPS_TLS_LDM
:
3909 /* Find the index into the GOT where this value is located. */
3910 if (r_type
== R_MIPS_TLS_LDM
)
3912 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
, 0, 0, NULL
,
3915 return bfd_reloc_outofrange
;
3919 /* GOT_PAGE may take a non-zero addend, that is ignored in a
3920 GOT_PAGE relocation that decays to GOT_DISP because the
3921 symbol turns out to be global. The addend is then added
3923 BFD_ASSERT (addend
== 0 || r_type
== R_MIPS_GOT_PAGE
);
3924 g
= mips_elf_global_got_index (elf_hash_table (info
)->dynobj
,
3926 (struct elf_link_hash_entry
*) h
,
3928 if (h
->tls_type
== GOT_NORMAL
3929 && (! elf_hash_table(info
)->dynamic_sections_created
3931 && (info
->symbolic
|| h
->root
.forced_local
)
3932 && h
->root
.def_regular
)))
3934 /* This is a static link or a -Bsymbolic link. The
3935 symbol is defined locally, or was forced to be local.
3936 We must initialize this entry in the GOT. */
3937 bfd
*tmpbfd
= elf_hash_table (info
)->dynobj
;
3938 asection
*sgot
= mips_elf_got_section (tmpbfd
, FALSE
);
3939 MIPS_ELF_PUT_WORD (tmpbfd
, symbol
, sgot
->contents
+ g
);
3942 else if (r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS_CALL16
)
3943 /* There's no need to create a local GOT entry here; the
3944 calculation for a local GOT16 entry does not involve G. */
3948 g
= mips_elf_local_got_index (abfd
, input_bfd
,
3949 info
, symbol
+ addend
, r_symndx
, h
,
3952 return bfd_reloc_outofrange
;
3955 /* Convert GOT indices to actual offsets. */
3956 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
3957 abfd
, input_bfd
, g
);
3962 case R_MIPS_GPREL16
:
3963 case R_MIPS_GPREL32
:
3964 case R_MIPS_LITERAL
:
3967 case R_MIPS16_GPREL
:
3968 gp0
= _bfd_get_gp_value (input_bfd
);
3969 gp
= _bfd_get_gp_value (abfd
);
3970 if (elf_hash_table (info
)->dynobj
)
3971 gp
+= mips_elf_adjust_gp (abfd
,
3973 (elf_hash_table (info
)->dynobj
, NULL
),
3984 /* Figure out what kind of relocation is being performed. */
3988 return bfd_reloc_continue
;
3991 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
3992 overflowed_p
= mips_elf_overflow_p (value
, 16);
3999 || (elf_hash_table (info
)->dynamic_sections_created
4001 && h
->root
.def_dynamic
4002 && !h
->root
.def_regular
))
4004 && (input_section
->flags
& SEC_ALLOC
) != 0)
4006 /* If we're creating a shared library, or this relocation is
4007 against a symbol in a shared library, then we can't know
4008 where the symbol will end up. So, we create a relocation
4009 record in the output, and leave the job up to the dynamic
4012 if (!mips_elf_create_dynamic_relocation (abfd
,
4020 return bfd_reloc_undefined
;
4024 if (r_type
!= R_MIPS_REL32
)
4025 value
= symbol
+ addend
;
4029 value
&= howto
->dst_mask
;
4033 value
= symbol
+ addend
- p
;
4034 value
&= howto
->dst_mask
;
4038 /* The calculation for R_MIPS16_26 is just the same as for an
4039 R_MIPS_26. It's only the storage of the relocated field into
4040 the output file that's different. That's handled in
4041 mips_elf_perform_relocation. So, we just fall through to the
4042 R_MIPS_26 case here. */
4045 value
= ((addend
| ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
4048 value
= (_bfd_mips_elf_sign_extend (addend
, 28) + symbol
) >> 2;
4049 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
)
4050 overflowed_p
= (value
>> 26) != ((p
+ 4) >> 28);
4052 value
&= howto
->dst_mask
;
4055 case R_MIPS_TLS_DTPREL_HI16
:
4056 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
4060 case R_MIPS_TLS_DTPREL_LO16
:
4061 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
4064 case R_MIPS_TLS_TPREL_HI16
:
4065 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
4069 case R_MIPS_TLS_TPREL_LO16
:
4070 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
4077 value
= mips_elf_high (addend
+ symbol
);
4078 value
&= howto
->dst_mask
;
4082 /* For MIPS16 ABI code we generate this sequence
4083 0: li $v0,%hi(_gp_disp)
4084 4: addiupc $v1,%lo(_gp_disp)
4088 So the offsets of hi and lo relocs are the same, but the
4089 $pc is four higher than $t9 would be, so reduce
4090 both reloc addends by 4. */
4091 if (r_type
== R_MIPS16_HI16
)
4092 value
= mips_elf_high (addend
+ gp
- p
- 4);
4094 value
= mips_elf_high (addend
+ gp
- p
);
4095 overflowed_p
= mips_elf_overflow_p (value
, 16);
4102 value
= (symbol
+ addend
) & howto
->dst_mask
;
4105 /* See the comment for R_MIPS16_HI16 above for the reason
4106 for this conditional. */
4107 if (r_type
== R_MIPS16_LO16
)
4108 value
= addend
+ gp
- p
;
4110 value
= addend
+ gp
- p
+ 4;
4111 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
4112 for overflow. But, on, say, IRIX5, relocations against
4113 _gp_disp are normally generated from the .cpload
4114 pseudo-op. It generates code that normally looks like
4117 lui $gp,%hi(_gp_disp)
4118 addiu $gp,$gp,%lo(_gp_disp)
4121 Here $t9 holds the address of the function being called,
4122 as required by the MIPS ELF ABI. The R_MIPS_LO16
4123 relocation can easily overflow in this situation, but the
4124 R_MIPS_HI16 relocation will handle the overflow.
4125 Therefore, we consider this a bug in the MIPS ABI, and do
4126 not check for overflow here. */
4130 case R_MIPS_LITERAL
:
4131 /* Because we don't merge literal sections, we can handle this
4132 just like R_MIPS_GPREL16. In the long run, we should merge
4133 shared literals, and then we will need to additional work
4138 case R_MIPS16_GPREL
:
4139 /* The R_MIPS16_GPREL performs the same calculation as
4140 R_MIPS_GPREL16, but stores the relocated bits in a different
4141 order. We don't need to do anything special here; the
4142 differences are handled in mips_elf_perform_relocation. */
4143 case R_MIPS_GPREL16
:
4144 /* Only sign-extend the addend if it was extracted from the
4145 instruction. If the addend was separate, leave it alone,
4146 otherwise we may lose significant bits. */
4147 if (howto
->partial_inplace
)
4148 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
4149 value
= symbol
+ addend
- gp
;
4150 /* If the symbol was local, any earlier relocatable links will
4151 have adjusted its addend with the gp offset, so compensate
4152 for that now. Don't do it for symbols forced local in this
4153 link, though, since they won't have had the gp offset applied
4157 overflowed_p
= mips_elf_overflow_p (value
, 16);
4166 /* The special case is when the symbol is forced to be local. We
4167 need the full address in the GOT since no R_MIPS_LO16 relocation
4169 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
4170 local_sections
, FALSE
);
4171 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
4172 symbol
+ addend
, forced
);
4173 if (value
== MINUS_ONE
)
4174 return bfd_reloc_outofrange
;
4176 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
4177 abfd
, input_bfd
, value
);
4178 overflowed_p
= mips_elf_overflow_p (value
, 16);
4185 case R_MIPS_TLS_GOTTPREL
:
4186 case R_MIPS_TLS_LDM
:
4187 case R_MIPS_GOT_DISP
:
4190 overflowed_p
= mips_elf_overflow_p (value
, 16);
4193 case R_MIPS_GPREL32
:
4194 value
= (addend
+ symbol
+ gp0
- gp
);
4196 value
&= howto
->dst_mask
;
4200 case R_MIPS_GNU_REL16_S2
:
4201 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
4202 overflowed_p
= mips_elf_overflow_p (value
, 18);
4203 value
= (value
>> 2) & howto
->dst_mask
;
4206 case R_MIPS_GOT_HI16
:
4207 case R_MIPS_CALL_HI16
:
4208 /* We're allowed to handle these two relocations identically.
4209 The dynamic linker is allowed to handle the CALL relocations
4210 differently by creating a lazy evaluation stub. */
4212 value
= mips_elf_high (value
);
4213 value
&= howto
->dst_mask
;
4216 case R_MIPS_GOT_LO16
:
4217 case R_MIPS_CALL_LO16
:
4218 value
= g
& howto
->dst_mask
;
4221 case R_MIPS_GOT_PAGE
:
4222 /* GOT_PAGE relocations that reference non-local symbols decay
4223 to GOT_DISP. The corresponding GOT_OFST relocation decays to
4227 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
4228 if (value
== MINUS_ONE
)
4229 return bfd_reloc_outofrange
;
4230 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
4231 abfd
, input_bfd
, value
);
4232 overflowed_p
= mips_elf_overflow_p (value
, 16);
4235 case R_MIPS_GOT_OFST
:
4237 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
4240 overflowed_p
= mips_elf_overflow_p (value
, 16);
4244 value
= symbol
- addend
;
4245 value
&= howto
->dst_mask
;
4249 value
= mips_elf_higher (addend
+ symbol
);
4250 value
&= howto
->dst_mask
;
4253 case R_MIPS_HIGHEST
:
4254 value
= mips_elf_highest (addend
+ symbol
);
4255 value
&= howto
->dst_mask
;
4258 case R_MIPS_SCN_DISP
:
4259 value
= symbol
+ addend
- sec
->output_offset
;
4260 value
&= howto
->dst_mask
;
4264 /* This relocation is only a hint. In some cases, we optimize
4265 it into a bal instruction. But we don't try to optimize
4266 branches to the PLT; that will wind up wasting time. */
4267 if (h
!= NULL
&& h
->root
.plt
.offset
!= (bfd_vma
) -1)
4268 return bfd_reloc_continue
;
4269 value
= symbol
+ addend
;
4273 case R_MIPS_GNU_VTINHERIT
:
4274 case R_MIPS_GNU_VTENTRY
:
4275 /* We don't do anything with these at present. */
4276 return bfd_reloc_continue
;
4279 /* An unrecognized relocation type. */
4280 return bfd_reloc_notsupported
;
4283 /* Store the VALUE for our caller. */
4285 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
4288 /* Obtain the field relocated by RELOCATION. */
4291 mips_elf_obtain_contents (reloc_howto_type
*howto
,
4292 const Elf_Internal_Rela
*relocation
,
4293 bfd
*input_bfd
, bfd_byte
*contents
)
4296 bfd_byte
*location
= contents
+ relocation
->r_offset
;
4298 /* Obtain the bytes. */
4299 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
4304 /* It has been determined that the result of the RELOCATION is the
4305 VALUE. Use HOWTO to place VALUE into the output file at the
4306 appropriate position. The SECTION is the section to which the
4307 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
4308 for the relocation must be either JAL or JALX, and it is
4309 unconditionally converted to JALX.
4311 Returns FALSE if anything goes wrong. */
4314 mips_elf_perform_relocation (struct bfd_link_info
*info
,
4315 reloc_howto_type
*howto
,
4316 const Elf_Internal_Rela
*relocation
,
4317 bfd_vma value
, bfd
*input_bfd
,
4318 asection
*input_section
, bfd_byte
*contents
,
4319 bfd_boolean require_jalx
)
4323 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4325 /* Figure out where the relocation is occurring. */
4326 location
= contents
+ relocation
->r_offset
;
4328 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
4330 /* Obtain the current value. */
4331 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
4333 /* Clear the field we are setting. */
4334 x
&= ~howto
->dst_mask
;
4336 /* Set the field. */
4337 x
|= (value
& howto
->dst_mask
);
4339 /* If required, turn JAL into JALX. */
4343 bfd_vma opcode
= x
>> 26;
4344 bfd_vma jalx_opcode
;
4346 /* Check to see if the opcode is already JAL or JALX. */
4347 if (r_type
== R_MIPS16_26
)
4349 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
4354 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
4358 /* If the opcode is not JAL or JALX, there's a problem. */
4361 (*_bfd_error_handler
)
4362 (_("%B: %A+0x%lx: jump to stub routine which is not jal"),
4365 (unsigned long) relocation
->r_offset
);
4366 bfd_set_error (bfd_error_bad_value
);
4370 /* Make this the JALX opcode. */
4371 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
4374 /* On the RM9000, bal is faster than jal, because bal uses branch
4375 prediction hardware. If we are linking for the RM9000, and we
4376 see jal, and bal fits, use it instead. Note that this
4377 transformation should be safe for all architectures. */
4378 if (bfd_get_mach (input_bfd
) == bfd_mach_mips9000
4379 && !info
->relocatable
4381 && ((r_type
== R_MIPS_26
&& (x
>> 26) == 0x3) /* jal addr */
4382 || (r_type
== R_MIPS_JALR
&& x
== 0x0320f809))) /* jalr t9 */
4388 addr
= (input_section
->output_section
->vma
4389 + input_section
->output_offset
4390 + relocation
->r_offset
4392 if (r_type
== R_MIPS_26
)
4393 dest
= (value
<< 2) | ((addr
>> 28) << 28);
4397 if (off
<= 0x1ffff && off
>= -0x20000)
4398 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
4401 /* Put the value into the output. */
4402 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
4404 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, !info
->relocatable
,
4410 /* Returns TRUE if SECTION is a MIPS16 stub section. */
4413 mips_elf_stub_section_p (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
)
4415 const char *name
= bfd_get_section_name (abfd
, section
);
4417 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
4418 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
4419 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
4422 /* Add room for N relocations to the .rel.dyn section in ABFD. */
4425 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, unsigned int n
)
4429 s
= mips_elf_rel_dyn_section (abfd
, FALSE
);
4430 BFD_ASSERT (s
!= NULL
);
4434 /* Make room for a null element. */
4435 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
4438 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
4441 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
4442 is the original relocation, which is now being transformed into a
4443 dynamic relocation. The ADDENDP is adjusted if necessary; the
4444 caller should store the result in place of the original addend. */
4447 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
4448 struct bfd_link_info
*info
,
4449 const Elf_Internal_Rela
*rel
,
4450 struct mips_elf_link_hash_entry
*h
,
4451 asection
*sec
, bfd_vma symbol
,
4452 bfd_vma
*addendp
, asection
*input_section
)
4454 Elf_Internal_Rela outrel
[3];
4459 bfd_boolean defined_p
;
4461 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
4462 dynobj
= elf_hash_table (info
)->dynobj
;
4463 sreloc
= mips_elf_rel_dyn_section (dynobj
, FALSE
);
4464 BFD_ASSERT (sreloc
!= NULL
);
4465 BFD_ASSERT (sreloc
->contents
!= NULL
);
4466 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
4469 outrel
[0].r_offset
=
4470 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
4471 outrel
[1].r_offset
=
4472 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
4473 outrel
[2].r_offset
=
4474 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
4476 if (outrel
[0].r_offset
== MINUS_ONE
)
4477 /* The relocation field has been deleted. */
4480 if (outrel
[0].r_offset
== MINUS_TWO
)
4482 /* The relocation field has been converted into a relative value of
4483 some sort. Functions like _bfd_elf_write_section_eh_frame expect
4484 the field to be fully relocated, so add in the symbol's value. */
4489 /* We must now calculate the dynamic symbol table index to use
4490 in the relocation. */
4492 && (!h
->root
.def_regular
4493 || (info
->shared
&& !info
->symbolic
&& !h
->root
.forced_local
)))
4495 indx
= h
->root
.dynindx
;
4496 if (SGI_COMPAT (output_bfd
))
4497 defined_p
= h
->root
.def_regular
;
4499 /* ??? glibc's ld.so just adds the final GOT entry to the
4500 relocation field. It therefore treats relocs against
4501 defined symbols in the same way as relocs against
4502 undefined symbols. */
4507 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
4509 else if (sec
== NULL
|| sec
->owner
== NULL
)
4511 bfd_set_error (bfd_error_bad_value
);
4516 indx
= elf_section_data (sec
->output_section
)->dynindx
;
4521 /* Instead of generating a relocation using the section
4522 symbol, we may as well make it a fully relative
4523 relocation. We want to avoid generating relocations to
4524 local symbols because we used to generate them
4525 incorrectly, without adding the original symbol value,
4526 which is mandated by the ABI for section symbols. In
4527 order to give dynamic loaders and applications time to
4528 phase out the incorrect use, we refrain from emitting
4529 section-relative relocations. It's not like they're
4530 useful, after all. This should be a bit more efficient
4532 /* ??? Although this behavior is compatible with glibc's ld.so,
4533 the ABI says that relocations against STN_UNDEF should have
4534 a symbol value of 0. Irix rld honors this, so relocations
4535 against STN_UNDEF have no effect. */
4536 if (!SGI_COMPAT (output_bfd
))
4541 /* If the relocation was previously an absolute relocation and
4542 this symbol will not be referred to by the relocation, we must
4543 adjust it by the value we give it in the dynamic symbol table.
4544 Otherwise leave the job up to the dynamic linker. */
4545 if (defined_p
&& r_type
!= R_MIPS_REL32
)
4548 /* The relocation is always an REL32 relocation because we don't
4549 know where the shared library will wind up at load-time. */
4550 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
4552 /* For strict adherence to the ABI specification, we should
4553 generate a R_MIPS_64 relocation record by itself before the
4554 _REL32/_64 record as well, such that the addend is read in as
4555 a 64-bit value (REL32 is a 32-bit relocation, after all).
4556 However, since none of the existing ELF64 MIPS dynamic
4557 loaders seems to care, we don't waste space with these
4558 artificial relocations. If this turns out to not be true,
4559 mips_elf_allocate_dynamic_relocation() should be tweaked so
4560 as to make room for a pair of dynamic relocations per
4561 invocation if ABI_64_P, and here we should generate an
4562 additional relocation record with R_MIPS_64 by itself for a
4563 NULL symbol before this relocation record. */
4564 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
4565 ABI_64_P (output_bfd
)
4568 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
4570 /* Adjust the output offset of the relocation to reference the
4571 correct location in the output file. */
4572 outrel
[0].r_offset
+= (input_section
->output_section
->vma
4573 + input_section
->output_offset
);
4574 outrel
[1].r_offset
+= (input_section
->output_section
->vma
4575 + input_section
->output_offset
);
4576 outrel
[2].r_offset
+= (input_section
->output_section
->vma
4577 + input_section
->output_offset
);
4579 /* Put the relocation back out. We have to use the special
4580 relocation outputter in the 64-bit case since the 64-bit
4581 relocation format is non-standard. */
4582 if (ABI_64_P (output_bfd
))
4584 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
4585 (output_bfd
, &outrel
[0],
4587 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
4590 bfd_elf32_swap_reloc_out
4591 (output_bfd
, &outrel
[0],
4592 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
4594 /* We've now added another relocation. */
4595 ++sreloc
->reloc_count
;
4597 /* Make sure the output section is writable. The dynamic linker
4598 will be writing to it. */
4599 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
4602 /* On IRIX5, make an entry of compact relocation info. */
4603 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
4605 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4610 Elf32_crinfo cptrel
;
4612 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4613 cptrel
.vaddr
= (rel
->r_offset
4614 + input_section
->output_section
->vma
4615 + input_section
->output_offset
);
4616 if (r_type
== R_MIPS_REL32
)
4617 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
4619 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
4620 mips_elf_set_cr_dist2to (cptrel
, 0);
4621 cptrel
.konst
= *addendp
;
4623 cr
= (scpt
->contents
4624 + sizeof (Elf32_External_compact_rel
));
4625 mips_elf_set_cr_relvaddr (cptrel
, 0);
4626 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4627 ((Elf32_External_crinfo
*) cr
4628 + scpt
->reloc_count
));
4629 ++scpt
->reloc_count
;
4636 /* Return the MACH for a MIPS e_flags value. */
4639 _bfd_elf_mips_mach (flagword flags
)
4641 switch (flags
& EF_MIPS_MACH
)
4643 case E_MIPS_MACH_3900
:
4644 return bfd_mach_mips3900
;
4646 case E_MIPS_MACH_4010
:
4647 return bfd_mach_mips4010
;
4649 case E_MIPS_MACH_4100
:
4650 return bfd_mach_mips4100
;
4652 case E_MIPS_MACH_4111
:
4653 return bfd_mach_mips4111
;
4655 case E_MIPS_MACH_4120
:
4656 return bfd_mach_mips4120
;
4658 case E_MIPS_MACH_4650
:
4659 return bfd_mach_mips4650
;
4661 case E_MIPS_MACH_5400
:
4662 return bfd_mach_mips5400
;
4664 case E_MIPS_MACH_5500
:
4665 return bfd_mach_mips5500
;
4667 case E_MIPS_MACH_9000
:
4668 return bfd_mach_mips9000
;
4670 case E_MIPS_MACH_SB1
:
4671 return bfd_mach_mips_sb1
;
4674 switch (flags
& EF_MIPS_ARCH
)
4678 return bfd_mach_mips3000
;
4682 return bfd_mach_mips6000
;
4686 return bfd_mach_mips4000
;
4690 return bfd_mach_mips8000
;
4694 return bfd_mach_mips5
;
4697 case E_MIPS_ARCH_32
:
4698 return bfd_mach_mipsisa32
;
4701 case E_MIPS_ARCH_64
:
4702 return bfd_mach_mipsisa64
;
4705 case E_MIPS_ARCH_32R2
:
4706 return bfd_mach_mipsisa32r2
;
4709 case E_MIPS_ARCH_64R2
:
4710 return bfd_mach_mipsisa64r2
;
4718 /* Return printable name for ABI. */
4720 static INLINE
char *
4721 elf_mips_abi_name (bfd
*abfd
)
4725 flags
= elf_elfheader (abfd
)->e_flags
;
4726 switch (flags
& EF_MIPS_ABI
)
4729 if (ABI_N32_P (abfd
))
4731 else if (ABI_64_P (abfd
))
4735 case E_MIPS_ABI_O32
:
4737 case E_MIPS_ABI_O64
:
4739 case E_MIPS_ABI_EABI32
:
4741 case E_MIPS_ABI_EABI64
:
4744 return "unknown abi";
4748 /* MIPS ELF uses two common sections. One is the usual one, and the
4749 other is for small objects. All the small objects are kept
4750 together, and then referenced via the gp pointer, which yields
4751 faster assembler code. This is what we use for the small common
4752 section. This approach is copied from ecoff.c. */
4753 static asection mips_elf_scom_section
;
4754 static asymbol mips_elf_scom_symbol
;
4755 static asymbol
*mips_elf_scom_symbol_ptr
;
4757 /* MIPS ELF also uses an acommon section, which represents an
4758 allocated common symbol which may be overridden by a
4759 definition in a shared library. */
4760 static asection mips_elf_acom_section
;
4761 static asymbol mips_elf_acom_symbol
;
4762 static asymbol
*mips_elf_acom_symbol_ptr
;
4764 /* Handle the special MIPS section numbers that a symbol may use.
4765 This is used for both the 32-bit and the 64-bit ABI. */
4768 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
4770 elf_symbol_type
*elfsym
;
4772 elfsym
= (elf_symbol_type
*) asym
;
4773 switch (elfsym
->internal_elf_sym
.st_shndx
)
4775 case SHN_MIPS_ACOMMON
:
4776 /* This section is used in a dynamically linked executable file.
4777 It is an allocated common section. The dynamic linker can
4778 either resolve these symbols to something in a shared
4779 library, or it can just leave them here. For our purposes,
4780 we can consider these symbols to be in a new section. */
4781 if (mips_elf_acom_section
.name
== NULL
)
4783 /* Initialize the acommon section. */
4784 mips_elf_acom_section
.name
= ".acommon";
4785 mips_elf_acom_section
.flags
= SEC_ALLOC
;
4786 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
4787 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
4788 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
4789 mips_elf_acom_symbol
.name
= ".acommon";
4790 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
4791 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
4792 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
4794 asym
->section
= &mips_elf_acom_section
;
4798 /* Common symbols less than the GP size are automatically
4799 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
4800 if (asym
->value
> elf_gp_size (abfd
)
4801 || IRIX_COMPAT (abfd
) == ict_irix6
)
4804 case SHN_MIPS_SCOMMON
:
4805 if (mips_elf_scom_section
.name
== NULL
)
4807 /* Initialize the small common section. */
4808 mips_elf_scom_section
.name
= ".scommon";
4809 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
4810 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
4811 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
4812 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
4813 mips_elf_scom_symbol
.name
= ".scommon";
4814 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
4815 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
4816 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
4818 asym
->section
= &mips_elf_scom_section
;
4819 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4822 case SHN_MIPS_SUNDEFINED
:
4823 asym
->section
= bfd_und_section_ptr
;
4828 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
4830 BFD_ASSERT (SGI_COMPAT (abfd
));
4831 if (section
!= NULL
)
4833 asym
->section
= section
;
4834 /* MIPS_TEXT is a bit special, the address is not an offset
4835 to the base of the .text section. So substract the section
4836 base address to make it an offset. */
4837 asym
->value
-= section
->vma
;
4844 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
4846 BFD_ASSERT (SGI_COMPAT (abfd
));
4847 if (section
!= NULL
)
4849 asym
->section
= section
;
4850 /* MIPS_DATA is a bit special, the address is not an offset
4851 to the base of the .data section. So substract the section
4852 base address to make it an offset. */
4853 asym
->value
-= section
->vma
;
4860 /* Implement elf_backend_eh_frame_address_size. This differs from
4861 the default in the way it handles EABI64.
4863 EABI64 was originally specified as an LP64 ABI, and that is what
4864 -mabi=eabi normally gives on a 64-bit target. However, gcc has
4865 historically accepted the combination of -mabi=eabi and -mlong32,
4866 and this ILP32 variation has become semi-official over time.
4867 Both forms use elf32 and have pointer-sized FDE addresses.
4869 If an EABI object was generated by GCC 4.0 or above, it will have
4870 an empty .gcc_compiled_longXX section, where XX is the size of longs
4871 in bits. Unfortunately, ILP32 objects generated by earlier compilers
4872 have no special marking to distinguish them from LP64 objects.
4874 We don't want users of the official LP64 ABI to be punished for the
4875 existence of the ILP32 variant, but at the same time, we don't want
4876 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
4877 We therefore take the following approach:
4879 - If ABFD contains a .gcc_compiled_longXX section, use it to
4880 determine the pointer size.
4882 - Otherwise check the type of the first relocation. Assume that
4883 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
4887 The second check is enough to detect LP64 objects generated by pre-4.0
4888 compilers because, in the kind of output generated by those compilers,
4889 the first relocation will be associated with either a CIE personality
4890 routine or an FDE start address. Furthermore, the compilers never
4891 used a special (non-pointer) encoding for this ABI.
4893 Checking the relocation type should also be safe because there is no
4894 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
4898 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
4900 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
4902 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
4904 bfd_boolean long32_p
, long64_p
;
4906 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
4907 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
4908 if (long32_p
&& long64_p
)
4915 if (sec
->reloc_count
> 0
4916 && elf_section_data (sec
)->relocs
!= NULL
4917 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
4926 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
4927 relocations against two unnamed section symbols to resolve to the
4928 same address. For example, if we have code like:
4930 lw $4,%got_disp(.data)($gp)
4931 lw $25,%got_disp(.text)($gp)
4934 then the linker will resolve both relocations to .data and the program
4935 will jump there rather than to .text.
4937 We can work around this problem by giving names to local section symbols.
4938 This is also what the MIPSpro tools do. */
4941 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
4943 return SGI_COMPAT (abfd
);
4946 /* Work over a section just before writing it out. This routine is
4947 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
4948 sections that need the SHF_MIPS_GPREL flag by name; there has to be
4952 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
4954 if (hdr
->sh_type
== SHT_MIPS_REGINFO
4955 && hdr
->sh_size
> 0)
4959 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
4960 BFD_ASSERT (hdr
->contents
== NULL
);
4963 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
4966 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
4967 if (bfd_bwrite (buf
, 4, abfd
) != 4)
4971 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
4972 && hdr
->bfd_section
!= NULL
4973 && mips_elf_section_data (hdr
->bfd_section
) != NULL
4974 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
4976 bfd_byte
*contents
, *l
, *lend
;
4978 /* We stored the section contents in the tdata field in the
4979 set_section_contents routine. We save the section contents
4980 so that we don't have to read them again.
4981 At this point we know that elf_gp is set, so we can look
4982 through the section contents to see if there is an
4983 ODK_REGINFO structure. */
4985 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
4987 lend
= contents
+ hdr
->sh_size
;
4988 while (l
+ sizeof (Elf_External_Options
) <= lend
)
4990 Elf_Internal_Options intopt
;
4992 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
4994 if (intopt
.size
< sizeof (Elf_External_Options
))
4996 (*_bfd_error_handler
)
4997 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
4998 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
5001 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
5008 + sizeof (Elf_External_Options
)
5009 + (sizeof (Elf64_External_RegInfo
) - 8)),
5012 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
5013 if (bfd_bwrite (buf
, 8, abfd
) != 8)
5016 else if (intopt
.kind
== ODK_REGINFO
)
5023 + sizeof (Elf_External_Options
)
5024 + (sizeof (Elf32_External_RegInfo
) - 4)),
5027 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
5028 if (bfd_bwrite (buf
, 4, abfd
) != 4)
5035 if (hdr
->bfd_section
!= NULL
)
5037 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
5039 if (strcmp (name
, ".sdata") == 0
5040 || strcmp (name
, ".lit8") == 0
5041 || strcmp (name
, ".lit4") == 0)
5043 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5044 hdr
->sh_type
= SHT_PROGBITS
;
5046 else if (strcmp (name
, ".sbss") == 0)
5048 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
5049 hdr
->sh_type
= SHT_NOBITS
;
5051 else if (strcmp (name
, ".srdata") == 0)
5053 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
5054 hdr
->sh_type
= SHT_PROGBITS
;
5056 else if (strcmp (name
, ".compact_rel") == 0)
5059 hdr
->sh_type
= SHT_PROGBITS
;
5061 else if (strcmp (name
, ".rtproc") == 0)
5063 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
5065 unsigned int adjust
;
5067 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
5069 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
5077 /* Handle a MIPS specific section when reading an object file. This
5078 is called when elfcode.h finds a section with an unknown type.
5079 This routine supports both the 32-bit and 64-bit ELF ABI.
5081 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
5085 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
5086 Elf_Internal_Shdr
*hdr
,
5092 /* There ought to be a place to keep ELF backend specific flags, but
5093 at the moment there isn't one. We just keep track of the
5094 sections by their name, instead. Fortunately, the ABI gives
5095 suggested names for all the MIPS specific sections, so we will
5096 probably get away with this. */
5097 switch (hdr
->sh_type
)
5099 case SHT_MIPS_LIBLIST
:
5100 if (strcmp (name
, ".liblist") != 0)
5104 if (strcmp (name
, ".msym") != 0)
5107 case SHT_MIPS_CONFLICT
:
5108 if (strcmp (name
, ".conflict") != 0)
5111 case SHT_MIPS_GPTAB
:
5112 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
5115 case SHT_MIPS_UCODE
:
5116 if (strcmp (name
, ".ucode") != 0)
5119 case SHT_MIPS_DEBUG
:
5120 if (strcmp (name
, ".mdebug") != 0)
5122 flags
= SEC_DEBUGGING
;
5124 case SHT_MIPS_REGINFO
:
5125 if (strcmp (name
, ".reginfo") != 0
5126 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
5128 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
5130 case SHT_MIPS_IFACE
:
5131 if (strcmp (name
, ".MIPS.interfaces") != 0)
5134 case SHT_MIPS_CONTENT
:
5135 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
5138 case SHT_MIPS_OPTIONS
:
5139 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
5142 case SHT_MIPS_DWARF
:
5143 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
5146 case SHT_MIPS_SYMBOL_LIB
:
5147 if (strcmp (name
, ".MIPS.symlib") != 0)
5150 case SHT_MIPS_EVENTS
:
5151 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
5152 && strncmp (name
, ".MIPS.post_rel",
5153 sizeof ".MIPS.post_rel" - 1) != 0)
5160 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
5165 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
5166 (bfd_get_section_flags (abfd
,
5172 /* FIXME: We should record sh_info for a .gptab section. */
5174 /* For a .reginfo section, set the gp value in the tdata information
5175 from the contents of this section. We need the gp value while
5176 processing relocs, so we just get it now. The .reginfo section
5177 is not used in the 64-bit MIPS ELF ABI. */
5178 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
5180 Elf32_External_RegInfo ext
;
5183 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
5184 &ext
, 0, sizeof ext
))
5186 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
5187 elf_gp (abfd
) = s
.ri_gp_value
;
5190 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
5191 set the gp value based on what we find. We may see both
5192 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
5193 they should agree. */
5194 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
5196 bfd_byte
*contents
, *l
, *lend
;
5198 contents
= bfd_malloc (hdr
->sh_size
);
5199 if (contents
== NULL
)
5201 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
5208 lend
= contents
+ hdr
->sh_size
;
5209 while (l
+ sizeof (Elf_External_Options
) <= lend
)
5211 Elf_Internal_Options intopt
;
5213 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
5215 if (intopt
.size
< sizeof (Elf_External_Options
))
5217 (*_bfd_error_handler
)
5218 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
5219 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
5222 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
5224 Elf64_Internal_RegInfo intreg
;
5226 bfd_mips_elf64_swap_reginfo_in
5228 ((Elf64_External_RegInfo
*)
5229 (l
+ sizeof (Elf_External_Options
))),
5231 elf_gp (abfd
) = intreg
.ri_gp_value
;
5233 else if (intopt
.kind
== ODK_REGINFO
)
5235 Elf32_RegInfo intreg
;
5237 bfd_mips_elf32_swap_reginfo_in
5239 ((Elf32_External_RegInfo
*)
5240 (l
+ sizeof (Elf_External_Options
))),
5242 elf_gp (abfd
) = intreg
.ri_gp_value
;
5252 /* Set the correct type for a MIPS ELF section. We do this by the
5253 section name, which is a hack, but ought to work. This routine is
5254 used by both the 32-bit and the 64-bit ABI. */
5257 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
5259 register const char *name
;
5260 unsigned int sh_type
;
5262 name
= bfd_get_section_name (abfd
, sec
);
5263 sh_type
= hdr
->sh_type
;
5265 if (strcmp (name
, ".liblist") == 0)
5267 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
5268 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
5269 /* The sh_link field is set in final_write_processing. */
5271 else if (strcmp (name
, ".conflict") == 0)
5272 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
5273 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
5275 hdr
->sh_type
= SHT_MIPS_GPTAB
;
5276 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
5277 /* The sh_info field is set in final_write_processing. */
5279 else if (strcmp (name
, ".ucode") == 0)
5280 hdr
->sh_type
= SHT_MIPS_UCODE
;
5281 else if (strcmp (name
, ".mdebug") == 0)
5283 hdr
->sh_type
= SHT_MIPS_DEBUG
;
5284 /* In a shared object on IRIX 5.3, the .mdebug section has an
5285 entsize of 0. FIXME: Does this matter? */
5286 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
5287 hdr
->sh_entsize
= 0;
5289 hdr
->sh_entsize
= 1;
5291 else if (strcmp (name
, ".reginfo") == 0)
5293 hdr
->sh_type
= SHT_MIPS_REGINFO
;
5294 /* In a shared object on IRIX 5.3, the .reginfo section has an
5295 entsize of 0x18. FIXME: Does this matter? */
5296 if (SGI_COMPAT (abfd
))
5298 if ((abfd
->flags
& DYNAMIC
) != 0)
5299 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
5301 hdr
->sh_entsize
= 1;
5304 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
5306 else if (SGI_COMPAT (abfd
)
5307 && (strcmp (name
, ".hash") == 0
5308 || strcmp (name
, ".dynamic") == 0
5309 || strcmp (name
, ".dynstr") == 0))
5311 if (SGI_COMPAT (abfd
))
5312 hdr
->sh_entsize
= 0;
5314 /* This isn't how the IRIX6 linker behaves. */
5315 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
5318 else if (strcmp (name
, ".got") == 0
5319 || strcmp (name
, ".srdata") == 0
5320 || strcmp (name
, ".sdata") == 0
5321 || strcmp (name
, ".sbss") == 0
5322 || strcmp (name
, ".lit4") == 0
5323 || strcmp (name
, ".lit8") == 0)
5324 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
5325 else if (strcmp (name
, ".MIPS.interfaces") == 0)
5327 hdr
->sh_type
= SHT_MIPS_IFACE
;
5328 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
5330 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
5332 hdr
->sh_type
= SHT_MIPS_CONTENT
;
5333 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
5334 /* The sh_info field is set in final_write_processing. */
5336 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
5338 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
5339 hdr
->sh_entsize
= 1;
5340 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
5342 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
5343 hdr
->sh_type
= SHT_MIPS_DWARF
;
5344 else if (strcmp (name
, ".MIPS.symlib") == 0)
5346 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
5347 /* The sh_link and sh_info fields are set in
5348 final_write_processing. */
5350 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
5351 || strncmp (name
, ".MIPS.post_rel",
5352 sizeof ".MIPS.post_rel" - 1) == 0)
5354 hdr
->sh_type
= SHT_MIPS_EVENTS
;
5355 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
5356 /* The sh_link field is set in final_write_processing. */
5358 else if (strcmp (name
, ".msym") == 0)
5360 hdr
->sh_type
= SHT_MIPS_MSYM
;
5361 hdr
->sh_flags
|= SHF_ALLOC
;
5362 hdr
->sh_entsize
= 8;
5365 /* In the unlikely event a special section is empty it has to lose its
5366 special meaning. This may happen e.g. when using `strip' with the
5367 "--only-keep-debug" option. */
5368 if (sec
->size
> 0 && !(sec
->flags
& SEC_HAS_CONTENTS
))
5369 hdr
->sh_type
= sh_type
;
5371 /* The generic elf_fake_sections will set up REL_HDR using the default
5372 kind of relocations. We used to set up a second header for the
5373 non-default kind of relocations here, but only NewABI would use
5374 these, and the IRIX ld doesn't like resulting empty RELA sections.
5375 Thus we create those header only on demand now. */
5380 /* Given a BFD section, try to locate the corresponding ELF section
5381 index. This is used by both the 32-bit and the 64-bit ABI.
5382 Actually, it's not clear to me that the 64-bit ABI supports these,
5383 but for non-PIC objects we will certainly want support for at least
5384 the .scommon section. */
5387 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
5388 asection
*sec
, int *retval
)
5390 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
5392 *retval
= SHN_MIPS_SCOMMON
;
5395 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
5397 *retval
= SHN_MIPS_ACOMMON
;
5403 /* Hook called by the linker routine which adds symbols from an object
5404 file. We must handle the special MIPS section numbers here. */
5407 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5408 Elf_Internal_Sym
*sym
, const char **namep
,
5409 flagword
*flagsp ATTRIBUTE_UNUSED
,
5410 asection
**secp
, bfd_vma
*valp
)
5412 if (SGI_COMPAT (abfd
)
5413 && (abfd
->flags
& DYNAMIC
) != 0
5414 && strcmp (*namep
, "_rld_new_interface") == 0)
5416 /* Skip IRIX5 rld entry name. */
5421 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
5422 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
5423 by setting a DT_NEEDED for the shared object. Since _gp_disp is
5424 a magic symbol resolved by the linker, we ignore this bogus definition
5425 of _gp_disp. New ABI objects do not suffer from this problem so this
5426 is not done for them. */
5428 && (sym
->st_shndx
== SHN_ABS
)
5429 && (strcmp (*namep
, "_gp_disp") == 0))
5435 switch (sym
->st_shndx
)
5438 /* Common symbols less than the GP size are automatically
5439 treated as SHN_MIPS_SCOMMON symbols. */
5440 if (sym
->st_size
> elf_gp_size (abfd
)
5441 || IRIX_COMPAT (abfd
) == ict_irix6
)
5444 case SHN_MIPS_SCOMMON
:
5445 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
5446 (*secp
)->flags
|= SEC_IS_COMMON
;
5447 *valp
= sym
->st_size
;
5451 /* This section is used in a shared object. */
5452 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
5454 asymbol
*elf_text_symbol
;
5455 asection
*elf_text_section
;
5456 bfd_size_type amt
= sizeof (asection
);
5458 elf_text_section
= bfd_zalloc (abfd
, amt
);
5459 if (elf_text_section
== NULL
)
5462 amt
= sizeof (asymbol
);
5463 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
5464 if (elf_text_symbol
== NULL
)
5467 /* Initialize the section. */
5469 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
5470 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
5472 elf_text_section
->symbol
= elf_text_symbol
;
5473 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
5475 elf_text_section
->name
= ".text";
5476 elf_text_section
->flags
= SEC_NO_FLAGS
;
5477 elf_text_section
->output_section
= NULL
;
5478 elf_text_section
->owner
= abfd
;
5479 elf_text_symbol
->name
= ".text";
5480 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
5481 elf_text_symbol
->section
= elf_text_section
;
5483 /* This code used to do *secp = bfd_und_section_ptr if
5484 info->shared. I don't know why, and that doesn't make sense,
5485 so I took it out. */
5486 *secp
= elf_tdata (abfd
)->elf_text_section
;
5489 case SHN_MIPS_ACOMMON
:
5490 /* Fall through. XXX Can we treat this as allocated data? */
5492 /* This section is used in a shared object. */
5493 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
5495 asymbol
*elf_data_symbol
;
5496 asection
*elf_data_section
;
5497 bfd_size_type amt
= sizeof (asection
);
5499 elf_data_section
= bfd_zalloc (abfd
, amt
);
5500 if (elf_data_section
== NULL
)
5503 amt
= sizeof (asymbol
);
5504 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
5505 if (elf_data_symbol
== NULL
)
5508 /* Initialize the section. */
5510 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
5511 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
5513 elf_data_section
->symbol
= elf_data_symbol
;
5514 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
5516 elf_data_section
->name
= ".data";
5517 elf_data_section
->flags
= SEC_NO_FLAGS
;
5518 elf_data_section
->output_section
= NULL
;
5519 elf_data_section
->owner
= abfd
;
5520 elf_data_symbol
->name
= ".data";
5521 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
5522 elf_data_symbol
->section
= elf_data_section
;
5524 /* This code used to do *secp = bfd_und_section_ptr if
5525 info->shared. I don't know why, and that doesn't make sense,
5526 so I took it out. */
5527 *secp
= elf_tdata (abfd
)->elf_data_section
;
5530 case SHN_MIPS_SUNDEFINED
:
5531 *secp
= bfd_und_section_ptr
;
5535 if (SGI_COMPAT (abfd
)
5537 && info
->hash
->creator
== abfd
->xvec
5538 && strcmp (*namep
, "__rld_obj_head") == 0)
5540 struct elf_link_hash_entry
*h
;
5541 struct bfd_link_hash_entry
*bh
;
5543 /* Mark __rld_obj_head as dynamic. */
5545 if (! (_bfd_generic_link_add_one_symbol
5546 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
5547 get_elf_backend_data (abfd
)->collect
, &bh
)))
5550 h
= (struct elf_link_hash_entry
*) bh
;
5553 h
->type
= STT_OBJECT
;
5555 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5558 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
5561 /* If this is a mips16 text symbol, add 1 to the value to make it
5562 odd. This will cause something like .word SYM to come up with
5563 the right value when it is loaded into the PC. */
5564 if (sym
->st_other
== STO_MIPS16
)
5570 /* This hook function is called before the linker writes out a global
5571 symbol. We mark symbols as small common if appropriate. This is
5572 also where we undo the increment of the value for a mips16 symbol. */
5575 _bfd_mips_elf_link_output_symbol_hook
5576 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5577 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
5578 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5580 /* If we see a common symbol, which implies a relocatable link, then
5581 if a symbol was small common in an input file, mark it as small
5582 common in the output file. */
5583 if (sym
->st_shndx
== SHN_COMMON
5584 && strcmp (input_sec
->name
, ".scommon") == 0)
5585 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
5587 if (sym
->st_other
== STO_MIPS16
)
5588 sym
->st_value
&= ~1;
5593 /* Functions for the dynamic linker. */
5595 /* Create dynamic sections when linking against a dynamic object. */
5598 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5600 struct elf_link_hash_entry
*h
;
5601 struct bfd_link_hash_entry
*bh
;
5603 register asection
*s
;
5604 const char * const *namep
;
5606 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
5607 | SEC_LINKER_CREATED
| SEC_READONLY
);
5609 /* Mips ABI requests the .dynamic section to be read only. */
5610 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5613 if (! bfd_set_section_flags (abfd
, s
, flags
))
5617 /* We need to create .got section. */
5618 if (! mips_elf_create_got_section (abfd
, info
, FALSE
))
5621 if (! mips_elf_rel_dyn_section (elf_hash_table (info
)->dynobj
, TRUE
))
5624 /* Create .stub section. */
5625 if (bfd_get_section_by_name (abfd
,
5626 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
5628 s
= bfd_make_section_with_flags (abfd
,
5629 MIPS_ELF_STUB_SECTION_NAME (abfd
),
5632 || ! bfd_set_section_alignment (abfd
, s
,
5633 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
5637 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
5639 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
5641 s
= bfd_make_section_with_flags (abfd
, ".rld_map",
5642 flags
&~ (flagword
) SEC_READONLY
);
5644 || ! bfd_set_section_alignment (abfd
, s
,
5645 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
5649 /* On IRIX5, we adjust add some additional symbols and change the
5650 alignments of several sections. There is no ABI documentation
5651 indicating that this is necessary on IRIX6, nor any evidence that
5652 the linker takes such action. */
5653 if (IRIX_COMPAT (abfd
) == ict_irix5
)
5655 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
5658 if (! (_bfd_generic_link_add_one_symbol
5659 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
5660 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
5663 h
= (struct elf_link_hash_entry
*) bh
;
5666 h
->type
= STT_SECTION
;
5668 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5672 /* We need to create a .compact_rel section. */
5673 if (SGI_COMPAT (abfd
))
5675 if (!mips_elf_create_compact_rel_section (abfd
, info
))
5679 /* Change alignments of some sections. */
5680 s
= bfd_get_section_by_name (abfd
, ".hash");
5682 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
5683 s
= bfd_get_section_by_name (abfd
, ".dynsym");
5685 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
5686 s
= bfd_get_section_by_name (abfd
, ".dynstr");
5688 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
5689 s
= bfd_get_section_by_name (abfd
, ".reginfo");
5691 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
5692 s
= bfd_get_section_by_name (abfd
, ".dynamic");
5694 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
5701 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
5703 if (!(_bfd_generic_link_add_one_symbol
5704 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
5705 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
5708 h
= (struct elf_link_hash_entry
*) bh
;
5711 h
->type
= STT_SECTION
;
5713 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5716 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
5718 /* __rld_map is a four byte word located in the .data section
5719 and is filled in by the rtld to contain a pointer to
5720 the _r_debug structure. Its symbol value will be set in
5721 _bfd_mips_elf_finish_dynamic_symbol. */
5722 s
= bfd_get_section_by_name (abfd
, ".rld_map");
5723 BFD_ASSERT (s
!= NULL
);
5725 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
5727 if (!(_bfd_generic_link_add_one_symbol
5728 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
5729 get_elf_backend_data (abfd
)->collect
, &bh
)))
5732 h
= (struct elf_link_hash_entry
*) bh
;
5735 h
->type
= STT_OBJECT
;
5737 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5745 /* Look through the relocs for a section during the first phase, and
5746 allocate space in the global offset table. */
5749 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
5750 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5754 Elf_Internal_Shdr
*symtab_hdr
;
5755 struct elf_link_hash_entry
**sym_hashes
;
5756 struct mips_got_info
*g
;
5758 const Elf_Internal_Rela
*rel
;
5759 const Elf_Internal_Rela
*rel_end
;
5762 const struct elf_backend_data
*bed
;
5764 if (info
->relocatable
)
5767 dynobj
= elf_hash_table (info
)->dynobj
;
5768 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5769 sym_hashes
= elf_sym_hashes (abfd
);
5770 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
5772 /* Check for the mips16 stub sections. */
5774 name
= bfd_get_section_name (abfd
, sec
);
5775 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
5777 unsigned long r_symndx
;
5779 /* Look at the relocation information to figure out which symbol
5782 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
5784 if (r_symndx
< extsymoff
5785 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5789 /* This stub is for a local symbol. This stub will only be
5790 needed if there is some relocation in this BFD, other
5791 than a 16 bit function call, which refers to this symbol. */
5792 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5794 Elf_Internal_Rela
*sec_relocs
;
5795 const Elf_Internal_Rela
*r
, *rend
;
5797 /* We can ignore stub sections when looking for relocs. */
5798 if ((o
->flags
& SEC_RELOC
) == 0
5799 || o
->reloc_count
== 0
5800 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
5801 sizeof FN_STUB
- 1) == 0
5802 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
5803 sizeof CALL_STUB
- 1) == 0
5804 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
5805 sizeof CALL_FP_STUB
- 1) == 0)
5809 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
5811 if (sec_relocs
== NULL
)
5814 rend
= sec_relocs
+ o
->reloc_count
;
5815 for (r
= sec_relocs
; r
< rend
; r
++)
5816 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
5817 && ELF_R_TYPE (abfd
, r
->r_info
) != R_MIPS16_26
)
5820 if (elf_section_data (o
)->relocs
!= sec_relocs
)
5829 /* There is no non-call reloc for this stub, so we do
5830 not need it. Since this function is called before
5831 the linker maps input sections to output sections, we
5832 can easily discard it by setting the SEC_EXCLUDE
5834 sec
->flags
|= SEC_EXCLUDE
;
5838 /* Record this stub in an array of local symbol stubs for
5840 if (elf_tdata (abfd
)->local_stubs
== NULL
)
5842 unsigned long symcount
;
5846 if (elf_bad_symtab (abfd
))
5847 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
5849 symcount
= symtab_hdr
->sh_info
;
5850 amt
= symcount
* sizeof (asection
*);
5851 n
= bfd_zalloc (abfd
, amt
);
5854 elf_tdata (abfd
)->local_stubs
= n
;
5857 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
5859 /* We don't need to set mips16_stubs_seen in this case.
5860 That flag is used to see whether we need to look through
5861 the global symbol table for stubs. We don't need to set
5862 it here, because we just have a local stub. */
5866 struct mips_elf_link_hash_entry
*h
;
5868 h
= ((struct mips_elf_link_hash_entry
*)
5869 sym_hashes
[r_symndx
- extsymoff
]);
5871 while (h
->root
.root
.type
== bfd_link_hash_indirect
5872 || h
->root
.root
.type
== bfd_link_hash_warning
)
5873 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5875 /* H is the symbol this stub is for. */
5878 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
5881 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
5882 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5884 unsigned long r_symndx
;
5885 struct mips_elf_link_hash_entry
*h
;
5888 /* Look at the relocation information to figure out which symbol
5891 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
5893 if (r_symndx
< extsymoff
5894 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
5896 /* This stub was actually built for a static symbol defined
5897 in the same file. We assume that all static symbols in
5898 mips16 code are themselves mips16, so we can simply
5899 discard this stub. Since this function is called before
5900 the linker maps input sections to output sections, we can
5901 easily discard it by setting the SEC_EXCLUDE flag. */
5902 sec
->flags
|= SEC_EXCLUDE
;
5906 h
= ((struct mips_elf_link_hash_entry
*)
5907 sym_hashes
[r_symndx
- extsymoff
]);
5909 /* H is the symbol this stub is for. */
5911 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5912 loc
= &h
->call_fp_stub
;
5914 loc
= &h
->call_stub
;
5916 /* If we already have an appropriate stub for this function, we
5917 don't need another one, so we can discard this one. Since
5918 this function is called before the linker maps input sections
5919 to output sections, we can easily discard it by setting the
5920 SEC_EXCLUDE flag. We can also discard this section if we
5921 happen to already know that this is a mips16 function; it is
5922 not necessary to check this here, as it is checked later, but
5923 it is slightly faster to check now. */
5924 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
5926 sec
->flags
|= SEC_EXCLUDE
;
5931 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
5941 sgot
= mips_elf_got_section (dynobj
, FALSE
);
5946 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
5947 g
= mips_elf_section_data (sgot
)->u
.got_info
;
5948 BFD_ASSERT (g
!= NULL
);
5953 bed
= get_elf_backend_data (abfd
);
5954 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
5955 for (rel
= relocs
; rel
< rel_end
; ++rel
)
5957 unsigned long r_symndx
;
5958 unsigned int r_type
;
5959 struct elf_link_hash_entry
*h
;
5961 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
5962 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
5964 if (r_symndx
< extsymoff
)
5966 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
5968 (*_bfd_error_handler
)
5969 (_("%B: Malformed reloc detected for section %s"),
5971 bfd_set_error (bfd_error_bad_value
);
5976 h
= sym_hashes
[r_symndx
- extsymoff
];
5978 /* This may be an indirect symbol created because of a version. */
5981 while (h
->root
.type
== bfd_link_hash_indirect
)
5982 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5986 /* Some relocs require a global offset table. */
5987 if (dynobj
== NULL
|| sgot
== NULL
)
5993 case R_MIPS_CALL_HI16
:
5994 case R_MIPS_CALL_LO16
:
5995 case R_MIPS_GOT_HI16
:
5996 case R_MIPS_GOT_LO16
:
5997 case R_MIPS_GOT_PAGE
:
5998 case R_MIPS_GOT_OFST
:
5999 case R_MIPS_GOT_DISP
:
6001 case R_MIPS_TLS_LDM
:
6003 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6004 if (! mips_elf_create_got_section (dynobj
, info
, FALSE
))
6006 g
= mips_elf_got_info (dynobj
, &sgot
);
6013 && (info
->shared
|| h
!= NULL
)
6014 && (sec
->flags
& SEC_ALLOC
) != 0)
6015 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6023 if (!h
&& (r_type
== R_MIPS_CALL_LO16
6024 || r_type
== R_MIPS_GOT_LO16
6025 || r_type
== R_MIPS_GOT_DISP
))
6027 /* We may need a local GOT entry for this relocation. We
6028 don't count R_MIPS_GOT_PAGE because we can estimate the
6029 maximum number of pages needed by looking at the size of
6030 the segment. Similar comments apply to R_MIPS_GOT16 and
6031 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
6032 R_MIPS_CALL_HI16 because these are always followed by an
6033 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
6034 if (! mips_elf_record_local_got_symbol (abfd
, r_symndx
,
6035 rel
->r_addend
, g
, 0))
6044 (*_bfd_error_handler
)
6045 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
6046 abfd
, (unsigned long) rel
->r_offset
);
6047 bfd_set_error (bfd_error_bad_value
);
6052 case R_MIPS_CALL_HI16
:
6053 case R_MIPS_CALL_LO16
:
6056 /* This symbol requires a global offset table entry. */
6057 if (! mips_elf_record_global_got_symbol (h
, abfd
, info
, g
, 0))
6060 /* We need a stub, not a plt entry for the undefined
6061 function. But we record it as if it needs plt. See
6062 _bfd_elf_adjust_dynamic_symbol. */
6068 case R_MIPS_GOT_PAGE
:
6069 /* If this is a global, overridable symbol, GOT_PAGE will
6070 decay to GOT_DISP, so we'll need a GOT entry for it. */
6075 struct mips_elf_link_hash_entry
*hmips
=
6076 (struct mips_elf_link_hash_entry
*) h
;
6078 while (hmips
->root
.root
.type
== bfd_link_hash_indirect
6079 || hmips
->root
.root
.type
== bfd_link_hash_warning
)
6080 hmips
= (struct mips_elf_link_hash_entry
*)
6081 hmips
->root
.root
.u
.i
.link
;
6083 if (hmips
->root
.def_regular
6084 && ! (info
->shared
&& ! info
->symbolic
6085 && ! hmips
->root
.forced_local
))
6091 case R_MIPS_GOT_HI16
:
6092 case R_MIPS_GOT_LO16
:
6093 case R_MIPS_GOT_DISP
:
6094 if (h
&& ! mips_elf_record_global_got_symbol (h
, abfd
, info
, g
, 0))
6098 case R_MIPS_TLS_GOTTPREL
:
6100 info
->flags
|= DF_STATIC_TLS
;
6103 case R_MIPS_TLS_LDM
:
6104 if (r_type
== R_MIPS_TLS_LDM
)
6112 /* This symbol requires a global offset table entry, or two
6113 for TLS GD relocations. */
6115 unsigned char flag
= (r_type
== R_MIPS_TLS_GD
6117 : r_type
== R_MIPS_TLS_LDM
6122 struct mips_elf_link_hash_entry
*hmips
=
6123 (struct mips_elf_link_hash_entry
*) h
;
6124 hmips
->tls_type
|= flag
;
6126 if (h
&& ! mips_elf_record_global_got_symbol (h
, abfd
, info
, g
, flag
))
6131 BFD_ASSERT (flag
== GOT_TLS_LDM
|| r_symndx
!= 0);
6133 if (! mips_elf_record_local_got_symbol (abfd
, r_symndx
,
6134 rel
->r_addend
, g
, flag
))
6143 if ((info
->shared
|| h
!= NULL
)
6144 && (sec
->flags
& SEC_ALLOC
) != 0)
6148 sreloc
= mips_elf_rel_dyn_section (dynobj
, TRUE
);
6152 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
6155 /* When creating a shared object, we must copy these
6156 reloc types into the output file as R_MIPS_REL32
6157 relocs. We make room for this reloc in the
6158 .rel.dyn reloc section. */
6159 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
6160 if ((sec
->flags
& MIPS_READONLY_SECTION
)
6161 == MIPS_READONLY_SECTION
)
6162 /* We tell the dynamic linker that there are
6163 relocations against the text segment. */
6164 info
->flags
|= DF_TEXTREL
;
6168 struct mips_elf_link_hash_entry
*hmips
;
6170 /* We only need to copy this reloc if the symbol is
6171 defined in a dynamic object. */
6172 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6173 ++hmips
->possibly_dynamic_relocs
;
6174 if ((sec
->flags
& MIPS_READONLY_SECTION
)
6175 == MIPS_READONLY_SECTION
)
6176 /* We need it to tell the dynamic linker if there
6177 are relocations against the text segment. */
6178 hmips
->readonly_reloc
= TRUE
;
6181 /* Even though we don't directly need a GOT entry for
6182 this symbol, a symbol must have a dynamic symbol
6183 table index greater that DT_MIPS_GOTSYM if there are
6184 dynamic relocations against it. */
6188 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
6189 if (! mips_elf_create_got_section (dynobj
, info
, TRUE
))
6191 g
= mips_elf_got_info (dynobj
, &sgot
);
6192 if (! mips_elf_record_global_got_symbol (h
, abfd
, info
, g
, 0))
6197 if (SGI_COMPAT (abfd
))
6198 mips_elf_hash_table (info
)->compact_rel_size
+=
6199 sizeof (Elf32_External_crinfo
);
6203 case R_MIPS_GPREL16
:
6204 case R_MIPS_LITERAL
:
6205 case R_MIPS_GPREL32
:
6206 if (SGI_COMPAT (abfd
))
6207 mips_elf_hash_table (info
)->compact_rel_size
+=
6208 sizeof (Elf32_External_crinfo
);
6211 /* This relocation describes the C++ object vtable hierarchy.
6212 Reconstruct it for later use during GC. */
6213 case R_MIPS_GNU_VTINHERIT
:
6214 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6218 /* This relocation describes which C++ vtable entries are actually
6219 used. Record for later use during GC. */
6220 case R_MIPS_GNU_VTENTRY
:
6221 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6229 /* We must not create a stub for a symbol that has relocations
6230 related to taking the function's address. */
6236 struct mips_elf_link_hash_entry
*mh
;
6238 mh
= (struct mips_elf_link_hash_entry
*) h
;
6239 mh
->no_fn_stub
= TRUE
;
6243 case R_MIPS_CALL_HI16
:
6244 case R_MIPS_CALL_LO16
:
6249 /* If this reloc is not a 16 bit call, and it has a global
6250 symbol, then we will need the fn_stub if there is one.
6251 References from a stub section do not count. */
6253 && r_type
!= R_MIPS16_26
6254 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
6255 sizeof FN_STUB
- 1) != 0
6256 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
6257 sizeof CALL_STUB
- 1) != 0
6258 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
6259 sizeof CALL_FP_STUB
- 1) != 0)
6261 struct mips_elf_link_hash_entry
*mh
;
6263 mh
= (struct mips_elf_link_hash_entry
*) h
;
6264 mh
->need_fn_stub
= TRUE
;
6272 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
6273 struct bfd_link_info
*link_info
,
6276 Elf_Internal_Rela
*internal_relocs
;
6277 Elf_Internal_Rela
*irel
, *irelend
;
6278 Elf_Internal_Shdr
*symtab_hdr
;
6279 bfd_byte
*contents
= NULL
;
6281 bfd_boolean changed_contents
= FALSE
;
6282 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
6283 Elf_Internal_Sym
*isymbuf
= NULL
;
6285 /* We are not currently changing any sizes, so only one pass. */
6288 if (link_info
->relocatable
)
6291 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
6292 link_info
->keep_memory
);
6293 if (internal_relocs
== NULL
)
6296 irelend
= internal_relocs
+ sec
->reloc_count
6297 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
6298 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6299 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
6301 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6304 bfd_signed_vma sym_offset
;
6305 unsigned int r_type
;
6306 unsigned long r_symndx
;
6308 unsigned long instruction
;
6310 /* Turn jalr into bgezal, and jr into beq, if they're marked
6311 with a JALR relocation, that indicate where they jump to.
6312 This saves some pipeline bubbles. */
6313 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
6314 if (r_type
!= R_MIPS_JALR
)
6317 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
6318 /* Compute the address of the jump target. */
6319 if (r_symndx
>= extsymoff
)
6321 struct mips_elf_link_hash_entry
*h
6322 = ((struct mips_elf_link_hash_entry
*)
6323 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
6325 while (h
->root
.root
.type
== bfd_link_hash_indirect
6326 || h
->root
.root
.type
== bfd_link_hash_warning
)
6327 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
6329 /* If a symbol is undefined, or if it may be overridden,
6331 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
6332 || h
->root
.root
.type
== bfd_link_hash_defweak
)
6333 && h
->root
.root
.u
.def
.section
)
6334 || (link_info
->shared
&& ! link_info
->symbolic
6335 && !h
->root
.forced_local
))
6338 sym_sec
= h
->root
.root
.u
.def
.section
;
6339 if (sym_sec
->output_section
)
6340 symval
= (h
->root
.root
.u
.def
.value
6341 + sym_sec
->output_section
->vma
6342 + sym_sec
->output_offset
);
6344 symval
= h
->root
.root
.u
.def
.value
;
6348 Elf_Internal_Sym
*isym
;
6350 /* Read this BFD's symbols if we haven't done so already. */
6351 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
6353 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6354 if (isymbuf
== NULL
)
6355 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
6356 symtab_hdr
->sh_info
, 0,
6358 if (isymbuf
== NULL
)
6362 isym
= isymbuf
+ r_symndx
;
6363 if (isym
->st_shndx
== SHN_UNDEF
)
6365 else if (isym
->st_shndx
== SHN_ABS
)
6366 sym_sec
= bfd_abs_section_ptr
;
6367 else if (isym
->st_shndx
== SHN_COMMON
)
6368 sym_sec
= bfd_com_section_ptr
;
6371 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6372 symval
= isym
->st_value
6373 + sym_sec
->output_section
->vma
6374 + sym_sec
->output_offset
;
6377 /* Compute branch offset, from delay slot of the jump to the
6379 sym_offset
= (symval
+ irel
->r_addend
)
6380 - (sec_start
+ irel
->r_offset
+ 4);
6382 /* Branch offset must be properly aligned. */
6383 if ((sym_offset
& 3) != 0)
6388 /* Check that it's in range. */
6389 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
6392 /* Get the section contents if we haven't done so already. */
6393 if (contents
== NULL
)
6395 /* Get cached copy if it exists. */
6396 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6397 contents
= elf_section_data (sec
)->this_hdr
.contents
;
6400 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
6405 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
6407 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
6408 if ((instruction
& 0xfc1fffff) == 0x0000f809)
6409 instruction
= 0x04110000;
6410 /* If it was jr <reg>, turn it into b <target>. */
6411 else if ((instruction
& 0xfc1fffff) == 0x00000008)
6412 instruction
= 0x10000000;
6416 instruction
|= (sym_offset
& 0xffff);
6417 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
6418 changed_contents
= TRUE
;
6421 if (contents
!= NULL
6422 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6424 if (!changed_contents
&& !link_info
->keep_memory
)
6428 /* Cache the section contents for elf_link_input_bfd. */
6429 elf_section_data (sec
)->this_hdr
.contents
= contents
;
6435 if (contents
!= NULL
6436 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6441 /* Adjust a symbol defined by a dynamic object and referenced by a
6442 regular object. The current definition is in some section of the
6443 dynamic object, but we're not including those sections. We have to
6444 change the definition to something the rest of the link can
6448 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6449 struct elf_link_hash_entry
*h
)
6452 struct mips_elf_link_hash_entry
*hmips
;
6455 dynobj
= elf_hash_table (info
)->dynobj
;
6457 /* Make sure we know what is going on here. */
6458 BFD_ASSERT (dynobj
!= NULL
6460 || h
->u
.weakdef
!= NULL
6463 && !h
->def_regular
)));
6465 /* If this symbol is defined in a dynamic object, we need to copy
6466 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
6468 hmips
= (struct mips_elf_link_hash_entry
*) h
;
6469 if (! info
->relocatable
6470 && hmips
->possibly_dynamic_relocs
!= 0
6471 && (h
->root
.type
== bfd_link_hash_defweak
6472 || !h
->def_regular
))
6474 mips_elf_allocate_dynamic_relocations (dynobj
,
6475 hmips
->possibly_dynamic_relocs
);
6476 if (hmips
->readonly_reloc
)
6477 /* We tell the dynamic linker that there are relocations
6478 against the text segment. */
6479 info
->flags
|= DF_TEXTREL
;
6482 /* For a function, create a stub, if allowed. */
6483 if (! hmips
->no_fn_stub
6486 if (! elf_hash_table (info
)->dynamic_sections_created
)
6489 /* If this symbol is not defined in a regular file, then set
6490 the symbol to the stub location. This is required to make
6491 function pointers compare as equal between the normal
6492 executable and the shared library. */
6493 if (!h
->def_regular
)
6495 /* We need .stub section. */
6496 s
= bfd_get_section_by_name (dynobj
,
6497 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
6498 BFD_ASSERT (s
!= NULL
);
6500 h
->root
.u
.def
.section
= s
;
6501 h
->root
.u
.def
.value
= s
->size
;
6503 /* XXX Write this stub address somewhere. */
6504 h
->plt
.offset
= s
->size
;
6506 /* Make room for this stub code. */
6507 s
->size
+= MIPS_FUNCTION_STUB_SIZE
;
6509 /* The last half word of the stub will be filled with the index
6510 of this symbol in .dynsym section. */
6514 else if ((h
->type
== STT_FUNC
)
6517 /* This will set the entry for this symbol in the GOT to 0, and
6518 the dynamic linker will take care of this. */
6519 h
->root
.u
.def
.value
= 0;
6523 /* If this is a weak symbol, and there is a real definition, the
6524 processor independent code will have arranged for us to see the
6525 real definition first, and we can just use the same value. */
6526 if (h
->u
.weakdef
!= NULL
)
6528 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6529 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6530 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6531 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6535 /* This is a reference to a symbol defined by a dynamic object which
6536 is not a function. */
6541 /* This function is called after all the input files have been read,
6542 and the input sections have been assigned to output sections. We
6543 check for any mips16 stub sections that we can discard. */
6546 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
6547 struct bfd_link_info
*info
)
6553 struct mips_got_info
*g
;
6555 bfd_size_type loadable_size
= 0;
6556 bfd_size_type local_gotno
;
6558 struct mips_elf_count_tls_arg count_tls_arg
;
6560 /* The .reginfo section has a fixed size. */
6561 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
6563 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
6565 if (! (info
->relocatable
6566 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
))
6567 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
6568 mips_elf_check_mips16_stubs
, NULL
);
6570 dynobj
= elf_hash_table (info
)->dynobj
;
6572 /* Relocatable links don't have it. */
6575 g
= mips_elf_got_info (dynobj
, &s
);
6579 /* Calculate the total loadable size of the output. That
6580 will give us the maximum number of GOT_PAGE entries
6582 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
6584 asection
*subsection
;
6586 for (subsection
= sub
->sections
;
6588 subsection
= subsection
->next
)
6590 if ((subsection
->flags
& SEC_ALLOC
) == 0)
6592 loadable_size
+= ((subsection
->size
+ 0xf)
6593 &~ (bfd_size_type
) 0xf);
6597 /* There has to be a global GOT entry for every symbol with
6598 a dynamic symbol table index of DT_MIPS_GOTSYM or
6599 higher. Therefore, it make sense to put those symbols
6600 that need GOT entries at the end of the symbol table. We
6602 if (! mips_elf_sort_hash_table (info
, 1))
6605 if (g
->global_gotsym
!= NULL
)
6606 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
6608 /* If there are no global symbols, or none requiring
6609 relocations, then GLOBAL_GOTSYM will be NULL. */
6612 /* In the worst case, we'll get one stub per dynamic symbol, plus
6613 one to account for the dummy entry at the end required by IRIX
6615 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
* (i
+ 1);
6617 /* Assume there are two loadable segments consisting of
6618 contiguous sections. Is 5 enough? */
6619 local_gotno
= (loadable_size
>> 16) + 5;
6621 g
->local_gotno
+= local_gotno
;
6622 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
6624 g
->global_gotno
= i
;
6625 s
->size
+= i
* MIPS_ELF_GOT_SIZE (output_bfd
);
6627 /* We need to calculate tls_gotno for global symbols at this point
6628 instead of building it up earlier, to avoid doublecounting
6629 entries for one global symbol from multiple input files. */
6630 count_tls_arg
.info
= info
;
6631 count_tls_arg
.needed
= 0;
6632 elf_link_hash_traverse (elf_hash_table (info
),
6633 mips_elf_count_global_tls_entries
,
6635 g
->tls_gotno
+= count_tls_arg
.needed
;
6636 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
6638 mips_elf_resolve_final_got_entries (g
);
6640 if (s
->size
> MIPS_ELF_GOT_MAX_SIZE (output_bfd
))
6642 if (! mips_elf_multi_got (output_bfd
, info
, g
, s
, local_gotno
))
6647 /* Set up TLS entries for the first GOT. */
6648 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
6649 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
6655 /* Set the sizes of the dynamic sections. */
6658 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
6659 struct bfd_link_info
*info
)
6663 bfd_boolean reltext
;
6665 dynobj
= elf_hash_table (info
)->dynobj
;
6666 BFD_ASSERT (dynobj
!= NULL
);
6668 if (elf_hash_table (info
)->dynamic_sections_created
)
6670 /* Set the contents of the .interp section to the interpreter. */
6671 if (info
->executable
)
6673 s
= bfd_get_section_by_name (dynobj
, ".interp");
6674 BFD_ASSERT (s
!= NULL
);
6676 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
6678 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
6682 /* The check_relocs and adjust_dynamic_symbol entry points have
6683 determined the sizes of the various dynamic sections. Allocate
6686 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6690 /* It's OK to base decisions on the section name, because none
6691 of the dynobj section names depend upon the input files. */
6692 name
= bfd_get_section_name (dynobj
, s
);
6694 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6697 if (strncmp (name
, ".rel", 4) == 0)
6701 const char *outname
;
6704 /* If this relocation section applies to a read only
6705 section, then we probably need a DT_TEXTREL entry.
6706 If the relocation section is .rel.dyn, we always
6707 assert a DT_TEXTREL entry rather than testing whether
6708 there exists a relocation to a read only section or
6710 outname
= bfd_get_section_name (output_bfd
,
6712 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
6714 && (target
->flags
& SEC_READONLY
) != 0
6715 && (target
->flags
& SEC_ALLOC
) != 0)
6716 || strcmp (outname
, ".rel.dyn") == 0)
6719 /* We use the reloc_count field as a counter if we need
6720 to copy relocs into the output file. */
6721 if (strcmp (name
, ".rel.dyn") != 0)
6724 /* If combreloc is enabled, elf_link_sort_relocs() will
6725 sort relocations, but in a different way than we do,
6726 and before we're done creating relocations. Also, it
6727 will move them around between input sections'
6728 relocation's contents, so our sorting would be
6729 broken, so don't let it run. */
6730 info
->combreloc
= 0;
6733 else if (strncmp (name
, ".got", 4) == 0)
6735 /* _bfd_mips_elf_always_size_sections() has already done
6736 most of the work, but some symbols may have been mapped
6737 to versions that we must now resolve in the got_entries
6739 struct mips_got_info
*gg
= mips_elf_got_info (dynobj
, NULL
);
6740 struct mips_got_info
*g
= gg
;
6741 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
6742 unsigned int needed_relocs
= 0;
6746 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (output_bfd
);
6747 set_got_offset_arg
.info
= info
;
6749 /* NOTE 2005-02-03: How can this call, or the next, ever
6750 find any indirect entries to resolve? They were all
6751 resolved in mips_elf_multi_got. */
6752 mips_elf_resolve_final_got_entries (gg
);
6753 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
6755 unsigned int save_assign
;
6757 mips_elf_resolve_final_got_entries (g
);
6759 /* Assign offsets to global GOT entries. */
6760 save_assign
= g
->assigned_gotno
;
6761 g
->assigned_gotno
= g
->local_gotno
;
6762 set_got_offset_arg
.g
= g
;
6763 set_got_offset_arg
.needed_relocs
= 0;
6764 htab_traverse (g
->got_entries
,
6765 mips_elf_set_global_got_offset
,
6766 &set_got_offset_arg
);
6767 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
6768 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
6769 <= g
->global_gotno
);
6771 g
->assigned_gotno
= save_assign
;
6774 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
6775 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
6776 + g
->next
->global_gotno
6777 + g
->next
->tls_gotno
6778 + MIPS_RESERVED_GOTNO
);
6784 struct mips_elf_count_tls_arg arg
;
6788 htab_traverse (gg
->got_entries
, mips_elf_count_local_tls_relocs
,
6790 elf_link_hash_traverse (elf_hash_table (info
),
6791 mips_elf_count_global_tls_relocs
,
6794 needed_relocs
+= arg
.needed
;
6798 mips_elf_allocate_dynamic_relocations (dynobj
, needed_relocs
);
6800 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
6802 /* IRIX rld assumes that the function stub isn't at the end
6803 of .text section. So put a dummy. XXX */
6804 s
->size
+= MIPS_FUNCTION_STUB_SIZE
;
6806 else if (! info
->shared
6807 && ! mips_elf_hash_table (info
)->use_rld_obj_head
6808 && strncmp (name
, ".rld_map", 8) == 0)
6810 /* We add a room for __rld_map. It will be filled in by the
6811 rtld to contain a pointer to the _r_debug structure. */
6814 else if (SGI_COMPAT (output_bfd
)
6815 && strncmp (name
, ".compact_rel", 12) == 0)
6816 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
6817 else if (strncmp (name
, ".init", 5) != 0)
6819 /* It's not one of our sections, so don't allocate space. */
6825 s
->flags
|= SEC_EXCLUDE
;
6829 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
6832 /* Allocate memory for the section contents. */
6833 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
6834 if (s
->contents
== NULL
)
6836 bfd_set_error (bfd_error_no_memory
);
6841 if (elf_hash_table (info
)->dynamic_sections_created
)
6843 /* Add some entries to the .dynamic section. We fill in the
6844 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
6845 must add the entries now so that we get the correct size for
6846 the .dynamic section. The DT_DEBUG entry is filled in by the
6847 dynamic linker and used by the debugger. */
6850 /* SGI object has the equivalence of DT_DEBUG in the
6851 DT_MIPS_RLD_MAP entry. */
6852 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
6854 if (!SGI_COMPAT (output_bfd
))
6856 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
6862 /* Shared libraries on traditional mips have DT_DEBUG. */
6863 if (!SGI_COMPAT (output_bfd
))
6865 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
6870 if (reltext
&& SGI_COMPAT (output_bfd
))
6871 info
->flags
|= DF_TEXTREL
;
6873 if ((info
->flags
& DF_TEXTREL
) != 0)
6875 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
6879 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
6882 if (mips_elf_rel_dyn_section (dynobj
, FALSE
))
6884 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
6887 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
6890 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
6894 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
6897 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
6900 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
6903 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
6906 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
6909 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
6912 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
6915 if (IRIX_COMPAT (dynobj
) == ict_irix5
6916 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
6919 if (IRIX_COMPAT (dynobj
) == ict_irix6
6920 && (bfd_get_section_by_name
6921 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
6922 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
6929 /* Relocate a MIPS ELF section. */
6932 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
6933 bfd
*input_bfd
, asection
*input_section
,
6934 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
6935 Elf_Internal_Sym
*local_syms
,
6936 asection
**local_sections
)
6938 Elf_Internal_Rela
*rel
;
6939 const Elf_Internal_Rela
*relend
;
6941 bfd_boolean use_saved_addend_p
= FALSE
;
6942 const struct elf_backend_data
*bed
;
6944 bed
= get_elf_backend_data (output_bfd
);
6945 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6946 for (rel
= relocs
; rel
< relend
; ++rel
)
6950 reloc_howto_type
*howto
;
6951 bfd_boolean require_jalx
;
6952 /* TRUE if the relocation is a RELA relocation, rather than a
6954 bfd_boolean rela_relocation_p
= TRUE
;
6955 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
6958 /* Find the relocation howto for this relocation. */
6959 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
6961 /* Some 32-bit code uses R_MIPS_64. In particular, people use
6962 64-bit code, but make sure all their addresses are in the
6963 lowermost or uppermost 32-bit section of the 64-bit address
6964 space. Thus, when they use an R_MIPS_64 they mean what is
6965 usually meant by R_MIPS_32, with the exception that the
6966 stored value is sign-extended to 64 bits. */
6967 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
6969 /* On big-endian systems, we need to lie about the position
6971 if (bfd_big_endian (input_bfd
))
6975 /* NewABI defaults to RELA relocations. */
6976 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
6977 NEWABI_P (input_bfd
)
6978 && (MIPS_RELOC_RELA_P
6979 (input_bfd
, input_section
,
6982 if (!use_saved_addend_p
)
6984 Elf_Internal_Shdr
*rel_hdr
;
6986 /* If these relocations were originally of the REL variety,
6987 we must pull the addend out of the field that will be
6988 relocated. Otherwise, we simply use the contents of the
6989 RELA relocation. To determine which flavor or relocation
6990 this is, we depend on the fact that the INPUT_SECTION's
6991 REL_HDR is read before its REL_HDR2. */
6992 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
6993 if ((size_t) (rel
- relocs
)
6994 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
6995 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
6996 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
6998 bfd_byte
*location
= contents
+ rel
->r_offset
;
7000 /* Note that this is a REL relocation. */
7001 rela_relocation_p
= FALSE
;
7003 /* Get the addend, which is stored in the input file. */
7004 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
,
7006 addend
= mips_elf_obtain_contents (howto
, rel
, input_bfd
,
7008 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, FALSE
,
7011 addend
&= howto
->src_mask
;
7013 /* For some kinds of relocations, the ADDEND is a
7014 combination of the addend stored in two different
7016 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS16_HI16
7017 || (r_type
== R_MIPS_GOT16
7018 && mips_elf_local_relocation_p (input_bfd
, rel
,
7019 local_sections
, FALSE
)))
7022 const Elf_Internal_Rela
*lo16_relocation
;
7023 reloc_howto_type
*lo16_howto
;
7024 bfd_byte
*lo16_location
;
7027 if (r_type
== R_MIPS16_HI16
)
7028 lo16_type
= R_MIPS16_LO16
;
7030 lo16_type
= R_MIPS_LO16
;
7032 /* The combined value is the sum of the HI16 addend,
7033 left-shifted by sixteen bits, and the LO16
7034 addend, sign extended. (Usually, the code does
7035 a `lui' of the HI16 value, and then an `addiu' of
7038 Scan ahead to find a matching LO16 relocation.
7040 According to the MIPS ELF ABI, the R_MIPS_LO16
7041 relocation must be immediately following.
7042 However, for the IRIX6 ABI, the next relocation
7043 may be a composed relocation consisting of
7044 several relocations for the same address. In
7045 that case, the R_MIPS_LO16 relocation may occur
7046 as one of these. We permit a similar extension
7047 in general, as that is useful for GCC. */
7048 lo16_relocation
= mips_elf_next_relocation (input_bfd
,
7051 if (lo16_relocation
== NULL
)
7054 lo16_location
= contents
+ lo16_relocation
->r_offset
;
7056 /* Obtain the addend kept there. */
7057 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
,
7059 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, lo16_type
, FALSE
,
7061 l
= mips_elf_obtain_contents (lo16_howto
, lo16_relocation
,
7062 input_bfd
, contents
);
7063 _bfd_mips16_elf_reloc_shuffle (input_bfd
, lo16_type
, FALSE
,
7065 l
&= lo16_howto
->src_mask
;
7066 l
<<= lo16_howto
->rightshift
;
7067 l
= _bfd_mips_elf_sign_extend (l
, 16);
7071 /* Compute the combined addend. */
7075 addend
<<= howto
->rightshift
;
7078 addend
= rel
->r_addend
;
7081 if (info
->relocatable
)
7083 Elf_Internal_Sym
*sym
;
7084 unsigned long r_symndx
;
7086 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
7087 && bfd_big_endian (input_bfd
))
7090 /* Since we're just relocating, all we need to do is copy
7091 the relocations back out to the object file, unless
7092 they're against a section symbol, in which case we need
7093 to adjust by the section offset, or unless they're GP
7094 relative in which case we need to adjust by the amount
7095 that we're adjusting GP in this relocatable object. */
7097 if (! mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
7099 /* There's nothing to do for non-local relocations. */
7102 if (r_type
== R_MIPS16_GPREL
7103 || r_type
== R_MIPS_GPREL16
7104 || r_type
== R_MIPS_GPREL32
7105 || r_type
== R_MIPS_LITERAL
)
7106 addend
-= (_bfd_get_gp_value (output_bfd
)
7107 - _bfd_get_gp_value (input_bfd
));
7109 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
7110 sym
= local_syms
+ r_symndx
;
7111 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7112 /* Adjust the addend appropriately. */
7113 addend
+= local_sections
[r_symndx
]->output_offset
;
7115 if (rela_relocation_p
)
7116 /* If this is a RELA relocation, just update the addend. */
7117 rel
->r_addend
= addend
;
7120 if (r_type
== R_MIPS_HI16
7121 || r_type
== R_MIPS_GOT16
)
7122 addend
= mips_elf_high (addend
);
7123 else if (r_type
== R_MIPS_HIGHER
)
7124 addend
= mips_elf_higher (addend
);
7125 else if (r_type
== R_MIPS_HIGHEST
)
7126 addend
= mips_elf_highest (addend
);
7128 addend
>>= howto
->rightshift
;
7130 /* We use the source mask, rather than the destination
7131 mask because the place to which we are writing will be
7132 source of the addend in the final link. */
7133 addend
&= howto
->src_mask
;
7135 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
7136 /* See the comment above about using R_MIPS_64 in the 32-bit
7137 ABI. Here, we need to update the addend. It would be
7138 possible to get away with just using the R_MIPS_32 reloc
7139 but for endianness. */
7145 if (addend
& ((bfd_vma
) 1 << 31))
7147 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
7154 /* If we don't know that we have a 64-bit type,
7155 do two separate stores. */
7156 if (bfd_big_endian (input_bfd
))
7158 /* Store the sign-bits (which are most significant)
7160 low_bits
= sign_bits
;
7166 high_bits
= sign_bits
;
7168 bfd_put_32 (input_bfd
, low_bits
,
7169 contents
+ rel
->r_offset
);
7170 bfd_put_32 (input_bfd
, high_bits
,
7171 contents
+ rel
->r_offset
+ 4);
7175 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
7176 input_bfd
, input_section
,
7181 /* Go on to the next relocation. */
7185 /* In the N32 and 64-bit ABIs there may be multiple consecutive
7186 relocations for the same offset. In that case we are
7187 supposed to treat the output of each relocation as the addend
7189 if (rel
+ 1 < relend
7190 && rel
->r_offset
== rel
[1].r_offset
7191 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
7192 use_saved_addend_p
= TRUE
;
7194 use_saved_addend_p
= FALSE
;
7196 /* Figure out what value we are supposed to relocate. */
7197 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
7198 input_section
, info
, rel
,
7199 addend
, howto
, local_syms
,
7200 local_sections
, &value
,
7201 &name
, &require_jalx
,
7202 use_saved_addend_p
))
7204 case bfd_reloc_continue
:
7205 /* There's nothing to do. */
7208 case bfd_reloc_undefined
:
7209 /* mips_elf_calculate_relocation already called the
7210 undefined_symbol callback. There's no real point in
7211 trying to perform the relocation at this point, so we
7212 just skip ahead to the next relocation. */
7215 case bfd_reloc_notsupported
:
7216 msg
= _("internal error: unsupported relocation error");
7217 info
->callbacks
->warning
7218 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
7221 case bfd_reloc_overflow
:
7222 if (use_saved_addend_p
)
7223 /* Ignore overflow until we reach the last relocation for
7224 a given location. */
7228 BFD_ASSERT (name
!= NULL
);
7229 if (! ((*info
->callbacks
->reloc_overflow
)
7230 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
7231 input_bfd
, input_section
, rel
->r_offset
)))
7244 /* If we've got another relocation for the address, keep going
7245 until we reach the last one. */
7246 if (use_saved_addend_p
)
7252 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
7253 /* See the comment above about using R_MIPS_64 in the 32-bit
7254 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
7255 that calculated the right value. Now, however, we
7256 sign-extend the 32-bit result to 64-bits, and store it as a
7257 64-bit value. We are especially generous here in that we
7258 go to extreme lengths to support this usage on systems with
7259 only a 32-bit VMA. */
7265 if (value
& ((bfd_vma
) 1 << 31))
7267 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
7274 /* If we don't know that we have a 64-bit type,
7275 do two separate stores. */
7276 if (bfd_big_endian (input_bfd
))
7278 /* Undo what we did above. */
7280 /* Store the sign-bits (which are most significant)
7282 low_bits
= sign_bits
;
7288 high_bits
= sign_bits
;
7290 bfd_put_32 (input_bfd
, low_bits
,
7291 contents
+ rel
->r_offset
);
7292 bfd_put_32 (input_bfd
, high_bits
,
7293 contents
+ rel
->r_offset
+ 4);
7297 /* Actually perform the relocation. */
7298 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
7299 input_bfd
, input_section
,
7300 contents
, require_jalx
))
7307 /* If NAME is one of the special IRIX6 symbols defined by the linker,
7308 adjust it appropriately now. */
7311 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7312 const char *name
, Elf_Internal_Sym
*sym
)
7314 /* The linker script takes care of providing names and values for
7315 these, but we must place them into the right sections. */
7316 static const char* const text_section_symbols
[] = {
7319 "__dso_displacement",
7321 "__program_header_table",
7325 static const char* const data_section_symbols
[] = {
7333 const char* const *p
;
7336 for (i
= 0; i
< 2; ++i
)
7337 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
7340 if (strcmp (*p
, name
) == 0)
7342 /* All of these symbols are given type STT_SECTION by the
7344 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7345 sym
->st_other
= STO_PROTECTED
;
7347 /* The IRIX linker puts these symbols in special sections. */
7349 sym
->st_shndx
= SHN_MIPS_TEXT
;
7351 sym
->st_shndx
= SHN_MIPS_DATA
;
7357 /* Finish up dynamic symbol handling. We set the contents of various
7358 dynamic sections here. */
7361 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
7362 struct bfd_link_info
*info
,
7363 struct elf_link_hash_entry
*h
,
7364 Elf_Internal_Sym
*sym
)
7368 struct mips_got_info
*g
, *gg
;
7371 dynobj
= elf_hash_table (info
)->dynobj
;
7373 if (h
->plt
.offset
!= MINUS_ONE
)
7376 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
7378 /* This symbol has a stub. Set it up. */
7380 BFD_ASSERT (h
->dynindx
!= -1);
7382 s
= bfd_get_section_by_name (dynobj
,
7383 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7384 BFD_ASSERT (s
!= NULL
);
7386 /* FIXME: Can h->dynindx be more than 64K? */
7387 if (h
->dynindx
& 0xffff0000)
7390 /* Fill the stub. */
7391 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
);
7392 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ 4);
7393 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ 8);
7394 bfd_put_32 (output_bfd
, STUB_LI16 (output_bfd
) + h
->dynindx
, stub
+ 12);
7396 BFD_ASSERT (h
->plt
.offset
<= s
->size
);
7397 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
7399 /* Mark the symbol as undefined. plt.offset != -1 occurs
7400 only for the referenced symbol. */
7401 sym
->st_shndx
= SHN_UNDEF
;
7403 /* The run-time linker uses the st_value field of the symbol
7404 to reset the global offset table entry for this external
7405 to its stub address when unlinking a shared object. */
7406 sym
->st_value
= (s
->output_section
->vma
+ s
->output_offset
7410 BFD_ASSERT (h
->dynindx
!= -1
7411 || h
->forced_local
);
7413 sgot
= mips_elf_got_section (dynobj
, FALSE
);
7414 BFD_ASSERT (sgot
!= NULL
);
7415 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
7416 g
= mips_elf_section_data (sgot
)->u
.got_info
;
7417 BFD_ASSERT (g
!= NULL
);
7419 /* Run through the global symbol table, creating GOT entries for all
7420 the symbols that need them. */
7421 if (g
->global_gotsym
!= NULL
7422 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
7427 value
= sym
->st_value
;
7428 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
, R_MIPS_GOT16
, info
);
7429 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
7432 if (g
->next
&& h
->dynindx
!= -1 && h
->type
!= STT_TLS
)
7434 struct mips_got_entry e
, *p
;
7440 e
.abfd
= output_bfd
;
7442 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
7445 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
7448 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
7453 || (elf_hash_table (info
)->dynamic_sections_created
7455 && p
->d
.h
->root
.def_dynamic
7456 && !p
->d
.h
->root
.def_regular
))
7458 /* Create an R_MIPS_REL32 relocation for this entry. Due to
7459 the various compatibility problems, it's easier to mock
7460 up an R_MIPS_32 or R_MIPS_64 relocation and leave
7461 mips_elf_create_dynamic_relocation to calculate the
7462 appropriate addend. */
7463 Elf_Internal_Rela rel
[3];
7465 memset (rel
, 0, sizeof (rel
));
7466 if (ABI_64_P (output_bfd
))
7467 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
7469 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
7470 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
7473 if (! (mips_elf_create_dynamic_relocation
7474 (output_bfd
, info
, rel
,
7475 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
7479 entry
= sym
->st_value
;
7480 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
7485 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7486 name
= h
->root
.root
.string
;
7487 if (strcmp (name
, "_DYNAMIC") == 0
7488 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
7489 sym
->st_shndx
= SHN_ABS
;
7490 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
7491 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
7493 sym
->st_shndx
= SHN_ABS
;
7494 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7497 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
7499 sym
->st_shndx
= SHN_ABS
;
7500 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7501 sym
->st_value
= elf_gp (output_bfd
);
7503 else if (SGI_COMPAT (output_bfd
))
7505 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
7506 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
7508 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7509 sym
->st_other
= STO_PROTECTED
;
7511 sym
->st_shndx
= SHN_MIPS_DATA
;
7513 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
7515 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
7516 sym
->st_other
= STO_PROTECTED
;
7517 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
7518 sym
->st_shndx
= SHN_ABS
;
7520 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
7522 if (h
->type
== STT_FUNC
)
7523 sym
->st_shndx
= SHN_MIPS_TEXT
;
7524 else if (h
->type
== STT_OBJECT
)
7525 sym
->st_shndx
= SHN_MIPS_DATA
;
7529 /* Handle the IRIX6-specific symbols. */
7530 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
7531 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
7535 if (! mips_elf_hash_table (info
)->use_rld_obj_head
7536 && (strcmp (name
, "__rld_map") == 0
7537 || strcmp (name
, "__RLD_MAP") == 0))
7539 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
7540 BFD_ASSERT (s
!= NULL
);
7541 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
7542 bfd_put_32 (output_bfd
, 0, s
->contents
);
7543 if (mips_elf_hash_table (info
)->rld_value
== 0)
7544 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7546 else if (mips_elf_hash_table (info
)->use_rld_obj_head
7547 && strcmp (name
, "__rld_obj_head") == 0)
7549 /* IRIX6 does not use a .rld_map section. */
7550 if (IRIX_COMPAT (output_bfd
) == ict_irix5
7551 || IRIX_COMPAT (output_bfd
) == ict_none
)
7552 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
7554 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
7558 /* If this is a mips16 symbol, force the value to be even. */
7559 if (sym
->st_other
== STO_MIPS16
)
7560 sym
->st_value
&= ~1;
7565 /* Finish up the dynamic sections. */
7568 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
7569 struct bfd_link_info
*info
)
7574 struct mips_got_info
*gg
, *g
;
7576 dynobj
= elf_hash_table (info
)->dynobj
;
7578 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7580 sgot
= mips_elf_got_section (dynobj
, FALSE
);
7585 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
7586 gg
= mips_elf_section_data (sgot
)->u
.got_info
;
7587 BFD_ASSERT (gg
!= NULL
);
7588 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
7589 BFD_ASSERT (g
!= NULL
);
7592 if (elf_hash_table (info
)->dynamic_sections_created
)
7596 BFD_ASSERT (sdyn
!= NULL
);
7597 BFD_ASSERT (g
!= NULL
);
7599 for (b
= sdyn
->contents
;
7600 b
< sdyn
->contents
+ sdyn
->size
;
7601 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
7603 Elf_Internal_Dyn dyn
;
7607 bfd_boolean swap_out_p
;
7609 /* Read in the current dynamic entry. */
7610 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
7612 /* Assume that we're going to modify it and write it out. */
7618 s
= mips_elf_rel_dyn_section (dynobj
, FALSE
);
7619 BFD_ASSERT (s
!= NULL
);
7620 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
7624 /* Rewrite DT_STRSZ. */
7626 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
7631 s
= bfd_get_section_by_name (output_bfd
, name
);
7632 BFD_ASSERT (s
!= NULL
);
7633 dyn
.d_un
.d_ptr
= s
->vma
;
7636 case DT_MIPS_RLD_VERSION
:
7637 dyn
.d_un
.d_val
= 1; /* XXX */
7641 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
7644 case DT_MIPS_TIME_STAMP
:
7652 case DT_MIPS_ICHECKSUM
:
7657 case DT_MIPS_IVERSION
:
7662 case DT_MIPS_BASE_ADDRESS
:
7663 s
= output_bfd
->sections
;
7664 BFD_ASSERT (s
!= NULL
);
7665 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
7668 case DT_MIPS_LOCAL_GOTNO
:
7669 dyn
.d_un
.d_val
= g
->local_gotno
;
7672 case DT_MIPS_UNREFEXTNO
:
7673 /* The index into the dynamic symbol table which is the
7674 entry of the first external symbol that is not
7675 referenced within the same object. */
7676 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
7679 case DT_MIPS_GOTSYM
:
7680 if (gg
->global_gotsym
)
7682 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
7685 /* In case if we don't have global got symbols we default
7686 to setting DT_MIPS_GOTSYM to the same value as
7687 DT_MIPS_SYMTABNO, so we just fall through. */
7689 case DT_MIPS_SYMTABNO
:
7691 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
7692 s
= bfd_get_section_by_name (output_bfd
, name
);
7693 BFD_ASSERT (s
!= NULL
);
7695 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
7698 case DT_MIPS_HIPAGENO
:
7699 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
7702 case DT_MIPS_RLD_MAP
:
7703 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
7706 case DT_MIPS_OPTIONS
:
7707 s
= (bfd_get_section_by_name
7708 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
7709 dyn
.d_un
.d_ptr
= s
->vma
;
7718 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
7723 /* The first entry of the global offset table will be filled at
7724 runtime. The second entry will be used by some runtime loaders.
7725 This isn't the case of IRIX rld. */
7726 if (sgot
!= NULL
&& sgot
->size
> 0)
7728 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
);
7729 MIPS_ELF_PUT_WORD (output_bfd
, 0x80000000,
7730 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
7734 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
7735 = MIPS_ELF_GOT_SIZE (output_bfd
);
7737 /* Generate dynamic relocations for the non-primary gots. */
7738 if (gg
!= NULL
&& gg
->next
)
7740 Elf_Internal_Rela rel
[3];
7743 memset (rel
, 0, sizeof (rel
));
7744 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
7746 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
7748 bfd_vma index
= g
->next
->local_gotno
+ g
->next
->global_gotno
7749 + g
->next
->tls_gotno
;
7751 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
7752 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
7753 MIPS_ELF_PUT_WORD (output_bfd
, 0x80000000, sgot
->contents
7754 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
7759 while (index
< g
->assigned_gotno
)
7761 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
7762 = index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
7763 if (!(mips_elf_create_dynamic_relocation
7764 (output_bfd
, info
, rel
, NULL
,
7765 bfd_abs_section_ptr
,
7768 BFD_ASSERT (addend
== 0);
7773 /* The generation of dynamic relocations for the non-primary gots
7774 adds more dynamic relocations. We cannot count them until
7777 if (elf_hash_table (info
)->dynamic_sections_created
)
7780 bfd_boolean swap_out_p
;
7782 BFD_ASSERT (sdyn
!= NULL
);
7784 for (b
= sdyn
->contents
;
7785 b
< sdyn
->contents
+ sdyn
->size
;
7786 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
7788 Elf_Internal_Dyn dyn
;
7791 /* Read in the current dynamic entry. */
7792 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
7794 /* Assume that we're going to modify it and write it out. */
7800 /* Reduce DT_RELSZ to account for any relocations we
7801 decided not to make. This is for the n64 irix rld,
7802 which doesn't seem to apply any relocations if there
7803 are trailing null entries. */
7804 s
= mips_elf_rel_dyn_section (dynobj
, FALSE
);
7805 dyn
.d_un
.d_val
= (s
->reloc_count
7806 * (ABI_64_P (output_bfd
)
7807 ? sizeof (Elf64_Mips_External_Rel
)
7808 : sizeof (Elf32_External_Rel
)));
7817 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
7824 Elf32_compact_rel cpt
;
7826 if (SGI_COMPAT (output_bfd
))
7828 /* Write .compact_rel section out. */
7829 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
7833 cpt
.num
= s
->reloc_count
;
7835 cpt
.offset
= (s
->output_section
->filepos
7836 + sizeof (Elf32_External_compact_rel
));
7839 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
7840 ((Elf32_External_compact_rel
*)
7843 /* Clean up a dummy stub function entry in .text. */
7844 s
= bfd_get_section_by_name (dynobj
,
7845 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
7848 file_ptr dummy_offset
;
7850 BFD_ASSERT (s
->size
>= MIPS_FUNCTION_STUB_SIZE
);
7851 dummy_offset
= s
->size
- MIPS_FUNCTION_STUB_SIZE
;
7852 memset (s
->contents
+ dummy_offset
, 0,
7853 MIPS_FUNCTION_STUB_SIZE
);
7858 /* We need to sort the entries of the dynamic relocation section. */
7860 s
= mips_elf_rel_dyn_section (dynobj
, FALSE
);
7863 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
7865 reldyn_sorting_bfd
= output_bfd
;
7867 if (ABI_64_P (output_bfd
))
7868 qsort ((Elf64_External_Rel
*) s
->contents
+ 1, s
->reloc_count
- 1,
7869 sizeof (Elf64_Mips_External_Rel
), sort_dynamic_relocs_64
);
7871 qsort ((Elf32_External_Rel
*) s
->contents
+ 1, s
->reloc_count
- 1,
7872 sizeof (Elf32_External_Rel
), sort_dynamic_relocs
);
7880 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
7883 mips_set_isa_flags (bfd
*abfd
)
7887 switch (bfd_get_mach (abfd
))
7890 case bfd_mach_mips3000
:
7891 val
= E_MIPS_ARCH_1
;
7894 case bfd_mach_mips3900
:
7895 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
7898 case bfd_mach_mips6000
:
7899 val
= E_MIPS_ARCH_2
;
7902 case bfd_mach_mips4000
:
7903 case bfd_mach_mips4300
:
7904 case bfd_mach_mips4400
:
7905 case bfd_mach_mips4600
:
7906 val
= E_MIPS_ARCH_3
;
7909 case bfd_mach_mips4010
:
7910 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
7913 case bfd_mach_mips4100
:
7914 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
7917 case bfd_mach_mips4111
:
7918 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
7921 case bfd_mach_mips4120
:
7922 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
7925 case bfd_mach_mips4650
:
7926 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
7929 case bfd_mach_mips5400
:
7930 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
7933 case bfd_mach_mips5500
:
7934 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
7937 case bfd_mach_mips9000
:
7938 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
7941 case bfd_mach_mips5000
:
7942 case bfd_mach_mips7000
:
7943 case bfd_mach_mips8000
:
7944 case bfd_mach_mips10000
:
7945 case bfd_mach_mips12000
:
7946 val
= E_MIPS_ARCH_4
;
7949 case bfd_mach_mips5
:
7950 val
= E_MIPS_ARCH_5
;
7953 case bfd_mach_mips_sb1
:
7954 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
7957 case bfd_mach_mipsisa32
:
7958 val
= E_MIPS_ARCH_32
;
7961 case bfd_mach_mipsisa64
:
7962 val
= E_MIPS_ARCH_64
;
7965 case bfd_mach_mipsisa32r2
:
7966 val
= E_MIPS_ARCH_32R2
;
7969 case bfd_mach_mipsisa64r2
:
7970 val
= E_MIPS_ARCH_64R2
;
7973 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
7974 elf_elfheader (abfd
)->e_flags
|= val
;
7979 /* The final processing done just before writing out a MIPS ELF object
7980 file. This gets the MIPS architecture right based on the machine
7981 number. This is used by both the 32-bit and the 64-bit ABI. */
7984 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
7985 bfd_boolean linker ATTRIBUTE_UNUSED
)
7988 Elf_Internal_Shdr
**hdrpp
;
7992 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
7993 is nonzero. This is for compatibility with old objects, which used
7994 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
7995 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
7996 mips_set_isa_flags (abfd
);
7998 /* Set the sh_info field for .gptab sections and other appropriate
7999 info for each special section. */
8000 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
8001 i
< elf_numsections (abfd
);
8004 switch ((*hdrpp
)->sh_type
)
8007 case SHT_MIPS_LIBLIST
:
8008 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
8010 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
8013 case SHT_MIPS_GPTAB
:
8014 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
8015 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
8016 BFD_ASSERT (name
!= NULL
8017 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
8018 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
8019 BFD_ASSERT (sec
!= NULL
);
8020 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
8023 case SHT_MIPS_CONTENT
:
8024 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
8025 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
8026 BFD_ASSERT (name
!= NULL
8027 && strncmp (name
, ".MIPS.content",
8028 sizeof ".MIPS.content" - 1) == 0);
8029 sec
= bfd_get_section_by_name (abfd
,
8030 name
+ sizeof ".MIPS.content" - 1);
8031 BFD_ASSERT (sec
!= NULL
);
8032 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
8035 case SHT_MIPS_SYMBOL_LIB
:
8036 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
8038 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
8039 sec
= bfd_get_section_by_name (abfd
, ".liblist");
8041 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
8044 case SHT_MIPS_EVENTS
:
8045 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
8046 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
8047 BFD_ASSERT (name
!= NULL
);
8048 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
8049 sec
= bfd_get_section_by_name (abfd
,
8050 name
+ sizeof ".MIPS.events" - 1);
8053 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
8054 sizeof ".MIPS.post_rel" - 1) == 0);
8055 sec
= bfd_get_section_by_name (abfd
,
8057 + sizeof ".MIPS.post_rel" - 1));
8059 BFD_ASSERT (sec
!= NULL
);
8060 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
8067 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
8071 _bfd_mips_elf_additional_program_headers (bfd
*abfd
)
8076 /* See if we need a PT_MIPS_REGINFO segment. */
8077 s
= bfd_get_section_by_name (abfd
, ".reginfo");
8078 if (s
&& (s
->flags
& SEC_LOAD
))
8081 /* See if we need a PT_MIPS_OPTIONS segment. */
8082 if (IRIX_COMPAT (abfd
) == ict_irix6
8083 && bfd_get_section_by_name (abfd
,
8084 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
8087 /* See if we need a PT_MIPS_RTPROC segment. */
8088 if (IRIX_COMPAT (abfd
) == ict_irix5
8089 && bfd_get_section_by_name (abfd
, ".dynamic")
8090 && bfd_get_section_by_name (abfd
, ".mdebug"))
8096 /* Modify the segment map for an IRIX5 executable. */
8099 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
8100 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
8103 struct elf_segment_map
*m
, **pm
;
8106 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
8108 s
= bfd_get_section_by_name (abfd
, ".reginfo");
8109 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
8111 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
8112 if (m
->p_type
== PT_MIPS_REGINFO
)
8117 m
= bfd_zalloc (abfd
, amt
);
8121 m
->p_type
= PT_MIPS_REGINFO
;
8125 /* We want to put it after the PHDR and INTERP segments. */
8126 pm
= &elf_tdata (abfd
)->segment_map
;
8128 && ((*pm
)->p_type
== PT_PHDR
8129 || (*pm
)->p_type
== PT_INTERP
))
8137 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
8138 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
8139 PT_MIPS_OPTIONS segment immediately following the program header
8142 /* On non-IRIX6 new abi, we'll have already created a segment
8143 for this section, so don't create another. I'm not sure this
8144 is not also the case for IRIX 6, but I can't test it right
8146 && IRIX_COMPAT (abfd
) == ict_irix6
)
8148 for (s
= abfd
->sections
; s
; s
= s
->next
)
8149 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
8154 struct elf_segment_map
*options_segment
;
8156 pm
= &elf_tdata (abfd
)->segment_map
;
8158 && ((*pm
)->p_type
== PT_PHDR
8159 || (*pm
)->p_type
== PT_INTERP
))
8162 amt
= sizeof (struct elf_segment_map
);
8163 options_segment
= bfd_zalloc (abfd
, amt
);
8164 options_segment
->next
= *pm
;
8165 options_segment
->p_type
= PT_MIPS_OPTIONS
;
8166 options_segment
->p_flags
= PF_R
;
8167 options_segment
->p_flags_valid
= TRUE
;
8168 options_segment
->count
= 1;
8169 options_segment
->sections
[0] = s
;
8170 *pm
= options_segment
;
8175 if (IRIX_COMPAT (abfd
) == ict_irix5
)
8177 /* If there are .dynamic and .mdebug sections, we make a room
8178 for the RTPROC header. FIXME: Rewrite without section names. */
8179 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
8180 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
8181 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
8183 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
8184 if (m
->p_type
== PT_MIPS_RTPROC
)
8189 m
= bfd_zalloc (abfd
, amt
);
8193 m
->p_type
= PT_MIPS_RTPROC
;
8195 s
= bfd_get_section_by_name (abfd
, ".rtproc");
8200 m
->p_flags_valid
= 1;
8208 /* We want to put it after the DYNAMIC segment. */
8209 pm
= &elf_tdata (abfd
)->segment_map
;
8210 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
8220 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
8221 .dynstr, .dynsym, and .hash sections, and everything in
8223 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
8225 if ((*pm
)->p_type
== PT_DYNAMIC
)
8228 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
8230 /* For a normal mips executable the permissions for the PT_DYNAMIC
8231 segment are read, write and execute. We do that here since
8232 the code in elf.c sets only the read permission. This matters
8233 sometimes for the dynamic linker. */
8234 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
8236 m
->p_flags
= PF_R
| PF_W
| PF_X
;
8237 m
->p_flags_valid
= 1;
8241 && m
->count
== 1 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
8243 static const char *sec_names
[] =
8245 ".dynamic", ".dynstr", ".dynsym", ".hash"
8249 struct elf_segment_map
*n
;
8253 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
8255 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
8256 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
8263 if (high
< s
->vma
+ sz
)
8269 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
8270 if ((s
->flags
& SEC_LOAD
) != 0
8272 && s
->vma
+ s
->size
<= high
)
8275 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
8276 n
= bfd_zalloc (abfd
, amt
);
8283 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
8285 if ((s
->flags
& SEC_LOAD
) != 0
8287 && s
->vma
+ s
->size
<= high
)
8301 /* Return the section that should be marked against GC for a given
8305 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
8306 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
8307 Elf_Internal_Rela
*rel
,
8308 struct elf_link_hash_entry
*h
,
8309 Elf_Internal_Sym
*sym
)
8311 /* ??? Do mips16 stub sections need to be handled special? */
8315 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
8317 case R_MIPS_GNU_VTINHERIT
:
8318 case R_MIPS_GNU_VTENTRY
:
8322 switch (h
->root
.type
)
8324 case bfd_link_hash_defined
:
8325 case bfd_link_hash_defweak
:
8326 return h
->root
.u
.def
.section
;
8328 case bfd_link_hash_common
:
8329 return h
->root
.u
.c
.p
->section
;
8337 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
8342 /* Update the got entry reference counts for the section being removed. */
8345 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
8346 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
8347 asection
*sec ATTRIBUTE_UNUSED
,
8348 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
8351 Elf_Internal_Shdr
*symtab_hdr
;
8352 struct elf_link_hash_entry
**sym_hashes
;
8353 bfd_signed_vma
*local_got_refcounts
;
8354 const Elf_Internal_Rela
*rel
, *relend
;
8355 unsigned long r_symndx
;
8356 struct elf_link_hash_entry
*h
;
8358 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8359 sym_hashes
= elf_sym_hashes (abfd
);
8360 local_got_refcounts
= elf_local_got_refcounts (abfd
);
8362 relend
= relocs
+ sec
->reloc_count
;
8363 for (rel
= relocs
; rel
< relend
; rel
++)
8364 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
8368 case R_MIPS_CALL_HI16
:
8369 case R_MIPS_CALL_LO16
:
8370 case R_MIPS_GOT_HI16
:
8371 case R_MIPS_GOT_LO16
:
8372 case R_MIPS_GOT_DISP
:
8373 case R_MIPS_GOT_PAGE
:
8374 case R_MIPS_GOT_OFST
:
8375 /* ??? It would seem that the existing MIPS code does no sort
8376 of reference counting or whatnot on its GOT and PLT entries,
8377 so it is not possible to garbage collect them at this time. */
8388 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
8389 hiding the old indirect symbol. Process additional relocation
8390 information. Also called for weakdefs, in which case we just let
8391 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
8394 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
8395 struct elf_link_hash_entry
*dir
,
8396 struct elf_link_hash_entry
*ind
)
8398 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
8400 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
8402 if (ind
->root
.type
!= bfd_link_hash_indirect
)
8405 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
8406 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
8407 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
8408 if (indmips
->readonly_reloc
)
8409 dirmips
->readonly_reloc
= TRUE
;
8410 if (indmips
->no_fn_stub
)
8411 dirmips
->no_fn_stub
= TRUE
;
8413 if (dirmips
->tls_type
== 0)
8414 dirmips
->tls_type
= indmips
->tls_type
;
8418 _bfd_mips_elf_hide_symbol (struct bfd_link_info
*info
,
8419 struct elf_link_hash_entry
*entry
,
8420 bfd_boolean force_local
)
8424 struct mips_got_info
*g
;
8425 struct mips_elf_link_hash_entry
*h
;
8427 h
= (struct mips_elf_link_hash_entry
*) entry
;
8428 if (h
->forced_local
)
8430 h
->forced_local
= force_local
;
8432 dynobj
= elf_hash_table (info
)->dynobj
;
8433 if (dynobj
!= NULL
&& force_local
&& h
->root
.type
!= STT_TLS
8434 && (got
= mips_elf_got_section (dynobj
, FALSE
)) != NULL
8435 && (g
= mips_elf_section_data (got
)->u
.got_info
) != NULL
)
8439 struct mips_got_entry e
;
8440 struct mips_got_info
*gg
= g
;
8442 /* Since we're turning what used to be a global symbol into a
8443 local one, bump up the number of local entries of each GOT
8444 that had an entry for it. This will automatically decrease
8445 the number of global entries, since global_gotno is actually
8446 the upper limit of global entries. */
8452 for (g
= g
->next
; g
!= gg
; g
= g
->next
)
8453 if (htab_find (g
->got_entries
, &e
))
8455 BFD_ASSERT (g
->global_gotno
> 0);
8460 /* If this was a global symbol forced into the primary GOT, we
8461 no longer need an entry for it. We can't release the entry
8462 at this point, but we must at least stop counting it as one
8463 of the symbols that required a forced got entry. */
8464 if (h
->root
.got
.offset
== 2)
8466 BFD_ASSERT (gg
->assigned_gotno
> 0);
8467 gg
->assigned_gotno
--;
8470 else if (g
->global_gotno
== 0 && g
->global_gotsym
== NULL
)
8471 /* If we haven't got through GOT allocation yet, just bump up the
8472 number of local entries, as this symbol won't be counted as
8475 else if (h
->root
.got
.offset
== 1)
8477 /* If we're past non-multi-GOT allocation and this symbol had
8478 been marked for a global got entry, give it a local entry
8480 BFD_ASSERT (g
->global_gotno
> 0);
8486 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
8492 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
8493 struct bfd_link_info
*info
)
8496 bfd_boolean ret
= FALSE
;
8497 unsigned char *tdata
;
8500 o
= bfd_get_section_by_name (abfd
, ".pdr");
8505 if (o
->size
% PDR_SIZE
!= 0)
8507 if (o
->output_section
!= NULL
8508 && bfd_is_abs_section (o
->output_section
))
8511 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
8515 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
8523 cookie
->rel
= cookie
->rels
;
8524 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
8526 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
8528 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
8537 mips_elf_section_data (o
)->u
.tdata
= tdata
;
8538 o
->size
-= skip
* PDR_SIZE
;
8544 if (! info
->keep_memory
)
8545 free (cookie
->rels
);
8551 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
8553 if (strcmp (sec
->name
, ".pdr") == 0)
8559 _bfd_mips_elf_write_section (bfd
*output_bfd
, asection
*sec
,
8562 bfd_byte
*to
, *from
, *end
;
8565 if (strcmp (sec
->name
, ".pdr") != 0)
8568 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
8572 end
= contents
+ sec
->size
;
8573 for (from
= contents
, i
= 0;
8575 from
+= PDR_SIZE
, i
++)
8577 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
8580 memcpy (to
, from
, PDR_SIZE
);
8583 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
8584 sec
->output_offset
, sec
->size
);
8588 /* MIPS ELF uses a special find_nearest_line routine in order the
8589 handle the ECOFF debugging information. */
8591 struct mips_elf_find_line
8593 struct ecoff_debug_info d
;
8594 struct ecoff_find_line i
;
8598 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
8599 asymbol
**symbols
, bfd_vma offset
,
8600 const char **filename_ptr
,
8601 const char **functionname_ptr
,
8602 unsigned int *line_ptr
)
8606 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
8607 filename_ptr
, functionname_ptr
,
8611 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
8612 filename_ptr
, functionname_ptr
,
8613 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
8614 &elf_tdata (abfd
)->dwarf2_find_line_info
))
8617 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
8621 struct mips_elf_find_line
*fi
;
8622 const struct ecoff_debug_swap
* const swap
=
8623 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
8625 /* If we are called during a link, mips_elf_final_link may have
8626 cleared the SEC_HAS_CONTENTS field. We force it back on here
8627 if appropriate (which it normally will be). */
8628 origflags
= msec
->flags
;
8629 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
8630 msec
->flags
|= SEC_HAS_CONTENTS
;
8632 fi
= elf_tdata (abfd
)->find_line_info
;
8635 bfd_size_type external_fdr_size
;
8638 struct fdr
*fdr_ptr
;
8639 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
8641 fi
= bfd_zalloc (abfd
, amt
);
8644 msec
->flags
= origflags
;
8648 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
8650 msec
->flags
= origflags
;
8654 /* Swap in the FDR information. */
8655 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
8656 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
8657 if (fi
->d
.fdr
== NULL
)
8659 msec
->flags
= origflags
;
8662 external_fdr_size
= swap
->external_fdr_size
;
8663 fdr_ptr
= fi
->d
.fdr
;
8664 fraw_src
= (char *) fi
->d
.external_fdr
;
8665 fraw_end
= (fraw_src
8666 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
8667 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
8668 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
8670 elf_tdata (abfd
)->find_line_info
= fi
;
8672 /* Note that we don't bother to ever free this information.
8673 find_nearest_line is either called all the time, as in
8674 objdump -l, so the information should be saved, or it is
8675 rarely called, as in ld error messages, so the memory
8676 wasted is unimportant. Still, it would probably be a
8677 good idea for free_cached_info to throw it away. */
8680 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
8681 &fi
->i
, filename_ptr
, functionname_ptr
,
8684 msec
->flags
= origflags
;
8688 msec
->flags
= origflags
;
8691 /* Fall back on the generic ELF find_nearest_line routine. */
8693 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
8694 filename_ptr
, functionname_ptr
,
8699 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
8700 const char **filename_ptr
,
8701 const char **functionname_ptr
,
8702 unsigned int *line_ptr
)
8705 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
8706 functionname_ptr
, line_ptr
,
8707 & elf_tdata (abfd
)->dwarf2_find_line_info
);
8712 /* When are writing out the .options or .MIPS.options section,
8713 remember the bytes we are writing out, so that we can install the
8714 GP value in the section_processing routine. */
8717 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
8718 const void *location
,
8719 file_ptr offset
, bfd_size_type count
)
8721 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
8725 if (elf_section_data (section
) == NULL
)
8727 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
8728 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
8729 if (elf_section_data (section
) == NULL
)
8732 c
= mips_elf_section_data (section
)->u
.tdata
;
8735 c
= bfd_zalloc (abfd
, section
->size
);
8738 mips_elf_section_data (section
)->u
.tdata
= c
;
8741 memcpy (c
+ offset
, location
, count
);
8744 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
8748 /* This is almost identical to bfd_generic_get_... except that some
8749 MIPS relocations need to be handled specially. Sigh. */
8752 _bfd_elf_mips_get_relocated_section_contents
8754 struct bfd_link_info
*link_info
,
8755 struct bfd_link_order
*link_order
,
8757 bfd_boolean relocatable
,
8760 /* Get enough memory to hold the stuff */
8761 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
8762 asection
*input_section
= link_order
->u
.indirect
.section
;
8765 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
8766 arelent
**reloc_vector
= NULL
;
8772 reloc_vector
= bfd_malloc (reloc_size
);
8773 if (reloc_vector
== NULL
&& reloc_size
!= 0)
8776 /* read in the section */
8777 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
8778 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
8781 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
8785 if (reloc_count
< 0)
8788 if (reloc_count
> 0)
8793 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
8796 struct bfd_hash_entry
*h
;
8797 struct bfd_link_hash_entry
*lh
;
8798 /* Skip all this stuff if we aren't mixing formats. */
8799 if (abfd
&& input_bfd
8800 && abfd
->xvec
== input_bfd
->xvec
)
8804 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
8805 lh
= (struct bfd_link_hash_entry
*) h
;
8812 case bfd_link_hash_undefined
:
8813 case bfd_link_hash_undefweak
:
8814 case bfd_link_hash_common
:
8817 case bfd_link_hash_defined
:
8818 case bfd_link_hash_defweak
:
8820 gp
= lh
->u
.def
.value
;
8822 case bfd_link_hash_indirect
:
8823 case bfd_link_hash_warning
:
8825 /* @@FIXME ignoring warning for now */
8827 case bfd_link_hash_new
:
8836 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
8838 char *error_message
= NULL
;
8839 bfd_reloc_status_type r
;
8841 /* Specific to MIPS: Deal with relocation types that require
8842 knowing the gp of the output bfd. */
8843 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
8845 /* If we've managed to find the gp and have a special
8846 function for the relocation then go ahead, else default
8847 to the generic handling. */
8849 && (*parent
)->howto
->special_function
8850 == _bfd_mips_elf32_gprel16_reloc
)
8851 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
8852 input_section
, relocatable
,
8855 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
8857 relocatable
? abfd
: NULL
,
8862 asection
*os
= input_section
->output_section
;
8864 /* A partial link, so keep the relocs */
8865 os
->orelocation
[os
->reloc_count
] = *parent
;
8869 if (r
!= bfd_reloc_ok
)
8873 case bfd_reloc_undefined
:
8874 if (!((*link_info
->callbacks
->undefined_symbol
)
8875 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
8876 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
8879 case bfd_reloc_dangerous
:
8880 BFD_ASSERT (error_message
!= NULL
);
8881 if (!((*link_info
->callbacks
->reloc_dangerous
)
8882 (link_info
, error_message
, input_bfd
, input_section
,
8883 (*parent
)->address
)))
8886 case bfd_reloc_overflow
:
8887 if (!((*link_info
->callbacks
->reloc_overflow
)
8889 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
8890 (*parent
)->howto
->name
, (*parent
)->addend
,
8891 input_bfd
, input_section
, (*parent
)->address
)))
8894 case bfd_reloc_outofrange
:
8903 if (reloc_vector
!= NULL
)
8904 free (reloc_vector
);
8908 if (reloc_vector
!= NULL
)
8909 free (reloc_vector
);
8913 /* Create a MIPS ELF linker hash table. */
8915 struct bfd_link_hash_table
*
8916 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
8918 struct mips_elf_link_hash_table
*ret
;
8919 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
8921 ret
= bfd_malloc (amt
);
8925 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
8926 mips_elf_link_hash_newfunc
))
8933 /* We no longer use this. */
8934 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
8935 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
8937 ret
->procedure_count
= 0;
8938 ret
->compact_rel_size
= 0;
8939 ret
->use_rld_obj_head
= FALSE
;
8941 ret
->mips16_stubs_seen
= FALSE
;
8943 return &ret
->root
.root
;
8946 /* We need to use a special link routine to handle the .reginfo and
8947 the .mdebug sections. We need to merge all instances of these
8948 sections together, not write them all out sequentially. */
8951 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
8954 struct bfd_link_order
*p
;
8955 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
8956 asection
*rtproc_sec
;
8957 Elf32_RegInfo reginfo
;
8958 struct ecoff_debug_info debug
;
8959 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
8960 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
8961 HDRR
*symhdr
= &debug
.symbolic_header
;
8962 void *mdebug_handle
= NULL
;
8968 static const char * const secname
[] =
8970 ".text", ".init", ".fini", ".data",
8971 ".rodata", ".sdata", ".sbss", ".bss"
8973 static const int sc
[] =
8975 scText
, scInit
, scFini
, scData
,
8976 scRData
, scSData
, scSBss
, scBss
8979 /* We'd carefully arranged the dynamic symbol indices, and then the
8980 generic size_dynamic_sections renumbered them out from under us.
8981 Rather than trying somehow to prevent the renumbering, just do
8983 if (elf_hash_table (info
)->dynamic_sections_created
)
8987 struct mips_got_info
*g
;
8988 bfd_size_type dynsecsymcount
;
8990 /* When we resort, we must tell mips_elf_sort_hash_table what
8991 the lowest index it may use is. That's the number of section
8992 symbols we're going to add. The generic ELF linker only
8993 adds these symbols when building a shared object. Note that
8994 we count the sections after (possibly) removing the .options
9002 for (p
= abfd
->sections
; p
; p
= p
->next
)
9003 if ((p
->flags
& SEC_EXCLUDE
) == 0
9004 && (p
->flags
& SEC_ALLOC
) != 0
9005 && !(*bed
->elf_backend_omit_section_dynsym
) (abfd
, info
, p
))
9009 if (! mips_elf_sort_hash_table (info
, dynsecsymcount
+ 1))
9012 /* Make sure we didn't grow the global .got region. */
9013 dynobj
= elf_hash_table (info
)->dynobj
;
9014 got
= mips_elf_got_section (dynobj
, FALSE
);
9015 g
= mips_elf_section_data (got
)->u
.got_info
;
9017 if (g
->global_gotsym
!= NULL
)
9018 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
9019 - g
->global_gotsym
->dynindx
)
9020 <= g
->global_gotno
);
9023 /* Get a value for the GP register. */
9024 if (elf_gp (abfd
) == 0)
9026 struct bfd_link_hash_entry
*h
;
9028 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
9029 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
9030 elf_gp (abfd
) = (h
->u
.def
.value
9031 + h
->u
.def
.section
->output_section
->vma
9032 + h
->u
.def
.section
->output_offset
);
9033 else if (info
->relocatable
)
9035 bfd_vma lo
= MINUS_ONE
;
9037 /* Find the GP-relative section with the lowest offset. */
9038 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
9040 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
9043 /* And calculate GP relative to that. */
9044 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
9048 /* If the relocate_section function needs to do a reloc
9049 involving the GP value, it should make a reloc_dangerous
9050 callback to warn that GP is not defined. */
9054 /* Go through the sections and collect the .reginfo and .mdebug
9058 gptab_data_sec
= NULL
;
9059 gptab_bss_sec
= NULL
;
9060 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
9062 if (strcmp (o
->name
, ".reginfo") == 0)
9064 memset (®info
, 0, sizeof reginfo
);
9066 /* We have found the .reginfo section in the output file.
9067 Look through all the link_orders comprising it and merge
9068 the information together. */
9069 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
9071 asection
*input_section
;
9073 Elf32_External_RegInfo ext
;
9076 if (p
->type
!= bfd_indirect_link_order
)
9078 if (p
->type
== bfd_data_link_order
)
9083 input_section
= p
->u
.indirect
.section
;
9084 input_bfd
= input_section
->owner
;
9086 if (! bfd_get_section_contents (input_bfd
, input_section
,
9087 &ext
, 0, sizeof ext
))
9090 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
9092 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
9093 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
9094 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
9095 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
9096 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
9098 /* ri_gp_value is set by the function
9099 mips_elf32_section_processing when the section is
9100 finally written out. */
9102 /* Hack: reset the SEC_HAS_CONTENTS flag so that
9103 elf_link_input_bfd ignores this section. */
9104 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
9107 /* Size has been set in _bfd_mips_elf_always_size_sections. */
9108 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
9110 /* Skip this section later on (I don't think this currently
9111 matters, but someday it might). */
9112 o
->map_head
.link_order
= NULL
;
9117 if (strcmp (o
->name
, ".mdebug") == 0)
9119 struct extsym_info einfo
;
9122 /* We have found the .mdebug section in the output file.
9123 Look through all the link_orders comprising it and merge
9124 the information together. */
9125 symhdr
->magic
= swap
->sym_magic
;
9126 /* FIXME: What should the version stamp be? */
9128 symhdr
->ilineMax
= 0;
9132 symhdr
->isymMax
= 0;
9133 symhdr
->ioptMax
= 0;
9134 symhdr
->iauxMax
= 0;
9136 symhdr
->issExtMax
= 0;
9139 symhdr
->iextMax
= 0;
9141 /* We accumulate the debugging information itself in the
9142 debug_info structure. */
9144 debug
.external_dnr
= NULL
;
9145 debug
.external_pdr
= NULL
;
9146 debug
.external_sym
= NULL
;
9147 debug
.external_opt
= NULL
;
9148 debug
.external_aux
= NULL
;
9150 debug
.ssext
= debug
.ssext_end
= NULL
;
9151 debug
.external_fdr
= NULL
;
9152 debug
.external_rfd
= NULL
;
9153 debug
.external_ext
= debug
.external_ext_end
= NULL
;
9155 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
9156 if (mdebug_handle
== NULL
)
9160 esym
.cobol_main
= 0;
9164 esym
.asym
.iss
= issNil
;
9165 esym
.asym
.st
= stLocal
;
9166 esym
.asym
.reserved
= 0;
9167 esym
.asym
.index
= indexNil
;
9169 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
9171 esym
.asym
.sc
= sc
[i
];
9172 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
9175 esym
.asym
.value
= s
->vma
;
9176 last
= s
->vma
+ s
->size
;
9179 esym
.asym
.value
= last
;
9180 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
9185 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
9187 asection
*input_section
;
9189 const struct ecoff_debug_swap
*input_swap
;
9190 struct ecoff_debug_info input_debug
;
9194 if (p
->type
!= bfd_indirect_link_order
)
9196 if (p
->type
== bfd_data_link_order
)
9201 input_section
= p
->u
.indirect
.section
;
9202 input_bfd
= input_section
->owner
;
9204 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
9205 || (get_elf_backend_data (input_bfd
)
9206 ->elf_backend_ecoff_debug_swap
) == NULL
)
9208 /* I don't know what a non MIPS ELF bfd would be
9209 doing with a .mdebug section, but I don't really
9210 want to deal with it. */
9214 input_swap
= (get_elf_backend_data (input_bfd
)
9215 ->elf_backend_ecoff_debug_swap
);
9217 BFD_ASSERT (p
->size
== input_section
->size
);
9219 /* The ECOFF linking code expects that we have already
9220 read in the debugging information and set up an
9221 ecoff_debug_info structure, so we do that now. */
9222 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
9226 if (! (bfd_ecoff_debug_accumulate
9227 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
9228 &input_debug
, input_swap
, info
)))
9231 /* Loop through the external symbols. For each one with
9232 interesting information, try to find the symbol in
9233 the linker global hash table and save the information
9234 for the output external symbols. */
9235 eraw_src
= input_debug
.external_ext
;
9236 eraw_end
= (eraw_src
9237 + (input_debug
.symbolic_header
.iextMax
9238 * input_swap
->external_ext_size
));
9240 eraw_src
< eraw_end
;
9241 eraw_src
+= input_swap
->external_ext_size
)
9245 struct mips_elf_link_hash_entry
*h
;
9247 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
9248 if (ext
.asym
.sc
== scNil
9249 || ext
.asym
.sc
== scUndefined
9250 || ext
.asym
.sc
== scSUndefined
)
9253 name
= input_debug
.ssext
+ ext
.asym
.iss
;
9254 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
9255 name
, FALSE
, FALSE
, TRUE
);
9256 if (h
== NULL
|| h
->esym
.ifd
!= -2)
9262 < input_debug
.symbolic_header
.ifdMax
);
9263 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
9269 /* Free up the information we just read. */
9270 free (input_debug
.line
);
9271 free (input_debug
.external_dnr
);
9272 free (input_debug
.external_pdr
);
9273 free (input_debug
.external_sym
);
9274 free (input_debug
.external_opt
);
9275 free (input_debug
.external_aux
);
9276 free (input_debug
.ss
);
9277 free (input_debug
.ssext
);
9278 free (input_debug
.external_fdr
);
9279 free (input_debug
.external_rfd
);
9280 free (input_debug
.external_ext
);
9282 /* Hack: reset the SEC_HAS_CONTENTS flag so that
9283 elf_link_input_bfd ignores this section. */
9284 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
9287 if (SGI_COMPAT (abfd
) && info
->shared
)
9289 /* Create .rtproc section. */
9290 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
9291 if (rtproc_sec
== NULL
)
9293 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
9294 | SEC_LINKER_CREATED
| SEC_READONLY
);
9296 rtproc_sec
= bfd_make_section_with_flags (abfd
,
9299 if (rtproc_sec
== NULL
9300 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
9304 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
9310 /* Build the external symbol information. */
9313 einfo
.debug
= &debug
;
9315 einfo
.failed
= FALSE
;
9316 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
9317 mips_elf_output_extsym
, &einfo
);
9321 /* Set the size of the .mdebug section. */
9322 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
9324 /* Skip this section later on (I don't think this currently
9325 matters, but someday it might). */
9326 o
->map_head
.link_order
= NULL
;
9331 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
9333 const char *subname
;
9336 Elf32_External_gptab
*ext_tab
;
9339 /* The .gptab.sdata and .gptab.sbss sections hold
9340 information describing how the small data area would
9341 change depending upon the -G switch. These sections
9342 not used in executables files. */
9343 if (! info
->relocatable
)
9345 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
9347 asection
*input_section
;
9349 if (p
->type
!= bfd_indirect_link_order
)
9351 if (p
->type
== bfd_data_link_order
)
9356 input_section
= p
->u
.indirect
.section
;
9358 /* Hack: reset the SEC_HAS_CONTENTS flag so that
9359 elf_link_input_bfd ignores this section. */
9360 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
9363 /* Skip this section later on (I don't think this
9364 currently matters, but someday it might). */
9365 o
->map_head
.link_order
= NULL
;
9367 /* Really remove the section. */
9368 bfd_section_list_remove (abfd
, o
);
9369 --abfd
->section_count
;
9374 /* There is one gptab for initialized data, and one for
9375 uninitialized data. */
9376 if (strcmp (o
->name
, ".gptab.sdata") == 0)
9378 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
9382 (*_bfd_error_handler
)
9383 (_("%s: illegal section name `%s'"),
9384 bfd_get_filename (abfd
), o
->name
);
9385 bfd_set_error (bfd_error_nonrepresentable_section
);
9389 /* The linker script always combines .gptab.data and
9390 .gptab.sdata into .gptab.sdata, and likewise for
9391 .gptab.bss and .gptab.sbss. It is possible that there is
9392 no .sdata or .sbss section in the output file, in which
9393 case we must change the name of the output section. */
9394 subname
= o
->name
+ sizeof ".gptab" - 1;
9395 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
9397 if (o
== gptab_data_sec
)
9398 o
->name
= ".gptab.data";
9400 o
->name
= ".gptab.bss";
9401 subname
= o
->name
+ sizeof ".gptab" - 1;
9402 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
9405 /* Set up the first entry. */
9407 amt
= c
* sizeof (Elf32_gptab
);
9408 tab
= bfd_malloc (amt
);
9411 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
9412 tab
[0].gt_header
.gt_unused
= 0;
9414 /* Combine the input sections. */
9415 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
9417 asection
*input_section
;
9421 bfd_size_type gpentry
;
9423 if (p
->type
!= bfd_indirect_link_order
)
9425 if (p
->type
== bfd_data_link_order
)
9430 input_section
= p
->u
.indirect
.section
;
9431 input_bfd
= input_section
->owner
;
9433 /* Combine the gptab entries for this input section one
9434 by one. We know that the input gptab entries are
9435 sorted by ascending -G value. */
9436 size
= input_section
->size
;
9438 for (gpentry
= sizeof (Elf32_External_gptab
);
9440 gpentry
+= sizeof (Elf32_External_gptab
))
9442 Elf32_External_gptab ext_gptab
;
9443 Elf32_gptab int_gptab
;
9449 if (! (bfd_get_section_contents
9450 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
9451 sizeof (Elf32_External_gptab
))))
9457 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
9459 val
= int_gptab
.gt_entry
.gt_g_value
;
9460 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
9463 for (look
= 1; look
< c
; look
++)
9465 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
9466 tab
[look
].gt_entry
.gt_bytes
+= add
;
9468 if (tab
[look
].gt_entry
.gt_g_value
== val
)
9474 Elf32_gptab
*new_tab
;
9477 /* We need a new table entry. */
9478 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
9479 new_tab
= bfd_realloc (tab
, amt
);
9480 if (new_tab
== NULL
)
9486 tab
[c
].gt_entry
.gt_g_value
= val
;
9487 tab
[c
].gt_entry
.gt_bytes
= add
;
9489 /* Merge in the size for the next smallest -G
9490 value, since that will be implied by this new
9493 for (look
= 1; look
< c
; look
++)
9495 if (tab
[look
].gt_entry
.gt_g_value
< val
9497 || (tab
[look
].gt_entry
.gt_g_value
9498 > tab
[max
].gt_entry
.gt_g_value
)))
9502 tab
[c
].gt_entry
.gt_bytes
+=
9503 tab
[max
].gt_entry
.gt_bytes
;
9508 last
= int_gptab
.gt_entry
.gt_bytes
;
9511 /* Hack: reset the SEC_HAS_CONTENTS flag so that
9512 elf_link_input_bfd ignores this section. */
9513 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
9516 /* The table must be sorted by -G value. */
9518 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
9520 /* Swap out the table. */
9521 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
9522 ext_tab
= bfd_alloc (abfd
, amt
);
9523 if (ext_tab
== NULL
)
9529 for (j
= 0; j
< c
; j
++)
9530 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
9533 o
->size
= c
* sizeof (Elf32_External_gptab
);
9534 o
->contents
= (bfd_byte
*) ext_tab
;
9536 /* Skip this section later on (I don't think this currently
9537 matters, but someday it might). */
9538 o
->map_head
.link_order
= NULL
;
9542 /* Invoke the regular ELF backend linker to do all the work. */
9543 if (!bfd_elf_final_link (abfd
, info
))
9546 /* Now write out the computed sections. */
9548 if (reginfo_sec
!= NULL
)
9550 Elf32_External_RegInfo ext
;
9552 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
9553 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
9557 if (mdebug_sec
!= NULL
)
9559 BFD_ASSERT (abfd
->output_has_begun
);
9560 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
9562 mdebug_sec
->filepos
))
9565 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
9568 if (gptab_data_sec
!= NULL
)
9570 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
9571 gptab_data_sec
->contents
,
9572 0, gptab_data_sec
->size
))
9576 if (gptab_bss_sec
!= NULL
)
9578 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
9579 gptab_bss_sec
->contents
,
9580 0, gptab_bss_sec
->size
))
9584 if (SGI_COMPAT (abfd
))
9586 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
9587 if (rtproc_sec
!= NULL
)
9589 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
9590 rtproc_sec
->contents
,
9591 0, rtproc_sec
->size
))
9599 /* Structure for saying that BFD machine EXTENSION extends BASE. */
9601 struct mips_mach_extension
{
9602 unsigned long extension
, base
;
9606 /* An array describing how BFD machines relate to one another. The entries
9607 are ordered topologically with MIPS I extensions listed last. */
9609 static const struct mips_mach_extension mips_mach_extensions
[] = {
9610 /* MIPS64 extensions. */
9611 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
9612 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
9614 /* MIPS V extensions. */
9615 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
9617 /* R10000 extensions. */
9618 { bfd_mach_mips12000
, bfd_mach_mips10000
},
9620 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
9621 vr5400 ISA, but doesn't include the multimedia stuff. It seems
9622 better to allow vr5400 and vr5500 code to be merged anyway, since
9623 many libraries will just use the core ISA. Perhaps we could add
9624 some sort of ASE flag if this ever proves a problem. */
9625 { bfd_mach_mips5500
, bfd_mach_mips5400
},
9626 { bfd_mach_mips5400
, bfd_mach_mips5000
},
9628 /* MIPS IV extensions. */
9629 { bfd_mach_mips5
, bfd_mach_mips8000
},
9630 { bfd_mach_mips10000
, bfd_mach_mips8000
},
9631 { bfd_mach_mips5000
, bfd_mach_mips8000
},
9632 { bfd_mach_mips7000
, bfd_mach_mips8000
},
9633 { bfd_mach_mips9000
, bfd_mach_mips8000
},
9635 /* VR4100 extensions. */
9636 { bfd_mach_mips4120
, bfd_mach_mips4100
},
9637 { bfd_mach_mips4111
, bfd_mach_mips4100
},
9639 /* MIPS III extensions. */
9640 { bfd_mach_mips8000
, bfd_mach_mips4000
},
9641 { bfd_mach_mips4650
, bfd_mach_mips4000
},
9642 { bfd_mach_mips4600
, bfd_mach_mips4000
},
9643 { bfd_mach_mips4400
, bfd_mach_mips4000
},
9644 { bfd_mach_mips4300
, bfd_mach_mips4000
},
9645 { bfd_mach_mips4100
, bfd_mach_mips4000
},
9646 { bfd_mach_mips4010
, bfd_mach_mips4000
},
9648 /* MIPS32 extensions. */
9649 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
9651 /* MIPS II extensions. */
9652 { bfd_mach_mips4000
, bfd_mach_mips6000
},
9653 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
9655 /* MIPS I extensions. */
9656 { bfd_mach_mips6000
, bfd_mach_mips3000
},
9657 { bfd_mach_mips3900
, bfd_mach_mips3000
}
9661 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
9664 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
9668 if (extension
== base
)
9671 if (base
== bfd_mach_mipsisa32
9672 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
9675 if (base
== bfd_mach_mipsisa32r2
9676 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
9679 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
9680 if (extension
== mips_mach_extensions
[i
].extension
)
9682 extension
= mips_mach_extensions
[i
].base
;
9683 if (extension
== base
)
9691 /* Return true if the given ELF header flags describe a 32-bit binary. */
9694 mips_32bit_flags_p (flagword flags
)
9696 return ((flags
& EF_MIPS_32BITMODE
) != 0
9697 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
9698 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
9699 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
9700 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
9701 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
9702 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
9706 /* Merge backend specific data from an object file to the output
9707 object file when linking. */
9710 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
9715 bfd_boolean null_input_bfd
= TRUE
;
9718 /* Check if we have the same endianess */
9719 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
9721 (*_bfd_error_handler
)
9722 (_("%B: endianness incompatible with that of the selected emulation"),
9727 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
9728 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
9731 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
9733 (*_bfd_error_handler
)
9734 (_("%B: ABI is incompatible with that of the selected emulation"),
9739 new_flags
= elf_elfheader (ibfd
)->e_flags
;
9740 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
9741 old_flags
= elf_elfheader (obfd
)->e_flags
;
9743 if (! elf_flags_init (obfd
))
9745 elf_flags_init (obfd
) = TRUE
;
9746 elf_elfheader (obfd
)->e_flags
= new_flags
;
9747 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
9748 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
9750 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
9751 && bfd_get_arch_info (obfd
)->the_default
)
9753 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
9754 bfd_get_mach (ibfd
)))
9761 /* Check flag compatibility. */
9763 new_flags
&= ~EF_MIPS_NOREORDER
;
9764 old_flags
&= ~EF_MIPS_NOREORDER
;
9766 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
9767 doesn't seem to matter. */
9768 new_flags
&= ~EF_MIPS_XGOT
;
9769 old_flags
&= ~EF_MIPS_XGOT
;
9771 /* MIPSpro generates ucode info in n64 objects. Again, we should
9772 just be able to ignore this. */
9773 new_flags
&= ~EF_MIPS_UCODE
;
9774 old_flags
&= ~EF_MIPS_UCODE
;
9776 if (new_flags
== old_flags
)
9779 /* Check to see if the input BFD actually contains any sections.
9780 If not, its flags may not have been initialised either, but it cannot
9781 actually cause any incompatibility. */
9782 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9784 /* Ignore synthetic sections and empty .text, .data and .bss sections
9785 which are automatically generated by gas. */
9786 if (strcmp (sec
->name
, ".reginfo")
9787 && strcmp (sec
->name
, ".mdebug")
9789 || (strcmp (sec
->name
, ".text")
9790 && strcmp (sec
->name
, ".data")
9791 && strcmp (sec
->name
, ".bss"))))
9793 null_input_bfd
= FALSE
;
9802 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
9803 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
9805 (*_bfd_error_handler
)
9806 (_("%B: warning: linking PIC files with non-PIC files"),
9811 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
9812 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
9813 if (! (new_flags
& EF_MIPS_PIC
))
9814 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
9816 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
9817 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
9819 /* Compare the ISAs. */
9820 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
9822 (*_bfd_error_handler
)
9823 (_("%B: linking 32-bit code with 64-bit code"),
9827 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
9829 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
9830 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
9832 /* Copy the architecture info from IBFD to OBFD. Also copy
9833 the 32-bit flag (if set) so that we continue to recognise
9834 OBFD as a 32-bit binary. */
9835 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
9836 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
9837 elf_elfheader (obfd
)->e_flags
9838 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
9840 /* Copy across the ABI flags if OBFD doesn't use them
9841 and if that was what caused us to treat IBFD as 32-bit. */
9842 if ((old_flags
& EF_MIPS_ABI
) == 0
9843 && mips_32bit_flags_p (new_flags
)
9844 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
9845 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
9849 /* The ISAs aren't compatible. */
9850 (*_bfd_error_handler
)
9851 (_("%B: linking %s module with previous %s modules"),
9853 bfd_printable_name (ibfd
),
9854 bfd_printable_name (obfd
));
9859 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
9860 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
9862 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
9863 does set EI_CLASS differently from any 32-bit ABI. */
9864 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
9865 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
9866 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
9868 /* Only error if both are set (to different values). */
9869 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
9870 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
9871 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
9873 (*_bfd_error_handler
)
9874 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
9876 elf_mips_abi_name (ibfd
),
9877 elf_mips_abi_name (obfd
));
9880 new_flags
&= ~EF_MIPS_ABI
;
9881 old_flags
&= ~EF_MIPS_ABI
;
9884 /* For now, allow arbitrary mixing of ASEs (retain the union). */
9885 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
9887 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
9889 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
9890 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
9893 /* Warn about any other mismatches */
9894 if (new_flags
!= old_flags
)
9896 (*_bfd_error_handler
)
9897 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
9898 ibfd
, (unsigned long) new_flags
,
9899 (unsigned long) old_flags
);
9905 bfd_set_error (bfd_error_bad_value
);
9912 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
9915 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
9917 BFD_ASSERT (!elf_flags_init (abfd
)
9918 || elf_elfheader (abfd
)->e_flags
== flags
);
9920 elf_elfheader (abfd
)->e_flags
= flags
;
9921 elf_flags_init (abfd
) = TRUE
;
9926 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
9930 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
9932 /* Print normal ELF private data. */
9933 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
9935 /* xgettext:c-format */
9936 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
9938 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
9939 fprintf (file
, _(" [abi=O32]"));
9940 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
9941 fprintf (file
, _(" [abi=O64]"));
9942 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
9943 fprintf (file
, _(" [abi=EABI32]"));
9944 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
9945 fprintf (file
, _(" [abi=EABI64]"));
9946 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
9947 fprintf (file
, _(" [abi unknown]"));
9948 else if (ABI_N32_P (abfd
))
9949 fprintf (file
, _(" [abi=N32]"));
9950 else if (ABI_64_P (abfd
))
9951 fprintf (file
, _(" [abi=64]"));
9953 fprintf (file
, _(" [no abi set]"));
9955 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
9956 fprintf (file
, _(" [mips1]"));
9957 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
9958 fprintf (file
, _(" [mips2]"));
9959 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
9960 fprintf (file
, _(" [mips3]"));
9961 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
9962 fprintf (file
, _(" [mips4]"));
9963 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
9964 fprintf (file
, _(" [mips5]"));
9965 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
9966 fprintf (file
, _(" [mips32]"));
9967 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
9968 fprintf (file
, _(" [mips64]"));
9969 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
9970 fprintf (file
, _(" [mips32r2]"));
9971 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
9972 fprintf (file
, _(" [mips64r2]"));
9974 fprintf (file
, _(" [unknown ISA]"));
9976 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
9977 fprintf (file
, _(" [mdmx]"));
9979 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
9980 fprintf (file
, _(" [mips16]"));
9982 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
9983 fprintf (file
, _(" [32bitmode]"));
9985 fprintf (file
, _(" [not 32bitmode]"));
9992 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
9994 { ".lit4", 5, 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
9995 { ".lit8", 5, 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
9996 { ".mdebug", 7, 0, SHT_MIPS_DEBUG
, 0 },
9997 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
9998 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
9999 { ".ucode", 6, 0, SHT_MIPS_UCODE
, 0 },
10000 { NULL
, 0, 0, 0, 0 }
10003 /* Ensure that the STO_OPTIONAL flag is copied into h->other,
10004 even if this is not a defintion of the symbol. */
10006 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
10007 const Elf_Internal_Sym
*isym
,
10008 bfd_boolean definition
,
10009 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
10012 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
10013 h
->other
|= STO_OPTIONAL
;