1 /* MIPS-specific support for ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 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. */
34 #include "elfxx-mips.h"
37 /* Get the ECOFF swapping routines. */
39 #include "coff/symconst.h"
40 #include "coff/ecoff.h"
41 #include "coff/mips.h"
45 /* This structure is used to hold .got entries while estimating got
49 /* The input bfd in which the symbol is defined. */
51 /* The index of the symbol, as stored in the relocation r_info. If
52 it's -1, the addend is a complete address into the
53 executable/shared library. */
55 /* The addend of the relocation that should be added to the symbol
58 /* The offset from the beginning of the .got section to the entry
59 corresponding to this symbol+addend. */
63 /* This structure is used to hold .got information when linking. It
64 is stored in the tdata field of the bfd_elf_section_data structure. */
68 /* The global symbol in the GOT with the lowest index in the dynamic
70 struct elf_link_hash_entry
*global_gotsym
;
71 /* The number of global .got entries. */
72 unsigned int global_gotno
;
73 /* The number of local .got entries. */
74 unsigned int local_gotno
;
75 /* The number of local .got entries we have used. */
76 unsigned int assigned_gotno
;
77 /* A hash table holding members of the got. */
78 struct htab
*got_entries
;
81 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
82 the dynamic symbols. */
84 struct mips_elf_hash_sort_data
86 /* The symbol in the global GOT with the lowest dynamic symbol table
88 struct elf_link_hash_entry
*low
;
89 /* The least dynamic symbol table index corresponding to a symbol
92 /* The greatest dynamic symbol table index not corresponding to a
93 symbol without a GOT entry. */
94 long max_non_got_dynindx
;
97 /* The MIPS ELF linker needs additional information for each symbol in
98 the global hash table. */
100 struct mips_elf_link_hash_entry
102 struct elf_link_hash_entry root
;
104 /* External symbol information. */
107 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
109 unsigned int possibly_dynamic_relocs
;
111 /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
112 a readonly section. */
113 bfd_boolean readonly_reloc
;
115 /* The index of the first dynamic relocation (in the .rel.dyn
116 section) against this symbol. */
117 unsigned int min_dyn_reloc_index
;
119 /* We must not create a stub for a symbol that has relocations
120 related to taking the function's address, i.e. any but
121 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
123 bfd_boolean no_fn_stub
;
125 /* If there is a stub that 32 bit functions should use to call this
126 16 bit function, this points to the section containing the stub. */
129 /* Whether we need the fn_stub; this is set if this symbol appears
130 in any relocs other than a 16 bit call. */
131 bfd_boolean need_fn_stub
;
133 /* If there is a stub that 16 bit functions should use to call this
134 32 bit function, this points to the section containing the stub. */
137 /* This is like the call_stub field, but it is used if the function
138 being called returns a floating point value. */
139 asection
*call_fp_stub
;
141 /* Are we forced local? .*/
142 bfd_boolean forced_local
;
145 /* MIPS ELF linker hash table. */
147 struct mips_elf_link_hash_table
149 struct elf_link_hash_table root
;
151 /* We no longer use this. */
152 /* String section indices for the dynamic section symbols. */
153 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
155 /* The number of .rtproc entries. */
156 bfd_size_type procedure_count
;
157 /* The size of the .compact_rel section (if SGI_COMPAT). */
158 bfd_size_type compact_rel_size
;
159 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
160 entry is set to the address of __rld_obj_head as in IRIX5. */
161 bfd_boolean use_rld_obj_head
;
162 /* This is the value of the __rld_map or __rld_obj_head symbol. */
164 /* This is set if we see any mips16 stub sections. */
165 bfd_boolean mips16_stubs_seen
;
168 /* Structure used to pass information to mips_elf_output_extsym. */
173 struct bfd_link_info
*info
;
174 struct ecoff_debug_info
*debug
;
175 const struct ecoff_debug_swap
*swap
;
179 /* The names of the runtime procedure table symbols used on IRIX5. */
181 static const char * const mips_elf_dynsym_rtproc_names
[] =
184 "_procedure_string_table",
185 "_procedure_table_size",
189 /* These structures are used to generate the .compact_rel section on
194 unsigned long id1
; /* Always one? */
195 unsigned long num
; /* Number of compact relocation entries. */
196 unsigned long id2
; /* Always two? */
197 unsigned long offset
; /* The file offset of the first relocation. */
198 unsigned long reserved0
; /* Zero? */
199 unsigned long reserved1
; /* Zero? */
208 bfd_byte reserved0
[4];
209 bfd_byte reserved1
[4];
210 } Elf32_External_compact_rel
;
214 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
215 unsigned int rtype
: 4; /* Relocation types. See below. */
216 unsigned int dist2to
: 8;
217 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
218 unsigned long konst
; /* KONST field. See below. */
219 unsigned long vaddr
; /* VADDR to be relocated. */
224 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
225 unsigned int rtype
: 4; /* Relocation types. See below. */
226 unsigned int dist2to
: 8;
227 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
228 unsigned long konst
; /* KONST field. See below. */
236 } Elf32_External_crinfo
;
242 } Elf32_External_crinfo2
;
244 /* These are the constants used to swap the bitfields in a crinfo. */
246 #define CRINFO_CTYPE (0x1)
247 #define CRINFO_CTYPE_SH (31)
248 #define CRINFO_RTYPE (0xf)
249 #define CRINFO_RTYPE_SH (27)
250 #define CRINFO_DIST2TO (0xff)
251 #define CRINFO_DIST2TO_SH (19)
252 #define CRINFO_RELVADDR (0x7ffff)
253 #define CRINFO_RELVADDR_SH (0)
255 /* A compact relocation info has long (3 words) or short (2 words)
256 formats. A short format doesn't have VADDR field and relvaddr
257 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
258 #define CRF_MIPS_LONG 1
259 #define CRF_MIPS_SHORT 0
261 /* There are 4 types of compact relocation at least. The value KONST
262 has different meaning for each type:
265 CT_MIPS_REL32 Address in data
266 CT_MIPS_WORD Address in word (XXX)
267 CT_MIPS_GPHI_LO GP - vaddr
268 CT_MIPS_JMPAD Address to jump
271 #define CRT_MIPS_REL32 0xa
272 #define CRT_MIPS_WORD 0xb
273 #define CRT_MIPS_GPHI_LO 0xc
274 #define CRT_MIPS_JMPAD 0xd
276 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
277 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
278 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
279 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
281 /* The structure of the runtime procedure descriptor created by the
282 loader for use by the static exception system. */
284 typedef struct runtime_pdr
{
285 bfd_vma adr
; /* memory address of start of procedure */
286 long regmask
; /* save register mask */
287 long regoffset
; /* save register offset */
288 long fregmask
; /* save floating point register mask */
289 long fregoffset
; /* save floating point register offset */
290 long frameoffset
; /* frame size */
291 short framereg
; /* frame pointer register */
292 short pcreg
; /* offset or reg of return pc */
293 long irpss
; /* index into the runtime string table */
295 struct exception_info
*exception_info
;/* pointer to exception array */
297 #define cbRPDR sizeof (RPDR)
298 #define rpdNil ((pRPDR) 0)
300 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
301 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
302 static void ecoff_swap_rpdr_out
303 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
304 static bfd_boolean mips_elf_create_procedure_table
305 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
306 struct ecoff_debug_info
*));
307 static bfd_boolean mips_elf_check_mips16_stubs
308 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
309 static void bfd_mips_elf32_swap_gptab_in
310 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
311 static void bfd_mips_elf32_swap_gptab_out
312 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
313 static void bfd_elf32_swap_compact_rel_out
314 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
315 static void bfd_elf32_swap_crinfo_out
316 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
318 static void bfd_mips_elf_swap_msym_in
319 PARAMS ((bfd
*, const Elf32_External_Msym
*, Elf32_Internal_Msym
*));
321 static void bfd_mips_elf_swap_msym_out
322 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
323 static int sort_dynamic_relocs
324 PARAMS ((const void *, const void *));
325 static bfd_boolean mips_elf_output_extsym
326 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
327 static int gptab_compare
PARAMS ((const void *, const void *));
328 static asection
* mips_elf_got_section
PARAMS ((bfd
*));
329 static struct mips_got_info
*mips_elf_got_info
330 PARAMS ((bfd
*, asection
**));
331 static bfd_vma mips_elf_local_got_index
332 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
333 static bfd_vma mips_elf_global_got_index
334 PARAMS ((bfd
*, struct elf_link_hash_entry
*));
335 static bfd_vma mips_elf_got_page
336 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*));
337 static bfd_vma mips_elf_got16_entry
338 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_boolean
));
339 static bfd_vma mips_elf_got_offset_from_index
340 PARAMS ((bfd
*, bfd
*, bfd_vma
));
341 static struct mips_got_entry
*mips_elf_create_local_got_entry
342 PARAMS ((bfd
*, struct mips_got_info
*, asection
*, bfd_vma
));
343 static bfd_boolean mips_elf_sort_hash_table
344 PARAMS ((struct bfd_link_info
*, unsigned long));
345 static bfd_boolean mips_elf_sort_hash_table_f
346 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
347 static bfd_boolean mips_elf_record_global_got_symbol
348 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*,
349 struct mips_got_info
*));
350 static const Elf_Internal_Rela
*mips_elf_next_relocation
351 PARAMS ((bfd
*, unsigned int, const Elf_Internal_Rela
*,
352 const Elf_Internal_Rela
*));
353 static bfd_boolean mips_elf_local_relocation_p
354 PARAMS ((bfd
*, const Elf_Internal_Rela
*, asection
**, bfd_boolean
));
355 static bfd_vma mips_elf_sign_extend
PARAMS ((bfd_vma
, int));
356 static bfd_boolean mips_elf_overflow_p
PARAMS ((bfd_vma
, int));
357 static bfd_vma mips_elf_high
PARAMS ((bfd_vma
));
358 static bfd_vma mips_elf_higher
PARAMS ((bfd_vma
));
359 static bfd_vma mips_elf_highest
PARAMS ((bfd_vma
));
360 static bfd_boolean mips_elf_create_compact_rel_section
361 PARAMS ((bfd
*, struct bfd_link_info
*));
362 static bfd_boolean mips_elf_create_got_section
363 PARAMS ((bfd
*, struct bfd_link_info
*));
364 static asection
*mips_elf_create_msym_section
366 static bfd_reloc_status_type mips_elf_calculate_relocation
367 PARAMS ((bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
368 const Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
369 Elf_Internal_Sym
*, asection
**, bfd_vma
*, const char **,
370 bfd_boolean
*, bfd_boolean
));
371 static bfd_vma mips_elf_obtain_contents
372 PARAMS ((reloc_howto_type
*, const Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
373 static bfd_boolean mips_elf_perform_relocation
374 PARAMS ((struct bfd_link_info
*, reloc_howto_type
*,
375 const Elf_Internal_Rela
*, bfd_vma
, bfd
*, asection
*, bfd_byte
*,
377 static bfd_boolean mips_elf_stub_section_p
378 PARAMS ((bfd
*, asection
*));
379 static void mips_elf_allocate_dynamic_relocations
380 PARAMS ((bfd
*, unsigned int));
381 static bfd_boolean mips_elf_create_dynamic_relocation
382 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
383 struct mips_elf_link_hash_entry
*, asection
*,
384 bfd_vma
, bfd_vma
*, asection
*));
385 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
386 static INLINE
char* elf_mips_abi_name
PARAMS ((bfd
*));
387 static void mips_elf_irix6_finish_dynamic_symbol
388 PARAMS ((bfd
*, const char *, Elf_Internal_Sym
*));
389 static bfd_boolean _bfd_mips_elf_mach_extends_p
PARAMS ((flagword
, flagword
));
390 static hashval_t mips_elf_got_entry_hash
PARAMS ((const PTR
));
391 static int mips_elf_got_entry_eq
PARAMS ((const PTR
, const PTR
));
393 /* This will be used when we sort the dynamic relocation records. */
394 static bfd
*reldyn_sorting_bfd
;
396 /* Nonzero if ABFD is using the N32 ABI. */
398 #define ABI_N32_P(abfd) \
399 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
401 /* Nonzero if ABFD is using the N64 ABI. */
402 #define ABI_64_P(abfd) \
403 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
405 /* Nonzero if ABFD is using NewABI conventions. */
406 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
408 /* The IRIX compatibility level we are striving for. */
409 #define IRIX_COMPAT(abfd) \
410 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
412 /* Whether we are trying to be compatible with IRIX at all. */
413 #define SGI_COMPAT(abfd) \
414 (IRIX_COMPAT (abfd) != ict_none)
416 /* The name of the options section. */
417 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
418 (ABI_64_P (abfd) ? ".MIPS.options" : ".options")
420 /* The name of the stub section. */
421 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
422 (ABI_64_P (abfd) ? ".MIPS.stubs" : ".stub")
424 /* The size of an external REL relocation. */
425 #define MIPS_ELF_REL_SIZE(abfd) \
426 (get_elf_backend_data (abfd)->s->sizeof_rel)
428 /* The size of an external dynamic table entry. */
429 #define MIPS_ELF_DYN_SIZE(abfd) \
430 (get_elf_backend_data (abfd)->s->sizeof_dyn)
432 /* The size of a GOT entry. */
433 #define MIPS_ELF_GOT_SIZE(abfd) \
434 (get_elf_backend_data (abfd)->s->arch_size / 8)
436 /* The size of a symbol-table entry. */
437 #define MIPS_ELF_SYM_SIZE(abfd) \
438 (get_elf_backend_data (abfd)->s->sizeof_sym)
440 /* The default alignment for sections, as a power of two. */
441 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
442 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
444 /* Get word-sized data. */
445 #define MIPS_ELF_GET_WORD(abfd, ptr) \
446 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
448 /* Put out word-sized data. */
449 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
451 ? bfd_put_64 (abfd, val, ptr) \
452 : bfd_put_32 (abfd, val, ptr))
454 /* Add a dynamic symbol table-entry. */
456 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
457 (ABI_64_P (elf_hash_table (info)->dynobj) \
458 ? bfd_elf64_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val) \
459 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
461 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
462 (ABI_64_P (elf_hash_table (info)->dynobj) \
463 ? (abort (), FALSE) \
464 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
467 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
468 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
470 /* Determine whether the internal relocation of index REL_IDX is REL
471 (zero) or RELA (non-zero). The assumption is that, if there are
472 two relocation sections for this section, one of them is REL and
473 the other is RELA. If the index of the relocation we're testing is
474 in range for the first relocation section, check that the external
475 relocation size is that for RELA. It is also assumed that, if
476 rel_idx is not in range for the first section, and this first
477 section contains REL relocs, then the relocation is in the second
478 section, that is RELA. */
479 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
480 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
481 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
482 > (bfd_vma)(rel_idx)) \
483 == (elf_section_data (sec)->rel_hdr.sh_entsize \
484 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
485 : sizeof (Elf32_External_Rela))))
487 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
488 from smaller values. Start with zero, widen, *then* decrement. */
489 #define MINUS_ONE (((bfd_vma)0) - 1)
491 /* The number of local .got entries we reserve. */
492 #define MIPS_RESERVED_GOTNO (2)
494 /* Instructions which appear in a stub. For some reason the stub is
495 slightly different on an SGI system. */
496 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
497 #define STUB_LW(abfd) \
500 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
501 : 0x8f998010) /* lw t9,0x8010(gp) */ \
502 : 0x8f998010) /* lw t9,0x8000(gp) */
503 #define STUB_MOVE(abfd) \
504 (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */
505 #define STUB_JALR 0x0320f809 /* jal t9 */
506 #define STUB_LI16(abfd) \
507 (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */
508 #define MIPS_FUNCTION_STUB_SIZE (16)
510 /* The name of the dynamic interpreter. This is put in the .interp
513 #define ELF_DYNAMIC_INTERPRETER(abfd) \
514 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
515 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
516 : "/usr/lib/libc.so.1")
519 #define MNAME(bfd,pre,pos) \
520 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
521 #define ELF_R_SYM(bfd, i) \
522 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
523 #define ELF_R_TYPE(bfd, i) \
524 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
525 #define ELF_R_INFO(bfd, s, t) \
526 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
528 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
529 #define ELF_R_SYM(bfd, i) \
531 #define ELF_R_TYPE(bfd, i) \
533 #define ELF_R_INFO(bfd, s, t) \
534 (ELF32_R_INFO (s, t))
537 /* The mips16 compiler uses a couple of special sections to handle
538 floating point arguments.
540 Section names that look like .mips16.fn.FNNAME contain stubs that
541 copy floating point arguments from the fp regs to the gp regs and
542 then jump to FNNAME. If any 32 bit function calls FNNAME, the
543 call should be redirected to the stub instead. If no 32 bit
544 function calls FNNAME, the stub should be discarded. We need to
545 consider any reference to the function, not just a call, because
546 if the address of the function is taken we will need the stub,
547 since the address might be passed to a 32 bit function.
549 Section names that look like .mips16.call.FNNAME contain stubs
550 that copy floating point arguments from the gp regs to the fp
551 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
552 then any 16 bit function that calls FNNAME should be redirected
553 to the stub instead. If FNNAME is not a 32 bit function, the
554 stub should be discarded.
556 .mips16.call.fp.FNNAME sections are similar, but contain stubs
557 which call FNNAME and then copy the return value from the fp regs
558 to the gp regs. These stubs store the return value in $18 while
559 calling FNNAME; any function which might call one of these stubs
560 must arrange to save $18 around the call. (This case is not
561 needed for 32 bit functions that call 16 bit functions, because
562 16 bit functions always return floating point values in both
565 Note that in all cases FNNAME might be defined statically.
566 Therefore, FNNAME is not used literally. Instead, the relocation
567 information will indicate which symbol the section is for.
569 We record any stubs that we find in the symbol table. */
571 #define FN_STUB ".mips16.fn."
572 #define CALL_STUB ".mips16.call."
573 #define CALL_FP_STUB ".mips16.call.fp."
575 /* Look up an entry in a MIPS ELF linker hash table. */
577 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
578 ((struct mips_elf_link_hash_entry *) \
579 elf_link_hash_lookup (&(table)->root, (string), (create), \
582 /* Traverse a MIPS ELF linker hash table. */
584 #define mips_elf_link_hash_traverse(table, func, info) \
585 (elf_link_hash_traverse \
587 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
590 /* Get the MIPS ELF linker hash table from a link_info structure. */
592 #define mips_elf_hash_table(p) \
593 ((struct mips_elf_link_hash_table *) ((p)->hash))
595 /* Create an entry in a MIPS ELF linker hash table. */
597 static struct bfd_hash_entry
*
598 mips_elf_link_hash_newfunc (entry
, table
, string
)
599 struct bfd_hash_entry
*entry
;
600 struct bfd_hash_table
*table
;
603 struct mips_elf_link_hash_entry
*ret
=
604 (struct mips_elf_link_hash_entry
*) entry
;
606 /* Allocate the structure if it has not already been allocated by a
608 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
609 ret
= ((struct mips_elf_link_hash_entry
*)
610 bfd_hash_allocate (table
,
611 sizeof (struct mips_elf_link_hash_entry
)));
612 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
613 return (struct bfd_hash_entry
*) ret
;
615 /* Call the allocation method of the superclass. */
616 ret
= ((struct mips_elf_link_hash_entry
*)
617 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
619 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
621 /* Set local fields. */
622 memset (&ret
->esym
, 0, sizeof (EXTR
));
623 /* We use -2 as a marker to indicate that the information has
624 not been set. -1 means there is no associated ifd. */
626 ret
->possibly_dynamic_relocs
= 0;
627 ret
->readonly_reloc
= FALSE
;
628 ret
->min_dyn_reloc_index
= 0;
629 ret
->no_fn_stub
= FALSE
;
631 ret
->need_fn_stub
= FALSE
;
632 ret
->call_stub
= NULL
;
633 ret
->call_fp_stub
= NULL
;
634 ret
->forced_local
= FALSE
;
637 return (struct bfd_hash_entry
*) ret
;
640 /* Read ECOFF debugging information from a .mdebug section into a
641 ecoff_debug_info structure. */
644 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
647 struct ecoff_debug_info
*debug
;
650 const struct ecoff_debug_swap
*swap
;
651 char *ext_hdr
= NULL
;
653 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
654 memset (debug
, 0, sizeof (*debug
));
656 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
657 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
660 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
661 swap
->external_hdr_size
))
664 symhdr
= &debug
->symbolic_header
;
665 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
667 /* The symbolic header contains absolute file offsets and sizes to
669 #define READ(ptr, offset, count, size, type) \
670 if (symhdr->count == 0) \
674 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
675 debug->ptr = (type) bfd_malloc (amt); \
676 if (debug->ptr == NULL) \
678 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
679 || bfd_bread (debug->ptr, amt, abfd) != amt) \
683 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
684 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
685 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
686 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
687 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
688 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
690 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
691 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
692 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
693 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
694 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
698 debug
->adjust
= NULL
;
705 if (debug
->line
!= NULL
)
707 if (debug
->external_dnr
!= NULL
)
708 free (debug
->external_dnr
);
709 if (debug
->external_pdr
!= NULL
)
710 free (debug
->external_pdr
);
711 if (debug
->external_sym
!= NULL
)
712 free (debug
->external_sym
);
713 if (debug
->external_opt
!= NULL
)
714 free (debug
->external_opt
);
715 if (debug
->external_aux
!= NULL
)
716 free (debug
->external_aux
);
717 if (debug
->ss
!= NULL
)
719 if (debug
->ssext
!= NULL
)
721 if (debug
->external_fdr
!= NULL
)
722 free (debug
->external_fdr
);
723 if (debug
->external_rfd
!= NULL
)
724 free (debug
->external_rfd
);
725 if (debug
->external_ext
!= NULL
)
726 free (debug
->external_ext
);
730 /* Swap RPDR (runtime procedure table entry) for output. */
733 ecoff_swap_rpdr_out (abfd
, in
, ex
)
738 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
739 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
740 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
741 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
742 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
743 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
745 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
746 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
748 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
750 H_PUT_S32 (abfd
, in
->exception_info
, ex
->p_exception_info
);
754 /* Create a runtime procedure table from the .mdebug section. */
757 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
760 struct bfd_link_info
*info
;
762 struct ecoff_debug_info
*debug
;
764 const struct ecoff_debug_swap
*swap
;
765 HDRR
*hdr
= &debug
->symbolic_header
;
767 struct rpdr_ext
*erp
;
769 struct pdr_ext
*epdr
;
770 struct sym_ext
*esym
;
775 unsigned long sindex
;
779 const char *no_name_func
= _("static procedure (no name)");
787 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
789 sindex
= strlen (no_name_func
) + 1;
793 size
= swap
->external_pdr_size
;
795 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
799 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
802 size
= sizeof (RPDR
);
803 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
807 size
= sizeof (char *);
808 sv
= (char **) bfd_malloc (size
* count
);
812 count
= hdr
->isymMax
;
813 size
= swap
->external_sym_size
;
814 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
818 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
822 ss
= (char *) bfd_malloc (count
);
825 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
829 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
831 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
832 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
834 rp
->regmask
= pdr
.regmask
;
835 rp
->regoffset
= pdr
.regoffset
;
836 rp
->fregmask
= pdr
.fregmask
;
837 rp
->fregoffset
= pdr
.fregoffset
;
838 rp
->frameoffset
= pdr
.frameoffset
;
839 rp
->framereg
= pdr
.framereg
;
840 rp
->pcreg
= pdr
.pcreg
;
842 sv
[i
] = ss
+ sym
.iss
;
843 sindex
+= strlen (sv
[i
]) + 1;
847 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
848 size
= BFD_ALIGN (size
, 16);
849 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
852 mips_elf_hash_table (info
)->procedure_count
= 0;
856 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
858 erp
= (struct rpdr_ext
*) rtproc
;
859 memset (erp
, 0, sizeof (struct rpdr_ext
));
861 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
862 strcpy (str
, no_name_func
);
863 str
+= strlen (no_name_func
) + 1;
864 for (i
= 0; i
< count
; i
++)
866 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
868 str
+= strlen (sv
[i
]) + 1;
870 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
872 /* Set the size and contents of .rtproc section. */
874 s
->contents
= (bfd_byte
*) rtproc
;
876 /* Skip this section later on (I don't think this currently
877 matters, but someday it might). */
878 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
907 /* Check the mips16 stubs for a particular symbol, and see if we can
911 mips_elf_check_mips16_stubs (h
, data
)
912 struct mips_elf_link_hash_entry
*h
;
913 PTR data ATTRIBUTE_UNUSED
;
915 if (h
->root
.root
.type
== bfd_link_hash_warning
)
916 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
918 if (h
->fn_stub
!= NULL
919 && ! h
->need_fn_stub
)
921 /* We don't need the fn_stub; the only references to this symbol
922 are 16 bit calls. Clobber the size to 0 to prevent it from
923 being included in the link. */
924 h
->fn_stub
->_raw_size
= 0;
925 h
->fn_stub
->_cooked_size
= 0;
926 h
->fn_stub
->flags
&= ~SEC_RELOC
;
927 h
->fn_stub
->reloc_count
= 0;
928 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
931 if (h
->call_stub
!= NULL
932 && h
->root
.other
== STO_MIPS16
)
934 /* We don't need the call_stub; this is a 16 bit function, so
935 calls from other 16 bit functions are OK. Clobber the size
936 to 0 to prevent it from being included in the link. */
937 h
->call_stub
->_raw_size
= 0;
938 h
->call_stub
->_cooked_size
= 0;
939 h
->call_stub
->flags
&= ~SEC_RELOC
;
940 h
->call_stub
->reloc_count
= 0;
941 h
->call_stub
->flags
|= SEC_EXCLUDE
;
944 if (h
->call_fp_stub
!= NULL
945 && h
->root
.other
== STO_MIPS16
)
947 /* We don't need the call_stub; this is a 16 bit function, so
948 calls from other 16 bit functions are OK. Clobber the size
949 to 0 to prevent it from being included in the link. */
950 h
->call_fp_stub
->_raw_size
= 0;
951 h
->call_fp_stub
->_cooked_size
= 0;
952 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
953 h
->call_fp_stub
->reloc_count
= 0;
954 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
960 bfd_reloc_status_type
961 _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
962 relocateable
, data
, gp
)
965 arelent
*reloc_entry
;
966 asection
*input_section
;
967 bfd_boolean relocateable
;
975 if (bfd_is_com_section (symbol
->section
))
978 relocation
= symbol
->value
;
980 relocation
+= symbol
->section
->output_section
->vma
;
981 relocation
+= symbol
->section
->output_offset
;
983 if (reloc_entry
->address
> input_section
->_cooked_size
)
984 return bfd_reloc_outofrange
;
986 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
988 /* Set val to the offset into the section or symbol. */
989 if (reloc_entry
->howto
->src_mask
== 0)
991 /* This case occurs with the 64-bit MIPS ELF ABI. */
992 val
= reloc_entry
->addend
;
996 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1001 /* Adjust val for the final section location and GP value. If we
1002 are producing relocateable output, we don't want to do this for
1003 an external symbol. */
1005 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1006 val
+= relocation
- gp
;
1008 insn
= (insn
& ~0xffff) | (val
& 0xffff);
1009 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1012 reloc_entry
->address
+= input_section
->output_offset
;
1014 else if ((long) val
>= 0x8000 || (long) val
< -0x8000)
1015 return bfd_reloc_overflow
;
1017 return bfd_reloc_ok
;
1020 /* Swap an entry in a .gptab section. Note that these routines rely
1021 on the equivalence of the two elements of the union. */
1024 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1026 const Elf32_External_gptab
*ex
;
1029 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1030 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1034 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1036 const Elf32_gptab
*in
;
1037 Elf32_External_gptab
*ex
;
1039 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
1040 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
1044 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1046 const Elf32_compact_rel
*in
;
1047 Elf32_External_compact_rel
*ex
;
1049 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1050 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1051 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1052 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1053 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1054 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1058 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1060 const Elf32_crinfo
*in
;
1061 Elf32_External_crinfo
*ex
;
1065 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1066 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1067 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1068 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1069 H_PUT_32 (abfd
, l
, ex
->info
);
1070 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1071 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1075 /* Swap in an MSYM entry. */
1078 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
1080 const Elf32_External_Msym
*ex
;
1081 Elf32_Internal_Msym
*in
;
1083 in
->ms_hash_value
= H_GET_32 (abfd
, ex
->ms_hash_value
);
1084 in
->ms_info
= H_GET_32 (abfd
, ex
->ms_info
);
1087 /* Swap out an MSYM entry. */
1090 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
1092 const Elf32_Internal_Msym
*in
;
1093 Elf32_External_Msym
*ex
;
1095 H_PUT_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
1096 H_PUT_32 (abfd
, in
->ms_info
, ex
->ms_info
);
1099 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1100 routines swap this structure in and out. They are used outside of
1101 BFD, so they are globally visible. */
1104 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1106 const Elf32_External_RegInfo
*ex
;
1109 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1110 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1111 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1112 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1113 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1114 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1118 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1120 const Elf32_RegInfo
*in
;
1121 Elf32_External_RegInfo
*ex
;
1123 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1124 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1125 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1126 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1127 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1128 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1131 /* In the 64 bit ABI, the .MIPS.options section holds register
1132 information in an Elf64_Reginfo structure. These routines swap
1133 them in and out. They are globally visible because they are used
1134 outside of BFD. These routines are here so that gas can call them
1135 without worrying about whether the 64 bit ABI has been included. */
1138 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1140 const Elf64_External_RegInfo
*ex
;
1141 Elf64_Internal_RegInfo
*in
;
1143 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1144 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1145 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1146 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1147 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1148 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1149 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1153 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1155 const Elf64_Internal_RegInfo
*in
;
1156 Elf64_External_RegInfo
*ex
;
1158 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1159 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1160 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1161 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1162 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1163 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1164 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1167 /* Swap in an options header. */
1170 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1172 const Elf_External_Options
*ex
;
1173 Elf_Internal_Options
*in
;
1175 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1176 in
->size
= H_GET_8 (abfd
, ex
->size
);
1177 in
->section
= H_GET_16 (abfd
, ex
->section
);
1178 in
->info
= H_GET_32 (abfd
, ex
->info
);
1181 /* Swap out an options header. */
1184 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1186 const Elf_Internal_Options
*in
;
1187 Elf_External_Options
*ex
;
1189 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1190 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1191 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1192 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1195 /* This function is called via qsort() to sort the dynamic relocation
1196 entries by increasing r_symndx value. */
1199 sort_dynamic_relocs (arg1
, arg2
)
1203 Elf_Internal_Rela int_reloc1
;
1204 Elf_Internal_Rela int_reloc2
;
1206 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1207 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1209 return ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
1212 /* This routine is used to write out ECOFF debugging external symbol
1213 information. It is called via mips_elf_link_hash_traverse. The
1214 ECOFF external symbol information must match the ELF external
1215 symbol information. Unfortunately, at this point we don't know
1216 whether a symbol is required by reloc information, so the two
1217 tables may wind up being different. We must sort out the external
1218 symbol information before we can set the final size of the .mdebug
1219 section, and we must set the size of the .mdebug section before we
1220 can relocate any sections, and we can't know which symbols are
1221 required by relocation until we relocate the sections.
1222 Fortunately, it is relatively unlikely that any symbol will be
1223 stripped but required by a reloc. In particular, it can not happen
1224 when generating a final executable. */
1227 mips_elf_output_extsym (h
, data
)
1228 struct mips_elf_link_hash_entry
*h
;
1231 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
1233 asection
*sec
, *output_section
;
1235 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1236 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1238 if (h
->root
.indx
== -2)
1240 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1241 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
1242 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
1243 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
1245 else if (einfo
->info
->strip
== strip_all
1246 || (einfo
->info
->strip
== strip_some
1247 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1248 h
->root
.root
.root
.string
,
1249 FALSE
, FALSE
) == NULL
))
1257 if (h
->esym
.ifd
== -2)
1260 h
->esym
.cobol_main
= 0;
1261 h
->esym
.weakext
= 0;
1262 h
->esym
.reserved
= 0;
1263 h
->esym
.ifd
= ifdNil
;
1264 h
->esym
.asym
.value
= 0;
1265 h
->esym
.asym
.st
= stGlobal
;
1267 if (h
->root
.root
.type
== bfd_link_hash_undefined
1268 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
1272 /* Use undefined class. Also, set class and type for some
1274 name
= h
->root
.root
.root
.string
;
1275 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
1276 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
1278 h
->esym
.asym
.sc
= scData
;
1279 h
->esym
.asym
.st
= stLabel
;
1280 h
->esym
.asym
.value
= 0;
1282 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
1284 h
->esym
.asym
.sc
= scAbs
;
1285 h
->esym
.asym
.st
= stLabel
;
1286 h
->esym
.asym
.value
=
1287 mips_elf_hash_table (einfo
->info
)->procedure_count
;
1289 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
1291 h
->esym
.asym
.sc
= scAbs
;
1292 h
->esym
.asym
.st
= stLabel
;
1293 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
1296 h
->esym
.asym
.sc
= scUndefined
;
1298 else if (h
->root
.root
.type
!= bfd_link_hash_defined
1299 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1300 h
->esym
.asym
.sc
= scAbs
;
1305 sec
= h
->root
.root
.u
.def
.section
;
1306 output_section
= sec
->output_section
;
1308 /* When making a shared library and symbol h is the one from
1309 the another shared library, OUTPUT_SECTION may be null. */
1310 if (output_section
== NULL
)
1311 h
->esym
.asym
.sc
= scUndefined
;
1314 name
= bfd_section_name (output_section
->owner
, output_section
);
1316 if (strcmp (name
, ".text") == 0)
1317 h
->esym
.asym
.sc
= scText
;
1318 else if (strcmp (name
, ".data") == 0)
1319 h
->esym
.asym
.sc
= scData
;
1320 else if (strcmp (name
, ".sdata") == 0)
1321 h
->esym
.asym
.sc
= scSData
;
1322 else if (strcmp (name
, ".rodata") == 0
1323 || strcmp (name
, ".rdata") == 0)
1324 h
->esym
.asym
.sc
= scRData
;
1325 else if (strcmp (name
, ".bss") == 0)
1326 h
->esym
.asym
.sc
= scBss
;
1327 else if (strcmp (name
, ".sbss") == 0)
1328 h
->esym
.asym
.sc
= scSBss
;
1329 else if (strcmp (name
, ".init") == 0)
1330 h
->esym
.asym
.sc
= scInit
;
1331 else if (strcmp (name
, ".fini") == 0)
1332 h
->esym
.asym
.sc
= scFini
;
1334 h
->esym
.asym
.sc
= scAbs
;
1338 h
->esym
.asym
.reserved
= 0;
1339 h
->esym
.asym
.index
= indexNil
;
1342 if (h
->root
.root
.type
== bfd_link_hash_common
)
1343 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1344 else if (h
->root
.root
.type
== bfd_link_hash_defined
1345 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1347 if (h
->esym
.asym
.sc
== scCommon
)
1348 h
->esym
.asym
.sc
= scBss
;
1349 else if (h
->esym
.asym
.sc
== scSCommon
)
1350 h
->esym
.asym
.sc
= scSBss
;
1352 sec
= h
->root
.root
.u
.def
.section
;
1353 output_section
= sec
->output_section
;
1354 if (output_section
!= NULL
)
1355 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1356 + sec
->output_offset
1357 + output_section
->vma
);
1359 h
->esym
.asym
.value
= 0;
1361 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1363 struct mips_elf_link_hash_entry
*hd
= h
;
1364 bfd_boolean no_fn_stub
= h
->no_fn_stub
;
1366 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
1368 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
1369 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
1374 /* Set type and value for a symbol with a function stub. */
1375 h
->esym
.asym
.st
= stProc
;
1376 sec
= hd
->root
.root
.u
.def
.section
;
1378 h
->esym
.asym
.value
= 0;
1381 output_section
= sec
->output_section
;
1382 if (output_section
!= NULL
)
1383 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
1384 + sec
->output_offset
1385 + output_section
->vma
);
1387 h
->esym
.asym
.value
= 0;
1395 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1396 h
->root
.root
.root
.string
,
1399 einfo
->failed
= TRUE
;
1406 /* A comparison routine used to sort .gptab entries. */
1409 gptab_compare (p1
, p2
)
1413 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
1414 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
1416 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
1419 /* Functions to manage the got entry hash table. */
1421 mips_elf_got_entry_hash (entry_
)
1424 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
1426 return htab_hash_pointer (entry
->abfd
) + entry
->symndx
1428 + (entry
->addend
>> 32)
1434 mips_elf_got_entry_eq (entry1
, entry2
)
1438 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
1439 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
1441 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
1442 && e1
->addend
== e2
->addend
;
1445 /* Returns the GOT section for ABFD. */
1448 mips_elf_got_section (abfd
)
1451 return bfd_get_section_by_name (abfd
, ".got");
1454 /* Returns the GOT information associated with the link indicated by
1455 INFO. If SGOTP is non-NULL, it is filled in with the GOT
1458 static struct mips_got_info
*
1459 mips_elf_got_info (abfd
, sgotp
)
1464 struct mips_got_info
*g
;
1466 sgot
= mips_elf_got_section (abfd
);
1467 BFD_ASSERT (sgot
!= NULL
);
1468 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
1469 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
1470 BFD_ASSERT (g
!= NULL
);
1477 /* Returns the GOT offset at which the indicated address can be found.
1478 If there is not yet a GOT entry for this value, create one. Returns
1479 -1 if no satisfactory GOT offset can be found. */
1482 mips_elf_local_got_index (abfd
, info
, value
)
1484 struct bfd_link_info
*info
;
1488 struct mips_got_info
*g
;
1489 struct mips_got_entry
*entry
;
1491 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1493 entry
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1495 return entry
->gotidx
;
1500 /* Returns the GOT index for the global symbol indicated by H. */
1503 mips_elf_global_got_index (abfd
, h
)
1505 struct elf_link_hash_entry
*h
;
1509 struct mips_got_info
*g
;
1510 long global_got_dynindx
= 0;
1512 g
= mips_elf_got_info (abfd
, &sgot
);
1513 if (g
->global_gotsym
!= NULL
)
1514 global_got_dynindx
= g
->global_gotsym
->dynindx
;
1516 /* Once we determine the global GOT entry with the lowest dynamic
1517 symbol table index, we must put all dynamic symbols with greater
1518 indices into the GOT. That makes it easy to calculate the GOT
1520 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
1521 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
1522 * MIPS_ELF_GOT_SIZE (abfd
));
1523 BFD_ASSERT (index
< sgot
->_raw_size
);
1528 /* Find a GOT entry that is within 32KB of the VALUE. These entries
1529 are supposed to be placed at small offsets in the GOT, i.e.,
1530 within 32KB of GP. Return the index into the GOT for this page,
1531 and store the offset from this entry to the desired address in
1532 OFFSETP, if it is non-NULL. */
1535 mips_elf_got_page (abfd
, info
, value
, offsetp
)
1537 struct bfd_link_info
*info
;
1542 struct mips_got_info
*g
;
1544 struct mips_got_entry
*entry
;
1546 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1548 entry
= mips_elf_create_local_got_entry (abfd
, g
, sgot
,
1550 & (~(bfd_vma
)0xffff));
1555 index
= entry
->gotidx
;
1558 *offsetp
= value
- entry
->addend
;
1563 /* Find a GOT entry whose higher-order 16 bits are the same as those
1564 for value. Return the index into the GOT for this entry. */
1567 mips_elf_got16_entry (abfd
, info
, value
, external
)
1569 struct bfd_link_info
*info
;
1571 bfd_boolean external
;
1574 struct mips_got_info
*g
;
1575 struct mips_got_entry
*entry
;
1579 /* Although the ABI says that it is "the high-order 16 bits" that we
1580 want, it is really the %high value. The complete value is
1581 calculated with a `addiu' of a LO16 relocation, just as with a
1583 value
= mips_elf_high (value
) << 16;
1586 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1588 entry
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1590 return entry
->gotidx
;
1595 /* Returns the offset for the entry at the INDEXth position
1599 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
1607 sgot
= mips_elf_got_section (dynobj
);
1608 gp
= _bfd_get_gp_value (output_bfd
);
1609 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
1613 /* Create a local GOT entry for VALUE. Return the index of the entry,
1614 or -1 if it could not be created. */
1616 static struct mips_got_entry
*
1617 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
1619 struct mips_got_info
*g
;
1623 struct mips_got_entry entry
, **loc
;
1626 entry
.symndx
= (unsigned long)-1;
1627 entry
.addend
= value
;
1629 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
1634 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
1636 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
1641 memcpy (*loc
, &entry
, sizeof entry
);
1643 if (g
->assigned_gotno
>= g
->local_gotno
)
1645 (*loc
)->gotidx
= (unsigned long)-1;
1646 /* We didn't allocate enough space in the GOT. */
1647 (*_bfd_error_handler
)
1648 (_("not enough GOT space for local GOT entries"));
1649 bfd_set_error (bfd_error_bad_value
);
1653 MIPS_ELF_PUT_WORD (abfd
, value
,
1654 (sgot
->contents
+ entry
.gotidx
));
1659 /* Sort the dynamic symbol table so that symbols that need GOT entries
1660 appear towards the end. This reduces the amount of GOT space
1661 required. MAX_LOCAL is used to set the number of local symbols
1662 known to be in the dynamic symbol table. During
1663 _bfd_mips_elf_size_dynamic_sections, this value is 1. Afterward, the
1664 section symbols are added and the count is higher. */
1667 mips_elf_sort_hash_table (info
, max_local
)
1668 struct bfd_link_info
*info
;
1669 unsigned long max_local
;
1671 struct mips_elf_hash_sort_data hsd
;
1672 struct mips_got_info
*g
;
1675 dynobj
= elf_hash_table (info
)->dynobj
;
1678 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
1679 hsd
.max_non_got_dynindx
= max_local
;
1680 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
1681 elf_hash_table (info
)),
1682 mips_elf_sort_hash_table_f
,
1685 /* There should have been enough room in the symbol table to
1686 accommodate both the GOT and non-GOT symbols. */
1687 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
1689 /* Now we know which dynamic symbol has the lowest dynamic symbol
1690 table index in the GOT. */
1691 g
= mips_elf_got_info (dynobj
, NULL
);
1692 g
->global_gotsym
= hsd
.low
;
1697 /* If H needs a GOT entry, assign it the highest available dynamic
1698 index. Otherwise, assign it the lowest available dynamic
1702 mips_elf_sort_hash_table_f (h
, data
)
1703 struct mips_elf_link_hash_entry
*h
;
1706 struct mips_elf_hash_sort_data
*hsd
1707 = (struct mips_elf_hash_sort_data
*) data
;
1709 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1710 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1712 /* Symbols without dynamic symbol table entries aren't interesting
1714 if (h
->root
.dynindx
== -1)
1717 if (h
->root
.got
.offset
!= 1)
1718 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
1721 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
1722 hsd
->low
= (struct elf_link_hash_entry
*) h
;
1728 /* If H is a symbol that needs a global GOT entry, but has a dynamic
1729 symbol table index lower than any we've seen to date, record it for
1733 mips_elf_record_global_got_symbol (h
, info
, g
)
1734 struct elf_link_hash_entry
*h
;
1735 struct bfd_link_info
*info
;
1736 struct mips_got_info
*g ATTRIBUTE_UNUSED
;
1738 /* A global symbol in the GOT must also be in the dynamic symbol
1740 if (h
->dynindx
== -1)
1742 switch (ELF_ST_VISIBILITY (h
->other
))
1746 _bfd_mips_elf_hide_symbol (info
, h
, TRUE
);
1749 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
1753 /* If we've already marked this entry as needing GOT space, we don't
1754 need to do it again. */
1755 if (h
->got
.offset
!= MINUS_ONE
)
1758 /* By setting this to a value other than -1, we are indicating that
1759 there needs to be a GOT entry for H. Avoid using zero, as the
1760 generic ELF copy_indirect_symbol tests for <= 0. */
1766 /* Returns the first relocation of type r_type found, beginning with
1767 RELOCATION. RELEND is one-past-the-end of the relocation table. */
1769 static const Elf_Internal_Rela
*
1770 mips_elf_next_relocation (abfd
, r_type
, relocation
, relend
)
1771 bfd
*abfd ATTRIBUTE_UNUSED
;
1772 unsigned int r_type
;
1773 const Elf_Internal_Rela
*relocation
;
1774 const Elf_Internal_Rela
*relend
;
1776 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
1777 immediately following. However, for the IRIX6 ABI, the next
1778 relocation may be a composed relocation consisting of several
1779 relocations for the same address. In that case, the R_MIPS_LO16
1780 relocation may occur as one of these. We permit a similar
1781 extension in general, as that is useful for GCC. */
1782 while (relocation
< relend
)
1784 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
)
1790 /* We didn't find it. */
1791 bfd_set_error (bfd_error_bad_value
);
1795 /* Return whether a relocation is against a local symbol. */
1798 mips_elf_local_relocation_p (input_bfd
, relocation
, local_sections
,
1801 const Elf_Internal_Rela
*relocation
;
1802 asection
**local_sections
;
1803 bfd_boolean check_forced
;
1805 unsigned long r_symndx
;
1806 Elf_Internal_Shdr
*symtab_hdr
;
1807 struct mips_elf_link_hash_entry
*h
;
1810 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
1811 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1812 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
1814 if (r_symndx
< extsymoff
)
1816 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
1821 /* Look up the hash table to check whether the symbol
1822 was forced local. */
1823 h
= (struct mips_elf_link_hash_entry
*)
1824 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
1825 /* Find the real hash-table entry for this symbol. */
1826 while (h
->root
.root
.type
== bfd_link_hash_indirect
1827 || h
->root
.root
.type
== bfd_link_hash_warning
)
1828 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1829 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
1836 /* Sign-extend VALUE, which has the indicated number of BITS. */
1839 mips_elf_sign_extend (value
, bits
)
1843 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
1844 /* VALUE is negative. */
1845 value
|= ((bfd_vma
) - 1) << bits
;
1850 /* Return non-zero if the indicated VALUE has overflowed the maximum
1851 range expressable by a signed number with the indicated number of
1855 mips_elf_overflow_p (value
, bits
)
1859 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
1861 if (svalue
> (1 << (bits
- 1)) - 1)
1862 /* The value is too big. */
1864 else if (svalue
< -(1 << (bits
- 1)))
1865 /* The value is too small. */
1872 /* Calculate the %high function. */
1875 mips_elf_high (value
)
1878 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
1881 /* Calculate the %higher function. */
1884 mips_elf_higher (value
)
1885 bfd_vma value ATTRIBUTE_UNUSED
;
1888 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
1891 return (bfd_vma
) -1;
1895 /* Calculate the %highest function. */
1898 mips_elf_highest (value
)
1899 bfd_vma value ATTRIBUTE_UNUSED
;
1902 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
1905 return (bfd_vma
) -1;
1909 /* Create the .compact_rel section. */
1912 mips_elf_create_compact_rel_section (abfd
, info
)
1914 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1917 register asection
*s
;
1919 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
1921 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
1924 s
= bfd_make_section (abfd
, ".compact_rel");
1926 || ! bfd_set_section_flags (abfd
, s
, flags
)
1927 || ! bfd_set_section_alignment (abfd
, s
,
1928 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
1931 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
1937 /* Create the .got section to hold the global offset table. */
1940 mips_elf_create_got_section (abfd
, info
)
1942 struct bfd_link_info
*info
;
1945 register asection
*s
;
1946 struct elf_link_hash_entry
*h
;
1947 struct bfd_link_hash_entry
*bh
;
1948 struct mips_got_info
*g
;
1951 /* This function may be called more than once. */
1952 if (mips_elf_got_section (abfd
))
1955 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1956 | SEC_LINKER_CREATED
);
1958 s
= bfd_make_section (abfd
, ".got");
1960 || ! bfd_set_section_flags (abfd
, s
, flags
)
1961 || ! bfd_set_section_alignment (abfd
, s
, 4))
1964 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
1965 linker script because we don't want to define the symbol if we
1966 are not creating a global offset table. */
1968 if (! (_bfd_generic_link_add_one_symbol
1969 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
1970 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
1971 get_elf_backend_data (abfd
)->collect
, &bh
)))
1974 h
= (struct elf_link_hash_entry
*) bh
;
1975 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
1976 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1977 h
->type
= STT_OBJECT
;
1980 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1983 /* The first several global offset table entries are reserved. */
1984 s
->_raw_size
= MIPS_RESERVED_GOTNO
* MIPS_ELF_GOT_SIZE (abfd
);
1986 amt
= sizeof (struct mips_got_info
);
1987 g
= (struct mips_got_info
*) bfd_alloc (abfd
, amt
);
1990 g
->global_gotsym
= NULL
;
1991 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
1992 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
1993 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
1994 mips_elf_got_entry_eq
,
1996 if (g
->got_entries
== NULL
)
1998 if (elf_section_data (s
) == NULL
)
2000 amt
= sizeof (struct bfd_elf_section_data
);
2001 s
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
2002 if (elf_section_data (s
) == NULL
)
2005 elf_section_data (s
)->tdata
= (PTR
) g
;
2006 elf_section_data (s
)->this_hdr
.sh_flags
2007 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2012 /* Returns the .msym section for ABFD, creating it if it does not
2013 already exist. Returns NULL to indicate error. */
2016 mips_elf_create_msym_section (abfd
)
2021 s
= bfd_get_section_by_name (abfd
, ".msym");
2024 s
= bfd_make_section (abfd
, ".msym");
2026 || !bfd_set_section_flags (abfd
, s
,
2030 | SEC_LINKER_CREATED
2032 || !bfd_set_section_alignment (abfd
, s
,
2033 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
2040 /* Calculate the value produced by the RELOCATION (which comes from
2041 the INPUT_BFD). The ADDEND is the addend to use for this
2042 RELOCATION; RELOCATION->R_ADDEND is ignored.
2044 The result of the relocation calculation is stored in VALUEP.
2045 REQUIRE_JALXP indicates whether or not the opcode used with this
2046 relocation must be JALX.
2048 This function returns bfd_reloc_continue if the caller need take no
2049 further action regarding this relocation, bfd_reloc_notsupported if
2050 something goes dramatically wrong, bfd_reloc_overflow if an
2051 overflow occurs, and bfd_reloc_ok to indicate success. */
2053 static bfd_reloc_status_type
2054 mips_elf_calculate_relocation (abfd
, input_bfd
, input_section
, info
,
2055 relocation
, addend
, howto
, local_syms
,
2056 local_sections
, valuep
, namep
,
2057 require_jalxp
, save_addend
)
2060 asection
*input_section
;
2061 struct bfd_link_info
*info
;
2062 const Elf_Internal_Rela
*relocation
;
2064 reloc_howto_type
*howto
;
2065 Elf_Internal_Sym
*local_syms
;
2066 asection
**local_sections
;
2069 bfd_boolean
*require_jalxp
;
2070 bfd_boolean save_addend
;
2072 /* The eventual value we will return. */
2074 /* The address of the symbol against which the relocation is
2077 /* The final GP value to be used for the relocatable, executable, or
2078 shared object file being produced. */
2079 bfd_vma gp
= MINUS_ONE
;
2080 /* The place (section offset or address) of the storage unit being
2083 /* The value of GP used to create the relocatable object. */
2084 bfd_vma gp0
= MINUS_ONE
;
2085 /* The offset into the global offset table at which the address of
2086 the relocation entry symbol, adjusted by the addend, resides
2087 during execution. */
2088 bfd_vma g
= MINUS_ONE
;
2089 /* The section in which the symbol referenced by the relocation is
2091 asection
*sec
= NULL
;
2092 struct mips_elf_link_hash_entry
*h
= NULL
;
2093 /* TRUE if the symbol referred to by this relocation is a local
2095 bfd_boolean local_p
, was_local_p
;
2096 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
2097 bfd_boolean gp_disp_p
= FALSE
;
2098 Elf_Internal_Shdr
*symtab_hdr
;
2100 unsigned long r_symndx
;
2102 /* TRUE if overflow occurred during the calculation of the
2103 relocation value. */
2104 bfd_boolean overflowed_p
;
2105 /* TRUE if this relocation refers to a MIPS16 function. */
2106 bfd_boolean target_is_16_bit_code_p
= FALSE
;
2108 /* Parse the relocation. */
2109 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
2110 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
2111 p
= (input_section
->output_section
->vma
2112 + input_section
->output_offset
2113 + relocation
->r_offset
);
2115 /* Assume that there will be no overflow. */
2116 overflowed_p
= FALSE
;
2118 /* Figure out whether or not the symbol is local, and get the offset
2119 used in the array of hash table entries. */
2120 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2121 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
2122 local_sections
, FALSE
);
2123 was_local_p
= local_p
;
2124 if (! elf_bad_symtab (input_bfd
))
2125 extsymoff
= symtab_hdr
->sh_info
;
2128 /* The symbol table does not follow the rule that local symbols
2129 must come before globals. */
2133 /* Figure out the value of the symbol. */
2136 Elf_Internal_Sym
*sym
;
2138 sym
= local_syms
+ r_symndx
;
2139 sec
= local_sections
[r_symndx
];
2141 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2142 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
2143 || (sec
->flags
& SEC_MERGE
))
2144 symbol
+= sym
->st_value
;
2145 if ((sec
->flags
& SEC_MERGE
)
2146 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2148 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
2150 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
2153 /* MIPS16 text labels should be treated as odd. */
2154 if (sym
->st_other
== STO_MIPS16
)
2157 /* Record the name of this symbol, for our caller. */
2158 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
2159 symtab_hdr
->sh_link
,
2162 *namep
= bfd_section_name (input_bfd
, sec
);
2164 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
2168 /* For global symbols we look up the symbol in the hash-table. */
2169 h
= ((struct mips_elf_link_hash_entry
*)
2170 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
2171 /* Find the real hash-table entry for this symbol. */
2172 while (h
->root
.root
.type
== bfd_link_hash_indirect
2173 || h
->root
.root
.type
== bfd_link_hash_warning
)
2174 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2176 /* Record the name of this symbol, for our caller. */
2177 *namep
= h
->root
.root
.root
.string
;
2179 /* See if this is the special _gp_disp symbol. Note that such a
2180 symbol must always be a global symbol. */
2181 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0
2182 && ! NEWABI_P (input_bfd
))
2184 /* Relocations against _gp_disp are permitted only with
2185 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
2186 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
2187 return bfd_reloc_notsupported
;
2191 /* If this symbol is defined, calculate its address. Note that
2192 _gp_disp is a magic symbol, always implicitly defined by the
2193 linker, so it's inappropriate to check to see whether or not
2195 else if ((h
->root
.root
.type
== bfd_link_hash_defined
2196 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2197 && h
->root
.root
.u
.def
.section
)
2199 sec
= h
->root
.root
.u
.def
.section
;
2200 if (sec
->output_section
)
2201 symbol
= (h
->root
.root
.u
.def
.value
2202 + sec
->output_section
->vma
2203 + sec
->output_offset
);
2205 symbol
= h
->root
.root
.u
.def
.value
;
2207 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
2208 /* We allow relocations against undefined weak symbols, giving
2209 it the value zero, so that you can undefined weak functions
2210 and check to see if they exist by looking at their
2213 else if (info
->shared
2214 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
2215 && !info
->no_undefined
2216 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
2218 else if (strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINK") == 0 ||
2219 strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINKING") == 0)
2221 /* If this is a dynamic link, we should have created a
2222 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
2223 in in _bfd_mips_elf_create_dynamic_sections.
2224 Otherwise, we should define the symbol with a value of 0.
2225 FIXME: It should probably get into the symbol table
2227 BFD_ASSERT (! info
->shared
);
2228 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
2233 if (! ((*info
->callbacks
->undefined_symbol
)
2234 (info
, h
->root
.root
.root
.string
, input_bfd
,
2235 input_section
, relocation
->r_offset
,
2236 (!info
->shared
|| info
->no_undefined
2237 || ELF_ST_VISIBILITY (h
->root
.other
)))))
2238 return bfd_reloc_undefined
;
2242 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
2245 /* If this is a 32- or 64-bit call to a 16-bit function with a stub, we
2246 need to redirect the call to the stub, unless we're already *in*
2248 if (r_type
!= R_MIPS16_26
&& !info
->relocateable
2249 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
2250 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
2251 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
2252 && !mips_elf_stub_section_p (input_bfd
, input_section
))
2254 /* This is a 32- or 64-bit call to a 16-bit function. We should
2255 have already noticed that we were going to need the
2258 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
2261 BFD_ASSERT (h
->need_fn_stub
);
2265 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2267 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
2268 need to redirect the call to the stub. */
2269 else if (r_type
== R_MIPS16_26
&& !info
->relocateable
2271 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
2272 && !target_is_16_bit_code_p
)
2274 /* If both call_stub and call_fp_stub are defined, we can figure
2275 out which one to use by seeing which one appears in the input
2277 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
2282 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
2284 if (strncmp (bfd_get_section_name (input_bfd
, o
),
2285 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
2287 sec
= h
->call_fp_stub
;
2294 else if (h
->call_stub
!= NULL
)
2297 sec
= h
->call_fp_stub
;
2299 BFD_ASSERT (sec
->_raw_size
> 0);
2300 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2303 /* Calls from 16-bit code to 32-bit code and vice versa require the
2304 special jalx instruction. */
2305 *require_jalxp
= (!info
->relocateable
2306 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
2307 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
2309 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
2310 local_sections
, TRUE
);
2312 /* If we haven't already determined the GOT offset, or the GP value,
2313 and we're going to need it, get it now. */
2318 case R_MIPS_GOT_DISP
:
2319 case R_MIPS_GOT_HI16
:
2320 case R_MIPS_CALL_HI16
:
2321 case R_MIPS_GOT_LO16
:
2322 case R_MIPS_CALL_LO16
:
2323 /* Find the index into the GOT where this value is located. */
2326 BFD_ASSERT (addend
== 0);
2327 g
= mips_elf_global_got_index (elf_hash_table (info
)->dynobj
,
2328 (struct elf_link_hash_entry
*) h
);
2329 if (! elf_hash_table(info
)->dynamic_sections_created
2331 && (info
->symbolic
|| h
->root
.dynindx
== -1)
2332 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2334 /* This is a static link or a -Bsymbolic link. The
2335 symbol is defined locally, or was forced to be local.
2336 We must initialize this entry in the GOT. */
2337 bfd
*tmpbfd
= elf_hash_table (info
)->dynobj
;
2338 asection
*sgot
= mips_elf_got_section(tmpbfd
);
2339 MIPS_ELF_PUT_WORD (tmpbfd
, symbol
+ addend
, sgot
->contents
+ g
);
2342 else if (r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS_CALL16
)
2343 /* There's no need to create a local GOT entry here; the
2344 calculation for a local GOT16 entry does not involve G. */
2348 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
2350 return bfd_reloc_outofrange
;
2353 /* Convert GOT indices to actual offsets. */
2354 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2360 case R_MIPS16_GPREL
:
2361 case R_MIPS_GPREL16
:
2362 case R_MIPS_GPREL32
:
2363 case R_MIPS_LITERAL
:
2364 gp0
= _bfd_get_gp_value (input_bfd
);
2365 gp
= _bfd_get_gp_value (abfd
);
2372 /* Figure out what kind of relocation is being performed. */
2376 return bfd_reloc_continue
;
2379 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
2380 overflowed_p
= mips_elf_overflow_p (value
, 16);
2387 || (elf_hash_table (info
)->dynamic_sections_created
2389 && ((h
->root
.elf_link_hash_flags
2390 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
2391 && ((h
->root
.elf_link_hash_flags
2392 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2394 && (input_section
->flags
& SEC_ALLOC
) != 0)
2396 /* If we're creating a shared library, or this relocation is
2397 against a symbol in a shared library, then we can't know
2398 where the symbol will end up. So, we create a relocation
2399 record in the output, and leave the job up to the dynamic
2402 if (!mips_elf_create_dynamic_relocation (abfd
,
2410 return bfd_reloc_undefined
;
2414 if (r_type
!= R_MIPS_REL32
)
2415 value
= symbol
+ addend
;
2419 value
&= howto
->dst_mask
;
2424 case R_MIPS_GNU_REL_LO16
:
2425 value
= symbol
+ addend
- p
;
2426 value
&= howto
->dst_mask
;
2429 case R_MIPS_GNU_REL16_S2
:
2430 value
= symbol
+ mips_elf_sign_extend (addend
<< 2, 18) - p
;
2431 overflowed_p
= mips_elf_overflow_p (value
, 18);
2432 value
= (value
>> 2) & howto
->dst_mask
;
2435 case R_MIPS_GNU_REL_HI16
:
2436 /* Instead of subtracting 'p' here, we should be subtracting the
2437 equivalent value for the LO part of the reloc, since the value
2438 here is relative to that address. Because that's not easy to do,
2439 we adjust 'addend' in _bfd_mips_elf_relocate_section(). See also
2440 the comment there for more information. */
2441 value
= mips_elf_high (addend
+ symbol
- p
);
2442 value
&= howto
->dst_mask
;
2446 /* The calculation for R_MIPS16_26 is just the same as for an
2447 R_MIPS_26. It's only the storage of the relocated field into
2448 the output file that's different. That's handled in
2449 mips_elf_perform_relocation. So, we just fall through to the
2450 R_MIPS_26 case here. */
2453 value
= (((addend
<< 2) | ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
2455 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
2456 value
&= howto
->dst_mask
;
2462 value
= mips_elf_high (addend
+ symbol
);
2463 value
&= howto
->dst_mask
;
2467 value
= mips_elf_high (addend
+ gp
- p
);
2468 overflowed_p
= mips_elf_overflow_p (value
, 16);
2474 value
= (symbol
+ addend
) & howto
->dst_mask
;
2477 value
= addend
+ gp
- p
+ 4;
2478 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
2479 for overflow. But, on, say, IRIX5, relocations against
2480 _gp_disp are normally generated from the .cpload
2481 pseudo-op. It generates code that normally looks like
2484 lui $gp,%hi(_gp_disp)
2485 addiu $gp,$gp,%lo(_gp_disp)
2488 Here $t9 holds the address of the function being called,
2489 as required by the MIPS ELF ABI. The R_MIPS_LO16
2490 relocation can easily overflow in this situation, but the
2491 R_MIPS_HI16 relocation will handle the overflow.
2492 Therefore, we consider this a bug in the MIPS ABI, and do
2493 not check for overflow here. */
2497 case R_MIPS_LITERAL
:
2498 /* Because we don't merge literal sections, we can handle this
2499 just like R_MIPS_GPREL16. In the long run, we should merge
2500 shared literals, and then we will need to additional work
2505 case R_MIPS16_GPREL
:
2506 /* The R_MIPS16_GPREL performs the same calculation as
2507 R_MIPS_GPREL16, but stores the relocated bits in a different
2508 order. We don't need to do anything special here; the
2509 differences are handled in mips_elf_perform_relocation. */
2510 case R_MIPS_GPREL16
:
2511 /* Only sign-extend the addend if it was extracted from the
2512 instruction. If the addend was separate, leave it alone,
2513 otherwise we may lose significant bits. */
2514 if (howto
->partial_inplace
)
2515 addend
= mips_elf_sign_extend (addend
, 16);
2516 value
= symbol
+ addend
- gp
;
2517 /* If the symbol was local, any earlier relocatable links will
2518 have adjusted its addend with the gp offset, so compensate
2519 for that now. Don't do it for symbols forced local in this
2520 link, though, since they won't have had the gp offset applied
2524 overflowed_p
= mips_elf_overflow_p (value
, 16);
2533 /* The special case is when the symbol is forced to be local. We
2534 need the full address in the GOT since no R_MIPS_LO16 relocation
2536 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
2537 local_sections
, FALSE
);
2538 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
, forced
);
2539 if (value
== MINUS_ONE
)
2540 return bfd_reloc_outofrange
;
2542 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2544 overflowed_p
= mips_elf_overflow_p (value
, 16);
2550 case R_MIPS_GOT_DISP
:
2552 overflowed_p
= mips_elf_overflow_p (value
, 16);
2555 case R_MIPS_GPREL32
:
2556 value
= (addend
+ symbol
+ gp0
- gp
);
2558 value
&= howto
->dst_mask
;
2562 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
2563 overflowed_p
= mips_elf_overflow_p (value
, 16);
2566 case R_MIPS_GOT_HI16
:
2567 case R_MIPS_CALL_HI16
:
2568 /* We're allowed to handle these two relocations identically.
2569 The dynamic linker is allowed to handle the CALL relocations
2570 differently by creating a lazy evaluation stub. */
2572 value
= mips_elf_high (value
);
2573 value
&= howto
->dst_mask
;
2576 case R_MIPS_GOT_LO16
:
2577 case R_MIPS_CALL_LO16
:
2578 value
= g
& howto
->dst_mask
;
2581 case R_MIPS_GOT_PAGE
:
2582 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
2583 if (value
== MINUS_ONE
)
2584 return bfd_reloc_outofrange
;
2585 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2587 overflowed_p
= mips_elf_overflow_p (value
, 16);
2590 case R_MIPS_GOT_OFST
:
2591 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
2592 overflowed_p
= mips_elf_overflow_p (value
, 16);
2596 value
= symbol
- addend
;
2597 value
&= howto
->dst_mask
;
2601 value
= mips_elf_higher (addend
+ symbol
);
2602 value
&= howto
->dst_mask
;
2605 case R_MIPS_HIGHEST
:
2606 value
= mips_elf_highest (addend
+ symbol
);
2607 value
&= howto
->dst_mask
;
2610 case R_MIPS_SCN_DISP
:
2611 value
= symbol
+ addend
- sec
->output_offset
;
2612 value
&= howto
->dst_mask
;
2617 /* Both of these may be ignored. R_MIPS_JALR is an optimization
2618 hint; we could improve performance by honoring that hint. */
2619 return bfd_reloc_continue
;
2621 case R_MIPS_GNU_VTINHERIT
:
2622 case R_MIPS_GNU_VTENTRY
:
2623 /* We don't do anything with these at present. */
2624 return bfd_reloc_continue
;
2627 /* An unrecognized relocation type. */
2628 return bfd_reloc_notsupported
;
2631 /* Store the VALUE for our caller. */
2633 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
2636 /* Obtain the field relocated by RELOCATION. */
2639 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
2640 reloc_howto_type
*howto
;
2641 const Elf_Internal_Rela
*relocation
;
2646 bfd_byte
*location
= contents
+ relocation
->r_offset
;
2648 /* Obtain the bytes. */
2649 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
2651 if ((ELF_R_TYPE (input_bfd
, relocation
->r_info
) == R_MIPS16_26
2652 || ELF_R_TYPE (input_bfd
, relocation
->r_info
) == R_MIPS16_GPREL
)
2653 && bfd_little_endian (input_bfd
))
2654 /* The two 16-bit words will be reversed on a little-endian system.
2655 See mips_elf_perform_relocation for more details. */
2656 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
2661 /* It has been determined that the result of the RELOCATION is the
2662 VALUE. Use HOWTO to place VALUE into the output file at the
2663 appropriate position. The SECTION is the section to which the
2664 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
2665 for the relocation must be either JAL or JALX, and it is
2666 unconditionally converted to JALX.
2668 Returns FALSE if anything goes wrong. */
2671 mips_elf_perform_relocation (info
, howto
, relocation
, value
, input_bfd
,
2672 input_section
, contents
, require_jalx
)
2673 struct bfd_link_info
*info
;
2674 reloc_howto_type
*howto
;
2675 const Elf_Internal_Rela
*relocation
;
2678 asection
*input_section
;
2680 bfd_boolean require_jalx
;
2684 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
2686 /* Figure out where the relocation is occurring. */
2687 location
= contents
+ relocation
->r_offset
;
2689 /* Obtain the current value. */
2690 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
2692 /* Clear the field we are setting. */
2693 x
&= ~howto
->dst_mask
;
2695 /* If this is the R_MIPS16_26 relocation, we must store the
2696 value in a funny way. */
2697 if (r_type
== R_MIPS16_26
)
2699 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
2700 Most mips16 instructions are 16 bits, but these instructions
2703 The format of these instructions is:
2705 +--------------+--------------------------------+
2706 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
2707 +--------------+--------------------------------+
2709 +-----------------------------------------------+
2711 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
2712 Note that the immediate value in the first word is swapped.
2714 When producing a relocateable object file, R_MIPS16_26 is
2715 handled mostly like R_MIPS_26. In particular, the addend is
2716 stored as a straight 26-bit value in a 32-bit instruction.
2717 (gas makes life simpler for itself by never adjusting a
2718 R_MIPS16_26 reloc to be against a section, so the addend is
2719 always zero). However, the 32 bit instruction is stored as 2
2720 16-bit values, rather than a single 32-bit value. In a
2721 big-endian file, the result is the same; in a little-endian
2722 file, the two 16-bit halves of the 32 bit value are swapped.
2723 This is so that a disassembler can recognize the jal
2726 When doing a final link, R_MIPS16_26 is treated as a 32 bit
2727 instruction stored as two 16-bit values. The addend A is the
2728 contents of the targ26 field. The calculation is the same as
2729 R_MIPS_26. When storing the calculated value, reorder the
2730 immediate value as shown above, and don't forget to store the
2731 value as two 16-bit values.
2733 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
2737 +--------+----------------------+
2741 +--------+----------------------+
2744 +----------+------+-------------+
2748 +----------+--------------------+
2749 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
2750 ((sub1 << 16) | sub2)).
2752 When producing a relocateable object file, the calculation is
2753 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2754 When producing a fully linked file, the calculation is
2755 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2756 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
2758 if (!info
->relocateable
)
2759 /* Shuffle the bits according to the formula above. */
2760 value
= (((value
& 0x1f0000) << 5)
2761 | ((value
& 0x3e00000) >> 5)
2762 | (value
& 0xffff));
2764 else if (r_type
== R_MIPS16_GPREL
)
2766 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
2767 mode. A typical instruction will have a format like this:
2769 +--------------+--------------------------------+
2770 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
2771 +--------------+--------------------------------+
2772 ! Major ! rx ! ry ! Imm 4:0 !
2773 +--------------+--------------------------------+
2775 EXTEND is the five bit value 11110. Major is the instruction
2778 This is handled exactly like R_MIPS_GPREL16, except that the
2779 addend is retrieved and stored as shown in this diagram; that
2780 is, the Imm fields above replace the V-rel16 field.
2782 All we need to do here is shuffle the bits appropriately. As
2783 above, the two 16-bit halves must be swapped on a
2784 little-endian system. */
2785 value
= (((value
& 0x7e0) << 16)
2786 | ((value
& 0xf800) << 5)
2790 /* Set the field. */
2791 x
|= (value
& howto
->dst_mask
);
2793 /* If required, turn JAL into JALX. */
2797 bfd_vma opcode
= x
>> 26;
2798 bfd_vma jalx_opcode
;
2800 /* Check to see if the opcode is already JAL or JALX. */
2801 if (r_type
== R_MIPS16_26
)
2803 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
2808 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
2812 /* If the opcode is not JAL or JALX, there's a problem. */
2815 (*_bfd_error_handler
)
2816 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
2817 bfd_archive_filename (input_bfd
),
2818 input_section
->name
,
2819 (unsigned long) relocation
->r_offset
);
2820 bfd_set_error (bfd_error_bad_value
);
2824 /* Make this the JALX opcode. */
2825 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
2828 /* Swap the high- and low-order 16 bits on little-endian systems
2829 when doing a MIPS16 relocation. */
2830 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
2831 && bfd_little_endian (input_bfd
))
2832 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
2834 /* Put the value into the output. */
2835 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
2839 /* Returns TRUE if SECTION is a MIPS16 stub section. */
2842 mips_elf_stub_section_p (abfd
, section
)
2843 bfd
*abfd ATTRIBUTE_UNUSED
;
2846 const char *name
= bfd_get_section_name (abfd
, section
);
2848 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
2849 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
2850 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
2853 /* Add room for N relocations to the .rel.dyn section in ABFD. */
2856 mips_elf_allocate_dynamic_relocations (abfd
, n
)
2862 s
= bfd_get_section_by_name (abfd
, ".rel.dyn");
2863 BFD_ASSERT (s
!= NULL
);
2865 if (s
->_raw_size
== 0)
2867 /* Make room for a null element. */
2868 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
2871 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
2874 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
2875 is the original relocation, which is now being transformed into a
2876 dynamic relocation. The ADDENDP is adjusted if necessary; the
2877 caller should store the result in place of the original addend. */
2880 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
, sec
,
2881 symbol
, addendp
, input_section
)
2883 struct bfd_link_info
*info
;
2884 const Elf_Internal_Rela
*rel
;
2885 struct mips_elf_link_hash_entry
*h
;
2889 asection
*input_section
;
2891 Elf_Internal_Rela outrel
[3];
2897 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
2898 dynobj
= elf_hash_table (info
)->dynobj
;
2899 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
2900 BFD_ASSERT (sreloc
!= NULL
);
2901 BFD_ASSERT (sreloc
->contents
!= NULL
);
2902 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
2903 < sreloc
->_raw_size
);
2906 outrel
[0].r_offset
=
2907 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
2908 outrel
[1].r_offset
=
2909 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
2910 outrel
[2].r_offset
=
2911 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
2914 /* We begin by assuming that the offset for the dynamic relocation
2915 is the same as for the original relocation. We'll adjust this
2916 later to reflect the correct output offsets. */
2917 if (elf_section_data (input_section
)->sec_info_type
!= ELF_INFO_TYPE_STABS
)
2919 outrel
[1].r_offset
= rel
[1].r_offset
;
2920 outrel
[2].r_offset
= rel
[2].r_offset
;
2924 /* Except that in a stab section things are more complex.
2925 Because we compress stab information, the offset given in the
2926 relocation may not be the one we want; we must let the stabs
2927 machinery tell us the offset. */
2928 outrel
[1].r_offset
= outrel
[0].r_offset
;
2929 outrel
[2].r_offset
= outrel
[0].r_offset
;
2930 /* If we didn't need the relocation at all, this value will be
2932 if (outrel
[0].r_offset
== (bfd_vma
) -1)
2937 if (outrel
[0].r_offset
== (bfd_vma
) -1)
2939 /* FIXME: For -2 runtime relocation needs to be skipped, but
2940 properly resolved statically and installed. */
2941 BFD_ASSERT (outrel
[0].r_offset
!= (bfd_vma
) -2);
2943 /* If we've decided to skip this relocation, just output an empty
2944 record. Note that R_MIPS_NONE == 0, so that this call to memset
2945 is a way of setting R_TYPE to R_MIPS_NONE. */
2947 memset (outrel
, 0, sizeof (Elf_Internal_Rela
) * 3);
2951 bfd_vma section_offset
;
2953 /* We must now calculate the dynamic symbol table index to use
2954 in the relocation. */
2956 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
2957 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2959 indx
= h
->root
.dynindx
;
2960 /* h->root.dynindx may be -1 if this symbol was marked to
2967 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
2969 else if (sec
== NULL
|| sec
->owner
== NULL
)
2971 bfd_set_error (bfd_error_bad_value
);
2976 indx
= elf_section_data (sec
->output_section
)->dynindx
;
2981 /* Figure out how far the target of the relocation is from
2982 the beginning of its section. */
2983 section_offset
= symbol
- sec
->output_section
->vma
;
2984 /* The relocation we're building is section-relative.
2985 Therefore, the original addend must be adjusted by the
2987 *addendp
+= section_offset
;
2988 /* Now, the relocation is just against the section. */
2989 symbol
= sec
->output_section
->vma
;
2992 /* If the relocation was previously an absolute relocation and
2993 this symbol will not be referred to by the relocation, we must
2994 adjust it by the value we give it in the dynamic symbol table.
2995 Otherwise leave the job up to the dynamic linker. */
2996 if (!indx
&& r_type
!= R_MIPS_REL32
)
2999 /* The relocation is always an REL32 relocation because we don't
3000 know where the shared library will wind up at load-time. */
3001 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
3003 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) 0,
3004 ABI_64_P (output_bfd
)
3007 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) 0,
3010 /* Adjust the output offset of the relocation to reference the
3011 correct location in the output file. */
3012 outrel
[0].r_offset
+= (input_section
->output_section
->vma
3013 + input_section
->output_offset
);
3014 outrel
[1].r_offset
+= (input_section
->output_section
->vma
3015 + input_section
->output_offset
);
3016 outrel
[2].r_offset
+= (input_section
->output_section
->vma
3017 + input_section
->output_offset
);
3020 /* Put the relocation back out. We have to use the special
3021 relocation outputter in the 64-bit case since the 64-bit
3022 relocation format is non-standard. */
3023 if (ABI_64_P (output_bfd
))
3025 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
3026 (output_bfd
, &outrel
[0],
3028 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
3031 bfd_elf32_swap_reloc_out
3032 (output_bfd
, &outrel
[0],
3033 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
3035 /* Record the index of the first relocation referencing H. This
3036 information is later emitted in the .msym section. */
3038 && (h
->min_dyn_reloc_index
== 0
3039 || sreloc
->reloc_count
< h
->min_dyn_reloc_index
))
3040 h
->min_dyn_reloc_index
= sreloc
->reloc_count
;
3042 /* We've now added another relocation. */
3043 ++sreloc
->reloc_count
;
3045 /* Make sure the output section is writable. The dynamic linker
3046 will be writing to it. */
3047 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
3050 /* On IRIX5, make an entry of compact relocation info. */
3051 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
3053 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
3058 Elf32_crinfo cptrel
;
3060 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
3061 cptrel
.vaddr
= (rel
->r_offset
3062 + input_section
->output_section
->vma
3063 + input_section
->output_offset
);
3064 if (r_type
== R_MIPS_REL32
)
3065 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
3067 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
3068 mips_elf_set_cr_dist2to (cptrel
, 0);
3069 cptrel
.konst
= *addendp
;
3071 cr
= (scpt
->contents
3072 + sizeof (Elf32_External_compact_rel
));
3073 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
3074 ((Elf32_External_crinfo
*) cr
3075 + scpt
->reloc_count
));
3076 ++scpt
->reloc_count
;
3083 /* Return the ISA for a MIPS e_flags value. */
3086 elf_mips_isa (flags
)
3089 switch (flags
& EF_MIPS_ARCH
)
3101 case E_MIPS_ARCH_32
:
3103 case E_MIPS_ARCH_64
:
3109 /* Return the MACH for a MIPS e_flags value. */
3112 _bfd_elf_mips_mach (flags
)
3115 switch (flags
& EF_MIPS_MACH
)
3117 case E_MIPS_MACH_3900
:
3118 return bfd_mach_mips3900
;
3120 case E_MIPS_MACH_4010
:
3121 return bfd_mach_mips4010
;
3123 case E_MIPS_MACH_4100
:
3124 return bfd_mach_mips4100
;
3126 case E_MIPS_MACH_4111
:
3127 return bfd_mach_mips4111
;
3129 case E_MIPS_MACH_4120
:
3130 return bfd_mach_mips4120
;
3132 case E_MIPS_MACH_4650
:
3133 return bfd_mach_mips4650
;
3135 case E_MIPS_MACH_5400
:
3136 return bfd_mach_mips5400
;
3138 case E_MIPS_MACH_5500
:
3139 return bfd_mach_mips5500
;
3141 case E_MIPS_MACH_SB1
:
3142 return bfd_mach_mips_sb1
;
3145 switch (flags
& EF_MIPS_ARCH
)
3149 return bfd_mach_mips3000
;
3153 return bfd_mach_mips6000
;
3157 return bfd_mach_mips4000
;
3161 return bfd_mach_mips8000
;
3165 return bfd_mach_mips5
;
3168 case E_MIPS_ARCH_32
:
3169 return bfd_mach_mipsisa32
;
3172 case E_MIPS_ARCH_64
:
3173 return bfd_mach_mipsisa64
;
3181 /* Return printable name for ABI. */
3183 static INLINE
char *
3184 elf_mips_abi_name (abfd
)
3189 flags
= elf_elfheader (abfd
)->e_flags
;
3190 switch (flags
& EF_MIPS_ABI
)
3193 if (ABI_N32_P (abfd
))
3195 else if (ABI_64_P (abfd
))
3199 case E_MIPS_ABI_O32
:
3201 case E_MIPS_ABI_O64
:
3203 case E_MIPS_ABI_EABI32
:
3205 case E_MIPS_ABI_EABI64
:
3208 return "unknown abi";
3212 /* MIPS ELF uses two common sections. One is the usual one, and the
3213 other is for small objects. All the small objects are kept
3214 together, and then referenced via the gp pointer, which yields
3215 faster assembler code. This is what we use for the small common
3216 section. This approach is copied from ecoff.c. */
3217 static asection mips_elf_scom_section
;
3218 static asymbol mips_elf_scom_symbol
;
3219 static asymbol
*mips_elf_scom_symbol_ptr
;
3221 /* MIPS ELF also uses an acommon section, which represents an
3222 allocated common symbol which may be overridden by a
3223 definition in a shared library. */
3224 static asection mips_elf_acom_section
;
3225 static asymbol mips_elf_acom_symbol
;
3226 static asymbol
*mips_elf_acom_symbol_ptr
;
3228 /* Handle the special MIPS section numbers that a symbol may use.
3229 This is used for both the 32-bit and the 64-bit ABI. */
3232 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3236 elf_symbol_type
*elfsym
;
3238 elfsym
= (elf_symbol_type
*) asym
;
3239 switch (elfsym
->internal_elf_sym
.st_shndx
)
3241 case SHN_MIPS_ACOMMON
:
3242 /* This section is used in a dynamically linked executable file.
3243 It is an allocated common section. The dynamic linker can
3244 either resolve these symbols to something in a shared
3245 library, or it can just leave them here. For our purposes,
3246 we can consider these symbols to be in a new section. */
3247 if (mips_elf_acom_section
.name
== NULL
)
3249 /* Initialize the acommon section. */
3250 mips_elf_acom_section
.name
= ".acommon";
3251 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3252 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3253 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3254 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3255 mips_elf_acom_symbol
.name
= ".acommon";
3256 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3257 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3258 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3260 asym
->section
= &mips_elf_acom_section
;
3264 /* Common symbols less than the GP size are automatically
3265 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3266 if (asym
->value
> elf_gp_size (abfd
)
3267 || IRIX_COMPAT (abfd
) == ict_irix6
)
3270 case SHN_MIPS_SCOMMON
:
3271 if (mips_elf_scom_section
.name
== NULL
)
3273 /* Initialize the small common section. */
3274 mips_elf_scom_section
.name
= ".scommon";
3275 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3276 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3277 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3278 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3279 mips_elf_scom_symbol
.name
= ".scommon";
3280 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3281 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3282 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3284 asym
->section
= &mips_elf_scom_section
;
3285 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3288 case SHN_MIPS_SUNDEFINED
:
3289 asym
->section
= bfd_und_section_ptr
;
3292 #if 0 /* for SGI_COMPAT */
3294 asym
->section
= mips_elf_text_section_ptr
;
3298 asym
->section
= mips_elf_data_section_ptr
;
3304 /* Work over a section just before writing it out. This routine is
3305 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3306 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3310 _bfd_mips_elf_section_processing (abfd
, hdr
)
3312 Elf_Internal_Shdr
*hdr
;
3314 if (hdr
->sh_type
== SHT_MIPS_REGINFO
3315 && hdr
->sh_size
> 0)
3319 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
3320 BFD_ASSERT (hdr
->contents
== NULL
);
3323 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
3326 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3327 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3331 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
3332 && hdr
->bfd_section
!= NULL
3333 && elf_section_data (hdr
->bfd_section
) != NULL
3334 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
3336 bfd_byte
*contents
, *l
, *lend
;
3338 /* We stored the section contents in the elf_section_data tdata
3339 field in the set_section_contents routine. We save the
3340 section contents so that we don't have to read them again.
3341 At this point we know that elf_gp is set, so we can look
3342 through the section contents to see if there is an
3343 ODK_REGINFO structure. */
3345 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
3347 lend
= contents
+ hdr
->sh_size
;
3348 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3350 Elf_Internal_Options intopt
;
3352 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3354 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3361 + sizeof (Elf_External_Options
)
3362 + (sizeof (Elf64_External_RegInfo
) - 8)),
3365 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
3366 if (bfd_bwrite (buf
, (bfd_size_type
) 8, abfd
) != 8)
3369 else if (intopt
.kind
== ODK_REGINFO
)
3376 + sizeof (Elf_External_Options
)
3377 + (sizeof (Elf32_External_RegInfo
) - 4)),
3380 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3381 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3388 if (hdr
->bfd_section
!= NULL
)
3390 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3392 if (strcmp (name
, ".sdata") == 0
3393 || strcmp (name
, ".lit8") == 0
3394 || strcmp (name
, ".lit4") == 0)
3396 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3397 hdr
->sh_type
= SHT_PROGBITS
;
3399 else if (strcmp (name
, ".sbss") == 0)
3401 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3402 hdr
->sh_type
= SHT_NOBITS
;
3404 else if (strcmp (name
, ".srdata") == 0)
3406 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
3407 hdr
->sh_type
= SHT_PROGBITS
;
3409 else if (strcmp (name
, ".compact_rel") == 0)
3412 hdr
->sh_type
= SHT_PROGBITS
;
3414 else if (strcmp (name
, ".rtproc") == 0)
3416 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
3418 unsigned int adjust
;
3420 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
3422 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
3430 /* Handle a MIPS specific section when reading an object file. This
3431 is called when elfcode.h finds a section with an unknown type.
3432 This routine supports both the 32-bit and 64-bit ELF ABI.
3434 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
3438 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
3440 Elf_Internal_Shdr
*hdr
;
3445 /* There ought to be a place to keep ELF backend specific flags, but
3446 at the moment there isn't one. We just keep track of the
3447 sections by their name, instead. Fortunately, the ABI gives
3448 suggested names for all the MIPS specific sections, so we will
3449 probably get away with this. */
3450 switch (hdr
->sh_type
)
3452 case SHT_MIPS_LIBLIST
:
3453 if (strcmp (name
, ".liblist") != 0)
3457 if (strcmp (name
, ".msym") != 0)
3460 case SHT_MIPS_CONFLICT
:
3461 if (strcmp (name
, ".conflict") != 0)
3464 case SHT_MIPS_GPTAB
:
3465 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
3468 case SHT_MIPS_UCODE
:
3469 if (strcmp (name
, ".ucode") != 0)
3472 case SHT_MIPS_DEBUG
:
3473 if (strcmp (name
, ".mdebug") != 0)
3475 flags
= SEC_DEBUGGING
;
3477 case SHT_MIPS_REGINFO
:
3478 if (strcmp (name
, ".reginfo") != 0
3479 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
3481 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
3483 case SHT_MIPS_IFACE
:
3484 if (strcmp (name
, ".MIPS.interfaces") != 0)
3487 case SHT_MIPS_CONTENT
:
3488 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
3491 case SHT_MIPS_OPTIONS
:
3492 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
3495 case SHT_MIPS_DWARF
:
3496 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
3499 case SHT_MIPS_SYMBOL_LIB
:
3500 if (strcmp (name
, ".MIPS.symlib") != 0)
3503 case SHT_MIPS_EVENTS
:
3504 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
3505 && strncmp (name
, ".MIPS.post_rel",
3506 sizeof ".MIPS.post_rel" - 1) != 0)
3513 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
3518 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
3519 (bfd_get_section_flags (abfd
,
3525 /* FIXME: We should record sh_info for a .gptab section. */
3527 /* For a .reginfo section, set the gp value in the tdata information
3528 from the contents of this section. We need the gp value while
3529 processing relocs, so we just get it now. The .reginfo section
3530 is not used in the 64-bit MIPS ELF ABI. */
3531 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
3533 Elf32_External_RegInfo ext
;
3536 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
3538 (bfd_size_type
) sizeof ext
))
3540 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
3541 elf_gp (abfd
) = s
.ri_gp_value
;
3544 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
3545 set the gp value based on what we find. We may see both
3546 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
3547 they should agree. */
3548 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
3550 bfd_byte
*contents
, *l
, *lend
;
3552 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
3553 if (contents
== NULL
)
3555 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
3556 (file_ptr
) 0, hdr
->sh_size
))
3562 lend
= contents
+ hdr
->sh_size
;
3563 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3565 Elf_Internal_Options intopt
;
3567 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3569 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3571 Elf64_Internal_RegInfo intreg
;
3573 bfd_mips_elf64_swap_reginfo_in
3575 ((Elf64_External_RegInfo
*)
3576 (l
+ sizeof (Elf_External_Options
))),
3578 elf_gp (abfd
) = intreg
.ri_gp_value
;
3580 else if (intopt
.kind
== ODK_REGINFO
)
3582 Elf32_RegInfo intreg
;
3584 bfd_mips_elf32_swap_reginfo_in
3586 ((Elf32_External_RegInfo
*)
3587 (l
+ sizeof (Elf_External_Options
))),
3589 elf_gp (abfd
) = intreg
.ri_gp_value
;
3599 /* Set the correct type for a MIPS ELF section. We do this by the
3600 section name, which is a hack, but ought to work. This routine is
3601 used by both the 32-bit and the 64-bit ABI. */
3604 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
3606 Elf_Internal_Shdr
*hdr
;
3609 register const char *name
;
3611 name
= bfd_get_section_name (abfd
, sec
);
3613 if (strcmp (name
, ".liblist") == 0)
3615 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
3616 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
3617 /* The sh_link field is set in final_write_processing. */
3619 else if (strcmp (name
, ".conflict") == 0)
3620 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
3621 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3623 hdr
->sh_type
= SHT_MIPS_GPTAB
;
3624 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
3625 /* The sh_info field is set in final_write_processing. */
3627 else if (strcmp (name
, ".ucode") == 0)
3628 hdr
->sh_type
= SHT_MIPS_UCODE
;
3629 else if (strcmp (name
, ".mdebug") == 0)
3631 hdr
->sh_type
= SHT_MIPS_DEBUG
;
3632 /* In a shared object on IRIX 5.3, the .mdebug section has an
3633 entsize of 0. FIXME: Does this matter? */
3634 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
3635 hdr
->sh_entsize
= 0;
3637 hdr
->sh_entsize
= 1;
3639 else if (strcmp (name
, ".reginfo") == 0)
3641 hdr
->sh_type
= SHT_MIPS_REGINFO
;
3642 /* In a shared object on IRIX 5.3, the .reginfo section has an
3643 entsize of 0x18. FIXME: Does this matter? */
3644 if (SGI_COMPAT (abfd
))
3646 if ((abfd
->flags
& DYNAMIC
) != 0)
3647 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3649 hdr
->sh_entsize
= 1;
3652 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3654 else if (SGI_COMPAT (abfd
)
3655 && (strcmp (name
, ".hash") == 0
3656 || strcmp (name
, ".dynamic") == 0
3657 || strcmp (name
, ".dynstr") == 0))
3659 if (SGI_COMPAT (abfd
))
3660 hdr
->sh_entsize
= 0;
3662 /* This isn't how the IRIX6 linker behaves. */
3663 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
3666 else if (strcmp (name
, ".got") == 0
3667 || strcmp (name
, ".srdata") == 0
3668 || strcmp (name
, ".sdata") == 0
3669 || strcmp (name
, ".sbss") == 0
3670 || strcmp (name
, ".lit4") == 0
3671 || strcmp (name
, ".lit8") == 0)
3672 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
3673 else if (strcmp (name
, ".MIPS.interfaces") == 0)
3675 hdr
->sh_type
= SHT_MIPS_IFACE
;
3676 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3678 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
3680 hdr
->sh_type
= SHT_MIPS_CONTENT
;
3681 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3682 /* The sh_info field is set in final_write_processing. */
3684 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3686 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
3687 hdr
->sh_entsize
= 1;
3688 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3690 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
3691 hdr
->sh_type
= SHT_MIPS_DWARF
;
3692 else if (strcmp (name
, ".MIPS.symlib") == 0)
3694 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
3695 /* The sh_link and sh_info fields are set in
3696 final_write_processing. */
3698 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
3699 || strncmp (name
, ".MIPS.post_rel",
3700 sizeof ".MIPS.post_rel" - 1) == 0)
3702 hdr
->sh_type
= SHT_MIPS_EVENTS
;
3703 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3704 /* The sh_link field is set in final_write_processing. */
3706 else if (strcmp (name
, ".msym") == 0)
3708 hdr
->sh_type
= SHT_MIPS_MSYM
;
3709 hdr
->sh_flags
|= SHF_ALLOC
;
3710 hdr
->sh_entsize
= 8;
3713 /* The generic elf_fake_sections will set up REL_HDR using the
3714 default kind of relocations. But, we may actually need both
3715 kinds of relocations, so we set up the second header here.
3717 This is not necessary for the O32 ABI since that only uses Elf32_Rel
3718 relocations (cf. System V ABI, MIPS RISC Processor Supplement,
3719 3rd Edition, p. 4-17). It breaks the IRIX 5/6 32-bit ld, since one
3720 of the resulting empty .rela.<section> sections starts with
3721 sh_offset == object size, and ld doesn't allow that. While the check
3722 is arguably bogus for empty or SHT_NOBITS sections, it can easily be
3723 avoided by not emitting those useless sections in the first place. */
3724 if (! SGI_COMPAT (abfd
) && ! NEWABI_P(abfd
)
3725 && (sec
->flags
& SEC_RELOC
) != 0)
3727 struct bfd_elf_section_data
*esd
;
3728 bfd_size_type amt
= sizeof (Elf_Internal_Shdr
);
3730 esd
= elf_section_data (sec
);
3731 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
3732 esd
->rel_hdr2
= (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, amt
);
3735 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
3736 !elf_section_data (sec
)->use_rela_p
);
3742 /* Given a BFD section, try to locate the corresponding ELF section
3743 index. This is used by both the 32-bit and the 64-bit ABI.
3744 Actually, it's not clear to me that the 64-bit ABI supports these,
3745 but for non-PIC objects we will certainly want support for at least
3746 the .scommon section. */
3749 _bfd_mips_elf_section_from_bfd_section (abfd
, sec
, retval
)
3750 bfd
*abfd ATTRIBUTE_UNUSED
;
3754 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3756 *retval
= SHN_MIPS_SCOMMON
;
3759 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
3761 *retval
= SHN_MIPS_ACOMMON
;
3767 /* Hook called by the linker routine which adds symbols from an object
3768 file. We must handle the special MIPS section numbers here. */
3771 _bfd_mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3773 struct bfd_link_info
*info
;
3774 const Elf_Internal_Sym
*sym
;
3776 flagword
*flagsp ATTRIBUTE_UNUSED
;
3780 if (SGI_COMPAT (abfd
)
3781 && (abfd
->flags
& DYNAMIC
) != 0
3782 && strcmp (*namep
, "_rld_new_interface") == 0)
3784 /* Skip IRIX5 rld entry name. */
3789 switch (sym
->st_shndx
)
3792 /* Common symbols less than the GP size are automatically
3793 treated as SHN_MIPS_SCOMMON symbols. */
3794 if (sym
->st_size
> elf_gp_size (abfd
)
3795 || IRIX_COMPAT (abfd
) == ict_irix6
)
3798 case SHN_MIPS_SCOMMON
:
3799 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3800 (*secp
)->flags
|= SEC_IS_COMMON
;
3801 *valp
= sym
->st_size
;
3805 /* This section is used in a shared object. */
3806 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
3808 asymbol
*elf_text_symbol
;
3809 asection
*elf_text_section
;
3810 bfd_size_type amt
= sizeof (asection
);
3812 elf_text_section
= bfd_zalloc (abfd
, amt
);
3813 if (elf_text_section
== NULL
)
3816 amt
= sizeof (asymbol
);
3817 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
3818 if (elf_text_symbol
== NULL
)
3821 /* Initialize the section. */
3823 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
3824 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
3826 elf_text_section
->symbol
= elf_text_symbol
;
3827 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
3829 elf_text_section
->name
= ".text";
3830 elf_text_section
->flags
= SEC_NO_FLAGS
;
3831 elf_text_section
->output_section
= NULL
;
3832 elf_text_section
->owner
= abfd
;
3833 elf_text_symbol
->name
= ".text";
3834 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
3835 elf_text_symbol
->section
= elf_text_section
;
3837 /* This code used to do *secp = bfd_und_section_ptr if
3838 info->shared. I don't know why, and that doesn't make sense,
3839 so I took it out. */
3840 *secp
= elf_tdata (abfd
)->elf_text_section
;
3843 case SHN_MIPS_ACOMMON
:
3844 /* Fall through. XXX Can we treat this as allocated data? */
3846 /* This section is used in a shared object. */
3847 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
3849 asymbol
*elf_data_symbol
;
3850 asection
*elf_data_section
;
3851 bfd_size_type amt
= sizeof (asection
);
3853 elf_data_section
= bfd_zalloc (abfd
, amt
);
3854 if (elf_data_section
== NULL
)
3857 amt
= sizeof (asymbol
);
3858 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
3859 if (elf_data_symbol
== NULL
)
3862 /* Initialize the section. */
3864 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
3865 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
3867 elf_data_section
->symbol
= elf_data_symbol
;
3868 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
3870 elf_data_section
->name
= ".data";
3871 elf_data_section
->flags
= SEC_NO_FLAGS
;
3872 elf_data_section
->output_section
= NULL
;
3873 elf_data_section
->owner
= abfd
;
3874 elf_data_symbol
->name
= ".data";
3875 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
3876 elf_data_symbol
->section
= elf_data_section
;
3878 /* This code used to do *secp = bfd_und_section_ptr if
3879 info->shared. I don't know why, and that doesn't make sense,
3880 so I took it out. */
3881 *secp
= elf_tdata (abfd
)->elf_data_section
;
3884 case SHN_MIPS_SUNDEFINED
:
3885 *secp
= bfd_und_section_ptr
;
3889 if (SGI_COMPAT (abfd
)
3891 && info
->hash
->creator
== abfd
->xvec
3892 && strcmp (*namep
, "__rld_obj_head") == 0)
3894 struct elf_link_hash_entry
*h
;
3895 struct bfd_link_hash_entry
*bh
;
3897 /* Mark __rld_obj_head as dynamic. */
3899 if (! (_bfd_generic_link_add_one_symbol
3900 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3901 (bfd_vma
) *valp
, (const char *) NULL
, FALSE
,
3902 get_elf_backend_data (abfd
)->collect
, &bh
)))
3905 h
= (struct elf_link_hash_entry
*) bh
;
3906 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3907 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3908 h
->type
= STT_OBJECT
;
3910 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3913 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
3916 /* If this is a mips16 text symbol, add 1 to the value to make it
3917 odd. This will cause something like .word SYM to come up with
3918 the right value when it is loaded into the PC. */
3919 if (sym
->st_other
== STO_MIPS16
)
3925 /* This hook function is called before the linker writes out a global
3926 symbol. We mark symbols as small common if appropriate. This is
3927 also where we undo the increment of the value for a mips16 symbol. */
3930 _bfd_mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
3931 bfd
*abfd ATTRIBUTE_UNUSED
;
3932 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3933 const char *name ATTRIBUTE_UNUSED
;
3934 Elf_Internal_Sym
*sym
;
3935 asection
*input_sec
;
3937 /* If we see a common symbol, which implies a relocatable link, then
3938 if a symbol was small common in an input file, mark it as small
3939 common in the output file. */
3940 if (sym
->st_shndx
== SHN_COMMON
3941 && strcmp (input_sec
->name
, ".scommon") == 0)
3942 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
3944 if (sym
->st_other
== STO_MIPS16
3945 && (sym
->st_value
& 1) != 0)
3951 /* Functions for the dynamic linker. */
3953 /* Create dynamic sections when linking against a dynamic object. */
3956 _bfd_mips_elf_create_dynamic_sections (abfd
, info
)
3958 struct bfd_link_info
*info
;
3960 struct elf_link_hash_entry
*h
;
3961 struct bfd_link_hash_entry
*bh
;
3963 register asection
*s
;
3964 const char * const *namep
;
3966 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3967 | SEC_LINKER_CREATED
| SEC_READONLY
);
3969 /* Mips ABI requests the .dynamic section to be read only. */
3970 s
= bfd_get_section_by_name (abfd
, ".dynamic");
3973 if (! bfd_set_section_flags (abfd
, s
, flags
))
3977 /* We need to create .got section. */
3978 if (! mips_elf_create_got_section (abfd
, info
))
3981 /* Create the .msym section on IRIX6. It is used by the dynamic
3982 linker to speed up dynamic relocations, and to avoid computing
3983 the ELF hash for symbols. */
3984 if (IRIX_COMPAT (abfd
) == ict_irix6
3985 && !mips_elf_create_msym_section (abfd
))
3988 /* Create .stub section. */
3989 if (bfd_get_section_by_name (abfd
,
3990 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
3992 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
3994 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
3995 || ! bfd_set_section_alignment (abfd
, s
,
3996 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4000 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
4002 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
4004 s
= bfd_make_section (abfd
, ".rld_map");
4006 || ! bfd_set_section_flags (abfd
, s
, flags
&~ (flagword
) SEC_READONLY
)
4007 || ! bfd_set_section_alignment (abfd
, s
,
4008 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4012 /* On IRIX5, we adjust add some additional symbols and change the
4013 alignments of several sections. There is no ABI documentation
4014 indicating that this is necessary on IRIX6, nor any evidence that
4015 the linker takes such action. */
4016 if (IRIX_COMPAT (abfd
) == ict_irix5
)
4018 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
4021 if (! (_bfd_generic_link_add_one_symbol
4022 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
4023 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
4024 get_elf_backend_data (abfd
)->collect
, &bh
)))
4027 h
= (struct elf_link_hash_entry
*) bh
;
4028 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4029 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4030 h
->type
= STT_SECTION
;
4032 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4036 /* We need to create a .compact_rel section. */
4037 if (SGI_COMPAT (abfd
))
4039 if (!mips_elf_create_compact_rel_section (abfd
, info
))
4043 /* Change alignments of some sections. */
4044 s
= bfd_get_section_by_name (abfd
, ".hash");
4046 bfd_set_section_alignment (abfd
, s
, 4);
4047 s
= bfd_get_section_by_name (abfd
, ".dynsym");
4049 bfd_set_section_alignment (abfd
, s
, 4);
4050 s
= bfd_get_section_by_name (abfd
, ".dynstr");
4052 bfd_set_section_alignment (abfd
, s
, 4);
4053 s
= bfd_get_section_by_name (abfd
, ".reginfo");
4055 bfd_set_section_alignment (abfd
, s
, 4);
4056 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4058 bfd_set_section_alignment (abfd
, s
, 4);
4065 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
4067 if (!(_bfd_generic_link_add_one_symbol
4068 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
,
4069 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
4070 get_elf_backend_data (abfd
)->collect
, &bh
)))
4073 h
= (struct elf_link_hash_entry
*) bh
;
4074 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4075 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4076 h
->type
= STT_SECTION
;
4078 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4081 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
4083 /* __rld_map is a four byte word located in the .data section
4084 and is filled in by the rtld to contain a pointer to
4085 the _r_debug structure. Its symbol value will be set in
4086 _bfd_mips_elf_finish_dynamic_symbol. */
4087 s
= bfd_get_section_by_name (abfd
, ".rld_map");
4088 BFD_ASSERT (s
!= NULL
);
4090 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
4092 if (!(_bfd_generic_link_add_one_symbol
4093 (info
, abfd
, name
, BSF_GLOBAL
, s
,
4094 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
4095 get_elf_backend_data (abfd
)->collect
, &bh
)))
4098 h
= (struct elf_link_hash_entry
*) bh
;
4099 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4100 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4101 h
->type
= STT_OBJECT
;
4103 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4111 /* Look through the relocs for a section during the first phase, and
4112 allocate space in the global offset table. */
4115 _bfd_mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
4117 struct bfd_link_info
*info
;
4119 const Elf_Internal_Rela
*relocs
;
4123 Elf_Internal_Shdr
*symtab_hdr
;
4124 struct elf_link_hash_entry
**sym_hashes
;
4125 struct mips_got_info
*g
;
4127 const Elf_Internal_Rela
*rel
;
4128 const Elf_Internal_Rela
*rel_end
;
4131 struct elf_backend_data
*bed
;
4133 if (info
->relocateable
)
4136 dynobj
= elf_hash_table (info
)->dynobj
;
4137 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4138 sym_hashes
= elf_sym_hashes (abfd
);
4139 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
4141 /* Check for the mips16 stub sections. */
4143 name
= bfd_get_section_name (abfd
, sec
);
4144 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
4146 unsigned long r_symndx
;
4148 /* Look at the relocation information to figure out which symbol
4151 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
4153 if (r_symndx
< extsymoff
4154 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
4158 /* This stub is for a local symbol. This stub will only be
4159 needed if there is some relocation in this BFD, other
4160 than a 16 bit function call, which refers to this symbol. */
4161 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4163 Elf_Internal_Rela
*sec_relocs
;
4164 const Elf_Internal_Rela
*r
, *rend
;
4166 /* We can ignore stub sections when looking for relocs. */
4167 if ((o
->flags
& SEC_RELOC
) == 0
4168 || o
->reloc_count
== 0
4169 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
4170 sizeof FN_STUB
- 1) == 0
4171 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
4172 sizeof CALL_STUB
- 1) == 0
4173 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
4174 sizeof CALL_FP_STUB
- 1) == 0)
4177 sec_relocs
= (MNAME(abfd
,_bfd_elf
,link_read_relocs
)
4178 (abfd
, o
, (PTR
) NULL
,
4179 (Elf_Internal_Rela
*) NULL
,
4180 info
->keep_memory
));
4181 if (sec_relocs
== NULL
)
4184 rend
= sec_relocs
+ o
->reloc_count
;
4185 for (r
= sec_relocs
; r
< rend
; r
++)
4186 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
4187 && ELF_R_TYPE (abfd
, r
->r_info
) != R_MIPS16_26
)
4190 if (elf_section_data (o
)->relocs
!= sec_relocs
)
4199 /* There is no non-call reloc for this stub, so we do
4200 not need it. Since this function is called before
4201 the linker maps input sections to output sections, we
4202 can easily discard it by setting the SEC_EXCLUDE
4204 sec
->flags
|= SEC_EXCLUDE
;
4208 /* Record this stub in an array of local symbol stubs for
4210 if (elf_tdata (abfd
)->local_stubs
== NULL
)
4212 unsigned long symcount
;
4216 if (elf_bad_symtab (abfd
))
4217 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
4219 symcount
= symtab_hdr
->sh_info
;
4220 amt
= symcount
* sizeof (asection
*);
4221 n
= (asection
**) bfd_zalloc (abfd
, amt
);
4224 elf_tdata (abfd
)->local_stubs
= n
;
4227 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
4229 /* We don't need to set mips16_stubs_seen in this case.
4230 That flag is used to see whether we need to look through
4231 the global symbol table for stubs. We don't need to set
4232 it here, because we just have a local stub. */
4236 struct mips_elf_link_hash_entry
*h
;
4238 h
= ((struct mips_elf_link_hash_entry
*)
4239 sym_hashes
[r_symndx
- extsymoff
]);
4241 /* H is the symbol this stub is for. */
4244 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
4247 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
4248 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4250 unsigned long r_symndx
;
4251 struct mips_elf_link_hash_entry
*h
;
4254 /* Look at the relocation information to figure out which symbol
4257 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
4259 if (r_symndx
< extsymoff
4260 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
4262 /* This stub was actually built for a static symbol defined
4263 in the same file. We assume that all static symbols in
4264 mips16 code are themselves mips16, so we can simply
4265 discard this stub. Since this function is called before
4266 the linker maps input sections to output sections, we can
4267 easily discard it by setting the SEC_EXCLUDE flag. */
4268 sec
->flags
|= SEC_EXCLUDE
;
4272 h
= ((struct mips_elf_link_hash_entry
*)
4273 sym_hashes
[r_symndx
- extsymoff
]);
4275 /* H is the symbol this stub is for. */
4277 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4278 loc
= &h
->call_fp_stub
;
4280 loc
= &h
->call_stub
;
4282 /* If we already have an appropriate stub for this function, we
4283 don't need another one, so we can discard this one. Since
4284 this function is called before the linker maps input sections
4285 to output sections, we can easily discard it by setting the
4286 SEC_EXCLUDE flag. We can also discard this section if we
4287 happen to already know that this is a mips16 function; it is
4288 not necessary to check this here, as it is checked later, but
4289 it is slightly faster to check now. */
4290 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
4292 sec
->flags
|= SEC_EXCLUDE
;
4297 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
4307 sgot
= mips_elf_got_section (dynobj
);
4312 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4313 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4314 BFD_ASSERT (g
!= NULL
);
4319 bed
= get_elf_backend_data (abfd
);
4320 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
4321 for (rel
= relocs
; rel
< rel_end
; ++rel
)
4323 unsigned long r_symndx
;
4324 unsigned int r_type
;
4325 struct elf_link_hash_entry
*h
;
4327 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
4328 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
4330 if (r_symndx
< extsymoff
)
4332 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
4334 (*_bfd_error_handler
)
4335 (_("%s: Malformed reloc detected for section %s"),
4336 bfd_archive_filename (abfd
), name
);
4337 bfd_set_error (bfd_error_bad_value
);
4342 h
= sym_hashes
[r_symndx
- extsymoff
];
4344 /* This may be an indirect symbol created because of a version. */
4347 while (h
->root
.type
== bfd_link_hash_indirect
)
4348 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4352 /* Some relocs require a global offset table. */
4353 if (dynobj
== NULL
|| sgot
== NULL
)
4359 case R_MIPS_CALL_HI16
:
4360 case R_MIPS_CALL_LO16
:
4361 case R_MIPS_GOT_HI16
:
4362 case R_MIPS_GOT_LO16
:
4363 case R_MIPS_GOT_PAGE
:
4364 case R_MIPS_GOT_OFST
:
4365 case R_MIPS_GOT_DISP
:
4367 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4368 if (! mips_elf_create_got_section (dynobj
, info
))
4370 g
= mips_elf_got_info (dynobj
, &sgot
);
4377 && (info
->shared
|| h
!= NULL
)
4378 && (sec
->flags
& SEC_ALLOC
) != 0)
4379 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4387 if (!h
&& (r_type
== R_MIPS_CALL_LO16
4388 || r_type
== R_MIPS_GOT_LO16
4389 || r_type
== R_MIPS_GOT_DISP
))
4391 struct mips_got_entry entry
, **loc
;
4393 /* We may need a local GOT entry for this relocation. We
4394 don't count R_MIPS_GOT_PAGE because we can estimate the
4395 maximum number of pages needed by looking at the size of
4396 the segment. Similar comments apply to R_MIPS_GOT16 and
4397 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
4398 R_MIPS_CALL_HI16 because these are always followed by an
4399 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
4402 entry
.symndx
= r_symndx
;
4403 entry
.addend
= rel
->r_addend
;
4404 loc
= (struct mips_got_entry
**)
4405 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
4409 entry
.gotidx
= g
->local_gotno
++;
4411 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
4416 memcpy (*loc
, &entry
, sizeof entry
);
4418 sgot
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
4427 (*_bfd_error_handler
)
4428 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
4429 bfd_archive_filename (abfd
), (unsigned long) rel
->r_offset
);
4430 bfd_set_error (bfd_error_bad_value
);
4435 case R_MIPS_CALL_HI16
:
4436 case R_MIPS_CALL_LO16
:
4439 /* This symbol requires a global offset table entry. */
4440 if (! mips_elf_record_global_got_symbol (h
, info
, g
))
4443 /* We need a stub, not a plt entry for the undefined
4444 function. But we record it as if it needs plt. See
4445 elf_adjust_dynamic_symbol in elflink.h. */
4446 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4452 case R_MIPS_GOT_HI16
:
4453 case R_MIPS_GOT_LO16
:
4454 case R_MIPS_GOT_DISP
:
4455 /* This symbol requires a global offset table entry. */
4456 if (h
&& ! mips_elf_record_global_got_symbol (h
, info
, g
))
4463 if ((info
->shared
|| h
!= NULL
)
4464 && (sec
->flags
& SEC_ALLOC
) != 0)
4468 const char *dname
= ".rel.dyn";
4470 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
4473 sreloc
= bfd_make_section (dynobj
, dname
);
4475 || ! bfd_set_section_flags (dynobj
, sreloc
,
4480 | SEC_LINKER_CREATED
4482 || ! bfd_set_section_alignment (dynobj
, sreloc
,
4487 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
4490 /* When creating a shared object, we must copy these
4491 reloc types into the output file as R_MIPS_REL32
4492 relocs. We make room for this reloc in the
4493 .rel.dyn reloc section. */
4494 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
4495 if ((sec
->flags
& MIPS_READONLY_SECTION
)
4496 == MIPS_READONLY_SECTION
)
4497 /* We tell the dynamic linker that there are
4498 relocations against the text segment. */
4499 info
->flags
|= DF_TEXTREL
;
4503 struct mips_elf_link_hash_entry
*hmips
;
4505 /* We only need to copy this reloc if the symbol is
4506 defined in a dynamic object. */
4507 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4508 ++hmips
->possibly_dynamic_relocs
;
4509 if ((sec
->flags
& MIPS_READONLY_SECTION
)
4510 == MIPS_READONLY_SECTION
)
4511 /* We need it to tell the dynamic linker if there
4512 are relocations against the text segment. */
4513 hmips
->readonly_reloc
= TRUE
;
4516 /* Even though we don't directly need a GOT entry for
4517 this symbol, a symbol must have a dynamic symbol
4518 table index greater that DT_MIPS_GOTSYM if there are
4519 dynamic relocations against it. */
4521 && ! mips_elf_record_global_got_symbol (h
, info
, g
))
4525 if (SGI_COMPAT (abfd
))
4526 mips_elf_hash_table (info
)->compact_rel_size
+=
4527 sizeof (Elf32_External_crinfo
);
4531 case R_MIPS_GPREL16
:
4532 case R_MIPS_LITERAL
:
4533 case R_MIPS_GPREL32
:
4534 if (SGI_COMPAT (abfd
))
4535 mips_elf_hash_table (info
)->compact_rel_size
+=
4536 sizeof (Elf32_External_crinfo
);
4539 /* This relocation describes the C++ object vtable hierarchy.
4540 Reconstruct it for later use during GC. */
4541 case R_MIPS_GNU_VTINHERIT
:
4542 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4546 /* This relocation describes which C++ vtable entries are actually
4547 used. Record for later use during GC. */
4548 case R_MIPS_GNU_VTENTRY
:
4549 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
4557 /* We must not create a stub for a symbol that has relocations
4558 related to taking the function's address. */
4564 struct mips_elf_link_hash_entry
*mh
;
4566 mh
= (struct mips_elf_link_hash_entry
*) h
;
4567 mh
->no_fn_stub
= TRUE
;
4571 case R_MIPS_CALL_HI16
:
4572 case R_MIPS_CALL_LO16
:
4576 /* If this reloc is not a 16 bit call, and it has a global
4577 symbol, then we will need the fn_stub if there is one.
4578 References from a stub section do not count. */
4580 && r_type
!= R_MIPS16_26
4581 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
4582 sizeof FN_STUB
- 1) != 0
4583 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
4584 sizeof CALL_STUB
- 1) != 0
4585 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
4586 sizeof CALL_FP_STUB
- 1) != 0)
4588 struct mips_elf_link_hash_entry
*mh
;
4590 mh
= (struct mips_elf_link_hash_entry
*) h
;
4591 mh
->need_fn_stub
= TRUE
;
4598 /* Adjust a symbol defined by a dynamic object and referenced by a
4599 regular object. The current definition is in some section of the
4600 dynamic object, but we're not including those sections. We have to
4601 change the definition to something the rest of the link can
4605 _bfd_mips_elf_adjust_dynamic_symbol (info
, h
)
4606 struct bfd_link_info
*info
;
4607 struct elf_link_hash_entry
*h
;
4610 struct mips_elf_link_hash_entry
*hmips
;
4613 dynobj
= elf_hash_table (info
)->dynobj
;
4615 /* Make sure we know what is going on here. */
4616 BFD_ASSERT (dynobj
!= NULL
4617 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
4618 || h
->weakdef
!= NULL
4619 || ((h
->elf_link_hash_flags
4620 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4621 && (h
->elf_link_hash_flags
4622 & ELF_LINK_HASH_REF_REGULAR
) != 0
4623 && (h
->elf_link_hash_flags
4624 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
4626 /* If this symbol is defined in a dynamic object, we need to copy
4627 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
4629 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4630 if (! info
->relocateable
4631 && hmips
->possibly_dynamic_relocs
!= 0
4632 && (h
->root
.type
== bfd_link_hash_defweak
4633 || (h
->elf_link_hash_flags
4634 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4636 mips_elf_allocate_dynamic_relocations (dynobj
,
4637 hmips
->possibly_dynamic_relocs
);
4638 if (hmips
->readonly_reloc
)
4639 /* We tell the dynamic linker that there are relocations
4640 against the text segment. */
4641 info
->flags
|= DF_TEXTREL
;
4644 /* For a function, create a stub, if allowed. */
4645 if (! hmips
->no_fn_stub
4646 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4648 if (! elf_hash_table (info
)->dynamic_sections_created
)
4651 /* If this symbol is not defined in a regular file, then set
4652 the symbol to the stub location. This is required to make
4653 function pointers compare as equal between the normal
4654 executable and the shared library. */
4655 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4657 /* We need .stub section. */
4658 s
= bfd_get_section_by_name (dynobj
,
4659 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
4660 BFD_ASSERT (s
!= NULL
);
4662 h
->root
.u
.def
.section
= s
;
4663 h
->root
.u
.def
.value
= s
->_raw_size
;
4665 /* XXX Write this stub address somewhere. */
4666 h
->plt
.offset
= s
->_raw_size
;
4668 /* Make room for this stub code. */
4669 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4671 /* The last half word of the stub will be filled with the index
4672 of this symbol in .dynsym section. */
4676 else if ((h
->type
== STT_FUNC
)
4677 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
4679 /* This will set the entry for this symbol in the GOT to 0, and
4680 the dynamic linker will take care of this. */
4681 h
->root
.u
.def
.value
= 0;
4685 /* If this is a weak symbol, and there is a real definition, the
4686 processor independent code will have arranged for us to see the
4687 real definition first, and we can just use the same value. */
4688 if (h
->weakdef
!= NULL
)
4690 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4691 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4692 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4693 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4697 /* This is a reference to a symbol defined by a dynamic object which
4698 is not a function. */
4703 /* This function is called after all the input files have been read,
4704 and the input sections have been assigned to output sections. We
4705 check for any mips16 stub sections that we can discard. */
4708 _bfd_mips_elf_always_size_sections (output_bfd
, info
)
4710 struct bfd_link_info
*info
;
4714 /* The .reginfo section has a fixed size. */
4715 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
4717 bfd_set_section_size (output_bfd
, ri
,
4718 (bfd_size_type
) sizeof (Elf32_External_RegInfo
));
4720 if (info
->relocateable
4721 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
4724 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4725 mips_elf_check_mips16_stubs
,
4731 /* Set the sizes of the dynamic sections. */
4734 _bfd_mips_elf_size_dynamic_sections (output_bfd
, info
)
4736 struct bfd_link_info
*info
;
4740 bfd_boolean reltext
;
4741 struct mips_got_info
*g
= NULL
;
4743 dynobj
= elf_hash_table (info
)->dynobj
;
4744 BFD_ASSERT (dynobj
!= NULL
);
4746 if (elf_hash_table (info
)->dynamic_sections_created
)
4748 /* Set the contents of the .interp section to the interpreter. */
4751 s
= bfd_get_section_by_name (dynobj
, ".interp");
4752 BFD_ASSERT (s
!= NULL
);
4754 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
4756 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
4760 /* The check_relocs and adjust_dynamic_symbol entry points have
4761 determined the sizes of the various dynamic sections. Allocate
4764 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4769 /* It's OK to base decisions on the section name, because none
4770 of the dynobj section names depend upon the input files. */
4771 name
= bfd_get_section_name (dynobj
, s
);
4773 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4778 if (strncmp (name
, ".rel", 4) == 0)
4780 if (s
->_raw_size
== 0)
4782 /* We only strip the section if the output section name
4783 has the same name. Otherwise, there might be several
4784 input sections for this output section. FIXME: This
4785 code is probably not needed these days anyhow, since
4786 the linker now does not create empty output sections. */
4787 if (s
->output_section
!= NULL
4789 bfd_get_section_name (s
->output_section
->owner
,
4790 s
->output_section
)) == 0)
4795 const char *outname
;
4798 /* If this relocation section applies to a read only
4799 section, then we probably need a DT_TEXTREL entry.
4800 If the relocation section is .rel.dyn, we always
4801 assert a DT_TEXTREL entry rather than testing whether
4802 there exists a relocation to a read only section or
4804 outname
= bfd_get_section_name (output_bfd
,
4806 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
4808 && (target
->flags
& SEC_READONLY
) != 0
4809 && (target
->flags
& SEC_ALLOC
) != 0)
4810 || strcmp (outname
, ".rel.dyn") == 0)
4813 /* We use the reloc_count field as a counter if we need
4814 to copy relocs into the output file. */
4815 if (strcmp (name
, ".rel.dyn") != 0)
4819 else if (strncmp (name
, ".got", 4) == 0)
4822 bfd_size_type loadable_size
= 0;
4823 bfd_size_type local_gotno
;
4826 BFD_ASSERT (elf_section_data (s
) != NULL
);
4827 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
4828 BFD_ASSERT (g
!= NULL
);
4830 /* Calculate the total loadable size of the output. That
4831 will give us the maximum number of GOT_PAGE entries
4833 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
4835 asection
*subsection
;
4837 for (subsection
= sub
->sections
;
4839 subsection
= subsection
->next
)
4841 if ((subsection
->flags
& SEC_ALLOC
) == 0)
4843 loadable_size
+= ((subsection
->_raw_size
+ 0xf)
4844 &~ (bfd_size_type
) 0xf);
4847 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
4849 /* Assume there are two loadable segments consisting of
4850 contiguous sections. Is 5 enough? */
4851 local_gotno
= (loadable_size
>> 16) + 5;
4853 g
->local_gotno
+= local_gotno
;
4854 s
->_raw_size
+= local_gotno
* MIPS_ELF_GOT_SIZE (dynobj
);
4856 /* There has to be a global GOT entry for every symbol with
4857 a dynamic symbol table index of DT_MIPS_GOTSYM or
4858 higher. Therefore, it make sense to put those symbols
4859 that need GOT entries at the end of the symbol table. We
4861 if (! mips_elf_sort_hash_table (info
, 1))
4864 if (g
->global_gotsym
!= NULL
)
4865 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
4867 /* If there are no global symbols, or none requiring
4868 relocations, then GLOBAL_GOTSYM will be NULL. */
4870 g
->global_gotno
= i
;
4871 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (dynobj
);
4873 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
4875 /* IRIX rld assumes that the function stub isn't at the end
4876 of .text section. So put a dummy. XXX */
4877 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4879 else if (! info
->shared
4880 && ! mips_elf_hash_table (info
)->use_rld_obj_head
4881 && strncmp (name
, ".rld_map", 8) == 0)
4883 /* We add a room for __rld_map. It will be filled in by the
4884 rtld to contain a pointer to the _r_debug structure. */
4887 else if (SGI_COMPAT (output_bfd
)
4888 && strncmp (name
, ".compact_rel", 12) == 0)
4889 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
4890 else if (strcmp (name
, ".msym") == 0)
4891 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
4892 * (elf_hash_table (info
)->dynsymcount
4893 + bfd_count_sections (output_bfd
)));
4894 else if (strncmp (name
, ".init", 5) != 0)
4896 /* It's not one of our sections, so don't allocate space. */
4902 _bfd_strip_section_from_output (info
, s
);
4906 /* Allocate memory for the section contents. */
4907 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4908 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
4910 bfd_set_error (bfd_error_no_memory
);
4915 if (elf_hash_table (info
)->dynamic_sections_created
)
4917 /* Add some entries to the .dynamic section. We fill in the
4918 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
4919 must add the entries now so that we get the correct size for
4920 the .dynamic section. The DT_DEBUG entry is filled in by the
4921 dynamic linker and used by the debugger. */
4924 /* SGI object has the equivalence of DT_DEBUG in the
4925 DT_MIPS_RLD_MAP entry. */
4926 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
4928 if (!SGI_COMPAT (output_bfd
))
4930 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
4936 /* Shared libraries on traditional mips have DT_DEBUG. */
4937 if (!SGI_COMPAT (output_bfd
))
4939 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
4944 if (reltext
&& SGI_COMPAT (output_bfd
))
4945 info
->flags
|= DF_TEXTREL
;
4947 if ((info
->flags
& DF_TEXTREL
) != 0)
4949 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
4953 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
4956 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
4958 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
4961 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
4964 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
4968 if (SGI_COMPAT (output_bfd
))
4970 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICTNO
, 0))
4974 if (SGI_COMPAT (output_bfd
))
4976 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLISTNO
, 0))
4980 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
4982 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICT
, 0))
4985 s
= bfd_get_section_by_name (dynobj
, ".liblist");
4986 BFD_ASSERT (s
!= NULL
);
4988 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLIST
, 0))
4992 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
4995 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
4999 /* Time stamps in executable files are a bad idea. */
5000 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
5005 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
5010 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
5014 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
5017 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
5020 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
5023 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
5026 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
5029 if (IRIX_COMPAT (dynobj
) == ict_irix5
5030 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
5033 if (IRIX_COMPAT (dynobj
) == ict_irix6
5034 && (bfd_get_section_by_name
5035 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
5036 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
5039 if (bfd_get_section_by_name (dynobj
, ".msym")
5040 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_MSYM
, 0))
5047 /* Relocate a MIPS ELF section. */
5050 _bfd_mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
5051 contents
, relocs
, local_syms
, local_sections
)
5053 struct bfd_link_info
*info
;
5055 asection
*input_section
;
5057 Elf_Internal_Rela
*relocs
;
5058 Elf_Internal_Sym
*local_syms
;
5059 asection
**local_sections
;
5061 Elf_Internal_Rela
*rel
;
5062 const Elf_Internal_Rela
*relend
;
5064 bfd_boolean use_saved_addend_p
= FALSE
;
5065 struct elf_backend_data
*bed
;
5067 bed
= get_elf_backend_data (output_bfd
);
5068 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
5069 for (rel
= relocs
; rel
< relend
; ++rel
)
5073 reloc_howto_type
*howto
;
5074 bfd_boolean require_jalx
;
5075 /* TRUE if the relocation is a RELA relocation, rather than a
5077 bfd_boolean rela_relocation_p
= TRUE
;
5078 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5079 const char * msg
= (const char *) NULL
;
5081 /* Find the relocation howto for this relocation. */
5082 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
5084 /* Some 32-bit code uses R_MIPS_64. In particular, people use
5085 64-bit code, but make sure all their addresses are in the
5086 lowermost or uppermost 32-bit section of the 64-bit address
5087 space. Thus, when they use an R_MIPS_64 they mean what is
5088 usually meant by R_MIPS_32, with the exception that the
5089 stored value is sign-extended to 64 bits. */
5090 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
5092 /* On big-endian systems, we need to lie about the position
5094 if (bfd_big_endian (input_bfd
))
5098 /* NewABI defaults to RELA relocations. */
5099 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
5100 NEWABI_P (input_bfd
)
5101 && (MIPS_RELOC_RELA_P
5102 (input_bfd
, input_section
,
5105 if (!use_saved_addend_p
)
5107 Elf_Internal_Shdr
*rel_hdr
;
5109 /* If these relocations were originally of the REL variety,
5110 we must pull the addend out of the field that will be
5111 relocated. Otherwise, we simply use the contents of the
5112 RELA relocation. To determine which flavor or relocation
5113 this is, we depend on the fact that the INPUT_SECTION's
5114 REL_HDR is read before its REL_HDR2. */
5115 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
5116 if ((size_t) (rel
- relocs
)
5117 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
5118 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
5119 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
5121 /* Note that this is a REL relocation. */
5122 rela_relocation_p
= FALSE
;
5124 /* Get the addend, which is stored in the input file. */
5125 addend
= mips_elf_obtain_contents (howto
, rel
, input_bfd
,
5127 addend
&= howto
->src_mask
;
5128 addend
<<= howto
->rightshift
;
5130 /* For some kinds of relocations, the ADDEND is a
5131 combination of the addend stored in two different
5133 if (r_type
== R_MIPS_HI16
5134 || r_type
== R_MIPS_GNU_REL_HI16
5135 || (r_type
== R_MIPS_GOT16
5136 && mips_elf_local_relocation_p (input_bfd
, rel
,
5137 local_sections
, FALSE
)))
5140 const Elf_Internal_Rela
*lo16_relocation
;
5141 reloc_howto_type
*lo16_howto
;
5144 /* The combined value is the sum of the HI16 addend,
5145 left-shifted by sixteen bits, and the LO16
5146 addend, sign extended. (Usually, the code does
5147 a `lui' of the HI16 value, and then an `addiu' of
5150 Scan ahead to find a matching LO16 relocation. */
5151 if (r_type
== R_MIPS_GNU_REL_HI16
)
5152 lo
= R_MIPS_GNU_REL_LO16
;
5155 lo16_relocation
= mips_elf_next_relocation (input_bfd
, lo
,
5157 if (lo16_relocation
== NULL
)
5160 /* Obtain the addend kept there. */
5161 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, lo
, FALSE
);
5162 l
= mips_elf_obtain_contents (lo16_howto
, lo16_relocation
,
5163 input_bfd
, contents
);
5164 l
&= lo16_howto
->src_mask
;
5165 l
<<= lo16_howto
->rightshift
;
5166 l
= mips_elf_sign_extend (l
, 16);
5170 /* Compute the combined addend. */
5173 /* If PC-relative, subtract the difference between the
5174 address of the LO part of the reloc and the address of
5175 the HI part. The relocation is relative to the LO
5176 part, but mips_elf_calculate_relocation() doesn't
5177 know its address or the difference from the HI part, so
5178 we subtract that difference here. See also the
5179 comment in mips_elf_calculate_relocation(). */
5180 if (r_type
== R_MIPS_GNU_REL_HI16
)
5181 addend
-= (lo16_relocation
->r_offset
- rel
->r_offset
);
5183 else if (r_type
== R_MIPS16_GPREL
)
5185 /* The addend is scrambled in the object file. See
5186 mips_elf_perform_relocation for details on the
5188 addend
= (((addend
& 0x1f0000) >> 5)
5189 | ((addend
& 0x7e00000) >> 16)
5194 addend
= rel
->r_addend
;
5197 if (info
->relocateable
)
5199 Elf_Internal_Sym
*sym
;
5200 unsigned long r_symndx
;
5202 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
5203 && bfd_big_endian (input_bfd
))
5206 /* Since we're just relocating, all we need to do is copy
5207 the relocations back out to the object file, unless
5208 they're against a section symbol, in which case we need
5209 to adjust by the section offset, or unless they're GP
5210 relative in which case we need to adjust by the amount
5211 that we're adjusting GP in this relocateable object. */
5213 if (! mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
5215 /* There's nothing to do for non-local relocations. */
5218 if (r_type
== R_MIPS16_GPREL
5219 || r_type
== R_MIPS_GPREL16
5220 || r_type
== R_MIPS_GPREL32
5221 || r_type
== R_MIPS_LITERAL
)
5222 addend
-= (_bfd_get_gp_value (output_bfd
)
5223 - _bfd_get_gp_value (input_bfd
));
5225 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
5226 sym
= local_syms
+ r_symndx
;
5227 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
5228 /* Adjust the addend appropriately. */
5229 addend
+= local_sections
[r_symndx
]->output_offset
;
5231 if (howto
->partial_inplace
)
5233 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
5234 then we only want to write out the high-order 16 bits.
5235 The subsequent R_MIPS_LO16 will handle the low-order bits.
5237 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
5238 || r_type
== R_MIPS_GNU_REL_HI16
)
5239 addend
= mips_elf_high (addend
);
5240 else if (r_type
== R_MIPS_HIGHER
)
5241 addend
= mips_elf_higher (addend
);
5242 else if (r_type
== R_MIPS_HIGHEST
)
5243 addend
= mips_elf_highest (addend
);
5246 if (rela_relocation_p
)
5247 /* If this is a RELA relocation, just update the addend.
5248 We have to cast away constness for REL. */
5249 rel
->r_addend
= addend
;
5252 /* Otherwise, we have to write the value back out. Note
5253 that we use the source mask, rather than the
5254 destination mask because the place to which we are
5255 writing will be source of the addend in the final
5257 addend
>>= howto
->rightshift
;
5258 addend
&= howto
->src_mask
;
5260 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
5261 /* See the comment above about using R_MIPS_64 in the 32-bit
5262 ABI. Here, we need to update the addend. It would be
5263 possible to get away with just using the R_MIPS_32 reloc
5264 but for endianness. */
5270 if (addend
& ((bfd_vma
) 1 << 31))
5272 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
5279 /* If we don't know that we have a 64-bit type,
5280 do two separate stores. */
5281 if (bfd_big_endian (input_bfd
))
5283 /* Store the sign-bits (which are most significant)
5285 low_bits
= sign_bits
;
5291 high_bits
= sign_bits
;
5293 bfd_put_32 (input_bfd
, low_bits
,
5294 contents
+ rel
->r_offset
);
5295 bfd_put_32 (input_bfd
, high_bits
,
5296 contents
+ rel
->r_offset
+ 4);
5300 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
5301 input_bfd
, input_section
,
5306 /* Go on to the next relocation. */
5310 /* In the N32 and 64-bit ABIs there may be multiple consecutive
5311 relocations for the same offset. In that case we are
5312 supposed to treat the output of each relocation as the addend
5314 if (rel
+ 1 < relend
5315 && rel
->r_offset
== rel
[1].r_offset
5316 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
5317 use_saved_addend_p
= TRUE
;
5319 use_saved_addend_p
= FALSE
;
5321 addend
>>= howto
->rightshift
;
5323 /* Figure out what value we are supposed to relocate. */
5324 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
5325 input_section
, info
, rel
,
5326 addend
, howto
, local_syms
,
5327 local_sections
, &value
,
5328 &name
, &require_jalx
,
5329 use_saved_addend_p
))
5331 case bfd_reloc_continue
:
5332 /* There's nothing to do. */
5335 case bfd_reloc_undefined
:
5336 /* mips_elf_calculate_relocation already called the
5337 undefined_symbol callback. There's no real point in
5338 trying to perform the relocation at this point, so we
5339 just skip ahead to the next relocation. */
5342 case bfd_reloc_notsupported
:
5343 msg
= _("internal error: unsupported relocation error");
5344 info
->callbacks
->warning
5345 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
5348 case bfd_reloc_overflow
:
5349 if (use_saved_addend_p
)
5350 /* Ignore overflow until we reach the last relocation for
5351 a given location. */
5355 BFD_ASSERT (name
!= NULL
);
5356 if (! ((*info
->callbacks
->reloc_overflow
)
5357 (info
, name
, howto
->name
, (bfd_vma
) 0,
5358 input_bfd
, input_section
, rel
->r_offset
)))
5371 /* If we've got another relocation for the address, keep going
5372 until we reach the last one. */
5373 if (use_saved_addend_p
)
5379 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
5380 /* See the comment above about using R_MIPS_64 in the 32-bit
5381 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
5382 that calculated the right value. Now, however, we
5383 sign-extend the 32-bit result to 64-bits, and store it as a
5384 64-bit value. We are especially generous here in that we
5385 go to extreme lengths to support this usage on systems with
5386 only a 32-bit VMA. */
5392 if (value
& ((bfd_vma
) 1 << 31))
5394 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
5401 /* If we don't know that we have a 64-bit type,
5402 do two separate stores. */
5403 if (bfd_big_endian (input_bfd
))
5405 /* Undo what we did above. */
5407 /* Store the sign-bits (which are most significant)
5409 low_bits
= sign_bits
;
5415 high_bits
= sign_bits
;
5417 bfd_put_32 (input_bfd
, low_bits
,
5418 contents
+ rel
->r_offset
);
5419 bfd_put_32 (input_bfd
, high_bits
,
5420 contents
+ rel
->r_offset
+ 4);
5424 /* Actually perform the relocation. */
5425 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
5426 input_bfd
, input_section
,
5427 contents
, require_jalx
))
5434 /* If NAME is one of the special IRIX6 symbols defined by the linker,
5435 adjust it appropriately now. */
5438 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
5439 bfd
*abfd ATTRIBUTE_UNUSED
;
5441 Elf_Internal_Sym
*sym
;
5443 /* The linker script takes care of providing names and values for
5444 these, but we must place them into the right sections. */
5445 static const char* const text_section_symbols
[] = {
5448 "__dso_displacement",
5450 "__program_header_table",
5454 static const char* const data_section_symbols
[] = {
5462 const char* const *p
;
5465 for (i
= 0; i
< 2; ++i
)
5466 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
5469 if (strcmp (*p
, name
) == 0)
5471 /* All of these symbols are given type STT_SECTION by the
5473 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5475 /* The IRIX linker puts these symbols in special sections. */
5477 sym
->st_shndx
= SHN_MIPS_TEXT
;
5479 sym
->st_shndx
= SHN_MIPS_DATA
;
5485 /* Finish up dynamic symbol handling. We set the contents of various
5486 dynamic sections here. */
5489 _bfd_mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5491 struct bfd_link_info
*info
;
5492 struct elf_link_hash_entry
*h
;
5493 Elf_Internal_Sym
*sym
;
5499 struct mips_got_info
*g
;
5501 struct mips_elf_link_hash_entry
*mh
;
5503 dynobj
= elf_hash_table (info
)->dynobj
;
5504 gval
= sym
->st_value
;
5505 mh
= (struct mips_elf_link_hash_entry
*) h
;
5507 if (h
->plt
.offset
!= (bfd_vma
) -1)
5510 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5512 /* This symbol has a stub. Set it up. */
5514 BFD_ASSERT (h
->dynindx
!= -1);
5516 s
= bfd_get_section_by_name (dynobj
,
5517 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
5518 BFD_ASSERT (s
!= NULL
);
5520 /* FIXME: Can h->dynindex be more than 64K? */
5521 if (h
->dynindx
& 0xffff0000)
5524 /* Fill the stub. */
5525 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
);
5526 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ 4);
5527 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ 8);
5528 bfd_put_32 (output_bfd
, STUB_LI16 (output_bfd
) + h
->dynindx
, stub
+ 12);
5530 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
5531 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5533 /* Mark the symbol as undefined. plt.offset != -1 occurs
5534 only for the referenced symbol. */
5535 sym
->st_shndx
= SHN_UNDEF
;
5537 /* The run-time linker uses the st_value field of the symbol
5538 to reset the global offset table entry for this external
5539 to its stub address when unlinking a shared object. */
5540 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
5541 sym
->st_value
= gval
;
5544 BFD_ASSERT (h
->dynindx
!= -1
5545 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
5547 sgot
= mips_elf_got_section (dynobj
);
5548 BFD_ASSERT (sgot
!= NULL
);
5549 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5550 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5551 BFD_ASSERT (g
!= NULL
);
5553 /* Run through the global symbol table, creating GOT entries for all
5554 the symbols that need them. */
5555 if (g
->global_gotsym
!= NULL
5556 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
5562 value
= sym
->st_value
;
5565 /* For an entity defined in a shared object, this will be
5566 NULL. (For functions in shared objects for
5567 which we have created stubs, ST_VALUE will be non-NULL.
5568 That's because such the functions are now no longer defined
5569 in a shared object.) */
5571 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
5574 value
= h
->root
.u
.def
.value
;
5576 offset
= mips_elf_global_got_index (dynobj
, h
);
5577 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
5580 /* Create a .msym entry, if appropriate. */
5581 smsym
= bfd_get_section_by_name (dynobj
, ".msym");
5584 Elf32_Internal_Msym msym
;
5586 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
5587 /* It is undocumented what the `1' indicates, but IRIX6 uses
5589 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
5590 bfd_mips_elf_swap_msym_out
5592 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
5595 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5596 name
= h
->root
.root
.string
;
5597 if (strcmp (name
, "_DYNAMIC") == 0
5598 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5599 sym
->st_shndx
= SHN_ABS
;
5600 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
5601 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
5603 sym
->st_shndx
= SHN_ABS
;
5604 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5607 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
5609 sym
->st_shndx
= SHN_ABS
;
5610 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5611 sym
->st_value
= elf_gp (output_bfd
);
5613 else if (SGI_COMPAT (output_bfd
))
5615 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
5616 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
5618 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5619 sym
->st_other
= STO_PROTECTED
;
5621 sym
->st_shndx
= SHN_MIPS_DATA
;
5623 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
5625 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5626 sym
->st_other
= STO_PROTECTED
;
5627 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
5628 sym
->st_shndx
= SHN_ABS
;
5630 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
5632 if (h
->type
== STT_FUNC
)
5633 sym
->st_shndx
= SHN_MIPS_TEXT
;
5634 else if (h
->type
== STT_OBJECT
)
5635 sym
->st_shndx
= SHN_MIPS_DATA
;
5639 /* Handle the IRIX6-specific symbols. */
5640 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
5641 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
5645 if (! mips_elf_hash_table (info
)->use_rld_obj_head
5646 && (strcmp (name
, "__rld_map") == 0
5647 || strcmp (name
, "__RLD_MAP") == 0))
5649 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
5650 BFD_ASSERT (s
!= NULL
);
5651 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
5652 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
5653 if (mips_elf_hash_table (info
)->rld_value
== 0)
5654 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5656 else if (mips_elf_hash_table (info
)->use_rld_obj_head
5657 && strcmp (name
, "__rld_obj_head") == 0)
5659 /* IRIX6 does not use a .rld_map section. */
5660 if (IRIX_COMPAT (output_bfd
) == ict_irix5
5661 || IRIX_COMPAT (output_bfd
) == ict_none
)
5662 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
5664 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5668 /* If this is a mips16 symbol, force the value to be even. */
5669 if (sym
->st_other
== STO_MIPS16
5670 && (sym
->st_value
& 1) != 0)
5676 /* Finish up the dynamic sections. */
5679 _bfd_mips_elf_finish_dynamic_sections (output_bfd
, info
)
5681 struct bfd_link_info
*info
;
5686 struct mips_got_info
*g
;
5688 dynobj
= elf_hash_table (info
)->dynobj
;
5690 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5692 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5697 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5698 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5699 BFD_ASSERT (g
!= NULL
);
5702 if (elf_hash_table (info
)->dynamic_sections_created
)
5706 BFD_ASSERT (sdyn
!= NULL
);
5707 BFD_ASSERT (g
!= NULL
);
5709 for (b
= sdyn
->contents
;
5710 b
< sdyn
->contents
+ sdyn
->_raw_size
;
5711 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
5713 Elf_Internal_Dyn dyn
;
5717 bfd_boolean swap_out_p
;
5719 /* Read in the current dynamic entry. */
5720 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
5722 /* Assume that we're going to modify it and write it out. */
5728 s
= (bfd_get_section_by_name (dynobj
, ".rel.dyn"));
5729 BFD_ASSERT (s
!= NULL
);
5730 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
5734 /* Rewrite DT_STRSZ. */
5736 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
5742 case DT_MIPS_CONFLICT
:
5745 case DT_MIPS_LIBLIST
:
5748 s
= bfd_get_section_by_name (output_bfd
, name
);
5749 BFD_ASSERT (s
!= NULL
);
5750 dyn
.d_un
.d_ptr
= s
->vma
;
5753 case DT_MIPS_RLD_VERSION
:
5754 dyn
.d_un
.d_val
= 1; /* XXX */
5758 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5761 case DT_MIPS_CONFLICTNO
:
5763 elemsize
= sizeof (Elf32_Conflict
);
5766 case DT_MIPS_LIBLISTNO
:
5768 elemsize
= sizeof (Elf32_Lib
);
5770 s
= bfd_get_section_by_name (output_bfd
, name
);
5773 if (s
->_cooked_size
!= 0)
5774 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5776 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5782 case DT_MIPS_TIME_STAMP
:
5783 time ((time_t *) &dyn
.d_un
.d_val
);
5786 case DT_MIPS_ICHECKSUM
:
5791 case DT_MIPS_IVERSION
:
5796 case DT_MIPS_BASE_ADDRESS
:
5797 s
= output_bfd
->sections
;
5798 BFD_ASSERT (s
!= NULL
);
5799 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
5802 case DT_MIPS_LOCAL_GOTNO
:
5803 dyn
.d_un
.d_val
= g
->local_gotno
;
5806 case DT_MIPS_UNREFEXTNO
:
5807 /* The index into the dynamic symbol table which is the
5808 entry of the first external symbol that is not
5809 referenced within the same object. */
5810 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
5813 case DT_MIPS_GOTSYM
:
5814 if (g
->global_gotsym
)
5816 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
5819 /* In case if we don't have global got symbols we default
5820 to setting DT_MIPS_GOTSYM to the same value as
5821 DT_MIPS_SYMTABNO, so we just fall through. */
5823 case DT_MIPS_SYMTABNO
:
5825 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
5826 s
= bfd_get_section_by_name (output_bfd
, name
);
5827 BFD_ASSERT (s
!= NULL
);
5829 if (s
->_cooked_size
!= 0)
5830 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5832 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5835 case DT_MIPS_HIPAGENO
:
5836 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
5839 case DT_MIPS_RLD_MAP
:
5840 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
5843 case DT_MIPS_OPTIONS
:
5844 s
= (bfd_get_section_by_name
5845 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
5846 dyn
.d_un
.d_ptr
= s
->vma
;
5850 s
= (bfd_get_section_by_name (output_bfd
, ".msym"));
5851 dyn
.d_un
.d_ptr
= s
->vma
;
5860 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
5865 /* The first entry of the global offset table will be filled at
5866 runtime. The second entry will be used by some runtime loaders.
5867 This isn't the case of IRIX rld. */
5868 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
5870 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5871 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
5872 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
5876 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
5877 = MIPS_ELF_GOT_SIZE (output_bfd
);
5882 Elf32_compact_rel cpt
;
5884 /* ??? The section symbols for the output sections were set up in
5885 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
5886 symbols. Should we do so? */
5888 smsym
= bfd_get_section_by_name (dynobj
, ".msym");
5891 Elf32_Internal_Msym msym
;
5893 msym
.ms_hash_value
= 0;
5894 msym
.ms_info
= ELF32_MS_INFO (0, 1);
5896 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
5898 long dynindx
= elf_section_data (s
)->dynindx
;
5900 bfd_mips_elf_swap_msym_out
5902 (((Elf32_External_Msym
*) smsym
->contents
)
5907 if (SGI_COMPAT (output_bfd
))
5909 /* Write .compact_rel section out. */
5910 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5914 cpt
.num
= s
->reloc_count
;
5916 cpt
.offset
= (s
->output_section
->filepos
5917 + sizeof (Elf32_External_compact_rel
));
5920 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
5921 ((Elf32_External_compact_rel
*)
5924 /* Clean up a dummy stub function entry in .text. */
5925 s
= bfd_get_section_by_name (dynobj
,
5926 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
5929 file_ptr dummy_offset
;
5931 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
5932 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
5933 memset (s
->contents
+ dummy_offset
, 0,
5934 MIPS_FUNCTION_STUB_SIZE
);
5939 /* We need to sort the entries of the dynamic relocation section. */
5941 if (!ABI_64_P (output_bfd
))
5945 reldyn
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5946 if (reldyn
!= NULL
&& reldyn
->reloc_count
> 2)
5948 reldyn_sorting_bfd
= output_bfd
;
5949 qsort ((Elf32_External_Rel
*) reldyn
->contents
+ 1,
5950 (size_t) reldyn
->reloc_count
- 1,
5951 sizeof (Elf32_External_Rel
), sort_dynamic_relocs
);
5955 /* Clean up a first relocation in .rel.dyn. */
5956 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5957 if (s
!= NULL
&& s
->_raw_size
> 0)
5958 memset (s
->contents
, 0, MIPS_ELF_REL_SIZE (dynobj
));
5964 /* The final processing done just before writing out a MIPS ELF object
5965 file. This gets the MIPS architecture right based on the machine
5966 number. This is used by both the 32-bit and the 64-bit ABI. */
5969 _bfd_mips_elf_final_write_processing (abfd
, linker
)
5971 bfd_boolean linker ATTRIBUTE_UNUSED
;
5975 Elf_Internal_Shdr
**hdrpp
;
5979 switch (bfd_get_mach (abfd
))
5982 case bfd_mach_mips3000
:
5983 val
= E_MIPS_ARCH_1
;
5986 case bfd_mach_mips3900
:
5987 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
5990 case bfd_mach_mips6000
:
5991 val
= E_MIPS_ARCH_2
;
5994 case bfd_mach_mips4000
:
5995 case bfd_mach_mips4300
:
5996 case bfd_mach_mips4400
:
5997 case bfd_mach_mips4600
:
5998 val
= E_MIPS_ARCH_3
;
6001 case bfd_mach_mips4010
:
6002 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
6005 case bfd_mach_mips4100
:
6006 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
6009 case bfd_mach_mips4111
:
6010 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
6013 case bfd_mach_mips4120
:
6014 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
6017 case bfd_mach_mips4650
:
6018 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
6021 case bfd_mach_mips5400
:
6022 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
6025 case bfd_mach_mips5500
:
6026 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
6029 case bfd_mach_mips5000
:
6030 case bfd_mach_mips8000
:
6031 case bfd_mach_mips10000
:
6032 case bfd_mach_mips12000
:
6033 val
= E_MIPS_ARCH_4
;
6036 case bfd_mach_mips5
:
6037 val
= E_MIPS_ARCH_5
;
6040 case bfd_mach_mips_sb1
:
6041 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
6044 case bfd_mach_mipsisa32
:
6045 val
= E_MIPS_ARCH_32
;
6048 case bfd_mach_mipsisa64
:
6049 val
= E_MIPS_ARCH_64
;
6052 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
6053 elf_elfheader (abfd
)->e_flags
|= val
;
6055 /* Set the sh_info field for .gptab sections and other appropriate
6056 info for each special section. */
6057 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
6058 i
< elf_numsections (abfd
);
6061 switch ((*hdrpp
)->sh_type
)
6064 case SHT_MIPS_LIBLIST
:
6065 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
6067 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6070 case SHT_MIPS_GPTAB
:
6071 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
6072 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
6073 BFD_ASSERT (name
!= NULL
6074 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
6075 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
6076 BFD_ASSERT (sec
!= NULL
);
6077 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
6080 case SHT_MIPS_CONTENT
:
6081 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
6082 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
6083 BFD_ASSERT (name
!= NULL
6084 && strncmp (name
, ".MIPS.content",
6085 sizeof ".MIPS.content" - 1) == 0);
6086 sec
= bfd_get_section_by_name (abfd
,
6087 name
+ sizeof ".MIPS.content" - 1);
6088 BFD_ASSERT (sec
!= NULL
);
6089 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6092 case SHT_MIPS_SYMBOL_LIB
:
6093 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
6095 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6096 sec
= bfd_get_section_by_name (abfd
, ".liblist");
6098 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
6101 case SHT_MIPS_EVENTS
:
6102 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
6103 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
6104 BFD_ASSERT (name
!= NULL
);
6105 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
6106 sec
= bfd_get_section_by_name (abfd
,
6107 name
+ sizeof ".MIPS.events" - 1);
6110 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
6111 sizeof ".MIPS.post_rel" - 1) == 0);
6112 sec
= bfd_get_section_by_name (abfd
,
6114 + sizeof ".MIPS.post_rel" - 1));
6116 BFD_ASSERT (sec
!= NULL
);
6117 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6124 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
6128 _bfd_mips_elf_additional_program_headers (abfd
)
6134 /* See if we need a PT_MIPS_REGINFO segment. */
6135 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6136 if (s
&& (s
->flags
& SEC_LOAD
))
6139 /* See if we need a PT_MIPS_OPTIONS segment. */
6140 if (IRIX_COMPAT (abfd
) == ict_irix6
6141 && bfd_get_section_by_name (abfd
,
6142 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
6145 /* See if we need a PT_MIPS_RTPROC segment. */
6146 if (IRIX_COMPAT (abfd
) == ict_irix5
6147 && bfd_get_section_by_name (abfd
, ".dynamic")
6148 && bfd_get_section_by_name (abfd
, ".mdebug"))
6154 /* Modify the segment map for an IRIX5 executable. */
6157 _bfd_mips_elf_modify_segment_map (abfd
)
6161 struct elf_segment_map
*m
, **pm
;
6164 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
6166 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6167 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
6169 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
6170 if (m
->p_type
== PT_MIPS_REGINFO
)
6175 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6179 m
->p_type
= PT_MIPS_REGINFO
;
6183 /* We want to put it after the PHDR and INTERP segments. */
6184 pm
= &elf_tdata (abfd
)->segment_map
;
6186 && ((*pm
)->p_type
== PT_PHDR
6187 || (*pm
)->p_type
== PT_INTERP
))
6195 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
6196 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
6197 PT_OPTIONS segment immediately following the program header
6200 /* On non-IRIX6 new abi, we'll have already created a segment
6201 for this section, so don't create another. I'm not sure this
6202 is not also the case for IRIX 6, but I can't test it right
6204 && IRIX_COMPAT (abfd
) == ict_irix6
)
6206 for (s
= abfd
->sections
; s
; s
= s
->next
)
6207 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
6212 struct elf_segment_map
*options_segment
;
6214 /* Usually, there's a program header table. But, sometimes
6215 there's not (like when running the `ld' testsuite). So,
6216 if there's no program header table, we just put the
6217 options segment at the end. */
6218 for (pm
= &elf_tdata (abfd
)->segment_map
;
6221 if ((*pm
)->p_type
== PT_PHDR
)
6224 amt
= sizeof (struct elf_segment_map
);
6225 options_segment
= bfd_zalloc (abfd
, amt
);
6226 options_segment
->next
= *pm
;
6227 options_segment
->p_type
= PT_MIPS_OPTIONS
;
6228 options_segment
->p_flags
= PF_R
;
6229 options_segment
->p_flags_valid
= TRUE
;
6230 options_segment
->count
= 1;
6231 options_segment
->sections
[0] = s
;
6232 *pm
= options_segment
;
6237 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6239 /* If there are .dynamic and .mdebug sections, we make a room
6240 for the RTPROC header. FIXME: Rewrite without section names. */
6241 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
6242 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
6243 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
6245 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
6246 if (m
->p_type
== PT_MIPS_RTPROC
)
6251 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6255 m
->p_type
= PT_MIPS_RTPROC
;
6257 s
= bfd_get_section_by_name (abfd
, ".rtproc");
6262 m
->p_flags_valid
= 1;
6270 /* We want to put it after the DYNAMIC segment. */
6271 pm
= &elf_tdata (abfd
)->segment_map
;
6272 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
6282 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
6283 .dynstr, .dynsym, and .hash sections, and everything in
6285 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
6287 if ((*pm
)->p_type
== PT_DYNAMIC
)
6290 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
6292 /* For a normal mips executable the permissions for the PT_DYNAMIC
6293 segment are read, write and execute. We do that here since
6294 the code in elf.c sets only the read permission. This matters
6295 sometimes for the dynamic linker. */
6296 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
6298 m
->p_flags
= PF_R
| PF_W
| PF_X
;
6299 m
->p_flags_valid
= 1;
6303 && m
->count
== 1 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
6305 static const char *sec_names
[] =
6307 ".dynamic", ".dynstr", ".dynsym", ".hash"
6311 struct elf_segment_map
*n
;
6315 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
6317 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
6318 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
6324 sz
= s
->_cooked_size
;
6327 if (high
< s
->vma
+ sz
)
6333 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
6334 if ((s
->flags
& SEC_LOAD
) != 0
6337 + (s
->_cooked_size
!=
6338 0 ? s
->_cooked_size
: s
->_raw_size
)) <= high
))
6341 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
6342 n
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6349 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
6351 if ((s
->flags
& SEC_LOAD
) != 0
6354 + (s
->_cooked_size
!= 0 ?
6355 s
->_cooked_size
: s
->_raw_size
)) <= high
))
6369 /* Return the section that should be marked against GC for a given
6373 _bfd_mips_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
6375 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
6376 Elf_Internal_Rela
*rel
;
6377 struct elf_link_hash_entry
*h
;
6378 Elf_Internal_Sym
*sym
;
6380 /* ??? Do mips16 stub sections need to be handled special? */
6384 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
6386 case R_MIPS_GNU_VTINHERIT
:
6387 case R_MIPS_GNU_VTENTRY
:
6391 switch (h
->root
.type
)
6393 case bfd_link_hash_defined
:
6394 case bfd_link_hash_defweak
:
6395 return h
->root
.u
.def
.section
;
6397 case bfd_link_hash_common
:
6398 return h
->root
.u
.c
.p
->section
;
6406 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6411 /* Update the got entry reference counts for the section being removed. */
6414 _bfd_mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6415 bfd
*abfd ATTRIBUTE_UNUSED
;
6416 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
6417 asection
*sec ATTRIBUTE_UNUSED
;
6418 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
6421 Elf_Internal_Shdr
*symtab_hdr
;
6422 struct elf_link_hash_entry
**sym_hashes
;
6423 bfd_signed_vma
*local_got_refcounts
;
6424 const Elf_Internal_Rela
*rel
, *relend
;
6425 unsigned long r_symndx
;
6426 struct elf_link_hash_entry
*h
;
6428 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6429 sym_hashes
= elf_sym_hashes (abfd
);
6430 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6432 relend
= relocs
+ sec
->reloc_count
;
6433 for (rel
= relocs
; rel
< relend
; rel
++)
6434 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
6438 case R_MIPS_CALL_HI16
:
6439 case R_MIPS_CALL_LO16
:
6440 case R_MIPS_GOT_HI16
:
6441 case R_MIPS_GOT_LO16
:
6442 case R_MIPS_GOT_DISP
:
6443 case R_MIPS_GOT_PAGE
:
6444 case R_MIPS_GOT_OFST
:
6445 /* ??? It would seem that the existing MIPS code does no sort
6446 of reference counting or whatnot on its GOT and PLT entries,
6447 so it is not possible to garbage collect them at this time. */
6458 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
6459 hiding the old indirect symbol. Process additional relocation
6460 information. Also called for weakdefs, in which case we just let
6461 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
6464 _bfd_mips_elf_copy_indirect_symbol (bed
, dir
, ind
)
6465 struct elf_backend_data
*bed
;
6466 struct elf_link_hash_entry
*dir
, *ind
;
6468 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
6470 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
6472 if (ind
->root
.type
!= bfd_link_hash_indirect
)
6475 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
6476 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
6477 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
6478 if (indmips
->readonly_reloc
)
6479 dirmips
->readonly_reloc
= TRUE
;
6480 if (dirmips
->min_dyn_reloc_index
== 0
6481 || (indmips
->min_dyn_reloc_index
!= 0
6482 && indmips
->min_dyn_reloc_index
< dirmips
->min_dyn_reloc_index
))
6483 dirmips
->min_dyn_reloc_index
= indmips
->min_dyn_reloc_index
;
6484 if (indmips
->no_fn_stub
)
6485 dirmips
->no_fn_stub
= TRUE
;
6489 _bfd_mips_elf_hide_symbol (info
, entry
, force_local
)
6490 struct bfd_link_info
*info
;
6491 struct elf_link_hash_entry
*entry
;
6492 bfd_boolean force_local
;
6496 struct mips_got_info
*g
;
6497 struct mips_elf_link_hash_entry
*h
;
6499 h
= (struct mips_elf_link_hash_entry
*) entry
;
6500 if (h
->forced_local
)
6502 h
->forced_local
= TRUE
;
6504 dynobj
= elf_hash_table (info
)->dynobj
;
6505 got
= bfd_get_section_by_name (dynobj
, ".got");
6506 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
6508 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
6510 /* FIXME: Do we allocate too much GOT space here? */
6512 got
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
6518 _bfd_mips_elf_discard_info (abfd
, cookie
, info
)
6520 struct elf_reloc_cookie
*cookie
;
6521 struct bfd_link_info
*info
;
6524 bfd_boolean ret
= FALSE
;
6525 unsigned char *tdata
;
6528 o
= bfd_get_section_by_name (abfd
, ".pdr");
6531 if (o
->_raw_size
== 0)
6533 if (o
->_raw_size
% PDR_SIZE
!= 0)
6535 if (o
->output_section
!= NULL
6536 && bfd_is_abs_section (o
->output_section
))
6539 tdata
= bfd_zmalloc (o
->_raw_size
/ PDR_SIZE
);
6543 cookie
->rels
= (MNAME(abfd
,_bfd_elf
,link_read_relocs
)
6544 (abfd
, o
, (PTR
) NULL
,
6545 (Elf_Internal_Rela
*) NULL
,
6546 info
->keep_memory
));
6553 cookie
->rel
= cookie
->rels
;
6554 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
6556 for (i
= 0, skip
= 0; i
< o
->_raw_size
; i
++)
6558 if (MNAME(abfd
,_bfd_elf
,reloc_symbol_deleted_p
) (i
* PDR_SIZE
, cookie
))
6567 elf_section_data (o
)->tdata
= tdata
;
6568 o
->_cooked_size
= o
->_raw_size
- skip
* PDR_SIZE
;
6574 if (! info
->keep_memory
)
6575 free (cookie
->rels
);
6581 _bfd_mips_elf_ignore_discarded_relocs (sec
)
6584 if (strcmp (sec
->name
, ".pdr") == 0)
6590 _bfd_mips_elf_write_section (output_bfd
, sec
, contents
)
6595 bfd_byte
*to
, *from
, *end
;
6598 if (strcmp (sec
->name
, ".pdr") != 0)
6601 if (elf_section_data (sec
)->tdata
== NULL
)
6605 end
= contents
+ sec
->_raw_size
;
6606 for (from
= contents
, i
= 0;
6608 from
+= PDR_SIZE
, i
++)
6610 if (((unsigned char *) elf_section_data (sec
)->tdata
)[i
] == 1)
6613 memcpy (to
, from
, PDR_SIZE
);
6616 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
6617 (file_ptr
) sec
->output_offset
,
6622 /* MIPS ELF uses a special find_nearest_line routine in order the
6623 handle the ECOFF debugging information. */
6625 struct mips_elf_find_line
6627 struct ecoff_debug_info d
;
6628 struct ecoff_find_line i
;
6632 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
6633 functionname_ptr
, line_ptr
)
6638 const char **filename_ptr
;
6639 const char **functionname_ptr
;
6640 unsigned int *line_ptr
;
6644 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
6645 filename_ptr
, functionname_ptr
,
6649 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
6650 filename_ptr
, functionname_ptr
,
6652 (unsigned) (ABI_64_P (abfd
) ? 8 : 0),
6653 &elf_tdata (abfd
)->dwarf2_find_line_info
))
6656 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
6660 struct mips_elf_find_line
*fi
;
6661 const struct ecoff_debug_swap
* const swap
=
6662 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
6664 /* If we are called during a link, mips_elf_final_link may have
6665 cleared the SEC_HAS_CONTENTS field. We force it back on here
6666 if appropriate (which it normally will be). */
6667 origflags
= msec
->flags
;
6668 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
6669 msec
->flags
|= SEC_HAS_CONTENTS
;
6671 fi
= elf_tdata (abfd
)->find_line_info
;
6674 bfd_size_type external_fdr_size
;
6677 struct fdr
*fdr_ptr
;
6678 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
6680 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
6683 msec
->flags
= origflags
;
6687 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
6689 msec
->flags
= origflags
;
6693 /* Swap in the FDR information. */
6694 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
6695 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
6696 if (fi
->d
.fdr
== NULL
)
6698 msec
->flags
= origflags
;
6701 external_fdr_size
= swap
->external_fdr_size
;
6702 fdr_ptr
= fi
->d
.fdr
;
6703 fraw_src
= (char *) fi
->d
.external_fdr
;
6704 fraw_end
= (fraw_src
6705 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
6706 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
6707 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
6709 elf_tdata (abfd
)->find_line_info
= fi
;
6711 /* Note that we don't bother to ever free this information.
6712 find_nearest_line is either called all the time, as in
6713 objdump -l, so the information should be saved, or it is
6714 rarely called, as in ld error messages, so the memory
6715 wasted is unimportant. Still, it would probably be a
6716 good idea for free_cached_info to throw it away. */
6719 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
6720 &fi
->i
, filename_ptr
, functionname_ptr
,
6723 msec
->flags
= origflags
;
6727 msec
->flags
= origflags
;
6730 /* Fall back on the generic ELF find_nearest_line routine. */
6732 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
6733 filename_ptr
, functionname_ptr
,
6737 /* When are writing out the .options or .MIPS.options section,
6738 remember the bytes we are writing out, so that we can install the
6739 GP value in the section_processing routine. */
6742 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
6747 bfd_size_type count
;
6749 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
6753 if (elf_section_data (section
) == NULL
)
6755 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
6756 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
6757 if (elf_section_data (section
) == NULL
)
6760 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
6765 if (section
->_cooked_size
!= 0)
6766 size
= section
->_cooked_size
;
6768 size
= section
->_raw_size
;
6769 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
6772 elf_section_data (section
)->tdata
= (PTR
) c
;
6775 memcpy (c
+ offset
, location
, (size_t) count
);
6778 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
6782 /* This is almost identical to bfd_generic_get_... except that some
6783 MIPS relocations need to be handled specially. Sigh. */
6786 _bfd_elf_mips_get_relocated_section_contents (abfd
, link_info
, link_order
,
6787 data
, relocateable
, symbols
)
6789 struct bfd_link_info
*link_info
;
6790 struct bfd_link_order
*link_order
;
6792 bfd_boolean relocateable
;
6795 /* Get enough memory to hold the stuff */
6796 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
6797 asection
*input_section
= link_order
->u
.indirect
.section
;
6799 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
6800 arelent
**reloc_vector
= NULL
;
6806 reloc_vector
= (arelent
**) bfd_malloc ((bfd_size_type
) reloc_size
);
6807 if (reloc_vector
== NULL
&& reloc_size
!= 0)
6810 /* read in the section */
6811 if (!bfd_get_section_contents (input_bfd
,
6815 input_section
->_raw_size
))
6818 /* We're not relaxing the section, so just copy the size info */
6819 input_section
->_cooked_size
= input_section
->_raw_size
;
6820 input_section
->reloc_done
= TRUE
;
6822 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
6826 if (reloc_count
< 0)
6829 if (reloc_count
> 0)
6834 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
6837 struct bfd_hash_entry
*h
;
6838 struct bfd_link_hash_entry
*lh
;
6839 /* Skip all this stuff if we aren't mixing formats. */
6840 if (abfd
&& input_bfd
6841 && abfd
->xvec
== input_bfd
->xvec
)
6845 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
6846 lh
= (struct bfd_link_hash_entry
*) h
;
6853 case bfd_link_hash_undefined
:
6854 case bfd_link_hash_undefweak
:
6855 case bfd_link_hash_common
:
6858 case bfd_link_hash_defined
:
6859 case bfd_link_hash_defweak
:
6861 gp
= lh
->u
.def
.value
;
6863 case bfd_link_hash_indirect
:
6864 case bfd_link_hash_warning
:
6866 /* @@FIXME ignoring warning for now */
6868 case bfd_link_hash_new
:
6877 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
6880 char *error_message
= (char *) NULL
;
6881 bfd_reloc_status_type r
;
6883 /* Specific to MIPS: Deal with relocation types that require
6884 knowing the gp of the output bfd. */
6885 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
6886 if (bfd_is_abs_section (sym
->section
) && abfd
)
6888 /* The special_function wouldn't get called anyway. */
6892 /* The gp isn't there; let the special function code
6893 fall over on its own. */
6895 else if ((*parent
)->howto
->special_function
6896 == _bfd_mips_elf32_gprel16_reloc
)
6898 /* bypass special_function call */
6899 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
6900 input_section
, relocateable
,
6902 goto skip_bfd_perform_relocation
;
6904 /* end mips specific stuff */
6906 r
= bfd_perform_relocation (input_bfd
,
6910 relocateable
? abfd
: (bfd
*) NULL
,
6912 skip_bfd_perform_relocation
:
6916 asection
*os
= input_section
->output_section
;
6918 /* A partial link, so keep the relocs */
6919 os
->orelocation
[os
->reloc_count
] = *parent
;
6923 if (r
!= bfd_reloc_ok
)
6927 case bfd_reloc_undefined
:
6928 if (!((*link_info
->callbacks
->undefined_symbol
)
6929 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6930 input_bfd
, input_section
, (*parent
)->address
,
6934 case bfd_reloc_dangerous
:
6935 BFD_ASSERT (error_message
!= (char *) NULL
);
6936 if (!((*link_info
->callbacks
->reloc_dangerous
)
6937 (link_info
, error_message
, input_bfd
, input_section
,
6938 (*parent
)->address
)))
6941 case bfd_reloc_overflow
:
6942 if (!((*link_info
->callbacks
->reloc_overflow
)
6943 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6944 (*parent
)->howto
->name
, (*parent
)->addend
,
6945 input_bfd
, input_section
, (*parent
)->address
)))
6948 case bfd_reloc_outofrange
:
6957 if (reloc_vector
!= NULL
)
6958 free (reloc_vector
);
6962 if (reloc_vector
!= NULL
)
6963 free (reloc_vector
);
6967 /* Create a MIPS ELF linker hash table. */
6969 struct bfd_link_hash_table
*
6970 _bfd_mips_elf_link_hash_table_create (abfd
)
6973 struct mips_elf_link_hash_table
*ret
;
6974 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
6976 ret
= (struct mips_elf_link_hash_table
*) bfd_malloc (amt
);
6977 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
6980 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
6981 mips_elf_link_hash_newfunc
))
6988 /* We no longer use this. */
6989 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
6990 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
6992 ret
->procedure_count
= 0;
6993 ret
->compact_rel_size
= 0;
6994 ret
->use_rld_obj_head
= FALSE
;
6996 ret
->mips16_stubs_seen
= FALSE
;
6998 return &ret
->root
.root
;
7001 /* We need to use a special link routine to handle the .reginfo and
7002 the .mdebug sections. We need to merge all instances of these
7003 sections together, not write them all out sequentially. */
7006 _bfd_mips_elf_final_link (abfd
, info
)
7008 struct bfd_link_info
*info
;
7012 struct bfd_link_order
*p
;
7013 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
7014 asection
*rtproc_sec
;
7015 Elf32_RegInfo reginfo
;
7016 struct ecoff_debug_info debug
;
7017 const struct ecoff_debug_swap
*swap
7018 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
7019 HDRR
*symhdr
= &debug
.symbolic_header
;
7020 PTR mdebug_handle
= NULL
;
7026 static const char * const secname
[] =
7028 ".text", ".init", ".fini", ".data",
7029 ".rodata", ".sdata", ".sbss", ".bss"
7031 static const int sc
[] =
7033 scText
, scInit
, scFini
, scData
,
7034 scRData
, scSData
, scSBss
, scBss
7037 /* If all the things we linked together were PIC, but we're
7038 producing an executable (rather than a shared object), then the
7039 resulting file is CPIC (i.e., it calls PIC code.) */
7041 && !info
->relocateable
7042 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
7044 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
7045 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
7048 /* We'd carefully arranged the dynamic symbol indices, and then the
7049 generic size_dynamic_sections renumbered them out from under us.
7050 Rather than trying somehow to prevent the renumbering, just do
7052 if (elf_hash_table (info
)->dynamic_sections_created
)
7056 struct mips_got_info
*g
;
7058 /* When we resort, we must tell mips_elf_sort_hash_table what
7059 the lowest index it may use is. That's the number of section
7060 symbols we're going to add. The generic ELF linker only
7061 adds these symbols when building a shared object. Note that
7062 we count the sections after (possibly) removing the .options
7064 if (! mips_elf_sort_hash_table (info
, (info
->shared
7065 ? bfd_count_sections (abfd
) + 1
7069 /* Make sure we didn't grow the global .got region. */
7070 dynobj
= elf_hash_table (info
)->dynobj
;
7071 got
= bfd_get_section_by_name (dynobj
, ".got");
7072 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
7074 if (g
->global_gotsym
!= NULL
)
7075 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
7076 - g
->global_gotsym
->dynindx
)
7077 <= g
->global_gotno
);
7081 /* We want to set the GP value for ld -r. */
7082 /* On IRIX5, we omit the .options section. On IRIX6, however, we
7083 include it, even though we don't process it quite right. (Some
7084 entries are supposed to be merged.) Empirically, we seem to be
7085 better off including it then not. */
7086 if (IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
7087 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
7089 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
7091 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
7092 if (p
->type
== bfd_indirect_link_order
)
7093 p
->u
.indirect
.section
->flags
&= ~SEC_HAS_CONTENTS
;
7094 (*secpp
)->link_order_head
= NULL
;
7095 bfd_section_list_remove (abfd
, secpp
);
7096 --abfd
->section_count
;
7102 /* We include .MIPS.options, even though we don't process it quite right.
7103 (Some entries are supposed to be merged.) At IRIX6 empirically we seem
7104 to be better off including it than not. */
7105 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
7107 if (strcmp ((*secpp
)->name
, ".MIPS.options") == 0)
7109 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
7110 if (p
->type
== bfd_indirect_link_order
)
7111 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
7112 (*secpp
)->link_order_head
= NULL
;
7113 bfd_section_list_remove (abfd
, secpp
);
7114 --abfd
->section_count
;
7121 /* Get a value for the GP register. */
7122 if (elf_gp (abfd
) == 0)
7124 struct bfd_link_hash_entry
*h
;
7126 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
7127 if (h
!= (struct bfd_link_hash_entry
*) NULL
7128 && h
->type
== bfd_link_hash_defined
)
7129 elf_gp (abfd
) = (h
->u
.def
.value
7130 + h
->u
.def
.section
->output_section
->vma
7131 + h
->u
.def
.section
->output_offset
);
7132 else if (info
->relocateable
)
7134 bfd_vma lo
= MINUS_ONE
;
7136 /* Find the GP-relative section with the lowest offset. */
7137 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
7139 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
7142 /* And calculate GP relative to that. */
7143 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
7147 /* If the relocate_section function needs to do a reloc
7148 involving the GP value, it should make a reloc_dangerous
7149 callback to warn that GP is not defined. */
7153 /* Go through the sections and collect the .reginfo and .mdebug
7157 gptab_data_sec
= NULL
;
7158 gptab_bss_sec
= NULL
;
7159 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
7161 if (strcmp (o
->name
, ".reginfo") == 0)
7163 memset (®info
, 0, sizeof reginfo
);
7165 /* We have found the .reginfo section in the output file.
7166 Look through all the link_orders comprising it and merge
7167 the information together. */
7168 for (p
= o
->link_order_head
;
7169 p
!= (struct bfd_link_order
*) NULL
;
7172 asection
*input_section
;
7174 Elf32_External_RegInfo ext
;
7177 if (p
->type
!= bfd_indirect_link_order
)
7179 if (p
->type
== bfd_data_link_order
)
7184 input_section
= p
->u
.indirect
.section
;
7185 input_bfd
= input_section
->owner
;
7187 /* The linker emulation code has probably clobbered the
7188 size to be zero bytes. */
7189 if (input_section
->_raw_size
== 0)
7190 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
7192 if (! bfd_get_section_contents (input_bfd
, input_section
,
7195 (bfd_size_type
) sizeof ext
))
7198 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
7200 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
7201 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
7202 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
7203 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
7204 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
7206 /* ri_gp_value is set by the function
7207 mips_elf32_section_processing when the section is
7208 finally written out. */
7210 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7211 elf_link_input_bfd ignores this section. */
7212 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7215 /* Size has been set in _bfd_mips_elf_always_size_sections. */
7216 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
7218 /* Skip this section later on (I don't think this currently
7219 matters, but someday it might). */
7220 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7225 if (strcmp (o
->name
, ".mdebug") == 0)
7227 struct extsym_info einfo
;
7230 /* We have found the .mdebug section in the output file.
7231 Look through all the link_orders comprising it and merge
7232 the information together. */
7233 symhdr
->magic
= swap
->sym_magic
;
7234 /* FIXME: What should the version stamp be? */
7236 symhdr
->ilineMax
= 0;
7240 symhdr
->isymMax
= 0;
7241 symhdr
->ioptMax
= 0;
7242 symhdr
->iauxMax
= 0;
7244 symhdr
->issExtMax
= 0;
7247 symhdr
->iextMax
= 0;
7249 /* We accumulate the debugging information itself in the
7250 debug_info structure. */
7252 debug
.external_dnr
= NULL
;
7253 debug
.external_pdr
= NULL
;
7254 debug
.external_sym
= NULL
;
7255 debug
.external_opt
= NULL
;
7256 debug
.external_aux
= NULL
;
7258 debug
.ssext
= debug
.ssext_end
= NULL
;
7259 debug
.external_fdr
= NULL
;
7260 debug
.external_rfd
= NULL
;
7261 debug
.external_ext
= debug
.external_ext_end
= NULL
;
7263 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
7264 if (mdebug_handle
== (PTR
) NULL
)
7268 esym
.cobol_main
= 0;
7272 esym
.asym
.iss
= issNil
;
7273 esym
.asym
.st
= stLocal
;
7274 esym
.asym
.reserved
= 0;
7275 esym
.asym
.index
= indexNil
;
7277 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
7279 esym
.asym
.sc
= sc
[i
];
7280 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
7283 esym
.asym
.value
= s
->vma
;
7284 last
= s
->vma
+ s
->_raw_size
;
7287 esym
.asym
.value
= last
;
7288 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
7293 for (p
= o
->link_order_head
;
7294 p
!= (struct bfd_link_order
*) NULL
;
7297 asection
*input_section
;
7299 const struct ecoff_debug_swap
*input_swap
;
7300 struct ecoff_debug_info input_debug
;
7304 if (p
->type
!= bfd_indirect_link_order
)
7306 if (p
->type
== bfd_data_link_order
)
7311 input_section
= p
->u
.indirect
.section
;
7312 input_bfd
= input_section
->owner
;
7314 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
7315 || (get_elf_backend_data (input_bfd
)
7316 ->elf_backend_ecoff_debug_swap
) == NULL
)
7318 /* I don't know what a non MIPS ELF bfd would be
7319 doing with a .mdebug section, but I don't really
7320 want to deal with it. */
7324 input_swap
= (get_elf_backend_data (input_bfd
)
7325 ->elf_backend_ecoff_debug_swap
);
7327 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
7329 /* The ECOFF linking code expects that we have already
7330 read in the debugging information and set up an
7331 ecoff_debug_info structure, so we do that now. */
7332 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
7336 if (! (bfd_ecoff_debug_accumulate
7337 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
7338 &input_debug
, input_swap
, info
)))
7341 /* Loop through the external symbols. For each one with
7342 interesting information, try to find the symbol in
7343 the linker global hash table and save the information
7344 for the output external symbols. */
7345 eraw_src
= input_debug
.external_ext
;
7346 eraw_end
= (eraw_src
7347 + (input_debug
.symbolic_header
.iextMax
7348 * input_swap
->external_ext_size
));
7350 eraw_src
< eraw_end
;
7351 eraw_src
+= input_swap
->external_ext_size
)
7355 struct mips_elf_link_hash_entry
*h
;
7357 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
7358 if (ext
.asym
.sc
== scNil
7359 || ext
.asym
.sc
== scUndefined
7360 || ext
.asym
.sc
== scSUndefined
)
7363 name
= input_debug
.ssext
+ ext
.asym
.iss
;
7364 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
7365 name
, FALSE
, FALSE
, TRUE
);
7366 if (h
== NULL
|| h
->esym
.ifd
!= -2)
7372 < input_debug
.symbolic_header
.ifdMax
);
7373 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
7379 /* Free up the information we just read. */
7380 free (input_debug
.line
);
7381 free (input_debug
.external_dnr
);
7382 free (input_debug
.external_pdr
);
7383 free (input_debug
.external_sym
);
7384 free (input_debug
.external_opt
);
7385 free (input_debug
.external_aux
);
7386 free (input_debug
.ss
);
7387 free (input_debug
.ssext
);
7388 free (input_debug
.external_fdr
);
7389 free (input_debug
.external_rfd
);
7390 free (input_debug
.external_ext
);
7392 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7393 elf_link_input_bfd ignores this section. */
7394 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7397 if (SGI_COMPAT (abfd
) && info
->shared
)
7399 /* Create .rtproc section. */
7400 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
7401 if (rtproc_sec
== NULL
)
7403 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7404 | SEC_LINKER_CREATED
| SEC_READONLY
);
7406 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
7407 if (rtproc_sec
== NULL
7408 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
7409 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
7413 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
7419 /* Build the external symbol information. */
7422 einfo
.debug
= &debug
;
7424 einfo
.failed
= FALSE
;
7425 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7426 mips_elf_output_extsym
,
7431 /* Set the size of the .mdebug section. */
7432 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
7434 /* Skip this section later on (I don't think this currently
7435 matters, but someday it might). */
7436 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7441 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
7443 const char *subname
;
7446 Elf32_External_gptab
*ext_tab
;
7449 /* The .gptab.sdata and .gptab.sbss sections hold
7450 information describing how the small data area would
7451 change depending upon the -G switch. These sections
7452 not used in executables files. */
7453 if (! info
->relocateable
)
7455 for (p
= o
->link_order_head
;
7456 p
!= (struct bfd_link_order
*) NULL
;
7459 asection
*input_section
;
7461 if (p
->type
!= bfd_indirect_link_order
)
7463 if (p
->type
== bfd_data_link_order
)
7468 input_section
= p
->u
.indirect
.section
;
7470 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7471 elf_link_input_bfd ignores this section. */
7472 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7475 /* Skip this section later on (I don't think this
7476 currently matters, but someday it might). */
7477 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7479 /* Really remove the section. */
7480 for (secpp
= &abfd
->sections
;
7482 secpp
= &(*secpp
)->next
)
7484 bfd_section_list_remove (abfd
, secpp
);
7485 --abfd
->section_count
;
7490 /* There is one gptab for initialized data, and one for
7491 uninitialized data. */
7492 if (strcmp (o
->name
, ".gptab.sdata") == 0)
7494 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
7498 (*_bfd_error_handler
)
7499 (_("%s: illegal section name `%s'"),
7500 bfd_get_filename (abfd
), o
->name
);
7501 bfd_set_error (bfd_error_nonrepresentable_section
);
7505 /* The linker script always combines .gptab.data and
7506 .gptab.sdata into .gptab.sdata, and likewise for
7507 .gptab.bss and .gptab.sbss. It is possible that there is
7508 no .sdata or .sbss section in the output file, in which
7509 case we must change the name of the output section. */
7510 subname
= o
->name
+ sizeof ".gptab" - 1;
7511 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
7513 if (o
== gptab_data_sec
)
7514 o
->name
= ".gptab.data";
7516 o
->name
= ".gptab.bss";
7517 subname
= o
->name
+ sizeof ".gptab" - 1;
7518 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
7521 /* Set up the first entry. */
7523 amt
= c
* sizeof (Elf32_gptab
);
7524 tab
= (Elf32_gptab
*) bfd_malloc (amt
);
7527 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
7528 tab
[0].gt_header
.gt_unused
= 0;
7530 /* Combine the input sections. */
7531 for (p
= o
->link_order_head
;
7532 p
!= (struct bfd_link_order
*) NULL
;
7535 asection
*input_section
;
7539 bfd_size_type gpentry
;
7541 if (p
->type
!= bfd_indirect_link_order
)
7543 if (p
->type
== bfd_data_link_order
)
7548 input_section
= p
->u
.indirect
.section
;
7549 input_bfd
= input_section
->owner
;
7551 /* Combine the gptab entries for this input section one
7552 by one. We know that the input gptab entries are
7553 sorted by ascending -G value. */
7554 size
= bfd_section_size (input_bfd
, input_section
);
7556 for (gpentry
= sizeof (Elf32_External_gptab
);
7558 gpentry
+= sizeof (Elf32_External_gptab
))
7560 Elf32_External_gptab ext_gptab
;
7561 Elf32_gptab int_gptab
;
7567 if (! (bfd_get_section_contents
7568 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
7570 (bfd_size_type
) sizeof (Elf32_External_gptab
))))
7576 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
7578 val
= int_gptab
.gt_entry
.gt_g_value
;
7579 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
7582 for (look
= 1; look
< c
; look
++)
7584 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
7585 tab
[look
].gt_entry
.gt_bytes
+= add
;
7587 if (tab
[look
].gt_entry
.gt_g_value
== val
)
7593 Elf32_gptab
*new_tab
;
7596 /* We need a new table entry. */
7597 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
7598 new_tab
= (Elf32_gptab
*) bfd_realloc ((PTR
) tab
, amt
);
7599 if (new_tab
== NULL
)
7605 tab
[c
].gt_entry
.gt_g_value
= val
;
7606 tab
[c
].gt_entry
.gt_bytes
= add
;
7608 /* Merge in the size for the next smallest -G
7609 value, since that will be implied by this new
7612 for (look
= 1; look
< c
; look
++)
7614 if (tab
[look
].gt_entry
.gt_g_value
< val
7616 || (tab
[look
].gt_entry
.gt_g_value
7617 > tab
[max
].gt_entry
.gt_g_value
)))
7621 tab
[c
].gt_entry
.gt_bytes
+=
7622 tab
[max
].gt_entry
.gt_bytes
;
7627 last
= int_gptab
.gt_entry
.gt_bytes
;
7630 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7631 elf_link_input_bfd ignores this section. */
7632 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7635 /* The table must be sorted by -G value. */
7637 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
7639 /* Swap out the table. */
7640 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
7641 ext_tab
= (Elf32_External_gptab
*) bfd_alloc (abfd
, amt
);
7642 if (ext_tab
== NULL
)
7648 for (j
= 0; j
< c
; j
++)
7649 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
7652 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
7653 o
->contents
= (bfd_byte
*) ext_tab
;
7655 /* Skip this section later on (I don't think this currently
7656 matters, but someday it might). */
7657 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7661 /* Invoke the regular ELF backend linker to do all the work. */
7662 if (!MNAME(abfd
,bfd_elf
,bfd_final_link
) (abfd
, info
))
7665 /* Now write out the computed sections. */
7667 if (reginfo_sec
!= (asection
*) NULL
)
7669 Elf32_External_RegInfo ext
;
7671 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
7672 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
7674 (bfd_size_type
) sizeof ext
))
7678 if (mdebug_sec
!= (asection
*) NULL
)
7680 BFD_ASSERT (abfd
->output_has_begun
);
7681 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
7683 mdebug_sec
->filepos
))
7686 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
7689 if (gptab_data_sec
!= (asection
*) NULL
)
7691 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
7692 gptab_data_sec
->contents
,
7694 gptab_data_sec
->_raw_size
))
7698 if (gptab_bss_sec
!= (asection
*) NULL
)
7700 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
7701 gptab_bss_sec
->contents
,
7703 gptab_bss_sec
->_raw_size
))
7707 if (SGI_COMPAT (abfd
))
7709 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
7710 if (rtproc_sec
!= NULL
)
7712 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
7713 rtproc_sec
->contents
,
7715 rtproc_sec
->_raw_size
))
7723 /* Return TRUE if machine EXTENSION is an extension of machine BASE,
7724 meaning that it should be safe to link code for the two machines
7725 and set the output machine to EXTENSION. EXTENSION and BASE are
7726 both submasks of EF_MIPS_MACH. */
7729 _bfd_mips_elf_mach_extends_p (base
, extension
)
7730 flagword base
, extension
;
7732 /* The vr5500 ISA is an extension of the core vr5400 ISA, but doesn't
7733 include the multimedia stuff. It seems better to allow vr5400
7734 and vr5500 code to be merged anyway, since many libraries will
7735 just use the core ISA. Perhaps we could add some sort of ASE
7736 flag if this ever proves a problem. */
7738 || (base
== E_MIPS_MACH_5400
&& extension
== E_MIPS_MACH_5500
)
7739 || (base
== E_MIPS_MACH_4100
&& extension
== E_MIPS_MACH_4111
)
7740 || (base
== E_MIPS_MACH_4100
&& extension
== E_MIPS_MACH_4120
));
7743 /* Merge backend specific data from an object file to the output
7744 object file when linking. */
7747 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
7754 bfd_boolean null_input_bfd
= TRUE
;
7757 /* Check if we have the same endianess */
7758 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
7761 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
7762 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
7765 new_flags
= elf_elfheader (ibfd
)->e_flags
;
7766 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
7767 old_flags
= elf_elfheader (obfd
)->e_flags
;
7769 if (! elf_flags_init (obfd
))
7771 elf_flags_init (obfd
) = TRUE
;
7772 elf_elfheader (obfd
)->e_flags
= new_flags
;
7773 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
7774 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
7776 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
7777 && bfd_get_arch_info (obfd
)->the_default
)
7779 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
7780 bfd_get_mach (ibfd
)))
7787 /* Check flag compatibility. */
7789 new_flags
&= ~EF_MIPS_NOREORDER
;
7790 old_flags
&= ~EF_MIPS_NOREORDER
;
7792 if (new_flags
== old_flags
)
7795 /* Check to see if the input BFD actually contains any sections.
7796 If not, its flags may not have been initialised either, but it cannot
7797 actually cause any incompatibility. */
7798 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7800 /* Ignore synthetic sections and empty .text, .data and .bss sections
7801 which are automatically generated by gas. */
7802 if (strcmp (sec
->name
, ".reginfo")
7803 && strcmp (sec
->name
, ".mdebug")
7804 && ((!strcmp (sec
->name
, ".text")
7805 || !strcmp (sec
->name
, ".data")
7806 || !strcmp (sec
->name
, ".bss"))
7807 && sec
->_raw_size
!= 0))
7809 null_input_bfd
= FALSE
;
7818 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
7820 new_flags
&= ~EF_MIPS_PIC
;
7821 old_flags
&= ~EF_MIPS_PIC
;
7822 (*_bfd_error_handler
)
7823 (_("%s: linking PIC files with non-PIC files"),
7824 bfd_archive_filename (ibfd
));
7828 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
7830 new_flags
&= ~EF_MIPS_CPIC
;
7831 old_flags
&= ~EF_MIPS_CPIC
;
7832 (*_bfd_error_handler
)
7833 (_("%s: linking abicalls files with non-abicalls files"),
7834 bfd_archive_filename (ibfd
));
7838 /* Compare the ISA's. */
7839 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
7840 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
7842 int new_mach
= new_flags
& EF_MIPS_MACH
;
7843 int old_mach
= old_flags
& EF_MIPS_MACH
;
7844 int new_isa
= elf_mips_isa (new_flags
);
7845 int old_isa
= elf_mips_isa (old_flags
);
7847 /* If either has no machine specified, just compare the general isa's.
7848 Some combinations of machines are ok, if the isa's match. */
7849 if (new_mach
== old_mach
7850 || _bfd_mips_elf_mach_extends_p (new_mach
, old_mach
)
7851 || _bfd_mips_elf_mach_extends_p (old_mach
, new_mach
))
7853 /* Don't warn about mixing code using 32-bit ISAs, or mixing code
7854 using 64-bit ISAs. They will normally use the same data sizes
7855 and calling conventions. */
7857 if (( (new_isa
== 1 || new_isa
== 2 || new_isa
== 32)
7858 ^ (old_isa
== 1 || old_isa
== 2 || old_isa
== 32)) != 0)
7860 (*_bfd_error_handler
)
7861 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
7862 bfd_archive_filename (ibfd
), new_isa
, old_isa
);
7867 /* Do we need to update the mach field? */
7868 if (_bfd_mips_elf_mach_extends_p (old_mach
, new_mach
))
7870 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_MACH
;
7871 elf_elfheader (obfd
)->e_flags
|= new_mach
;
7874 /* Do we need to update the ISA field? */
7875 if (new_isa
> old_isa
)
7877 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_ARCH
;
7878 elf_elfheader (obfd
)->e_flags
7879 |= new_flags
& EF_MIPS_ARCH
;
7885 (*_bfd_error_handler
)
7886 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
7887 bfd_archive_filename (ibfd
),
7888 _bfd_elf_mips_mach (new_flags
),
7889 _bfd_elf_mips_mach (old_flags
));
7893 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
7894 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
7897 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
7898 does set EI_CLASS differently from any 32-bit ABI. */
7899 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
7900 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
7901 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
7903 /* Only error if both are set (to different values). */
7904 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
7905 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
7906 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
7908 (*_bfd_error_handler
)
7909 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
7910 bfd_archive_filename (ibfd
),
7911 elf_mips_abi_name (ibfd
),
7912 elf_mips_abi_name (obfd
));
7915 new_flags
&= ~EF_MIPS_ABI
;
7916 old_flags
&= ~EF_MIPS_ABI
;
7919 /* For now, allow arbitrary mixing of ASEs (retain the union). */
7920 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
7922 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
7924 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
7925 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
7928 /* Warn about any other mismatches */
7929 if (new_flags
!= old_flags
)
7931 (*_bfd_error_handler
)
7932 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
7933 bfd_archive_filename (ibfd
), (unsigned long) new_flags
,
7934 (unsigned long) old_flags
);
7940 bfd_set_error (bfd_error_bad_value
);
7947 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
7950 _bfd_mips_elf_set_private_flags (abfd
, flags
)
7954 BFD_ASSERT (!elf_flags_init (abfd
)
7955 || elf_elfheader (abfd
)->e_flags
== flags
);
7957 elf_elfheader (abfd
)->e_flags
= flags
;
7958 elf_flags_init (abfd
) = TRUE
;
7963 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
7967 FILE *file
= (FILE *) ptr
;
7969 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
7971 /* Print normal ELF private data. */
7972 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
7974 /* xgettext:c-format */
7975 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
7977 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
7978 fprintf (file
, _(" [abi=O32]"));
7979 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
7980 fprintf (file
, _(" [abi=O64]"));
7981 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
7982 fprintf (file
, _(" [abi=EABI32]"));
7983 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
7984 fprintf (file
, _(" [abi=EABI64]"));
7985 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
7986 fprintf (file
, _(" [abi unknown]"));
7987 else if (ABI_N32_P (abfd
))
7988 fprintf (file
, _(" [abi=N32]"));
7989 else if (ABI_64_P (abfd
))
7990 fprintf (file
, _(" [abi=64]"));
7992 fprintf (file
, _(" [no abi set]"));
7994 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
7995 fprintf (file
, _(" [mips1]"));
7996 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
7997 fprintf (file
, _(" [mips2]"));
7998 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
7999 fprintf (file
, _(" [mips3]"));
8000 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
8001 fprintf (file
, _(" [mips4]"));
8002 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
8003 fprintf (file
, _(" [mips5]"));
8004 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
8005 fprintf (file
, _(" [mips32]"));
8006 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
8007 fprintf (file
, _(" [mips64]"));
8009 fprintf (file
, _(" [unknown ISA]"));
8011 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
8012 fprintf (file
, _(" [mdmx]"));
8014 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
8015 fprintf (file
, _(" [mips16]"));
8017 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
8018 fprintf (file
, _(" [32bitmode]"));
8020 fprintf (file
, _(" [not 32bitmode]"));