1 /* MIPS-specific support for ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
;
67 /* The offset from the beginning of the .got section to the entry
68 corresponding to this symbol+addend. If it's a global symbol
69 whose offset is yet to be decided, it's going to be -1. */
73 /* This structure is used to hold .got information when linking. */
77 /* The global symbol in the GOT with the lowest index in the dynamic
79 struct elf_link_hash_entry
*global_gotsym
;
80 /* The number of global .got entries. */
81 unsigned int global_gotno
;
82 /* The number of local .got entries. */
83 unsigned int local_gotno
;
84 /* The number of local .got entries we have used. */
85 unsigned int assigned_gotno
;
86 /* A hash table holding members of the got. */
87 struct htab
*got_entries
;
88 /* A hash table mapping input bfds to other mips_got_info. NULL
89 unless multi-got was necessary. */
91 /* In multi-got links, a pointer to the next got (err, rather, most
92 of the time, it points to the previous got). */
93 struct mips_got_info
*next
;
96 /* Map an input bfd to a got in a multi-got link. */
98 struct mips_elf_bfd2got_hash
{
100 struct mips_got_info
*g
;
103 /* Structure passed when traversing the bfd2got hash table, used to
104 create and merge bfd's gots. */
106 struct mips_elf_got_per_bfd_arg
108 /* A hashtable that maps bfds to gots. */
110 /* The output bfd. */
112 /* The link information. */
113 struct bfd_link_info
*info
;
114 /* A pointer to the primary got, i.e., the one that's going to get
115 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
117 struct mips_got_info
*primary
;
118 /* A non-primary got we're trying to merge with other input bfd's
120 struct mips_got_info
*current
;
121 /* The maximum number of got entries that can be addressed with a
123 unsigned int max_count
;
124 /* The number of local and global entries in the primary got. */
125 unsigned int primary_count
;
126 /* The number of local and global entries in the current got. */
127 unsigned int current_count
;
130 /* Another structure used to pass arguments for got entries traversal. */
132 struct mips_elf_set_global_got_offset_arg
134 struct mips_got_info
*g
;
136 unsigned int needed_relocs
;
137 struct bfd_link_info
*info
;
140 struct _mips_elf_section_data
142 struct bfd_elf_section_data elf
;
145 struct mips_got_info
*got_info
;
150 #define mips_elf_section_data(sec) \
151 ((struct _mips_elf_section_data *) elf_section_data (sec))
153 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
154 the dynamic symbols. */
156 struct mips_elf_hash_sort_data
158 /* The symbol in the global GOT with the lowest dynamic symbol table
160 struct elf_link_hash_entry
*low
;
161 /* The least dynamic symbol table index corresponding to a symbol
163 long min_got_dynindx
;
164 /* The greatest dynamic symbol table index corresponding to a symbol
165 with a GOT entry that is not referenced (e.g., a dynamic symbol
166 with dynamic relocations pointing to it from non-primary GOTs). */
167 long max_unref_got_dynindx
;
168 /* The greatest dynamic symbol table index not corresponding to a
169 symbol without a GOT entry. */
170 long max_non_got_dynindx
;
173 /* The MIPS ELF linker needs additional information for each symbol in
174 the global hash table. */
176 struct mips_elf_link_hash_entry
178 struct elf_link_hash_entry root
;
180 /* External symbol information. */
183 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
185 unsigned int possibly_dynamic_relocs
;
187 /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
188 a readonly section. */
189 bfd_boolean readonly_reloc
;
191 /* We must not create a stub for a symbol that has relocations
192 related to taking the function's address, i.e. any but
193 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
195 bfd_boolean no_fn_stub
;
197 /* If there is a stub that 32 bit functions should use to call this
198 16 bit function, this points to the section containing the stub. */
201 /* Whether we need the fn_stub; this is set if this symbol appears
202 in any relocs other than a 16 bit call. */
203 bfd_boolean need_fn_stub
;
205 /* If there is a stub that 16 bit functions should use to call this
206 32 bit function, this points to the section containing the stub. */
209 /* This is like the call_stub field, but it is used if the function
210 being called returns a floating point value. */
211 asection
*call_fp_stub
;
213 /* Are we forced local? .*/
214 bfd_boolean forced_local
;
217 /* MIPS ELF linker hash table. */
219 struct mips_elf_link_hash_table
221 struct elf_link_hash_table root
;
223 /* We no longer use this. */
224 /* String section indices for the dynamic section symbols. */
225 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
227 /* The number of .rtproc entries. */
228 bfd_size_type procedure_count
;
229 /* The size of the .compact_rel section (if SGI_COMPAT). */
230 bfd_size_type compact_rel_size
;
231 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
232 entry is set to the address of __rld_obj_head as in IRIX5. */
233 bfd_boolean use_rld_obj_head
;
234 /* This is the value of the __rld_map or __rld_obj_head symbol. */
236 /* This is set if we see any mips16 stub sections. */
237 bfd_boolean mips16_stubs_seen
;
240 /* Structure used to pass information to mips_elf_output_extsym. */
245 struct bfd_link_info
*info
;
246 struct ecoff_debug_info
*debug
;
247 const struct ecoff_debug_swap
*swap
;
251 /* The names of the runtime procedure table symbols used on IRIX5. */
253 static const char * const mips_elf_dynsym_rtproc_names
[] =
256 "_procedure_string_table",
257 "_procedure_table_size",
261 /* These structures are used to generate the .compact_rel section on
266 unsigned long id1
; /* Always one? */
267 unsigned long num
; /* Number of compact relocation entries. */
268 unsigned long id2
; /* Always two? */
269 unsigned long offset
; /* The file offset of the first relocation. */
270 unsigned long reserved0
; /* Zero? */
271 unsigned long reserved1
; /* Zero? */
280 bfd_byte reserved0
[4];
281 bfd_byte reserved1
[4];
282 } Elf32_External_compact_rel
;
286 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
287 unsigned int rtype
: 4; /* Relocation types. See below. */
288 unsigned int dist2to
: 8;
289 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
290 unsigned long konst
; /* KONST field. See below. */
291 unsigned long vaddr
; /* VADDR to be relocated. */
296 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
297 unsigned int rtype
: 4; /* Relocation types. See below. */
298 unsigned int dist2to
: 8;
299 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
300 unsigned long konst
; /* KONST field. See below. */
308 } Elf32_External_crinfo
;
314 } Elf32_External_crinfo2
;
316 /* These are the constants used to swap the bitfields in a crinfo. */
318 #define CRINFO_CTYPE (0x1)
319 #define CRINFO_CTYPE_SH (31)
320 #define CRINFO_RTYPE (0xf)
321 #define CRINFO_RTYPE_SH (27)
322 #define CRINFO_DIST2TO (0xff)
323 #define CRINFO_DIST2TO_SH (19)
324 #define CRINFO_RELVADDR (0x7ffff)
325 #define CRINFO_RELVADDR_SH (0)
327 /* A compact relocation info has long (3 words) or short (2 words)
328 formats. A short format doesn't have VADDR field and relvaddr
329 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
330 #define CRF_MIPS_LONG 1
331 #define CRF_MIPS_SHORT 0
333 /* There are 4 types of compact relocation at least. The value KONST
334 has different meaning for each type:
337 CT_MIPS_REL32 Address in data
338 CT_MIPS_WORD Address in word (XXX)
339 CT_MIPS_GPHI_LO GP - vaddr
340 CT_MIPS_JMPAD Address to jump
343 #define CRT_MIPS_REL32 0xa
344 #define CRT_MIPS_WORD 0xb
345 #define CRT_MIPS_GPHI_LO 0xc
346 #define CRT_MIPS_JMPAD 0xd
348 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
349 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
350 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
351 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
353 /* The structure of the runtime procedure descriptor created by the
354 loader for use by the static exception system. */
356 typedef struct runtime_pdr
{
357 bfd_vma adr
; /* Memory address of start of procedure. */
358 long regmask
; /* Save register mask. */
359 long regoffset
; /* Save register offset. */
360 long fregmask
; /* Save floating point register mask. */
361 long fregoffset
; /* Save floating point register offset. */
362 long frameoffset
; /* Frame size. */
363 short framereg
; /* Frame pointer register. */
364 short pcreg
; /* Offset or reg of return pc. */
365 long irpss
; /* Index into the runtime string table. */
367 struct exception_info
*exception_info
;/* Pointer to exception array. */
369 #define cbRPDR sizeof (RPDR)
370 #define rpdNil ((pRPDR) 0)
372 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
373 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
374 static void ecoff_swap_rpdr_out
375 (bfd
*, const RPDR
*, struct rpdr_ext
*);
376 static bfd_boolean mips_elf_create_procedure_table
377 (void *, bfd
*, struct bfd_link_info
*, asection
*,
378 struct ecoff_debug_info
*);
379 static bfd_boolean mips_elf_check_mips16_stubs
380 (struct mips_elf_link_hash_entry
*, void *);
381 static void bfd_mips_elf32_swap_gptab_in
382 (bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*);
383 static void bfd_mips_elf32_swap_gptab_out
384 (bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*);
385 static void bfd_elf32_swap_compact_rel_out
386 (bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*);
387 static void bfd_elf32_swap_crinfo_out
388 (bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*);
389 static int sort_dynamic_relocs
390 (const void *, const void *);
391 static int sort_dynamic_relocs_64
392 (const void *, const void *);
393 static bfd_boolean mips_elf_output_extsym
394 (struct mips_elf_link_hash_entry
*, void *);
395 static int gptab_compare
396 (const void *, const void *);
397 static asection
*mips_elf_rel_dyn_section
398 (bfd
*, bfd_boolean
);
399 static asection
*mips_elf_got_section
400 (bfd
*, bfd_boolean
);
401 static struct mips_got_info
*mips_elf_got_info
402 (bfd
*, asection
**);
403 static long mips_elf_get_global_gotsym_index
405 static bfd_vma mips_elf_local_got_index
406 (bfd
*, bfd
*, struct bfd_link_info
*, bfd_vma
);
407 static bfd_vma mips_elf_global_got_index
408 (bfd
*, bfd
*, struct elf_link_hash_entry
*);
409 static bfd_vma mips_elf_got_page
410 (bfd
*, bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*);
411 static bfd_vma mips_elf_got16_entry
412 (bfd
*, bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_boolean
);
413 static bfd_vma mips_elf_got_offset_from_index
414 (bfd
*, bfd
*, bfd
*, bfd_vma
);
415 static struct mips_got_entry
*mips_elf_create_local_got_entry
416 (bfd
*, bfd
*, struct mips_got_info
*, asection
*, bfd_vma
);
417 static bfd_boolean mips_elf_sort_hash_table
418 (struct bfd_link_info
*, unsigned long);
419 static bfd_boolean mips_elf_sort_hash_table_f
420 (struct mips_elf_link_hash_entry
*, void *);
421 static bfd_boolean mips_elf_record_local_got_symbol
422 (bfd
*, long, bfd_vma
, struct mips_got_info
*);
423 static bfd_boolean mips_elf_record_global_got_symbol
424 (struct elf_link_hash_entry
*, bfd
*, struct bfd_link_info
*,
425 struct mips_got_info
*);
426 static const Elf_Internal_Rela
*mips_elf_next_relocation
427 (bfd
*, unsigned int, const Elf_Internal_Rela
*, const Elf_Internal_Rela
*);
428 static bfd_boolean mips_elf_local_relocation_p
429 (bfd
*, const Elf_Internal_Rela
*, asection
**, bfd_boolean
);
430 static bfd_boolean mips_elf_overflow_p
432 static bfd_vma mips_elf_high
434 static bfd_vma mips_elf_higher
436 static bfd_vma mips_elf_highest
438 static bfd_boolean mips_elf_create_compact_rel_section
439 (bfd
*, struct bfd_link_info
*);
440 static bfd_boolean mips_elf_create_got_section
441 (bfd
*, struct bfd_link_info
*, bfd_boolean
);
442 static bfd_reloc_status_type mips_elf_calculate_relocation
443 (bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
444 const Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
445 Elf_Internal_Sym
*, asection
**, bfd_vma
*, const char **,
446 bfd_boolean
*, bfd_boolean
);
447 static bfd_vma mips_elf_obtain_contents
448 (reloc_howto_type
*, const Elf_Internal_Rela
*, bfd
*, bfd_byte
*);
449 static bfd_boolean mips_elf_perform_relocation
450 (struct bfd_link_info
*, reloc_howto_type
*, const Elf_Internal_Rela
*,
451 bfd_vma
, bfd
*, asection
*, bfd_byte
*, bfd_boolean
);
452 static bfd_boolean mips_elf_stub_section_p
454 static void mips_elf_allocate_dynamic_relocations
455 (bfd
*, unsigned int);
456 static bfd_boolean mips_elf_create_dynamic_relocation
457 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
458 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
459 bfd_vma
*, asection
*);
460 static void mips_set_isa_flags
462 static INLINE
char *elf_mips_abi_name
464 static void mips_elf_irix6_finish_dynamic_symbol
465 (bfd
*, const char *, Elf_Internal_Sym
*);
466 static bfd_boolean mips_mach_extends_p
467 (unsigned long, unsigned long);
468 static bfd_boolean mips_32bit_flags_p
470 static INLINE hashval_t mips_elf_hash_bfd_vma
472 static hashval_t mips_elf_got_entry_hash
474 static int mips_elf_got_entry_eq
475 (const void *, const void *);
477 static bfd_boolean mips_elf_multi_got
478 (bfd
*, struct bfd_link_info
*, struct mips_got_info
*,
479 asection
*, bfd_size_type
);
480 static hashval_t mips_elf_multi_got_entry_hash
482 static int mips_elf_multi_got_entry_eq
483 (const void *, const void *);
484 static hashval_t mips_elf_bfd2got_entry_hash
486 static int mips_elf_bfd2got_entry_eq
487 (const void *, const void *);
488 static int mips_elf_make_got_per_bfd
490 static int mips_elf_merge_gots
492 static int mips_elf_set_global_got_offset
494 static int mips_elf_set_no_stub
496 static int mips_elf_resolve_final_got_entry
498 static void mips_elf_resolve_final_got_entries
499 (struct mips_got_info
*);
500 static bfd_vma mips_elf_adjust_gp
501 (bfd
*, struct mips_got_info
*, bfd
*);
502 static struct mips_got_info
*mips_elf_got_for_ibfd
503 (struct mips_got_info
*, bfd
*);
505 /* This will be used when we sort the dynamic relocation records. */
506 static bfd
*reldyn_sorting_bfd
;
508 /* Nonzero if ABFD is using the N32 ABI. */
510 #define ABI_N32_P(abfd) \
511 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
513 /* Nonzero if ABFD is using the N64 ABI. */
514 #define ABI_64_P(abfd) \
515 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
517 /* Nonzero if ABFD is using NewABI conventions. */
518 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
520 /* The IRIX compatibility level we are striving for. */
521 #define IRIX_COMPAT(abfd) \
522 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
524 /* Whether we are trying to be compatible with IRIX at all. */
525 #define SGI_COMPAT(abfd) \
526 (IRIX_COMPAT (abfd) != ict_none)
528 /* The name of the options section. */
529 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
530 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
532 /* The name of the stub section. */
533 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
534 (NEWABI_P (abfd) ? ".MIPS.stubs" : ".stub")
536 /* The size of an external REL relocation. */
537 #define MIPS_ELF_REL_SIZE(abfd) \
538 (get_elf_backend_data (abfd)->s->sizeof_rel)
540 /* The size of an external dynamic table entry. */
541 #define MIPS_ELF_DYN_SIZE(abfd) \
542 (get_elf_backend_data (abfd)->s->sizeof_dyn)
544 /* The size of a GOT entry. */
545 #define MIPS_ELF_GOT_SIZE(abfd) \
546 (get_elf_backend_data (abfd)->s->arch_size / 8)
548 /* The size of a symbol-table entry. */
549 #define MIPS_ELF_SYM_SIZE(abfd) \
550 (get_elf_backend_data (abfd)->s->sizeof_sym)
552 /* The default alignment for sections, as a power of two. */
553 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
554 (get_elf_backend_data (abfd)->s->log_file_align)
556 /* Get word-sized data. */
557 #define MIPS_ELF_GET_WORD(abfd, ptr) \
558 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
560 /* Put out word-sized data. */
561 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
563 ? bfd_put_64 (abfd, val, ptr) \
564 : bfd_put_32 (abfd, val, ptr))
566 /* Add a dynamic symbol table-entry. */
568 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
569 (ABI_64_P (elf_hash_table (info)->dynobj) \
570 ? bfd_elf64_add_dynamic_entry (info, tag, val) \
571 : bfd_elf32_add_dynamic_entry (info, tag, val))
573 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
574 (ABI_64_P (elf_hash_table (info)->dynobj) \
575 ? (abort (), FALSE) \
576 : bfd_elf32_add_dynamic_entry (info, tag, val))
579 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
580 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
582 /* Determine whether the internal relocation of index REL_IDX is REL
583 (zero) or RELA (non-zero). The assumption is that, if there are
584 two relocation sections for this section, one of them is REL and
585 the other is RELA. If the index of the relocation we're testing is
586 in range for the first relocation section, check that the external
587 relocation size is that for RELA. It is also assumed that, if
588 rel_idx is not in range for the first section, and this first
589 section contains REL relocs, then the relocation is in the second
590 section, that is RELA. */
591 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
592 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
593 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
594 > (bfd_vma)(rel_idx)) \
595 == (elf_section_data (sec)->rel_hdr.sh_entsize \
596 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
597 : sizeof (Elf32_External_Rela))))
599 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
600 from smaller values. Start with zero, widen, *then* decrement. */
601 #define MINUS_ONE (((bfd_vma)0) - 1)
603 /* The number of local .got entries we reserve. */
604 #define MIPS_RESERVED_GOTNO (2)
606 /* The offset of $gp from the beginning of the .got section. */
607 #define ELF_MIPS_GP_OFFSET(abfd) (0x7ff0)
609 /* The maximum size of the GOT for it to be addressable using 16-bit
611 #define MIPS_ELF_GOT_MAX_SIZE(abfd) (ELF_MIPS_GP_OFFSET(abfd) + 0x7fff)
613 /* Instructions which appear in a stub. */
614 #define STUB_LW(abfd) \
616 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
617 : 0x8f998010)) /* lw t9,0x8010(gp) */
618 #define STUB_MOVE(abfd) \
620 ? 0x03e0782d /* daddu t7,ra */ \
621 : 0x03e07821)) /* addu t7,ra */
622 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
623 #define STUB_LI16(abfd) \
625 ? 0x64180000 /* daddiu t8,zero,0 */ \
626 : 0x24180000)) /* addiu t8,zero,0 */
627 #define MIPS_FUNCTION_STUB_SIZE (16)
629 /* The name of the dynamic interpreter. This is put in the .interp
632 #define ELF_DYNAMIC_INTERPRETER(abfd) \
633 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
634 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
635 : "/usr/lib/libc.so.1")
638 #define MNAME(bfd,pre,pos) \
639 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
640 #define ELF_R_SYM(bfd, i) \
641 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
642 #define ELF_R_TYPE(bfd, i) \
643 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
644 #define ELF_R_INFO(bfd, s, t) \
645 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
647 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
648 #define ELF_R_SYM(bfd, i) \
650 #define ELF_R_TYPE(bfd, i) \
652 #define ELF_R_INFO(bfd, s, t) \
653 (ELF32_R_INFO (s, t))
656 /* The mips16 compiler uses a couple of special sections to handle
657 floating point arguments.
659 Section names that look like .mips16.fn.FNNAME contain stubs that
660 copy floating point arguments from the fp regs to the gp regs and
661 then jump to FNNAME. If any 32 bit function calls FNNAME, the
662 call should be redirected to the stub instead. If no 32 bit
663 function calls FNNAME, the stub should be discarded. We need to
664 consider any reference to the function, not just a call, because
665 if the address of the function is taken we will need the stub,
666 since the address might be passed to a 32 bit function.
668 Section names that look like .mips16.call.FNNAME contain stubs
669 that copy floating point arguments from the gp regs to the fp
670 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
671 then any 16 bit function that calls FNNAME should be redirected
672 to the stub instead. If FNNAME is not a 32 bit function, the
673 stub should be discarded.
675 .mips16.call.fp.FNNAME sections are similar, but contain stubs
676 which call FNNAME and then copy the return value from the fp regs
677 to the gp regs. These stubs store the return value in $18 while
678 calling FNNAME; any function which might call one of these stubs
679 must arrange to save $18 around the call. (This case is not
680 needed for 32 bit functions that call 16 bit functions, because
681 16 bit functions always return floating point values in both
684 Note that in all cases FNNAME might be defined statically.
685 Therefore, FNNAME is not used literally. Instead, the relocation
686 information will indicate which symbol the section is for.
688 We record any stubs that we find in the symbol table. */
690 #define FN_STUB ".mips16.fn."
691 #define CALL_STUB ".mips16.call."
692 #define CALL_FP_STUB ".mips16.call.fp."
694 /* Look up an entry in a MIPS ELF linker hash table. */
696 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
697 ((struct mips_elf_link_hash_entry *) \
698 elf_link_hash_lookup (&(table)->root, (string), (create), \
701 /* Traverse a MIPS ELF linker hash table. */
703 #define mips_elf_link_hash_traverse(table, func, info) \
704 (elf_link_hash_traverse \
706 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
709 /* Get the MIPS ELF linker hash table from a link_info structure. */
711 #define mips_elf_hash_table(p) \
712 ((struct mips_elf_link_hash_table *) ((p)->hash))
714 /* Create an entry in a MIPS ELF linker hash table. */
716 static struct bfd_hash_entry
*
717 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
718 struct bfd_hash_table
*table
, const char *string
)
720 struct mips_elf_link_hash_entry
*ret
=
721 (struct mips_elf_link_hash_entry
*) entry
;
723 /* Allocate the structure if it has not already been allocated by a
726 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
728 return (struct bfd_hash_entry
*) ret
;
730 /* Call the allocation method of the superclass. */
731 ret
= ((struct mips_elf_link_hash_entry
*)
732 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
736 /* Set local fields. */
737 memset (&ret
->esym
, 0, sizeof (EXTR
));
738 /* We use -2 as a marker to indicate that the information has
739 not been set. -1 means there is no associated ifd. */
741 ret
->possibly_dynamic_relocs
= 0;
742 ret
->readonly_reloc
= FALSE
;
743 ret
->no_fn_stub
= FALSE
;
745 ret
->need_fn_stub
= FALSE
;
746 ret
->call_stub
= NULL
;
747 ret
->call_fp_stub
= NULL
;
748 ret
->forced_local
= FALSE
;
751 return (struct bfd_hash_entry
*) ret
;
755 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
757 struct _mips_elf_section_data
*sdata
;
758 bfd_size_type amt
= sizeof (*sdata
);
760 sdata
= bfd_zalloc (abfd
, amt
);
763 sec
->used_by_bfd
= sdata
;
765 return _bfd_elf_new_section_hook (abfd
, sec
);
768 /* Read ECOFF debugging information from a .mdebug section into a
769 ecoff_debug_info structure. */
772 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
773 struct ecoff_debug_info
*debug
)
776 const struct ecoff_debug_swap
*swap
;
779 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
780 memset (debug
, 0, sizeof (*debug
));
782 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
783 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
786 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
787 swap
->external_hdr_size
))
790 symhdr
= &debug
->symbolic_header
;
791 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
793 /* The symbolic header contains absolute file offsets and sizes to
795 #define READ(ptr, offset, count, size, type) \
796 if (symhdr->count == 0) \
800 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
801 debug->ptr = bfd_malloc (amt); \
802 if (debug->ptr == NULL) \
804 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
805 || bfd_bread (debug->ptr, amt, abfd) != amt) \
809 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
810 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
811 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
812 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
813 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
814 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
816 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
817 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
818 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
819 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
820 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
824 debug
->adjust
= NULL
;
831 if (debug
->line
!= NULL
)
833 if (debug
->external_dnr
!= NULL
)
834 free (debug
->external_dnr
);
835 if (debug
->external_pdr
!= NULL
)
836 free (debug
->external_pdr
);
837 if (debug
->external_sym
!= NULL
)
838 free (debug
->external_sym
);
839 if (debug
->external_opt
!= NULL
)
840 free (debug
->external_opt
);
841 if (debug
->external_aux
!= NULL
)
842 free (debug
->external_aux
);
843 if (debug
->ss
!= NULL
)
845 if (debug
->ssext
!= NULL
)
847 if (debug
->external_fdr
!= NULL
)
848 free (debug
->external_fdr
);
849 if (debug
->external_rfd
!= NULL
)
850 free (debug
->external_rfd
);
851 if (debug
->external_ext
!= NULL
)
852 free (debug
->external_ext
);
856 /* Swap RPDR (runtime procedure table entry) for output. */
859 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
861 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
862 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
863 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
864 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
865 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
866 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
868 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
869 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
871 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
873 H_PUT_S32 (abfd
, in
->exception_info
, ex
->p_exception_info
);
877 /* Create a runtime procedure table from the .mdebug section. */
880 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
881 struct bfd_link_info
*info
, asection
*s
,
882 struct ecoff_debug_info
*debug
)
884 const struct ecoff_debug_swap
*swap
;
885 HDRR
*hdr
= &debug
->symbolic_header
;
887 struct rpdr_ext
*erp
;
889 struct pdr_ext
*epdr
;
890 struct sym_ext
*esym
;
895 unsigned long sindex
;
899 const char *no_name_func
= _("static procedure (no name)");
907 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
909 sindex
= strlen (no_name_func
) + 1;
913 size
= swap
->external_pdr_size
;
915 epdr
= bfd_malloc (size
* count
);
919 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
922 size
= sizeof (RPDR
);
923 rp
= rpdr
= bfd_malloc (size
* count
);
927 size
= sizeof (char *);
928 sv
= bfd_malloc (size
* count
);
932 count
= hdr
->isymMax
;
933 size
= swap
->external_sym_size
;
934 esym
= bfd_malloc (size
* count
);
938 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
942 ss
= bfd_malloc (count
);
945 if (! _bfd_ecoff_get_accumulated_ss (handle
, ss
))
949 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
951 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
952 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
954 rp
->regmask
= pdr
.regmask
;
955 rp
->regoffset
= pdr
.regoffset
;
956 rp
->fregmask
= pdr
.fregmask
;
957 rp
->fregoffset
= pdr
.fregoffset
;
958 rp
->frameoffset
= pdr
.frameoffset
;
959 rp
->framereg
= pdr
.framereg
;
960 rp
->pcreg
= pdr
.pcreg
;
962 sv
[i
] = ss
+ sym
.iss
;
963 sindex
+= strlen (sv
[i
]) + 1;
967 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
968 size
= BFD_ALIGN (size
, 16);
969 rtproc
= bfd_alloc (abfd
, size
);
972 mips_elf_hash_table (info
)->procedure_count
= 0;
976 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
979 memset (erp
, 0, sizeof (struct rpdr_ext
));
981 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
982 strcpy (str
, no_name_func
);
983 str
+= strlen (no_name_func
) + 1;
984 for (i
= 0; i
< count
; i
++)
986 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
988 str
+= strlen (sv
[i
]) + 1;
990 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
992 /* Set the size and contents of .rtproc section. */
994 s
->contents
= rtproc
;
996 /* Skip this section later on (I don't think this currently
997 matters, but someday it might). */
998 s
->link_order_head
= NULL
;
1027 /* Check the mips16 stubs for a particular symbol, and see if we can
1031 mips_elf_check_mips16_stubs (struct mips_elf_link_hash_entry
*h
,
1032 void *data ATTRIBUTE_UNUSED
)
1034 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1035 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1037 if (h
->fn_stub
!= NULL
1038 && ! h
->need_fn_stub
)
1040 /* We don't need the fn_stub; the only references to this symbol
1041 are 16 bit calls. Clobber the size to 0 to prevent it from
1042 being included in the link. */
1043 h
->fn_stub
->_raw_size
= 0;
1044 h
->fn_stub
->_cooked_size
= 0;
1045 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1046 h
->fn_stub
->reloc_count
= 0;
1047 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1050 if (h
->call_stub
!= NULL
1051 && h
->root
.other
== STO_MIPS16
)
1053 /* We don't need the call_stub; this is a 16 bit function, so
1054 calls from other 16 bit functions are OK. Clobber the size
1055 to 0 to prevent it from being included in the link. */
1056 h
->call_stub
->_raw_size
= 0;
1057 h
->call_stub
->_cooked_size
= 0;
1058 h
->call_stub
->flags
&= ~SEC_RELOC
;
1059 h
->call_stub
->reloc_count
= 0;
1060 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1063 if (h
->call_fp_stub
!= NULL
1064 && h
->root
.other
== STO_MIPS16
)
1066 /* We don't need the call_stub; this is a 16 bit function, so
1067 calls from other 16 bit functions are OK. Clobber the size
1068 to 0 to prevent it from being included in the link. */
1069 h
->call_fp_stub
->_raw_size
= 0;
1070 h
->call_fp_stub
->_cooked_size
= 0;
1071 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1072 h
->call_fp_stub
->reloc_count
= 0;
1073 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1079 bfd_reloc_status_type
1080 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1081 arelent
*reloc_entry
, asection
*input_section
,
1082 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1085 unsigned long insn
= 0;
1088 if (bfd_is_com_section (symbol
->section
))
1091 relocation
= symbol
->value
;
1093 relocation
+= symbol
->section
->output_section
->vma
;
1094 relocation
+= symbol
->section
->output_offset
;
1096 if (reloc_entry
->address
> input_section
->_cooked_size
)
1097 return bfd_reloc_outofrange
;
1099 /* Set val to the offset into the section or symbol. */
1100 val
= reloc_entry
->addend
;
1102 if (reloc_entry
->howto
->partial_inplace
)
1104 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1105 val
+= insn
& 0xffff;
1108 _bfd_mips_elf_sign_extend(val
, 16);
1110 /* Adjust val for the final section location and GP value. If we
1111 are producing relocatable output, we don't want to do this for
1112 an external symbol. */
1114 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1115 val
+= relocation
- gp
;
1117 if (reloc_entry
->howto
->partial_inplace
)
1119 insn
= (insn
& ~0xffff) | (val
& 0xffff);
1120 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1123 reloc_entry
->addend
= val
;
1126 reloc_entry
->address
+= input_section
->output_offset
;
1127 else if (((val
& ~0xffff) != ~0xffff) && ((val
& ~0xffff) != 0))
1128 return bfd_reloc_overflow
;
1130 return bfd_reloc_ok
;
1133 /* Swap an entry in a .gptab section. Note that these routines rely
1134 on the equivalence of the two elements of the union. */
1137 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
1140 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1141 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1145 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
1146 Elf32_External_gptab
*ex
)
1148 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
1149 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
1153 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
1154 Elf32_External_compact_rel
*ex
)
1156 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1157 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1158 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1159 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1160 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1161 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1165 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
1166 Elf32_External_crinfo
*ex
)
1170 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1171 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1172 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1173 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1174 H_PUT_32 (abfd
, l
, ex
->info
);
1175 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1176 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1179 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1180 routines swap this structure in and out. They are used outside of
1181 BFD, so they are globally visible. */
1184 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
1187 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1188 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1189 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1190 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1191 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1192 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1196 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
1197 Elf32_External_RegInfo
*ex
)
1199 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1200 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1201 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1202 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1203 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1204 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1207 /* In the 64 bit ABI, the .MIPS.options section holds register
1208 information in an Elf64_Reginfo structure. These routines swap
1209 them in and out. They are globally visible because they are used
1210 outside of BFD. These routines are here so that gas can call them
1211 without worrying about whether the 64 bit ABI has been included. */
1214 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
1215 Elf64_Internal_RegInfo
*in
)
1217 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1218 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1219 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1220 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1221 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1222 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1223 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1227 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
1228 Elf64_External_RegInfo
*ex
)
1230 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1231 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1232 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1233 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1234 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1235 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1236 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1239 /* Swap in an options header. */
1242 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
1243 Elf_Internal_Options
*in
)
1245 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1246 in
->size
= H_GET_8 (abfd
, ex
->size
);
1247 in
->section
= H_GET_16 (abfd
, ex
->section
);
1248 in
->info
= H_GET_32 (abfd
, ex
->info
);
1251 /* Swap out an options header. */
1254 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
1255 Elf_External_Options
*ex
)
1257 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1258 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1259 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1260 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1263 /* This function is called via qsort() to sort the dynamic relocation
1264 entries by increasing r_symndx value. */
1267 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
1269 Elf_Internal_Rela int_reloc1
;
1270 Elf_Internal_Rela int_reloc2
;
1272 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1273 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1275 return ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
1278 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
1281 sort_dynamic_relocs_64 (const void *arg1
, const void *arg2
)
1283 Elf_Internal_Rela int_reloc1
[3];
1284 Elf_Internal_Rela int_reloc2
[3];
1286 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1287 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
1288 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
1289 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
1291 return (ELF64_R_SYM (int_reloc1
[0].r_info
)
1292 - ELF64_R_SYM (int_reloc2
[0].r_info
));
1296 /* This routine is used to write out ECOFF debugging external symbol
1297 information. It is called via mips_elf_link_hash_traverse. The
1298 ECOFF external symbol information must match the ELF external
1299 symbol information. Unfortunately, at this point we don't know
1300 whether a symbol is required by reloc information, so the two
1301 tables may wind up being different. We must sort out the external
1302 symbol information before we can set the final size of the .mdebug
1303 section, and we must set the size of the .mdebug section before we
1304 can relocate any sections, and we can't know which symbols are
1305 required by relocation until we relocate the sections.
1306 Fortunately, it is relatively unlikely that any symbol will be
1307 stripped but required by a reloc. In particular, it can not happen
1308 when generating a final executable. */
1311 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
1313 struct extsym_info
*einfo
= data
;
1315 asection
*sec
, *output_section
;
1317 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1318 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1320 if (h
->root
.indx
== -2)
1322 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1323 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
1324 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
1325 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
1327 else if (einfo
->info
->strip
== strip_all
1328 || (einfo
->info
->strip
== strip_some
1329 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1330 h
->root
.root
.root
.string
,
1331 FALSE
, FALSE
) == NULL
))
1339 if (h
->esym
.ifd
== -2)
1342 h
->esym
.cobol_main
= 0;
1343 h
->esym
.weakext
= 0;
1344 h
->esym
.reserved
= 0;
1345 h
->esym
.ifd
= ifdNil
;
1346 h
->esym
.asym
.value
= 0;
1347 h
->esym
.asym
.st
= stGlobal
;
1349 if (h
->root
.root
.type
== bfd_link_hash_undefined
1350 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
1354 /* Use undefined class. Also, set class and type for some
1356 name
= h
->root
.root
.root
.string
;
1357 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
1358 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
1360 h
->esym
.asym
.sc
= scData
;
1361 h
->esym
.asym
.st
= stLabel
;
1362 h
->esym
.asym
.value
= 0;
1364 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
1366 h
->esym
.asym
.sc
= scAbs
;
1367 h
->esym
.asym
.st
= stLabel
;
1368 h
->esym
.asym
.value
=
1369 mips_elf_hash_table (einfo
->info
)->procedure_count
;
1371 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
1373 h
->esym
.asym
.sc
= scAbs
;
1374 h
->esym
.asym
.st
= stLabel
;
1375 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
1378 h
->esym
.asym
.sc
= scUndefined
;
1380 else if (h
->root
.root
.type
!= bfd_link_hash_defined
1381 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1382 h
->esym
.asym
.sc
= scAbs
;
1387 sec
= h
->root
.root
.u
.def
.section
;
1388 output_section
= sec
->output_section
;
1390 /* When making a shared library and symbol h is the one from
1391 the another shared library, OUTPUT_SECTION may be null. */
1392 if (output_section
== NULL
)
1393 h
->esym
.asym
.sc
= scUndefined
;
1396 name
= bfd_section_name (output_section
->owner
, output_section
);
1398 if (strcmp (name
, ".text") == 0)
1399 h
->esym
.asym
.sc
= scText
;
1400 else if (strcmp (name
, ".data") == 0)
1401 h
->esym
.asym
.sc
= scData
;
1402 else if (strcmp (name
, ".sdata") == 0)
1403 h
->esym
.asym
.sc
= scSData
;
1404 else if (strcmp (name
, ".rodata") == 0
1405 || strcmp (name
, ".rdata") == 0)
1406 h
->esym
.asym
.sc
= scRData
;
1407 else if (strcmp (name
, ".bss") == 0)
1408 h
->esym
.asym
.sc
= scBss
;
1409 else if (strcmp (name
, ".sbss") == 0)
1410 h
->esym
.asym
.sc
= scSBss
;
1411 else if (strcmp (name
, ".init") == 0)
1412 h
->esym
.asym
.sc
= scInit
;
1413 else if (strcmp (name
, ".fini") == 0)
1414 h
->esym
.asym
.sc
= scFini
;
1416 h
->esym
.asym
.sc
= scAbs
;
1420 h
->esym
.asym
.reserved
= 0;
1421 h
->esym
.asym
.index
= indexNil
;
1424 if (h
->root
.root
.type
== bfd_link_hash_common
)
1425 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1426 else if (h
->root
.root
.type
== bfd_link_hash_defined
1427 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1429 if (h
->esym
.asym
.sc
== scCommon
)
1430 h
->esym
.asym
.sc
= scBss
;
1431 else if (h
->esym
.asym
.sc
== scSCommon
)
1432 h
->esym
.asym
.sc
= scSBss
;
1434 sec
= h
->root
.root
.u
.def
.section
;
1435 output_section
= sec
->output_section
;
1436 if (output_section
!= NULL
)
1437 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1438 + sec
->output_offset
1439 + output_section
->vma
);
1441 h
->esym
.asym
.value
= 0;
1443 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1445 struct mips_elf_link_hash_entry
*hd
= h
;
1446 bfd_boolean no_fn_stub
= h
->no_fn_stub
;
1448 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
1450 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
1451 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
1456 /* Set type and value for a symbol with a function stub. */
1457 h
->esym
.asym
.st
= stProc
;
1458 sec
= hd
->root
.root
.u
.def
.section
;
1460 h
->esym
.asym
.value
= 0;
1463 output_section
= sec
->output_section
;
1464 if (output_section
!= NULL
)
1465 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
1466 + sec
->output_offset
1467 + output_section
->vma
);
1469 h
->esym
.asym
.value
= 0;
1477 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1478 h
->root
.root
.root
.string
,
1481 einfo
->failed
= TRUE
;
1488 /* A comparison routine used to sort .gptab entries. */
1491 gptab_compare (const void *p1
, const void *p2
)
1493 const Elf32_gptab
*a1
= p1
;
1494 const Elf32_gptab
*a2
= p2
;
1496 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
1499 /* Functions to manage the got entry hash table. */
1501 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
1504 static INLINE hashval_t
1505 mips_elf_hash_bfd_vma (bfd_vma addr
)
1508 return addr
+ (addr
>> 32);
1514 /* got_entries only match if they're identical, except for gotidx, so
1515 use all fields to compute the hash, and compare the appropriate
1519 mips_elf_got_entry_hash (const void *entry_
)
1521 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
1523 return entry
->symndx
1524 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
1526 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
1527 : entry
->d
.h
->root
.root
.root
.hash
));
1531 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
1533 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
1534 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
1536 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
1537 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
1538 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
1539 : e1
->d
.h
== e2
->d
.h
);
1542 /* multi_got_entries are still a match in the case of global objects,
1543 even if the input bfd in which they're referenced differs, so the
1544 hash computation and compare functions are adjusted
1548 mips_elf_multi_got_entry_hash (const void *entry_
)
1550 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
1552 return entry
->symndx
1554 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
1555 : entry
->symndx
>= 0
1557 + mips_elf_hash_bfd_vma (entry
->d
.addend
))
1558 : entry
->d
.h
->root
.root
.root
.hash
);
1562 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
1564 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
1565 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
1567 return e1
->symndx
== e2
->symndx
1568 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
1569 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
1570 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
1571 : e1
->d
.h
== e2
->d
.h
);
1574 /* Returns the dynamic relocation section for DYNOBJ. */
1577 mips_elf_rel_dyn_section (bfd
*dynobj
, bfd_boolean create_p
)
1579 static const char dname
[] = ".rel.dyn";
1582 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
1583 if (sreloc
== NULL
&& create_p
)
1585 sreloc
= bfd_make_section (dynobj
, dname
);
1587 || ! bfd_set_section_flags (dynobj
, sreloc
,
1592 | SEC_LINKER_CREATED
1594 || ! bfd_set_section_alignment (dynobj
, sreloc
,
1595 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
1601 /* Returns the GOT section for ABFD. */
1604 mips_elf_got_section (bfd
*abfd
, bfd_boolean maybe_excluded
)
1606 asection
*sgot
= bfd_get_section_by_name (abfd
, ".got");
1608 || (! maybe_excluded
&& (sgot
->flags
& SEC_EXCLUDE
) != 0))
1613 /* Returns the GOT information associated with the link indicated by
1614 INFO. If SGOTP is non-NULL, it is filled in with the GOT
1617 static struct mips_got_info
*
1618 mips_elf_got_info (bfd
*abfd
, asection
**sgotp
)
1621 struct mips_got_info
*g
;
1623 sgot
= mips_elf_got_section (abfd
, TRUE
);
1624 BFD_ASSERT (sgot
!= NULL
);
1625 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
1626 g
= mips_elf_section_data (sgot
)->u
.got_info
;
1627 BFD_ASSERT (g
!= NULL
);
1630 *sgotp
= (sgot
->flags
& SEC_EXCLUDE
) == 0 ? sgot
: NULL
;
1635 /* Obtain the lowest dynamic index of a symbol that was assigned a
1636 global GOT entry. */
1638 mips_elf_get_global_gotsym_index (bfd
*abfd
)
1641 struct mips_got_info
*g
;
1646 sgot
= mips_elf_got_section (abfd
, TRUE
);
1647 if (sgot
== NULL
|| mips_elf_section_data (sgot
) == NULL
)
1650 g
= mips_elf_section_data (sgot
)->u
.got_info
;
1651 if (g
== NULL
|| g
->global_gotsym
== NULL
)
1654 return g
->global_gotsym
->dynindx
;
1657 /* Returns the GOT offset at which the indicated address can be found.
1658 If there is not yet a GOT entry for this value, create one. Returns
1659 -1 if no satisfactory GOT offset can be found. */
1662 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
1666 struct mips_got_info
*g
;
1667 struct mips_got_entry
*entry
;
1669 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1671 entry
= mips_elf_create_local_got_entry (abfd
, ibfd
, g
, sgot
, value
);
1673 return entry
->gotidx
;
1678 /* Returns the GOT index for the global symbol indicated by H. */
1681 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
)
1685 struct mips_got_info
*g
, *gg
;
1686 long global_got_dynindx
= 0;
1688 gg
= g
= mips_elf_got_info (abfd
, &sgot
);
1689 if (g
->bfd2got
&& ibfd
)
1691 struct mips_got_entry e
, *p
;
1693 BFD_ASSERT (h
->dynindx
>= 0);
1695 g
= mips_elf_got_for_ibfd (g
, ibfd
);
1700 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
1702 p
= htab_find (g
->got_entries
, &e
);
1704 BFD_ASSERT (p
->gotidx
> 0);
1709 if (gg
->global_gotsym
!= NULL
)
1710 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
1712 /* Once we determine the global GOT entry with the lowest dynamic
1713 symbol table index, we must put all dynamic symbols with greater
1714 indices into the GOT. That makes it easy to calculate the GOT
1716 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
1717 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
1718 * MIPS_ELF_GOT_SIZE (abfd
));
1719 BFD_ASSERT (index
< sgot
->_raw_size
);
1724 /* Find a GOT entry that is within 32KB of the VALUE. These entries
1725 are supposed to be placed at small offsets in the GOT, i.e.,
1726 within 32KB of GP. Return the index into the GOT for this page,
1727 and store the offset from this entry to the desired address in
1728 OFFSETP, if it is non-NULL. */
1731 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
1732 bfd_vma value
, bfd_vma
*offsetp
)
1735 struct mips_got_info
*g
;
1737 struct mips_got_entry
*entry
;
1739 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1741 entry
= mips_elf_create_local_got_entry (abfd
, ibfd
, g
, sgot
,
1743 & (~(bfd_vma
)0xffff));
1748 index
= entry
->gotidx
;
1751 *offsetp
= value
- entry
->d
.address
;
1756 /* Find a GOT entry whose higher-order 16 bits are the same as those
1757 for value. Return the index into the GOT for this entry. */
1760 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
1761 bfd_vma value
, bfd_boolean external
)
1764 struct mips_got_info
*g
;
1765 struct mips_got_entry
*entry
;
1769 /* Although the ABI says that it is "the high-order 16 bits" that we
1770 want, it is really the %high value. The complete value is
1771 calculated with a `addiu' of a LO16 relocation, just as with a
1773 value
= mips_elf_high (value
) << 16;
1776 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1778 entry
= mips_elf_create_local_got_entry (abfd
, ibfd
, g
, sgot
, value
);
1780 return entry
->gotidx
;
1785 /* Returns the offset for the entry at the INDEXth position
1789 mips_elf_got_offset_from_index (bfd
*dynobj
, bfd
*output_bfd
,
1790 bfd
*input_bfd
, bfd_vma index
)
1794 struct mips_got_info
*g
;
1796 g
= mips_elf_got_info (dynobj
, &sgot
);
1797 gp
= _bfd_get_gp_value (output_bfd
)
1798 + mips_elf_adjust_gp (output_bfd
, g
, input_bfd
);
1800 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
1803 /* Create a local GOT entry for VALUE. Return the index of the entry,
1804 or -1 if it could not be created. */
1806 static struct mips_got_entry
*
1807 mips_elf_create_local_got_entry (bfd
*abfd
, bfd
*ibfd
,
1808 struct mips_got_info
*gg
,
1809 asection
*sgot
, bfd_vma value
)
1811 struct mips_got_entry entry
, **loc
;
1812 struct mips_got_info
*g
;
1816 entry
.d
.address
= value
;
1818 g
= mips_elf_got_for_ibfd (gg
, ibfd
);
1821 g
= mips_elf_got_for_ibfd (gg
, abfd
);
1822 BFD_ASSERT (g
!= NULL
);
1825 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
1830 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
1832 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
1837 memcpy (*loc
, &entry
, sizeof entry
);
1839 if (g
->assigned_gotno
>= g
->local_gotno
)
1841 (*loc
)->gotidx
= -1;
1842 /* We didn't allocate enough space in the GOT. */
1843 (*_bfd_error_handler
)
1844 (_("not enough GOT space for local GOT entries"));
1845 bfd_set_error (bfd_error_bad_value
);
1849 MIPS_ELF_PUT_WORD (abfd
, value
,
1850 (sgot
->contents
+ entry
.gotidx
));
1855 /* Sort the dynamic symbol table so that symbols that need GOT entries
1856 appear towards the end. This reduces the amount of GOT space
1857 required. MAX_LOCAL is used to set the number of local symbols
1858 known to be in the dynamic symbol table. During
1859 _bfd_mips_elf_size_dynamic_sections, this value is 1. Afterward, the
1860 section symbols are added and the count is higher. */
1863 mips_elf_sort_hash_table (struct bfd_link_info
*info
, unsigned long max_local
)
1865 struct mips_elf_hash_sort_data hsd
;
1866 struct mips_got_info
*g
;
1869 dynobj
= elf_hash_table (info
)->dynobj
;
1871 g
= mips_elf_got_info (dynobj
, NULL
);
1874 hsd
.max_unref_got_dynindx
=
1875 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
1876 /* In the multi-got case, assigned_gotno of the master got_info
1877 indicate the number of entries that aren't referenced in the
1878 primary GOT, but that must have entries because there are
1879 dynamic relocations that reference it. Since they aren't
1880 referenced, we move them to the end of the GOT, so that they
1881 don't prevent other entries that are referenced from getting
1882 too large offsets. */
1883 - (g
->next
? g
->assigned_gotno
: 0);
1884 hsd
.max_non_got_dynindx
= max_local
;
1885 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
1886 elf_hash_table (info
)),
1887 mips_elf_sort_hash_table_f
,
1890 /* There should have been enough room in the symbol table to
1891 accommodate both the GOT and non-GOT symbols. */
1892 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
1893 BFD_ASSERT ((unsigned long)hsd
.max_unref_got_dynindx
1894 <= elf_hash_table (info
)->dynsymcount
);
1896 /* Now we know which dynamic symbol has the lowest dynamic symbol
1897 table index in the GOT. */
1898 g
->global_gotsym
= hsd
.low
;
1903 /* If H needs a GOT entry, assign it the highest available dynamic
1904 index. Otherwise, assign it the lowest available dynamic
1908 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
1910 struct mips_elf_hash_sort_data
*hsd
= data
;
1912 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1913 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1915 /* Symbols without dynamic symbol table entries aren't interesting
1917 if (h
->root
.dynindx
== -1)
1920 /* Global symbols that need GOT entries that are not explicitly
1921 referenced are marked with got offset 2. Those that are
1922 referenced get a 1, and those that don't need GOT entries get
1924 if (h
->root
.got
.offset
== 2)
1926 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
1927 hsd
->low
= (struct elf_link_hash_entry
*) h
;
1928 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
1930 else if (h
->root
.got
.offset
!= 1)
1931 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
1934 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
1935 hsd
->low
= (struct elf_link_hash_entry
*) h
;
1941 /* If H is a symbol that needs a global GOT entry, but has a dynamic
1942 symbol table index lower than any we've seen to date, record it for
1946 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
1947 bfd
*abfd
, struct bfd_link_info
*info
,
1948 struct mips_got_info
*g
)
1950 struct mips_got_entry entry
, **loc
;
1952 /* A global symbol in the GOT must also be in the dynamic symbol
1954 if (h
->dynindx
== -1)
1956 switch (ELF_ST_VISIBILITY (h
->other
))
1960 _bfd_mips_elf_hide_symbol (info
, h
, TRUE
);
1963 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
1969 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
1971 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
1974 /* If we've already marked this entry as needing GOT space, we don't
1975 need to do it again. */
1979 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
1985 memcpy (*loc
, &entry
, sizeof entry
);
1987 if (h
->got
.offset
!= MINUS_ONE
)
1990 /* By setting this to a value other than -1, we are indicating that
1991 there needs to be a GOT entry for H. Avoid using zero, as the
1992 generic ELF copy_indirect_symbol tests for <= 0. */
1998 /* Reserve space in G for a GOT entry containing the value of symbol
1999 SYMNDX in input bfd ABDF, plus ADDEND. */
2002 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
2003 struct mips_got_info
*g
)
2005 struct mips_got_entry entry
, **loc
;
2008 entry
.symndx
= symndx
;
2009 entry
.d
.addend
= addend
;
2010 loc
= (struct mips_got_entry
**)
2011 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
2016 entry
.gotidx
= g
->local_gotno
++;
2018 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
2023 memcpy (*loc
, &entry
, sizeof entry
);
2028 /* Compute the hash value of the bfd in a bfd2got hash entry. */
2031 mips_elf_bfd2got_entry_hash (const void *entry_
)
2033 const struct mips_elf_bfd2got_hash
*entry
2034 = (struct mips_elf_bfd2got_hash
*)entry_
;
2036 return entry
->bfd
->id
;
2039 /* Check whether two hash entries have the same bfd. */
2042 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
2044 const struct mips_elf_bfd2got_hash
*e1
2045 = (const struct mips_elf_bfd2got_hash
*)entry1
;
2046 const struct mips_elf_bfd2got_hash
*e2
2047 = (const struct mips_elf_bfd2got_hash
*)entry2
;
2049 return e1
->bfd
== e2
->bfd
;
2052 /* In a multi-got link, determine the GOT to be used for IBDF. G must
2053 be the master GOT data. */
2055 static struct mips_got_info
*
2056 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
2058 struct mips_elf_bfd2got_hash e
, *p
;
2064 p
= htab_find (g
->bfd2got
, &e
);
2065 return p
? p
->g
: NULL
;
2068 /* Create one separate got for each bfd that has entries in the global
2069 got, such that we can tell how many local and global entries each
2073 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
2075 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
2076 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
2077 htab_t bfd2got
= arg
->bfd2got
;
2078 struct mips_got_info
*g
;
2079 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
2082 /* Find the got_info for this GOT entry's input bfd. Create one if
2084 bfdgot_entry
.bfd
= entry
->abfd
;
2085 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
2086 bfdgot
= (struct mips_elf_bfd2got_hash
*)*bfdgotp
;
2092 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
2093 (arg
->obfd
, sizeof (struct mips_elf_bfd2got_hash
));
2103 bfdgot
->bfd
= entry
->abfd
;
2104 bfdgot
->g
= g
= (struct mips_got_info
*)
2105 bfd_alloc (arg
->obfd
, sizeof (struct mips_got_info
));
2112 g
->global_gotsym
= NULL
;
2113 g
->global_gotno
= 0;
2115 g
->assigned_gotno
= -1;
2116 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
2117 mips_elf_multi_got_entry_eq
, NULL
);
2118 if (g
->got_entries
== NULL
)
2128 /* Insert the GOT entry in the bfd's got entry hash table. */
2129 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
2130 if (*entryp
!= NULL
)
2135 if (entry
->symndx
>= 0 || entry
->d
.h
->forced_local
)
2143 /* Attempt to merge gots of different input bfds. Try to use as much
2144 as possible of the primary got, since it doesn't require explicit
2145 dynamic relocations, but don't use bfds that would reference global
2146 symbols out of the addressable range. Failing the primary got,
2147 attempt to merge with the current got, or finish the current got
2148 and then make make the new got current. */
2151 mips_elf_merge_gots (void **bfd2got_
, void *p
)
2153 struct mips_elf_bfd2got_hash
*bfd2got
2154 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
2155 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
2156 unsigned int lcount
= bfd2got
->g
->local_gotno
;
2157 unsigned int gcount
= bfd2got
->g
->global_gotno
;
2158 unsigned int maxcnt
= arg
->max_count
;
2160 /* If we don't have a primary GOT and this is not too big, use it as
2161 a starting point for the primary GOT. */
2162 if (! arg
->primary
&& lcount
+ gcount
<= maxcnt
)
2164 arg
->primary
= bfd2got
->g
;
2165 arg
->primary_count
= lcount
+ gcount
;
2167 /* If it looks like we can merge this bfd's entries with those of
2168 the primary, merge them. The heuristics is conservative, but we
2169 don't have to squeeze it too hard. */
2170 else if (arg
->primary
2171 && (arg
->primary_count
+ lcount
+ gcount
) <= maxcnt
)
2173 struct mips_got_info
*g
= bfd2got
->g
;
2174 int old_lcount
= arg
->primary
->local_gotno
;
2175 int old_gcount
= arg
->primary
->global_gotno
;
2177 bfd2got
->g
= arg
->primary
;
2179 htab_traverse (g
->got_entries
,
2180 mips_elf_make_got_per_bfd
,
2182 if (arg
->obfd
== NULL
)
2185 htab_delete (g
->got_entries
);
2186 /* We don't have to worry about releasing memory of the actual
2187 got entries, since they're all in the master got_entries hash
2190 BFD_ASSERT (old_lcount
+ lcount
>= arg
->primary
->local_gotno
);
2191 BFD_ASSERT (old_gcount
+ gcount
>= arg
->primary
->global_gotno
);
2193 arg
->primary_count
= arg
->primary
->local_gotno
2194 + arg
->primary
->global_gotno
;
2196 /* If we can merge with the last-created got, do it. */
2197 else if (arg
->current
2198 && arg
->current_count
+ lcount
+ gcount
<= maxcnt
)
2200 struct mips_got_info
*g
= bfd2got
->g
;
2201 int old_lcount
= arg
->current
->local_gotno
;
2202 int old_gcount
= arg
->current
->global_gotno
;
2204 bfd2got
->g
= arg
->current
;
2206 htab_traverse (g
->got_entries
,
2207 mips_elf_make_got_per_bfd
,
2209 if (arg
->obfd
== NULL
)
2212 htab_delete (g
->got_entries
);
2214 BFD_ASSERT (old_lcount
+ lcount
>= arg
->current
->local_gotno
);
2215 BFD_ASSERT (old_gcount
+ gcount
>= arg
->current
->global_gotno
);
2217 arg
->current_count
= arg
->current
->local_gotno
2218 + arg
->current
->global_gotno
;
2220 /* Well, we couldn't merge, so create a new GOT. Don't check if it
2221 fits; if it turns out that it doesn't, we'll get relocation
2222 overflows anyway. */
2225 bfd2got
->g
->next
= arg
->current
;
2226 arg
->current
= bfd2got
->g
;
2228 arg
->current_count
= lcount
+ gcount
;
2234 /* If passed a NULL mips_got_info in the argument, set the marker used
2235 to tell whether a global symbol needs a got entry (in the primary
2236 got) to the given VALUE.
2238 If passed a pointer G to a mips_got_info in the argument (it must
2239 not be the primary GOT), compute the offset from the beginning of
2240 the (primary) GOT section to the entry in G corresponding to the
2241 global symbol. G's assigned_gotno must contain the index of the
2242 first available global GOT entry in G. VALUE must contain the size
2243 of a GOT entry in bytes. For each global GOT entry that requires a
2244 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
2245 marked as not eligible for lazy resolution through a function
2248 mips_elf_set_global_got_offset (void **entryp
, void *p
)
2250 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
2251 struct mips_elf_set_global_got_offset_arg
*arg
2252 = (struct mips_elf_set_global_got_offset_arg
*)p
;
2253 struct mips_got_info
*g
= arg
->g
;
2255 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1
2256 && entry
->d
.h
->root
.dynindx
!= -1)
2260 BFD_ASSERT (g
->global_gotsym
== NULL
);
2262 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
2263 if (arg
->info
->shared
2264 || (elf_hash_table (arg
->info
)->dynamic_sections_created
2265 && ((entry
->d
.h
->root
.elf_link_hash_flags
2266 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
2267 && ((entry
->d
.h
->root
.elf_link_hash_flags
2268 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2269 ++arg
->needed_relocs
;
2272 entry
->d
.h
->root
.got
.offset
= arg
->value
;
2278 /* Mark any global symbols referenced in the GOT we are iterating over
2279 as inelligible for lazy resolution stubs. */
2281 mips_elf_set_no_stub (void **entryp
, void *p ATTRIBUTE_UNUSED
)
2283 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
2285 if (entry
->abfd
!= NULL
2286 && entry
->symndx
== -1
2287 && entry
->d
.h
->root
.dynindx
!= -1)
2288 entry
->d
.h
->no_fn_stub
= TRUE
;
2293 /* Follow indirect and warning hash entries so that each got entry
2294 points to the final symbol definition. P must point to a pointer
2295 to the hash table we're traversing. Since this traversal may
2296 modify the hash table, we set this pointer to NULL to indicate
2297 we've made a potentially-destructive change to the hash table, so
2298 the traversal must be restarted. */
2300 mips_elf_resolve_final_got_entry (void **entryp
, void *p
)
2302 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
2303 htab_t got_entries
= *(htab_t
*)p
;
2305 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
2307 struct mips_elf_link_hash_entry
*h
= entry
->d
.h
;
2309 while (h
->root
.root
.type
== bfd_link_hash_indirect
2310 || h
->root
.root
.type
== bfd_link_hash_warning
)
2311 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2313 if (entry
->d
.h
== h
)
2318 /* If we can't find this entry with the new bfd hash, re-insert
2319 it, and get the traversal restarted. */
2320 if (! htab_find (got_entries
, entry
))
2322 htab_clear_slot (got_entries
, entryp
);
2323 entryp
= htab_find_slot (got_entries
, entry
, INSERT
);
2326 /* Abort the traversal, since the whole table may have
2327 moved, and leave it up to the parent to restart the
2329 *(htab_t
*)p
= NULL
;
2332 /* We might want to decrement the global_gotno count, but it's
2333 either too early or too late for that at this point. */
2339 /* Turn indirect got entries in a got_entries table into their final
2342 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
2348 got_entries
= g
->got_entries
;
2350 htab_traverse (got_entries
,
2351 mips_elf_resolve_final_got_entry
,
2354 while (got_entries
== NULL
);
2357 /* Return the offset of an input bfd IBFD's GOT from the beginning of
2360 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
2362 if (g
->bfd2got
== NULL
)
2365 g
= mips_elf_got_for_ibfd (g
, ibfd
);
2369 BFD_ASSERT (g
->next
);
2373 return (g
->local_gotno
+ g
->global_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
2376 /* Turn a single GOT that is too big for 16-bit addressing into
2377 a sequence of GOTs, each one 16-bit addressable. */
2380 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
2381 struct mips_got_info
*g
, asection
*got
,
2382 bfd_size_type pages
)
2384 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
2385 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
2386 struct mips_got_info
*gg
;
2387 unsigned int assign
;
2389 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
2390 mips_elf_bfd2got_entry_eq
, NULL
);
2391 if (g
->bfd2got
== NULL
)
2394 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
2395 got_per_bfd_arg
.obfd
= abfd
;
2396 got_per_bfd_arg
.info
= info
;
2398 /* Count how many GOT entries each input bfd requires, creating a
2399 map from bfd to got info while at that. */
2400 mips_elf_resolve_final_got_entries (g
);
2401 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
2402 if (got_per_bfd_arg
.obfd
== NULL
)
2405 got_per_bfd_arg
.current
= NULL
;
2406 got_per_bfd_arg
.primary
= NULL
;
2407 /* Taking out PAGES entries is a worst-case estimate. We could
2408 compute the maximum number of pages that each separate input bfd
2409 uses, but it's probably not worth it. */
2410 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (abfd
)
2411 / MIPS_ELF_GOT_SIZE (abfd
))
2412 - MIPS_RESERVED_GOTNO
- pages
);
2414 /* Try to merge the GOTs of input bfds together, as long as they
2415 don't seem to exceed the maximum GOT size, choosing one of them
2416 to be the primary GOT. */
2417 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
2418 if (got_per_bfd_arg
.obfd
== NULL
)
2421 /* If we find any suitable primary GOT, create an empty one. */
2422 if (got_per_bfd_arg
.primary
== NULL
)
2424 g
->next
= (struct mips_got_info
*)
2425 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
2426 if (g
->next
== NULL
)
2429 g
->next
->global_gotsym
= NULL
;
2430 g
->next
->global_gotno
= 0;
2431 g
->next
->local_gotno
= 0;
2432 g
->next
->assigned_gotno
= 0;
2433 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
2434 mips_elf_multi_got_entry_eq
,
2436 if (g
->next
->got_entries
== NULL
)
2438 g
->next
->bfd2got
= NULL
;
2441 g
->next
= got_per_bfd_arg
.primary
;
2442 g
->next
->next
= got_per_bfd_arg
.current
;
2444 /* GG is now the master GOT, and G is the primary GOT. */
2448 /* Map the output bfd to the primary got. That's what we're going
2449 to use for bfds that use GOT16 or GOT_PAGE relocations that we
2450 didn't mark in check_relocs, and we want a quick way to find it.
2451 We can't just use gg->next because we're going to reverse the
2454 struct mips_elf_bfd2got_hash
*bfdgot
;
2457 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
2458 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
2465 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
2467 BFD_ASSERT (*bfdgotp
== NULL
);
2471 /* The IRIX dynamic linker requires every symbol that is referenced
2472 in a dynamic relocation to be present in the primary GOT, so
2473 arrange for them to appear after those that are actually
2476 GNU/Linux could very well do without it, but it would slow down
2477 the dynamic linker, since it would have to resolve every dynamic
2478 symbol referenced in other GOTs more than once, without help from
2479 the cache. Also, knowing that every external symbol has a GOT
2480 helps speed up the resolution of local symbols too, so GNU/Linux
2481 follows IRIX's practice.
2483 The number 2 is used by mips_elf_sort_hash_table_f to count
2484 global GOT symbols that are unreferenced in the primary GOT, with
2485 an initial dynamic index computed from gg->assigned_gotno, where
2486 the number of unreferenced global entries in the primary GOT is
2490 gg
->assigned_gotno
= gg
->global_gotno
- g
->global_gotno
;
2491 g
->global_gotno
= gg
->global_gotno
;
2492 set_got_offset_arg
.value
= 2;
2496 /* This could be used for dynamic linkers that don't optimize
2497 symbol resolution while applying relocations so as to use
2498 primary GOT entries or assuming the symbol is locally-defined.
2499 With this code, we assign lower dynamic indices to global
2500 symbols that are not referenced in the primary GOT, so that
2501 their entries can be omitted. */
2502 gg
->assigned_gotno
= 0;
2503 set_got_offset_arg
.value
= -1;
2506 /* Reorder dynamic symbols as described above (which behavior
2507 depends on the setting of VALUE). */
2508 set_got_offset_arg
.g
= NULL
;
2509 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
2510 &set_got_offset_arg
);
2511 set_got_offset_arg
.value
= 1;
2512 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
2513 &set_got_offset_arg
);
2514 if (! mips_elf_sort_hash_table (info
, 1))
2517 /* Now go through the GOTs assigning them offset ranges.
2518 [assigned_gotno, local_gotno[ will be set to the range of local
2519 entries in each GOT. We can then compute the end of a GOT by
2520 adding local_gotno to global_gotno. We reverse the list and make
2521 it circular since then we'll be able to quickly compute the
2522 beginning of a GOT, by computing the end of its predecessor. To
2523 avoid special cases for the primary GOT, while still preserving
2524 assertions that are valid for both single- and multi-got links,
2525 we arrange for the main got struct to have the right number of
2526 global entries, but set its local_gotno such that the initial
2527 offset of the primary GOT is zero. Remember that the primary GOT
2528 will become the last item in the circular linked list, so it
2529 points back to the master GOT. */
2530 gg
->local_gotno
= -g
->global_gotno
;
2531 gg
->global_gotno
= g
->global_gotno
;
2537 struct mips_got_info
*gn
;
2539 assign
+= MIPS_RESERVED_GOTNO
;
2540 g
->assigned_gotno
= assign
;
2541 g
->local_gotno
+= assign
+ pages
;
2542 assign
= g
->local_gotno
+ g
->global_gotno
;
2544 /* Take g out of the direct list, and push it onto the reversed
2545 list that gg points to. */
2551 /* Mark global symbols in every non-primary GOT as ineligible for
2554 htab_traverse (g
->got_entries
, mips_elf_set_no_stub
, NULL
);
2558 got
->_raw_size
= (gg
->next
->local_gotno
2559 + gg
->next
->global_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
2565 /* Returns the first relocation of type r_type found, beginning with
2566 RELOCATION. RELEND is one-past-the-end of the relocation table. */
2568 static const Elf_Internal_Rela
*
2569 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
2570 const Elf_Internal_Rela
*relocation
,
2571 const Elf_Internal_Rela
*relend
)
2573 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
2574 immediately following. However, for the IRIX6 ABI, the next
2575 relocation may be a composed relocation consisting of several
2576 relocations for the same address. In that case, the R_MIPS_LO16
2577 relocation may occur as one of these. We permit a similar
2578 extension in general, as that is useful for GCC. */
2579 while (relocation
< relend
)
2581 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
)
2587 /* We didn't find it. */
2588 bfd_set_error (bfd_error_bad_value
);
2592 /* Return whether a relocation is against a local symbol. */
2595 mips_elf_local_relocation_p (bfd
*input_bfd
,
2596 const Elf_Internal_Rela
*relocation
,
2597 asection
**local_sections
,
2598 bfd_boolean check_forced
)
2600 unsigned long r_symndx
;
2601 Elf_Internal_Shdr
*symtab_hdr
;
2602 struct mips_elf_link_hash_entry
*h
;
2605 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
2606 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2607 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
2609 if (r_symndx
< extsymoff
)
2611 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
2616 /* Look up the hash table to check whether the symbol
2617 was forced local. */
2618 h
= (struct mips_elf_link_hash_entry
*)
2619 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
2620 /* Find the real hash-table entry for this symbol. */
2621 while (h
->root
.root
.type
== bfd_link_hash_indirect
2622 || h
->root
.root
.type
== bfd_link_hash_warning
)
2623 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2624 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
2631 /* Sign-extend VALUE, which has the indicated number of BITS. */
2634 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
2636 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
2637 /* VALUE is negative. */
2638 value
|= ((bfd_vma
) - 1) << bits
;
2643 /* Return non-zero if the indicated VALUE has overflowed the maximum
2644 range expressible by a signed number with the indicated number of
2648 mips_elf_overflow_p (bfd_vma value
, int bits
)
2650 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
2652 if (svalue
> (1 << (bits
- 1)) - 1)
2653 /* The value is too big. */
2655 else if (svalue
< -(1 << (bits
- 1)))
2656 /* The value is too small. */
2663 /* Calculate the %high function. */
2666 mips_elf_high (bfd_vma value
)
2668 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
2671 /* Calculate the %higher function. */
2674 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
2677 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
2680 return (bfd_vma
) -1;
2684 /* Calculate the %highest function. */
2687 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
2690 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
2693 return (bfd_vma
) -1;
2697 /* Create the .compact_rel section. */
2700 mips_elf_create_compact_rel_section
2701 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2704 register asection
*s
;
2706 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
2708 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
2711 s
= bfd_make_section (abfd
, ".compact_rel");
2713 || ! bfd_set_section_flags (abfd
, s
, flags
)
2714 || ! bfd_set_section_alignment (abfd
, s
,
2715 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
2718 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
2724 /* Create the .got section to hold the global offset table. */
2727 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
,
2728 bfd_boolean maybe_exclude
)
2731 register asection
*s
;
2732 struct elf_link_hash_entry
*h
;
2733 struct bfd_link_hash_entry
*bh
;
2734 struct mips_got_info
*g
;
2737 /* This function may be called more than once. */
2738 s
= mips_elf_got_section (abfd
, TRUE
);
2741 if (! maybe_exclude
)
2742 s
->flags
&= ~SEC_EXCLUDE
;
2746 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2747 | SEC_LINKER_CREATED
);
2750 flags
|= SEC_EXCLUDE
;
2752 /* We have to use an alignment of 2**4 here because this is hardcoded
2753 in the function stub generation and in the linker script. */
2754 s
= bfd_make_section (abfd
, ".got");
2756 || ! bfd_set_section_flags (abfd
, s
, flags
)
2757 || ! bfd_set_section_alignment (abfd
, s
, 4))
2760 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
2761 linker script because we don't want to define the symbol if we
2762 are not creating a global offset table. */
2764 if (! (_bfd_generic_link_add_one_symbol
2765 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
2766 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2769 h
= (struct elf_link_hash_entry
*) bh
;
2770 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
2771 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2772 h
->type
= STT_OBJECT
;
2775 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2778 amt
= sizeof (struct mips_got_info
);
2779 g
= bfd_alloc (abfd
, amt
);
2782 g
->global_gotsym
= NULL
;
2783 g
->global_gotno
= 0;
2784 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
2785 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
2788 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
2789 mips_elf_got_entry_eq
, NULL
);
2790 if (g
->got_entries
== NULL
)
2792 mips_elf_section_data (s
)->u
.got_info
= g
;
2793 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
2794 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2799 /* Calculate the value produced by the RELOCATION (which comes from
2800 the INPUT_BFD). The ADDEND is the addend to use for this
2801 RELOCATION; RELOCATION->R_ADDEND is ignored.
2803 The result of the relocation calculation is stored in VALUEP.
2804 REQUIRE_JALXP indicates whether or not the opcode used with this
2805 relocation must be JALX.
2807 This function returns bfd_reloc_continue if the caller need take no
2808 further action regarding this relocation, bfd_reloc_notsupported if
2809 something goes dramatically wrong, bfd_reloc_overflow if an
2810 overflow occurs, and bfd_reloc_ok to indicate success. */
2812 static bfd_reloc_status_type
2813 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
2814 asection
*input_section
,
2815 struct bfd_link_info
*info
,
2816 const Elf_Internal_Rela
*relocation
,
2817 bfd_vma addend
, reloc_howto_type
*howto
,
2818 Elf_Internal_Sym
*local_syms
,
2819 asection
**local_sections
, bfd_vma
*valuep
,
2820 const char **namep
, bfd_boolean
*require_jalxp
,
2821 bfd_boolean save_addend
)
2823 /* The eventual value we will return. */
2825 /* The address of the symbol against which the relocation is
2828 /* The final GP value to be used for the relocatable, executable, or
2829 shared object file being produced. */
2830 bfd_vma gp
= MINUS_ONE
;
2831 /* The place (section offset or address) of the storage unit being
2834 /* The value of GP used to create the relocatable object. */
2835 bfd_vma gp0
= MINUS_ONE
;
2836 /* The offset into the global offset table at which the address of
2837 the relocation entry symbol, adjusted by the addend, resides
2838 during execution. */
2839 bfd_vma g
= MINUS_ONE
;
2840 /* The section in which the symbol referenced by the relocation is
2842 asection
*sec
= NULL
;
2843 struct mips_elf_link_hash_entry
*h
= NULL
;
2844 /* TRUE if the symbol referred to by this relocation is a local
2846 bfd_boolean local_p
, was_local_p
;
2847 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
2848 bfd_boolean gp_disp_p
= FALSE
;
2849 Elf_Internal_Shdr
*symtab_hdr
;
2851 unsigned long r_symndx
;
2853 /* TRUE if overflow occurred during the calculation of the
2854 relocation value. */
2855 bfd_boolean overflowed_p
;
2856 /* TRUE if this relocation refers to a MIPS16 function. */
2857 bfd_boolean target_is_16_bit_code_p
= FALSE
;
2859 /* Parse the relocation. */
2860 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
2861 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
2862 p
= (input_section
->output_section
->vma
2863 + input_section
->output_offset
2864 + relocation
->r_offset
);
2866 /* Assume that there will be no overflow. */
2867 overflowed_p
= FALSE
;
2869 /* Figure out whether or not the symbol is local, and get the offset
2870 used in the array of hash table entries. */
2871 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2872 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
2873 local_sections
, FALSE
);
2874 was_local_p
= local_p
;
2875 if (! elf_bad_symtab (input_bfd
))
2876 extsymoff
= symtab_hdr
->sh_info
;
2879 /* The symbol table does not follow the rule that local symbols
2880 must come before globals. */
2884 /* Figure out the value of the symbol. */
2887 Elf_Internal_Sym
*sym
;
2889 sym
= local_syms
+ r_symndx
;
2890 sec
= local_sections
[r_symndx
];
2892 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2893 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
2894 || (sec
->flags
& SEC_MERGE
))
2895 symbol
+= sym
->st_value
;
2896 if ((sec
->flags
& SEC_MERGE
)
2897 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2899 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
2901 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
2904 /* MIPS16 text labels should be treated as odd. */
2905 if (sym
->st_other
== STO_MIPS16
)
2908 /* Record the name of this symbol, for our caller. */
2909 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
2910 symtab_hdr
->sh_link
,
2913 *namep
= bfd_section_name (input_bfd
, sec
);
2915 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
2919 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
2921 /* For global symbols we look up the symbol in the hash-table. */
2922 h
= ((struct mips_elf_link_hash_entry
*)
2923 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
2924 /* Find the real hash-table entry for this symbol. */
2925 while (h
->root
.root
.type
== bfd_link_hash_indirect
2926 || h
->root
.root
.type
== bfd_link_hash_warning
)
2927 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2929 /* Record the name of this symbol, for our caller. */
2930 *namep
= h
->root
.root
.root
.string
;
2932 /* See if this is the special _gp_disp symbol. Note that such a
2933 symbol must always be a global symbol. */
2934 if (strcmp (*namep
, "_gp_disp") == 0
2935 && ! NEWABI_P (input_bfd
))
2937 /* Relocations against _gp_disp are permitted only with
2938 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
2939 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
2940 return bfd_reloc_notsupported
;
2944 /* If this symbol is defined, calculate its address. Note that
2945 _gp_disp is a magic symbol, always implicitly defined by the
2946 linker, so it's inappropriate to check to see whether or not
2948 else if ((h
->root
.root
.type
== bfd_link_hash_defined
2949 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2950 && h
->root
.root
.u
.def
.section
)
2952 sec
= h
->root
.root
.u
.def
.section
;
2953 if (sec
->output_section
)
2954 symbol
= (h
->root
.root
.u
.def
.value
2955 + sec
->output_section
->vma
2956 + sec
->output_offset
);
2958 symbol
= h
->root
.root
.u
.def
.value
;
2960 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
2961 /* We allow relocations against undefined weak symbols, giving
2962 it the value zero, so that you can undefined weak functions
2963 and check to see if they exist by looking at their
2966 else if (info
->shared
2967 && info
->unresolved_syms_in_objects
== RM_IGNORE
2968 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
2970 else if (strcmp (*namep
, "_DYNAMIC_LINK") == 0 ||
2971 strcmp (*namep
, "_DYNAMIC_LINKING") == 0)
2973 /* If this is a dynamic link, we should have created a
2974 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
2975 in in _bfd_mips_elf_create_dynamic_sections.
2976 Otherwise, we should define the symbol with a value of 0.
2977 FIXME: It should probably get into the symbol table
2979 BFD_ASSERT (! info
->shared
);
2980 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
2985 if (! ((*info
->callbacks
->undefined_symbol
)
2986 (info
, h
->root
.root
.root
.string
, input_bfd
,
2987 input_section
, relocation
->r_offset
,
2988 ((info
->shared
&& info
->unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
2989 || (!info
->shared
&& info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
2990 || ELF_ST_VISIBILITY (h
->root
.other
)))))
2991 return bfd_reloc_undefined
;
2995 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
2998 /* If this is a 32- or 64-bit call to a 16-bit function with a stub, we
2999 need to redirect the call to the stub, unless we're already *in*
3001 if (r_type
!= R_MIPS16_26
&& !info
->relocatable
3002 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
3003 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
3004 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
3005 && !mips_elf_stub_section_p (input_bfd
, input_section
))
3007 /* This is a 32- or 64-bit call to a 16-bit function. We should
3008 have already noticed that we were going to need the
3011 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
3014 BFD_ASSERT (h
->need_fn_stub
);
3018 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
3020 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
3021 need to redirect the call to the stub. */
3022 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
3024 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
3025 && !target_is_16_bit_code_p
)
3027 /* If both call_stub and call_fp_stub are defined, we can figure
3028 out which one to use by seeing which one appears in the input
3030 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
3035 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
3037 if (strncmp (bfd_get_section_name (input_bfd
, o
),
3038 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
3040 sec
= h
->call_fp_stub
;
3047 else if (h
->call_stub
!= NULL
)
3050 sec
= h
->call_fp_stub
;
3052 BFD_ASSERT (sec
->_raw_size
> 0);
3053 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
3056 /* Calls from 16-bit code to 32-bit code and vice versa require the
3057 special jalx instruction. */
3058 *require_jalxp
= (!info
->relocatable
3059 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
3060 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
3062 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
3063 local_sections
, TRUE
);
3065 /* If we haven't already determined the GOT offset, or the GP value,
3066 and we're going to need it, get it now. */
3069 case R_MIPS_GOT_PAGE
:
3070 case R_MIPS_GOT_OFST
:
3071 /* If this symbol got a global GOT entry, we have to decay
3072 GOT_PAGE/GOT_OFST to GOT_DISP/addend. */
3073 local_p
= local_p
|| ! h
3075 < mips_elf_get_global_gotsym_index (elf_hash_table (info
)
3077 if (local_p
|| r_type
== R_MIPS_GOT_OFST
)
3083 case R_MIPS_GOT_DISP
:
3084 case R_MIPS_GOT_HI16
:
3085 case R_MIPS_CALL_HI16
:
3086 case R_MIPS_GOT_LO16
:
3087 case R_MIPS_CALL_LO16
:
3088 /* Find the index into the GOT where this value is located. */
3091 /* GOT_PAGE may take a non-zero addend, that is ignored in a
3092 GOT_PAGE relocation that decays to GOT_DISP because the
3093 symbol turns out to be global. The addend is then added
3095 BFD_ASSERT (addend
== 0 || r_type
== R_MIPS_GOT_PAGE
);
3096 g
= mips_elf_global_got_index (elf_hash_table (info
)->dynobj
,
3098 (struct elf_link_hash_entry
*) h
);
3099 if (! elf_hash_table(info
)->dynamic_sections_created
3101 && (info
->symbolic
|| h
->root
.dynindx
== -1)
3102 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
3104 /* This is a static link or a -Bsymbolic link. The
3105 symbol is defined locally, or was forced to be local.
3106 We must initialize this entry in the GOT. */
3107 bfd
*tmpbfd
= elf_hash_table (info
)->dynobj
;
3108 asection
*sgot
= mips_elf_got_section (tmpbfd
, FALSE
);
3109 MIPS_ELF_PUT_WORD (tmpbfd
, symbol
, sgot
->contents
+ g
);
3112 else if (r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS_CALL16
)
3113 /* There's no need to create a local GOT entry here; the
3114 calculation for a local GOT16 entry does not involve G. */
3118 g
= mips_elf_local_got_index (abfd
, input_bfd
,
3119 info
, symbol
+ addend
);
3121 return bfd_reloc_outofrange
;
3124 /* Convert GOT indices to actual offsets. */
3125 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
3126 abfd
, input_bfd
, g
);
3131 case R_MIPS16_GPREL
:
3132 case R_MIPS_GPREL16
:
3133 case R_MIPS_GPREL32
:
3134 case R_MIPS_LITERAL
:
3135 gp0
= _bfd_get_gp_value (input_bfd
);
3136 gp
= _bfd_get_gp_value (abfd
);
3137 if (elf_hash_table (info
)->dynobj
)
3138 gp
+= mips_elf_adjust_gp (abfd
,
3140 (elf_hash_table (info
)->dynobj
, NULL
),
3148 /* Figure out what kind of relocation is being performed. */
3152 return bfd_reloc_continue
;
3155 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
3156 overflowed_p
= mips_elf_overflow_p (value
, 16);
3163 || (elf_hash_table (info
)->dynamic_sections_created
3165 && ((h
->root
.elf_link_hash_flags
3166 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
3167 && ((h
->root
.elf_link_hash_flags
3168 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3170 && (input_section
->flags
& SEC_ALLOC
) != 0)
3172 /* If we're creating a shared library, or this relocation is
3173 against a symbol in a shared library, then we can't know
3174 where the symbol will end up. So, we create a relocation
3175 record in the output, and leave the job up to the dynamic
3178 if (!mips_elf_create_dynamic_relocation (abfd
,
3186 return bfd_reloc_undefined
;
3190 if (r_type
!= R_MIPS_REL32
)
3191 value
= symbol
+ addend
;
3195 value
&= howto
->dst_mask
;
3200 case R_MIPS_GNU_REL_LO16
:
3201 value
= symbol
+ addend
- p
;
3202 value
&= howto
->dst_mask
;
3205 case R_MIPS_GNU_REL16_S2
:
3206 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
<< 2, 18) - p
;
3207 overflowed_p
= mips_elf_overflow_p (value
, 18);
3208 value
= (value
>> 2) & howto
->dst_mask
;
3211 case R_MIPS_GNU_REL_HI16
:
3212 /* Instead of subtracting 'p' here, we should be subtracting the
3213 equivalent value for the LO part of the reloc, since the value
3214 here is relative to that address. Because that's not easy to do,
3215 we adjust 'addend' in _bfd_mips_elf_relocate_section(). See also
3216 the comment there for more information. */
3217 value
= mips_elf_high (addend
+ symbol
- p
);
3218 value
&= howto
->dst_mask
;
3222 /* The calculation for R_MIPS16_26 is just the same as for an
3223 R_MIPS_26. It's only the storage of the relocated field into
3224 the output file that's different. That's handled in
3225 mips_elf_perform_relocation. So, we just fall through to the
3226 R_MIPS_26 case here. */
3229 value
= (((addend
<< 2) | ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
3231 value
= (_bfd_mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
3232 value
&= howto
->dst_mask
;
3238 value
= mips_elf_high (addend
+ symbol
);
3239 value
&= howto
->dst_mask
;
3243 value
= mips_elf_high (addend
+ gp
- p
);
3244 overflowed_p
= mips_elf_overflow_p (value
, 16);
3250 value
= (symbol
+ addend
) & howto
->dst_mask
;
3253 value
= addend
+ gp
- p
+ 4;
3254 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
3255 for overflow. But, on, say, IRIX5, relocations against
3256 _gp_disp are normally generated from the .cpload
3257 pseudo-op. It generates code that normally looks like
3260 lui $gp,%hi(_gp_disp)
3261 addiu $gp,$gp,%lo(_gp_disp)
3264 Here $t9 holds the address of the function being called,
3265 as required by the MIPS ELF ABI. The R_MIPS_LO16
3266 relocation can easily overflow in this situation, but the
3267 R_MIPS_HI16 relocation will handle the overflow.
3268 Therefore, we consider this a bug in the MIPS ABI, and do
3269 not check for overflow here. */
3273 case R_MIPS_LITERAL
:
3274 /* Because we don't merge literal sections, we can handle this
3275 just like R_MIPS_GPREL16. In the long run, we should merge
3276 shared literals, and then we will need to additional work
3281 case R_MIPS16_GPREL
:
3282 /* The R_MIPS16_GPREL performs the same calculation as
3283 R_MIPS_GPREL16, but stores the relocated bits in a different
3284 order. We don't need to do anything special here; the
3285 differences are handled in mips_elf_perform_relocation. */
3286 case R_MIPS_GPREL16
:
3287 /* Only sign-extend the addend if it was extracted from the
3288 instruction. If the addend was separate, leave it alone,
3289 otherwise we may lose significant bits. */
3290 if (howto
->partial_inplace
)
3291 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
3292 value
= symbol
+ addend
- gp
;
3293 /* If the symbol was local, any earlier relocatable links will
3294 have adjusted its addend with the gp offset, so compensate
3295 for that now. Don't do it for symbols forced local in this
3296 link, though, since they won't have had the gp offset applied
3300 overflowed_p
= mips_elf_overflow_p (value
, 16);
3309 /* The special case is when the symbol is forced to be local. We
3310 need the full address in the GOT since no R_MIPS_LO16 relocation
3312 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
3313 local_sections
, FALSE
);
3314 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
3315 symbol
+ addend
, forced
);
3316 if (value
== MINUS_ONE
)
3317 return bfd_reloc_outofrange
;
3319 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
3320 abfd
, input_bfd
, value
);
3321 overflowed_p
= mips_elf_overflow_p (value
, 16);
3327 case R_MIPS_GOT_DISP
:
3330 overflowed_p
= mips_elf_overflow_p (value
, 16);
3333 case R_MIPS_GPREL32
:
3334 value
= (addend
+ symbol
+ gp0
- gp
);
3336 value
&= howto
->dst_mask
;
3340 value
= _bfd_mips_elf_sign_extend (addend
, 16) + symbol
- p
;
3341 overflowed_p
= mips_elf_overflow_p (value
, 16);
3344 case R_MIPS_GOT_HI16
:
3345 case R_MIPS_CALL_HI16
:
3346 /* We're allowed to handle these two relocations identically.
3347 The dynamic linker is allowed to handle the CALL relocations
3348 differently by creating a lazy evaluation stub. */
3350 value
= mips_elf_high (value
);
3351 value
&= howto
->dst_mask
;
3354 case R_MIPS_GOT_LO16
:
3355 case R_MIPS_CALL_LO16
:
3356 value
= g
& howto
->dst_mask
;
3359 case R_MIPS_GOT_PAGE
:
3360 /* GOT_PAGE relocations that reference non-local symbols decay
3361 to GOT_DISP. The corresponding GOT_OFST relocation decays to
3365 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
3366 if (value
== MINUS_ONE
)
3367 return bfd_reloc_outofrange
;
3368 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
3369 abfd
, input_bfd
, value
);
3370 overflowed_p
= mips_elf_overflow_p (value
, 16);
3373 case R_MIPS_GOT_OFST
:
3375 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
3378 overflowed_p
= mips_elf_overflow_p (value
, 16);
3382 value
= symbol
- addend
;
3383 value
&= howto
->dst_mask
;
3387 value
= mips_elf_higher (addend
+ symbol
);
3388 value
&= howto
->dst_mask
;
3391 case R_MIPS_HIGHEST
:
3392 value
= mips_elf_highest (addend
+ symbol
);
3393 value
&= howto
->dst_mask
;
3396 case R_MIPS_SCN_DISP
:
3397 value
= symbol
+ addend
- sec
->output_offset
;
3398 value
&= howto
->dst_mask
;
3403 /* Both of these may be ignored. R_MIPS_JALR is an optimization
3404 hint; we could improve performance by honoring that hint. */
3405 return bfd_reloc_continue
;
3407 case R_MIPS_GNU_VTINHERIT
:
3408 case R_MIPS_GNU_VTENTRY
:
3409 /* We don't do anything with these at present. */
3410 return bfd_reloc_continue
;
3413 /* An unrecognized relocation type. */
3414 return bfd_reloc_notsupported
;
3417 /* Store the VALUE for our caller. */
3419 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
3422 /* Obtain the field relocated by RELOCATION. */
3425 mips_elf_obtain_contents (reloc_howto_type
*howto
,
3426 const Elf_Internal_Rela
*relocation
,
3427 bfd
*input_bfd
, bfd_byte
*contents
)
3430 bfd_byte
*location
= contents
+ relocation
->r_offset
;
3432 /* Obtain the bytes. */
3433 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
3435 if ((ELF_R_TYPE (input_bfd
, relocation
->r_info
) == R_MIPS16_26
3436 || ELF_R_TYPE (input_bfd
, relocation
->r_info
) == R_MIPS16_GPREL
)
3437 && bfd_little_endian (input_bfd
))
3438 /* The two 16-bit words will be reversed on a little-endian system.
3439 See mips_elf_perform_relocation for more details. */
3440 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
3445 /* It has been determined that the result of the RELOCATION is the
3446 VALUE. Use HOWTO to place VALUE into the output file at the
3447 appropriate position. The SECTION is the section to which the
3448 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
3449 for the relocation must be either JAL or JALX, and it is
3450 unconditionally converted to JALX.
3452 Returns FALSE if anything goes wrong. */
3455 mips_elf_perform_relocation (struct bfd_link_info
*info
,
3456 reloc_howto_type
*howto
,
3457 const Elf_Internal_Rela
*relocation
,
3458 bfd_vma value
, bfd
*input_bfd
,
3459 asection
*input_section
, bfd_byte
*contents
,
3460 bfd_boolean require_jalx
)
3464 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
3466 /* Figure out where the relocation is occurring. */
3467 location
= contents
+ relocation
->r_offset
;
3469 /* Obtain the current value. */
3470 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
3472 /* Clear the field we are setting. */
3473 x
&= ~howto
->dst_mask
;
3475 /* If this is the R_MIPS16_26 relocation, we must store the
3476 value in a funny way. */
3477 if (r_type
== R_MIPS16_26
)
3479 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
3480 Most mips16 instructions are 16 bits, but these instructions
3483 The format of these instructions is:
3485 +--------------+--------------------------------+
3486 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
3487 +--------------+--------------------------------+
3489 +-----------------------------------------------+
3491 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
3492 Note that the immediate value in the first word is swapped.
3494 When producing a relocatable object file, R_MIPS16_26 is
3495 handled mostly like R_MIPS_26. In particular, the addend is
3496 stored as a straight 26-bit value in a 32-bit instruction.
3497 (gas makes life simpler for itself by never adjusting a
3498 R_MIPS16_26 reloc to be against a section, so the addend is
3499 always zero). However, the 32 bit instruction is stored as 2
3500 16-bit values, rather than a single 32-bit value. In a
3501 big-endian file, the result is the same; in a little-endian
3502 file, the two 16-bit halves of the 32 bit value are swapped.
3503 This is so that a disassembler can recognize the jal
3506 When doing a final link, R_MIPS16_26 is treated as a 32 bit
3507 instruction stored as two 16-bit values. The addend A is the
3508 contents of the targ26 field. The calculation is the same as
3509 R_MIPS_26. When storing the calculated value, reorder the
3510 immediate value as shown above, and don't forget to store the
3511 value as two 16-bit values.
3513 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
3517 +--------+----------------------+
3521 +--------+----------------------+
3524 +----------+------+-------------+
3528 +----------+--------------------+
3529 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
3530 ((sub1 << 16) | sub2)).
3532 When producing a relocatable object file, the calculation is
3533 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
3534 When producing a fully linked file, the calculation is
3535 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
3536 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
3538 if (!info
->relocatable
)
3539 /* Shuffle the bits according to the formula above. */
3540 value
= (((value
& 0x1f0000) << 5)
3541 | ((value
& 0x3e00000) >> 5)
3542 | (value
& 0xffff));
3544 else if (r_type
== R_MIPS16_GPREL
)
3546 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
3547 mode. A typical instruction will have a format like this:
3549 +--------------+--------------------------------+
3550 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
3551 +--------------+--------------------------------+
3552 ! Major ! rx ! ry ! Imm 4:0 !
3553 +--------------+--------------------------------+
3555 EXTEND is the five bit value 11110. Major is the instruction
3558 This is handled exactly like R_MIPS_GPREL16, except that the
3559 addend is retrieved and stored as shown in this diagram; that
3560 is, the Imm fields above replace the V-rel16 field.
3562 All we need to do here is shuffle the bits appropriately. As
3563 above, the two 16-bit halves must be swapped on a
3564 little-endian system. */
3565 value
= (((value
& 0x7e0) << 16)
3566 | ((value
& 0xf800) << 5)
3570 /* Set the field. */
3571 x
|= (value
& howto
->dst_mask
);
3573 /* If required, turn JAL into JALX. */
3577 bfd_vma opcode
= x
>> 26;
3578 bfd_vma jalx_opcode
;
3580 /* Check to see if the opcode is already JAL or JALX. */
3581 if (r_type
== R_MIPS16_26
)
3583 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
3588 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
3592 /* If the opcode is not JAL or JALX, there's a problem. */
3595 (*_bfd_error_handler
)
3596 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
3597 bfd_archive_filename (input_bfd
),
3598 input_section
->name
,
3599 (unsigned long) relocation
->r_offset
);
3600 bfd_set_error (bfd_error_bad_value
);
3604 /* Make this the JALX opcode. */
3605 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
3608 /* Swap the high- and low-order 16 bits on little-endian systems
3609 when doing a MIPS16 relocation. */
3610 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
3611 && bfd_little_endian (input_bfd
))
3612 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
3614 /* Put the value into the output. */
3615 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
3619 /* Returns TRUE if SECTION is a MIPS16 stub section. */
3622 mips_elf_stub_section_p (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
)
3624 const char *name
= bfd_get_section_name (abfd
, section
);
3626 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
3627 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
3628 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
3631 /* Add room for N relocations to the .rel.dyn section in ABFD. */
3634 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, unsigned int n
)
3638 s
= mips_elf_rel_dyn_section (abfd
, FALSE
);
3639 BFD_ASSERT (s
!= NULL
);
3641 if (s
->_raw_size
== 0)
3643 /* Make room for a null element. */
3644 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
3647 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
3650 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
3651 is the original relocation, which is now being transformed into a
3652 dynamic relocation. The ADDENDP is adjusted if necessary; the
3653 caller should store the result in place of the original addend. */
3656 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
3657 struct bfd_link_info
*info
,
3658 const Elf_Internal_Rela
*rel
,
3659 struct mips_elf_link_hash_entry
*h
,
3660 asection
*sec
, bfd_vma symbol
,
3661 bfd_vma
*addendp
, asection
*input_section
)
3663 Elf_Internal_Rela outrel
[3];
3669 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
3670 dynobj
= elf_hash_table (info
)->dynobj
;
3671 sreloc
= mips_elf_rel_dyn_section (dynobj
, FALSE
);
3672 BFD_ASSERT (sreloc
!= NULL
);
3673 BFD_ASSERT (sreloc
->contents
!= NULL
);
3674 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
3675 < sreloc
->_raw_size
);
3678 outrel
[0].r_offset
=
3679 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
3680 outrel
[1].r_offset
=
3681 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
3682 outrel
[2].r_offset
=
3683 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
3686 /* We begin by assuming that the offset for the dynamic relocation
3687 is the same as for the original relocation. We'll adjust this
3688 later to reflect the correct output offsets. */
3689 if (input_section
->sec_info_type
!= ELF_INFO_TYPE_STABS
)
3691 outrel
[1].r_offset
= rel
[1].r_offset
;
3692 outrel
[2].r_offset
= rel
[2].r_offset
;
3696 /* Except that in a stab section things are more complex.
3697 Because we compress stab information, the offset given in the
3698 relocation may not be the one we want; we must let the stabs
3699 machinery tell us the offset. */
3700 outrel
[1].r_offset
= outrel
[0].r_offset
;
3701 outrel
[2].r_offset
= outrel
[0].r_offset
;
3702 /* If we didn't need the relocation at all, this value will be
3704 if (outrel
[0].r_offset
== (bfd_vma
) -1)
3709 if (outrel
[0].r_offset
== (bfd_vma
) -1)
3710 /* The relocation field has been deleted. */
3712 else if (outrel
[0].r_offset
== (bfd_vma
) -2)
3714 /* The relocation field has been converted into a relative value of
3715 some sort. Functions like _bfd_elf_write_section_eh_frame expect
3716 the field to be fully relocated, so add in the symbol's value. */
3721 /* If we've decided to skip this relocation, just output an empty
3722 record. Note that R_MIPS_NONE == 0, so that this call to memset
3723 is a way of setting R_TYPE to R_MIPS_NONE. */
3725 memset (outrel
, 0, sizeof (Elf_Internal_Rela
) * 3);
3729 bfd_boolean defined_p
;
3731 /* We must now calculate the dynamic symbol table index to use
3732 in the relocation. */
3734 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
3735 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
3736 /* h->root.dynindx may be -1 if this symbol was marked to
3738 && h
->root
.dynindx
!= -1)
3740 indx
= h
->root
.dynindx
;
3741 if (SGI_COMPAT (output_bfd
))
3742 defined_p
= ((h
->root
.elf_link_hash_flags
3743 & ELF_LINK_HASH_DEF_REGULAR
) != 0);
3745 /* ??? glibc's ld.so just adds the final GOT entry to the
3746 relocation field. It therefore treats relocs against
3747 defined symbols in the same way as relocs against
3748 undefined symbols. */
3753 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
3755 else if (sec
== NULL
|| sec
->owner
== NULL
)
3757 bfd_set_error (bfd_error_bad_value
);
3762 indx
= elf_section_data (sec
->output_section
)->dynindx
;
3767 /* Instead of generating a relocation using the section
3768 symbol, we may as well make it a fully relative
3769 relocation. We want to avoid generating relocations to
3770 local symbols because we used to generate them
3771 incorrectly, without adding the original symbol value,
3772 which is mandated by the ABI for section symbols. In
3773 order to give dynamic loaders and applications time to
3774 phase out the incorrect use, we refrain from emitting
3775 section-relative relocations. It's not like they're
3776 useful, after all. This should be a bit more efficient
3778 /* ??? Although this behavior is compatible with glibc's ld.so,
3779 the ABI says that relocations against STN_UNDEF should have
3780 a symbol value of 0. Irix rld honors this, so relocations
3781 against STN_UNDEF have no effect. */
3782 if (!SGI_COMPAT (output_bfd
))
3787 /* If the relocation was previously an absolute relocation and
3788 this symbol will not be referred to by the relocation, we must
3789 adjust it by the value we give it in the dynamic symbol table.
3790 Otherwise leave the job up to the dynamic linker. */
3791 if (defined_p
&& r_type
!= R_MIPS_REL32
)
3794 /* The relocation is always an REL32 relocation because we don't
3795 know where the shared library will wind up at load-time. */
3796 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
3798 /* For strict adherence to the ABI specification, we should
3799 generate a R_MIPS_64 relocation record by itself before the
3800 _REL32/_64 record as well, such that the addend is read in as
3801 a 64-bit value (REL32 is a 32-bit relocation, after all).
3802 However, since none of the existing ELF64 MIPS dynamic
3803 loaders seems to care, we don't waste space with these
3804 artificial relocations. If this turns out to not be true,
3805 mips_elf_allocate_dynamic_relocation() should be tweaked so
3806 as to make room for a pair of dynamic relocations per
3807 invocation if ABI_64_P, and here we should generate an
3808 additional relocation record with R_MIPS_64 by itself for a
3809 NULL symbol before this relocation record. */
3810 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
3811 ABI_64_P (output_bfd
)
3814 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
3816 /* Adjust the output offset of the relocation to reference the
3817 correct location in the output file. */
3818 outrel
[0].r_offset
+= (input_section
->output_section
->vma
3819 + input_section
->output_offset
);
3820 outrel
[1].r_offset
+= (input_section
->output_section
->vma
3821 + input_section
->output_offset
);
3822 outrel
[2].r_offset
+= (input_section
->output_section
->vma
3823 + input_section
->output_offset
);
3826 /* Put the relocation back out. We have to use the special
3827 relocation outputter in the 64-bit case since the 64-bit
3828 relocation format is non-standard. */
3829 if (ABI_64_P (output_bfd
))
3831 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
3832 (output_bfd
, &outrel
[0],
3834 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
3837 bfd_elf32_swap_reloc_out
3838 (output_bfd
, &outrel
[0],
3839 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
3841 /* We've now added another relocation. */
3842 ++sreloc
->reloc_count
;
3844 /* Make sure the output section is writable. The dynamic linker
3845 will be writing to it. */
3846 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
3849 /* On IRIX5, make an entry of compact relocation info. */
3850 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
3852 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
3857 Elf32_crinfo cptrel
;
3859 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
3860 cptrel
.vaddr
= (rel
->r_offset
3861 + input_section
->output_section
->vma
3862 + input_section
->output_offset
);
3863 if (r_type
== R_MIPS_REL32
)
3864 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
3866 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
3867 mips_elf_set_cr_dist2to (cptrel
, 0);
3868 cptrel
.konst
= *addendp
;
3870 cr
= (scpt
->contents
3871 + sizeof (Elf32_External_compact_rel
));
3872 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
3873 ((Elf32_External_crinfo
*) cr
3874 + scpt
->reloc_count
));
3875 ++scpt
->reloc_count
;
3882 /* Return the MACH for a MIPS e_flags value. */
3885 _bfd_elf_mips_mach (flagword flags
)
3887 switch (flags
& EF_MIPS_MACH
)
3889 case E_MIPS_MACH_3900
:
3890 return bfd_mach_mips3900
;
3892 case E_MIPS_MACH_4010
:
3893 return bfd_mach_mips4010
;
3895 case E_MIPS_MACH_4100
:
3896 return bfd_mach_mips4100
;
3898 case E_MIPS_MACH_4111
:
3899 return bfd_mach_mips4111
;
3901 case E_MIPS_MACH_4120
:
3902 return bfd_mach_mips4120
;
3904 case E_MIPS_MACH_4650
:
3905 return bfd_mach_mips4650
;
3907 case E_MIPS_MACH_5400
:
3908 return bfd_mach_mips5400
;
3910 case E_MIPS_MACH_5500
:
3911 return bfd_mach_mips5500
;
3913 case E_MIPS_MACH_SB1
:
3914 return bfd_mach_mips_sb1
;
3917 switch (flags
& EF_MIPS_ARCH
)
3921 return bfd_mach_mips3000
;
3925 return bfd_mach_mips6000
;
3929 return bfd_mach_mips4000
;
3933 return bfd_mach_mips8000
;
3937 return bfd_mach_mips5
;
3940 case E_MIPS_ARCH_32
:
3941 return bfd_mach_mipsisa32
;
3944 case E_MIPS_ARCH_64
:
3945 return bfd_mach_mipsisa64
;
3948 case E_MIPS_ARCH_32R2
:
3949 return bfd_mach_mipsisa32r2
;
3952 case E_MIPS_ARCH_64R2
:
3953 return bfd_mach_mipsisa64r2
;
3961 /* Return printable name for ABI. */
3963 static INLINE
char *
3964 elf_mips_abi_name (bfd
*abfd
)
3968 flags
= elf_elfheader (abfd
)->e_flags
;
3969 switch (flags
& EF_MIPS_ABI
)
3972 if (ABI_N32_P (abfd
))
3974 else if (ABI_64_P (abfd
))
3978 case E_MIPS_ABI_O32
:
3980 case E_MIPS_ABI_O64
:
3982 case E_MIPS_ABI_EABI32
:
3984 case E_MIPS_ABI_EABI64
:
3987 return "unknown abi";
3991 /* MIPS ELF uses two common sections. One is the usual one, and the
3992 other is for small objects. All the small objects are kept
3993 together, and then referenced via the gp pointer, which yields
3994 faster assembler code. This is what we use for the small common
3995 section. This approach is copied from ecoff.c. */
3996 static asection mips_elf_scom_section
;
3997 static asymbol mips_elf_scom_symbol
;
3998 static asymbol
*mips_elf_scom_symbol_ptr
;
4000 /* MIPS ELF also uses an acommon section, which represents an
4001 allocated common symbol which may be overridden by a
4002 definition in a shared library. */
4003 static asection mips_elf_acom_section
;
4004 static asymbol mips_elf_acom_symbol
;
4005 static asymbol
*mips_elf_acom_symbol_ptr
;
4007 /* Handle the special MIPS section numbers that a symbol may use.
4008 This is used for both the 32-bit and the 64-bit ABI. */
4011 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
4013 elf_symbol_type
*elfsym
;
4015 elfsym
= (elf_symbol_type
*) asym
;
4016 switch (elfsym
->internal_elf_sym
.st_shndx
)
4018 case SHN_MIPS_ACOMMON
:
4019 /* This section is used in a dynamically linked executable file.
4020 It is an allocated common section. The dynamic linker can
4021 either resolve these symbols to something in a shared
4022 library, or it can just leave them here. For our purposes,
4023 we can consider these symbols to be in a new section. */
4024 if (mips_elf_acom_section
.name
== NULL
)
4026 /* Initialize the acommon section. */
4027 mips_elf_acom_section
.name
= ".acommon";
4028 mips_elf_acom_section
.flags
= SEC_ALLOC
;
4029 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
4030 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
4031 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
4032 mips_elf_acom_symbol
.name
= ".acommon";
4033 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
4034 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
4035 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
4037 asym
->section
= &mips_elf_acom_section
;
4041 /* Common symbols less than the GP size are automatically
4042 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
4043 if (asym
->value
> elf_gp_size (abfd
)
4044 || IRIX_COMPAT (abfd
) == ict_irix6
)
4047 case SHN_MIPS_SCOMMON
:
4048 if (mips_elf_scom_section
.name
== NULL
)
4050 /* Initialize the small common section. */
4051 mips_elf_scom_section
.name
= ".scommon";
4052 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
4053 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
4054 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
4055 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
4056 mips_elf_scom_symbol
.name
= ".scommon";
4057 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
4058 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
4059 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
4061 asym
->section
= &mips_elf_scom_section
;
4062 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4065 case SHN_MIPS_SUNDEFINED
:
4066 asym
->section
= bfd_und_section_ptr
;
4069 #if 0 /* for SGI_COMPAT */
4071 asym
->section
= mips_elf_text_section_ptr
;
4075 asym
->section
= mips_elf_data_section_ptr
;
4081 /* Work over a section just before writing it out. This routine is
4082 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
4083 sections that need the SHF_MIPS_GPREL flag by name; there has to be
4087 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
4089 if (hdr
->sh_type
== SHT_MIPS_REGINFO
4090 && hdr
->sh_size
> 0)
4094 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
4095 BFD_ASSERT (hdr
->contents
== NULL
);
4098 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
4101 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
4102 if (bfd_bwrite (buf
, 4, abfd
) != 4)
4106 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
4107 && hdr
->bfd_section
!= NULL
4108 && mips_elf_section_data (hdr
->bfd_section
) != NULL
4109 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
4111 bfd_byte
*contents
, *l
, *lend
;
4113 /* We stored the section contents in the tdata field in the
4114 set_section_contents routine. We save the section contents
4115 so that we don't have to read them again.
4116 At this point we know that elf_gp is set, so we can look
4117 through the section contents to see if there is an
4118 ODK_REGINFO structure. */
4120 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
4122 lend
= contents
+ hdr
->sh_size
;
4123 while (l
+ sizeof (Elf_External_Options
) <= lend
)
4125 Elf_Internal_Options intopt
;
4127 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
4129 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
4136 + sizeof (Elf_External_Options
)
4137 + (sizeof (Elf64_External_RegInfo
) - 8)),
4140 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
4141 if (bfd_bwrite (buf
, 8, abfd
) != 8)
4144 else if (intopt
.kind
== ODK_REGINFO
)
4151 + sizeof (Elf_External_Options
)
4152 + (sizeof (Elf32_External_RegInfo
) - 4)),
4155 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
4156 if (bfd_bwrite (buf
, 4, abfd
) != 4)
4163 if (hdr
->bfd_section
!= NULL
)
4165 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
4167 if (strcmp (name
, ".sdata") == 0
4168 || strcmp (name
, ".lit8") == 0
4169 || strcmp (name
, ".lit4") == 0)
4171 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
4172 hdr
->sh_type
= SHT_PROGBITS
;
4174 else if (strcmp (name
, ".sbss") == 0)
4176 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
4177 hdr
->sh_type
= SHT_NOBITS
;
4179 else if (strcmp (name
, ".srdata") == 0)
4181 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
4182 hdr
->sh_type
= SHT_PROGBITS
;
4184 else if (strcmp (name
, ".compact_rel") == 0)
4187 hdr
->sh_type
= SHT_PROGBITS
;
4189 else if (strcmp (name
, ".rtproc") == 0)
4191 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
4193 unsigned int adjust
;
4195 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
4197 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
4205 /* Handle a MIPS specific section when reading an object file. This
4206 is called when elfcode.h finds a section with an unknown type.
4207 This routine supports both the 32-bit and 64-bit ELF ABI.
4209 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
4213 _bfd_mips_elf_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
4218 /* There ought to be a place to keep ELF backend specific flags, but
4219 at the moment there isn't one. We just keep track of the
4220 sections by their name, instead. Fortunately, the ABI gives
4221 suggested names for all the MIPS specific sections, so we will
4222 probably get away with this. */
4223 switch (hdr
->sh_type
)
4225 case SHT_MIPS_LIBLIST
:
4226 if (strcmp (name
, ".liblist") != 0)
4230 if (strcmp (name
, ".msym") != 0)
4233 case SHT_MIPS_CONFLICT
:
4234 if (strcmp (name
, ".conflict") != 0)
4237 case SHT_MIPS_GPTAB
:
4238 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
4241 case SHT_MIPS_UCODE
:
4242 if (strcmp (name
, ".ucode") != 0)
4245 case SHT_MIPS_DEBUG
:
4246 if (strcmp (name
, ".mdebug") != 0)
4248 flags
= SEC_DEBUGGING
;
4250 case SHT_MIPS_REGINFO
:
4251 if (strcmp (name
, ".reginfo") != 0
4252 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
4254 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
4256 case SHT_MIPS_IFACE
:
4257 if (strcmp (name
, ".MIPS.interfaces") != 0)
4260 case SHT_MIPS_CONTENT
:
4261 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
4264 case SHT_MIPS_OPTIONS
:
4265 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
4268 case SHT_MIPS_DWARF
:
4269 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
4272 case SHT_MIPS_SYMBOL_LIB
:
4273 if (strcmp (name
, ".MIPS.symlib") != 0)
4276 case SHT_MIPS_EVENTS
:
4277 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
4278 && strncmp (name
, ".MIPS.post_rel",
4279 sizeof ".MIPS.post_rel" - 1) != 0)
4286 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
4291 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
4292 (bfd_get_section_flags (abfd
,
4298 /* FIXME: We should record sh_info for a .gptab section. */
4300 /* For a .reginfo section, set the gp value in the tdata information
4301 from the contents of this section. We need the gp value while
4302 processing relocs, so we just get it now. The .reginfo section
4303 is not used in the 64-bit MIPS ELF ABI. */
4304 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
4306 Elf32_External_RegInfo ext
;
4309 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
4310 &ext
, 0, sizeof ext
))
4312 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
4313 elf_gp (abfd
) = s
.ri_gp_value
;
4316 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
4317 set the gp value based on what we find. We may see both
4318 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
4319 they should agree. */
4320 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
4322 bfd_byte
*contents
, *l
, *lend
;
4324 contents
= bfd_malloc (hdr
->sh_size
);
4325 if (contents
== NULL
)
4327 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
4334 lend
= contents
+ hdr
->sh_size
;
4335 while (l
+ sizeof (Elf_External_Options
) <= lend
)
4337 Elf_Internal_Options intopt
;
4339 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
4341 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
4343 Elf64_Internal_RegInfo intreg
;
4345 bfd_mips_elf64_swap_reginfo_in
4347 ((Elf64_External_RegInfo
*)
4348 (l
+ sizeof (Elf_External_Options
))),
4350 elf_gp (abfd
) = intreg
.ri_gp_value
;
4352 else if (intopt
.kind
== ODK_REGINFO
)
4354 Elf32_RegInfo intreg
;
4356 bfd_mips_elf32_swap_reginfo_in
4358 ((Elf32_External_RegInfo
*)
4359 (l
+ sizeof (Elf_External_Options
))),
4361 elf_gp (abfd
) = intreg
.ri_gp_value
;
4371 /* Set the correct type for a MIPS ELF section. We do this by the
4372 section name, which is a hack, but ought to work. This routine is
4373 used by both the 32-bit and the 64-bit ABI. */
4376 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
4378 register const char *name
;
4380 name
= bfd_get_section_name (abfd
, sec
);
4382 if (strcmp (name
, ".liblist") == 0)
4384 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
4385 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
4386 /* The sh_link field is set in final_write_processing. */
4388 else if (strcmp (name
, ".conflict") == 0)
4389 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
4390 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4392 hdr
->sh_type
= SHT_MIPS_GPTAB
;
4393 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
4394 /* The sh_info field is set in final_write_processing. */
4396 else if (strcmp (name
, ".ucode") == 0)
4397 hdr
->sh_type
= SHT_MIPS_UCODE
;
4398 else if (strcmp (name
, ".mdebug") == 0)
4400 hdr
->sh_type
= SHT_MIPS_DEBUG
;
4401 /* In a shared object on IRIX 5.3, the .mdebug section has an
4402 entsize of 0. FIXME: Does this matter? */
4403 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
4404 hdr
->sh_entsize
= 0;
4406 hdr
->sh_entsize
= 1;
4408 else if (strcmp (name
, ".reginfo") == 0)
4410 hdr
->sh_type
= SHT_MIPS_REGINFO
;
4411 /* In a shared object on IRIX 5.3, the .reginfo section has an
4412 entsize of 0x18. FIXME: Does this matter? */
4413 if (SGI_COMPAT (abfd
))
4415 if ((abfd
->flags
& DYNAMIC
) != 0)
4416 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
4418 hdr
->sh_entsize
= 1;
4421 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
4423 else if (SGI_COMPAT (abfd
)
4424 && (strcmp (name
, ".hash") == 0
4425 || strcmp (name
, ".dynamic") == 0
4426 || strcmp (name
, ".dynstr") == 0))
4428 if (SGI_COMPAT (abfd
))
4429 hdr
->sh_entsize
= 0;
4431 /* This isn't how the IRIX6 linker behaves. */
4432 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
4435 else if (strcmp (name
, ".got") == 0
4436 || strcmp (name
, ".srdata") == 0
4437 || strcmp (name
, ".sdata") == 0
4438 || strcmp (name
, ".sbss") == 0
4439 || strcmp (name
, ".lit4") == 0
4440 || strcmp (name
, ".lit8") == 0)
4441 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
4442 else if (strcmp (name
, ".MIPS.interfaces") == 0)
4444 hdr
->sh_type
= SHT_MIPS_IFACE
;
4445 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
4447 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
4449 hdr
->sh_type
= SHT_MIPS_CONTENT
;
4450 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
4451 /* The sh_info field is set in final_write_processing. */
4453 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
4455 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
4456 hdr
->sh_entsize
= 1;
4457 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
4459 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
4460 hdr
->sh_type
= SHT_MIPS_DWARF
;
4461 else if (strcmp (name
, ".MIPS.symlib") == 0)
4463 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
4464 /* The sh_link and sh_info fields are set in
4465 final_write_processing. */
4467 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
4468 || strncmp (name
, ".MIPS.post_rel",
4469 sizeof ".MIPS.post_rel" - 1) == 0)
4471 hdr
->sh_type
= SHT_MIPS_EVENTS
;
4472 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
4473 /* The sh_link field is set in final_write_processing. */
4475 else if (strcmp (name
, ".msym") == 0)
4477 hdr
->sh_type
= SHT_MIPS_MSYM
;
4478 hdr
->sh_flags
|= SHF_ALLOC
;
4479 hdr
->sh_entsize
= 8;
4482 /* The generic elf_fake_sections will set up REL_HDR using the default
4483 kind of relocations. We used to set up a second header for the
4484 non-default kind of relocations here, but only NewABI would use
4485 these, and the IRIX ld doesn't like resulting empty RELA sections.
4486 Thus we create those header only on demand now. */
4491 /* Given a BFD section, try to locate the corresponding ELF section
4492 index. This is used by both the 32-bit and the 64-bit ABI.
4493 Actually, it's not clear to me that the 64-bit ABI supports these,
4494 but for non-PIC objects we will certainly want support for at least
4495 the .scommon section. */
4498 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4499 asection
*sec
, int *retval
)
4501 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
4503 *retval
= SHN_MIPS_SCOMMON
;
4506 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
4508 *retval
= SHN_MIPS_ACOMMON
;
4514 /* Hook called by the linker routine which adds symbols from an object
4515 file. We must handle the special MIPS section numbers here. */
4518 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
4519 const Elf_Internal_Sym
*sym
, const char **namep
,
4520 flagword
*flagsp ATTRIBUTE_UNUSED
,
4521 asection
**secp
, bfd_vma
*valp
)
4523 if (SGI_COMPAT (abfd
)
4524 && (abfd
->flags
& DYNAMIC
) != 0
4525 && strcmp (*namep
, "_rld_new_interface") == 0)
4527 /* Skip IRIX5 rld entry name. */
4532 switch (sym
->st_shndx
)
4535 /* Common symbols less than the GP size are automatically
4536 treated as SHN_MIPS_SCOMMON symbols. */
4537 if (sym
->st_size
> elf_gp_size (abfd
)
4538 || IRIX_COMPAT (abfd
) == ict_irix6
)
4541 case SHN_MIPS_SCOMMON
:
4542 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
4543 (*secp
)->flags
|= SEC_IS_COMMON
;
4544 *valp
= sym
->st_size
;
4548 /* This section is used in a shared object. */
4549 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
4551 asymbol
*elf_text_symbol
;
4552 asection
*elf_text_section
;
4553 bfd_size_type amt
= sizeof (asection
);
4555 elf_text_section
= bfd_zalloc (abfd
, amt
);
4556 if (elf_text_section
== NULL
)
4559 amt
= sizeof (asymbol
);
4560 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
4561 if (elf_text_symbol
== NULL
)
4564 /* Initialize the section. */
4566 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
4567 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
4569 elf_text_section
->symbol
= elf_text_symbol
;
4570 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
4572 elf_text_section
->name
= ".text";
4573 elf_text_section
->flags
= SEC_NO_FLAGS
;
4574 elf_text_section
->output_section
= NULL
;
4575 elf_text_section
->owner
= abfd
;
4576 elf_text_symbol
->name
= ".text";
4577 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
4578 elf_text_symbol
->section
= elf_text_section
;
4580 /* This code used to do *secp = bfd_und_section_ptr if
4581 info->shared. I don't know why, and that doesn't make sense,
4582 so I took it out. */
4583 *secp
= elf_tdata (abfd
)->elf_text_section
;
4586 case SHN_MIPS_ACOMMON
:
4587 /* Fall through. XXX Can we treat this as allocated data? */
4589 /* This section is used in a shared object. */
4590 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
4592 asymbol
*elf_data_symbol
;
4593 asection
*elf_data_section
;
4594 bfd_size_type amt
= sizeof (asection
);
4596 elf_data_section
= bfd_zalloc (abfd
, amt
);
4597 if (elf_data_section
== NULL
)
4600 amt
= sizeof (asymbol
);
4601 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
4602 if (elf_data_symbol
== NULL
)
4605 /* Initialize the section. */
4607 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
4608 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
4610 elf_data_section
->symbol
= elf_data_symbol
;
4611 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
4613 elf_data_section
->name
= ".data";
4614 elf_data_section
->flags
= SEC_NO_FLAGS
;
4615 elf_data_section
->output_section
= NULL
;
4616 elf_data_section
->owner
= abfd
;
4617 elf_data_symbol
->name
= ".data";
4618 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
4619 elf_data_symbol
->section
= elf_data_section
;
4621 /* This code used to do *secp = bfd_und_section_ptr if
4622 info->shared. I don't know why, and that doesn't make sense,
4623 so I took it out. */
4624 *secp
= elf_tdata (abfd
)->elf_data_section
;
4627 case SHN_MIPS_SUNDEFINED
:
4628 *secp
= bfd_und_section_ptr
;
4632 if (SGI_COMPAT (abfd
)
4634 && info
->hash
->creator
== abfd
->xvec
4635 && strcmp (*namep
, "__rld_obj_head") == 0)
4637 struct elf_link_hash_entry
*h
;
4638 struct bfd_link_hash_entry
*bh
;
4640 /* Mark __rld_obj_head as dynamic. */
4642 if (! (_bfd_generic_link_add_one_symbol
4643 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
4644 get_elf_backend_data (abfd
)->collect
, &bh
)))
4647 h
= (struct elf_link_hash_entry
*) bh
;
4648 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4649 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4650 h
->type
= STT_OBJECT
;
4652 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4655 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
4658 /* If this is a mips16 text symbol, add 1 to the value to make it
4659 odd. This will cause something like .word SYM to come up with
4660 the right value when it is loaded into the PC. */
4661 if (sym
->st_other
== STO_MIPS16
)
4667 /* This hook function is called before the linker writes out a global
4668 symbol. We mark symbols as small common if appropriate. This is
4669 also where we undo the increment of the value for a mips16 symbol. */
4672 _bfd_mips_elf_link_output_symbol_hook
4673 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4674 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
4675 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
4677 /* If we see a common symbol, which implies a relocatable link, then
4678 if a symbol was small common in an input file, mark it as small
4679 common in the output file. */
4680 if (sym
->st_shndx
== SHN_COMMON
4681 && strcmp (input_sec
->name
, ".scommon") == 0)
4682 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
4684 if (sym
->st_other
== STO_MIPS16
4685 && (sym
->st_value
& 1) != 0)
4691 /* Functions for the dynamic linker. */
4693 /* Create dynamic sections when linking against a dynamic object. */
4696 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
4698 struct elf_link_hash_entry
*h
;
4699 struct bfd_link_hash_entry
*bh
;
4701 register asection
*s
;
4702 const char * const *namep
;
4704 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4705 | SEC_LINKER_CREATED
| SEC_READONLY
);
4707 /* Mips ABI requests the .dynamic section to be read only. */
4708 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4711 if (! bfd_set_section_flags (abfd
, s
, flags
))
4715 /* We need to create .got section. */
4716 if (! mips_elf_create_got_section (abfd
, info
, FALSE
))
4719 if (! mips_elf_rel_dyn_section (elf_hash_table (info
)->dynobj
, TRUE
))
4722 /* Create .stub section. */
4723 if (bfd_get_section_by_name (abfd
,
4724 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
4726 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
4728 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
4729 || ! bfd_set_section_alignment (abfd
, s
,
4730 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4734 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
4736 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
4738 s
= bfd_make_section (abfd
, ".rld_map");
4740 || ! bfd_set_section_flags (abfd
, s
, flags
&~ (flagword
) SEC_READONLY
)
4741 || ! bfd_set_section_alignment (abfd
, s
,
4742 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4746 /* On IRIX5, we adjust add some additional symbols and change the
4747 alignments of several sections. There is no ABI documentation
4748 indicating that this is necessary on IRIX6, nor any evidence that
4749 the linker takes such action. */
4750 if (IRIX_COMPAT (abfd
) == ict_irix5
)
4752 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
4755 if (! (_bfd_generic_link_add_one_symbol
4756 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
4757 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4760 h
= (struct elf_link_hash_entry
*) bh
;
4761 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4762 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4763 h
->type
= STT_SECTION
;
4765 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4769 /* We need to create a .compact_rel section. */
4770 if (SGI_COMPAT (abfd
))
4772 if (!mips_elf_create_compact_rel_section (abfd
, info
))
4776 /* Change alignments of some sections. */
4777 s
= bfd_get_section_by_name (abfd
, ".hash");
4779 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
4780 s
= bfd_get_section_by_name (abfd
, ".dynsym");
4782 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
4783 s
= bfd_get_section_by_name (abfd
, ".dynstr");
4785 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
4786 s
= bfd_get_section_by_name (abfd
, ".reginfo");
4788 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
4789 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4791 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
4798 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
4800 if (!(_bfd_generic_link_add_one_symbol
4801 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
4802 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4805 h
= (struct elf_link_hash_entry
*) bh
;
4806 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4807 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4808 h
->type
= STT_SECTION
;
4810 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4813 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
4815 /* __rld_map is a four byte word located in the .data section
4816 and is filled in by the rtld to contain a pointer to
4817 the _r_debug structure. Its symbol value will be set in
4818 _bfd_mips_elf_finish_dynamic_symbol. */
4819 s
= bfd_get_section_by_name (abfd
, ".rld_map");
4820 BFD_ASSERT (s
!= NULL
);
4822 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
4824 if (!(_bfd_generic_link_add_one_symbol
4825 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
4826 get_elf_backend_data (abfd
)->collect
, &bh
)))
4829 h
= (struct elf_link_hash_entry
*) bh
;
4830 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4831 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4832 h
->type
= STT_OBJECT
;
4834 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4842 /* Look through the relocs for a section during the first phase, and
4843 allocate space in the global offset table. */
4846 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4847 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4851 Elf_Internal_Shdr
*symtab_hdr
;
4852 struct elf_link_hash_entry
**sym_hashes
;
4853 struct mips_got_info
*g
;
4855 const Elf_Internal_Rela
*rel
;
4856 const Elf_Internal_Rela
*rel_end
;
4859 const struct elf_backend_data
*bed
;
4861 if (info
->relocatable
)
4864 dynobj
= elf_hash_table (info
)->dynobj
;
4865 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4866 sym_hashes
= elf_sym_hashes (abfd
);
4867 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
4869 /* Check for the mips16 stub sections. */
4871 name
= bfd_get_section_name (abfd
, sec
);
4872 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
4874 unsigned long r_symndx
;
4876 /* Look at the relocation information to figure out which symbol
4879 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
4881 if (r_symndx
< extsymoff
4882 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
4886 /* This stub is for a local symbol. This stub will only be
4887 needed if there is some relocation in this BFD, other
4888 than a 16 bit function call, which refers to this symbol. */
4889 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4891 Elf_Internal_Rela
*sec_relocs
;
4892 const Elf_Internal_Rela
*r
, *rend
;
4894 /* We can ignore stub sections when looking for relocs. */
4895 if ((o
->flags
& SEC_RELOC
) == 0
4896 || o
->reloc_count
== 0
4897 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
4898 sizeof FN_STUB
- 1) == 0
4899 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
4900 sizeof CALL_STUB
- 1) == 0
4901 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
4902 sizeof CALL_FP_STUB
- 1) == 0)
4906 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
4908 if (sec_relocs
== NULL
)
4911 rend
= sec_relocs
+ o
->reloc_count
;
4912 for (r
= sec_relocs
; r
< rend
; r
++)
4913 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
4914 && ELF_R_TYPE (abfd
, r
->r_info
) != R_MIPS16_26
)
4917 if (elf_section_data (o
)->relocs
!= sec_relocs
)
4926 /* There is no non-call reloc for this stub, so we do
4927 not need it. Since this function is called before
4928 the linker maps input sections to output sections, we
4929 can easily discard it by setting the SEC_EXCLUDE
4931 sec
->flags
|= SEC_EXCLUDE
;
4935 /* Record this stub in an array of local symbol stubs for
4937 if (elf_tdata (abfd
)->local_stubs
== NULL
)
4939 unsigned long symcount
;
4943 if (elf_bad_symtab (abfd
))
4944 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
4946 symcount
= symtab_hdr
->sh_info
;
4947 amt
= symcount
* sizeof (asection
*);
4948 n
= bfd_zalloc (abfd
, amt
);
4951 elf_tdata (abfd
)->local_stubs
= n
;
4954 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
4956 /* We don't need to set mips16_stubs_seen in this case.
4957 That flag is used to see whether we need to look through
4958 the global symbol table for stubs. We don't need to set
4959 it here, because we just have a local stub. */
4963 struct mips_elf_link_hash_entry
*h
;
4965 h
= ((struct mips_elf_link_hash_entry
*)
4966 sym_hashes
[r_symndx
- extsymoff
]);
4968 /* H is the symbol this stub is for. */
4971 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
4974 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
4975 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4977 unsigned long r_symndx
;
4978 struct mips_elf_link_hash_entry
*h
;
4981 /* Look at the relocation information to figure out which symbol
4984 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
4986 if (r_symndx
< extsymoff
4987 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
4989 /* This stub was actually built for a static symbol defined
4990 in the same file. We assume that all static symbols in
4991 mips16 code are themselves mips16, so we can simply
4992 discard this stub. Since this function is called before
4993 the linker maps input sections to output sections, we can
4994 easily discard it by setting the SEC_EXCLUDE flag. */
4995 sec
->flags
|= SEC_EXCLUDE
;
4999 h
= ((struct mips_elf_link_hash_entry
*)
5000 sym_hashes
[r_symndx
- extsymoff
]);
5002 /* H is the symbol this stub is for. */
5004 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
5005 loc
= &h
->call_fp_stub
;
5007 loc
= &h
->call_stub
;
5009 /* If we already have an appropriate stub for this function, we
5010 don't need another one, so we can discard this one. Since
5011 this function is called before the linker maps input sections
5012 to output sections, we can easily discard it by setting the
5013 SEC_EXCLUDE flag. We can also discard this section if we
5014 happen to already know that this is a mips16 function; it is
5015 not necessary to check this here, as it is checked later, but
5016 it is slightly faster to check now. */
5017 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
5019 sec
->flags
|= SEC_EXCLUDE
;
5024 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
5034 sgot
= mips_elf_got_section (dynobj
, FALSE
);
5039 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
5040 g
= mips_elf_section_data (sgot
)->u
.got_info
;
5041 BFD_ASSERT (g
!= NULL
);
5046 bed
= get_elf_backend_data (abfd
);
5047 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
5048 for (rel
= relocs
; rel
< rel_end
; ++rel
)
5050 unsigned long r_symndx
;
5051 unsigned int r_type
;
5052 struct elf_link_hash_entry
*h
;
5054 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
5055 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
5057 if (r_symndx
< extsymoff
)
5059 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
5061 (*_bfd_error_handler
)
5062 (_("%s: Malformed reloc detected for section %s"),
5063 bfd_archive_filename (abfd
), name
);
5064 bfd_set_error (bfd_error_bad_value
);
5069 h
= sym_hashes
[r_symndx
- extsymoff
];
5071 /* This may be an indirect symbol created because of a version. */
5074 while (h
->root
.type
== bfd_link_hash_indirect
)
5075 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5079 /* Some relocs require a global offset table. */
5080 if (dynobj
== NULL
|| sgot
== NULL
)
5086 case R_MIPS_CALL_HI16
:
5087 case R_MIPS_CALL_LO16
:
5088 case R_MIPS_GOT_HI16
:
5089 case R_MIPS_GOT_LO16
:
5090 case R_MIPS_GOT_PAGE
:
5091 case R_MIPS_GOT_OFST
:
5092 case R_MIPS_GOT_DISP
:
5094 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5095 if (! mips_elf_create_got_section (dynobj
, info
, FALSE
))
5097 g
= mips_elf_got_info (dynobj
, &sgot
);
5104 && (info
->shared
|| h
!= NULL
)
5105 && (sec
->flags
& SEC_ALLOC
) != 0)
5106 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5114 if (!h
&& (r_type
== R_MIPS_CALL_LO16
5115 || r_type
== R_MIPS_GOT_LO16
5116 || r_type
== R_MIPS_GOT_DISP
))
5118 /* We may need a local GOT entry for this relocation. We
5119 don't count R_MIPS_GOT_PAGE because we can estimate the
5120 maximum number of pages needed by looking at the size of
5121 the segment. Similar comments apply to R_MIPS_GOT16 and
5122 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
5123 R_MIPS_CALL_HI16 because these are always followed by an
5124 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
5125 if (! mips_elf_record_local_got_symbol (abfd
, r_symndx
,
5135 (*_bfd_error_handler
)
5136 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
5137 bfd_archive_filename (abfd
), (unsigned long) rel
->r_offset
);
5138 bfd_set_error (bfd_error_bad_value
);
5143 case R_MIPS_CALL_HI16
:
5144 case R_MIPS_CALL_LO16
:
5147 /* This symbol requires a global offset table entry. */
5148 if (! mips_elf_record_global_got_symbol (h
, abfd
, info
, g
))
5151 /* We need a stub, not a plt entry for the undefined
5152 function. But we record it as if it needs plt. See
5153 elf_adjust_dynamic_symbol in elflink.h. */
5154 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
5159 case R_MIPS_GOT_PAGE
:
5160 /* If this is a global, overridable symbol, GOT_PAGE will
5161 decay to GOT_DISP, so we'll need a GOT entry for it. */
5166 struct mips_elf_link_hash_entry
*hmips
=
5167 (struct mips_elf_link_hash_entry
*) h
;
5169 while (hmips
->root
.root
.type
== bfd_link_hash_indirect
5170 || hmips
->root
.root
.type
== bfd_link_hash_warning
)
5171 hmips
= (struct mips_elf_link_hash_entry
*)
5172 hmips
->root
.root
.u
.i
.link
;
5174 if ((hmips
->root
.root
.type
== bfd_link_hash_defined
5175 || hmips
->root
.root
.type
== bfd_link_hash_defweak
)
5176 && hmips
->root
.root
.u
.def
.section
5177 && ! (info
->shared
&& ! info
->symbolic
5178 && ! (hmips
->root
.elf_link_hash_flags
5179 & ELF_LINK_FORCED_LOCAL
))
5180 /* If we've encountered any other relocation
5181 referencing the symbol, we'll have marked it as
5182 dynamic, and, even though we might be able to get
5183 rid of the GOT entry should we know for sure all
5184 previous relocations were GOT_PAGE ones, at this
5185 point we can't tell, so just keep using the
5186 symbol as dynamic. This is very important in the
5187 multi-got case, since we don't decide whether to
5188 decay GOT_PAGE to GOT_DISP on a per-GOT basis: if
5189 the symbol is dynamic, we'll need a GOT entry for
5190 every GOT in which the symbol is referenced with
5191 a GOT_PAGE relocation. */
5192 && hmips
->root
.dynindx
== -1)
5198 case R_MIPS_GOT_HI16
:
5199 case R_MIPS_GOT_LO16
:
5200 case R_MIPS_GOT_DISP
:
5201 /* This symbol requires a global offset table entry. */
5202 if (h
&& ! mips_elf_record_global_got_symbol (h
, abfd
, info
, g
))
5209 if ((info
->shared
|| h
!= NULL
)
5210 && (sec
->flags
& SEC_ALLOC
) != 0)
5214 sreloc
= mips_elf_rel_dyn_section (dynobj
, TRUE
);
5218 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
5221 /* When creating a shared object, we must copy these
5222 reloc types into the output file as R_MIPS_REL32
5223 relocs. We make room for this reloc in the
5224 .rel.dyn reloc section. */
5225 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
5226 if ((sec
->flags
& MIPS_READONLY_SECTION
)
5227 == MIPS_READONLY_SECTION
)
5228 /* We tell the dynamic linker that there are
5229 relocations against the text segment. */
5230 info
->flags
|= DF_TEXTREL
;
5234 struct mips_elf_link_hash_entry
*hmips
;
5236 /* We only need to copy this reloc if the symbol is
5237 defined in a dynamic object. */
5238 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5239 ++hmips
->possibly_dynamic_relocs
;
5240 if ((sec
->flags
& MIPS_READONLY_SECTION
)
5241 == MIPS_READONLY_SECTION
)
5242 /* We need it to tell the dynamic linker if there
5243 are relocations against the text segment. */
5244 hmips
->readonly_reloc
= TRUE
;
5247 /* Even though we don't directly need a GOT entry for
5248 this symbol, a symbol must have a dynamic symbol
5249 table index greater that DT_MIPS_GOTSYM if there are
5250 dynamic relocations against it. */
5254 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5255 if (! mips_elf_create_got_section (dynobj
, info
, TRUE
))
5257 g
= mips_elf_got_info (dynobj
, &sgot
);
5258 if (! mips_elf_record_global_got_symbol (h
, abfd
, info
, g
))
5263 if (SGI_COMPAT (abfd
))
5264 mips_elf_hash_table (info
)->compact_rel_size
+=
5265 sizeof (Elf32_External_crinfo
);
5269 case R_MIPS_GPREL16
:
5270 case R_MIPS_LITERAL
:
5271 case R_MIPS_GPREL32
:
5272 if (SGI_COMPAT (abfd
))
5273 mips_elf_hash_table (info
)->compact_rel_size
+=
5274 sizeof (Elf32_External_crinfo
);
5277 /* This relocation describes the C++ object vtable hierarchy.
5278 Reconstruct it for later use during GC. */
5279 case R_MIPS_GNU_VTINHERIT
:
5280 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5284 /* This relocation describes which C++ vtable entries are actually
5285 used. Record for later use during GC. */
5286 case R_MIPS_GNU_VTENTRY
:
5287 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
5295 /* We must not create a stub for a symbol that has relocations
5296 related to taking the function's address. */
5302 struct mips_elf_link_hash_entry
*mh
;
5304 mh
= (struct mips_elf_link_hash_entry
*) h
;
5305 mh
->no_fn_stub
= TRUE
;
5309 case R_MIPS_CALL_HI16
:
5310 case R_MIPS_CALL_LO16
:
5315 /* If this reloc is not a 16 bit call, and it has a global
5316 symbol, then we will need the fn_stub if there is one.
5317 References from a stub section do not count. */
5319 && r_type
!= R_MIPS16_26
5320 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
5321 sizeof FN_STUB
- 1) != 0
5322 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
5323 sizeof CALL_STUB
- 1) != 0
5324 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
5325 sizeof CALL_FP_STUB
- 1) != 0)
5327 struct mips_elf_link_hash_entry
*mh
;
5329 mh
= (struct mips_elf_link_hash_entry
*) h
;
5330 mh
->need_fn_stub
= TRUE
;
5338 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
5339 struct bfd_link_info
*link_info
,
5342 Elf_Internal_Rela
*internal_relocs
;
5343 Elf_Internal_Rela
*irel
, *irelend
;
5344 Elf_Internal_Shdr
*symtab_hdr
;
5345 bfd_byte
*contents
= NULL
;
5346 bfd_byte
*free_contents
= NULL
;
5348 bfd_boolean changed_contents
= FALSE
;
5349 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
5350 Elf_Internal_Sym
*isymbuf
= NULL
;
5352 /* We are not currently changing any sizes, so only one pass. */
5355 if (link_info
->relocatable
)
5358 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
5359 link_info
->keep_memory
);
5360 if (internal_relocs
== NULL
)
5363 irelend
= internal_relocs
+ sec
->reloc_count
5364 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
5365 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5366 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
5368 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
5371 bfd_signed_vma sym_offset
;
5372 unsigned int r_type
;
5373 unsigned long r_symndx
;
5375 unsigned long instruction
;
5377 /* Turn jalr into bgezal, and jr into beq, if they're marked
5378 with a JALR relocation, that indicate where they jump to.
5379 This saves some pipeline bubbles. */
5380 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
5381 if (r_type
!= R_MIPS_JALR
)
5384 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
5385 /* Compute the address of the jump target. */
5386 if (r_symndx
>= extsymoff
)
5388 struct mips_elf_link_hash_entry
*h
5389 = ((struct mips_elf_link_hash_entry
*)
5390 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
5392 while (h
->root
.root
.type
== bfd_link_hash_indirect
5393 || h
->root
.root
.type
== bfd_link_hash_warning
)
5394 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
5396 /* If a symbol is undefined, or if it may be overridden,
5398 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
5399 || h
->root
.root
.type
== bfd_link_hash_defweak
)
5400 && h
->root
.root
.u
.def
.section
)
5401 || (link_info
->shared
&& ! link_info
->symbolic
5402 && ! (h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)))
5405 sym_sec
= h
->root
.root
.u
.def
.section
;
5406 if (sym_sec
->output_section
)
5407 symval
= (h
->root
.root
.u
.def
.value
5408 + sym_sec
->output_section
->vma
5409 + sym_sec
->output_offset
);
5411 symval
= h
->root
.root
.u
.def
.value
;
5415 Elf_Internal_Sym
*isym
;
5417 /* Read this BFD's symbols if we haven't done so already. */
5418 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
5420 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5421 if (isymbuf
== NULL
)
5422 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
5423 symtab_hdr
->sh_info
, 0,
5425 if (isymbuf
== NULL
)
5429 isym
= isymbuf
+ r_symndx
;
5430 if (isym
->st_shndx
== SHN_UNDEF
)
5432 else if (isym
->st_shndx
== SHN_ABS
)
5433 sym_sec
= bfd_abs_section_ptr
;
5434 else if (isym
->st_shndx
== SHN_COMMON
)
5435 sym_sec
= bfd_com_section_ptr
;
5438 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5439 symval
= isym
->st_value
5440 + sym_sec
->output_section
->vma
5441 + sym_sec
->output_offset
;
5444 /* Compute branch offset, from delay slot of the jump to the
5446 sym_offset
= (symval
+ irel
->r_addend
)
5447 - (sec_start
+ irel
->r_offset
+ 4);
5449 /* Branch offset must be properly aligned. */
5450 if ((sym_offset
& 3) != 0)
5455 /* Check that it's in range. */
5456 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
5459 /* Get the section contents if we haven't done so already. */
5460 if (contents
== NULL
)
5462 /* Get cached copy if it exists. */
5463 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
5464 contents
= elf_section_data (sec
)->this_hdr
.contents
;
5467 contents
= bfd_malloc (sec
->_raw_size
);
5468 if (contents
== NULL
)
5471 free_contents
= contents
;
5472 if (! bfd_get_section_contents (abfd
, sec
, contents
,
5478 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
5480 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
5481 if ((instruction
& 0xfc1fffff) == 0x0000f809)
5482 instruction
= 0x04110000;
5483 /* If it was jr <reg>, turn it into b <target>. */
5484 else if ((instruction
& 0xfc1fffff) == 0x00000008)
5485 instruction
= 0x10000000;
5489 instruction
|= (sym_offset
& 0xffff);
5490 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
5491 changed_contents
= TRUE
;
5494 if (contents
!= NULL
5495 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
5497 if (!changed_contents
&& !link_info
->keep_memory
)
5501 /* Cache the section contents for elf_link_input_bfd. */
5502 elf_section_data (sec
)->this_hdr
.contents
= contents
;
5508 if (free_contents
!= NULL
)
5509 free (free_contents
);
5513 /* Adjust a symbol defined by a dynamic object and referenced by a
5514 regular object. The current definition is in some section of the
5515 dynamic object, but we're not including those sections. We have to
5516 change the definition to something the rest of the link can
5520 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
5521 struct elf_link_hash_entry
*h
)
5524 struct mips_elf_link_hash_entry
*hmips
;
5527 dynobj
= elf_hash_table (info
)->dynobj
;
5529 /* Make sure we know what is going on here. */
5530 BFD_ASSERT (dynobj
!= NULL
5531 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
5532 || h
->weakdef
!= NULL
5533 || ((h
->elf_link_hash_flags
5534 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5535 && (h
->elf_link_hash_flags
5536 & ELF_LINK_HASH_REF_REGULAR
) != 0
5537 && (h
->elf_link_hash_flags
5538 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
5540 /* If this symbol is defined in a dynamic object, we need to copy
5541 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
5543 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5544 if (! info
->relocatable
5545 && hmips
->possibly_dynamic_relocs
!= 0
5546 && (h
->root
.type
== bfd_link_hash_defweak
5547 || (h
->elf_link_hash_flags
5548 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5550 mips_elf_allocate_dynamic_relocations (dynobj
,
5551 hmips
->possibly_dynamic_relocs
);
5552 if (hmips
->readonly_reloc
)
5553 /* We tell the dynamic linker that there are relocations
5554 against the text segment. */
5555 info
->flags
|= DF_TEXTREL
;
5558 /* For a function, create a stub, if allowed. */
5559 if (! hmips
->no_fn_stub
5560 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
5562 if (! elf_hash_table (info
)->dynamic_sections_created
)
5565 /* If this symbol is not defined in a regular file, then set
5566 the symbol to the stub location. This is required to make
5567 function pointers compare as equal between the normal
5568 executable and the shared library. */
5569 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5571 /* We need .stub section. */
5572 s
= bfd_get_section_by_name (dynobj
,
5573 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
5574 BFD_ASSERT (s
!= NULL
);
5576 h
->root
.u
.def
.section
= s
;
5577 h
->root
.u
.def
.value
= s
->_raw_size
;
5579 /* XXX Write this stub address somewhere. */
5580 h
->plt
.offset
= s
->_raw_size
;
5582 /* Make room for this stub code. */
5583 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5585 /* The last half word of the stub will be filled with the index
5586 of this symbol in .dynsym section. */
5590 else if ((h
->type
== STT_FUNC
)
5591 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
5593 /* This will set the entry for this symbol in the GOT to 0, and
5594 the dynamic linker will take care of this. */
5595 h
->root
.u
.def
.value
= 0;
5599 /* If this is a weak symbol, and there is a real definition, the
5600 processor independent code will have arranged for us to see the
5601 real definition first, and we can just use the same value. */
5602 if (h
->weakdef
!= NULL
)
5604 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
5605 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
5606 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
5607 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
5611 /* This is a reference to a symbol defined by a dynamic object which
5612 is not a function. */
5617 /* This function is called after all the input files have been read,
5618 and the input sections have been assigned to output sections. We
5619 check for any mips16 stub sections that we can discard. */
5622 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
5623 struct bfd_link_info
*info
)
5629 struct mips_got_info
*g
;
5631 bfd_size_type loadable_size
= 0;
5632 bfd_size_type local_gotno
;
5635 /* The .reginfo section has a fixed size. */
5636 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
5638 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
5640 if (! (info
->relocatable
5641 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
))
5642 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
5643 mips_elf_check_mips16_stubs
, NULL
);
5645 dynobj
= elf_hash_table (info
)->dynobj
;
5647 /* Relocatable links don't have it. */
5650 g
= mips_elf_got_info (dynobj
, &s
);
5654 /* Calculate the total loadable size of the output. That
5655 will give us the maximum number of GOT_PAGE entries
5657 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
5659 asection
*subsection
;
5661 for (subsection
= sub
->sections
;
5663 subsection
= subsection
->next
)
5665 if ((subsection
->flags
& SEC_ALLOC
) == 0)
5667 loadable_size
+= ((subsection
->_raw_size
+ 0xf)
5668 &~ (bfd_size_type
) 0xf);
5672 /* There has to be a global GOT entry for every symbol with
5673 a dynamic symbol table index of DT_MIPS_GOTSYM or
5674 higher. Therefore, it make sense to put those symbols
5675 that need GOT entries at the end of the symbol table. We
5677 if (! mips_elf_sort_hash_table (info
, 1))
5680 if (g
->global_gotsym
!= NULL
)
5681 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
5683 /* If there are no global symbols, or none requiring
5684 relocations, then GLOBAL_GOTSYM will be NULL. */
5687 /* In the worst case, we'll get one stub per dynamic symbol, plus
5688 one to account for the dummy entry at the end required by IRIX
5690 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
* (i
+ 1);
5692 /* Assume there are two loadable segments consisting of
5693 contiguous sections. Is 5 enough? */
5694 local_gotno
= (loadable_size
>> 16) + 5;
5696 g
->local_gotno
+= local_gotno
;
5697 s
->_raw_size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
5699 g
->global_gotno
= i
;
5700 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (output_bfd
);
5702 if (s
->_raw_size
> MIPS_ELF_GOT_MAX_SIZE (output_bfd
)
5703 && ! mips_elf_multi_got (output_bfd
, info
, g
, s
, local_gotno
))
5709 /* Set the sizes of the dynamic sections. */
5712 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
5713 struct bfd_link_info
*info
)
5717 bfd_boolean reltext
;
5719 dynobj
= elf_hash_table (info
)->dynobj
;
5720 BFD_ASSERT (dynobj
!= NULL
);
5722 if (elf_hash_table (info
)->dynamic_sections_created
)
5724 /* Set the contents of the .interp section to the interpreter. */
5725 if (info
->executable
)
5727 s
= bfd_get_section_by_name (dynobj
, ".interp");
5728 BFD_ASSERT (s
!= NULL
);
5730 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
5732 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
5736 /* The check_relocs and adjust_dynamic_symbol entry points have
5737 determined the sizes of the various dynamic sections. Allocate
5740 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5745 /* It's OK to base decisions on the section name, because none
5746 of the dynobj section names depend upon the input files. */
5747 name
= bfd_get_section_name (dynobj
, s
);
5749 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5754 if (strncmp (name
, ".rel", 4) == 0)
5756 if (s
->_raw_size
== 0)
5758 /* We only strip the section if the output section name
5759 has the same name. Otherwise, there might be several
5760 input sections for this output section. FIXME: This
5761 code is probably not needed these days anyhow, since
5762 the linker now does not create empty output sections. */
5763 if (s
->output_section
!= NULL
5765 bfd_get_section_name (s
->output_section
->owner
,
5766 s
->output_section
)) == 0)
5771 const char *outname
;
5774 /* If this relocation section applies to a read only
5775 section, then we probably need a DT_TEXTREL entry.
5776 If the relocation section is .rel.dyn, we always
5777 assert a DT_TEXTREL entry rather than testing whether
5778 there exists a relocation to a read only section or
5780 outname
= bfd_get_section_name (output_bfd
,
5782 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
5784 && (target
->flags
& SEC_READONLY
) != 0
5785 && (target
->flags
& SEC_ALLOC
) != 0)
5786 || strcmp (outname
, ".rel.dyn") == 0)
5789 /* We use the reloc_count field as a counter if we need
5790 to copy relocs into the output file. */
5791 if (strcmp (name
, ".rel.dyn") != 0)
5794 /* If combreloc is enabled, elf_link_sort_relocs() will
5795 sort relocations, but in a different way than we do,
5796 and before we're done creating relocations. Also, it
5797 will move them around between input sections'
5798 relocation's contents, so our sorting would be
5799 broken, so don't let it run. */
5800 info
->combreloc
= 0;
5803 else if (strncmp (name
, ".got", 4) == 0)
5805 /* _bfd_mips_elf_always_size_sections() has already done
5806 most of the work, but some symbols may have been mapped
5807 to versions that we must now resolve in the got_entries
5809 struct mips_got_info
*gg
= mips_elf_got_info (dynobj
, NULL
);
5810 struct mips_got_info
*g
= gg
;
5811 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
5812 unsigned int needed_relocs
= 0;
5816 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (output_bfd
);
5817 set_got_offset_arg
.info
= info
;
5819 mips_elf_resolve_final_got_entries (gg
);
5820 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
5822 unsigned int save_assign
;
5824 mips_elf_resolve_final_got_entries (g
);
5826 /* Assign offsets to global GOT entries. */
5827 save_assign
= g
->assigned_gotno
;
5828 g
->assigned_gotno
= g
->local_gotno
;
5829 set_got_offset_arg
.g
= g
;
5830 set_got_offset_arg
.needed_relocs
= 0;
5831 htab_traverse (g
->got_entries
,
5832 mips_elf_set_global_got_offset
,
5833 &set_got_offset_arg
);
5834 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
5835 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
5836 <= g
->global_gotno
);
5838 g
->assigned_gotno
= save_assign
;
5841 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
5842 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
5843 + g
->next
->global_gotno
5844 + MIPS_RESERVED_GOTNO
);
5849 mips_elf_allocate_dynamic_relocations (dynobj
, needed_relocs
);
5852 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
5854 /* IRIX rld assumes that the function stub isn't at the end
5855 of .text section. So put a dummy. XXX */
5856 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5858 else if (! info
->shared
5859 && ! mips_elf_hash_table (info
)->use_rld_obj_head
5860 && strncmp (name
, ".rld_map", 8) == 0)
5862 /* We add a room for __rld_map. It will be filled in by the
5863 rtld to contain a pointer to the _r_debug structure. */
5866 else if (SGI_COMPAT (output_bfd
)
5867 && strncmp (name
, ".compact_rel", 12) == 0)
5868 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
5869 else if (strncmp (name
, ".init", 5) != 0)
5871 /* It's not one of our sections, so don't allocate space. */
5877 _bfd_strip_section_from_output (info
, s
);
5881 /* Allocate memory for the section contents. */
5882 s
->contents
= bfd_zalloc (dynobj
, s
->_raw_size
);
5883 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
5885 bfd_set_error (bfd_error_no_memory
);
5890 if (elf_hash_table (info
)->dynamic_sections_created
)
5892 /* Add some entries to the .dynamic section. We fill in the
5893 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
5894 must add the entries now so that we get the correct size for
5895 the .dynamic section. The DT_DEBUG entry is filled in by the
5896 dynamic linker and used by the debugger. */
5899 /* SGI object has the equivalence of DT_DEBUG in the
5900 DT_MIPS_RLD_MAP entry. */
5901 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
5903 if (!SGI_COMPAT (output_bfd
))
5905 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
5911 /* Shared libraries on traditional mips have DT_DEBUG. */
5912 if (!SGI_COMPAT (output_bfd
))
5914 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
5919 if (reltext
&& SGI_COMPAT (output_bfd
))
5920 info
->flags
|= DF_TEXTREL
;
5922 if ((info
->flags
& DF_TEXTREL
) != 0)
5924 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
5928 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
5931 if (mips_elf_rel_dyn_section (dynobj
, FALSE
))
5933 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
5936 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
5939 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
5943 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
5946 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
5950 /* Time stamps in executable files are a bad idea. */
5951 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
5956 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
5961 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
5965 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
5968 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
5971 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
5974 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
5977 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
5980 if (IRIX_COMPAT (dynobj
) == ict_irix5
5981 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
5984 if (IRIX_COMPAT (dynobj
) == ict_irix6
5985 && (bfd_get_section_by_name
5986 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
5987 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
5994 /* Relocate a MIPS ELF section. */
5997 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
5998 bfd
*input_bfd
, asection
*input_section
,
5999 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
6000 Elf_Internal_Sym
*local_syms
,
6001 asection
**local_sections
)
6003 Elf_Internal_Rela
*rel
;
6004 const Elf_Internal_Rela
*relend
;
6006 bfd_boolean use_saved_addend_p
= FALSE
;
6007 const struct elf_backend_data
*bed
;
6009 bed
= get_elf_backend_data (output_bfd
);
6010 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6011 for (rel
= relocs
; rel
< relend
; ++rel
)
6015 reloc_howto_type
*howto
;
6016 bfd_boolean require_jalx
;
6017 /* TRUE if the relocation is a RELA relocation, rather than a
6019 bfd_boolean rela_relocation_p
= TRUE
;
6020 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
6023 /* Find the relocation howto for this relocation. */
6024 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
6026 /* Some 32-bit code uses R_MIPS_64. In particular, people use
6027 64-bit code, but make sure all their addresses are in the
6028 lowermost or uppermost 32-bit section of the 64-bit address
6029 space. Thus, when they use an R_MIPS_64 they mean what is
6030 usually meant by R_MIPS_32, with the exception that the
6031 stored value is sign-extended to 64 bits. */
6032 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
6034 /* On big-endian systems, we need to lie about the position
6036 if (bfd_big_endian (input_bfd
))
6040 /* NewABI defaults to RELA relocations. */
6041 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
6042 NEWABI_P (input_bfd
)
6043 && (MIPS_RELOC_RELA_P
6044 (input_bfd
, input_section
,
6047 if (!use_saved_addend_p
)
6049 Elf_Internal_Shdr
*rel_hdr
;
6051 /* If these relocations were originally of the REL variety,
6052 we must pull the addend out of the field that will be
6053 relocated. Otherwise, we simply use the contents of the
6054 RELA relocation. To determine which flavor or relocation
6055 this is, we depend on the fact that the INPUT_SECTION's
6056 REL_HDR is read before its REL_HDR2. */
6057 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
6058 if ((size_t) (rel
- relocs
)
6059 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
6060 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
6061 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
6063 /* Note that this is a REL relocation. */
6064 rela_relocation_p
= FALSE
;
6066 /* Get the addend, which is stored in the input file. */
6067 addend
= mips_elf_obtain_contents (howto
, rel
, input_bfd
,
6069 addend
&= howto
->src_mask
;
6070 addend
<<= howto
->rightshift
;
6072 /* For some kinds of relocations, the ADDEND is a
6073 combination of the addend stored in two different
6075 if (r_type
== R_MIPS_HI16
6076 || r_type
== R_MIPS_GNU_REL_HI16
6077 || (r_type
== R_MIPS_GOT16
6078 && mips_elf_local_relocation_p (input_bfd
, rel
,
6079 local_sections
, FALSE
)))
6082 const Elf_Internal_Rela
*lo16_relocation
;
6083 reloc_howto_type
*lo16_howto
;
6086 /* The combined value is the sum of the HI16 addend,
6087 left-shifted by sixteen bits, and the LO16
6088 addend, sign extended. (Usually, the code does
6089 a `lui' of the HI16 value, and then an `addiu' of
6092 Scan ahead to find a matching LO16 relocation. */
6093 if (r_type
== R_MIPS_GNU_REL_HI16
)
6094 lo
= R_MIPS_GNU_REL_LO16
;
6097 lo16_relocation
= mips_elf_next_relocation (input_bfd
, lo
,
6099 if (lo16_relocation
== NULL
)
6102 /* Obtain the addend kept there. */
6103 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, lo
, FALSE
);
6104 l
= mips_elf_obtain_contents (lo16_howto
, lo16_relocation
,
6105 input_bfd
, contents
);
6106 l
&= lo16_howto
->src_mask
;
6107 l
<<= lo16_howto
->rightshift
;
6108 l
= _bfd_mips_elf_sign_extend (l
, 16);
6112 /* Compute the combined addend. */
6115 /* If PC-relative, subtract the difference between the
6116 address of the LO part of the reloc and the address of
6117 the HI part. The relocation is relative to the LO
6118 part, but mips_elf_calculate_relocation() doesn't
6119 know its address or the difference from the HI part, so
6120 we subtract that difference here. See also the
6121 comment in mips_elf_calculate_relocation(). */
6122 if (r_type
== R_MIPS_GNU_REL_HI16
)
6123 addend
-= (lo16_relocation
->r_offset
- rel
->r_offset
);
6125 else if (r_type
== R_MIPS16_GPREL
)
6127 /* The addend is scrambled in the object file. See
6128 mips_elf_perform_relocation for details on the
6130 addend
= (((addend
& 0x1f0000) >> 5)
6131 | ((addend
& 0x7e00000) >> 16)
6136 addend
= rel
->r_addend
;
6139 if (info
->relocatable
)
6141 Elf_Internal_Sym
*sym
;
6142 unsigned long r_symndx
;
6144 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
6145 && bfd_big_endian (input_bfd
))
6148 /* Since we're just relocating, all we need to do is copy
6149 the relocations back out to the object file, unless
6150 they're against a section symbol, in which case we need
6151 to adjust by the section offset, or unless they're GP
6152 relative in which case we need to adjust by the amount
6153 that we're adjusting GP in this relocatable object. */
6155 if (! mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
6157 /* There's nothing to do for non-local relocations. */
6160 if (r_type
== R_MIPS16_GPREL
6161 || r_type
== R_MIPS_GPREL16
6162 || r_type
== R_MIPS_GPREL32
6163 || r_type
== R_MIPS_LITERAL
)
6164 addend
-= (_bfd_get_gp_value (output_bfd
)
6165 - _bfd_get_gp_value (input_bfd
));
6167 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
6168 sym
= local_syms
+ r_symndx
;
6169 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
6170 /* Adjust the addend appropriately. */
6171 addend
+= local_sections
[r_symndx
]->output_offset
;
6173 if (howto
->partial_inplace
)
6175 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
6176 then we only want to write out the high-order 16 bits.
6177 The subsequent R_MIPS_LO16 will handle the low-order bits.
6179 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
6180 || r_type
== R_MIPS_GNU_REL_HI16
)
6181 addend
= mips_elf_high (addend
);
6182 else if (r_type
== R_MIPS_HIGHER
)
6183 addend
= mips_elf_higher (addend
);
6184 else if (r_type
== R_MIPS_HIGHEST
)
6185 addend
= mips_elf_highest (addend
);
6188 if (rela_relocation_p
)
6189 /* If this is a RELA relocation, just update the addend.
6190 We have to cast away constness for REL. */
6191 rel
->r_addend
= addend
;
6194 /* Otherwise, we have to write the value back out. Note
6195 that we use the source mask, rather than the
6196 destination mask because the place to which we are
6197 writing will be source of the addend in the final
6199 addend
>>= howto
->rightshift
;
6200 addend
&= howto
->src_mask
;
6202 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
6203 /* See the comment above about using R_MIPS_64 in the 32-bit
6204 ABI. Here, we need to update the addend. It would be
6205 possible to get away with just using the R_MIPS_32 reloc
6206 but for endianness. */
6212 if (addend
& ((bfd_vma
) 1 << 31))
6214 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
6221 /* If we don't know that we have a 64-bit type,
6222 do two separate stores. */
6223 if (bfd_big_endian (input_bfd
))
6225 /* Store the sign-bits (which are most significant)
6227 low_bits
= sign_bits
;
6233 high_bits
= sign_bits
;
6235 bfd_put_32 (input_bfd
, low_bits
,
6236 contents
+ rel
->r_offset
);
6237 bfd_put_32 (input_bfd
, high_bits
,
6238 contents
+ rel
->r_offset
+ 4);
6242 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
6243 input_bfd
, input_section
,
6248 /* Go on to the next relocation. */
6252 /* In the N32 and 64-bit ABIs there may be multiple consecutive
6253 relocations for the same offset. In that case we are
6254 supposed to treat the output of each relocation as the addend
6256 if (rel
+ 1 < relend
6257 && rel
->r_offset
== rel
[1].r_offset
6258 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
6259 use_saved_addend_p
= TRUE
;
6261 use_saved_addend_p
= FALSE
;
6263 addend
>>= howto
->rightshift
;
6265 /* Figure out what value we are supposed to relocate. */
6266 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
6267 input_section
, info
, rel
,
6268 addend
, howto
, local_syms
,
6269 local_sections
, &value
,
6270 &name
, &require_jalx
,
6271 use_saved_addend_p
))
6273 case bfd_reloc_continue
:
6274 /* There's nothing to do. */
6277 case bfd_reloc_undefined
:
6278 /* mips_elf_calculate_relocation already called the
6279 undefined_symbol callback. There's no real point in
6280 trying to perform the relocation at this point, so we
6281 just skip ahead to the next relocation. */
6284 case bfd_reloc_notsupported
:
6285 msg
= _("internal error: unsupported relocation error");
6286 info
->callbacks
->warning
6287 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
6290 case bfd_reloc_overflow
:
6291 if (use_saved_addend_p
)
6292 /* Ignore overflow until we reach the last relocation for
6293 a given location. */
6297 BFD_ASSERT (name
!= NULL
);
6298 if (! ((*info
->callbacks
->reloc_overflow
)
6299 (info
, name
, howto
->name
, 0,
6300 input_bfd
, input_section
, rel
->r_offset
)))
6313 /* If we've got another relocation for the address, keep going
6314 until we reach the last one. */
6315 if (use_saved_addend_p
)
6321 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
6322 /* See the comment above about using R_MIPS_64 in the 32-bit
6323 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
6324 that calculated the right value. Now, however, we
6325 sign-extend the 32-bit result to 64-bits, and store it as a
6326 64-bit value. We are especially generous here in that we
6327 go to extreme lengths to support this usage on systems with
6328 only a 32-bit VMA. */
6334 if (value
& ((bfd_vma
) 1 << 31))
6336 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
6343 /* If we don't know that we have a 64-bit type,
6344 do two separate stores. */
6345 if (bfd_big_endian (input_bfd
))
6347 /* Undo what we did above. */
6349 /* Store the sign-bits (which are most significant)
6351 low_bits
= sign_bits
;
6357 high_bits
= sign_bits
;
6359 bfd_put_32 (input_bfd
, low_bits
,
6360 contents
+ rel
->r_offset
);
6361 bfd_put_32 (input_bfd
, high_bits
,
6362 contents
+ rel
->r_offset
+ 4);
6366 /* Actually perform the relocation. */
6367 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
6368 input_bfd
, input_section
,
6369 contents
, require_jalx
))
6376 /* If NAME is one of the special IRIX6 symbols defined by the linker,
6377 adjust it appropriately now. */
6380 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
6381 const char *name
, Elf_Internal_Sym
*sym
)
6383 /* The linker script takes care of providing names and values for
6384 these, but we must place them into the right sections. */
6385 static const char* const text_section_symbols
[] = {
6388 "__dso_displacement",
6390 "__program_header_table",
6394 static const char* const data_section_symbols
[] = {
6402 const char* const *p
;
6405 for (i
= 0; i
< 2; ++i
)
6406 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
6409 if (strcmp (*p
, name
) == 0)
6411 /* All of these symbols are given type STT_SECTION by the
6413 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6414 sym
->st_other
= STO_PROTECTED
;
6416 /* The IRIX linker puts these symbols in special sections. */
6418 sym
->st_shndx
= SHN_MIPS_TEXT
;
6420 sym
->st_shndx
= SHN_MIPS_DATA
;
6426 /* Finish up dynamic symbol handling. We set the contents of various
6427 dynamic sections here. */
6430 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
6431 struct bfd_link_info
*info
,
6432 struct elf_link_hash_entry
*h
,
6433 Elf_Internal_Sym
*sym
)
6438 struct mips_got_info
*g
, *gg
;
6441 dynobj
= elf_hash_table (info
)->dynobj
;
6442 gval
= sym
->st_value
;
6444 if (h
->plt
.offset
!= (bfd_vma
) -1)
6447 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
6449 /* This symbol has a stub. Set it up. */
6451 BFD_ASSERT (h
->dynindx
!= -1);
6453 s
= bfd_get_section_by_name (dynobj
,
6454 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
6455 BFD_ASSERT (s
!= NULL
);
6457 /* FIXME: Can h->dynindex be more than 64K? */
6458 if (h
->dynindx
& 0xffff0000)
6461 /* Fill the stub. */
6462 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
);
6463 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ 4);
6464 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ 8);
6465 bfd_put_32 (output_bfd
, STUB_LI16 (output_bfd
) + h
->dynindx
, stub
+ 12);
6467 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
6468 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
6470 /* Mark the symbol as undefined. plt.offset != -1 occurs
6471 only for the referenced symbol. */
6472 sym
->st_shndx
= SHN_UNDEF
;
6474 /* The run-time linker uses the st_value field of the symbol
6475 to reset the global offset table entry for this external
6476 to its stub address when unlinking a shared object. */
6477 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
6478 sym
->st_value
= gval
;
6481 BFD_ASSERT (h
->dynindx
!= -1
6482 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
6484 sgot
= mips_elf_got_section (dynobj
, FALSE
);
6485 BFD_ASSERT (sgot
!= NULL
);
6486 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
6487 g
= mips_elf_section_data (sgot
)->u
.got_info
;
6488 BFD_ASSERT (g
!= NULL
);
6490 /* Run through the global symbol table, creating GOT entries for all
6491 the symbols that need them. */
6492 if (g
->global_gotsym
!= NULL
6493 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
6498 value
= sym
->st_value
;
6499 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
);
6500 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
6503 if (g
->next
&& h
->dynindx
!= -1)
6505 struct mips_got_entry e
, *p
;
6511 e
.abfd
= output_bfd
;
6513 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
6515 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
6518 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
6523 || (elf_hash_table (info
)->dynamic_sections_created
6525 && ((p
->d
.h
->root
.elf_link_hash_flags
6526 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
6527 && ((p
->d
.h
->root
.elf_link_hash_flags
6528 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
6530 /* Create an R_MIPS_REL32 relocation for this entry. Due to
6531 the various compatibility problems, it's easier to mock
6532 up an R_MIPS_32 or R_MIPS_64 relocation and leave
6533 mips_elf_create_dynamic_relocation to calculate the
6534 appropriate addend. */
6535 Elf_Internal_Rela rel
[3];
6537 memset (rel
, 0, sizeof (rel
));
6538 if (ABI_64_P (output_bfd
))
6539 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
6541 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
6542 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
6545 if (! (mips_elf_create_dynamic_relocation
6546 (output_bfd
, info
, rel
,
6547 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
6551 entry
= sym
->st_value
;
6552 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
6557 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6558 name
= h
->root
.root
.string
;
6559 if (strcmp (name
, "_DYNAMIC") == 0
6560 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
6561 sym
->st_shndx
= SHN_ABS
;
6562 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
6563 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
6565 sym
->st_shndx
= SHN_ABS
;
6566 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6569 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
6571 sym
->st_shndx
= SHN_ABS
;
6572 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6573 sym
->st_value
= elf_gp (output_bfd
);
6575 else if (SGI_COMPAT (output_bfd
))
6577 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
6578 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
6580 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6581 sym
->st_other
= STO_PROTECTED
;
6583 sym
->st_shndx
= SHN_MIPS_DATA
;
6585 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
6587 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
6588 sym
->st_other
= STO_PROTECTED
;
6589 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
6590 sym
->st_shndx
= SHN_ABS
;
6592 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
6594 if (h
->type
== STT_FUNC
)
6595 sym
->st_shndx
= SHN_MIPS_TEXT
;
6596 else if (h
->type
== STT_OBJECT
)
6597 sym
->st_shndx
= SHN_MIPS_DATA
;
6601 /* Handle the IRIX6-specific symbols. */
6602 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
6603 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
6607 if (! mips_elf_hash_table (info
)->use_rld_obj_head
6608 && (strcmp (name
, "__rld_map") == 0
6609 || strcmp (name
, "__RLD_MAP") == 0))
6611 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
6612 BFD_ASSERT (s
!= NULL
);
6613 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
6614 bfd_put_32 (output_bfd
, 0, s
->contents
);
6615 if (mips_elf_hash_table (info
)->rld_value
== 0)
6616 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6618 else if (mips_elf_hash_table (info
)->use_rld_obj_head
6619 && strcmp (name
, "__rld_obj_head") == 0)
6621 /* IRIX6 does not use a .rld_map section. */
6622 if (IRIX_COMPAT (output_bfd
) == ict_irix5
6623 || IRIX_COMPAT (output_bfd
) == ict_none
)
6624 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
6626 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
6630 /* If this is a mips16 symbol, force the value to be even. */
6631 if (sym
->st_other
== STO_MIPS16
6632 && (sym
->st_value
& 1) != 0)
6638 /* Finish up the dynamic sections. */
6641 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
6642 struct bfd_link_info
*info
)
6647 struct mips_got_info
*gg
, *g
;
6649 dynobj
= elf_hash_table (info
)->dynobj
;
6651 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6653 sgot
= mips_elf_got_section (dynobj
, FALSE
);
6658 BFD_ASSERT (mips_elf_section_data (sgot
) != NULL
);
6659 gg
= mips_elf_section_data (sgot
)->u
.got_info
;
6660 BFD_ASSERT (gg
!= NULL
);
6661 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
6662 BFD_ASSERT (g
!= NULL
);
6665 if (elf_hash_table (info
)->dynamic_sections_created
)
6669 BFD_ASSERT (sdyn
!= NULL
);
6670 BFD_ASSERT (g
!= NULL
);
6672 for (b
= sdyn
->contents
;
6673 b
< sdyn
->contents
+ sdyn
->_raw_size
;
6674 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
6676 Elf_Internal_Dyn dyn
;
6680 bfd_boolean swap_out_p
;
6682 /* Read in the current dynamic entry. */
6683 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
6685 /* Assume that we're going to modify it and write it out. */
6691 s
= mips_elf_rel_dyn_section (dynobj
, FALSE
);
6692 BFD_ASSERT (s
!= NULL
);
6693 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
6697 /* Rewrite DT_STRSZ. */
6699 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
6704 s
= bfd_get_section_by_name (output_bfd
, name
);
6705 BFD_ASSERT (s
!= NULL
);
6706 dyn
.d_un
.d_ptr
= s
->vma
;
6709 case DT_MIPS_RLD_VERSION
:
6710 dyn
.d_un
.d_val
= 1; /* XXX */
6714 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
6717 case DT_MIPS_TIME_STAMP
:
6718 time ((time_t *) &dyn
.d_un
.d_val
);
6721 case DT_MIPS_ICHECKSUM
:
6726 case DT_MIPS_IVERSION
:
6731 case DT_MIPS_BASE_ADDRESS
:
6732 s
= output_bfd
->sections
;
6733 BFD_ASSERT (s
!= NULL
);
6734 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
6737 case DT_MIPS_LOCAL_GOTNO
:
6738 dyn
.d_un
.d_val
= g
->local_gotno
;
6741 case DT_MIPS_UNREFEXTNO
:
6742 /* The index into the dynamic symbol table which is the
6743 entry of the first external symbol that is not
6744 referenced within the same object. */
6745 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
6748 case DT_MIPS_GOTSYM
:
6749 if (gg
->global_gotsym
)
6751 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
6754 /* In case if we don't have global got symbols we default
6755 to setting DT_MIPS_GOTSYM to the same value as
6756 DT_MIPS_SYMTABNO, so we just fall through. */
6758 case DT_MIPS_SYMTABNO
:
6760 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
6761 s
= bfd_get_section_by_name (output_bfd
, name
);
6762 BFD_ASSERT (s
!= NULL
);
6764 if (s
->_cooked_size
!= 0)
6765 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
6767 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
6770 case DT_MIPS_HIPAGENO
:
6771 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
6774 case DT_MIPS_RLD_MAP
:
6775 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
6778 case DT_MIPS_OPTIONS
:
6779 s
= (bfd_get_section_by_name
6780 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
6781 dyn
.d_un
.d_ptr
= s
->vma
;
6785 /* Reduce DT_RELSZ to account for any relocations we
6786 decided not to make. This is for the n64 irix rld,
6787 which doesn't seem to apply any relocations if there
6788 are trailing null entries. */
6789 s
= mips_elf_rel_dyn_section (dynobj
, FALSE
);
6790 dyn
.d_un
.d_val
= (s
->reloc_count
6791 * (ABI_64_P (output_bfd
)
6792 ? sizeof (Elf64_Mips_External_Rel
)
6793 : sizeof (Elf32_External_Rel
)));
6802 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
6807 /* The first entry of the global offset table will be filled at
6808 runtime. The second entry will be used by some runtime loaders.
6809 This isn't the case of IRIX rld. */
6810 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
6812 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
);
6813 MIPS_ELF_PUT_WORD (output_bfd
, 0x80000000,
6814 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
6818 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
6819 = MIPS_ELF_GOT_SIZE (output_bfd
);
6821 /* Generate dynamic relocations for the non-primary gots. */
6822 if (gg
!= NULL
&& gg
->next
)
6824 Elf_Internal_Rela rel
[3];
6827 memset (rel
, 0, sizeof (rel
));
6828 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
6830 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
6832 bfd_vma index
= g
->next
->local_gotno
+ g
->next
->global_gotno
;
6834 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
6835 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
6836 MIPS_ELF_PUT_WORD (output_bfd
, 0x80000000, sgot
->contents
6837 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
6842 while (index
< g
->assigned_gotno
)
6844 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
6845 = index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
6846 if (!(mips_elf_create_dynamic_relocation
6847 (output_bfd
, info
, rel
, NULL
,
6848 bfd_abs_section_ptr
,
6851 BFD_ASSERT (addend
== 0);
6858 Elf32_compact_rel cpt
;
6860 if (SGI_COMPAT (output_bfd
))
6862 /* Write .compact_rel section out. */
6863 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
6867 cpt
.num
= s
->reloc_count
;
6869 cpt
.offset
= (s
->output_section
->filepos
6870 + sizeof (Elf32_External_compact_rel
));
6873 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
6874 ((Elf32_External_compact_rel
*)
6877 /* Clean up a dummy stub function entry in .text. */
6878 s
= bfd_get_section_by_name (dynobj
,
6879 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
6882 file_ptr dummy_offset
;
6884 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
6885 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
6886 memset (s
->contents
+ dummy_offset
, 0,
6887 MIPS_FUNCTION_STUB_SIZE
);
6892 /* We need to sort the entries of the dynamic relocation section. */
6894 s
= mips_elf_rel_dyn_section (dynobj
, FALSE
);
6897 && s
->_raw_size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
6899 reldyn_sorting_bfd
= output_bfd
;
6901 if (ABI_64_P (output_bfd
))
6902 qsort ((Elf64_External_Rel
*) s
->contents
+ 1, s
->reloc_count
- 1,
6903 sizeof (Elf64_Mips_External_Rel
), sort_dynamic_relocs_64
);
6905 qsort ((Elf32_External_Rel
*) s
->contents
+ 1, s
->reloc_count
- 1,
6906 sizeof (Elf32_External_Rel
), sort_dynamic_relocs
);
6914 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
6917 mips_set_isa_flags (bfd
*abfd
)
6921 switch (bfd_get_mach (abfd
))
6924 case bfd_mach_mips3000
:
6925 val
= E_MIPS_ARCH_1
;
6928 case bfd_mach_mips3900
:
6929 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
6932 case bfd_mach_mips6000
:
6933 val
= E_MIPS_ARCH_2
;
6936 case bfd_mach_mips4000
:
6937 case bfd_mach_mips4300
:
6938 case bfd_mach_mips4400
:
6939 case bfd_mach_mips4600
:
6940 val
= E_MIPS_ARCH_3
;
6943 case bfd_mach_mips4010
:
6944 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
6947 case bfd_mach_mips4100
:
6948 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
6951 case bfd_mach_mips4111
:
6952 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
6955 case bfd_mach_mips4120
:
6956 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
6959 case bfd_mach_mips4650
:
6960 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
6963 case bfd_mach_mips5400
:
6964 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
6967 case bfd_mach_mips5500
:
6968 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
6971 case bfd_mach_mips5000
:
6972 case bfd_mach_mips7000
:
6973 case bfd_mach_mips8000
:
6974 case bfd_mach_mips10000
:
6975 case bfd_mach_mips12000
:
6976 val
= E_MIPS_ARCH_4
;
6979 case bfd_mach_mips5
:
6980 val
= E_MIPS_ARCH_5
;
6983 case bfd_mach_mips_sb1
:
6984 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
6987 case bfd_mach_mipsisa32
:
6988 val
= E_MIPS_ARCH_32
;
6991 case bfd_mach_mipsisa64
:
6992 val
= E_MIPS_ARCH_64
;
6995 case bfd_mach_mipsisa32r2
:
6996 val
= E_MIPS_ARCH_32R2
;
6999 case bfd_mach_mipsisa64r2
:
7000 val
= E_MIPS_ARCH_64R2
;
7003 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
7004 elf_elfheader (abfd
)->e_flags
|= val
;
7009 /* The final processing done just before writing out a MIPS ELF object
7010 file. This gets the MIPS architecture right based on the machine
7011 number. This is used by both the 32-bit and the 64-bit ABI. */
7014 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
7015 bfd_boolean linker ATTRIBUTE_UNUSED
)
7018 Elf_Internal_Shdr
**hdrpp
;
7022 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
7023 is nonzero. This is for compatibility with old objects, which used
7024 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
7025 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
7026 mips_set_isa_flags (abfd
);
7028 /* Set the sh_info field for .gptab sections and other appropriate
7029 info for each special section. */
7030 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
7031 i
< elf_numsections (abfd
);
7034 switch ((*hdrpp
)->sh_type
)
7037 case SHT_MIPS_LIBLIST
:
7038 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
7040 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
7043 case SHT_MIPS_GPTAB
:
7044 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
7045 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
7046 BFD_ASSERT (name
!= NULL
7047 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
7048 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
7049 BFD_ASSERT (sec
!= NULL
);
7050 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
7053 case SHT_MIPS_CONTENT
:
7054 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
7055 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
7056 BFD_ASSERT (name
!= NULL
7057 && strncmp (name
, ".MIPS.content",
7058 sizeof ".MIPS.content" - 1) == 0);
7059 sec
= bfd_get_section_by_name (abfd
,
7060 name
+ sizeof ".MIPS.content" - 1);
7061 BFD_ASSERT (sec
!= NULL
);
7062 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
7065 case SHT_MIPS_SYMBOL_LIB
:
7066 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
7068 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
7069 sec
= bfd_get_section_by_name (abfd
, ".liblist");
7071 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
7074 case SHT_MIPS_EVENTS
:
7075 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
7076 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
7077 BFD_ASSERT (name
!= NULL
);
7078 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
7079 sec
= bfd_get_section_by_name (abfd
,
7080 name
+ sizeof ".MIPS.events" - 1);
7083 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
7084 sizeof ".MIPS.post_rel" - 1) == 0);
7085 sec
= bfd_get_section_by_name (abfd
,
7087 + sizeof ".MIPS.post_rel" - 1));
7089 BFD_ASSERT (sec
!= NULL
);
7090 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
7097 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
7101 _bfd_mips_elf_additional_program_headers (bfd
*abfd
)
7106 /* See if we need a PT_MIPS_REGINFO segment. */
7107 s
= bfd_get_section_by_name (abfd
, ".reginfo");
7108 if (s
&& (s
->flags
& SEC_LOAD
))
7111 /* See if we need a PT_MIPS_OPTIONS segment. */
7112 if (IRIX_COMPAT (abfd
) == ict_irix6
7113 && bfd_get_section_by_name (abfd
,
7114 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
7117 /* See if we need a PT_MIPS_RTPROC segment. */
7118 if (IRIX_COMPAT (abfd
) == ict_irix5
7119 && bfd_get_section_by_name (abfd
, ".dynamic")
7120 && bfd_get_section_by_name (abfd
, ".mdebug"))
7126 /* Modify the segment map for an IRIX5 executable. */
7129 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
7130 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
7133 struct elf_segment_map
*m
, **pm
;
7136 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
7138 s
= bfd_get_section_by_name (abfd
, ".reginfo");
7139 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
7141 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
7142 if (m
->p_type
== PT_MIPS_REGINFO
)
7147 m
= bfd_zalloc (abfd
, amt
);
7151 m
->p_type
= PT_MIPS_REGINFO
;
7155 /* We want to put it after the PHDR and INTERP segments. */
7156 pm
= &elf_tdata (abfd
)->segment_map
;
7158 && ((*pm
)->p_type
== PT_PHDR
7159 || (*pm
)->p_type
== PT_INTERP
))
7167 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
7168 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
7169 PT_MIPS_OPTIONS segment immediately following the program header
7172 /* On non-IRIX6 new abi, we'll have already created a segment
7173 for this section, so don't create another. I'm not sure this
7174 is not also the case for IRIX 6, but I can't test it right
7176 && IRIX_COMPAT (abfd
) == ict_irix6
)
7178 for (s
= abfd
->sections
; s
; s
= s
->next
)
7179 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
7184 struct elf_segment_map
*options_segment
;
7186 pm
= &elf_tdata (abfd
)->segment_map
;
7188 && ((*pm
)->p_type
== PT_PHDR
7189 || (*pm
)->p_type
== PT_INTERP
))
7192 amt
= sizeof (struct elf_segment_map
);
7193 options_segment
= bfd_zalloc (abfd
, amt
);
7194 options_segment
->next
= *pm
;
7195 options_segment
->p_type
= PT_MIPS_OPTIONS
;
7196 options_segment
->p_flags
= PF_R
;
7197 options_segment
->p_flags_valid
= TRUE
;
7198 options_segment
->count
= 1;
7199 options_segment
->sections
[0] = s
;
7200 *pm
= options_segment
;
7205 if (IRIX_COMPAT (abfd
) == ict_irix5
)
7207 /* If there are .dynamic and .mdebug sections, we make a room
7208 for the RTPROC header. FIXME: Rewrite without section names. */
7209 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
7210 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
7211 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
7213 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
7214 if (m
->p_type
== PT_MIPS_RTPROC
)
7219 m
= bfd_zalloc (abfd
, amt
);
7223 m
->p_type
= PT_MIPS_RTPROC
;
7225 s
= bfd_get_section_by_name (abfd
, ".rtproc");
7230 m
->p_flags_valid
= 1;
7238 /* We want to put it after the DYNAMIC segment. */
7239 pm
= &elf_tdata (abfd
)->segment_map
;
7240 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
7250 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
7251 .dynstr, .dynsym, and .hash sections, and everything in
7253 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
7255 if ((*pm
)->p_type
== PT_DYNAMIC
)
7258 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
7260 /* For a normal mips executable the permissions for the PT_DYNAMIC
7261 segment are read, write and execute. We do that here since
7262 the code in elf.c sets only the read permission. This matters
7263 sometimes for the dynamic linker. */
7264 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
7266 m
->p_flags
= PF_R
| PF_W
| PF_X
;
7267 m
->p_flags_valid
= 1;
7271 && m
->count
== 1 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
7273 static const char *sec_names
[] =
7275 ".dynamic", ".dynstr", ".dynsym", ".hash"
7279 struct elf_segment_map
*n
;
7283 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
7285 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
7286 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
7292 sz
= s
->_cooked_size
;
7295 if (high
< s
->vma
+ sz
)
7301 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
7302 if ((s
->flags
& SEC_LOAD
) != 0
7305 + (s
->_cooked_size
!=
7306 0 ? s
->_cooked_size
: s
->_raw_size
)) <= high
))
7309 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
7310 n
= bfd_zalloc (abfd
, amt
);
7317 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
7319 if ((s
->flags
& SEC_LOAD
) != 0
7322 + (s
->_cooked_size
!= 0 ?
7323 s
->_cooked_size
: s
->_raw_size
)) <= high
))
7337 /* Return the section that should be marked against GC for a given
7341 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
7342 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7343 Elf_Internal_Rela
*rel
,
7344 struct elf_link_hash_entry
*h
,
7345 Elf_Internal_Sym
*sym
)
7347 /* ??? Do mips16 stub sections need to be handled special? */
7351 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
7353 case R_MIPS_GNU_VTINHERIT
:
7354 case R_MIPS_GNU_VTENTRY
:
7358 switch (h
->root
.type
)
7360 case bfd_link_hash_defined
:
7361 case bfd_link_hash_defweak
:
7362 return h
->root
.u
.def
.section
;
7364 case bfd_link_hash_common
:
7365 return h
->root
.u
.c
.p
->section
;
7373 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7378 /* Update the got entry reference counts for the section being removed. */
7381 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
7382 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7383 asection
*sec ATTRIBUTE_UNUSED
,
7384 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
7387 Elf_Internal_Shdr
*symtab_hdr
;
7388 struct elf_link_hash_entry
**sym_hashes
;
7389 bfd_signed_vma
*local_got_refcounts
;
7390 const Elf_Internal_Rela
*rel
, *relend
;
7391 unsigned long r_symndx
;
7392 struct elf_link_hash_entry
*h
;
7394 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7395 sym_hashes
= elf_sym_hashes (abfd
);
7396 local_got_refcounts
= elf_local_got_refcounts (abfd
);
7398 relend
= relocs
+ sec
->reloc_count
;
7399 for (rel
= relocs
; rel
< relend
; rel
++)
7400 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
7404 case R_MIPS_CALL_HI16
:
7405 case R_MIPS_CALL_LO16
:
7406 case R_MIPS_GOT_HI16
:
7407 case R_MIPS_GOT_LO16
:
7408 case R_MIPS_GOT_DISP
:
7409 case R_MIPS_GOT_PAGE
:
7410 case R_MIPS_GOT_OFST
:
7411 /* ??? It would seem that the existing MIPS code does no sort
7412 of reference counting or whatnot on its GOT and PLT entries,
7413 so it is not possible to garbage collect them at this time. */
7424 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
7425 hiding the old indirect symbol. Process additional relocation
7426 information. Also called for weakdefs, in which case we just let
7427 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
7430 _bfd_mips_elf_copy_indirect_symbol (const struct elf_backend_data
*bed
,
7431 struct elf_link_hash_entry
*dir
,
7432 struct elf_link_hash_entry
*ind
)
7434 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
7436 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
7438 if (ind
->root
.type
!= bfd_link_hash_indirect
)
7441 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
7442 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
7443 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
7444 if (indmips
->readonly_reloc
)
7445 dirmips
->readonly_reloc
= TRUE
;
7446 if (indmips
->no_fn_stub
)
7447 dirmips
->no_fn_stub
= TRUE
;
7451 _bfd_mips_elf_hide_symbol (struct bfd_link_info
*info
,
7452 struct elf_link_hash_entry
*entry
,
7453 bfd_boolean force_local
)
7457 struct mips_got_info
*g
;
7458 struct mips_elf_link_hash_entry
*h
;
7460 h
= (struct mips_elf_link_hash_entry
*) entry
;
7461 if (h
->forced_local
)
7463 h
->forced_local
= force_local
;
7465 dynobj
= elf_hash_table (info
)->dynobj
;
7466 if (dynobj
!= NULL
&& force_local
)
7468 got
= mips_elf_got_section (dynobj
, FALSE
);
7469 g
= mips_elf_section_data (got
)->u
.got_info
;
7473 struct mips_got_entry e
;
7474 struct mips_got_info
*gg
= g
;
7476 /* Since we're turning what used to be a global symbol into a
7477 local one, bump up the number of local entries of each GOT
7478 that had an entry for it. This will automatically decrease
7479 the number of global entries, since global_gotno is actually
7480 the upper limit of global entries. */
7485 for (g
= g
->next
; g
!= gg
; g
= g
->next
)
7486 if (htab_find (g
->got_entries
, &e
))
7488 BFD_ASSERT (g
->global_gotno
> 0);
7493 /* If this was a global symbol forced into the primary GOT, we
7494 no longer need an entry for it. We can't release the entry
7495 at this point, but we must at least stop counting it as one
7496 of the symbols that required a forced got entry. */
7497 if (h
->root
.got
.offset
== 2)
7499 BFD_ASSERT (gg
->assigned_gotno
> 0);
7500 gg
->assigned_gotno
--;
7503 else if (g
->global_gotno
== 0 && g
->global_gotsym
== NULL
)
7504 /* If we haven't got through GOT allocation yet, just bump up the
7505 number of local entries, as this symbol won't be counted as
7508 else if (h
->root
.got
.offset
== 1)
7510 /* If we're past non-multi-GOT allocation and this symbol had
7511 been marked for a global got entry, give it a local entry
7513 BFD_ASSERT (g
->global_gotno
> 0);
7519 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
7525 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
7526 struct bfd_link_info
*info
)
7529 bfd_boolean ret
= FALSE
;
7530 unsigned char *tdata
;
7533 o
= bfd_get_section_by_name (abfd
, ".pdr");
7536 if (o
->_raw_size
== 0)
7538 if (o
->_raw_size
% PDR_SIZE
!= 0)
7540 if (o
->output_section
!= NULL
7541 && bfd_is_abs_section (o
->output_section
))
7544 tdata
= bfd_zmalloc (o
->_raw_size
/ PDR_SIZE
);
7548 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7556 cookie
->rel
= cookie
->rels
;
7557 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
7559 for (i
= 0, skip
= 0; i
< o
->_raw_size
/ PDR_SIZE
; i
++)
7561 if (MNAME(abfd
,_bfd_elf
,reloc_symbol_deleted_p
) (i
* PDR_SIZE
, cookie
))
7570 mips_elf_section_data (o
)->u
.tdata
= tdata
;
7571 o
->_cooked_size
= o
->_raw_size
- skip
* PDR_SIZE
;
7577 if (! info
->keep_memory
)
7578 free (cookie
->rels
);
7584 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
7586 if (strcmp (sec
->name
, ".pdr") == 0)
7592 _bfd_mips_elf_write_section (bfd
*output_bfd
, asection
*sec
,
7595 bfd_byte
*to
, *from
, *end
;
7598 if (strcmp (sec
->name
, ".pdr") != 0)
7601 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
7605 end
= contents
+ sec
->_raw_size
;
7606 for (from
= contents
, i
= 0;
7608 from
+= PDR_SIZE
, i
++)
7610 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
7613 memcpy (to
, from
, PDR_SIZE
);
7616 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
7617 sec
->output_offset
, sec
->_cooked_size
);
7621 /* MIPS ELF uses a special find_nearest_line routine in order the
7622 handle the ECOFF debugging information. */
7624 struct mips_elf_find_line
7626 struct ecoff_debug_info d
;
7627 struct ecoff_find_line i
;
7631 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
7632 asymbol
**symbols
, bfd_vma offset
,
7633 const char **filename_ptr
,
7634 const char **functionname_ptr
,
7635 unsigned int *line_ptr
)
7639 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
7640 filename_ptr
, functionname_ptr
,
7644 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
7645 filename_ptr
, functionname_ptr
,
7646 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
7647 &elf_tdata (abfd
)->dwarf2_find_line_info
))
7650 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
7654 struct mips_elf_find_line
*fi
;
7655 const struct ecoff_debug_swap
* const swap
=
7656 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
7658 /* If we are called during a link, mips_elf_final_link may have
7659 cleared the SEC_HAS_CONTENTS field. We force it back on here
7660 if appropriate (which it normally will be). */
7661 origflags
= msec
->flags
;
7662 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
7663 msec
->flags
|= SEC_HAS_CONTENTS
;
7665 fi
= elf_tdata (abfd
)->find_line_info
;
7668 bfd_size_type external_fdr_size
;
7671 struct fdr
*fdr_ptr
;
7672 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
7674 fi
= bfd_zalloc (abfd
, amt
);
7677 msec
->flags
= origflags
;
7681 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
7683 msec
->flags
= origflags
;
7687 /* Swap in the FDR information. */
7688 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
7689 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
7690 if (fi
->d
.fdr
== NULL
)
7692 msec
->flags
= origflags
;
7695 external_fdr_size
= swap
->external_fdr_size
;
7696 fdr_ptr
= fi
->d
.fdr
;
7697 fraw_src
= (char *) fi
->d
.external_fdr
;
7698 fraw_end
= (fraw_src
7699 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
7700 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
7701 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
7703 elf_tdata (abfd
)->find_line_info
= fi
;
7705 /* Note that we don't bother to ever free this information.
7706 find_nearest_line is either called all the time, as in
7707 objdump -l, so the information should be saved, or it is
7708 rarely called, as in ld error messages, so the memory
7709 wasted is unimportant. Still, it would probably be a
7710 good idea for free_cached_info to throw it away. */
7713 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
7714 &fi
->i
, filename_ptr
, functionname_ptr
,
7717 msec
->flags
= origflags
;
7721 msec
->flags
= origflags
;
7724 /* Fall back on the generic ELF find_nearest_line routine. */
7726 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
7727 filename_ptr
, functionname_ptr
,
7731 /* When are writing out the .options or .MIPS.options section,
7732 remember the bytes we are writing out, so that we can install the
7733 GP value in the section_processing routine. */
7736 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
7737 const void *location
,
7738 file_ptr offset
, bfd_size_type count
)
7740 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
7744 if (elf_section_data (section
) == NULL
)
7746 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
7747 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
7748 if (elf_section_data (section
) == NULL
)
7751 c
= mips_elf_section_data (section
)->u
.tdata
;
7756 if (section
->_cooked_size
!= 0)
7757 size
= section
->_cooked_size
;
7759 size
= section
->_raw_size
;
7760 c
= bfd_zalloc (abfd
, size
);
7763 mips_elf_section_data (section
)->u
.tdata
= c
;
7766 memcpy (c
+ offset
, location
, count
);
7769 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
7773 /* This is almost identical to bfd_generic_get_... except that some
7774 MIPS relocations need to be handled specially. Sigh. */
7777 _bfd_elf_mips_get_relocated_section_contents
7779 struct bfd_link_info
*link_info
,
7780 struct bfd_link_order
*link_order
,
7782 bfd_boolean relocatable
,
7785 /* Get enough memory to hold the stuff */
7786 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
7787 asection
*input_section
= link_order
->u
.indirect
.section
;
7789 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
7790 arelent
**reloc_vector
= NULL
;
7796 reloc_vector
= bfd_malloc (reloc_size
);
7797 if (reloc_vector
== NULL
&& reloc_size
!= 0)
7800 /* read in the section */
7801 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0,
7802 input_section
->_raw_size
))
7805 /* We're not relaxing the section, so just copy the size info */
7806 input_section
->_cooked_size
= input_section
->_raw_size
;
7807 input_section
->reloc_done
= TRUE
;
7809 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
7813 if (reloc_count
< 0)
7816 if (reloc_count
> 0)
7821 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
7824 struct bfd_hash_entry
*h
;
7825 struct bfd_link_hash_entry
*lh
;
7826 /* Skip all this stuff if we aren't mixing formats. */
7827 if (abfd
&& input_bfd
7828 && abfd
->xvec
== input_bfd
->xvec
)
7832 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
7833 lh
= (struct bfd_link_hash_entry
*) h
;
7840 case bfd_link_hash_undefined
:
7841 case bfd_link_hash_undefweak
:
7842 case bfd_link_hash_common
:
7845 case bfd_link_hash_defined
:
7846 case bfd_link_hash_defweak
:
7848 gp
= lh
->u
.def
.value
;
7850 case bfd_link_hash_indirect
:
7851 case bfd_link_hash_warning
:
7853 /* @@FIXME ignoring warning for now */
7855 case bfd_link_hash_new
:
7864 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
7866 char *error_message
= NULL
;
7867 bfd_reloc_status_type r
;
7869 /* Specific to MIPS: Deal with relocation types that require
7870 knowing the gp of the output bfd. */
7871 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
7872 if (bfd_is_abs_section (sym
->section
) && abfd
)
7874 /* The special_function wouldn't get called anyway. */
7878 /* The gp isn't there; let the special function code
7879 fall over on its own. */
7881 else if ((*parent
)->howto
->special_function
7882 == _bfd_mips_elf32_gprel16_reloc
)
7884 /* bypass special_function call */
7885 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
7886 input_section
, relocatable
,
7888 goto skip_bfd_perform_relocation
;
7890 /* end mips specific stuff */
7892 r
= bfd_perform_relocation (input_bfd
, *parent
, data
, input_section
,
7893 relocatable
? abfd
: NULL
,
7895 skip_bfd_perform_relocation
:
7899 asection
*os
= input_section
->output_section
;
7901 /* A partial link, so keep the relocs */
7902 os
->orelocation
[os
->reloc_count
] = *parent
;
7906 if (r
!= bfd_reloc_ok
)
7910 case bfd_reloc_undefined
:
7911 if (!((*link_info
->callbacks
->undefined_symbol
)
7912 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7913 input_bfd
, input_section
, (*parent
)->address
,
7917 case bfd_reloc_dangerous
:
7918 BFD_ASSERT (error_message
!= NULL
);
7919 if (!((*link_info
->callbacks
->reloc_dangerous
)
7920 (link_info
, error_message
, input_bfd
, input_section
,
7921 (*parent
)->address
)))
7924 case bfd_reloc_overflow
:
7925 if (!((*link_info
->callbacks
->reloc_overflow
)
7926 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
7927 (*parent
)->howto
->name
, (*parent
)->addend
,
7928 input_bfd
, input_section
, (*parent
)->address
)))
7931 case bfd_reloc_outofrange
:
7940 if (reloc_vector
!= NULL
)
7941 free (reloc_vector
);
7945 if (reloc_vector
!= NULL
)
7946 free (reloc_vector
);
7950 /* Create a MIPS ELF linker hash table. */
7952 struct bfd_link_hash_table
*
7953 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
7955 struct mips_elf_link_hash_table
*ret
;
7956 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
7958 ret
= bfd_malloc (amt
);
7962 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
7963 mips_elf_link_hash_newfunc
))
7970 /* We no longer use this. */
7971 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
7972 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
7974 ret
->procedure_count
= 0;
7975 ret
->compact_rel_size
= 0;
7976 ret
->use_rld_obj_head
= FALSE
;
7978 ret
->mips16_stubs_seen
= FALSE
;
7980 return &ret
->root
.root
;
7983 /* We need to use a special link routine to handle the .reginfo and
7984 the .mdebug sections. We need to merge all instances of these
7985 sections together, not write them all out sequentially. */
7988 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
7992 struct bfd_link_order
*p
;
7993 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
7994 asection
*rtproc_sec
;
7995 Elf32_RegInfo reginfo
;
7996 struct ecoff_debug_info debug
;
7997 const struct ecoff_debug_swap
*swap
7998 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
7999 HDRR
*symhdr
= &debug
.symbolic_header
;
8000 void *mdebug_handle
= NULL
;
8006 static const char * const secname
[] =
8008 ".text", ".init", ".fini", ".data",
8009 ".rodata", ".sdata", ".sbss", ".bss"
8011 static const int sc
[] =
8013 scText
, scInit
, scFini
, scData
,
8014 scRData
, scSData
, scSBss
, scBss
8017 /* We'd carefully arranged the dynamic symbol indices, and then the
8018 generic size_dynamic_sections renumbered them out from under us.
8019 Rather than trying somehow to prevent the renumbering, just do
8021 if (elf_hash_table (info
)->dynamic_sections_created
)
8025 struct mips_got_info
*g
;
8027 /* When we resort, we must tell mips_elf_sort_hash_table what
8028 the lowest index it may use is. That's the number of section
8029 symbols we're going to add. The generic ELF linker only
8030 adds these symbols when building a shared object. Note that
8031 we count the sections after (possibly) removing the .options
8033 if (! mips_elf_sort_hash_table (info
, (info
->shared
8034 ? bfd_count_sections (abfd
) + 1
8038 /* Make sure we didn't grow the global .got region. */
8039 dynobj
= elf_hash_table (info
)->dynobj
;
8040 got
= mips_elf_got_section (dynobj
, FALSE
);
8041 g
= mips_elf_section_data (got
)->u
.got_info
;
8043 if (g
->global_gotsym
!= NULL
)
8044 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
8045 - g
->global_gotsym
->dynindx
)
8046 <= g
->global_gotno
);
8050 /* We want to set the GP value for ld -r. */
8051 /* On IRIX5, we omit the .options section. On IRIX6, however, we
8052 include it, even though we don't process it quite right. (Some
8053 entries are supposed to be merged.) Empirically, we seem to be
8054 better off including it then not. */
8055 if (IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
8056 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
8058 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
8060 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
8061 if (p
->type
== bfd_indirect_link_order
)
8062 p
->u
.indirect
.section
->flags
&= ~SEC_HAS_CONTENTS
;
8063 (*secpp
)->link_order_head
= NULL
;
8064 bfd_section_list_remove (abfd
, secpp
);
8065 --abfd
->section_count
;
8071 /* We include .MIPS.options, even though we don't process it quite right.
8072 (Some entries are supposed to be merged.) At IRIX6 empirically we seem
8073 to be better off including it than not. */
8074 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
8076 if (strcmp ((*secpp
)->name
, ".MIPS.options") == 0)
8078 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
8079 if (p
->type
== bfd_indirect_link_order
)
8080 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
8081 (*secpp
)->link_order_head
= NULL
;
8082 bfd_section_list_remove (abfd
, secpp
);
8083 --abfd
->section_count
;
8090 /* Get a value for the GP register. */
8091 if (elf_gp (abfd
) == 0)
8093 struct bfd_link_hash_entry
*h
;
8095 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
8096 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
8097 elf_gp (abfd
) = (h
->u
.def
.value
8098 + h
->u
.def
.section
->output_section
->vma
8099 + h
->u
.def
.section
->output_offset
);
8100 else if (info
->relocatable
)
8102 bfd_vma lo
= MINUS_ONE
;
8104 /* Find the GP-relative section with the lowest offset. */
8105 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
8107 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
8110 /* And calculate GP relative to that. */
8111 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
8115 /* If the relocate_section function needs to do a reloc
8116 involving the GP value, it should make a reloc_dangerous
8117 callback to warn that GP is not defined. */
8121 /* Go through the sections and collect the .reginfo and .mdebug
8125 gptab_data_sec
= NULL
;
8126 gptab_bss_sec
= NULL
;
8127 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
8129 if (strcmp (o
->name
, ".reginfo") == 0)
8131 memset (®info
, 0, sizeof reginfo
);
8133 /* We have found the .reginfo section in the output file.
8134 Look through all the link_orders comprising it and merge
8135 the information together. */
8136 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
8138 asection
*input_section
;
8140 Elf32_External_RegInfo ext
;
8143 if (p
->type
!= bfd_indirect_link_order
)
8145 if (p
->type
== bfd_data_link_order
)
8150 input_section
= p
->u
.indirect
.section
;
8151 input_bfd
= input_section
->owner
;
8153 /* The linker emulation code has probably clobbered the
8154 size to be zero bytes. */
8155 if (input_section
->_raw_size
== 0)
8156 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
8158 if (! bfd_get_section_contents (input_bfd
, input_section
,
8159 &ext
, 0, sizeof ext
))
8162 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
8164 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
8165 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
8166 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
8167 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
8168 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
8170 /* ri_gp_value is set by the function
8171 mips_elf32_section_processing when the section is
8172 finally written out. */
8174 /* Hack: reset the SEC_HAS_CONTENTS flag so that
8175 elf_link_input_bfd ignores this section. */
8176 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
8179 /* Size has been set in _bfd_mips_elf_always_size_sections. */
8180 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
8182 /* Skip this section later on (I don't think this currently
8183 matters, but someday it might). */
8184 o
->link_order_head
= NULL
;
8189 if (strcmp (o
->name
, ".mdebug") == 0)
8191 struct extsym_info einfo
;
8194 /* We have found the .mdebug section in the output file.
8195 Look through all the link_orders comprising it and merge
8196 the information together. */
8197 symhdr
->magic
= swap
->sym_magic
;
8198 /* FIXME: What should the version stamp be? */
8200 symhdr
->ilineMax
= 0;
8204 symhdr
->isymMax
= 0;
8205 symhdr
->ioptMax
= 0;
8206 symhdr
->iauxMax
= 0;
8208 symhdr
->issExtMax
= 0;
8211 symhdr
->iextMax
= 0;
8213 /* We accumulate the debugging information itself in the
8214 debug_info structure. */
8216 debug
.external_dnr
= NULL
;
8217 debug
.external_pdr
= NULL
;
8218 debug
.external_sym
= NULL
;
8219 debug
.external_opt
= NULL
;
8220 debug
.external_aux
= NULL
;
8222 debug
.ssext
= debug
.ssext_end
= NULL
;
8223 debug
.external_fdr
= NULL
;
8224 debug
.external_rfd
= NULL
;
8225 debug
.external_ext
= debug
.external_ext_end
= NULL
;
8227 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
8228 if (mdebug_handle
== NULL
)
8232 esym
.cobol_main
= 0;
8236 esym
.asym
.iss
= issNil
;
8237 esym
.asym
.st
= stLocal
;
8238 esym
.asym
.reserved
= 0;
8239 esym
.asym
.index
= indexNil
;
8241 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
8243 esym
.asym
.sc
= sc
[i
];
8244 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
8247 esym
.asym
.value
= s
->vma
;
8248 last
= s
->vma
+ s
->_raw_size
;
8251 esym
.asym
.value
= last
;
8252 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
8257 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
8259 asection
*input_section
;
8261 const struct ecoff_debug_swap
*input_swap
;
8262 struct ecoff_debug_info input_debug
;
8266 if (p
->type
!= bfd_indirect_link_order
)
8268 if (p
->type
== bfd_data_link_order
)
8273 input_section
= p
->u
.indirect
.section
;
8274 input_bfd
= input_section
->owner
;
8276 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
8277 || (get_elf_backend_data (input_bfd
)
8278 ->elf_backend_ecoff_debug_swap
) == NULL
)
8280 /* I don't know what a non MIPS ELF bfd would be
8281 doing with a .mdebug section, but I don't really
8282 want to deal with it. */
8286 input_swap
= (get_elf_backend_data (input_bfd
)
8287 ->elf_backend_ecoff_debug_swap
);
8289 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
8291 /* The ECOFF linking code expects that we have already
8292 read in the debugging information and set up an
8293 ecoff_debug_info structure, so we do that now. */
8294 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
8298 if (! (bfd_ecoff_debug_accumulate
8299 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
8300 &input_debug
, input_swap
, info
)))
8303 /* Loop through the external symbols. For each one with
8304 interesting information, try to find the symbol in
8305 the linker global hash table and save the information
8306 for the output external symbols. */
8307 eraw_src
= input_debug
.external_ext
;
8308 eraw_end
= (eraw_src
8309 + (input_debug
.symbolic_header
.iextMax
8310 * input_swap
->external_ext_size
));
8312 eraw_src
< eraw_end
;
8313 eraw_src
+= input_swap
->external_ext_size
)
8317 struct mips_elf_link_hash_entry
*h
;
8319 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
8320 if (ext
.asym
.sc
== scNil
8321 || ext
.asym
.sc
== scUndefined
8322 || ext
.asym
.sc
== scSUndefined
)
8325 name
= input_debug
.ssext
+ ext
.asym
.iss
;
8326 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
8327 name
, FALSE
, FALSE
, TRUE
);
8328 if (h
== NULL
|| h
->esym
.ifd
!= -2)
8334 < input_debug
.symbolic_header
.ifdMax
);
8335 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
8341 /* Free up the information we just read. */
8342 free (input_debug
.line
);
8343 free (input_debug
.external_dnr
);
8344 free (input_debug
.external_pdr
);
8345 free (input_debug
.external_sym
);
8346 free (input_debug
.external_opt
);
8347 free (input_debug
.external_aux
);
8348 free (input_debug
.ss
);
8349 free (input_debug
.ssext
);
8350 free (input_debug
.external_fdr
);
8351 free (input_debug
.external_rfd
);
8352 free (input_debug
.external_ext
);
8354 /* Hack: reset the SEC_HAS_CONTENTS flag so that
8355 elf_link_input_bfd ignores this section. */
8356 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
8359 if (SGI_COMPAT (abfd
) && info
->shared
)
8361 /* Create .rtproc section. */
8362 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
8363 if (rtproc_sec
== NULL
)
8365 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
8366 | SEC_LINKER_CREATED
| SEC_READONLY
);
8368 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
8369 if (rtproc_sec
== NULL
8370 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
8371 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
8375 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
8381 /* Build the external symbol information. */
8384 einfo
.debug
= &debug
;
8386 einfo
.failed
= FALSE
;
8387 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8388 mips_elf_output_extsym
, &einfo
);
8392 /* Set the size of the .mdebug section. */
8393 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
8395 /* Skip this section later on (I don't think this currently
8396 matters, but someday it might). */
8397 o
->link_order_head
= NULL
;
8402 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
8404 const char *subname
;
8407 Elf32_External_gptab
*ext_tab
;
8410 /* The .gptab.sdata and .gptab.sbss sections hold
8411 information describing how the small data area would
8412 change depending upon the -G switch. These sections
8413 not used in executables files. */
8414 if (! info
->relocatable
)
8416 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
8418 asection
*input_section
;
8420 if (p
->type
!= bfd_indirect_link_order
)
8422 if (p
->type
== bfd_data_link_order
)
8427 input_section
= p
->u
.indirect
.section
;
8429 /* Hack: reset the SEC_HAS_CONTENTS flag so that
8430 elf_link_input_bfd ignores this section. */
8431 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
8434 /* Skip this section later on (I don't think this
8435 currently matters, but someday it might). */
8436 o
->link_order_head
= NULL
;
8438 /* Really remove the section. */
8439 for (secpp
= &abfd
->sections
;
8441 secpp
= &(*secpp
)->next
)
8443 bfd_section_list_remove (abfd
, secpp
);
8444 --abfd
->section_count
;
8449 /* There is one gptab for initialized data, and one for
8450 uninitialized data. */
8451 if (strcmp (o
->name
, ".gptab.sdata") == 0)
8453 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
8457 (*_bfd_error_handler
)
8458 (_("%s: illegal section name `%s'"),
8459 bfd_get_filename (abfd
), o
->name
);
8460 bfd_set_error (bfd_error_nonrepresentable_section
);
8464 /* The linker script always combines .gptab.data and
8465 .gptab.sdata into .gptab.sdata, and likewise for
8466 .gptab.bss and .gptab.sbss. It is possible that there is
8467 no .sdata or .sbss section in the output file, in which
8468 case we must change the name of the output section. */
8469 subname
= o
->name
+ sizeof ".gptab" - 1;
8470 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
8472 if (o
== gptab_data_sec
)
8473 o
->name
= ".gptab.data";
8475 o
->name
= ".gptab.bss";
8476 subname
= o
->name
+ sizeof ".gptab" - 1;
8477 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
8480 /* Set up the first entry. */
8482 amt
= c
* sizeof (Elf32_gptab
);
8483 tab
= bfd_malloc (amt
);
8486 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
8487 tab
[0].gt_header
.gt_unused
= 0;
8489 /* Combine the input sections. */
8490 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
8492 asection
*input_section
;
8496 bfd_size_type gpentry
;
8498 if (p
->type
!= bfd_indirect_link_order
)
8500 if (p
->type
== bfd_data_link_order
)
8505 input_section
= p
->u
.indirect
.section
;
8506 input_bfd
= input_section
->owner
;
8508 /* Combine the gptab entries for this input section one
8509 by one. We know that the input gptab entries are
8510 sorted by ascending -G value. */
8511 size
= bfd_section_size (input_bfd
, input_section
);
8513 for (gpentry
= sizeof (Elf32_External_gptab
);
8515 gpentry
+= sizeof (Elf32_External_gptab
))
8517 Elf32_External_gptab ext_gptab
;
8518 Elf32_gptab int_gptab
;
8524 if (! (bfd_get_section_contents
8525 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
8526 sizeof (Elf32_External_gptab
))))
8532 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
8534 val
= int_gptab
.gt_entry
.gt_g_value
;
8535 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
8538 for (look
= 1; look
< c
; look
++)
8540 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
8541 tab
[look
].gt_entry
.gt_bytes
+= add
;
8543 if (tab
[look
].gt_entry
.gt_g_value
== val
)
8549 Elf32_gptab
*new_tab
;
8552 /* We need a new table entry. */
8553 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
8554 new_tab
= bfd_realloc (tab
, amt
);
8555 if (new_tab
== NULL
)
8561 tab
[c
].gt_entry
.gt_g_value
= val
;
8562 tab
[c
].gt_entry
.gt_bytes
= add
;
8564 /* Merge in the size for the next smallest -G
8565 value, since that will be implied by this new
8568 for (look
= 1; look
< c
; look
++)
8570 if (tab
[look
].gt_entry
.gt_g_value
< val
8572 || (tab
[look
].gt_entry
.gt_g_value
8573 > tab
[max
].gt_entry
.gt_g_value
)))
8577 tab
[c
].gt_entry
.gt_bytes
+=
8578 tab
[max
].gt_entry
.gt_bytes
;
8583 last
= int_gptab
.gt_entry
.gt_bytes
;
8586 /* Hack: reset the SEC_HAS_CONTENTS flag so that
8587 elf_link_input_bfd ignores this section. */
8588 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
8591 /* The table must be sorted by -G value. */
8593 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
8595 /* Swap out the table. */
8596 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
8597 ext_tab
= bfd_alloc (abfd
, amt
);
8598 if (ext_tab
== NULL
)
8604 for (j
= 0; j
< c
; j
++)
8605 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
8608 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
8609 o
->contents
= (bfd_byte
*) ext_tab
;
8611 /* Skip this section later on (I don't think this currently
8612 matters, but someday it might). */
8613 o
->link_order_head
= NULL
;
8617 /* Invoke the regular ELF backend linker to do all the work. */
8618 if (!MNAME(abfd
,bfd_elf
,bfd_final_link
) (abfd
, info
))
8621 /* Now write out the computed sections. */
8623 if (reginfo_sec
!= NULL
)
8625 Elf32_External_RegInfo ext
;
8627 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
8628 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
8632 if (mdebug_sec
!= NULL
)
8634 BFD_ASSERT (abfd
->output_has_begun
);
8635 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
8637 mdebug_sec
->filepos
))
8640 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
8643 if (gptab_data_sec
!= NULL
)
8645 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
8646 gptab_data_sec
->contents
,
8647 0, gptab_data_sec
->_raw_size
))
8651 if (gptab_bss_sec
!= NULL
)
8653 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
8654 gptab_bss_sec
->contents
,
8655 0, gptab_bss_sec
->_raw_size
))
8659 if (SGI_COMPAT (abfd
))
8661 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
8662 if (rtproc_sec
!= NULL
)
8664 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
8665 rtproc_sec
->contents
,
8666 0, rtproc_sec
->_raw_size
))
8674 /* Structure for saying that BFD machine EXTENSION extends BASE. */
8676 struct mips_mach_extension
{
8677 unsigned long extension
, base
;
8681 /* An array describing how BFD machines relate to one another. The entries
8682 are ordered topologically with MIPS I extensions listed last. */
8684 static const struct mips_mach_extension mips_mach_extensions
[] = {
8685 /* MIPS64 extensions. */
8686 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
8687 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
8689 /* MIPS V extensions. */
8690 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
8692 /* R10000 extensions. */
8693 { bfd_mach_mips12000
, bfd_mach_mips10000
},
8695 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
8696 vr5400 ISA, but doesn't include the multimedia stuff. It seems
8697 better to allow vr5400 and vr5500 code to be merged anyway, since
8698 many libraries will just use the core ISA. Perhaps we could add
8699 some sort of ASE flag if this ever proves a problem. */
8700 { bfd_mach_mips5500
, bfd_mach_mips5400
},
8701 { bfd_mach_mips5400
, bfd_mach_mips5000
},
8703 /* MIPS IV extensions. */
8704 { bfd_mach_mips5
, bfd_mach_mips8000
},
8705 { bfd_mach_mips10000
, bfd_mach_mips8000
},
8706 { bfd_mach_mips5000
, bfd_mach_mips8000
},
8707 { bfd_mach_mips7000
, bfd_mach_mips8000
},
8709 /* VR4100 extensions. */
8710 { bfd_mach_mips4120
, bfd_mach_mips4100
},
8711 { bfd_mach_mips4111
, bfd_mach_mips4100
},
8713 /* MIPS III extensions. */
8714 { bfd_mach_mips8000
, bfd_mach_mips4000
},
8715 { bfd_mach_mips4650
, bfd_mach_mips4000
},
8716 { bfd_mach_mips4600
, bfd_mach_mips4000
},
8717 { bfd_mach_mips4400
, bfd_mach_mips4000
},
8718 { bfd_mach_mips4300
, bfd_mach_mips4000
},
8719 { bfd_mach_mips4100
, bfd_mach_mips4000
},
8720 { bfd_mach_mips4010
, bfd_mach_mips4000
},
8722 /* MIPS32 extensions. */
8723 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
8725 /* MIPS II extensions. */
8726 { bfd_mach_mips4000
, bfd_mach_mips6000
},
8727 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
8729 /* MIPS I extensions. */
8730 { bfd_mach_mips6000
, bfd_mach_mips3000
},
8731 { bfd_mach_mips3900
, bfd_mach_mips3000
}
8735 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
8738 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
8742 for (i
= 0; extension
!= base
&& i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
8743 if (extension
== mips_mach_extensions
[i
].extension
)
8744 extension
= mips_mach_extensions
[i
].base
;
8746 return extension
== base
;
8750 /* Return true if the given ELF header flags describe a 32-bit binary. */
8753 mips_32bit_flags_p (flagword flags
)
8755 return ((flags
& EF_MIPS_32BITMODE
) != 0
8756 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
8757 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
8758 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
8759 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
8760 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
8761 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
8765 /* Merge backend specific data from an object file to the output
8766 object file when linking. */
8769 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
8774 bfd_boolean null_input_bfd
= TRUE
;
8777 /* Check if we have the same endianess */
8778 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
8780 (*_bfd_error_handler
)
8781 (_("%s: endianness incompatible with that of the selected emulation"),
8782 bfd_archive_filename (ibfd
));
8786 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
8787 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
8790 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
8792 (*_bfd_error_handler
)
8793 (_("%s: ABI is incompatible with that of the selected emulation"),
8794 bfd_archive_filename (ibfd
));
8798 new_flags
= elf_elfheader (ibfd
)->e_flags
;
8799 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
8800 old_flags
= elf_elfheader (obfd
)->e_flags
;
8802 if (! elf_flags_init (obfd
))
8804 elf_flags_init (obfd
) = TRUE
;
8805 elf_elfheader (obfd
)->e_flags
= new_flags
;
8806 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
8807 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
8809 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
8810 && bfd_get_arch_info (obfd
)->the_default
)
8812 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
8813 bfd_get_mach (ibfd
)))
8820 /* Check flag compatibility. */
8822 new_flags
&= ~EF_MIPS_NOREORDER
;
8823 old_flags
&= ~EF_MIPS_NOREORDER
;
8825 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
8826 doesn't seem to matter. */
8827 new_flags
&= ~EF_MIPS_XGOT
;
8828 old_flags
&= ~EF_MIPS_XGOT
;
8830 /* MIPSpro generates ucode info in n64 objects. Again, we should
8831 just be able to ignore this. */
8832 new_flags
&= ~EF_MIPS_UCODE
;
8833 old_flags
&= ~EF_MIPS_UCODE
;
8835 if (new_flags
== old_flags
)
8838 /* Check to see if the input BFD actually contains any sections.
8839 If not, its flags may not have been initialised either, but it cannot
8840 actually cause any incompatibility. */
8841 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8843 /* Ignore synthetic sections and empty .text, .data and .bss sections
8844 which are automatically generated by gas. */
8845 if (strcmp (sec
->name
, ".reginfo")
8846 && strcmp (sec
->name
, ".mdebug")
8847 && ((!strcmp (sec
->name
, ".text")
8848 || !strcmp (sec
->name
, ".data")
8849 || !strcmp (sec
->name
, ".bss"))
8850 && sec
->_raw_size
!= 0))
8852 null_input_bfd
= FALSE
;
8861 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
8862 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
8864 (*_bfd_error_handler
)
8865 (_("%s: warning: linking PIC files with non-PIC files"),
8866 bfd_archive_filename (ibfd
));
8870 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
8871 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
8872 if (! (new_flags
& EF_MIPS_PIC
))
8873 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
8875 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
8876 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
8878 /* Compare the ISAs. */
8879 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
8881 (*_bfd_error_handler
)
8882 (_("%s: linking 32-bit code with 64-bit code"),
8883 bfd_archive_filename (ibfd
));
8886 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
8888 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
8889 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
8891 /* Copy the architecture info from IBFD to OBFD. Also copy
8892 the 32-bit flag (if set) so that we continue to recognise
8893 OBFD as a 32-bit binary. */
8894 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
8895 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
8896 elf_elfheader (obfd
)->e_flags
8897 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
8899 /* Copy across the ABI flags if OBFD doesn't use them
8900 and if that was what caused us to treat IBFD as 32-bit. */
8901 if ((old_flags
& EF_MIPS_ABI
) == 0
8902 && mips_32bit_flags_p (new_flags
)
8903 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
8904 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
8908 /* The ISAs aren't compatible. */
8909 (*_bfd_error_handler
)
8910 (_("%s: linking %s module with previous %s modules"),
8911 bfd_archive_filename (ibfd
),
8912 bfd_printable_name (ibfd
),
8913 bfd_printable_name (obfd
));
8918 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
8919 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
8921 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
8922 does set EI_CLASS differently from any 32-bit ABI. */
8923 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
8924 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
8925 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
8927 /* Only error if both are set (to different values). */
8928 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
8929 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
8930 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
8932 (*_bfd_error_handler
)
8933 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
8934 bfd_archive_filename (ibfd
),
8935 elf_mips_abi_name (ibfd
),
8936 elf_mips_abi_name (obfd
));
8939 new_flags
&= ~EF_MIPS_ABI
;
8940 old_flags
&= ~EF_MIPS_ABI
;
8943 /* For now, allow arbitrary mixing of ASEs (retain the union). */
8944 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
8946 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
8948 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
8949 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
8952 /* Warn about any other mismatches */
8953 if (new_flags
!= old_flags
)
8955 (*_bfd_error_handler
)
8956 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
8957 bfd_archive_filename (ibfd
), (unsigned long) new_flags
,
8958 (unsigned long) old_flags
);
8964 bfd_set_error (bfd_error_bad_value
);
8971 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
8974 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
8976 BFD_ASSERT (!elf_flags_init (abfd
)
8977 || elf_elfheader (abfd
)->e_flags
== flags
);
8979 elf_elfheader (abfd
)->e_flags
= flags
;
8980 elf_flags_init (abfd
) = TRUE
;
8985 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
8989 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
8991 /* Print normal ELF private data. */
8992 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
8994 /* xgettext:c-format */
8995 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
8997 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
8998 fprintf (file
, _(" [abi=O32]"));
8999 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
9000 fprintf (file
, _(" [abi=O64]"));
9001 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
9002 fprintf (file
, _(" [abi=EABI32]"));
9003 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
9004 fprintf (file
, _(" [abi=EABI64]"));
9005 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
9006 fprintf (file
, _(" [abi unknown]"));
9007 else if (ABI_N32_P (abfd
))
9008 fprintf (file
, _(" [abi=N32]"));
9009 else if (ABI_64_P (abfd
))
9010 fprintf (file
, _(" [abi=64]"));
9012 fprintf (file
, _(" [no abi set]"));
9014 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
9015 fprintf (file
, _(" [mips1]"));
9016 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
9017 fprintf (file
, _(" [mips2]"));
9018 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
9019 fprintf (file
, _(" [mips3]"));
9020 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
9021 fprintf (file
, _(" [mips4]"));
9022 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
9023 fprintf (file
, _(" [mips5]"));
9024 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
9025 fprintf (file
, _(" [mips32]"));
9026 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
9027 fprintf (file
, _(" [mips64]"));
9028 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
9029 fprintf (file
, _(" [mips32r2]"));
9030 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
9031 fprintf (file
, _(" [mips64r2]"));
9033 fprintf (file
, _(" [unknown ISA]"));
9035 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
9036 fprintf (file
, _(" [mdmx]"));
9038 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
9039 fprintf (file
, _(" [mips16]"));
9041 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
9042 fprintf (file
, _(" [32bitmode]"));
9044 fprintf (file
, _(" [not 32bitmode]"));
9051 struct bfd_elf_special_section
const _bfd_mips_elf_special_sections
[]=
9053 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
9054 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
9055 { ".lit4", 5, 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
9056 { ".lit8", 5, 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
9057 { ".ucode", 6, 0, SHT_MIPS_UCODE
, 0 },
9058 { ".mdebug", 7, 0, SHT_MIPS_DEBUG
, 0 },
9059 { NULL
, 0, 0, 0, 0 }