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"
43 /* This structure is used to hold .got information when linking. It
44 is stored in the tdata field of the bfd_elf_section_data structure. */
48 /* The global symbol in the GOT with the lowest index in the dynamic
50 struct elf_link_hash_entry
*global_gotsym
;
51 /* The number of global .got entries. */
52 unsigned int global_gotno
;
53 /* The number of local .got entries. */
54 unsigned int local_gotno
;
55 /* The number of local .got entries we have used. */
56 unsigned int assigned_gotno
;
59 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
60 the dynamic symbols. */
62 struct mips_elf_hash_sort_data
64 /* The symbol in the global GOT with the lowest dynamic symbol table
66 struct elf_link_hash_entry
*low
;
67 /* The least dynamic symbol table index corresponding to a symbol
70 /* The greatest dynamic symbol table index not corresponding to a
71 symbol without a GOT entry. */
72 long max_non_got_dynindx
;
75 /* The MIPS ELF linker needs additional information for each symbol in
76 the global hash table. */
78 struct mips_elf_link_hash_entry
80 struct elf_link_hash_entry root
;
82 /* External symbol information. */
85 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
87 unsigned int possibly_dynamic_relocs
;
89 /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
90 a readonly section. */
91 bfd_boolean readonly_reloc
;
93 /* The index of the first dynamic relocation (in the .rel.dyn
94 section) against this symbol. */
95 unsigned int min_dyn_reloc_index
;
97 /* We must not create a stub for a symbol that has relocations
98 related to taking the function's address, i.e. any but
99 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition",
101 bfd_boolean no_fn_stub
;
103 /* If there is a stub that 32 bit functions should use to call this
104 16 bit function, this points to the section containing the stub. */
107 /* Whether we need the fn_stub; this is set if this symbol appears
108 in any relocs other than a 16 bit call. */
109 bfd_boolean need_fn_stub
;
111 /* If there is a stub that 16 bit functions should use to call this
112 32 bit function, this points to the section containing the stub. */
115 /* This is like the call_stub field, but it is used if the function
116 being called returns a floating point value. */
117 asection
*call_fp_stub
;
119 /* Are we forced local? .*/
120 bfd_boolean forced_local
;
123 /* MIPS ELF linker hash table. */
125 struct mips_elf_link_hash_table
127 struct elf_link_hash_table root
;
129 /* We no longer use this. */
130 /* String section indices for the dynamic section symbols. */
131 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
133 /* The number of .rtproc entries. */
134 bfd_size_type procedure_count
;
135 /* The size of the .compact_rel section (if SGI_COMPAT). */
136 bfd_size_type compact_rel_size
;
137 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
138 entry is set to the address of __rld_obj_head as in IRIX5. */
139 bfd_boolean use_rld_obj_head
;
140 /* This is the value of the __rld_map or __rld_obj_head symbol. */
142 /* This is set if we see any mips16 stub sections. */
143 bfd_boolean mips16_stubs_seen
;
146 /* Structure used to pass information to mips_elf_output_extsym. */
151 struct bfd_link_info
*info
;
152 struct ecoff_debug_info
*debug
;
153 const struct ecoff_debug_swap
*swap
;
157 /* The names of the runtime procedure table symbols used on IRIX5. */
159 static const char * const mips_elf_dynsym_rtproc_names
[] =
162 "_procedure_string_table",
163 "_procedure_table_size",
167 /* These structures are used to generate the .compact_rel section on
172 unsigned long id1
; /* Always one? */
173 unsigned long num
; /* Number of compact relocation entries. */
174 unsigned long id2
; /* Always two? */
175 unsigned long offset
; /* The file offset of the first relocation. */
176 unsigned long reserved0
; /* Zero? */
177 unsigned long reserved1
; /* Zero? */
186 bfd_byte reserved0
[4];
187 bfd_byte reserved1
[4];
188 } Elf32_External_compact_rel
;
192 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
193 unsigned int rtype
: 4; /* Relocation types. See below. */
194 unsigned int dist2to
: 8;
195 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
196 unsigned long konst
; /* KONST field. See below. */
197 unsigned long vaddr
; /* VADDR to be relocated. */
202 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
203 unsigned int rtype
: 4; /* Relocation types. See below. */
204 unsigned int dist2to
: 8;
205 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
206 unsigned long konst
; /* KONST field. See below. */
214 } Elf32_External_crinfo
;
220 } Elf32_External_crinfo2
;
222 /* These are the constants used to swap the bitfields in a crinfo. */
224 #define CRINFO_CTYPE (0x1)
225 #define CRINFO_CTYPE_SH (31)
226 #define CRINFO_RTYPE (0xf)
227 #define CRINFO_RTYPE_SH (27)
228 #define CRINFO_DIST2TO (0xff)
229 #define CRINFO_DIST2TO_SH (19)
230 #define CRINFO_RELVADDR (0x7ffff)
231 #define CRINFO_RELVADDR_SH (0)
233 /* A compact relocation info has long (3 words) or short (2 words)
234 formats. A short format doesn't have VADDR field and relvaddr
235 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
236 #define CRF_MIPS_LONG 1
237 #define CRF_MIPS_SHORT 0
239 /* There are 4 types of compact relocation at least. The value KONST
240 has different meaning for each type:
243 CT_MIPS_REL32 Address in data
244 CT_MIPS_WORD Address in word (XXX)
245 CT_MIPS_GPHI_LO GP - vaddr
246 CT_MIPS_JMPAD Address to jump
249 #define CRT_MIPS_REL32 0xa
250 #define CRT_MIPS_WORD 0xb
251 #define CRT_MIPS_GPHI_LO 0xc
252 #define CRT_MIPS_JMPAD 0xd
254 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
255 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
256 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
257 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
259 /* The structure of the runtime procedure descriptor created by the
260 loader for use by the static exception system. */
262 typedef struct runtime_pdr
{
263 bfd_vma adr
; /* memory address of start of procedure */
264 long regmask
; /* save register mask */
265 long regoffset
; /* save register offset */
266 long fregmask
; /* save floating point register mask */
267 long fregoffset
; /* save floating point register offset */
268 long frameoffset
; /* frame size */
269 short framereg
; /* frame pointer register */
270 short pcreg
; /* offset or reg of return pc */
271 long irpss
; /* index into the runtime string table */
273 struct exception_info
*exception_info
;/* pointer to exception array */
275 #define cbRPDR sizeof (RPDR)
276 #define rpdNil ((pRPDR) 0)
278 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
279 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
280 static void ecoff_swap_rpdr_out
281 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
282 static bfd_boolean mips_elf_create_procedure_table
283 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
284 struct ecoff_debug_info
*));
285 static bfd_boolean mips_elf_check_mips16_stubs
286 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
287 static void bfd_mips_elf32_swap_gptab_in
288 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
289 static void bfd_mips_elf32_swap_gptab_out
290 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
291 static void bfd_elf32_swap_compact_rel_out
292 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
293 static void bfd_elf32_swap_crinfo_out
294 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
296 static void bfd_mips_elf_swap_msym_in
297 PARAMS ((bfd
*, const Elf32_External_Msym
*, Elf32_Internal_Msym
*));
299 static void bfd_mips_elf_swap_msym_out
300 PARAMS ((bfd
*, const Elf32_Internal_Msym
*, Elf32_External_Msym
*));
301 static int sort_dynamic_relocs
302 PARAMS ((const void *, const void *));
303 static bfd_boolean mips_elf_output_extsym
304 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
305 static int gptab_compare
PARAMS ((const void *, const void *));
306 static asection
* mips_elf_got_section
PARAMS ((bfd
*));
307 static struct mips_got_info
*mips_elf_got_info
308 PARAMS ((bfd
*, asection
**));
309 static bfd_vma mips_elf_local_got_index
310 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
));
311 static bfd_vma mips_elf_global_got_index
312 PARAMS ((bfd
*, struct elf_link_hash_entry
*));
313 static bfd_vma mips_elf_got_page
314 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_vma
*));
315 static bfd_vma mips_elf_got16_entry
316 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_vma
, bfd_boolean
));
317 static bfd_vma mips_elf_got_offset_from_index
318 PARAMS ((bfd
*, bfd
*, bfd_vma
));
319 static bfd_vma mips_elf_create_local_got_entry
320 PARAMS ((bfd
*, struct mips_got_info
*, asection
*, bfd_vma
));
321 static bfd_boolean mips_elf_sort_hash_table
322 PARAMS ((struct bfd_link_info
*, unsigned long));
323 static bfd_boolean mips_elf_sort_hash_table_f
324 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
325 static bfd_boolean mips_elf_record_global_got_symbol
326 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*,
327 struct mips_got_info
*));
328 static const Elf_Internal_Rela
*mips_elf_next_relocation
329 PARAMS ((bfd
*, unsigned int, const Elf_Internal_Rela
*,
330 const Elf_Internal_Rela
*));
331 static bfd_boolean mips_elf_local_relocation_p
332 PARAMS ((bfd
*, const Elf_Internal_Rela
*, asection
**, bfd_boolean
));
333 static bfd_vma mips_elf_sign_extend
PARAMS ((bfd_vma
, int));
334 static bfd_boolean mips_elf_overflow_p
PARAMS ((bfd_vma
, int));
335 static bfd_vma mips_elf_high
PARAMS ((bfd_vma
));
336 static bfd_vma mips_elf_higher
PARAMS ((bfd_vma
));
337 static bfd_vma mips_elf_highest
PARAMS ((bfd_vma
));
338 static bfd_boolean mips_elf_create_compact_rel_section
339 PARAMS ((bfd
*, struct bfd_link_info
*));
340 static bfd_boolean mips_elf_create_got_section
341 PARAMS ((bfd
*, struct bfd_link_info
*));
342 static asection
*mips_elf_create_msym_section
344 static bfd_reloc_status_type mips_elf_calculate_relocation
345 PARAMS ((bfd
*, bfd
*, asection
*, struct bfd_link_info
*,
346 const Elf_Internal_Rela
*, bfd_vma
, reloc_howto_type
*,
347 Elf_Internal_Sym
*, asection
**, bfd_vma
*, const char **,
348 bfd_boolean
*, bfd_boolean
));
349 static bfd_vma mips_elf_obtain_contents
350 PARAMS ((reloc_howto_type
*, const Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
351 static bfd_boolean mips_elf_perform_relocation
352 PARAMS ((struct bfd_link_info
*, reloc_howto_type
*,
353 const Elf_Internal_Rela
*, bfd_vma
, bfd
*, asection
*, bfd_byte
*,
355 static bfd_boolean mips_elf_stub_section_p
356 PARAMS ((bfd
*, asection
*));
357 static void mips_elf_allocate_dynamic_relocations
358 PARAMS ((bfd
*, unsigned int));
359 static bfd_boolean mips_elf_create_dynamic_relocation
360 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
361 struct mips_elf_link_hash_entry
*, asection
*,
362 bfd_vma
, bfd_vma
*, asection
*));
363 static INLINE
int elf_mips_isa
PARAMS ((flagword
));
364 static INLINE
char* elf_mips_abi_name
PARAMS ((bfd
*));
365 static void mips_elf_irix6_finish_dynamic_symbol
366 PARAMS ((bfd
*, const char *, Elf_Internal_Sym
*));
367 static bfd_boolean _bfd_mips_elf_mach_extends_p
PARAMS ((flagword
, flagword
));
369 /* This will be used when we sort the dynamic relocation records. */
370 static bfd
*reldyn_sorting_bfd
;
372 /* Nonzero if ABFD is using the N32 ABI. */
374 #define ABI_N32_P(abfd) \
375 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
377 /* Nonzero if ABFD is using the N64 ABI. */
378 #define ABI_64_P(abfd) \
379 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
381 /* Nonzero if ABFD is using NewABI conventions. */
382 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
384 /* The IRIX compatibility level we are striving for. */
385 #define IRIX_COMPAT(abfd) \
386 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
388 /* Whether we are trying to be compatible with IRIX at all. */
389 #define SGI_COMPAT(abfd) \
390 (IRIX_COMPAT (abfd) != ict_none)
392 /* The name of the options section. */
393 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
394 (ABI_64_P (abfd) ? ".MIPS.options" : ".options")
396 /* The name of the stub section. */
397 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
398 (ABI_64_P (abfd) ? ".MIPS.stubs" : ".stub")
400 /* The size of an external REL relocation. */
401 #define MIPS_ELF_REL_SIZE(abfd) \
402 (get_elf_backend_data (abfd)->s->sizeof_rel)
404 /* The size of an external dynamic table entry. */
405 #define MIPS_ELF_DYN_SIZE(abfd) \
406 (get_elf_backend_data (abfd)->s->sizeof_dyn)
408 /* The size of a GOT entry. */
409 #define MIPS_ELF_GOT_SIZE(abfd) \
410 (get_elf_backend_data (abfd)->s->arch_size / 8)
412 /* The size of a symbol-table entry. */
413 #define MIPS_ELF_SYM_SIZE(abfd) \
414 (get_elf_backend_data (abfd)->s->sizeof_sym)
416 /* The default alignment for sections, as a power of two. */
417 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
418 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
420 /* Get word-sized data. */
421 #define MIPS_ELF_GET_WORD(abfd, ptr) \
422 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
424 /* Put out word-sized data. */
425 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
427 ? bfd_put_64 (abfd, val, ptr) \
428 : bfd_put_32 (abfd, val, ptr))
430 /* Add a dynamic symbol table-entry. */
432 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
433 (ABI_64_P (elf_hash_table (info)->dynobj) \
434 ? bfd_elf64_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val) \
435 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
437 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
438 (ABI_64_P (elf_hash_table (info)->dynobj) \
439 ? (abort (), FALSE) \
440 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
443 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
444 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
446 /* Determine whether the internal relocation of index REL_IDX is REL
447 (zero) or RELA (non-zero). The assumption is that, if there are
448 two relocation sections for this section, one of them is REL and
449 the other is RELA. If the index of the relocation we're testing is
450 in range for the first relocation section, check that the external
451 relocation size is that for RELA. It is also assumed that, if
452 rel_idx is not in range for the first section, and this first
453 section contains REL relocs, then the relocation is in the second
454 section, that is RELA. */
455 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
456 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
457 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
458 > (bfd_vma)(rel_idx)) \
459 == (elf_section_data (sec)->rel_hdr.sh_entsize \
460 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
461 : sizeof (Elf32_External_Rela))))
463 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
464 from smaller values. Start with zero, widen, *then* decrement. */
465 #define MINUS_ONE (((bfd_vma)0) - 1)
467 /* The number of local .got entries we reserve. */
468 #define MIPS_RESERVED_GOTNO (2)
470 /* Instructions which appear in a stub. For some reason the stub is
471 slightly different on an SGI system. */
472 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
473 #define STUB_LW(abfd) \
476 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
477 : 0x8f998010) /* lw t9,0x8010(gp) */ \
478 : 0x8f998010) /* lw t9,0x8000(gp) */
479 #define STUB_MOVE(abfd) \
480 (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */
481 #define STUB_JALR 0x0320f809 /* jal t9 */
482 #define STUB_LI16(abfd) \
483 (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */
484 #define MIPS_FUNCTION_STUB_SIZE (16)
486 /* The name of the dynamic interpreter. This is put in the .interp
489 #define ELF_DYNAMIC_INTERPRETER(abfd) \
490 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
491 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
492 : "/usr/lib/libc.so.1")
495 #define MNAME(bfd,pre,pos) \
496 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
497 #define ELF_R_SYM(bfd, i) \
498 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
499 #define ELF_R_TYPE(bfd, i) \
500 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
501 #define ELF_R_INFO(bfd, s, t) \
502 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
504 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
505 #define ELF_R_SYM(bfd, i) \
507 #define ELF_R_TYPE(bfd, i) \
509 #define ELF_R_INFO(bfd, s, t) \
510 (ELF32_R_INFO (s, t))
513 /* The mips16 compiler uses a couple of special sections to handle
514 floating point arguments.
516 Section names that look like .mips16.fn.FNNAME contain stubs that
517 copy floating point arguments from the fp regs to the gp regs and
518 then jump to FNNAME. If any 32 bit function calls FNNAME, the
519 call should be redirected to the stub instead. If no 32 bit
520 function calls FNNAME, the stub should be discarded. We need to
521 consider any reference to the function, not just a call, because
522 if the address of the function is taken we will need the stub,
523 since the address might be passed to a 32 bit function.
525 Section names that look like .mips16.call.FNNAME contain stubs
526 that copy floating point arguments from the gp regs to the fp
527 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
528 then any 16 bit function that calls FNNAME should be redirected
529 to the stub instead. If FNNAME is not a 32 bit function, the
530 stub should be discarded.
532 .mips16.call.fp.FNNAME sections are similar, but contain stubs
533 which call FNNAME and then copy the return value from the fp regs
534 to the gp regs. These stubs store the return value in $18 while
535 calling FNNAME; any function which might call one of these stubs
536 must arrange to save $18 around the call. (This case is not
537 needed for 32 bit functions that call 16 bit functions, because
538 16 bit functions always return floating point values in both
541 Note that in all cases FNNAME might be defined statically.
542 Therefore, FNNAME is not used literally. Instead, the relocation
543 information will indicate which symbol the section is for.
545 We record any stubs that we find in the symbol table. */
547 #define FN_STUB ".mips16.fn."
548 #define CALL_STUB ".mips16.call."
549 #define CALL_FP_STUB ".mips16.call.fp."
551 /* Look up an entry in a MIPS ELF linker hash table. */
553 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
554 ((struct mips_elf_link_hash_entry *) \
555 elf_link_hash_lookup (&(table)->root, (string), (create), \
558 /* Traverse a MIPS ELF linker hash table. */
560 #define mips_elf_link_hash_traverse(table, func, info) \
561 (elf_link_hash_traverse \
563 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
566 /* Get the MIPS ELF linker hash table from a link_info structure. */
568 #define mips_elf_hash_table(p) \
569 ((struct mips_elf_link_hash_table *) ((p)->hash))
571 /* Create an entry in a MIPS ELF linker hash table. */
573 static struct bfd_hash_entry
*
574 mips_elf_link_hash_newfunc (entry
, table
, string
)
575 struct bfd_hash_entry
*entry
;
576 struct bfd_hash_table
*table
;
579 struct mips_elf_link_hash_entry
*ret
=
580 (struct mips_elf_link_hash_entry
*) entry
;
582 /* Allocate the structure if it has not already been allocated by a
584 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
585 ret
= ((struct mips_elf_link_hash_entry
*)
586 bfd_hash_allocate (table
,
587 sizeof (struct mips_elf_link_hash_entry
)));
588 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
589 return (struct bfd_hash_entry
*) ret
;
591 /* Call the allocation method of the superclass. */
592 ret
= ((struct mips_elf_link_hash_entry
*)
593 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
595 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
597 /* Set local fields. */
598 memset (&ret
->esym
, 0, sizeof (EXTR
));
599 /* We use -2 as a marker to indicate that the information has
600 not been set. -1 means there is no associated ifd. */
602 ret
->possibly_dynamic_relocs
= 0;
603 ret
->readonly_reloc
= FALSE
;
604 ret
->min_dyn_reloc_index
= 0;
605 ret
->no_fn_stub
= FALSE
;
607 ret
->need_fn_stub
= FALSE
;
608 ret
->call_stub
= NULL
;
609 ret
->call_fp_stub
= NULL
;
610 ret
->forced_local
= FALSE
;
613 return (struct bfd_hash_entry
*) ret
;
616 /* Read ECOFF debugging information from a .mdebug section into a
617 ecoff_debug_info structure. */
620 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
623 struct ecoff_debug_info
*debug
;
626 const struct ecoff_debug_swap
*swap
;
627 char *ext_hdr
= NULL
;
629 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
630 memset (debug
, 0, sizeof (*debug
));
632 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
633 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
636 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
637 swap
->external_hdr_size
))
640 symhdr
= &debug
->symbolic_header
;
641 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
643 /* The symbolic header contains absolute file offsets and sizes to
645 #define READ(ptr, offset, count, size, type) \
646 if (symhdr->count == 0) \
650 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
651 debug->ptr = (type) bfd_malloc (amt); \
652 if (debug->ptr == NULL) \
654 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
655 || bfd_bread (debug->ptr, amt, abfd) != amt) \
659 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
660 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
661 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
662 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
663 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
664 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
666 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
667 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
668 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
669 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
670 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
674 debug
->adjust
= NULL
;
681 if (debug
->line
!= NULL
)
683 if (debug
->external_dnr
!= NULL
)
684 free (debug
->external_dnr
);
685 if (debug
->external_pdr
!= NULL
)
686 free (debug
->external_pdr
);
687 if (debug
->external_sym
!= NULL
)
688 free (debug
->external_sym
);
689 if (debug
->external_opt
!= NULL
)
690 free (debug
->external_opt
);
691 if (debug
->external_aux
!= NULL
)
692 free (debug
->external_aux
);
693 if (debug
->ss
!= NULL
)
695 if (debug
->ssext
!= NULL
)
697 if (debug
->external_fdr
!= NULL
)
698 free (debug
->external_fdr
);
699 if (debug
->external_rfd
!= NULL
)
700 free (debug
->external_rfd
);
701 if (debug
->external_ext
!= NULL
)
702 free (debug
->external_ext
);
706 /* Swap RPDR (runtime procedure table entry) for output. */
709 ecoff_swap_rpdr_out (abfd
, in
, ex
)
714 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
715 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
716 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
717 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
718 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
719 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
721 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
722 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
724 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
726 H_PUT_S32 (abfd
, in
->exception_info
, ex
->p_exception_info
);
730 /* Create a runtime procedure table from the .mdebug section. */
733 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
736 struct bfd_link_info
*info
;
738 struct ecoff_debug_info
*debug
;
740 const struct ecoff_debug_swap
*swap
;
741 HDRR
*hdr
= &debug
->symbolic_header
;
743 struct rpdr_ext
*erp
;
745 struct pdr_ext
*epdr
;
746 struct sym_ext
*esym
;
751 unsigned long sindex
;
755 const char *no_name_func
= _("static procedure (no name)");
763 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
765 sindex
= strlen (no_name_func
) + 1;
769 size
= swap
->external_pdr_size
;
771 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
775 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
778 size
= sizeof (RPDR
);
779 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
783 size
= sizeof (char *);
784 sv
= (char **) bfd_malloc (size
* count
);
788 count
= hdr
->isymMax
;
789 size
= swap
->external_sym_size
;
790 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
794 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
798 ss
= (char *) bfd_malloc (count
);
801 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
805 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
807 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
808 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
810 rp
->regmask
= pdr
.regmask
;
811 rp
->regoffset
= pdr
.regoffset
;
812 rp
->fregmask
= pdr
.fregmask
;
813 rp
->fregoffset
= pdr
.fregoffset
;
814 rp
->frameoffset
= pdr
.frameoffset
;
815 rp
->framereg
= pdr
.framereg
;
816 rp
->pcreg
= pdr
.pcreg
;
818 sv
[i
] = ss
+ sym
.iss
;
819 sindex
+= strlen (sv
[i
]) + 1;
823 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
824 size
= BFD_ALIGN (size
, 16);
825 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
828 mips_elf_hash_table (info
)->procedure_count
= 0;
832 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
834 erp
= (struct rpdr_ext
*) rtproc
;
835 memset (erp
, 0, sizeof (struct rpdr_ext
));
837 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
838 strcpy (str
, no_name_func
);
839 str
+= strlen (no_name_func
) + 1;
840 for (i
= 0; i
< count
; i
++)
842 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
844 str
+= strlen (sv
[i
]) + 1;
846 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
848 /* Set the size and contents of .rtproc section. */
850 s
->contents
= (bfd_byte
*) rtproc
;
852 /* Skip this section later on (I don't think this currently
853 matters, but someday it might). */
854 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
883 /* Check the mips16 stubs for a particular symbol, and see if we can
887 mips_elf_check_mips16_stubs (h
, data
)
888 struct mips_elf_link_hash_entry
*h
;
889 PTR data ATTRIBUTE_UNUSED
;
891 if (h
->root
.root
.type
== bfd_link_hash_warning
)
892 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
894 if (h
->fn_stub
!= NULL
895 && ! h
->need_fn_stub
)
897 /* We don't need the fn_stub; the only references to this symbol
898 are 16 bit calls. Clobber the size to 0 to prevent it from
899 being included in the link. */
900 h
->fn_stub
->_raw_size
= 0;
901 h
->fn_stub
->_cooked_size
= 0;
902 h
->fn_stub
->flags
&= ~SEC_RELOC
;
903 h
->fn_stub
->reloc_count
= 0;
904 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
907 if (h
->call_stub
!= NULL
908 && h
->root
.other
== STO_MIPS16
)
910 /* We don't need the call_stub; this is a 16 bit function, so
911 calls from other 16 bit functions are OK. Clobber the size
912 to 0 to prevent it from being included in the link. */
913 h
->call_stub
->_raw_size
= 0;
914 h
->call_stub
->_cooked_size
= 0;
915 h
->call_stub
->flags
&= ~SEC_RELOC
;
916 h
->call_stub
->reloc_count
= 0;
917 h
->call_stub
->flags
|= SEC_EXCLUDE
;
920 if (h
->call_fp_stub
!= NULL
921 && h
->root
.other
== STO_MIPS16
)
923 /* We don't need the call_stub; this is a 16 bit function, so
924 calls from other 16 bit functions are OK. Clobber the size
925 to 0 to prevent it from being included in the link. */
926 h
->call_fp_stub
->_raw_size
= 0;
927 h
->call_fp_stub
->_cooked_size
= 0;
928 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
929 h
->call_fp_stub
->reloc_count
= 0;
930 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
936 bfd_reloc_status_type
937 _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
938 relocateable
, data
, gp
)
941 arelent
*reloc_entry
;
942 asection
*input_section
;
943 bfd_boolean relocateable
;
951 if (bfd_is_com_section (symbol
->section
))
954 relocation
= symbol
->value
;
956 relocation
+= symbol
->section
->output_section
->vma
;
957 relocation
+= symbol
->section
->output_offset
;
959 if (reloc_entry
->address
> input_section
->_cooked_size
)
960 return bfd_reloc_outofrange
;
962 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
964 /* Set val to the offset into the section or symbol. */
965 if (reloc_entry
->howto
->src_mask
== 0)
967 /* This case occurs with the 64-bit MIPS ELF ABI. */
968 val
= reloc_entry
->addend
;
972 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
977 /* Adjust val for the final section location and GP value. If we
978 are producing relocateable output, we don't want to do this for
979 an external symbol. */
981 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
982 val
+= relocation
- gp
;
984 insn
= (insn
& ~0xffff) | (val
& 0xffff);
985 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
988 reloc_entry
->address
+= input_section
->output_offset
;
990 else if ((long) val
>= 0x8000 || (long) val
< -0x8000)
991 return bfd_reloc_overflow
;
996 /* Swap an entry in a .gptab section. Note that these routines rely
997 on the equivalence of the two elements of the union. */
1000 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1002 const Elf32_External_gptab
*ex
;
1005 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1006 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1010 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1012 const Elf32_gptab
*in
;
1013 Elf32_External_gptab
*ex
;
1015 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
1016 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
1020 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1022 const Elf32_compact_rel
*in
;
1023 Elf32_External_compact_rel
*ex
;
1025 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1026 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1027 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1028 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1029 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1030 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1034 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1036 const Elf32_crinfo
*in
;
1037 Elf32_External_crinfo
*ex
;
1041 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1042 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1043 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1044 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1045 H_PUT_32 (abfd
, l
, ex
->info
);
1046 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1047 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1051 /* Swap in an MSYM entry. */
1054 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
1056 const Elf32_External_Msym
*ex
;
1057 Elf32_Internal_Msym
*in
;
1059 in
->ms_hash_value
= H_GET_32 (abfd
, ex
->ms_hash_value
);
1060 in
->ms_info
= H_GET_32 (abfd
, ex
->ms_info
);
1063 /* Swap out an MSYM entry. */
1066 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
1068 const Elf32_Internal_Msym
*in
;
1069 Elf32_External_Msym
*ex
;
1071 H_PUT_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
1072 H_PUT_32 (abfd
, in
->ms_info
, ex
->ms_info
);
1075 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1076 routines swap this structure in and out. They are used outside of
1077 BFD, so they are globally visible. */
1080 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1082 const Elf32_External_RegInfo
*ex
;
1085 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1086 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1087 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1088 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1089 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1090 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1094 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1096 const Elf32_RegInfo
*in
;
1097 Elf32_External_RegInfo
*ex
;
1099 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1100 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1101 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1102 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1103 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1104 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1107 /* In the 64 bit ABI, the .MIPS.options section holds register
1108 information in an Elf64_Reginfo structure. These routines swap
1109 them in and out. They are globally visible because they are used
1110 outside of BFD. These routines are here so that gas can call them
1111 without worrying about whether the 64 bit ABI has been included. */
1114 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1116 const Elf64_External_RegInfo
*ex
;
1117 Elf64_Internal_RegInfo
*in
;
1119 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1120 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1121 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1122 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1123 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1124 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1125 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1129 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1131 const Elf64_Internal_RegInfo
*in
;
1132 Elf64_External_RegInfo
*ex
;
1134 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1135 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1136 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1137 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1138 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1139 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1140 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1143 /* Swap in an options header. */
1146 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1148 const Elf_External_Options
*ex
;
1149 Elf_Internal_Options
*in
;
1151 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1152 in
->size
= H_GET_8 (abfd
, ex
->size
);
1153 in
->section
= H_GET_16 (abfd
, ex
->section
);
1154 in
->info
= H_GET_32 (abfd
, ex
->info
);
1157 /* Swap out an options header. */
1160 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1162 const Elf_Internal_Options
*in
;
1163 Elf_External_Options
*ex
;
1165 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1166 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1167 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1168 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1171 /* This function is called via qsort() to sort the dynamic relocation
1172 entries by increasing r_symndx value. */
1175 sort_dynamic_relocs (arg1
, arg2
)
1179 Elf_Internal_Rela int_reloc1
;
1180 Elf_Internal_Rela int_reloc2
;
1182 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1183 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1185 return ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
1188 /* This routine is used to write out ECOFF debugging external symbol
1189 information. It is called via mips_elf_link_hash_traverse. The
1190 ECOFF external symbol information must match the ELF external
1191 symbol information. Unfortunately, at this point we don't know
1192 whether a symbol is required by reloc information, so the two
1193 tables may wind up being different. We must sort out the external
1194 symbol information before we can set the final size of the .mdebug
1195 section, and we must set the size of the .mdebug section before we
1196 can relocate any sections, and we can't know which symbols are
1197 required by relocation until we relocate the sections.
1198 Fortunately, it is relatively unlikely that any symbol will be
1199 stripped but required by a reloc. In particular, it can not happen
1200 when generating a final executable. */
1203 mips_elf_output_extsym (h
, data
)
1204 struct mips_elf_link_hash_entry
*h
;
1207 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
1209 asection
*sec
, *output_section
;
1211 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1212 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1214 if (h
->root
.indx
== -2)
1216 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1217 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
1218 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
1219 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
1221 else if (einfo
->info
->strip
== strip_all
1222 || (einfo
->info
->strip
== strip_some
1223 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1224 h
->root
.root
.root
.string
,
1225 FALSE
, FALSE
) == NULL
))
1233 if (h
->esym
.ifd
== -2)
1236 h
->esym
.cobol_main
= 0;
1237 h
->esym
.weakext
= 0;
1238 h
->esym
.reserved
= 0;
1239 h
->esym
.ifd
= ifdNil
;
1240 h
->esym
.asym
.value
= 0;
1241 h
->esym
.asym
.st
= stGlobal
;
1243 if (h
->root
.root
.type
== bfd_link_hash_undefined
1244 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
1248 /* Use undefined class. Also, set class and type for some
1250 name
= h
->root
.root
.root
.string
;
1251 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
1252 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
1254 h
->esym
.asym
.sc
= scData
;
1255 h
->esym
.asym
.st
= stLabel
;
1256 h
->esym
.asym
.value
= 0;
1258 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
1260 h
->esym
.asym
.sc
= scAbs
;
1261 h
->esym
.asym
.st
= stLabel
;
1262 h
->esym
.asym
.value
=
1263 mips_elf_hash_table (einfo
->info
)->procedure_count
;
1265 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
1267 h
->esym
.asym
.sc
= scAbs
;
1268 h
->esym
.asym
.st
= stLabel
;
1269 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
1272 h
->esym
.asym
.sc
= scUndefined
;
1274 else if (h
->root
.root
.type
!= bfd_link_hash_defined
1275 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1276 h
->esym
.asym
.sc
= scAbs
;
1281 sec
= h
->root
.root
.u
.def
.section
;
1282 output_section
= sec
->output_section
;
1284 /* When making a shared library and symbol h is the one from
1285 the another shared library, OUTPUT_SECTION may be null. */
1286 if (output_section
== NULL
)
1287 h
->esym
.asym
.sc
= scUndefined
;
1290 name
= bfd_section_name (output_section
->owner
, output_section
);
1292 if (strcmp (name
, ".text") == 0)
1293 h
->esym
.asym
.sc
= scText
;
1294 else if (strcmp (name
, ".data") == 0)
1295 h
->esym
.asym
.sc
= scData
;
1296 else if (strcmp (name
, ".sdata") == 0)
1297 h
->esym
.asym
.sc
= scSData
;
1298 else if (strcmp (name
, ".rodata") == 0
1299 || strcmp (name
, ".rdata") == 0)
1300 h
->esym
.asym
.sc
= scRData
;
1301 else if (strcmp (name
, ".bss") == 0)
1302 h
->esym
.asym
.sc
= scBss
;
1303 else if (strcmp (name
, ".sbss") == 0)
1304 h
->esym
.asym
.sc
= scSBss
;
1305 else if (strcmp (name
, ".init") == 0)
1306 h
->esym
.asym
.sc
= scInit
;
1307 else if (strcmp (name
, ".fini") == 0)
1308 h
->esym
.asym
.sc
= scFini
;
1310 h
->esym
.asym
.sc
= scAbs
;
1314 h
->esym
.asym
.reserved
= 0;
1315 h
->esym
.asym
.index
= indexNil
;
1318 if (h
->root
.root
.type
== bfd_link_hash_common
)
1319 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1320 else if (h
->root
.root
.type
== bfd_link_hash_defined
1321 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1323 if (h
->esym
.asym
.sc
== scCommon
)
1324 h
->esym
.asym
.sc
= scBss
;
1325 else if (h
->esym
.asym
.sc
== scSCommon
)
1326 h
->esym
.asym
.sc
= scSBss
;
1328 sec
= h
->root
.root
.u
.def
.section
;
1329 output_section
= sec
->output_section
;
1330 if (output_section
!= NULL
)
1331 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1332 + sec
->output_offset
1333 + output_section
->vma
);
1335 h
->esym
.asym
.value
= 0;
1337 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1339 struct mips_elf_link_hash_entry
*hd
= h
;
1340 bfd_boolean no_fn_stub
= h
->no_fn_stub
;
1342 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
1344 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
1345 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
1350 /* Set type and value for a symbol with a function stub. */
1351 h
->esym
.asym
.st
= stProc
;
1352 sec
= hd
->root
.root
.u
.def
.section
;
1354 h
->esym
.asym
.value
= 0;
1357 output_section
= sec
->output_section
;
1358 if (output_section
!= NULL
)
1359 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
1360 + sec
->output_offset
1361 + output_section
->vma
);
1363 h
->esym
.asym
.value
= 0;
1371 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1372 h
->root
.root
.root
.string
,
1375 einfo
->failed
= TRUE
;
1382 /* A comparison routine used to sort .gptab entries. */
1385 gptab_compare (p1
, p2
)
1389 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
1390 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
1392 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
1395 /* Returns the GOT section for ABFD. */
1398 mips_elf_got_section (abfd
)
1401 return bfd_get_section_by_name (abfd
, ".got");
1404 /* Returns the GOT information associated with the link indicated by
1405 INFO. If SGOTP is non-NULL, it is filled in with the GOT
1408 static struct mips_got_info
*
1409 mips_elf_got_info (abfd
, sgotp
)
1414 struct mips_got_info
*g
;
1416 sgot
= mips_elf_got_section (abfd
);
1417 BFD_ASSERT (sgot
!= NULL
);
1418 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
1419 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
1420 BFD_ASSERT (g
!= NULL
);
1427 /* Returns the GOT offset at which the indicated address can be found.
1428 If there is not yet a GOT entry for this value, create one. Returns
1429 -1 if no satisfactory GOT offset can be found. */
1432 mips_elf_local_got_index (abfd
, info
, value
)
1434 struct bfd_link_info
*info
;
1438 struct mips_got_info
*g
;
1441 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1443 /* Look to see if we already have an appropriate entry. */
1444 for (entry
= (sgot
->contents
1445 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
1446 entry
!= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
1447 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
1449 bfd_vma address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1450 if (address
== value
)
1451 return entry
- sgot
->contents
;
1454 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1457 /* Returns the GOT index for the global symbol indicated by H. */
1460 mips_elf_global_got_index (abfd
, h
)
1462 struct elf_link_hash_entry
*h
;
1466 struct mips_got_info
*g
;
1467 long global_got_dynindx
= 0;
1469 g
= mips_elf_got_info (abfd
, &sgot
);
1470 if (g
->global_gotsym
!= NULL
)
1471 global_got_dynindx
= g
->global_gotsym
->dynindx
;
1473 /* Once we determine the global GOT entry with the lowest dynamic
1474 symbol table index, we must put all dynamic symbols with greater
1475 indices into the GOT. That makes it easy to calculate the GOT
1477 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
1478 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
1479 * MIPS_ELF_GOT_SIZE (abfd
));
1480 BFD_ASSERT (index
< sgot
->_raw_size
);
1485 /* Find a GOT entry that is within 32KB of the VALUE. These entries
1486 are supposed to be placed at small offsets in the GOT, i.e.,
1487 within 32KB of GP. Return the index into the GOT for this page,
1488 and store the offset from this entry to the desired address in
1489 OFFSETP, if it is non-NULL. */
1492 mips_elf_got_page (abfd
, info
, value
, offsetp
)
1494 struct bfd_link_info
*info
;
1499 struct mips_got_info
*g
;
1501 bfd_byte
*last_entry
;
1505 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1507 /* Look to see if we already have an appropriate entry. */
1508 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
1509 for (entry
= (sgot
->contents
1510 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
1511 entry
!= last_entry
;
1512 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
1514 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1516 if (!mips_elf_overflow_p (value
- address
, 16))
1518 /* This entry will serve as the page pointer. We can add a
1519 16-bit number to it to get the actual address. */
1520 index
= entry
- sgot
->contents
;
1525 /* If we didn't have an appropriate entry, we create one now. */
1526 if (entry
== last_entry
)
1527 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1531 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1532 *offsetp
= value
- address
;
1538 /* Find a GOT entry whose higher-order 16 bits are the same as those
1539 for value. Return the index into the GOT for this entry. */
1542 mips_elf_got16_entry (abfd
, info
, value
, external
)
1544 struct bfd_link_info
*info
;
1546 bfd_boolean external
;
1549 struct mips_got_info
*g
;
1551 bfd_byte
*last_entry
;
1557 /* Although the ABI says that it is "the high-order 16 bits" that we
1558 want, it is really the %high value. The complete value is
1559 calculated with a `addiu' of a LO16 relocation, just as with a
1561 value
= mips_elf_high (value
) << 16;
1564 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1566 /* Look to see if we already have an appropriate entry. */
1567 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
1568 for (entry
= (sgot
->contents
1569 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
1570 entry
!= last_entry
;
1571 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
1573 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1574 if (address
== value
)
1576 /* This entry has the right high-order 16 bits, and the low-order
1577 16 bits are set to zero. */
1578 index
= entry
- sgot
->contents
;
1583 /* If we didn't have an appropriate entry, we create one now. */
1584 if (entry
== last_entry
)
1585 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1590 /* Returns the offset for the entry at the INDEXth position
1594 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
1602 sgot
= mips_elf_got_section (dynobj
);
1603 gp
= _bfd_get_gp_value (output_bfd
);
1604 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
1608 /* Create a local GOT entry for VALUE. Return the index of the entry,
1609 or -1 if it could not be created. */
1612 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
1614 struct mips_got_info
*g
;
1618 if (g
->assigned_gotno
>= g
->local_gotno
)
1620 /* We didn't allocate enough space in the GOT. */
1621 (*_bfd_error_handler
)
1622 (_("not enough GOT space for local GOT entries"));
1623 bfd_set_error (bfd_error_bad_value
);
1624 return (bfd_vma
) -1;
1627 MIPS_ELF_PUT_WORD (abfd
, value
,
1629 + MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
));
1630 return MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
1633 /* Sort the dynamic symbol table so that symbols that need GOT entries
1634 appear towards the end. This reduces the amount of GOT space
1635 required. MAX_LOCAL is used to set the number of local symbols
1636 known to be in the dynamic symbol table. During
1637 _bfd_mips_elf_size_dynamic_sections, this value is 1. Afterward, the
1638 section symbols are added and the count is higher. */
1641 mips_elf_sort_hash_table (info
, max_local
)
1642 struct bfd_link_info
*info
;
1643 unsigned long max_local
;
1645 struct mips_elf_hash_sort_data hsd
;
1646 struct mips_got_info
*g
;
1649 dynobj
= elf_hash_table (info
)->dynobj
;
1652 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
1653 hsd
.max_non_got_dynindx
= max_local
;
1654 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
1655 elf_hash_table (info
)),
1656 mips_elf_sort_hash_table_f
,
1659 /* There should have been enough room in the symbol table to
1660 accommodate both the GOT and non-GOT symbols. */
1661 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
1663 /* Now we know which dynamic symbol has the lowest dynamic symbol
1664 table index in the GOT. */
1665 g
= mips_elf_got_info (dynobj
, NULL
);
1666 g
->global_gotsym
= hsd
.low
;
1671 /* If H needs a GOT entry, assign it the highest available dynamic
1672 index. Otherwise, assign it the lowest available dynamic
1676 mips_elf_sort_hash_table_f (h
, data
)
1677 struct mips_elf_link_hash_entry
*h
;
1680 struct mips_elf_hash_sort_data
*hsd
1681 = (struct mips_elf_hash_sort_data
*) data
;
1683 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1684 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1686 /* Symbols without dynamic symbol table entries aren't interesting
1688 if (h
->root
.dynindx
== -1)
1691 if (h
->root
.got
.offset
!= 1)
1692 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
1695 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
1696 hsd
->low
= (struct elf_link_hash_entry
*) h
;
1702 /* If H is a symbol that needs a global GOT entry, but has a dynamic
1703 symbol table index lower than any we've seen to date, record it for
1707 mips_elf_record_global_got_symbol (h
, info
, g
)
1708 struct elf_link_hash_entry
*h
;
1709 struct bfd_link_info
*info
;
1710 struct mips_got_info
*g ATTRIBUTE_UNUSED
;
1712 /* A global symbol in the GOT must also be in the dynamic symbol
1714 if (h
->dynindx
== -1)
1716 switch (ELF_ST_VISIBILITY (h
->other
))
1720 _bfd_mips_elf_hide_symbol (info
, h
, TRUE
);
1723 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
1727 /* If we've already marked this entry as needing GOT space, we don't
1728 need to do it again. */
1729 if (h
->got
.offset
!= MINUS_ONE
)
1732 /* By setting this to a value other than -1, we are indicating that
1733 there needs to be a GOT entry for H. Avoid using zero, as the
1734 generic ELF copy_indirect_symbol tests for <= 0. */
1740 /* Returns the first relocation of type r_type found, beginning with
1741 RELOCATION. RELEND is one-past-the-end of the relocation table. */
1743 static const Elf_Internal_Rela
*
1744 mips_elf_next_relocation (abfd
, r_type
, relocation
, relend
)
1745 bfd
*abfd ATTRIBUTE_UNUSED
;
1746 unsigned int r_type
;
1747 const Elf_Internal_Rela
*relocation
;
1748 const Elf_Internal_Rela
*relend
;
1750 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
1751 immediately following. However, for the IRIX6 ABI, the next
1752 relocation may be a composed relocation consisting of several
1753 relocations for the same address. In that case, the R_MIPS_LO16
1754 relocation may occur as one of these. We permit a similar
1755 extension in general, as that is useful for GCC. */
1756 while (relocation
< relend
)
1758 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
)
1764 /* We didn't find it. */
1765 bfd_set_error (bfd_error_bad_value
);
1769 /* Return whether a relocation is against a local symbol. */
1772 mips_elf_local_relocation_p (input_bfd
, relocation
, local_sections
,
1775 const Elf_Internal_Rela
*relocation
;
1776 asection
**local_sections
;
1777 bfd_boolean check_forced
;
1779 unsigned long r_symndx
;
1780 Elf_Internal_Shdr
*symtab_hdr
;
1781 struct mips_elf_link_hash_entry
*h
;
1784 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
1785 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1786 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
1788 if (r_symndx
< extsymoff
)
1790 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
1795 /* Look up the hash table to check whether the symbol
1796 was forced local. */
1797 h
= (struct mips_elf_link_hash_entry
*)
1798 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
1799 /* Find the real hash-table entry for this symbol. */
1800 while (h
->root
.root
.type
== bfd_link_hash_indirect
1801 || h
->root
.root
.type
== bfd_link_hash_warning
)
1802 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1803 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
1810 /* Sign-extend VALUE, which has the indicated number of BITS. */
1813 mips_elf_sign_extend (value
, bits
)
1817 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
1818 /* VALUE is negative. */
1819 value
|= ((bfd_vma
) - 1) << bits
;
1824 /* Return non-zero if the indicated VALUE has overflowed the maximum
1825 range expressable by a signed number with the indicated number of
1829 mips_elf_overflow_p (value
, bits
)
1833 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
1835 if (svalue
> (1 << (bits
- 1)) - 1)
1836 /* The value is too big. */
1838 else if (svalue
< -(1 << (bits
- 1)))
1839 /* The value is too small. */
1846 /* Calculate the %high function. */
1849 mips_elf_high (value
)
1852 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
1855 /* Calculate the %higher function. */
1858 mips_elf_higher (value
)
1859 bfd_vma value ATTRIBUTE_UNUSED
;
1862 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
1865 return (bfd_vma
) -1;
1869 /* Calculate the %highest function. */
1872 mips_elf_highest (value
)
1873 bfd_vma value ATTRIBUTE_UNUSED
;
1876 return ((value
+ (bfd_vma
) 0x800080008000) >> 48) & 0xffff;
1879 return (bfd_vma
) -1;
1883 /* Create the .compact_rel section. */
1886 mips_elf_create_compact_rel_section (abfd
, info
)
1888 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1891 register asection
*s
;
1893 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
1895 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
1898 s
= bfd_make_section (abfd
, ".compact_rel");
1900 || ! bfd_set_section_flags (abfd
, s
, flags
)
1901 || ! bfd_set_section_alignment (abfd
, s
,
1902 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
1905 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
1911 /* Create the .got section to hold the global offset table. */
1914 mips_elf_create_got_section (abfd
, info
)
1916 struct bfd_link_info
*info
;
1919 register asection
*s
;
1920 struct elf_link_hash_entry
*h
;
1921 struct bfd_link_hash_entry
*bh
;
1922 struct mips_got_info
*g
;
1925 /* This function may be called more than once. */
1926 if (mips_elf_got_section (abfd
))
1929 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1930 | SEC_LINKER_CREATED
);
1932 s
= bfd_make_section (abfd
, ".got");
1934 || ! bfd_set_section_flags (abfd
, s
, flags
)
1935 || ! bfd_set_section_alignment (abfd
, s
, 4))
1938 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
1939 linker script because we don't want to define the symbol if we
1940 are not creating a global offset table. */
1942 if (! (_bfd_generic_link_add_one_symbol
1943 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
1944 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
1945 get_elf_backend_data (abfd
)->collect
, &bh
)))
1948 h
= (struct elf_link_hash_entry
*) bh
;
1949 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
1950 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1951 h
->type
= STT_OBJECT
;
1954 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1957 /* The first several global offset table entries are reserved. */
1958 s
->_raw_size
= MIPS_RESERVED_GOTNO
* MIPS_ELF_GOT_SIZE (abfd
);
1960 amt
= sizeof (struct mips_got_info
);
1961 g
= (struct mips_got_info
*) bfd_alloc (abfd
, amt
);
1964 g
->global_gotsym
= NULL
;
1965 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
1966 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
1967 if (elf_section_data (s
) == NULL
)
1969 amt
= sizeof (struct bfd_elf_section_data
);
1970 s
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
1971 if (elf_section_data (s
) == NULL
)
1974 elf_section_data (s
)->tdata
= (PTR
) g
;
1975 elf_section_data (s
)->this_hdr
.sh_flags
1976 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1981 /* Returns the .msym section for ABFD, creating it if it does not
1982 already exist. Returns NULL to indicate error. */
1985 mips_elf_create_msym_section (abfd
)
1990 s
= bfd_get_section_by_name (abfd
, ".msym");
1993 s
= bfd_make_section (abfd
, ".msym");
1995 || !bfd_set_section_flags (abfd
, s
,
1999 | SEC_LINKER_CREATED
2001 || !bfd_set_section_alignment (abfd
, s
,
2002 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
2009 /* Calculate the value produced by the RELOCATION (which comes from
2010 the INPUT_BFD). The ADDEND is the addend to use for this
2011 RELOCATION; RELOCATION->R_ADDEND is ignored.
2013 The result of the relocation calculation is stored in VALUEP.
2014 REQUIRE_JALXP indicates whether or not the opcode used with this
2015 relocation must be JALX.
2017 This function returns bfd_reloc_continue if the caller need take no
2018 further action regarding this relocation, bfd_reloc_notsupported if
2019 something goes dramatically wrong, bfd_reloc_overflow if an
2020 overflow occurs, and bfd_reloc_ok to indicate success. */
2022 static bfd_reloc_status_type
2023 mips_elf_calculate_relocation (abfd
, input_bfd
, input_section
, info
,
2024 relocation
, addend
, howto
, local_syms
,
2025 local_sections
, valuep
, namep
,
2026 require_jalxp
, save_addend
)
2029 asection
*input_section
;
2030 struct bfd_link_info
*info
;
2031 const Elf_Internal_Rela
*relocation
;
2033 reloc_howto_type
*howto
;
2034 Elf_Internal_Sym
*local_syms
;
2035 asection
**local_sections
;
2038 bfd_boolean
*require_jalxp
;
2039 bfd_boolean save_addend
;
2041 /* The eventual value we will return. */
2043 /* The address of the symbol against which the relocation is
2046 /* The final GP value to be used for the relocatable, executable, or
2047 shared object file being produced. */
2048 bfd_vma gp
= MINUS_ONE
;
2049 /* The place (section offset or address) of the storage unit being
2052 /* The value of GP used to create the relocatable object. */
2053 bfd_vma gp0
= MINUS_ONE
;
2054 /* The offset into the global offset table at which the address of
2055 the relocation entry symbol, adjusted by the addend, resides
2056 during execution. */
2057 bfd_vma g
= MINUS_ONE
;
2058 /* The section in which the symbol referenced by the relocation is
2060 asection
*sec
= NULL
;
2061 struct mips_elf_link_hash_entry
*h
= NULL
;
2062 /* TRUE if the symbol referred to by this relocation is a local
2064 bfd_boolean local_p
, was_local_p
;
2065 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
2066 bfd_boolean gp_disp_p
= FALSE
;
2067 Elf_Internal_Shdr
*symtab_hdr
;
2069 unsigned long r_symndx
;
2071 /* TRUE if overflow occurred during the calculation of the
2072 relocation value. */
2073 bfd_boolean overflowed_p
;
2074 /* TRUE if this relocation refers to a MIPS16 function. */
2075 bfd_boolean target_is_16_bit_code_p
= FALSE
;
2077 /* Parse the relocation. */
2078 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
2079 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
2080 p
= (input_section
->output_section
->vma
2081 + input_section
->output_offset
2082 + relocation
->r_offset
);
2084 /* Assume that there will be no overflow. */
2085 overflowed_p
= FALSE
;
2087 /* Figure out whether or not the symbol is local, and get the offset
2088 used in the array of hash table entries. */
2089 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2090 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
2091 local_sections
, FALSE
);
2092 was_local_p
= local_p
;
2093 if (! elf_bad_symtab (input_bfd
))
2094 extsymoff
= symtab_hdr
->sh_info
;
2097 /* The symbol table does not follow the rule that local symbols
2098 must come before globals. */
2102 /* Figure out the value of the symbol. */
2105 Elf_Internal_Sym
*sym
;
2107 sym
= local_syms
+ r_symndx
;
2108 sec
= local_sections
[r_symndx
];
2110 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2111 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
2112 || (sec
->flags
& SEC_MERGE
))
2113 symbol
+= sym
->st_value
;
2114 if ((sec
->flags
& SEC_MERGE
)
2115 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2117 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
2119 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
2122 /* MIPS16 text labels should be treated as odd. */
2123 if (sym
->st_other
== STO_MIPS16
)
2126 /* Record the name of this symbol, for our caller. */
2127 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
2128 symtab_hdr
->sh_link
,
2131 *namep
= bfd_section_name (input_bfd
, sec
);
2133 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
2137 /* For global symbols we look up the symbol in the hash-table. */
2138 h
= ((struct mips_elf_link_hash_entry
*)
2139 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
2140 /* Find the real hash-table entry for this symbol. */
2141 while (h
->root
.root
.type
== bfd_link_hash_indirect
2142 || h
->root
.root
.type
== bfd_link_hash_warning
)
2143 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2145 /* Record the name of this symbol, for our caller. */
2146 *namep
= h
->root
.root
.root
.string
;
2148 /* See if this is the special _gp_disp symbol. Note that such a
2149 symbol must always be a global symbol. */
2150 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0
2151 && ! NEWABI_P (input_bfd
))
2153 /* Relocations against _gp_disp are permitted only with
2154 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
2155 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
2156 return bfd_reloc_notsupported
;
2160 /* If this symbol is defined, calculate its address. Note that
2161 _gp_disp is a magic symbol, always implicitly defined by the
2162 linker, so it's inappropriate to check to see whether or not
2164 else if ((h
->root
.root
.type
== bfd_link_hash_defined
2165 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2166 && h
->root
.root
.u
.def
.section
)
2168 sec
= h
->root
.root
.u
.def
.section
;
2169 if (sec
->output_section
)
2170 symbol
= (h
->root
.root
.u
.def
.value
2171 + sec
->output_section
->vma
2172 + sec
->output_offset
);
2174 symbol
= h
->root
.root
.u
.def
.value
;
2176 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
2177 /* We allow relocations against undefined weak symbols, giving
2178 it the value zero, so that you can undefined weak functions
2179 and check to see if they exist by looking at their
2182 else if (info
->shared
2183 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
2184 && !info
->no_undefined
2185 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
2187 else if (strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINK") == 0 ||
2188 strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINKING") == 0)
2190 /* If this is a dynamic link, we should have created a
2191 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
2192 in in _bfd_mips_elf_create_dynamic_sections.
2193 Otherwise, we should define the symbol with a value of 0.
2194 FIXME: It should probably get into the symbol table
2196 BFD_ASSERT (! info
->shared
);
2197 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
2202 if (! ((*info
->callbacks
->undefined_symbol
)
2203 (info
, h
->root
.root
.root
.string
, input_bfd
,
2204 input_section
, relocation
->r_offset
,
2205 (!info
->shared
|| info
->no_undefined
2206 || ELF_ST_VISIBILITY (h
->root
.other
)))))
2207 return bfd_reloc_undefined
;
2211 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
2214 /* If this is a 32- or 64-bit call to a 16-bit function with a stub, we
2215 need to redirect the call to the stub, unless we're already *in*
2217 if (r_type
!= R_MIPS16_26
&& !info
->relocateable
2218 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
2219 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
2220 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
2221 && !mips_elf_stub_section_p (input_bfd
, input_section
))
2223 /* This is a 32- or 64-bit call to a 16-bit function. We should
2224 have already noticed that we were going to need the
2227 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
2230 BFD_ASSERT (h
->need_fn_stub
);
2234 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2236 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
2237 need to redirect the call to the stub. */
2238 else if (r_type
== R_MIPS16_26
&& !info
->relocateable
2240 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
2241 && !target_is_16_bit_code_p
)
2243 /* If both call_stub and call_fp_stub are defined, we can figure
2244 out which one to use by seeing which one appears in the input
2246 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
2251 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
2253 if (strncmp (bfd_get_section_name (input_bfd
, o
),
2254 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
2256 sec
= h
->call_fp_stub
;
2263 else if (h
->call_stub
!= NULL
)
2266 sec
= h
->call_fp_stub
;
2268 BFD_ASSERT (sec
->_raw_size
> 0);
2269 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2272 /* Calls from 16-bit code to 32-bit code and vice versa require the
2273 special jalx instruction. */
2274 *require_jalxp
= (!info
->relocateable
2275 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
2276 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
2278 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
2279 local_sections
, TRUE
);
2281 /* If we haven't already determined the GOT offset, or the GP value,
2282 and we're going to need it, get it now. */
2287 case R_MIPS_GOT_DISP
:
2288 case R_MIPS_GOT_HI16
:
2289 case R_MIPS_CALL_HI16
:
2290 case R_MIPS_GOT_LO16
:
2291 case R_MIPS_CALL_LO16
:
2292 /* Find the index into the GOT where this value is located. */
2295 BFD_ASSERT (addend
== 0);
2296 g
= mips_elf_global_got_index (elf_hash_table (info
)->dynobj
,
2297 (struct elf_link_hash_entry
*) h
);
2298 if (! elf_hash_table(info
)->dynamic_sections_created
2300 && (info
->symbolic
|| h
->root
.dynindx
== -1)
2301 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2303 /* This is a static link or a -Bsymbolic link. The
2304 symbol is defined locally, or was forced to be local.
2305 We must initialize this entry in the GOT. */
2306 bfd
*tmpbfd
= elf_hash_table (info
)->dynobj
;
2307 asection
*sgot
= mips_elf_got_section(tmpbfd
);
2308 MIPS_ELF_PUT_WORD (tmpbfd
, symbol
+ addend
, sgot
->contents
+ g
);
2311 else if (r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS_CALL16
)
2312 /* There's no need to create a local GOT entry here; the
2313 calculation for a local GOT16 entry does not involve G. */
2317 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
2319 return bfd_reloc_outofrange
;
2322 /* Convert GOT indices to actual offsets. */
2323 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2329 case R_MIPS16_GPREL
:
2330 case R_MIPS_GPREL16
:
2331 case R_MIPS_GPREL32
:
2332 case R_MIPS_LITERAL
:
2333 gp0
= _bfd_get_gp_value (input_bfd
);
2334 gp
= _bfd_get_gp_value (abfd
);
2341 /* Figure out what kind of relocation is being performed. */
2345 return bfd_reloc_continue
;
2348 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
2349 overflowed_p
= mips_elf_overflow_p (value
, 16);
2356 || (elf_hash_table (info
)->dynamic_sections_created
2358 && ((h
->root
.elf_link_hash_flags
2359 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
2360 && ((h
->root
.elf_link_hash_flags
2361 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2363 && (input_section
->flags
& SEC_ALLOC
) != 0)
2365 /* If we're creating a shared library, or this relocation is
2366 against a symbol in a shared library, then we can't know
2367 where the symbol will end up. So, we create a relocation
2368 record in the output, and leave the job up to the dynamic
2371 if (!mips_elf_create_dynamic_relocation (abfd
,
2379 return bfd_reloc_undefined
;
2383 if (r_type
!= R_MIPS_REL32
)
2384 value
= symbol
+ addend
;
2388 value
&= howto
->dst_mask
;
2393 case R_MIPS_GNU_REL_LO16
:
2394 value
= symbol
+ addend
- p
;
2395 value
&= howto
->dst_mask
;
2398 case R_MIPS_GNU_REL16_S2
:
2399 value
= symbol
+ mips_elf_sign_extend (addend
<< 2, 18) - p
;
2400 overflowed_p
= mips_elf_overflow_p (value
, 18);
2401 value
= (value
>> 2) & howto
->dst_mask
;
2404 case R_MIPS_GNU_REL_HI16
:
2405 /* Instead of subtracting 'p' here, we should be subtracting the
2406 equivalent value for the LO part of the reloc, since the value
2407 here is relative to that address. Because that's not easy to do,
2408 we adjust 'addend' in _bfd_mips_elf_relocate_section(). See also
2409 the comment there for more information. */
2410 value
= mips_elf_high (addend
+ symbol
- p
);
2411 value
&= howto
->dst_mask
;
2415 /* The calculation for R_MIPS16_26 is just the same as for an
2416 R_MIPS_26. It's only the storage of the relocated field into
2417 the output file that's different. That's handled in
2418 mips_elf_perform_relocation. So, we just fall through to the
2419 R_MIPS_26 case here. */
2422 value
= (((addend
<< 2) | ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
2424 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
2425 value
&= howto
->dst_mask
;
2431 value
= mips_elf_high (addend
+ symbol
);
2432 value
&= howto
->dst_mask
;
2436 value
= mips_elf_high (addend
+ gp
- p
);
2437 overflowed_p
= mips_elf_overflow_p (value
, 16);
2443 value
= (symbol
+ addend
) & howto
->dst_mask
;
2446 value
= addend
+ gp
- p
+ 4;
2447 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
2448 for overflow. But, on, say, IRIX5, relocations against
2449 _gp_disp are normally generated from the .cpload
2450 pseudo-op. It generates code that normally looks like
2453 lui $gp,%hi(_gp_disp)
2454 addiu $gp,$gp,%lo(_gp_disp)
2457 Here $t9 holds the address of the function being called,
2458 as required by the MIPS ELF ABI. The R_MIPS_LO16
2459 relocation can easily overflow in this situation, but the
2460 R_MIPS_HI16 relocation will handle the overflow.
2461 Therefore, we consider this a bug in the MIPS ABI, and do
2462 not check for overflow here. */
2466 case R_MIPS_LITERAL
:
2467 /* Because we don't merge literal sections, we can handle this
2468 just like R_MIPS_GPREL16. In the long run, we should merge
2469 shared literals, and then we will need to additional work
2474 case R_MIPS16_GPREL
:
2475 /* The R_MIPS16_GPREL performs the same calculation as
2476 R_MIPS_GPREL16, but stores the relocated bits in a different
2477 order. We don't need to do anything special here; the
2478 differences are handled in mips_elf_perform_relocation. */
2479 case R_MIPS_GPREL16
:
2480 /* Only sign-extend the addend if it was extracted from the
2481 instruction. If the addend was separate, leave it alone,
2482 otherwise we may lose significant bits. */
2483 if (howto
->partial_inplace
)
2484 addend
= mips_elf_sign_extend (addend
, 16);
2485 value
= symbol
+ addend
- gp
;
2486 /* If the symbol was local, any earlier relocatable links will
2487 have adjusted its addend with the gp offset, so compensate
2488 for that now. Don't do it for symbols forced local in this
2489 link, though, since they won't have had the gp offset applied
2493 overflowed_p
= mips_elf_overflow_p (value
, 16);
2502 /* The special case is when the symbol is forced to be local. We
2503 need the full address in the GOT since no R_MIPS_LO16 relocation
2505 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
2506 local_sections
, FALSE
);
2507 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
, forced
);
2508 if (value
== MINUS_ONE
)
2509 return bfd_reloc_outofrange
;
2511 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2513 overflowed_p
= mips_elf_overflow_p (value
, 16);
2519 case R_MIPS_GOT_DISP
:
2521 overflowed_p
= mips_elf_overflow_p (value
, 16);
2524 case R_MIPS_GPREL32
:
2525 value
= (addend
+ symbol
+ gp0
- gp
);
2527 value
&= howto
->dst_mask
;
2531 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
2532 overflowed_p
= mips_elf_overflow_p (value
, 16);
2533 value
= (bfd_vma
) ((bfd_signed_vma
) value
/ 4);
2536 case R_MIPS_GOT_HI16
:
2537 case R_MIPS_CALL_HI16
:
2538 /* We're allowed to handle these two relocations identically.
2539 The dynamic linker is allowed to handle the CALL relocations
2540 differently by creating a lazy evaluation stub. */
2542 value
= mips_elf_high (value
);
2543 value
&= howto
->dst_mask
;
2546 case R_MIPS_GOT_LO16
:
2547 case R_MIPS_CALL_LO16
:
2548 value
= g
& howto
->dst_mask
;
2551 case R_MIPS_GOT_PAGE
:
2552 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
2553 if (value
== MINUS_ONE
)
2554 return bfd_reloc_outofrange
;
2555 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2557 overflowed_p
= mips_elf_overflow_p (value
, 16);
2560 case R_MIPS_GOT_OFST
:
2561 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
2562 overflowed_p
= mips_elf_overflow_p (value
, 16);
2566 value
= symbol
- addend
;
2567 value
&= howto
->dst_mask
;
2571 value
= mips_elf_higher (addend
+ symbol
);
2572 value
&= howto
->dst_mask
;
2575 case R_MIPS_HIGHEST
:
2576 value
= mips_elf_highest (addend
+ symbol
);
2577 value
&= howto
->dst_mask
;
2580 case R_MIPS_SCN_DISP
:
2581 value
= symbol
+ addend
- sec
->output_offset
;
2582 value
&= howto
->dst_mask
;
2587 /* Both of these may be ignored. R_MIPS_JALR is an optimization
2588 hint; we could improve performance by honoring that hint. */
2589 return bfd_reloc_continue
;
2591 case R_MIPS_GNU_VTINHERIT
:
2592 case R_MIPS_GNU_VTENTRY
:
2593 /* We don't do anything with these at present. */
2594 return bfd_reloc_continue
;
2597 /* An unrecognized relocation type. */
2598 return bfd_reloc_notsupported
;
2601 /* Store the VALUE for our caller. */
2603 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
2606 /* Obtain the field relocated by RELOCATION. */
2609 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
2610 reloc_howto_type
*howto
;
2611 const Elf_Internal_Rela
*relocation
;
2616 bfd_byte
*location
= contents
+ relocation
->r_offset
;
2618 /* Obtain the bytes. */
2619 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
2621 if ((ELF_R_TYPE (input_bfd
, relocation
->r_info
) == R_MIPS16_26
2622 || ELF_R_TYPE (input_bfd
, relocation
->r_info
) == R_MIPS16_GPREL
)
2623 && bfd_little_endian (input_bfd
))
2624 /* The two 16-bit words will be reversed on a little-endian system.
2625 See mips_elf_perform_relocation for more details. */
2626 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
2631 /* It has been determined that the result of the RELOCATION is the
2632 VALUE. Use HOWTO to place VALUE into the output file at the
2633 appropriate position. The SECTION is the section to which the
2634 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
2635 for the relocation must be either JAL or JALX, and it is
2636 unconditionally converted to JALX.
2638 Returns FALSE if anything goes wrong. */
2641 mips_elf_perform_relocation (info
, howto
, relocation
, value
, input_bfd
,
2642 input_section
, contents
, require_jalx
)
2643 struct bfd_link_info
*info
;
2644 reloc_howto_type
*howto
;
2645 const Elf_Internal_Rela
*relocation
;
2648 asection
*input_section
;
2650 bfd_boolean require_jalx
;
2654 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
2656 /* Figure out where the relocation is occurring. */
2657 location
= contents
+ relocation
->r_offset
;
2659 /* Obtain the current value. */
2660 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
2662 /* Clear the field we are setting. */
2663 x
&= ~howto
->dst_mask
;
2665 /* If this is the R_MIPS16_26 relocation, we must store the
2666 value in a funny way. */
2667 if (r_type
== R_MIPS16_26
)
2669 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
2670 Most mips16 instructions are 16 bits, but these instructions
2673 The format of these instructions is:
2675 +--------------+--------------------------------+
2676 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
2677 +--------------+--------------------------------+
2679 +-----------------------------------------------+
2681 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
2682 Note that the immediate value in the first word is swapped.
2684 When producing a relocateable object file, R_MIPS16_26 is
2685 handled mostly like R_MIPS_26. In particular, the addend is
2686 stored as a straight 26-bit value in a 32-bit instruction.
2687 (gas makes life simpler for itself by never adjusting a
2688 R_MIPS16_26 reloc to be against a section, so the addend is
2689 always zero). However, the 32 bit instruction is stored as 2
2690 16-bit values, rather than a single 32-bit value. In a
2691 big-endian file, the result is the same; in a little-endian
2692 file, the two 16-bit halves of the 32 bit value are swapped.
2693 This is so that a disassembler can recognize the jal
2696 When doing a final link, R_MIPS16_26 is treated as a 32 bit
2697 instruction stored as two 16-bit values. The addend A is the
2698 contents of the targ26 field. The calculation is the same as
2699 R_MIPS_26. When storing the calculated value, reorder the
2700 immediate value as shown above, and don't forget to store the
2701 value as two 16-bit values.
2703 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
2707 +--------+----------------------+
2711 +--------+----------------------+
2714 +----------+------+-------------+
2718 +----------+--------------------+
2719 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
2720 ((sub1 << 16) | sub2)).
2722 When producing a relocateable object file, the calculation is
2723 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2724 When producing a fully linked file, the calculation is
2725 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2726 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
2728 if (!info
->relocateable
)
2729 /* Shuffle the bits according to the formula above. */
2730 value
= (((value
& 0x1f0000) << 5)
2731 | ((value
& 0x3e00000) >> 5)
2732 | (value
& 0xffff));
2734 else if (r_type
== R_MIPS16_GPREL
)
2736 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
2737 mode. A typical instruction will have a format like this:
2739 +--------------+--------------------------------+
2740 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
2741 +--------------+--------------------------------+
2742 ! Major ! rx ! ry ! Imm 4:0 !
2743 +--------------+--------------------------------+
2745 EXTEND is the five bit value 11110. Major is the instruction
2748 This is handled exactly like R_MIPS_GPREL16, except that the
2749 addend is retrieved and stored as shown in this diagram; that
2750 is, the Imm fields above replace the V-rel16 field.
2752 All we need to do here is shuffle the bits appropriately. As
2753 above, the two 16-bit halves must be swapped on a
2754 little-endian system. */
2755 value
= (((value
& 0x7e0) << 16)
2756 | ((value
& 0xf800) << 5)
2760 /* Set the field. */
2761 x
|= (value
& howto
->dst_mask
);
2763 /* If required, turn JAL into JALX. */
2767 bfd_vma opcode
= x
>> 26;
2768 bfd_vma jalx_opcode
;
2770 /* Check to see if the opcode is already JAL or JALX. */
2771 if (r_type
== R_MIPS16_26
)
2773 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
2778 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
2782 /* If the opcode is not JAL or JALX, there's a problem. */
2785 (*_bfd_error_handler
)
2786 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
2787 bfd_archive_filename (input_bfd
),
2788 input_section
->name
,
2789 (unsigned long) relocation
->r_offset
);
2790 bfd_set_error (bfd_error_bad_value
);
2794 /* Make this the JALX opcode. */
2795 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
2798 /* Swap the high- and low-order 16 bits on little-endian systems
2799 when doing a MIPS16 relocation. */
2800 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
2801 && bfd_little_endian (input_bfd
))
2802 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
2804 /* Put the value into the output. */
2805 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
2809 /* Returns TRUE if SECTION is a MIPS16 stub section. */
2812 mips_elf_stub_section_p (abfd
, section
)
2813 bfd
*abfd ATTRIBUTE_UNUSED
;
2816 const char *name
= bfd_get_section_name (abfd
, section
);
2818 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
2819 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
2820 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
2823 /* Add room for N relocations to the .rel.dyn section in ABFD. */
2826 mips_elf_allocate_dynamic_relocations (abfd
, n
)
2832 s
= bfd_get_section_by_name (abfd
, ".rel.dyn");
2833 BFD_ASSERT (s
!= NULL
);
2835 if (s
->_raw_size
== 0)
2837 /* Make room for a null element. */
2838 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
2841 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
2844 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
2845 is the original relocation, which is now being transformed into a
2846 dynamic relocation. The ADDENDP is adjusted if necessary; the
2847 caller should store the result in place of the original addend. */
2850 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
, sec
,
2851 symbol
, addendp
, input_section
)
2853 struct bfd_link_info
*info
;
2854 const Elf_Internal_Rela
*rel
;
2855 struct mips_elf_link_hash_entry
*h
;
2859 asection
*input_section
;
2861 Elf_Internal_Rela outrel
[3];
2867 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
2868 dynobj
= elf_hash_table (info
)->dynobj
;
2869 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
2870 BFD_ASSERT (sreloc
!= NULL
);
2871 BFD_ASSERT (sreloc
->contents
!= NULL
);
2872 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
2873 < sreloc
->_raw_size
);
2876 outrel
[0].r_offset
=
2877 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
2878 outrel
[1].r_offset
=
2879 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
2880 outrel
[2].r_offset
=
2881 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
2884 /* We begin by assuming that the offset for the dynamic relocation
2885 is the same as for the original relocation. We'll adjust this
2886 later to reflect the correct output offsets. */
2887 if (elf_section_data (input_section
)->sec_info_type
!= ELF_INFO_TYPE_STABS
)
2889 outrel
[1].r_offset
= rel
[1].r_offset
;
2890 outrel
[2].r_offset
= rel
[2].r_offset
;
2894 /* Except that in a stab section things are more complex.
2895 Because we compress stab information, the offset given in the
2896 relocation may not be the one we want; we must let the stabs
2897 machinery tell us the offset. */
2898 outrel
[1].r_offset
= outrel
[0].r_offset
;
2899 outrel
[2].r_offset
= outrel
[0].r_offset
;
2900 /* If we didn't need the relocation at all, this value will be
2902 if (outrel
[0].r_offset
== (bfd_vma
) -1)
2907 if (outrel
[0].r_offset
== (bfd_vma
) -1)
2909 /* FIXME: For -2 runtime relocation needs to be skipped, but
2910 properly resolved statically and installed. */
2911 BFD_ASSERT (outrel
[0].r_offset
!= (bfd_vma
) -2);
2913 /* If we've decided to skip this relocation, just output an empty
2914 record. Note that R_MIPS_NONE == 0, so that this call to memset
2915 is a way of setting R_TYPE to R_MIPS_NONE. */
2917 memset (outrel
, 0, sizeof (Elf_Internal_Rela
) * 3);
2921 bfd_vma section_offset
;
2923 /* We must now calculate the dynamic symbol table index to use
2924 in the relocation. */
2926 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
2927 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2929 indx
= h
->root
.dynindx
;
2930 /* h->root.dynindx may be -1 if this symbol was marked to
2937 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
2939 else if (sec
== NULL
|| sec
->owner
== NULL
)
2941 bfd_set_error (bfd_error_bad_value
);
2946 indx
= elf_section_data (sec
->output_section
)->dynindx
;
2951 /* Figure out how far the target of the relocation is from
2952 the beginning of its section. */
2953 section_offset
= symbol
- sec
->output_section
->vma
;
2954 /* The relocation we're building is section-relative.
2955 Therefore, the original addend must be adjusted by the
2957 *addendp
+= section_offset
;
2958 /* Now, the relocation is just against the section. */
2959 symbol
= sec
->output_section
->vma
;
2962 /* If the relocation was previously an absolute relocation and
2963 this symbol will not be referred to by the relocation, we must
2964 adjust it by the value we give it in the dynamic symbol table.
2965 Otherwise leave the job up to the dynamic linker. */
2966 if (!indx
&& r_type
!= R_MIPS_REL32
)
2969 /* The relocation is always an REL32 relocation because we don't
2970 know where the shared library will wind up at load-time. */
2971 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
2973 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) 0,
2974 ABI_64_P (output_bfd
)
2977 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) 0,
2980 /* Adjust the output offset of the relocation to reference the
2981 correct location in the output file. */
2982 outrel
[0].r_offset
+= (input_section
->output_section
->vma
2983 + input_section
->output_offset
);
2984 outrel
[1].r_offset
+= (input_section
->output_section
->vma
2985 + input_section
->output_offset
);
2986 outrel
[2].r_offset
+= (input_section
->output_section
->vma
2987 + input_section
->output_offset
);
2990 /* Put the relocation back out. We have to use the special
2991 relocation outputter in the 64-bit case since the 64-bit
2992 relocation format is non-standard. */
2993 if (ABI_64_P (output_bfd
))
2995 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2996 (output_bfd
, &outrel
[0],
2998 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
3001 bfd_elf32_swap_reloc_out
3002 (output_bfd
, &outrel
[0],
3003 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
3005 /* Record the index of the first relocation referencing H. This
3006 information is later emitted in the .msym section. */
3008 && (h
->min_dyn_reloc_index
== 0
3009 || sreloc
->reloc_count
< h
->min_dyn_reloc_index
))
3010 h
->min_dyn_reloc_index
= sreloc
->reloc_count
;
3012 /* We've now added another relocation. */
3013 ++sreloc
->reloc_count
;
3015 /* Make sure the output section is writable. The dynamic linker
3016 will be writing to it. */
3017 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
3020 /* On IRIX5, make an entry of compact relocation info. */
3021 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
3023 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
3028 Elf32_crinfo cptrel
;
3030 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
3031 cptrel
.vaddr
= (rel
->r_offset
3032 + input_section
->output_section
->vma
3033 + input_section
->output_offset
);
3034 if (r_type
== R_MIPS_REL32
)
3035 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
3037 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
3038 mips_elf_set_cr_dist2to (cptrel
, 0);
3039 cptrel
.konst
= *addendp
;
3041 cr
= (scpt
->contents
3042 + sizeof (Elf32_External_compact_rel
));
3043 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
3044 ((Elf32_External_crinfo
*) cr
3045 + scpt
->reloc_count
));
3046 ++scpt
->reloc_count
;
3053 /* Return the ISA for a MIPS e_flags value. */
3056 elf_mips_isa (flags
)
3059 switch (flags
& EF_MIPS_ARCH
)
3071 case E_MIPS_ARCH_32
:
3073 case E_MIPS_ARCH_64
:
3079 /* Return the MACH for a MIPS e_flags value. */
3082 _bfd_elf_mips_mach (flags
)
3085 switch (flags
& EF_MIPS_MACH
)
3087 case E_MIPS_MACH_3900
:
3088 return bfd_mach_mips3900
;
3090 case E_MIPS_MACH_4010
:
3091 return bfd_mach_mips4010
;
3093 case E_MIPS_MACH_4100
:
3094 return bfd_mach_mips4100
;
3096 case E_MIPS_MACH_4111
:
3097 return bfd_mach_mips4111
;
3099 case E_MIPS_MACH_4120
:
3100 return bfd_mach_mips4120
;
3102 case E_MIPS_MACH_4650
:
3103 return bfd_mach_mips4650
;
3105 case E_MIPS_MACH_5400
:
3106 return bfd_mach_mips5400
;
3108 case E_MIPS_MACH_5500
:
3109 return bfd_mach_mips5500
;
3111 case E_MIPS_MACH_SB1
:
3112 return bfd_mach_mips_sb1
;
3115 switch (flags
& EF_MIPS_ARCH
)
3119 return bfd_mach_mips3000
;
3123 return bfd_mach_mips6000
;
3127 return bfd_mach_mips4000
;
3131 return bfd_mach_mips8000
;
3135 return bfd_mach_mips5
;
3138 case E_MIPS_ARCH_32
:
3139 return bfd_mach_mipsisa32
;
3142 case E_MIPS_ARCH_64
:
3143 return bfd_mach_mipsisa64
;
3151 /* Return printable name for ABI. */
3153 static INLINE
char *
3154 elf_mips_abi_name (abfd
)
3159 flags
= elf_elfheader (abfd
)->e_flags
;
3160 switch (flags
& EF_MIPS_ABI
)
3163 if (ABI_N32_P (abfd
))
3165 else if (ABI_64_P (abfd
))
3169 case E_MIPS_ABI_O32
:
3171 case E_MIPS_ABI_O64
:
3173 case E_MIPS_ABI_EABI32
:
3175 case E_MIPS_ABI_EABI64
:
3178 return "unknown abi";
3182 /* MIPS ELF uses two common sections. One is the usual one, and the
3183 other is for small objects. All the small objects are kept
3184 together, and then referenced via the gp pointer, which yields
3185 faster assembler code. This is what we use for the small common
3186 section. This approach is copied from ecoff.c. */
3187 static asection mips_elf_scom_section
;
3188 static asymbol mips_elf_scom_symbol
;
3189 static asymbol
*mips_elf_scom_symbol_ptr
;
3191 /* MIPS ELF also uses an acommon section, which represents an
3192 allocated common symbol which may be overridden by a
3193 definition in a shared library. */
3194 static asection mips_elf_acom_section
;
3195 static asymbol mips_elf_acom_symbol
;
3196 static asymbol
*mips_elf_acom_symbol_ptr
;
3198 /* Handle the special MIPS section numbers that a symbol may use.
3199 This is used for both the 32-bit and the 64-bit ABI. */
3202 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3206 elf_symbol_type
*elfsym
;
3208 elfsym
= (elf_symbol_type
*) asym
;
3209 switch (elfsym
->internal_elf_sym
.st_shndx
)
3211 case SHN_MIPS_ACOMMON
:
3212 /* This section is used in a dynamically linked executable file.
3213 It is an allocated common section. The dynamic linker can
3214 either resolve these symbols to something in a shared
3215 library, or it can just leave them here. For our purposes,
3216 we can consider these symbols to be in a new section. */
3217 if (mips_elf_acom_section
.name
== NULL
)
3219 /* Initialize the acommon section. */
3220 mips_elf_acom_section
.name
= ".acommon";
3221 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3222 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3223 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3224 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3225 mips_elf_acom_symbol
.name
= ".acommon";
3226 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3227 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3228 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3230 asym
->section
= &mips_elf_acom_section
;
3234 /* Common symbols less than the GP size are automatically
3235 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3236 if (asym
->value
> elf_gp_size (abfd
)
3237 || IRIX_COMPAT (abfd
) == ict_irix6
)
3240 case SHN_MIPS_SCOMMON
:
3241 if (mips_elf_scom_section
.name
== NULL
)
3243 /* Initialize the small common section. */
3244 mips_elf_scom_section
.name
= ".scommon";
3245 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3246 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3247 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3248 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3249 mips_elf_scom_symbol
.name
= ".scommon";
3250 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3251 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3252 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3254 asym
->section
= &mips_elf_scom_section
;
3255 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3258 case SHN_MIPS_SUNDEFINED
:
3259 asym
->section
= bfd_und_section_ptr
;
3262 #if 0 /* for SGI_COMPAT */
3264 asym
->section
= mips_elf_text_section_ptr
;
3268 asym
->section
= mips_elf_data_section_ptr
;
3274 /* Work over a section just before writing it out. This routine is
3275 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3276 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3280 _bfd_mips_elf_section_processing (abfd
, hdr
)
3282 Elf_Internal_Shdr
*hdr
;
3284 if (hdr
->sh_type
== SHT_MIPS_REGINFO
3285 && hdr
->sh_size
> 0)
3289 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
3290 BFD_ASSERT (hdr
->contents
== NULL
);
3293 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
3296 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3297 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3301 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
3302 && hdr
->bfd_section
!= NULL
3303 && elf_section_data (hdr
->bfd_section
) != NULL
3304 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
3306 bfd_byte
*contents
, *l
, *lend
;
3308 /* We stored the section contents in the elf_section_data tdata
3309 field in the set_section_contents routine. We save the
3310 section contents so that we don't have to read them again.
3311 At this point we know that elf_gp is set, so we can look
3312 through the section contents to see if there is an
3313 ODK_REGINFO structure. */
3315 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
3317 lend
= contents
+ hdr
->sh_size
;
3318 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3320 Elf_Internal_Options intopt
;
3322 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3324 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3331 + sizeof (Elf_External_Options
)
3332 + (sizeof (Elf64_External_RegInfo
) - 8)),
3335 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
3336 if (bfd_bwrite (buf
, (bfd_size_type
) 8, abfd
) != 8)
3339 else if (intopt
.kind
== ODK_REGINFO
)
3346 + sizeof (Elf_External_Options
)
3347 + (sizeof (Elf32_External_RegInfo
) - 4)),
3350 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3351 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3358 if (hdr
->bfd_section
!= NULL
)
3360 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3362 if (strcmp (name
, ".sdata") == 0
3363 || strcmp (name
, ".lit8") == 0
3364 || strcmp (name
, ".lit4") == 0)
3366 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3367 hdr
->sh_type
= SHT_PROGBITS
;
3369 else if (strcmp (name
, ".sbss") == 0)
3371 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3372 hdr
->sh_type
= SHT_NOBITS
;
3374 else if (strcmp (name
, ".srdata") == 0)
3376 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
3377 hdr
->sh_type
= SHT_PROGBITS
;
3379 else if (strcmp (name
, ".compact_rel") == 0)
3382 hdr
->sh_type
= SHT_PROGBITS
;
3384 else if (strcmp (name
, ".rtproc") == 0)
3386 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
3388 unsigned int adjust
;
3390 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
3392 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
3400 /* Handle a MIPS specific section when reading an object file. This
3401 is called when elfcode.h finds a section with an unknown type.
3402 This routine supports both the 32-bit and 64-bit ELF ABI.
3404 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
3408 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
3410 Elf_Internal_Shdr
*hdr
;
3415 /* There ought to be a place to keep ELF backend specific flags, but
3416 at the moment there isn't one. We just keep track of the
3417 sections by their name, instead. Fortunately, the ABI gives
3418 suggested names for all the MIPS specific sections, so we will
3419 probably get away with this. */
3420 switch (hdr
->sh_type
)
3422 case SHT_MIPS_LIBLIST
:
3423 if (strcmp (name
, ".liblist") != 0)
3427 if (strcmp (name
, ".msym") != 0)
3430 case SHT_MIPS_CONFLICT
:
3431 if (strcmp (name
, ".conflict") != 0)
3434 case SHT_MIPS_GPTAB
:
3435 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
3438 case SHT_MIPS_UCODE
:
3439 if (strcmp (name
, ".ucode") != 0)
3442 case SHT_MIPS_DEBUG
:
3443 if (strcmp (name
, ".mdebug") != 0)
3445 flags
= SEC_DEBUGGING
;
3447 case SHT_MIPS_REGINFO
:
3448 if (strcmp (name
, ".reginfo") != 0
3449 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
3451 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
3453 case SHT_MIPS_IFACE
:
3454 if (strcmp (name
, ".MIPS.interfaces") != 0)
3457 case SHT_MIPS_CONTENT
:
3458 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
3461 case SHT_MIPS_OPTIONS
:
3462 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
3465 case SHT_MIPS_DWARF
:
3466 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
3469 case SHT_MIPS_SYMBOL_LIB
:
3470 if (strcmp (name
, ".MIPS.symlib") != 0)
3473 case SHT_MIPS_EVENTS
:
3474 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
3475 && strncmp (name
, ".MIPS.post_rel",
3476 sizeof ".MIPS.post_rel" - 1) != 0)
3483 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
3488 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
3489 (bfd_get_section_flags (abfd
,
3495 /* FIXME: We should record sh_info for a .gptab section. */
3497 /* For a .reginfo section, set the gp value in the tdata information
3498 from the contents of this section. We need the gp value while
3499 processing relocs, so we just get it now. The .reginfo section
3500 is not used in the 64-bit MIPS ELF ABI. */
3501 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
3503 Elf32_External_RegInfo ext
;
3506 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
3508 (bfd_size_type
) sizeof ext
))
3510 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
3511 elf_gp (abfd
) = s
.ri_gp_value
;
3514 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
3515 set the gp value based on what we find. We may see both
3516 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
3517 they should agree. */
3518 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
3520 bfd_byte
*contents
, *l
, *lend
;
3522 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
3523 if (contents
== NULL
)
3525 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
3526 (file_ptr
) 0, hdr
->sh_size
))
3532 lend
= contents
+ hdr
->sh_size
;
3533 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3535 Elf_Internal_Options intopt
;
3537 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3539 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3541 Elf64_Internal_RegInfo intreg
;
3543 bfd_mips_elf64_swap_reginfo_in
3545 ((Elf64_External_RegInfo
*)
3546 (l
+ sizeof (Elf_External_Options
))),
3548 elf_gp (abfd
) = intreg
.ri_gp_value
;
3550 else if (intopt
.kind
== ODK_REGINFO
)
3552 Elf32_RegInfo intreg
;
3554 bfd_mips_elf32_swap_reginfo_in
3556 ((Elf32_External_RegInfo
*)
3557 (l
+ sizeof (Elf_External_Options
))),
3559 elf_gp (abfd
) = intreg
.ri_gp_value
;
3569 /* Set the correct type for a MIPS ELF section. We do this by the
3570 section name, which is a hack, but ought to work. This routine is
3571 used by both the 32-bit and the 64-bit ABI. */
3574 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
3576 Elf_Internal_Shdr
*hdr
;
3579 register const char *name
;
3581 name
= bfd_get_section_name (abfd
, sec
);
3583 if (strcmp (name
, ".liblist") == 0)
3585 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
3586 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
3587 /* The sh_link field is set in final_write_processing. */
3589 else if (strcmp (name
, ".conflict") == 0)
3590 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
3591 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3593 hdr
->sh_type
= SHT_MIPS_GPTAB
;
3594 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
3595 /* The sh_info field is set in final_write_processing. */
3597 else if (strcmp (name
, ".ucode") == 0)
3598 hdr
->sh_type
= SHT_MIPS_UCODE
;
3599 else if (strcmp (name
, ".mdebug") == 0)
3601 hdr
->sh_type
= SHT_MIPS_DEBUG
;
3602 /* In a shared object on IRIX 5.3, the .mdebug section has an
3603 entsize of 0. FIXME: Does this matter? */
3604 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
3605 hdr
->sh_entsize
= 0;
3607 hdr
->sh_entsize
= 1;
3609 else if (strcmp (name
, ".reginfo") == 0)
3611 hdr
->sh_type
= SHT_MIPS_REGINFO
;
3612 /* In a shared object on IRIX 5.3, the .reginfo section has an
3613 entsize of 0x18. FIXME: Does this matter? */
3614 if (SGI_COMPAT (abfd
))
3616 if ((abfd
->flags
& DYNAMIC
) != 0)
3617 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3619 hdr
->sh_entsize
= 1;
3622 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3624 else if (SGI_COMPAT (abfd
)
3625 && (strcmp (name
, ".hash") == 0
3626 || strcmp (name
, ".dynamic") == 0
3627 || strcmp (name
, ".dynstr") == 0))
3629 if (SGI_COMPAT (abfd
))
3630 hdr
->sh_entsize
= 0;
3632 /* This isn't how the IRIX6 linker behaves. */
3633 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
3636 else if (strcmp (name
, ".got") == 0
3637 || strcmp (name
, ".srdata") == 0
3638 || strcmp (name
, ".sdata") == 0
3639 || strcmp (name
, ".sbss") == 0
3640 || strcmp (name
, ".lit4") == 0
3641 || strcmp (name
, ".lit8") == 0)
3642 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
3643 else if (strcmp (name
, ".MIPS.interfaces") == 0)
3645 hdr
->sh_type
= SHT_MIPS_IFACE
;
3646 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3648 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
3650 hdr
->sh_type
= SHT_MIPS_CONTENT
;
3651 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3652 /* The sh_info field is set in final_write_processing. */
3654 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3656 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
3657 hdr
->sh_entsize
= 1;
3658 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3660 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
3661 hdr
->sh_type
= SHT_MIPS_DWARF
;
3662 else if (strcmp (name
, ".MIPS.symlib") == 0)
3664 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
3665 /* The sh_link and sh_info fields are set in
3666 final_write_processing. */
3668 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
3669 || strncmp (name
, ".MIPS.post_rel",
3670 sizeof ".MIPS.post_rel" - 1) == 0)
3672 hdr
->sh_type
= SHT_MIPS_EVENTS
;
3673 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3674 /* The sh_link field is set in final_write_processing. */
3676 else if (strcmp (name
, ".msym") == 0)
3678 hdr
->sh_type
= SHT_MIPS_MSYM
;
3679 hdr
->sh_flags
|= SHF_ALLOC
;
3680 hdr
->sh_entsize
= 8;
3683 /* The generic elf_fake_sections will set up REL_HDR using the
3684 default kind of relocations. But, we may actually need both
3685 kinds of relocations, so we set up the second header here.
3687 This is not necessary for the O32 ABI since that only uses Elf32_Rel
3688 relocations (cf. System V ABI, MIPS RISC Processor Supplement,
3689 3rd Edition, p. 4-17). It breaks the IRIX 5/6 32-bit ld, since one
3690 of the resulting empty .rela.<section> sections starts with
3691 sh_offset == object size, and ld doesn't allow that. While the check
3692 is arguably bogus for empty or SHT_NOBITS sections, it can easily be
3693 avoided by not emitting those useless sections in the first place. */
3694 if (! SGI_COMPAT (abfd
) && ! NEWABI_P(abfd
)
3695 && (sec
->flags
& SEC_RELOC
) != 0)
3697 struct bfd_elf_section_data
*esd
;
3698 bfd_size_type amt
= sizeof (Elf_Internal_Shdr
);
3700 esd
= elf_section_data (sec
);
3701 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
3702 esd
->rel_hdr2
= (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, amt
);
3705 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
3706 !elf_section_data (sec
)->use_rela_p
);
3712 /* Given a BFD section, try to locate the corresponding ELF section
3713 index. This is used by both the 32-bit and the 64-bit ABI.
3714 Actually, it's not clear to me that the 64-bit ABI supports these,
3715 but for non-PIC objects we will certainly want support for at least
3716 the .scommon section. */
3719 _bfd_mips_elf_section_from_bfd_section (abfd
, sec
, retval
)
3720 bfd
*abfd ATTRIBUTE_UNUSED
;
3724 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3726 *retval
= SHN_MIPS_SCOMMON
;
3729 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
3731 *retval
= SHN_MIPS_ACOMMON
;
3737 /* Hook called by the linker routine which adds symbols from an object
3738 file. We must handle the special MIPS section numbers here. */
3741 _bfd_mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3743 struct bfd_link_info
*info
;
3744 const Elf_Internal_Sym
*sym
;
3746 flagword
*flagsp ATTRIBUTE_UNUSED
;
3750 if (SGI_COMPAT (abfd
)
3751 && (abfd
->flags
& DYNAMIC
) != 0
3752 && strcmp (*namep
, "_rld_new_interface") == 0)
3754 /* Skip IRIX5 rld entry name. */
3759 switch (sym
->st_shndx
)
3762 /* Common symbols less than the GP size are automatically
3763 treated as SHN_MIPS_SCOMMON symbols. */
3764 if (sym
->st_size
> elf_gp_size (abfd
)
3765 || IRIX_COMPAT (abfd
) == ict_irix6
)
3768 case SHN_MIPS_SCOMMON
:
3769 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3770 (*secp
)->flags
|= SEC_IS_COMMON
;
3771 *valp
= sym
->st_size
;
3775 /* This section is used in a shared object. */
3776 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
3778 asymbol
*elf_text_symbol
;
3779 asection
*elf_text_section
;
3780 bfd_size_type amt
= sizeof (asection
);
3782 elf_text_section
= bfd_zalloc (abfd
, amt
);
3783 if (elf_text_section
== NULL
)
3786 amt
= sizeof (asymbol
);
3787 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
3788 if (elf_text_symbol
== NULL
)
3791 /* Initialize the section. */
3793 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
3794 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
3796 elf_text_section
->symbol
= elf_text_symbol
;
3797 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
3799 elf_text_section
->name
= ".text";
3800 elf_text_section
->flags
= SEC_NO_FLAGS
;
3801 elf_text_section
->output_section
= NULL
;
3802 elf_text_section
->owner
= abfd
;
3803 elf_text_symbol
->name
= ".text";
3804 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
3805 elf_text_symbol
->section
= elf_text_section
;
3807 /* This code used to do *secp = bfd_und_section_ptr if
3808 info->shared. I don't know why, and that doesn't make sense,
3809 so I took it out. */
3810 *secp
= elf_tdata (abfd
)->elf_text_section
;
3813 case SHN_MIPS_ACOMMON
:
3814 /* Fall through. XXX Can we treat this as allocated data? */
3816 /* This section is used in a shared object. */
3817 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
3819 asymbol
*elf_data_symbol
;
3820 asection
*elf_data_section
;
3821 bfd_size_type amt
= sizeof (asection
);
3823 elf_data_section
= bfd_zalloc (abfd
, amt
);
3824 if (elf_data_section
== NULL
)
3827 amt
= sizeof (asymbol
);
3828 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
3829 if (elf_data_symbol
== NULL
)
3832 /* Initialize the section. */
3834 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
3835 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
3837 elf_data_section
->symbol
= elf_data_symbol
;
3838 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
3840 elf_data_section
->name
= ".data";
3841 elf_data_section
->flags
= SEC_NO_FLAGS
;
3842 elf_data_section
->output_section
= NULL
;
3843 elf_data_section
->owner
= abfd
;
3844 elf_data_symbol
->name
= ".data";
3845 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
3846 elf_data_symbol
->section
= elf_data_section
;
3848 /* This code used to do *secp = bfd_und_section_ptr if
3849 info->shared. I don't know why, and that doesn't make sense,
3850 so I took it out. */
3851 *secp
= elf_tdata (abfd
)->elf_data_section
;
3854 case SHN_MIPS_SUNDEFINED
:
3855 *secp
= bfd_und_section_ptr
;
3859 if (SGI_COMPAT (abfd
)
3861 && info
->hash
->creator
== abfd
->xvec
3862 && strcmp (*namep
, "__rld_obj_head") == 0)
3864 struct elf_link_hash_entry
*h
;
3865 struct bfd_link_hash_entry
*bh
;
3867 /* Mark __rld_obj_head as dynamic. */
3869 if (! (_bfd_generic_link_add_one_symbol
3870 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3871 (bfd_vma
) *valp
, (const char *) NULL
, FALSE
,
3872 get_elf_backend_data (abfd
)->collect
, &bh
)))
3875 h
= (struct elf_link_hash_entry
*) bh
;
3876 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3877 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3878 h
->type
= STT_OBJECT
;
3880 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3883 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
3886 /* If this is a mips16 text symbol, add 1 to the value to make it
3887 odd. This will cause something like .word SYM to come up with
3888 the right value when it is loaded into the PC. */
3889 if (sym
->st_other
== STO_MIPS16
)
3895 /* This hook function is called before the linker writes out a global
3896 symbol. We mark symbols as small common if appropriate. This is
3897 also where we undo the increment of the value for a mips16 symbol. */
3900 _bfd_mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
3901 bfd
*abfd ATTRIBUTE_UNUSED
;
3902 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3903 const char *name ATTRIBUTE_UNUSED
;
3904 Elf_Internal_Sym
*sym
;
3905 asection
*input_sec
;
3907 /* If we see a common symbol, which implies a relocatable link, then
3908 if a symbol was small common in an input file, mark it as small
3909 common in the output file. */
3910 if (sym
->st_shndx
== SHN_COMMON
3911 && strcmp (input_sec
->name
, ".scommon") == 0)
3912 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
3914 if (sym
->st_other
== STO_MIPS16
3915 && (sym
->st_value
& 1) != 0)
3921 /* Functions for the dynamic linker. */
3923 /* Create dynamic sections when linking against a dynamic object. */
3926 _bfd_mips_elf_create_dynamic_sections (abfd
, info
)
3928 struct bfd_link_info
*info
;
3930 struct elf_link_hash_entry
*h
;
3931 struct bfd_link_hash_entry
*bh
;
3933 register asection
*s
;
3934 const char * const *namep
;
3936 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3937 | SEC_LINKER_CREATED
| SEC_READONLY
);
3939 /* Mips ABI requests the .dynamic section to be read only. */
3940 s
= bfd_get_section_by_name (abfd
, ".dynamic");
3943 if (! bfd_set_section_flags (abfd
, s
, flags
))
3947 /* We need to create .got section. */
3948 if (! mips_elf_create_got_section (abfd
, info
))
3951 /* Create the .msym section on IRIX6. It is used by the dynamic
3952 linker to speed up dynamic relocations, and to avoid computing
3953 the ELF hash for symbols. */
3954 if (IRIX_COMPAT (abfd
) == ict_irix6
3955 && !mips_elf_create_msym_section (abfd
))
3958 /* Create .stub section. */
3959 if (bfd_get_section_by_name (abfd
,
3960 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
3962 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
3964 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
3965 || ! bfd_set_section_alignment (abfd
, s
,
3966 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
3970 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
3972 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
3974 s
= bfd_make_section (abfd
, ".rld_map");
3976 || ! bfd_set_section_flags (abfd
, s
, flags
&~ (flagword
) SEC_READONLY
)
3977 || ! bfd_set_section_alignment (abfd
, s
,
3978 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
3982 /* On IRIX5, we adjust add some additional symbols and change the
3983 alignments of several sections. There is no ABI documentation
3984 indicating that this is necessary on IRIX6, nor any evidence that
3985 the linker takes such action. */
3986 if (IRIX_COMPAT (abfd
) == ict_irix5
)
3988 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
3991 if (! (_bfd_generic_link_add_one_symbol
3992 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
3993 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
3994 get_elf_backend_data (abfd
)->collect
, &bh
)))
3997 h
= (struct elf_link_hash_entry
*) bh
;
3998 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3999 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4000 h
->type
= STT_SECTION
;
4002 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4006 /* We need to create a .compact_rel section. */
4007 if (SGI_COMPAT (abfd
))
4009 if (!mips_elf_create_compact_rel_section (abfd
, info
))
4013 /* Change alignments of some sections. */
4014 s
= bfd_get_section_by_name (abfd
, ".hash");
4016 bfd_set_section_alignment (abfd
, s
, 4);
4017 s
= bfd_get_section_by_name (abfd
, ".dynsym");
4019 bfd_set_section_alignment (abfd
, s
, 4);
4020 s
= bfd_get_section_by_name (abfd
, ".dynstr");
4022 bfd_set_section_alignment (abfd
, s
, 4);
4023 s
= bfd_get_section_by_name (abfd
, ".reginfo");
4025 bfd_set_section_alignment (abfd
, s
, 4);
4026 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4028 bfd_set_section_alignment (abfd
, s
, 4);
4035 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
4037 if (!(_bfd_generic_link_add_one_symbol
4038 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
,
4039 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
4040 get_elf_backend_data (abfd
)->collect
, &bh
)))
4043 h
= (struct elf_link_hash_entry
*) bh
;
4044 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4045 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4046 h
->type
= STT_SECTION
;
4048 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4051 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
4053 /* __rld_map is a four byte word located in the .data section
4054 and is filled in by the rtld to contain a pointer to
4055 the _r_debug structure. Its symbol value will be set in
4056 _bfd_mips_elf_finish_dynamic_symbol. */
4057 s
= bfd_get_section_by_name (abfd
, ".rld_map");
4058 BFD_ASSERT (s
!= NULL
);
4060 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
4062 if (!(_bfd_generic_link_add_one_symbol
4063 (info
, abfd
, name
, BSF_GLOBAL
, s
,
4064 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
4065 get_elf_backend_data (abfd
)->collect
, &bh
)))
4068 h
= (struct elf_link_hash_entry
*) bh
;
4069 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4070 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4071 h
->type
= STT_OBJECT
;
4073 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4081 /* Look through the relocs for a section during the first phase, and
4082 allocate space in the global offset table. */
4085 _bfd_mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
4087 struct bfd_link_info
*info
;
4089 const Elf_Internal_Rela
*relocs
;
4093 Elf_Internal_Shdr
*symtab_hdr
;
4094 struct elf_link_hash_entry
**sym_hashes
;
4095 struct mips_got_info
*g
;
4097 const Elf_Internal_Rela
*rel
;
4098 const Elf_Internal_Rela
*rel_end
;
4101 struct elf_backend_data
*bed
;
4103 if (info
->relocateable
)
4106 dynobj
= elf_hash_table (info
)->dynobj
;
4107 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4108 sym_hashes
= elf_sym_hashes (abfd
);
4109 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
4111 /* Check for the mips16 stub sections. */
4113 name
= bfd_get_section_name (abfd
, sec
);
4114 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
4116 unsigned long r_symndx
;
4118 /* Look at the relocation information to figure out which symbol
4121 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
4123 if (r_symndx
< extsymoff
4124 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
4128 /* This stub is for a local symbol. This stub will only be
4129 needed if there is some relocation in this BFD, other
4130 than a 16 bit function call, which refers to this symbol. */
4131 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4133 Elf_Internal_Rela
*sec_relocs
;
4134 const Elf_Internal_Rela
*r
, *rend
;
4136 /* We can ignore stub sections when looking for relocs. */
4137 if ((o
->flags
& SEC_RELOC
) == 0
4138 || o
->reloc_count
== 0
4139 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
4140 sizeof FN_STUB
- 1) == 0
4141 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
4142 sizeof CALL_STUB
- 1) == 0
4143 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
4144 sizeof CALL_FP_STUB
- 1) == 0)
4147 sec_relocs
= (MNAME(abfd
,_bfd_elf
,link_read_relocs
)
4148 (abfd
, o
, (PTR
) NULL
,
4149 (Elf_Internal_Rela
*) NULL
,
4150 info
->keep_memory
));
4151 if (sec_relocs
== NULL
)
4154 rend
= sec_relocs
+ o
->reloc_count
;
4155 for (r
= sec_relocs
; r
< rend
; r
++)
4156 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
4157 && ELF_R_TYPE (abfd
, r
->r_info
) != R_MIPS16_26
)
4160 if (elf_section_data (o
)->relocs
!= sec_relocs
)
4169 /* There is no non-call reloc for this stub, so we do
4170 not need it. Since this function is called before
4171 the linker maps input sections to output sections, we
4172 can easily discard it by setting the SEC_EXCLUDE
4174 sec
->flags
|= SEC_EXCLUDE
;
4178 /* Record this stub in an array of local symbol stubs for
4180 if (elf_tdata (abfd
)->local_stubs
== NULL
)
4182 unsigned long symcount
;
4186 if (elf_bad_symtab (abfd
))
4187 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
4189 symcount
= symtab_hdr
->sh_info
;
4190 amt
= symcount
* sizeof (asection
*);
4191 n
= (asection
**) bfd_zalloc (abfd
, amt
);
4194 elf_tdata (abfd
)->local_stubs
= n
;
4197 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
4199 /* We don't need to set mips16_stubs_seen in this case.
4200 That flag is used to see whether we need to look through
4201 the global symbol table for stubs. We don't need to set
4202 it here, because we just have a local stub. */
4206 struct mips_elf_link_hash_entry
*h
;
4208 h
= ((struct mips_elf_link_hash_entry
*)
4209 sym_hashes
[r_symndx
- extsymoff
]);
4211 /* H is the symbol this stub is for. */
4214 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
4217 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
4218 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4220 unsigned long r_symndx
;
4221 struct mips_elf_link_hash_entry
*h
;
4224 /* Look at the relocation information to figure out which symbol
4227 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
4229 if (r_symndx
< extsymoff
4230 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
4232 /* This stub was actually built for a static symbol defined
4233 in the same file. We assume that all static symbols in
4234 mips16 code are themselves mips16, so we can simply
4235 discard this stub. Since this function is called before
4236 the linker maps input sections to output sections, we can
4237 easily discard it by setting the SEC_EXCLUDE flag. */
4238 sec
->flags
|= SEC_EXCLUDE
;
4242 h
= ((struct mips_elf_link_hash_entry
*)
4243 sym_hashes
[r_symndx
- extsymoff
]);
4245 /* H is the symbol this stub is for. */
4247 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4248 loc
= &h
->call_fp_stub
;
4250 loc
= &h
->call_stub
;
4252 /* If we already have an appropriate stub for this function, we
4253 don't need another one, so we can discard this one. Since
4254 this function is called before the linker maps input sections
4255 to output sections, we can easily discard it by setting the
4256 SEC_EXCLUDE flag. We can also discard this section if we
4257 happen to already know that this is a mips16 function; it is
4258 not necessary to check this here, as it is checked later, but
4259 it is slightly faster to check now. */
4260 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
4262 sec
->flags
|= SEC_EXCLUDE
;
4267 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
4277 sgot
= mips_elf_got_section (dynobj
);
4282 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4283 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4284 BFD_ASSERT (g
!= NULL
);
4289 bed
= get_elf_backend_data (abfd
);
4290 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
4291 for (rel
= relocs
; rel
< rel_end
; ++rel
)
4293 unsigned long r_symndx
;
4294 unsigned int r_type
;
4295 struct elf_link_hash_entry
*h
;
4297 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
4298 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
4300 if (r_symndx
< extsymoff
)
4302 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
4304 (*_bfd_error_handler
)
4305 (_("%s: Malformed reloc detected for section %s"),
4306 bfd_archive_filename (abfd
), name
);
4307 bfd_set_error (bfd_error_bad_value
);
4312 h
= sym_hashes
[r_symndx
- extsymoff
];
4314 /* This may be an indirect symbol created because of a version. */
4317 while (h
->root
.type
== bfd_link_hash_indirect
)
4318 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4322 /* Some relocs require a global offset table. */
4323 if (dynobj
== NULL
|| sgot
== NULL
)
4329 case R_MIPS_CALL_HI16
:
4330 case R_MIPS_CALL_LO16
:
4331 case R_MIPS_GOT_HI16
:
4332 case R_MIPS_GOT_LO16
:
4333 case R_MIPS_GOT_PAGE
:
4334 case R_MIPS_GOT_OFST
:
4335 case R_MIPS_GOT_DISP
:
4337 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4338 if (! mips_elf_create_got_section (dynobj
, info
))
4340 g
= mips_elf_got_info (dynobj
, &sgot
);
4347 && (info
->shared
|| h
!= NULL
)
4348 && (sec
->flags
& SEC_ALLOC
) != 0)
4349 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4357 if (!h
&& (r_type
== R_MIPS_CALL_LO16
4358 || r_type
== R_MIPS_GOT_LO16
4359 || r_type
== R_MIPS_GOT_DISP
))
4361 /* We may need a local GOT entry for this relocation. We
4362 don't count R_MIPS_GOT_PAGE because we can estimate the
4363 maximum number of pages needed by looking at the size of
4364 the segment. Similar comments apply to R_MIPS_GOT16 and
4365 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
4366 R_MIPS_CALL_HI16 because these are always followed by an
4367 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
4369 This estimation is very conservative since we can merge
4370 duplicate entries in the GOT. In order to be less
4371 conservative, we could actually build the GOT here,
4372 rather than in relocate_section. */
4374 sgot
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
4382 (*_bfd_error_handler
)
4383 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
4384 bfd_archive_filename (abfd
), (unsigned long) rel
->r_offset
);
4385 bfd_set_error (bfd_error_bad_value
);
4390 case R_MIPS_CALL_HI16
:
4391 case R_MIPS_CALL_LO16
:
4394 /* This symbol requires a global offset table entry. */
4395 if (! mips_elf_record_global_got_symbol (h
, info
, g
))
4398 /* We need a stub, not a plt entry for the undefined
4399 function. But we record it as if it needs plt. See
4400 elf_adjust_dynamic_symbol in elflink.h. */
4401 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4407 case R_MIPS_GOT_HI16
:
4408 case R_MIPS_GOT_LO16
:
4409 case R_MIPS_GOT_DISP
:
4410 /* This symbol requires a global offset table entry. */
4411 if (h
&& ! mips_elf_record_global_got_symbol (h
, info
, g
))
4418 if ((info
->shared
|| h
!= NULL
)
4419 && (sec
->flags
& SEC_ALLOC
) != 0)
4423 const char *dname
= ".rel.dyn";
4425 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
4428 sreloc
= bfd_make_section (dynobj
, dname
);
4430 || ! bfd_set_section_flags (dynobj
, sreloc
,
4435 | SEC_LINKER_CREATED
4437 || ! bfd_set_section_alignment (dynobj
, sreloc
,
4442 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
4445 /* When creating a shared object, we must copy these
4446 reloc types into the output file as R_MIPS_REL32
4447 relocs. We make room for this reloc in the
4448 .rel.dyn reloc section. */
4449 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
4450 if ((sec
->flags
& MIPS_READONLY_SECTION
)
4451 == MIPS_READONLY_SECTION
)
4452 /* We tell the dynamic linker that there are
4453 relocations against the text segment. */
4454 info
->flags
|= DF_TEXTREL
;
4458 struct mips_elf_link_hash_entry
*hmips
;
4460 /* We only need to copy this reloc if the symbol is
4461 defined in a dynamic object. */
4462 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4463 ++hmips
->possibly_dynamic_relocs
;
4464 if ((sec
->flags
& MIPS_READONLY_SECTION
)
4465 == MIPS_READONLY_SECTION
)
4466 /* We need it to tell the dynamic linker if there
4467 are relocations against the text segment. */
4468 hmips
->readonly_reloc
= TRUE
;
4471 /* Even though we don't directly need a GOT entry for
4472 this symbol, a symbol must have a dynamic symbol
4473 table index greater that DT_MIPS_GOTSYM if there are
4474 dynamic relocations against it. */
4476 && ! mips_elf_record_global_got_symbol (h
, info
, g
))
4480 if (SGI_COMPAT (abfd
))
4481 mips_elf_hash_table (info
)->compact_rel_size
+=
4482 sizeof (Elf32_External_crinfo
);
4486 case R_MIPS_GPREL16
:
4487 case R_MIPS_LITERAL
:
4488 case R_MIPS_GPREL32
:
4489 if (SGI_COMPAT (abfd
))
4490 mips_elf_hash_table (info
)->compact_rel_size
+=
4491 sizeof (Elf32_External_crinfo
);
4494 /* This relocation describes the C++ object vtable hierarchy.
4495 Reconstruct it for later use during GC. */
4496 case R_MIPS_GNU_VTINHERIT
:
4497 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4501 /* This relocation describes which C++ vtable entries are actually
4502 used. Record for later use during GC. */
4503 case R_MIPS_GNU_VTENTRY
:
4504 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
4512 /* We must not create a stub for a symbol that has relocations
4513 related to taking the function's address. */
4519 struct mips_elf_link_hash_entry
*mh
;
4521 mh
= (struct mips_elf_link_hash_entry
*) h
;
4522 mh
->no_fn_stub
= TRUE
;
4526 case R_MIPS_CALL_HI16
:
4527 case R_MIPS_CALL_LO16
:
4531 /* If this reloc is not a 16 bit call, and it has a global
4532 symbol, then we will need the fn_stub if there is one.
4533 References from a stub section do not count. */
4535 && r_type
!= R_MIPS16_26
4536 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
4537 sizeof FN_STUB
- 1) != 0
4538 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
4539 sizeof CALL_STUB
- 1) != 0
4540 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
4541 sizeof CALL_FP_STUB
- 1) != 0)
4543 struct mips_elf_link_hash_entry
*mh
;
4545 mh
= (struct mips_elf_link_hash_entry
*) h
;
4546 mh
->need_fn_stub
= TRUE
;
4553 /* Adjust a symbol defined by a dynamic object and referenced by a
4554 regular object. The current definition is in some section of the
4555 dynamic object, but we're not including those sections. We have to
4556 change the definition to something the rest of the link can
4560 _bfd_mips_elf_adjust_dynamic_symbol (info
, h
)
4561 struct bfd_link_info
*info
;
4562 struct elf_link_hash_entry
*h
;
4565 struct mips_elf_link_hash_entry
*hmips
;
4568 dynobj
= elf_hash_table (info
)->dynobj
;
4570 /* Make sure we know what is going on here. */
4571 BFD_ASSERT (dynobj
!= NULL
4572 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
4573 || h
->weakdef
!= NULL
4574 || ((h
->elf_link_hash_flags
4575 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4576 && (h
->elf_link_hash_flags
4577 & ELF_LINK_HASH_REF_REGULAR
) != 0
4578 && (h
->elf_link_hash_flags
4579 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
4581 /* If this symbol is defined in a dynamic object, we need to copy
4582 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
4584 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4585 if (! info
->relocateable
4586 && hmips
->possibly_dynamic_relocs
!= 0
4587 && (h
->root
.type
== bfd_link_hash_defweak
4588 || (h
->elf_link_hash_flags
4589 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4591 mips_elf_allocate_dynamic_relocations (dynobj
,
4592 hmips
->possibly_dynamic_relocs
);
4593 if (hmips
->readonly_reloc
)
4594 /* We tell the dynamic linker that there are relocations
4595 against the text segment. */
4596 info
->flags
|= DF_TEXTREL
;
4599 /* For a function, create a stub, if allowed. */
4600 if (! hmips
->no_fn_stub
4601 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4603 if (! elf_hash_table (info
)->dynamic_sections_created
)
4606 /* If this symbol is not defined in a regular file, then set
4607 the symbol to the stub location. This is required to make
4608 function pointers compare as equal between the normal
4609 executable and the shared library. */
4610 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4612 /* We need .stub section. */
4613 s
= bfd_get_section_by_name (dynobj
,
4614 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
4615 BFD_ASSERT (s
!= NULL
);
4617 h
->root
.u
.def
.section
= s
;
4618 h
->root
.u
.def
.value
= s
->_raw_size
;
4620 /* XXX Write this stub address somewhere. */
4621 h
->plt
.offset
= s
->_raw_size
;
4623 /* Make room for this stub code. */
4624 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4626 /* The last half word of the stub will be filled with the index
4627 of this symbol in .dynsym section. */
4631 else if ((h
->type
== STT_FUNC
)
4632 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
4634 /* This will set the entry for this symbol in the GOT to 0, and
4635 the dynamic linker will take care of this. */
4636 h
->root
.u
.def
.value
= 0;
4640 /* If this is a weak symbol, and there is a real definition, the
4641 processor independent code will have arranged for us to see the
4642 real definition first, and we can just use the same value. */
4643 if (h
->weakdef
!= NULL
)
4645 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4646 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4647 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4648 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4652 /* This is a reference to a symbol defined by a dynamic object which
4653 is not a function. */
4658 /* This function is called after all the input files have been read,
4659 and the input sections have been assigned to output sections. We
4660 check for any mips16 stub sections that we can discard. */
4663 _bfd_mips_elf_always_size_sections (output_bfd
, info
)
4665 struct bfd_link_info
*info
;
4669 /* The .reginfo section has a fixed size. */
4670 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
4672 bfd_set_section_size (output_bfd
, ri
,
4673 (bfd_size_type
) sizeof (Elf32_External_RegInfo
));
4675 if (info
->relocateable
4676 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
4679 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4680 mips_elf_check_mips16_stubs
,
4686 /* Set the sizes of the dynamic sections. */
4689 _bfd_mips_elf_size_dynamic_sections (output_bfd
, info
)
4691 struct bfd_link_info
*info
;
4695 bfd_boolean reltext
;
4696 struct mips_got_info
*g
= NULL
;
4698 dynobj
= elf_hash_table (info
)->dynobj
;
4699 BFD_ASSERT (dynobj
!= NULL
);
4701 if (elf_hash_table (info
)->dynamic_sections_created
)
4703 /* Set the contents of the .interp section to the interpreter. */
4706 s
= bfd_get_section_by_name (dynobj
, ".interp");
4707 BFD_ASSERT (s
!= NULL
);
4709 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
4711 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
4715 /* The check_relocs and adjust_dynamic_symbol entry points have
4716 determined the sizes of the various dynamic sections. Allocate
4719 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4724 /* It's OK to base decisions on the section name, because none
4725 of the dynobj section names depend upon the input files. */
4726 name
= bfd_get_section_name (dynobj
, s
);
4728 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4733 if (strncmp (name
, ".rel", 4) == 0)
4735 if (s
->_raw_size
== 0)
4737 /* We only strip the section if the output section name
4738 has the same name. Otherwise, there might be several
4739 input sections for this output section. FIXME: This
4740 code is probably not needed these days anyhow, since
4741 the linker now does not create empty output sections. */
4742 if (s
->output_section
!= NULL
4744 bfd_get_section_name (s
->output_section
->owner
,
4745 s
->output_section
)) == 0)
4750 const char *outname
;
4753 /* If this relocation section applies to a read only
4754 section, then we probably need a DT_TEXTREL entry.
4755 If the relocation section is .rel.dyn, we always
4756 assert a DT_TEXTREL entry rather than testing whether
4757 there exists a relocation to a read only section or
4759 outname
= bfd_get_section_name (output_bfd
,
4761 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
4763 && (target
->flags
& SEC_READONLY
) != 0
4764 && (target
->flags
& SEC_ALLOC
) != 0)
4765 || strcmp (outname
, ".rel.dyn") == 0)
4768 /* We use the reloc_count field as a counter if we need
4769 to copy relocs into the output file. */
4770 if (strcmp (name
, ".rel.dyn") != 0)
4774 else if (strncmp (name
, ".got", 4) == 0)
4777 bfd_size_type loadable_size
= 0;
4778 bfd_size_type local_gotno
;
4781 BFD_ASSERT (elf_section_data (s
) != NULL
);
4782 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
4783 BFD_ASSERT (g
!= NULL
);
4785 /* Calculate the total loadable size of the output. That
4786 will give us the maximum number of GOT_PAGE entries
4788 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
4790 asection
*subsection
;
4792 for (subsection
= sub
->sections
;
4794 subsection
= subsection
->next
)
4796 if ((subsection
->flags
& SEC_ALLOC
) == 0)
4798 loadable_size
+= ((subsection
->_raw_size
+ 0xf)
4799 &~ (bfd_size_type
) 0xf);
4802 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
4804 /* Assume there are two loadable segments consisting of
4805 contiguous sections. Is 5 enough? */
4806 local_gotno
= (loadable_size
>> 16) + 5;
4807 if (NEWABI_P (output_bfd
))
4808 /* It's possible we will need GOT_PAGE entries as well as
4809 GOT16 entries. Often, these will be able to share GOT
4810 entries, but not always. */
4813 g
->local_gotno
+= local_gotno
;
4814 s
->_raw_size
+= local_gotno
* MIPS_ELF_GOT_SIZE (dynobj
);
4816 /* There has to be a global GOT entry for every symbol with
4817 a dynamic symbol table index of DT_MIPS_GOTSYM or
4818 higher. Therefore, it make sense to put those symbols
4819 that need GOT entries at the end of the symbol table. We
4821 if (! mips_elf_sort_hash_table (info
, 1))
4824 if (g
->global_gotsym
!= NULL
)
4825 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
4827 /* If there are no global symbols, or none requiring
4828 relocations, then GLOBAL_GOTSYM will be NULL. */
4830 g
->global_gotno
= i
;
4831 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (dynobj
);
4833 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
4835 /* IRIX rld assumes that the function stub isn't at the end
4836 of .text section. So put a dummy. XXX */
4837 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4839 else if (! info
->shared
4840 && ! mips_elf_hash_table (info
)->use_rld_obj_head
4841 && strncmp (name
, ".rld_map", 8) == 0)
4843 /* We add a room for __rld_map. It will be filled in by the
4844 rtld to contain a pointer to the _r_debug structure. */
4847 else if (SGI_COMPAT (output_bfd
)
4848 && strncmp (name
, ".compact_rel", 12) == 0)
4849 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
4850 else if (strcmp (name
, ".msym") == 0)
4851 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
4852 * (elf_hash_table (info
)->dynsymcount
4853 + bfd_count_sections (output_bfd
)));
4854 else if (strncmp (name
, ".init", 5) != 0)
4856 /* It's not one of our sections, so don't allocate space. */
4862 _bfd_strip_section_from_output (info
, s
);
4866 /* Allocate memory for the section contents. */
4867 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4868 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
4870 bfd_set_error (bfd_error_no_memory
);
4875 if (elf_hash_table (info
)->dynamic_sections_created
)
4877 /* Add some entries to the .dynamic section. We fill in the
4878 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
4879 must add the entries now so that we get the correct size for
4880 the .dynamic section. The DT_DEBUG entry is filled in by the
4881 dynamic linker and used by the debugger. */
4884 /* SGI object has the equivalence of DT_DEBUG in the
4885 DT_MIPS_RLD_MAP entry. */
4886 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
4888 if (!SGI_COMPAT (output_bfd
))
4890 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
4896 /* Shared libraries on traditional mips have DT_DEBUG. */
4897 if (!SGI_COMPAT (output_bfd
))
4899 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
4904 if (reltext
&& SGI_COMPAT (output_bfd
))
4905 info
->flags
|= DF_TEXTREL
;
4907 if ((info
->flags
& DF_TEXTREL
) != 0)
4909 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
4913 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
4916 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
4918 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
4921 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
4924 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
4928 if (SGI_COMPAT (output_bfd
))
4930 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICTNO
, 0))
4934 if (SGI_COMPAT (output_bfd
))
4936 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLISTNO
, 0))
4940 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
4942 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICT
, 0))
4945 s
= bfd_get_section_by_name (dynobj
, ".liblist");
4946 BFD_ASSERT (s
!= NULL
);
4948 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLIST
, 0))
4952 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
4955 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
4959 /* Time stamps in executable files are a bad idea. */
4960 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
4965 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
4970 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
4974 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
4977 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
4980 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
4983 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
4986 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
4989 if (IRIX_COMPAT (dynobj
) == ict_irix5
4990 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
4993 if (IRIX_COMPAT (dynobj
) == ict_irix6
4994 && (bfd_get_section_by_name
4995 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
4996 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
4999 if (bfd_get_section_by_name (dynobj
, ".msym")
5000 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_MSYM
, 0))
5007 /* Relocate a MIPS ELF section. */
5010 _bfd_mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
5011 contents
, relocs
, local_syms
, local_sections
)
5013 struct bfd_link_info
*info
;
5015 asection
*input_section
;
5017 Elf_Internal_Rela
*relocs
;
5018 Elf_Internal_Sym
*local_syms
;
5019 asection
**local_sections
;
5021 Elf_Internal_Rela
*rel
;
5022 const Elf_Internal_Rela
*relend
;
5024 bfd_boolean use_saved_addend_p
= FALSE
;
5025 struct elf_backend_data
*bed
;
5027 bed
= get_elf_backend_data (output_bfd
);
5028 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
5029 for (rel
= relocs
; rel
< relend
; ++rel
)
5033 reloc_howto_type
*howto
;
5034 bfd_boolean require_jalx
;
5035 /* TRUE if the relocation is a RELA relocation, rather than a
5037 bfd_boolean rela_relocation_p
= TRUE
;
5038 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5039 const char * msg
= (const char *) NULL
;
5041 /* Find the relocation howto for this relocation. */
5042 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
5044 /* Some 32-bit code uses R_MIPS_64. In particular, people use
5045 64-bit code, but make sure all their addresses are in the
5046 lowermost or uppermost 32-bit section of the 64-bit address
5047 space. Thus, when they use an R_MIPS_64 they mean what is
5048 usually meant by R_MIPS_32, with the exception that the
5049 stored value is sign-extended to 64 bits. */
5050 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
5052 /* On big-endian systems, we need to lie about the position
5054 if (bfd_big_endian (input_bfd
))
5058 /* NewABI defaults to RELA relocations. */
5059 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
5060 NEWABI_P (input_bfd
)
5061 && (MIPS_RELOC_RELA_P
5062 (input_bfd
, input_section
,
5065 if (!use_saved_addend_p
)
5067 Elf_Internal_Shdr
*rel_hdr
;
5069 /* If these relocations were originally of the REL variety,
5070 we must pull the addend out of the field that will be
5071 relocated. Otherwise, we simply use the contents of the
5072 RELA relocation. To determine which flavor or relocation
5073 this is, we depend on the fact that the INPUT_SECTION's
5074 REL_HDR is read before its REL_HDR2. */
5075 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
5076 if ((size_t) (rel
- relocs
)
5077 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
5078 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
5079 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
5081 /* Note that this is a REL relocation. */
5082 rela_relocation_p
= FALSE
;
5084 /* Get the addend, which is stored in the input file. */
5085 addend
= mips_elf_obtain_contents (howto
, rel
, input_bfd
,
5087 addend
&= howto
->src_mask
;
5088 addend
<<= howto
->rightshift
;
5090 /* For some kinds of relocations, the ADDEND is a
5091 combination of the addend stored in two different
5093 if (r_type
== R_MIPS_HI16
5094 || r_type
== R_MIPS_GNU_REL_HI16
5095 || (r_type
== R_MIPS_GOT16
5096 && mips_elf_local_relocation_p (input_bfd
, rel
,
5097 local_sections
, FALSE
)))
5100 const Elf_Internal_Rela
*lo16_relocation
;
5101 reloc_howto_type
*lo16_howto
;
5104 /* The combined value is the sum of the HI16 addend,
5105 left-shifted by sixteen bits, and the LO16
5106 addend, sign extended. (Usually, the code does
5107 a `lui' of the HI16 value, and then an `addiu' of
5110 Scan ahead to find a matching LO16 relocation. */
5111 if (r_type
== R_MIPS_GNU_REL_HI16
)
5112 lo
= R_MIPS_GNU_REL_LO16
;
5115 lo16_relocation
= mips_elf_next_relocation (input_bfd
, lo
,
5117 if (lo16_relocation
== NULL
)
5120 /* Obtain the addend kept there. */
5121 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, lo
, FALSE
);
5122 l
= mips_elf_obtain_contents (lo16_howto
, lo16_relocation
,
5123 input_bfd
, contents
);
5124 l
&= lo16_howto
->src_mask
;
5125 l
<<= lo16_howto
->rightshift
;
5126 l
= mips_elf_sign_extend (l
, 16);
5130 /* Compute the combined addend. */
5133 /* If PC-relative, subtract the difference between the
5134 address of the LO part of the reloc and the address of
5135 the HI part. The relocation is relative to the LO
5136 part, but mips_elf_calculate_relocation() doesn't
5137 know its address or the difference from the HI part, so
5138 we subtract that difference here. See also the
5139 comment in mips_elf_calculate_relocation(). */
5140 if (r_type
== R_MIPS_GNU_REL_HI16
)
5141 addend
-= (lo16_relocation
->r_offset
- rel
->r_offset
);
5143 else if (r_type
== R_MIPS16_GPREL
)
5145 /* The addend is scrambled in the object file. See
5146 mips_elf_perform_relocation for details on the
5148 addend
= (((addend
& 0x1f0000) >> 5)
5149 | ((addend
& 0x7e00000) >> 16)
5154 addend
= rel
->r_addend
;
5157 if (info
->relocateable
)
5159 Elf_Internal_Sym
*sym
;
5160 unsigned long r_symndx
;
5162 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
5163 && bfd_big_endian (input_bfd
))
5166 /* Since we're just relocating, all we need to do is copy
5167 the relocations back out to the object file, unless
5168 they're against a section symbol, in which case we need
5169 to adjust by the section offset, or unless they're GP
5170 relative in which case we need to adjust by the amount
5171 that we're adjusting GP in this relocateable object. */
5173 if (! mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
5175 /* There's nothing to do for non-local relocations. */
5178 if (r_type
== R_MIPS16_GPREL
5179 || r_type
== R_MIPS_GPREL16
5180 || r_type
== R_MIPS_GPREL32
5181 || r_type
== R_MIPS_LITERAL
)
5182 addend
-= (_bfd_get_gp_value (output_bfd
)
5183 - _bfd_get_gp_value (input_bfd
));
5185 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
5186 sym
= local_syms
+ r_symndx
;
5187 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
5188 /* Adjust the addend appropriately. */
5189 addend
+= local_sections
[r_symndx
]->output_offset
;
5191 if (howto
->partial_inplace
)
5193 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
5194 then we only want to write out the high-order 16 bits.
5195 The subsequent R_MIPS_LO16 will handle the low-order bits.
5197 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
5198 || r_type
== R_MIPS_GNU_REL_HI16
)
5199 addend
= mips_elf_high (addend
);
5200 else if (r_type
== R_MIPS_HIGHER
)
5201 addend
= mips_elf_higher (addend
);
5202 else if (r_type
== R_MIPS_HIGHEST
)
5203 addend
= mips_elf_highest (addend
);
5206 if (rela_relocation_p
)
5207 /* If this is a RELA relocation, just update the addend.
5208 We have to cast away constness for REL. */
5209 rel
->r_addend
= addend
;
5212 /* Otherwise, we have to write the value back out. Note
5213 that we use the source mask, rather than the
5214 destination mask because the place to which we are
5215 writing will be source of the addend in the final
5217 addend
>>= howto
->rightshift
;
5218 addend
&= howto
->src_mask
;
5220 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
5221 /* See the comment above about using R_MIPS_64 in the 32-bit
5222 ABI. Here, we need to update the addend. It would be
5223 possible to get away with just using the R_MIPS_32 reloc
5224 but for endianness. */
5230 if (addend
& ((bfd_vma
) 1 << 31))
5232 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
5239 /* If we don't know that we have a 64-bit type,
5240 do two separate stores. */
5241 if (bfd_big_endian (input_bfd
))
5243 /* Store the sign-bits (which are most significant)
5245 low_bits
= sign_bits
;
5251 high_bits
= sign_bits
;
5253 bfd_put_32 (input_bfd
, low_bits
,
5254 contents
+ rel
->r_offset
);
5255 bfd_put_32 (input_bfd
, high_bits
,
5256 contents
+ rel
->r_offset
+ 4);
5260 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
5261 input_bfd
, input_section
,
5266 /* Go on to the next relocation. */
5270 /* In the N32 and 64-bit ABIs there may be multiple consecutive
5271 relocations for the same offset. In that case we are
5272 supposed to treat the output of each relocation as the addend
5274 if (rel
+ 1 < relend
5275 && rel
->r_offset
== rel
[1].r_offset
5276 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
5277 use_saved_addend_p
= TRUE
;
5279 use_saved_addend_p
= FALSE
;
5281 addend
>>= howto
->rightshift
;
5283 /* Figure out what value we are supposed to relocate. */
5284 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
5285 input_section
, info
, rel
,
5286 addend
, howto
, local_syms
,
5287 local_sections
, &value
,
5288 &name
, &require_jalx
,
5289 use_saved_addend_p
))
5291 case bfd_reloc_continue
:
5292 /* There's nothing to do. */
5295 case bfd_reloc_undefined
:
5296 /* mips_elf_calculate_relocation already called the
5297 undefined_symbol callback. There's no real point in
5298 trying to perform the relocation at this point, so we
5299 just skip ahead to the next relocation. */
5302 case bfd_reloc_notsupported
:
5303 msg
= _("internal error: unsupported relocation error");
5304 info
->callbacks
->warning
5305 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
5308 case bfd_reloc_overflow
:
5309 if (use_saved_addend_p
)
5310 /* Ignore overflow until we reach the last relocation for
5311 a given location. */
5315 BFD_ASSERT (name
!= NULL
);
5316 if (! ((*info
->callbacks
->reloc_overflow
)
5317 (info
, name
, howto
->name
, (bfd_vma
) 0,
5318 input_bfd
, input_section
, rel
->r_offset
)))
5331 /* If we've got another relocation for the address, keep going
5332 until we reach the last one. */
5333 if (use_saved_addend_p
)
5339 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
5340 /* See the comment above about using R_MIPS_64 in the 32-bit
5341 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
5342 that calculated the right value. Now, however, we
5343 sign-extend the 32-bit result to 64-bits, and store it as a
5344 64-bit value. We are especially generous here in that we
5345 go to extreme lengths to support this usage on systems with
5346 only a 32-bit VMA. */
5352 if (value
& ((bfd_vma
) 1 << 31))
5354 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
5361 /* If we don't know that we have a 64-bit type,
5362 do two separate stores. */
5363 if (bfd_big_endian (input_bfd
))
5365 /* Undo what we did above. */
5367 /* Store the sign-bits (which are most significant)
5369 low_bits
= sign_bits
;
5375 high_bits
= sign_bits
;
5377 bfd_put_32 (input_bfd
, low_bits
,
5378 contents
+ rel
->r_offset
);
5379 bfd_put_32 (input_bfd
, high_bits
,
5380 contents
+ rel
->r_offset
+ 4);
5384 /* Actually perform the relocation. */
5385 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
5386 input_bfd
, input_section
,
5387 contents
, require_jalx
))
5394 /* If NAME is one of the special IRIX6 symbols defined by the linker,
5395 adjust it appropriately now. */
5398 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
5399 bfd
*abfd ATTRIBUTE_UNUSED
;
5401 Elf_Internal_Sym
*sym
;
5403 /* The linker script takes care of providing names and values for
5404 these, but we must place them into the right sections. */
5405 static const char* const text_section_symbols
[] = {
5408 "__dso_displacement",
5410 "__program_header_table",
5414 static const char* const data_section_symbols
[] = {
5422 const char* const *p
;
5425 for (i
= 0; i
< 2; ++i
)
5426 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
5429 if (strcmp (*p
, name
) == 0)
5431 /* All of these symbols are given type STT_SECTION by the
5433 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5435 /* The IRIX linker puts these symbols in special sections. */
5437 sym
->st_shndx
= SHN_MIPS_TEXT
;
5439 sym
->st_shndx
= SHN_MIPS_DATA
;
5445 /* Finish up dynamic symbol handling. We set the contents of various
5446 dynamic sections here. */
5449 _bfd_mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5451 struct bfd_link_info
*info
;
5452 struct elf_link_hash_entry
*h
;
5453 Elf_Internal_Sym
*sym
;
5459 struct mips_got_info
*g
;
5461 struct mips_elf_link_hash_entry
*mh
;
5463 dynobj
= elf_hash_table (info
)->dynobj
;
5464 gval
= sym
->st_value
;
5465 mh
= (struct mips_elf_link_hash_entry
*) h
;
5467 if (h
->plt
.offset
!= (bfd_vma
) -1)
5470 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5472 /* This symbol has a stub. Set it up. */
5474 BFD_ASSERT (h
->dynindx
!= -1);
5476 s
= bfd_get_section_by_name (dynobj
,
5477 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
5478 BFD_ASSERT (s
!= NULL
);
5480 /* FIXME: Can h->dynindex be more than 64K? */
5481 if (h
->dynindx
& 0xffff0000)
5484 /* Fill the stub. */
5485 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
);
5486 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ 4);
5487 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ 8);
5488 bfd_put_32 (output_bfd
, STUB_LI16 (output_bfd
) + h
->dynindx
, stub
+ 12);
5490 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
5491 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5493 /* Mark the symbol as undefined. plt.offset != -1 occurs
5494 only for the referenced symbol. */
5495 sym
->st_shndx
= SHN_UNDEF
;
5497 /* The run-time linker uses the st_value field of the symbol
5498 to reset the global offset table entry for this external
5499 to its stub address when unlinking a shared object. */
5500 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
5501 sym
->st_value
= gval
;
5504 BFD_ASSERT (h
->dynindx
!= -1
5505 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
5507 sgot
= mips_elf_got_section (dynobj
);
5508 BFD_ASSERT (sgot
!= NULL
);
5509 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5510 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5511 BFD_ASSERT (g
!= NULL
);
5513 /* Run through the global symbol table, creating GOT entries for all
5514 the symbols that need them. */
5515 if (g
->global_gotsym
!= NULL
5516 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
5522 value
= sym
->st_value
;
5525 /* For an entity defined in a shared object, this will be
5526 NULL. (For functions in shared objects for
5527 which we have created stubs, ST_VALUE will be non-NULL.
5528 That's because such the functions are now no longer defined
5529 in a shared object.) */
5531 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
5534 value
= h
->root
.u
.def
.value
;
5536 offset
= mips_elf_global_got_index (dynobj
, h
);
5537 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
5540 /* Create a .msym entry, if appropriate. */
5541 smsym
= bfd_get_section_by_name (dynobj
, ".msym");
5544 Elf32_Internal_Msym msym
;
5546 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
5547 /* It is undocumented what the `1' indicates, but IRIX6 uses
5549 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
5550 bfd_mips_elf_swap_msym_out
5552 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
5555 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5556 name
= h
->root
.root
.string
;
5557 if (strcmp (name
, "_DYNAMIC") == 0
5558 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5559 sym
->st_shndx
= SHN_ABS
;
5560 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
5561 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
5563 sym
->st_shndx
= SHN_ABS
;
5564 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5567 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
5569 sym
->st_shndx
= SHN_ABS
;
5570 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5571 sym
->st_value
= elf_gp (output_bfd
);
5573 else if (SGI_COMPAT (output_bfd
))
5575 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
5576 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
5578 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5579 sym
->st_other
= STO_PROTECTED
;
5581 sym
->st_shndx
= SHN_MIPS_DATA
;
5583 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
5585 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5586 sym
->st_other
= STO_PROTECTED
;
5587 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
5588 sym
->st_shndx
= SHN_ABS
;
5590 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
5592 if (h
->type
== STT_FUNC
)
5593 sym
->st_shndx
= SHN_MIPS_TEXT
;
5594 else if (h
->type
== STT_OBJECT
)
5595 sym
->st_shndx
= SHN_MIPS_DATA
;
5599 /* Handle the IRIX6-specific symbols. */
5600 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
5601 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
5605 if (! mips_elf_hash_table (info
)->use_rld_obj_head
5606 && (strcmp (name
, "__rld_map") == 0
5607 || strcmp (name
, "__RLD_MAP") == 0))
5609 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
5610 BFD_ASSERT (s
!= NULL
);
5611 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
5612 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
5613 if (mips_elf_hash_table (info
)->rld_value
== 0)
5614 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5616 else if (mips_elf_hash_table (info
)->use_rld_obj_head
5617 && strcmp (name
, "__rld_obj_head") == 0)
5619 /* IRIX6 does not use a .rld_map section. */
5620 if (IRIX_COMPAT (output_bfd
) == ict_irix5
5621 || IRIX_COMPAT (output_bfd
) == ict_none
)
5622 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
5624 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5628 /* If this is a mips16 symbol, force the value to be even. */
5629 if (sym
->st_other
== STO_MIPS16
5630 && (sym
->st_value
& 1) != 0)
5636 /* Finish up the dynamic sections. */
5639 _bfd_mips_elf_finish_dynamic_sections (output_bfd
, info
)
5641 struct bfd_link_info
*info
;
5646 struct mips_got_info
*g
;
5648 dynobj
= elf_hash_table (info
)->dynobj
;
5650 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5652 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5657 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5658 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5659 BFD_ASSERT (g
!= NULL
);
5662 if (elf_hash_table (info
)->dynamic_sections_created
)
5666 BFD_ASSERT (sdyn
!= NULL
);
5667 BFD_ASSERT (g
!= NULL
);
5669 for (b
= sdyn
->contents
;
5670 b
< sdyn
->contents
+ sdyn
->_raw_size
;
5671 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
5673 Elf_Internal_Dyn dyn
;
5677 bfd_boolean swap_out_p
;
5679 /* Read in the current dynamic entry. */
5680 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
5682 /* Assume that we're going to modify it and write it out. */
5688 s
= (bfd_get_section_by_name (dynobj
, ".rel.dyn"));
5689 BFD_ASSERT (s
!= NULL
);
5690 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
5694 /* Rewrite DT_STRSZ. */
5696 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
5702 case DT_MIPS_CONFLICT
:
5705 case DT_MIPS_LIBLIST
:
5708 s
= bfd_get_section_by_name (output_bfd
, name
);
5709 BFD_ASSERT (s
!= NULL
);
5710 dyn
.d_un
.d_ptr
= s
->vma
;
5713 case DT_MIPS_RLD_VERSION
:
5714 dyn
.d_un
.d_val
= 1; /* XXX */
5718 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5721 case DT_MIPS_CONFLICTNO
:
5723 elemsize
= sizeof (Elf32_Conflict
);
5726 case DT_MIPS_LIBLISTNO
:
5728 elemsize
= sizeof (Elf32_Lib
);
5730 s
= bfd_get_section_by_name (output_bfd
, name
);
5733 if (s
->_cooked_size
!= 0)
5734 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5736 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5742 case DT_MIPS_TIME_STAMP
:
5743 time ((time_t *) &dyn
.d_un
.d_val
);
5746 case DT_MIPS_ICHECKSUM
:
5751 case DT_MIPS_IVERSION
:
5756 case DT_MIPS_BASE_ADDRESS
:
5757 s
= output_bfd
->sections
;
5758 BFD_ASSERT (s
!= NULL
);
5759 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
5762 case DT_MIPS_LOCAL_GOTNO
:
5763 dyn
.d_un
.d_val
= g
->local_gotno
;
5766 case DT_MIPS_UNREFEXTNO
:
5767 /* The index into the dynamic symbol table which is the
5768 entry of the first external symbol that is not
5769 referenced within the same object. */
5770 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
5773 case DT_MIPS_GOTSYM
:
5774 if (g
->global_gotsym
)
5776 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
5779 /* In case if we don't have global got symbols we default
5780 to setting DT_MIPS_GOTSYM to the same value as
5781 DT_MIPS_SYMTABNO, so we just fall through. */
5783 case DT_MIPS_SYMTABNO
:
5785 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
5786 s
= bfd_get_section_by_name (output_bfd
, name
);
5787 BFD_ASSERT (s
!= NULL
);
5789 if (s
->_cooked_size
!= 0)
5790 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5792 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5795 case DT_MIPS_HIPAGENO
:
5796 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
5799 case DT_MIPS_RLD_MAP
:
5800 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
5803 case DT_MIPS_OPTIONS
:
5804 s
= (bfd_get_section_by_name
5805 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
5806 dyn
.d_un
.d_ptr
= s
->vma
;
5810 s
= (bfd_get_section_by_name (output_bfd
, ".msym"));
5811 dyn
.d_un
.d_ptr
= s
->vma
;
5820 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
5825 /* The first entry of the global offset table will be filled at
5826 runtime. The second entry will be used by some runtime loaders.
5827 This isn't the case of IRIX rld. */
5828 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
5830 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5831 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
5832 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
5836 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
5837 = MIPS_ELF_GOT_SIZE (output_bfd
);
5842 Elf32_compact_rel cpt
;
5844 /* ??? The section symbols for the output sections were set up in
5845 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
5846 symbols. Should we do so? */
5848 smsym
= bfd_get_section_by_name (dynobj
, ".msym");
5851 Elf32_Internal_Msym msym
;
5853 msym
.ms_hash_value
= 0;
5854 msym
.ms_info
= ELF32_MS_INFO (0, 1);
5856 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
5858 long dynindx
= elf_section_data (s
)->dynindx
;
5860 bfd_mips_elf_swap_msym_out
5862 (((Elf32_External_Msym
*) smsym
->contents
)
5867 if (SGI_COMPAT (output_bfd
))
5869 /* Write .compact_rel section out. */
5870 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5874 cpt
.num
= s
->reloc_count
;
5876 cpt
.offset
= (s
->output_section
->filepos
5877 + sizeof (Elf32_External_compact_rel
));
5880 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
5881 ((Elf32_External_compact_rel
*)
5884 /* Clean up a dummy stub function entry in .text. */
5885 s
= bfd_get_section_by_name (dynobj
,
5886 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
5889 file_ptr dummy_offset
;
5891 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
5892 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
5893 memset (s
->contents
+ dummy_offset
, 0,
5894 MIPS_FUNCTION_STUB_SIZE
);
5899 /* We need to sort the entries of the dynamic relocation section. */
5901 if (!ABI_64_P (output_bfd
))
5905 reldyn
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5906 if (reldyn
!= NULL
&& reldyn
->reloc_count
> 2)
5908 reldyn_sorting_bfd
= output_bfd
;
5909 qsort ((Elf32_External_Rel
*) reldyn
->contents
+ 1,
5910 (size_t) reldyn
->reloc_count
- 1,
5911 sizeof (Elf32_External_Rel
), sort_dynamic_relocs
);
5915 /* Clean up a first relocation in .rel.dyn. */
5916 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5917 if (s
!= NULL
&& s
->_raw_size
> 0)
5918 memset (s
->contents
, 0, MIPS_ELF_REL_SIZE (dynobj
));
5924 /* The final processing done just before writing out a MIPS ELF object
5925 file. This gets the MIPS architecture right based on the machine
5926 number. This is used by both the 32-bit and the 64-bit ABI. */
5929 _bfd_mips_elf_final_write_processing (abfd
, linker
)
5931 bfd_boolean linker ATTRIBUTE_UNUSED
;
5935 Elf_Internal_Shdr
**hdrpp
;
5939 switch (bfd_get_mach (abfd
))
5942 case bfd_mach_mips3000
:
5943 val
= E_MIPS_ARCH_1
;
5946 case bfd_mach_mips3900
:
5947 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
5950 case bfd_mach_mips6000
:
5951 val
= E_MIPS_ARCH_2
;
5954 case bfd_mach_mips4000
:
5955 case bfd_mach_mips4300
:
5956 case bfd_mach_mips4400
:
5957 case bfd_mach_mips4600
:
5958 val
= E_MIPS_ARCH_3
;
5961 case bfd_mach_mips4010
:
5962 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
5965 case bfd_mach_mips4100
:
5966 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
5969 case bfd_mach_mips4111
:
5970 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
5973 case bfd_mach_mips4120
:
5974 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
5977 case bfd_mach_mips4650
:
5978 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
5981 case bfd_mach_mips5400
:
5982 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
5985 case bfd_mach_mips5500
:
5986 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
5989 case bfd_mach_mips5000
:
5990 case bfd_mach_mips8000
:
5991 case bfd_mach_mips10000
:
5992 case bfd_mach_mips12000
:
5993 val
= E_MIPS_ARCH_4
;
5996 case bfd_mach_mips5
:
5997 val
= E_MIPS_ARCH_5
;
6000 case bfd_mach_mips_sb1
:
6001 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
6004 case bfd_mach_mipsisa32
:
6005 val
= E_MIPS_ARCH_32
;
6008 case bfd_mach_mipsisa64
:
6009 val
= E_MIPS_ARCH_64
;
6012 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
6013 elf_elfheader (abfd
)->e_flags
|= val
;
6015 /* Set the sh_info field for .gptab sections and other appropriate
6016 info for each special section. */
6017 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
6018 i
< elf_numsections (abfd
);
6021 switch ((*hdrpp
)->sh_type
)
6024 case SHT_MIPS_LIBLIST
:
6025 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
6027 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6030 case SHT_MIPS_GPTAB
:
6031 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
6032 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
6033 BFD_ASSERT (name
!= NULL
6034 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
6035 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
6036 BFD_ASSERT (sec
!= NULL
);
6037 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
6040 case SHT_MIPS_CONTENT
:
6041 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
6042 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
6043 BFD_ASSERT (name
!= NULL
6044 && strncmp (name
, ".MIPS.content",
6045 sizeof ".MIPS.content" - 1) == 0);
6046 sec
= bfd_get_section_by_name (abfd
,
6047 name
+ sizeof ".MIPS.content" - 1);
6048 BFD_ASSERT (sec
!= NULL
);
6049 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6052 case SHT_MIPS_SYMBOL_LIB
:
6053 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
6055 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6056 sec
= bfd_get_section_by_name (abfd
, ".liblist");
6058 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
6061 case SHT_MIPS_EVENTS
:
6062 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
6063 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
6064 BFD_ASSERT (name
!= NULL
);
6065 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
6066 sec
= bfd_get_section_by_name (abfd
,
6067 name
+ sizeof ".MIPS.events" - 1);
6070 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
6071 sizeof ".MIPS.post_rel" - 1) == 0);
6072 sec
= bfd_get_section_by_name (abfd
,
6074 + sizeof ".MIPS.post_rel" - 1));
6076 BFD_ASSERT (sec
!= NULL
);
6077 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6084 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
6088 _bfd_mips_elf_additional_program_headers (abfd
)
6094 /* See if we need a PT_MIPS_REGINFO segment. */
6095 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6096 if (s
&& (s
->flags
& SEC_LOAD
))
6099 /* See if we need a PT_MIPS_OPTIONS segment. */
6100 if (IRIX_COMPAT (abfd
) == ict_irix6
6101 && bfd_get_section_by_name (abfd
,
6102 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
6105 /* See if we need a PT_MIPS_RTPROC segment. */
6106 if (IRIX_COMPAT (abfd
) == ict_irix5
6107 && bfd_get_section_by_name (abfd
, ".dynamic")
6108 && bfd_get_section_by_name (abfd
, ".mdebug"))
6114 /* Modify the segment map for an IRIX5 executable. */
6117 _bfd_mips_elf_modify_segment_map (abfd
)
6121 struct elf_segment_map
*m
, **pm
;
6124 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
6126 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6127 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
6129 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
6130 if (m
->p_type
== PT_MIPS_REGINFO
)
6135 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6139 m
->p_type
= PT_MIPS_REGINFO
;
6143 /* We want to put it after the PHDR and INTERP segments. */
6144 pm
= &elf_tdata (abfd
)->segment_map
;
6146 && ((*pm
)->p_type
== PT_PHDR
6147 || (*pm
)->p_type
== PT_INTERP
))
6155 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
6156 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
6157 PT_OPTIONS segment immediately following the program header
6160 /* On non-IRIX6 new abi, we'll have already created a segment
6161 for this section, so don't create another. I'm not sure this
6162 is not also the case for IRIX 6, but I can't test it right
6164 && IRIX_COMPAT (abfd
) == ict_irix6
)
6166 for (s
= abfd
->sections
; s
; s
= s
->next
)
6167 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
6172 struct elf_segment_map
*options_segment
;
6174 /* Usually, there's a program header table. But, sometimes
6175 there's not (like when running the `ld' testsuite). So,
6176 if there's no program header table, we just put the
6177 options segment at the end. */
6178 for (pm
= &elf_tdata (abfd
)->segment_map
;
6181 if ((*pm
)->p_type
== PT_PHDR
)
6184 amt
= sizeof (struct elf_segment_map
);
6185 options_segment
= bfd_zalloc (abfd
, amt
);
6186 options_segment
->next
= *pm
;
6187 options_segment
->p_type
= PT_MIPS_OPTIONS
;
6188 options_segment
->p_flags
= PF_R
;
6189 options_segment
->p_flags_valid
= TRUE
;
6190 options_segment
->count
= 1;
6191 options_segment
->sections
[0] = s
;
6192 *pm
= options_segment
;
6197 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6199 /* If there are .dynamic and .mdebug sections, we make a room
6200 for the RTPROC header. FIXME: Rewrite without section names. */
6201 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
6202 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
6203 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
6205 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
6206 if (m
->p_type
== PT_MIPS_RTPROC
)
6211 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6215 m
->p_type
= PT_MIPS_RTPROC
;
6217 s
= bfd_get_section_by_name (abfd
, ".rtproc");
6222 m
->p_flags_valid
= 1;
6230 /* We want to put it after the DYNAMIC segment. */
6231 pm
= &elf_tdata (abfd
)->segment_map
;
6232 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
6242 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
6243 .dynstr, .dynsym, and .hash sections, and everything in
6245 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
6247 if ((*pm
)->p_type
== PT_DYNAMIC
)
6250 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
6252 /* For a normal mips executable the permissions for the PT_DYNAMIC
6253 segment are read, write and execute. We do that here since
6254 the code in elf.c sets only the read permission. This matters
6255 sometimes for the dynamic linker. */
6256 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
6258 m
->p_flags
= PF_R
| PF_W
| PF_X
;
6259 m
->p_flags_valid
= 1;
6263 && m
->count
== 1 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
6265 static const char *sec_names
[] =
6267 ".dynamic", ".dynstr", ".dynsym", ".hash"
6271 struct elf_segment_map
*n
;
6275 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
6277 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
6278 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
6284 sz
= s
->_cooked_size
;
6287 if (high
< s
->vma
+ sz
)
6293 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
6294 if ((s
->flags
& SEC_LOAD
) != 0
6297 + (s
->_cooked_size
!=
6298 0 ? s
->_cooked_size
: s
->_raw_size
)) <= high
))
6301 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
6302 n
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6309 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
6311 if ((s
->flags
& SEC_LOAD
) != 0
6314 + (s
->_cooked_size
!= 0 ?
6315 s
->_cooked_size
: s
->_raw_size
)) <= high
))
6329 /* Return the section that should be marked against GC for a given
6333 _bfd_mips_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
6335 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
6336 Elf_Internal_Rela
*rel
;
6337 struct elf_link_hash_entry
*h
;
6338 Elf_Internal_Sym
*sym
;
6340 /* ??? Do mips16 stub sections need to be handled special? */
6344 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
6346 case R_MIPS_GNU_VTINHERIT
:
6347 case R_MIPS_GNU_VTENTRY
:
6351 switch (h
->root
.type
)
6353 case bfd_link_hash_defined
:
6354 case bfd_link_hash_defweak
:
6355 return h
->root
.u
.def
.section
;
6357 case bfd_link_hash_common
:
6358 return h
->root
.u
.c
.p
->section
;
6366 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6371 /* Update the got entry reference counts for the section being removed. */
6374 _bfd_mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6375 bfd
*abfd ATTRIBUTE_UNUSED
;
6376 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
6377 asection
*sec ATTRIBUTE_UNUSED
;
6378 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
6381 Elf_Internal_Shdr
*symtab_hdr
;
6382 struct elf_link_hash_entry
**sym_hashes
;
6383 bfd_signed_vma
*local_got_refcounts
;
6384 const Elf_Internal_Rela
*rel
, *relend
;
6385 unsigned long r_symndx
;
6386 struct elf_link_hash_entry
*h
;
6388 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6389 sym_hashes
= elf_sym_hashes (abfd
);
6390 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6392 relend
= relocs
+ sec
->reloc_count
;
6393 for (rel
= relocs
; rel
< relend
; rel
++)
6394 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
6398 case R_MIPS_CALL_HI16
:
6399 case R_MIPS_CALL_LO16
:
6400 case R_MIPS_GOT_HI16
:
6401 case R_MIPS_GOT_LO16
:
6402 case R_MIPS_GOT_DISP
:
6403 case R_MIPS_GOT_PAGE
:
6404 case R_MIPS_GOT_OFST
:
6405 /* ??? It would seem that the existing MIPS code does no sort
6406 of reference counting or whatnot on its GOT and PLT entries,
6407 so it is not possible to garbage collect them at this time. */
6418 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
6419 hiding the old indirect symbol. Process additional relocation
6420 information. Also called for weakdefs, in which case we just let
6421 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
6424 _bfd_mips_elf_copy_indirect_symbol (bed
, dir
, ind
)
6425 struct elf_backend_data
*bed
;
6426 struct elf_link_hash_entry
*dir
, *ind
;
6428 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
6430 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
6432 if (ind
->root
.type
!= bfd_link_hash_indirect
)
6435 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
6436 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
6437 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
6438 if (indmips
->readonly_reloc
)
6439 dirmips
->readonly_reloc
= TRUE
;
6440 if (dirmips
->min_dyn_reloc_index
== 0
6441 || (indmips
->min_dyn_reloc_index
!= 0
6442 && indmips
->min_dyn_reloc_index
< dirmips
->min_dyn_reloc_index
))
6443 dirmips
->min_dyn_reloc_index
= indmips
->min_dyn_reloc_index
;
6444 if (indmips
->no_fn_stub
)
6445 dirmips
->no_fn_stub
= TRUE
;
6449 _bfd_mips_elf_hide_symbol (info
, entry
, force_local
)
6450 struct bfd_link_info
*info
;
6451 struct elf_link_hash_entry
*entry
;
6452 bfd_boolean force_local
;
6456 struct mips_got_info
*g
;
6457 struct mips_elf_link_hash_entry
*h
;
6459 h
= (struct mips_elf_link_hash_entry
*) entry
;
6460 if (h
->forced_local
)
6462 h
->forced_local
= TRUE
;
6464 dynobj
= elf_hash_table (info
)->dynobj
;
6465 got
= bfd_get_section_by_name (dynobj
, ".got");
6466 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
6468 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
6470 /* FIXME: Do we allocate too much GOT space here? */
6472 got
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
6478 _bfd_mips_elf_discard_info (abfd
, cookie
, info
)
6480 struct elf_reloc_cookie
*cookie
;
6481 struct bfd_link_info
*info
;
6484 bfd_boolean ret
= FALSE
;
6485 unsigned char *tdata
;
6488 o
= bfd_get_section_by_name (abfd
, ".pdr");
6491 if (o
->_raw_size
== 0)
6493 if (o
->_raw_size
% PDR_SIZE
!= 0)
6495 if (o
->output_section
!= NULL
6496 && bfd_is_abs_section (o
->output_section
))
6499 tdata
= bfd_zmalloc (o
->_raw_size
/ PDR_SIZE
);
6503 cookie
->rels
= (MNAME(abfd
,_bfd_elf
,link_read_relocs
)
6504 (abfd
, o
, (PTR
) NULL
,
6505 (Elf_Internal_Rela
*) NULL
,
6506 info
->keep_memory
));
6513 cookie
->rel
= cookie
->rels
;
6514 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
6516 for (i
= 0, skip
= 0; i
< o
->_raw_size
; i
++)
6518 if (MNAME(abfd
,_bfd_elf
,reloc_symbol_deleted_p
) (i
* PDR_SIZE
, cookie
))
6527 elf_section_data (o
)->tdata
= tdata
;
6528 o
->_cooked_size
= o
->_raw_size
- skip
* PDR_SIZE
;
6534 if (! info
->keep_memory
)
6535 free (cookie
->rels
);
6541 _bfd_mips_elf_ignore_discarded_relocs (sec
)
6544 if (strcmp (sec
->name
, ".pdr") == 0)
6550 _bfd_mips_elf_write_section (output_bfd
, sec
, contents
)
6555 bfd_byte
*to
, *from
, *end
;
6558 if (strcmp (sec
->name
, ".pdr") != 0)
6561 if (elf_section_data (sec
)->tdata
== NULL
)
6565 end
= contents
+ sec
->_raw_size
;
6566 for (from
= contents
, i
= 0;
6568 from
+= PDR_SIZE
, i
++)
6570 if (((unsigned char *) elf_section_data (sec
)->tdata
)[i
] == 1)
6573 memcpy (to
, from
, PDR_SIZE
);
6576 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
6577 (file_ptr
) sec
->output_offset
,
6582 /* MIPS ELF uses a special find_nearest_line routine in order the
6583 handle the ECOFF debugging information. */
6585 struct mips_elf_find_line
6587 struct ecoff_debug_info d
;
6588 struct ecoff_find_line i
;
6592 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
6593 functionname_ptr
, line_ptr
)
6598 const char **filename_ptr
;
6599 const char **functionname_ptr
;
6600 unsigned int *line_ptr
;
6604 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
6605 filename_ptr
, functionname_ptr
,
6609 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
6610 filename_ptr
, functionname_ptr
,
6612 (unsigned) (ABI_64_P (abfd
) ? 8 : 0),
6613 &elf_tdata (abfd
)->dwarf2_find_line_info
))
6616 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
6620 struct mips_elf_find_line
*fi
;
6621 const struct ecoff_debug_swap
* const swap
=
6622 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
6624 /* If we are called during a link, mips_elf_final_link may have
6625 cleared the SEC_HAS_CONTENTS field. We force it back on here
6626 if appropriate (which it normally will be). */
6627 origflags
= msec
->flags
;
6628 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
6629 msec
->flags
|= SEC_HAS_CONTENTS
;
6631 fi
= elf_tdata (abfd
)->find_line_info
;
6634 bfd_size_type external_fdr_size
;
6637 struct fdr
*fdr_ptr
;
6638 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
6640 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
6643 msec
->flags
= origflags
;
6647 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
6649 msec
->flags
= origflags
;
6653 /* Swap in the FDR information. */
6654 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
6655 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
6656 if (fi
->d
.fdr
== NULL
)
6658 msec
->flags
= origflags
;
6661 external_fdr_size
= swap
->external_fdr_size
;
6662 fdr_ptr
= fi
->d
.fdr
;
6663 fraw_src
= (char *) fi
->d
.external_fdr
;
6664 fraw_end
= (fraw_src
6665 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
6666 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
6667 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
6669 elf_tdata (abfd
)->find_line_info
= fi
;
6671 /* Note that we don't bother to ever free this information.
6672 find_nearest_line is either called all the time, as in
6673 objdump -l, so the information should be saved, or it is
6674 rarely called, as in ld error messages, so the memory
6675 wasted is unimportant. Still, it would probably be a
6676 good idea for free_cached_info to throw it away. */
6679 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
6680 &fi
->i
, filename_ptr
, functionname_ptr
,
6683 msec
->flags
= origflags
;
6687 msec
->flags
= origflags
;
6690 /* Fall back on the generic ELF find_nearest_line routine. */
6692 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
6693 filename_ptr
, functionname_ptr
,
6697 /* When are writing out the .options or .MIPS.options section,
6698 remember the bytes we are writing out, so that we can install the
6699 GP value in the section_processing routine. */
6702 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
6707 bfd_size_type count
;
6709 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
6713 if (elf_section_data (section
) == NULL
)
6715 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
6716 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
6717 if (elf_section_data (section
) == NULL
)
6720 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
6725 if (section
->_cooked_size
!= 0)
6726 size
= section
->_cooked_size
;
6728 size
= section
->_raw_size
;
6729 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
6732 elf_section_data (section
)->tdata
= (PTR
) c
;
6735 memcpy (c
+ offset
, location
, (size_t) count
);
6738 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
6742 /* This is almost identical to bfd_generic_get_... except that some
6743 MIPS relocations need to be handled specially. Sigh. */
6746 _bfd_elf_mips_get_relocated_section_contents (abfd
, link_info
, link_order
,
6747 data
, relocateable
, symbols
)
6749 struct bfd_link_info
*link_info
;
6750 struct bfd_link_order
*link_order
;
6752 bfd_boolean relocateable
;
6755 /* Get enough memory to hold the stuff */
6756 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
6757 asection
*input_section
= link_order
->u
.indirect
.section
;
6759 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
6760 arelent
**reloc_vector
= NULL
;
6766 reloc_vector
= (arelent
**) bfd_malloc ((bfd_size_type
) reloc_size
);
6767 if (reloc_vector
== NULL
&& reloc_size
!= 0)
6770 /* read in the section */
6771 if (!bfd_get_section_contents (input_bfd
,
6775 input_section
->_raw_size
))
6778 /* We're not relaxing the section, so just copy the size info */
6779 input_section
->_cooked_size
= input_section
->_raw_size
;
6780 input_section
->reloc_done
= TRUE
;
6782 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
6786 if (reloc_count
< 0)
6789 if (reloc_count
> 0)
6794 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
6797 struct bfd_hash_entry
*h
;
6798 struct bfd_link_hash_entry
*lh
;
6799 /* Skip all this stuff if we aren't mixing formats. */
6800 if (abfd
&& input_bfd
6801 && abfd
->xvec
== input_bfd
->xvec
)
6805 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
6806 lh
= (struct bfd_link_hash_entry
*) h
;
6813 case bfd_link_hash_undefined
:
6814 case bfd_link_hash_undefweak
:
6815 case bfd_link_hash_common
:
6818 case bfd_link_hash_defined
:
6819 case bfd_link_hash_defweak
:
6821 gp
= lh
->u
.def
.value
;
6823 case bfd_link_hash_indirect
:
6824 case bfd_link_hash_warning
:
6826 /* @@FIXME ignoring warning for now */
6828 case bfd_link_hash_new
:
6837 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
6840 char *error_message
= (char *) NULL
;
6841 bfd_reloc_status_type r
;
6843 /* Specific to MIPS: Deal with relocation types that require
6844 knowing the gp of the output bfd. */
6845 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
6846 if (bfd_is_abs_section (sym
->section
) && abfd
)
6848 /* The special_function wouldn't get called anyway. */
6852 /* The gp isn't there; let the special function code
6853 fall over on its own. */
6855 else if ((*parent
)->howto
->special_function
6856 == _bfd_mips_elf32_gprel16_reloc
)
6858 /* bypass special_function call */
6859 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
6860 input_section
, relocateable
,
6862 goto skip_bfd_perform_relocation
;
6864 /* end mips specific stuff */
6866 r
= bfd_perform_relocation (input_bfd
,
6870 relocateable
? abfd
: (bfd
*) NULL
,
6872 skip_bfd_perform_relocation
:
6876 asection
*os
= input_section
->output_section
;
6878 /* A partial link, so keep the relocs */
6879 os
->orelocation
[os
->reloc_count
] = *parent
;
6883 if (r
!= bfd_reloc_ok
)
6887 case bfd_reloc_undefined
:
6888 if (!((*link_info
->callbacks
->undefined_symbol
)
6889 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6890 input_bfd
, input_section
, (*parent
)->address
,
6894 case bfd_reloc_dangerous
:
6895 BFD_ASSERT (error_message
!= (char *) NULL
);
6896 if (!((*link_info
->callbacks
->reloc_dangerous
)
6897 (link_info
, error_message
, input_bfd
, input_section
,
6898 (*parent
)->address
)))
6901 case bfd_reloc_overflow
:
6902 if (!((*link_info
->callbacks
->reloc_overflow
)
6903 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6904 (*parent
)->howto
->name
, (*parent
)->addend
,
6905 input_bfd
, input_section
, (*parent
)->address
)))
6908 case bfd_reloc_outofrange
:
6917 if (reloc_vector
!= NULL
)
6918 free (reloc_vector
);
6922 if (reloc_vector
!= NULL
)
6923 free (reloc_vector
);
6927 /* Create a MIPS ELF linker hash table. */
6929 struct bfd_link_hash_table
*
6930 _bfd_mips_elf_link_hash_table_create (abfd
)
6933 struct mips_elf_link_hash_table
*ret
;
6934 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
6936 ret
= (struct mips_elf_link_hash_table
*) bfd_malloc (amt
);
6937 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
6940 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
6941 mips_elf_link_hash_newfunc
))
6948 /* We no longer use this. */
6949 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
6950 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
6952 ret
->procedure_count
= 0;
6953 ret
->compact_rel_size
= 0;
6954 ret
->use_rld_obj_head
= FALSE
;
6956 ret
->mips16_stubs_seen
= FALSE
;
6958 return &ret
->root
.root
;
6961 /* We need to use a special link routine to handle the .reginfo and
6962 the .mdebug sections. We need to merge all instances of these
6963 sections together, not write them all out sequentially. */
6966 _bfd_mips_elf_final_link (abfd
, info
)
6968 struct bfd_link_info
*info
;
6972 struct bfd_link_order
*p
;
6973 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
6974 asection
*rtproc_sec
;
6975 Elf32_RegInfo reginfo
;
6976 struct ecoff_debug_info debug
;
6977 const struct ecoff_debug_swap
*swap
6978 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
6979 HDRR
*symhdr
= &debug
.symbolic_header
;
6980 PTR mdebug_handle
= NULL
;
6986 static const char * const secname
[] =
6988 ".text", ".init", ".fini", ".data",
6989 ".rodata", ".sdata", ".sbss", ".bss"
6991 static const int sc
[] =
6993 scText
, scInit
, scFini
, scData
,
6994 scRData
, scSData
, scSBss
, scBss
6997 /* If all the things we linked together were PIC, but we're
6998 producing an executable (rather than a shared object), then the
6999 resulting file is CPIC (i.e., it calls PIC code.) */
7001 && !info
->relocateable
7002 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
7004 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
7005 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
7008 /* We'd carefully arranged the dynamic symbol indices, and then the
7009 generic size_dynamic_sections renumbered them out from under us.
7010 Rather than trying somehow to prevent the renumbering, just do
7012 if (elf_hash_table (info
)->dynamic_sections_created
)
7016 struct mips_got_info
*g
;
7018 /* When we resort, we must tell mips_elf_sort_hash_table what
7019 the lowest index it may use is. That's the number of section
7020 symbols we're going to add. The generic ELF linker only
7021 adds these symbols when building a shared object. Note that
7022 we count the sections after (possibly) removing the .options
7024 if (! mips_elf_sort_hash_table (info
, (info
->shared
7025 ? bfd_count_sections (abfd
) + 1
7029 /* Make sure we didn't grow the global .got region. */
7030 dynobj
= elf_hash_table (info
)->dynobj
;
7031 got
= bfd_get_section_by_name (dynobj
, ".got");
7032 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
7034 if (g
->global_gotsym
!= NULL
)
7035 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
7036 - g
->global_gotsym
->dynindx
)
7037 <= g
->global_gotno
);
7041 /* We want to set the GP value for ld -r. */
7042 /* On IRIX5, we omit the .options section. On IRIX6, however, we
7043 include it, even though we don't process it quite right. (Some
7044 entries are supposed to be merged.) Empirically, we seem to be
7045 better off including it then not. */
7046 if (IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
7047 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
7049 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
7051 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
7052 if (p
->type
== bfd_indirect_link_order
)
7053 p
->u
.indirect
.section
->flags
&= ~SEC_HAS_CONTENTS
;
7054 (*secpp
)->link_order_head
= NULL
;
7055 bfd_section_list_remove (abfd
, secpp
);
7056 --abfd
->section_count
;
7062 /* We include .MIPS.options, even though we don't process it quite right.
7063 (Some entries are supposed to be merged.) At IRIX6 empirically we seem
7064 to be better off including it than not. */
7065 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
7067 if (strcmp ((*secpp
)->name
, ".MIPS.options") == 0)
7069 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
7070 if (p
->type
== bfd_indirect_link_order
)
7071 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
7072 (*secpp
)->link_order_head
= NULL
;
7073 bfd_section_list_remove (abfd
, secpp
);
7074 --abfd
->section_count
;
7081 /* Get a value for the GP register. */
7082 if (elf_gp (abfd
) == 0)
7084 struct bfd_link_hash_entry
*h
;
7086 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
7087 if (h
!= (struct bfd_link_hash_entry
*) NULL
7088 && h
->type
== bfd_link_hash_defined
)
7089 elf_gp (abfd
) = (h
->u
.def
.value
7090 + h
->u
.def
.section
->output_section
->vma
7091 + h
->u
.def
.section
->output_offset
);
7092 else if (info
->relocateable
)
7094 bfd_vma lo
= MINUS_ONE
;
7096 /* Find the GP-relative section with the lowest offset. */
7097 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
7099 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
7102 /* And calculate GP relative to that. */
7103 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
7107 /* If the relocate_section function needs to do a reloc
7108 involving the GP value, it should make a reloc_dangerous
7109 callback to warn that GP is not defined. */
7113 /* Go through the sections and collect the .reginfo and .mdebug
7117 gptab_data_sec
= NULL
;
7118 gptab_bss_sec
= NULL
;
7119 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
7121 if (strcmp (o
->name
, ".reginfo") == 0)
7123 memset (®info
, 0, sizeof reginfo
);
7125 /* We have found the .reginfo section in the output file.
7126 Look through all the link_orders comprising it and merge
7127 the information together. */
7128 for (p
= o
->link_order_head
;
7129 p
!= (struct bfd_link_order
*) NULL
;
7132 asection
*input_section
;
7134 Elf32_External_RegInfo ext
;
7137 if (p
->type
!= bfd_indirect_link_order
)
7139 if (p
->type
== bfd_data_link_order
)
7144 input_section
= p
->u
.indirect
.section
;
7145 input_bfd
= input_section
->owner
;
7147 /* The linker emulation code has probably clobbered the
7148 size to be zero bytes. */
7149 if (input_section
->_raw_size
== 0)
7150 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
7152 if (! bfd_get_section_contents (input_bfd
, input_section
,
7155 (bfd_size_type
) sizeof ext
))
7158 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
7160 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
7161 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
7162 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
7163 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
7164 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
7166 /* ri_gp_value is set by the function
7167 mips_elf32_section_processing when the section is
7168 finally written out. */
7170 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7171 elf_link_input_bfd ignores this section. */
7172 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7175 /* Size has been set in _bfd_mips_elf_always_size_sections. */
7176 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
7178 /* Skip this section later on (I don't think this currently
7179 matters, but someday it might). */
7180 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7185 if (strcmp (o
->name
, ".mdebug") == 0)
7187 struct extsym_info einfo
;
7190 /* We have found the .mdebug section in the output file.
7191 Look through all the link_orders comprising it and merge
7192 the information together. */
7193 symhdr
->magic
= swap
->sym_magic
;
7194 /* FIXME: What should the version stamp be? */
7196 symhdr
->ilineMax
= 0;
7200 symhdr
->isymMax
= 0;
7201 symhdr
->ioptMax
= 0;
7202 symhdr
->iauxMax
= 0;
7204 symhdr
->issExtMax
= 0;
7207 symhdr
->iextMax
= 0;
7209 /* We accumulate the debugging information itself in the
7210 debug_info structure. */
7212 debug
.external_dnr
= NULL
;
7213 debug
.external_pdr
= NULL
;
7214 debug
.external_sym
= NULL
;
7215 debug
.external_opt
= NULL
;
7216 debug
.external_aux
= NULL
;
7218 debug
.ssext
= debug
.ssext_end
= NULL
;
7219 debug
.external_fdr
= NULL
;
7220 debug
.external_rfd
= NULL
;
7221 debug
.external_ext
= debug
.external_ext_end
= NULL
;
7223 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
7224 if (mdebug_handle
== (PTR
) NULL
)
7228 esym
.cobol_main
= 0;
7232 esym
.asym
.iss
= issNil
;
7233 esym
.asym
.st
= stLocal
;
7234 esym
.asym
.reserved
= 0;
7235 esym
.asym
.index
= indexNil
;
7237 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
7239 esym
.asym
.sc
= sc
[i
];
7240 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
7243 esym
.asym
.value
= s
->vma
;
7244 last
= s
->vma
+ s
->_raw_size
;
7247 esym
.asym
.value
= last
;
7248 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
7253 for (p
= o
->link_order_head
;
7254 p
!= (struct bfd_link_order
*) NULL
;
7257 asection
*input_section
;
7259 const struct ecoff_debug_swap
*input_swap
;
7260 struct ecoff_debug_info input_debug
;
7264 if (p
->type
!= bfd_indirect_link_order
)
7266 if (p
->type
== bfd_data_link_order
)
7271 input_section
= p
->u
.indirect
.section
;
7272 input_bfd
= input_section
->owner
;
7274 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
7275 || (get_elf_backend_data (input_bfd
)
7276 ->elf_backend_ecoff_debug_swap
) == NULL
)
7278 /* I don't know what a non MIPS ELF bfd would be
7279 doing with a .mdebug section, but I don't really
7280 want to deal with it. */
7284 input_swap
= (get_elf_backend_data (input_bfd
)
7285 ->elf_backend_ecoff_debug_swap
);
7287 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
7289 /* The ECOFF linking code expects that we have already
7290 read in the debugging information and set up an
7291 ecoff_debug_info structure, so we do that now. */
7292 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
7296 if (! (bfd_ecoff_debug_accumulate
7297 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
7298 &input_debug
, input_swap
, info
)))
7301 /* Loop through the external symbols. For each one with
7302 interesting information, try to find the symbol in
7303 the linker global hash table and save the information
7304 for the output external symbols. */
7305 eraw_src
= input_debug
.external_ext
;
7306 eraw_end
= (eraw_src
7307 + (input_debug
.symbolic_header
.iextMax
7308 * input_swap
->external_ext_size
));
7310 eraw_src
< eraw_end
;
7311 eraw_src
+= input_swap
->external_ext_size
)
7315 struct mips_elf_link_hash_entry
*h
;
7317 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
7318 if (ext
.asym
.sc
== scNil
7319 || ext
.asym
.sc
== scUndefined
7320 || ext
.asym
.sc
== scSUndefined
)
7323 name
= input_debug
.ssext
+ ext
.asym
.iss
;
7324 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
7325 name
, FALSE
, FALSE
, TRUE
);
7326 if (h
== NULL
|| h
->esym
.ifd
!= -2)
7332 < input_debug
.symbolic_header
.ifdMax
);
7333 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
7339 /* Free up the information we just read. */
7340 free (input_debug
.line
);
7341 free (input_debug
.external_dnr
);
7342 free (input_debug
.external_pdr
);
7343 free (input_debug
.external_sym
);
7344 free (input_debug
.external_opt
);
7345 free (input_debug
.external_aux
);
7346 free (input_debug
.ss
);
7347 free (input_debug
.ssext
);
7348 free (input_debug
.external_fdr
);
7349 free (input_debug
.external_rfd
);
7350 free (input_debug
.external_ext
);
7352 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7353 elf_link_input_bfd ignores this section. */
7354 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7357 if (SGI_COMPAT (abfd
) && info
->shared
)
7359 /* Create .rtproc section. */
7360 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
7361 if (rtproc_sec
== NULL
)
7363 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7364 | SEC_LINKER_CREATED
| SEC_READONLY
);
7366 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
7367 if (rtproc_sec
== NULL
7368 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
7369 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
7373 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
7379 /* Build the external symbol information. */
7382 einfo
.debug
= &debug
;
7384 einfo
.failed
= FALSE
;
7385 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7386 mips_elf_output_extsym
,
7391 /* Set the size of the .mdebug section. */
7392 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
7394 /* Skip this section later on (I don't think this currently
7395 matters, but someday it might). */
7396 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7401 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
7403 const char *subname
;
7406 Elf32_External_gptab
*ext_tab
;
7409 /* The .gptab.sdata and .gptab.sbss sections hold
7410 information describing how the small data area would
7411 change depending upon the -G switch. These sections
7412 not used in executables files. */
7413 if (! info
->relocateable
)
7415 for (p
= o
->link_order_head
;
7416 p
!= (struct bfd_link_order
*) NULL
;
7419 asection
*input_section
;
7421 if (p
->type
!= bfd_indirect_link_order
)
7423 if (p
->type
== bfd_data_link_order
)
7428 input_section
= p
->u
.indirect
.section
;
7430 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7431 elf_link_input_bfd ignores this section. */
7432 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7435 /* Skip this section later on (I don't think this
7436 currently matters, but someday it might). */
7437 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7439 /* Really remove the section. */
7440 for (secpp
= &abfd
->sections
;
7442 secpp
= &(*secpp
)->next
)
7444 bfd_section_list_remove (abfd
, secpp
);
7445 --abfd
->section_count
;
7450 /* There is one gptab for initialized data, and one for
7451 uninitialized data. */
7452 if (strcmp (o
->name
, ".gptab.sdata") == 0)
7454 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
7458 (*_bfd_error_handler
)
7459 (_("%s: illegal section name `%s'"),
7460 bfd_get_filename (abfd
), o
->name
);
7461 bfd_set_error (bfd_error_nonrepresentable_section
);
7465 /* The linker script always combines .gptab.data and
7466 .gptab.sdata into .gptab.sdata, and likewise for
7467 .gptab.bss and .gptab.sbss. It is possible that there is
7468 no .sdata or .sbss section in the output file, in which
7469 case we must change the name of the output section. */
7470 subname
= o
->name
+ sizeof ".gptab" - 1;
7471 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
7473 if (o
== gptab_data_sec
)
7474 o
->name
= ".gptab.data";
7476 o
->name
= ".gptab.bss";
7477 subname
= o
->name
+ sizeof ".gptab" - 1;
7478 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
7481 /* Set up the first entry. */
7483 amt
= c
* sizeof (Elf32_gptab
);
7484 tab
= (Elf32_gptab
*) bfd_malloc (amt
);
7487 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
7488 tab
[0].gt_header
.gt_unused
= 0;
7490 /* Combine the input sections. */
7491 for (p
= o
->link_order_head
;
7492 p
!= (struct bfd_link_order
*) NULL
;
7495 asection
*input_section
;
7499 bfd_size_type gpentry
;
7501 if (p
->type
!= bfd_indirect_link_order
)
7503 if (p
->type
== bfd_data_link_order
)
7508 input_section
= p
->u
.indirect
.section
;
7509 input_bfd
= input_section
->owner
;
7511 /* Combine the gptab entries for this input section one
7512 by one. We know that the input gptab entries are
7513 sorted by ascending -G value. */
7514 size
= bfd_section_size (input_bfd
, input_section
);
7516 for (gpentry
= sizeof (Elf32_External_gptab
);
7518 gpentry
+= sizeof (Elf32_External_gptab
))
7520 Elf32_External_gptab ext_gptab
;
7521 Elf32_gptab int_gptab
;
7527 if (! (bfd_get_section_contents
7528 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
7530 (bfd_size_type
) sizeof (Elf32_External_gptab
))))
7536 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
7538 val
= int_gptab
.gt_entry
.gt_g_value
;
7539 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
7542 for (look
= 1; look
< c
; look
++)
7544 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
7545 tab
[look
].gt_entry
.gt_bytes
+= add
;
7547 if (tab
[look
].gt_entry
.gt_g_value
== val
)
7553 Elf32_gptab
*new_tab
;
7556 /* We need a new table entry. */
7557 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
7558 new_tab
= (Elf32_gptab
*) bfd_realloc ((PTR
) tab
, amt
);
7559 if (new_tab
== NULL
)
7565 tab
[c
].gt_entry
.gt_g_value
= val
;
7566 tab
[c
].gt_entry
.gt_bytes
= add
;
7568 /* Merge in the size for the next smallest -G
7569 value, since that will be implied by this new
7572 for (look
= 1; look
< c
; look
++)
7574 if (tab
[look
].gt_entry
.gt_g_value
< val
7576 || (tab
[look
].gt_entry
.gt_g_value
7577 > tab
[max
].gt_entry
.gt_g_value
)))
7581 tab
[c
].gt_entry
.gt_bytes
+=
7582 tab
[max
].gt_entry
.gt_bytes
;
7587 last
= int_gptab
.gt_entry
.gt_bytes
;
7590 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7591 elf_link_input_bfd ignores this section. */
7592 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7595 /* The table must be sorted by -G value. */
7597 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
7599 /* Swap out the table. */
7600 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
7601 ext_tab
= (Elf32_External_gptab
*) bfd_alloc (abfd
, amt
);
7602 if (ext_tab
== NULL
)
7608 for (j
= 0; j
< c
; j
++)
7609 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
7612 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
7613 o
->contents
= (bfd_byte
*) ext_tab
;
7615 /* Skip this section later on (I don't think this currently
7616 matters, but someday it might). */
7617 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7621 /* Invoke the regular ELF backend linker to do all the work. */
7622 if (!MNAME(abfd
,bfd_elf
,bfd_final_link
) (abfd
, info
))
7625 /* Now write out the computed sections. */
7627 if (reginfo_sec
!= (asection
*) NULL
)
7629 Elf32_External_RegInfo ext
;
7631 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
7632 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
7634 (bfd_size_type
) sizeof ext
))
7638 if (mdebug_sec
!= (asection
*) NULL
)
7640 BFD_ASSERT (abfd
->output_has_begun
);
7641 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
7643 mdebug_sec
->filepos
))
7646 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
7649 if (gptab_data_sec
!= (asection
*) NULL
)
7651 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
7652 gptab_data_sec
->contents
,
7654 gptab_data_sec
->_raw_size
))
7658 if (gptab_bss_sec
!= (asection
*) NULL
)
7660 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
7661 gptab_bss_sec
->contents
,
7663 gptab_bss_sec
->_raw_size
))
7667 if (SGI_COMPAT (abfd
))
7669 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
7670 if (rtproc_sec
!= NULL
)
7672 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
7673 rtproc_sec
->contents
,
7675 rtproc_sec
->_raw_size
))
7683 /* Return TRUE if machine EXTENSION is an extension of machine BASE,
7684 meaning that it should be safe to link code for the two machines
7685 and set the output machine to EXTENSION. EXTENSION and BASE are
7686 both submasks of EF_MIPS_MACH. */
7689 _bfd_mips_elf_mach_extends_p (base
, extension
)
7690 flagword base
, extension
;
7692 /* The vr5500 ISA is an extension of the core vr5400 ISA, but doesn't
7693 include the multimedia stuff. It seems better to allow vr5400
7694 and vr5500 code to be merged anyway, since many libraries will
7695 just use the core ISA. Perhaps we could add some sort of ASE
7696 flag if this ever proves a problem. */
7698 || (base
== E_MIPS_MACH_5400
&& extension
== E_MIPS_MACH_5500
)
7699 || (base
== E_MIPS_MACH_4100
&& extension
== E_MIPS_MACH_4111
)
7700 || (base
== E_MIPS_MACH_4100
&& extension
== E_MIPS_MACH_4120
));
7703 /* Merge backend specific data from an object file to the output
7704 object file when linking. */
7707 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
7714 bfd_boolean null_input_bfd
= TRUE
;
7717 /* Check if we have the same endianess */
7718 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
7721 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
7722 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
7725 new_flags
= elf_elfheader (ibfd
)->e_flags
;
7726 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
7727 old_flags
= elf_elfheader (obfd
)->e_flags
;
7729 if (! elf_flags_init (obfd
))
7731 elf_flags_init (obfd
) = TRUE
;
7732 elf_elfheader (obfd
)->e_flags
= new_flags
;
7733 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
7734 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
7736 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
7737 && bfd_get_arch_info (obfd
)->the_default
)
7739 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
7740 bfd_get_mach (ibfd
)))
7747 /* Check flag compatibility. */
7749 new_flags
&= ~EF_MIPS_NOREORDER
;
7750 old_flags
&= ~EF_MIPS_NOREORDER
;
7752 if (new_flags
== old_flags
)
7755 /* Check to see if the input BFD actually contains any sections.
7756 If not, its flags may not have been initialised either, but it cannot
7757 actually cause any incompatibility. */
7758 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7760 /* Ignore synthetic sections and empty .text, .data and .bss sections
7761 which are automatically generated by gas. */
7762 if (strcmp (sec
->name
, ".reginfo")
7763 && strcmp (sec
->name
, ".mdebug")
7764 && ((!strcmp (sec
->name
, ".text")
7765 || !strcmp (sec
->name
, ".data")
7766 || !strcmp (sec
->name
, ".bss"))
7767 && sec
->_raw_size
!= 0))
7769 null_input_bfd
= FALSE
;
7778 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
7780 new_flags
&= ~EF_MIPS_PIC
;
7781 old_flags
&= ~EF_MIPS_PIC
;
7782 (*_bfd_error_handler
)
7783 (_("%s: linking PIC files with non-PIC files"),
7784 bfd_archive_filename (ibfd
));
7788 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
7790 new_flags
&= ~EF_MIPS_CPIC
;
7791 old_flags
&= ~EF_MIPS_CPIC
;
7792 (*_bfd_error_handler
)
7793 (_("%s: linking abicalls files with non-abicalls files"),
7794 bfd_archive_filename (ibfd
));
7798 /* Compare the ISA's. */
7799 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
7800 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
7802 int new_mach
= new_flags
& EF_MIPS_MACH
;
7803 int old_mach
= old_flags
& EF_MIPS_MACH
;
7804 int new_isa
= elf_mips_isa (new_flags
);
7805 int old_isa
= elf_mips_isa (old_flags
);
7807 /* If either has no machine specified, just compare the general isa's.
7808 Some combinations of machines are ok, if the isa's match. */
7809 if (new_mach
== old_mach
7810 || _bfd_mips_elf_mach_extends_p (new_mach
, old_mach
)
7811 || _bfd_mips_elf_mach_extends_p (old_mach
, new_mach
))
7813 /* Don't warn about mixing code using 32-bit ISAs, or mixing code
7814 using 64-bit ISAs. They will normally use the same data sizes
7815 and calling conventions. */
7817 if (( (new_isa
== 1 || new_isa
== 2 || new_isa
== 32)
7818 ^ (old_isa
== 1 || old_isa
== 2 || old_isa
== 32)) != 0)
7820 (*_bfd_error_handler
)
7821 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
7822 bfd_archive_filename (ibfd
), new_isa
, old_isa
);
7827 /* Do we need to update the mach field? */
7828 if (_bfd_mips_elf_mach_extends_p (old_mach
, new_mach
))
7830 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_MACH
;
7831 elf_elfheader (obfd
)->e_flags
|= new_mach
;
7834 /* Do we need to update the ISA field? */
7835 if (new_isa
> old_isa
)
7837 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_ARCH
;
7838 elf_elfheader (obfd
)->e_flags
7839 |= new_flags
& EF_MIPS_ARCH
;
7845 (*_bfd_error_handler
)
7846 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
7847 bfd_archive_filename (ibfd
),
7848 _bfd_elf_mips_mach (new_flags
),
7849 _bfd_elf_mips_mach (old_flags
));
7853 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
7854 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
7857 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
7858 does set EI_CLASS differently from any 32-bit ABI. */
7859 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
7860 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
7861 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
7863 /* Only error if both are set (to different values). */
7864 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
7865 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
7866 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
7868 (*_bfd_error_handler
)
7869 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
7870 bfd_archive_filename (ibfd
),
7871 elf_mips_abi_name (ibfd
),
7872 elf_mips_abi_name (obfd
));
7875 new_flags
&= ~EF_MIPS_ABI
;
7876 old_flags
&= ~EF_MIPS_ABI
;
7879 /* For now, allow arbitrary mixing of ASEs (retain the union). */
7880 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
7882 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
7884 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
7885 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
7888 /* Warn about any other mismatches */
7889 if (new_flags
!= old_flags
)
7891 (*_bfd_error_handler
)
7892 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
7893 bfd_archive_filename (ibfd
), (unsigned long) new_flags
,
7894 (unsigned long) old_flags
);
7900 bfd_set_error (bfd_error_bad_value
);
7907 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
7910 _bfd_mips_elf_set_private_flags (abfd
, flags
)
7914 BFD_ASSERT (!elf_flags_init (abfd
)
7915 || elf_elfheader (abfd
)->e_flags
== flags
);
7917 elf_elfheader (abfd
)->e_flags
= flags
;
7918 elf_flags_init (abfd
) = TRUE
;
7923 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
7927 FILE *file
= (FILE *) ptr
;
7929 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
7931 /* Print normal ELF private data. */
7932 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
7934 /* xgettext:c-format */
7935 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
7937 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
7938 fprintf (file
, _(" [abi=O32]"));
7939 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
7940 fprintf (file
, _(" [abi=O64]"));
7941 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
7942 fprintf (file
, _(" [abi=EABI32]"));
7943 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
7944 fprintf (file
, _(" [abi=EABI64]"));
7945 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
7946 fprintf (file
, _(" [abi unknown]"));
7947 else if (ABI_N32_P (abfd
))
7948 fprintf (file
, _(" [abi=N32]"));
7949 else if (ABI_64_P (abfd
))
7950 fprintf (file
, _(" [abi=64]"));
7952 fprintf (file
, _(" [no abi set]"));
7954 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
7955 fprintf (file
, _(" [mips1]"));
7956 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
7957 fprintf (file
, _(" [mips2]"));
7958 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
7959 fprintf (file
, _(" [mips3]"));
7960 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
7961 fprintf (file
, _(" [mips4]"));
7962 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
7963 fprintf (file
, _(" [mips5]"));
7964 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
7965 fprintf (file
, _(" [mips32]"));
7966 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
7967 fprintf (file
, _(" [mips64]"));
7969 fprintf (file
, _(" [unknown ISA]"));
7971 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
7972 fprintf (file
, _(" [mdmx]"));
7974 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
7975 fprintf (file
, _(" [mips16]"));
7977 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
7978 fprintf (file
, _(" [32bitmode]"));
7980 fprintf (file
, _(" [not 32bitmode]"));