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 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",
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 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 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 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 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 boolean mips_elf_create_procedure_table
283 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
284 struct ecoff_debug_info
*));
285 static 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 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
, 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 boolean mips_elf_sort_hash_table
322 PARAMS ((struct bfd_link_info
*, unsigned long));
323 static boolean mips_elf_sort_hash_table_f
324 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
325 static 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 boolean mips_elf_local_relocation_p
332 PARAMS ((bfd
*, const Elf_Internal_Rela
*, asection
**, boolean
));
333 static bfd_vma mips_elf_sign_extend
PARAMS ((bfd_vma
, int));
334 static 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 boolean mips_elf_create_compact_rel_section
339 PARAMS ((bfd
*, struct bfd_link_info
*));
340 static 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 **,
349 static bfd_vma mips_elf_obtain_contents
350 PARAMS ((reloc_howto_type
*, const Elf_Internal_Rela
*, bfd
*, bfd_byte
*));
351 static 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 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 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
*));
368 /* This will be used when we sort the dynamic relocation records. */
369 static bfd
*reldyn_sorting_bfd
;
371 /* Nonzero if ABFD is using the N32 ABI. */
373 #define ABI_N32_P(abfd) \
374 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
376 /* Nonzero if ABFD is using the N64 ABI. */
377 #define ABI_64_P(abfd) \
378 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
380 /* Nonzero if ABFD is using NewABI conventions. */
381 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
383 /* The IRIX compatibility level we are striving for. */
384 #define IRIX_COMPAT(abfd) \
385 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
387 /* Whether we are trying to be compatible with IRIX at all. */
388 #define SGI_COMPAT(abfd) \
389 (IRIX_COMPAT (abfd) != ict_none)
391 /* The name of the options section. */
392 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
393 (ABI_64_P (abfd) ? ".MIPS.options" : ".options")
395 /* The name of the stub section. */
396 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
397 (ABI_64_P (abfd) ? ".MIPS.stubs" : ".stub")
399 /* The size of an external REL relocation. */
400 #define MIPS_ELF_REL_SIZE(abfd) \
401 (get_elf_backend_data (abfd)->s->sizeof_rel)
403 /* The size of an external dynamic table entry. */
404 #define MIPS_ELF_DYN_SIZE(abfd) \
405 (get_elf_backend_data (abfd)->s->sizeof_dyn)
407 /* The size of a GOT entry. */
408 #define MIPS_ELF_GOT_SIZE(abfd) \
409 (get_elf_backend_data (abfd)->s->arch_size / 8)
411 /* The size of a symbol-table entry. */
412 #define MIPS_ELF_SYM_SIZE(abfd) \
413 (get_elf_backend_data (abfd)->s->sizeof_sym)
415 /* The default alignment for sections, as a power of two. */
416 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
417 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
419 /* Get word-sized data. */
420 #define MIPS_ELF_GET_WORD(abfd, ptr) \
421 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
423 /* Put out word-sized data. */
424 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
426 ? bfd_put_64 (abfd, val, ptr) \
427 : bfd_put_32 (abfd, val, ptr))
429 /* Add a dynamic symbol table-entry. */
431 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
432 (ABI_64_P (elf_hash_table (info)->dynobj) \
433 ? bfd_elf64_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val) \
434 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
436 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
437 (ABI_64_P (elf_hash_table (info)->dynobj) \
438 ? (boolean) (abort (), false) \
439 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
442 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
443 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
445 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
446 from smaller values. Start with zero, widen, *then* decrement. */
447 #define MINUS_ONE (((bfd_vma)0) - 1)
449 /* The number of local .got entries we reserve. */
450 #define MIPS_RESERVED_GOTNO (2)
452 /* Instructions which appear in a stub. For some reason the stub is
453 slightly different on an SGI system. */
454 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
455 #define STUB_LW(abfd) \
458 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
459 : 0x8f998010) /* lw t9,0x8010(gp) */ \
460 : 0x8f998010) /* lw t9,0x8000(gp) */
461 #define STUB_MOVE(abfd) \
462 (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */
463 #define STUB_JALR 0x0320f809 /* jal t9 */
464 #define STUB_LI16(abfd) \
465 (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */
466 #define MIPS_FUNCTION_STUB_SIZE (16)
468 /* The name of the dynamic interpreter. This is put in the .interp
471 #define ELF_DYNAMIC_INTERPRETER(abfd) \
472 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
473 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
474 : "/usr/lib/libc.so.1")
477 #define ELF_R_SYM(bfd, i) \
478 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
479 #define ELF_R_TYPE(bfd, i) \
480 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
481 #define ELF_R_INFO(bfd, s, t) \
482 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
484 #define ELF_R_SYM(bfd, i) \
486 #define ELF_R_TYPE(bfd, i) \
488 #define ELF_R_INFO(bfd, s, t) \
489 (ELF32_R_INFO (s, t))
492 /* The mips16 compiler uses a couple of special sections to handle
493 floating point arguments.
495 Section names that look like .mips16.fn.FNNAME contain stubs that
496 copy floating point arguments from the fp regs to the gp regs and
497 then jump to FNNAME. If any 32 bit function calls FNNAME, the
498 call should be redirected to the stub instead. If no 32 bit
499 function calls FNNAME, the stub should be discarded. We need to
500 consider any reference to the function, not just a call, because
501 if the address of the function is taken we will need the stub,
502 since the address might be passed to a 32 bit function.
504 Section names that look like .mips16.call.FNNAME contain stubs
505 that copy floating point arguments from the gp regs to the fp
506 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
507 then any 16 bit function that calls FNNAME should be redirected
508 to the stub instead. If FNNAME is not a 32 bit function, the
509 stub should be discarded.
511 .mips16.call.fp.FNNAME sections are similar, but contain stubs
512 which call FNNAME and then copy the return value from the fp regs
513 to the gp regs. These stubs store the return value in $18 while
514 calling FNNAME; any function which might call one of these stubs
515 must arrange to save $18 around the call. (This case is not
516 needed for 32 bit functions that call 16 bit functions, because
517 16 bit functions always return floating point values in both
520 Note that in all cases FNNAME might be defined statically.
521 Therefore, FNNAME is not used literally. Instead, the relocation
522 information will indicate which symbol the section is for.
524 We record any stubs that we find in the symbol table. */
526 #define FN_STUB ".mips16.fn."
527 #define CALL_STUB ".mips16.call."
528 #define CALL_FP_STUB ".mips16.call.fp."
530 /* Look up an entry in a MIPS ELF linker hash table. */
532 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
533 ((struct mips_elf_link_hash_entry *) \
534 elf_link_hash_lookup (&(table)->root, (string), (create), \
537 /* Traverse a MIPS ELF linker hash table. */
539 #define mips_elf_link_hash_traverse(table, func, info) \
540 (elf_link_hash_traverse \
542 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
545 /* Get the MIPS ELF linker hash table from a link_info structure. */
547 #define mips_elf_hash_table(p) \
548 ((struct mips_elf_link_hash_table *) ((p)->hash))
550 /* Create an entry in a MIPS ELF linker hash table. */
552 static struct bfd_hash_entry
*
553 mips_elf_link_hash_newfunc (entry
, table
, string
)
554 struct bfd_hash_entry
*entry
;
555 struct bfd_hash_table
*table
;
558 struct mips_elf_link_hash_entry
*ret
=
559 (struct mips_elf_link_hash_entry
*) entry
;
561 /* Allocate the structure if it has not already been allocated by a
563 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
564 ret
= ((struct mips_elf_link_hash_entry
*)
565 bfd_hash_allocate (table
,
566 sizeof (struct mips_elf_link_hash_entry
)));
567 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
568 return (struct bfd_hash_entry
*) ret
;
570 /* Call the allocation method of the superclass. */
571 ret
= ((struct mips_elf_link_hash_entry
*)
572 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
574 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
576 /* Set local fields. */
577 memset (&ret
->esym
, 0, sizeof (EXTR
));
578 /* We use -2 as a marker to indicate that the information has
579 not been set. -1 means there is no associated ifd. */
581 ret
->possibly_dynamic_relocs
= 0;
582 ret
->readonly_reloc
= false;
583 ret
->min_dyn_reloc_index
= 0;
584 ret
->no_fn_stub
= false;
586 ret
->need_fn_stub
= false;
587 ret
->call_stub
= NULL
;
588 ret
->call_fp_stub
= NULL
;
589 ret
->forced_local
= false;
592 return (struct bfd_hash_entry
*) ret
;
595 /* Read ECOFF debugging information from a .mdebug section into a
596 ecoff_debug_info structure. */
599 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
602 struct ecoff_debug_info
*debug
;
605 const struct ecoff_debug_swap
*swap
;
606 char *ext_hdr
= NULL
;
608 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
609 memset (debug
, 0, sizeof (*debug
));
611 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
612 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
615 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
616 swap
->external_hdr_size
))
619 symhdr
= &debug
->symbolic_header
;
620 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
622 /* The symbolic header contains absolute file offsets and sizes to
624 #define READ(ptr, offset, count, size, type) \
625 if (symhdr->count == 0) \
629 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
630 debug->ptr = (type) bfd_malloc (amt); \
631 if (debug->ptr == NULL) \
633 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
634 || bfd_bread (debug->ptr, amt, abfd) != amt) \
638 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
639 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
640 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
641 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
642 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
643 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
645 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
646 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
647 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
648 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
649 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
653 debug
->adjust
= NULL
;
660 if (debug
->line
!= NULL
)
662 if (debug
->external_dnr
!= NULL
)
663 free (debug
->external_dnr
);
664 if (debug
->external_pdr
!= NULL
)
665 free (debug
->external_pdr
);
666 if (debug
->external_sym
!= NULL
)
667 free (debug
->external_sym
);
668 if (debug
->external_opt
!= NULL
)
669 free (debug
->external_opt
);
670 if (debug
->external_aux
!= NULL
)
671 free (debug
->external_aux
);
672 if (debug
->ss
!= NULL
)
674 if (debug
->ssext
!= NULL
)
676 if (debug
->external_fdr
!= NULL
)
677 free (debug
->external_fdr
);
678 if (debug
->external_rfd
!= NULL
)
679 free (debug
->external_rfd
);
680 if (debug
->external_ext
!= NULL
)
681 free (debug
->external_ext
);
685 /* Swap RPDR (runtime procedure table entry) for output. */
688 ecoff_swap_rpdr_out (abfd
, in
, ex
)
693 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
694 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
695 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
696 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
697 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
698 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
700 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
701 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
703 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
705 H_PUT_S32 (abfd
, in
->exception_info
, ex
->p_exception_info
);
709 /* Create a runtime procedure table from the .mdebug section. */
712 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
715 struct bfd_link_info
*info
;
717 struct ecoff_debug_info
*debug
;
719 const struct ecoff_debug_swap
*swap
;
720 HDRR
*hdr
= &debug
->symbolic_header
;
722 struct rpdr_ext
*erp
;
724 struct pdr_ext
*epdr
;
725 struct sym_ext
*esym
;
730 unsigned long sindex
;
734 const char *no_name_func
= _("static procedure (no name)");
742 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
744 sindex
= strlen (no_name_func
) + 1;
748 size
= swap
->external_pdr_size
;
750 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
754 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
757 size
= sizeof (RPDR
);
758 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
762 size
= sizeof (char *);
763 sv
= (char **) bfd_malloc (size
* count
);
767 count
= hdr
->isymMax
;
768 size
= swap
->external_sym_size
;
769 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
773 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
777 ss
= (char *) bfd_malloc (count
);
780 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
784 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
786 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
787 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
789 rp
->regmask
= pdr
.regmask
;
790 rp
->regoffset
= pdr
.regoffset
;
791 rp
->fregmask
= pdr
.fregmask
;
792 rp
->fregoffset
= pdr
.fregoffset
;
793 rp
->frameoffset
= pdr
.frameoffset
;
794 rp
->framereg
= pdr
.framereg
;
795 rp
->pcreg
= pdr
.pcreg
;
797 sv
[i
] = ss
+ sym
.iss
;
798 sindex
+= strlen (sv
[i
]) + 1;
802 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
803 size
= BFD_ALIGN (size
, 16);
804 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
807 mips_elf_hash_table (info
)->procedure_count
= 0;
811 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
813 erp
= (struct rpdr_ext
*) rtproc
;
814 memset (erp
, 0, sizeof (struct rpdr_ext
));
816 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
817 strcpy (str
, no_name_func
);
818 str
+= strlen (no_name_func
) + 1;
819 for (i
= 0; i
< count
; i
++)
821 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
823 str
+= strlen (sv
[i
]) + 1;
825 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
827 /* Set the size and contents of .rtproc section. */
829 s
->contents
= (bfd_byte
*) rtproc
;
831 /* Skip this section later on (I don't think this currently
832 matters, but someday it might). */
833 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
862 /* Check the mips16 stubs for a particular symbol, and see if we can
866 mips_elf_check_mips16_stubs (h
, data
)
867 struct mips_elf_link_hash_entry
*h
;
868 PTR data ATTRIBUTE_UNUSED
;
870 if (h
->root
.root
.type
== bfd_link_hash_warning
)
871 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
873 if (h
->fn_stub
!= NULL
874 && ! h
->need_fn_stub
)
876 /* We don't need the fn_stub; the only references to this symbol
877 are 16 bit calls. Clobber the size to 0 to prevent it from
878 being included in the link. */
879 h
->fn_stub
->_raw_size
= 0;
880 h
->fn_stub
->_cooked_size
= 0;
881 h
->fn_stub
->flags
&= ~SEC_RELOC
;
882 h
->fn_stub
->reloc_count
= 0;
883 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
886 if (h
->call_stub
!= NULL
887 && h
->root
.other
== STO_MIPS16
)
889 /* We don't need the call_stub; this is a 16 bit function, so
890 calls from other 16 bit functions are OK. Clobber the size
891 to 0 to prevent it from being included in the link. */
892 h
->call_stub
->_raw_size
= 0;
893 h
->call_stub
->_cooked_size
= 0;
894 h
->call_stub
->flags
&= ~SEC_RELOC
;
895 h
->call_stub
->reloc_count
= 0;
896 h
->call_stub
->flags
|= SEC_EXCLUDE
;
899 if (h
->call_fp_stub
!= NULL
900 && h
->root
.other
== STO_MIPS16
)
902 /* We don't need the call_stub; this is a 16 bit function, so
903 calls from other 16 bit functions are OK. Clobber the size
904 to 0 to prevent it from being included in the link. */
905 h
->call_fp_stub
->_raw_size
= 0;
906 h
->call_fp_stub
->_cooked_size
= 0;
907 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
908 h
->call_fp_stub
->reloc_count
= 0;
909 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
915 bfd_reloc_status_type
916 _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
917 relocateable
, data
, gp
)
920 arelent
*reloc_entry
;
921 asection
*input_section
;
922 boolean relocateable
;
930 if (bfd_is_com_section (symbol
->section
))
933 relocation
= symbol
->value
;
935 relocation
+= symbol
->section
->output_section
->vma
;
936 relocation
+= symbol
->section
->output_offset
;
938 if (reloc_entry
->address
> input_section
->_cooked_size
)
939 return bfd_reloc_outofrange
;
941 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
943 /* Set val to the offset into the section or symbol. */
944 if (reloc_entry
->howto
->src_mask
== 0)
946 /* This case occurs with the 64-bit MIPS ELF ABI. */
947 val
= reloc_entry
->addend
;
951 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
956 /* Adjust val for the final section location and GP value. If we
957 are producing relocateable output, we don't want to do this for
958 an external symbol. */
960 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
961 val
+= relocation
- gp
;
963 insn
= (insn
& ~0xffff) | (val
& 0xffff);
964 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
967 reloc_entry
->address
+= input_section
->output_offset
;
969 else if ((long) val
>= 0x8000 || (long) val
< -0x8000)
970 return bfd_reloc_overflow
;
975 /* Swap an entry in a .gptab section. Note that these routines rely
976 on the equivalence of the two elements of the union. */
979 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
981 const Elf32_External_gptab
*ex
;
984 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
985 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
989 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
991 const Elf32_gptab
*in
;
992 Elf32_External_gptab
*ex
;
994 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
995 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
999 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1001 const Elf32_compact_rel
*in
;
1002 Elf32_External_compact_rel
*ex
;
1004 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1005 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1006 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1007 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1008 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1009 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1013 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1015 const Elf32_crinfo
*in
;
1016 Elf32_External_crinfo
*ex
;
1020 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1021 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1022 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1023 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1024 H_PUT_32 (abfd
, l
, ex
->info
);
1025 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1026 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1030 /* Swap in an MSYM entry. */
1033 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
1035 const Elf32_External_Msym
*ex
;
1036 Elf32_Internal_Msym
*in
;
1038 in
->ms_hash_value
= H_GET_32 (abfd
, ex
->ms_hash_value
);
1039 in
->ms_info
= H_GET_32 (abfd
, ex
->ms_info
);
1042 /* Swap out an MSYM entry. */
1045 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
1047 const Elf32_Internal_Msym
*in
;
1048 Elf32_External_Msym
*ex
;
1050 H_PUT_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
1051 H_PUT_32 (abfd
, in
->ms_info
, ex
->ms_info
);
1054 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1055 routines swap this structure in and out. They are used outside of
1056 BFD, so they are globally visible. */
1059 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1061 const Elf32_External_RegInfo
*ex
;
1064 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1065 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1066 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1067 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1068 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1069 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1073 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1075 const Elf32_RegInfo
*in
;
1076 Elf32_External_RegInfo
*ex
;
1078 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1079 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1080 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1081 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1082 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1083 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1086 /* In the 64 bit ABI, the .MIPS.options section holds register
1087 information in an Elf64_Reginfo structure. These routines swap
1088 them in and out. They are globally visible because they are used
1089 outside of BFD. These routines are here so that gas can call them
1090 without worrying about whether the 64 bit ABI has been included. */
1093 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1095 const Elf64_External_RegInfo
*ex
;
1096 Elf64_Internal_RegInfo
*in
;
1098 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1099 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1100 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1101 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1102 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1103 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1104 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1108 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1110 const Elf64_Internal_RegInfo
*in
;
1111 Elf64_External_RegInfo
*ex
;
1113 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1114 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1115 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1116 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1117 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1118 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1119 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1122 /* Swap in an options header. */
1125 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1127 const Elf_External_Options
*ex
;
1128 Elf_Internal_Options
*in
;
1130 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1131 in
->size
= H_GET_8 (abfd
, ex
->size
);
1132 in
->section
= H_GET_16 (abfd
, ex
->section
);
1133 in
->info
= H_GET_32 (abfd
, ex
->info
);
1136 /* Swap out an options header. */
1139 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1141 const Elf_Internal_Options
*in
;
1142 Elf_External_Options
*ex
;
1144 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1145 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1146 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1147 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1150 /* This function is called via qsort() to sort the dynamic relocation
1151 entries by increasing r_symndx value. */
1154 sort_dynamic_relocs (arg1
, arg2
)
1158 const Elf32_External_Rel
*ext_reloc1
= (const Elf32_External_Rel
*) arg1
;
1159 const Elf32_External_Rel
*ext_reloc2
= (const Elf32_External_Rel
*) arg2
;
1161 Elf_Internal_Rel int_reloc1
;
1162 Elf_Internal_Rel int_reloc2
;
1164 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, ext_reloc1
, &int_reloc1
);
1165 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, ext_reloc2
, &int_reloc2
);
1167 return (ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
));
1170 /* This routine is used to write out ECOFF debugging external symbol
1171 information. It is called via mips_elf_link_hash_traverse. The
1172 ECOFF external symbol information must match the ELF external
1173 symbol information. Unfortunately, at this point we don't know
1174 whether a symbol is required by reloc information, so the two
1175 tables may wind up being different. We must sort out the external
1176 symbol information before we can set the final size of the .mdebug
1177 section, and we must set the size of the .mdebug section before we
1178 can relocate any sections, and we can't know which symbols are
1179 required by relocation until we relocate the sections.
1180 Fortunately, it is relatively unlikely that any symbol will be
1181 stripped but required by a reloc. In particular, it can not happen
1182 when generating a final executable. */
1185 mips_elf_output_extsym (h
, data
)
1186 struct mips_elf_link_hash_entry
*h
;
1189 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
1191 asection
*sec
, *output_section
;
1193 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1194 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1196 if (h
->root
.indx
== -2)
1198 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1199 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
1200 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
1201 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
1203 else if (einfo
->info
->strip
== strip_all
1204 || (einfo
->info
->strip
== strip_some
1205 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1206 h
->root
.root
.root
.string
,
1207 false, false) == NULL
))
1215 if (h
->esym
.ifd
== -2)
1218 h
->esym
.cobol_main
= 0;
1219 h
->esym
.weakext
= 0;
1220 h
->esym
.reserved
= 0;
1221 h
->esym
.ifd
= ifdNil
;
1222 h
->esym
.asym
.value
= 0;
1223 h
->esym
.asym
.st
= stGlobal
;
1225 if (h
->root
.root
.type
== bfd_link_hash_undefined
1226 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
1230 /* Use undefined class. Also, set class and type for some
1232 name
= h
->root
.root
.root
.string
;
1233 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
1234 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
1236 h
->esym
.asym
.sc
= scData
;
1237 h
->esym
.asym
.st
= stLabel
;
1238 h
->esym
.asym
.value
= 0;
1240 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
1242 h
->esym
.asym
.sc
= scAbs
;
1243 h
->esym
.asym
.st
= stLabel
;
1244 h
->esym
.asym
.value
=
1245 mips_elf_hash_table (einfo
->info
)->procedure_count
;
1247 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
1249 h
->esym
.asym
.sc
= scAbs
;
1250 h
->esym
.asym
.st
= stLabel
;
1251 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
1254 h
->esym
.asym
.sc
= scUndefined
;
1256 else if (h
->root
.root
.type
!= bfd_link_hash_defined
1257 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1258 h
->esym
.asym
.sc
= scAbs
;
1263 sec
= h
->root
.root
.u
.def
.section
;
1264 output_section
= sec
->output_section
;
1266 /* When making a shared library and symbol h is the one from
1267 the another shared library, OUTPUT_SECTION may be null. */
1268 if (output_section
== NULL
)
1269 h
->esym
.asym
.sc
= scUndefined
;
1272 name
= bfd_section_name (output_section
->owner
, output_section
);
1274 if (strcmp (name
, ".text") == 0)
1275 h
->esym
.asym
.sc
= scText
;
1276 else if (strcmp (name
, ".data") == 0)
1277 h
->esym
.asym
.sc
= scData
;
1278 else if (strcmp (name
, ".sdata") == 0)
1279 h
->esym
.asym
.sc
= scSData
;
1280 else if (strcmp (name
, ".rodata") == 0
1281 || strcmp (name
, ".rdata") == 0)
1282 h
->esym
.asym
.sc
= scRData
;
1283 else if (strcmp (name
, ".bss") == 0)
1284 h
->esym
.asym
.sc
= scBss
;
1285 else if (strcmp (name
, ".sbss") == 0)
1286 h
->esym
.asym
.sc
= scSBss
;
1287 else if (strcmp (name
, ".init") == 0)
1288 h
->esym
.asym
.sc
= scInit
;
1289 else if (strcmp (name
, ".fini") == 0)
1290 h
->esym
.asym
.sc
= scFini
;
1292 h
->esym
.asym
.sc
= scAbs
;
1296 h
->esym
.asym
.reserved
= 0;
1297 h
->esym
.asym
.index
= indexNil
;
1300 if (h
->root
.root
.type
== bfd_link_hash_common
)
1301 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1302 else if (h
->root
.root
.type
== bfd_link_hash_defined
1303 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1305 if (h
->esym
.asym
.sc
== scCommon
)
1306 h
->esym
.asym
.sc
= scBss
;
1307 else if (h
->esym
.asym
.sc
== scSCommon
)
1308 h
->esym
.asym
.sc
= scSBss
;
1310 sec
= h
->root
.root
.u
.def
.section
;
1311 output_section
= sec
->output_section
;
1312 if (output_section
!= NULL
)
1313 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1314 + sec
->output_offset
1315 + output_section
->vma
);
1317 h
->esym
.asym
.value
= 0;
1319 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1321 struct mips_elf_link_hash_entry
*hd
= h
;
1322 boolean no_fn_stub
= h
->no_fn_stub
;
1324 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
1326 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
1327 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
1332 /* Set type and value for a symbol with a function stub. */
1333 h
->esym
.asym
.st
= stProc
;
1334 sec
= hd
->root
.root
.u
.def
.section
;
1336 h
->esym
.asym
.value
= 0;
1339 output_section
= sec
->output_section
;
1340 if (output_section
!= NULL
)
1341 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
1342 + sec
->output_offset
1343 + output_section
->vma
);
1345 h
->esym
.asym
.value
= 0;
1353 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1354 h
->root
.root
.root
.string
,
1357 einfo
->failed
= true;
1364 /* A comparison routine used to sort .gptab entries. */
1367 gptab_compare (p1
, p2
)
1371 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
1372 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
1374 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
1377 /* Returns the GOT section for ABFD. */
1380 mips_elf_got_section (abfd
)
1383 return bfd_get_section_by_name (abfd
, ".got");
1386 /* Returns the GOT information associated with the link indicated by
1387 INFO. If SGOTP is non-NULL, it is filled in with the GOT
1390 static struct mips_got_info
*
1391 mips_elf_got_info (abfd
, sgotp
)
1396 struct mips_got_info
*g
;
1398 sgot
= mips_elf_got_section (abfd
);
1399 BFD_ASSERT (sgot
!= NULL
);
1400 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
1401 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
1402 BFD_ASSERT (g
!= NULL
);
1409 /* Returns the GOT offset at which the indicated address can be found.
1410 If there is not yet a GOT entry for this value, create one. Returns
1411 -1 if no satisfactory GOT offset can be found. */
1414 mips_elf_local_got_index (abfd
, info
, value
)
1416 struct bfd_link_info
*info
;
1420 struct mips_got_info
*g
;
1423 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1425 /* Look to see if we already have an appropriate entry. */
1426 for (entry
= (sgot
->contents
1427 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
1428 entry
!= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
1429 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
1431 bfd_vma address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1432 if (address
== value
)
1433 return entry
- sgot
->contents
;
1436 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1439 /* Returns the GOT index for the global symbol indicated by H. */
1442 mips_elf_global_got_index (abfd
, h
)
1444 struct elf_link_hash_entry
*h
;
1448 struct mips_got_info
*g
;
1449 long global_got_dynindx
= 0;
1451 g
= mips_elf_got_info (abfd
, &sgot
);
1452 if (g
->global_gotsym
!= NULL
)
1453 global_got_dynindx
= g
->global_gotsym
->dynindx
;
1455 /* Once we determine the global GOT entry with the lowest dynamic
1456 symbol table index, we must put all dynamic symbols with greater
1457 indices into the GOT. That makes it easy to calculate the GOT
1459 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
1460 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
1461 * MIPS_ELF_GOT_SIZE (abfd
));
1462 BFD_ASSERT (index
< sgot
->_raw_size
);
1467 /* Find a GOT entry that is within 32KB of the VALUE. These entries
1468 are supposed to be placed at small offsets in the GOT, i.e.,
1469 within 32KB of GP. Return the index into the GOT for this page,
1470 and store the offset from this entry to the desired address in
1471 OFFSETP, if it is non-NULL. */
1474 mips_elf_got_page (abfd
, info
, value
, offsetp
)
1476 struct bfd_link_info
*info
;
1481 struct mips_got_info
*g
;
1483 bfd_byte
*last_entry
;
1487 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1489 /* Look to see if we already have an appropriate entry. */
1490 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
1491 for (entry
= (sgot
->contents
1492 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
1493 entry
!= last_entry
;
1494 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
1496 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1498 if (!mips_elf_overflow_p (value
- address
, 16))
1500 /* This entry will serve as the page pointer. We can add a
1501 16-bit number to it to get the actual address. */
1502 index
= entry
- sgot
->contents
;
1507 /* If we didn't have an appropriate entry, we create one now. */
1508 if (entry
== last_entry
)
1509 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1513 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1514 *offsetp
= value
- address
;
1520 /* Find a GOT entry whose higher-order 16 bits are the same as those
1521 for value. Return the index into the GOT for this entry. */
1524 mips_elf_got16_entry (abfd
, info
, value
, external
)
1526 struct bfd_link_info
*info
;
1531 struct mips_got_info
*g
;
1533 bfd_byte
*last_entry
;
1539 /* Although the ABI says that it is "the high-order 16 bits" that we
1540 want, it is really the %high value. The complete value is
1541 calculated with a `addiu' of a LO16 relocation, just as with a
1543 value
= mips_elf_high (value
) << 16;
1546 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1548 /* Look to see if we already have an appropriate entry. */
1549 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
1550 for (entry
= (sgot
->contents
1551 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
1552 entry
!= last_entry
;
1553 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
1555 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1556 if (address
== value
)
1558 /* This entry has the right high-order 16 bits, and the low-order
1559 16 bits are set to zero. */
1560 index
= entry
- sgot
->contents
;
1565 /* If we didn't have an appropriate entry, we create one now. */
1566 if (entry
== last_entry
)
1567 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1572 /* Returns the offset for the entry at the INDEXth position
1576 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
1584 sgot
= mips_elf_got_section (dynobj
);
1585 gp
= _bfd_get_gp_value (output_bfd
);
1586 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
1590 /* Create a local GOT entry for VALUE. Return the index of the entry,
1591 or -1 if it could not be created. */
1594 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
1596 struct mips_got_info
*g
;
1600 if (g
->assigned_gotno
>= g
->local_gotno
)
1602 /* We didn't allocate enough space in the GOT. */
1603 (*_bfd_error_handler
)
1604 (_("not enough GOT space for local GOT entries"));
1605 bfd_set_error (bfd_error_bad_value
);
1606 return (bfd_vma
) -1;
1609 MIPS_ELF_PUT_WORD (abfd
, value
,
1611 + MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
));
1612 return MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
1615 /* Sort the dynamic symbol table so that symbols that need GOT entries
1616 appear towards the end. This reduces the amount of GOT space
1617 required. MAX_LOCAL is used to set the number of local symbols
1618 known to be in the dynamic symbol table. During
1619 _bfd_mips_elf_size_dynamic_sections, this value is 1. Afterward, the
1620 section symbols are added and the count is higher. */
1623 mips_elf_sort_hash_table (info
, max_local
)
1624 struct bfd_link_info
*info
;
1625 unsigned long max_local
;
1627 struct mips_elf_hash_sort_data hsd
;
1628 struct mips_got_info
*g
;
1631 dynobj
= elf_hash_table (info
)->dynobj
;
1634 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
1635 hsd
.max_non_got_dynindx
= max_local
;
1636 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
1637 elf_hash_table (info
)),
1638 mips_elf_sort_hash_table_f
,
1641 /* There should have been enough room in the symbol table to
1642 accommodate both the GOT and non-GOT symbols. */
1643 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
1645 /* Now we know which dynamic symbol has the lowest dynamic symbol
1646 table index in the GOT. */
1647 g
= mips_elf_got_info (dynobj
, NULL
);
1648 g
->global_gotsym
= hsd
.low
;
1653 /* If H needs a GOT entry, assign it the highest available dynamic
1654 index. Otherwise, assign it the lowest available dynamic
1658 mips_elf_sort_hash_table_f (h
, data
)
1659 struct mips_elf_link_hash_entry
*h
;
1662 struct mips_elf_hash_sort_data
*hsd
1663 = (struct mips_elf_hash_sort_data
*) data
;
1665 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1666 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1668 /* Symbols without dynamic symbol table entries aren't interesting
1670 if (h
->root
.dynindx
== -1)
1673 if (h
->root
.got
.offset
!= 1)
1674 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
1677 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
1678 hsd
->low
= (struct elf_link_hash_entry
*) h
;
1684 /* If H is a symbol that needs a global GOT entry, but has a dynamic
1685 symbol table index lower than any we've seen to date, record it for
1689 mips_elf_record_global_got_symbol (h
, info
, g
)
1690 struct elf_link_hash_entry
*h
;
1691 struct bfd_link_info
*info
;
1692 struct mips_got_info
*g ATTRIBUTE_UNUSED
;
1694 /* A global symbol in the GOT must also be in the dynamic symbol
1696 if (h
->dynindx
== -1)
1698 switch (ELF_ST_VISIBILITY (h
->other
))
1702 _bfd_mips_elf_hide_symbol (info
, h
, true);
1705 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
1709 /* If we've already marked this entry as needing GOT space, we don't
1710 need to do it again. */
1711 if (h
->got
.offset
!= MINUS_ONE
)
1714 /* By setting this to a value other than -1, we are indicating that
1715 there needs to be a GOT entry for H. Avoid using zero, as the
1716 generic ELF copy_indirect_symbol tests for <= 0. */
1722 /* Returns the first relocation of type r_type found, beginning with
1723 RELOCATION. RELEND is one-past-the-end of the relocation table. */
1725 static const Elf_Internal_Rela
*
1726 mips_elf_next_relocation (abfd
, r_type
, relocation
, relend
)
1727 bfd
*abfd ATTRIBUTE_UNUSED
;
1728 unsigned int r_type
;
1729 const Elf_Internal_Rela
*relocation
;
1730 const Elf_Internal_Rela
*relend
;
1732 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
1733 immediately following. However, for the IRIX6 ABI, the next
1734 relocation may be a composed relocation consisting of several
1735 relocations for the same address. In that case, the R_MIPS_LO16
1736 relocation may occur as one of these. We permit a similar
1737 extension in general, as that is useful for GCC. */
1738 while (relocation
< relend
)
1740 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
)
1746 /* We didn't find it. */
1747 bfd_set_error (bfd_error_bad_value
);
1751 /* Return whether a relocation is against a local symbol. */
1754 mips_elf_local_relocation_p (input_bfd
, relocation
, local_sections
,
1757 const Elf_Internal_Rela
*relocation
;
1758 asection
**local_sections
;
1759 boolean check_forced
;
1761 unsigned long r_symndx
;
1762 Elf_Internal_Shdr
*symtab_hdr
;
1763 struct mips_elf_link_hash_entry
*h
;
1766 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
1767 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1768 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
1770 if (r_symndx
< extsymoff
)
1772 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
1777 /* Look up the hash table to check whether the symbol
1778 was forced local. */
1779 h
= (struct mips_elf_link_hash_entry
*)
1780 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
1781 /* Find the real hash-table entry for this symbol. */
1782 while (h
->root
.root
.type
== bfd_link_hash_indirect
1783 || h
->root
.root
.type
== bfd_link_hash_warning
)
1784 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1785 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
1792 /* Sign-extend VALUE, which has the indicated number of BITS. */
1795 mips_elf_sign_extend (value
, bits
)
1799 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
1800 /* VALUE is negative. */
1801 value
|= ((bfd_vma
) - 1) << bits
;
1806 /* Return non-zero if the indicated VALUE has overflowed the maximum
1807 range expressable by a signed number with the indicated number of
1811 mips_elf_overflow_p (value
, bits
)
1815 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
1817 if (svalue
> (1 << (bits
- 1)) - 1)
1818 /* The value is too big. */
1820 else if (svalue
< -(1 << (bits
- 1)))
1821 /* The value is too small. */
1828 /* Calculate the %high function. */
1831 mips_elf_high (value
)
1834 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
1837 /* Calculate the %higher function. */
1840 mips_elf_higher (value
)
1841 bfd_vma value ATTRIBUTE_UNUSED
;
1844 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
1847 return (bfd_vma
) -1;
1851 /* Calculate the %highest function. */
1854 mips_elf_highest (value
)
1855 bfd_vma value ATTRIBUTE_UNUSED
;
1858 return ((value
+ (bfd_vma
) 0x800080008000) >> 48) & 0xffff;
1861 return (bfd_vma
) -1;
1865 /* Create the .compact_rel section. */
1868 mips_elf_create_compact_rel_section (abfd
, info
)
1870 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1873 register asection
*s
;
1875 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
1877 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
1880 s
= bfd_make_section (abfd
, ".compact_rel");
1882 || ! bfd_set_section_flags (abfd
, s
, flags
)
1883 || ! bfd_set_section_alignment (abfd
, s
,
1884 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
1887 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
1893 /* Create the .got section to hold the global offset table. */
1896 mips_elf_create_got_section (abfd
, info
)
1898 struct bfd_link_info
*info
;
1901 register asection
*s
;
1902 struct elf_link_hash_entry
*h
;
1903 struct mips_got_info
*g
;
1906 /* This function may be called more than once. */
1907 if (mips_elf_got_section (abfd
))
1910 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1911 | SEC_LINKER_CREATED
);
1913 s
= bfd_make_section (abfd
, ".got");
1915 || ! bfd_set_section_flags (abfd
, s
, flags
)
1916 || ! bfd_set_section_alignment (abfd
, s
, 4))
1919 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
1920 linker script because we don't want to define the symbol if we
1921 are not creating a global offset table. */
1923 if (! (_bfd_generic_link_add_one_symbol
1924 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
1925 (bfd_vma
) 0, (const char *) NULL
, false,
1926 get_elf_backend_data (abfd
)->collect
,
1927 (struct bfd_link_hash_entry
**) &h
)))
1929 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
1930 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1931 h
->type
= STT_OBJECT
;
1934 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1937 /* The first several global offset table entries are reserved. */
1938 s
->_raw_size
= MIPS_RESERVED_GOTNO
* MIPS_ELF_GOT_SIZE (abfd
);
1940 amt
= sizeof (struct mips_got_info
);
1941 g
= (struct mips_got_info
*) bfd_alloc (abfd
, amt
);
1944 g
->global_gotsym
= NULL
;
1945 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
1946 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
1947 if (elf_section_data (s
) == NULL
)
1949 amt
= sizeof (struct bfd_elf_section_data
);
1950 s
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
1951 if (elf_section_data (s
) == NULL
)
1954 elf_section_data (s
)->tdata
= (PTR
) g
;
1955 elf_section_data (s
)->this_hdr
.sh_flags
1956 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1961 /* Returns the .msym section for ABFD, creating it if it does not
1962 already exist. Returns NULL to indicate error. */
1965 mips_elf_create_msym_section (abfd
)
1970 s
= bfd_get_section_by_name (abfd
, ".msym");
1973 s
= bfd_make_section (abfd
, ".msym");
1975 || !bfd_set_section_flags (abfd
, s
,
1979 | SEC_LINKER_CREATED
1981 || !bfd_set_section_alignment (abfd
, s
,
1982 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
1989 /* Calculate the value produced by the RELOCATION (which comes from
1990 the INPUT_BFD). The ADDEND is the addend to use for this
1991 RELOCATION; RELOCATION->R_ADDEND is ignored.
1993 The result of the relocation calculation is stored in VALUEP.
1994 REQUIRE_JALXP indicates whether or not the opcode used with this
1995 relocation must be JALX.
1997 This function returns bfd_reloc_continue if the caller need take no
1998 further action regarding this relocation, bfd_reloc_notsupported if
1999 something goes dramatically wrong, bfd_reloc_overflow if an
2000 overflow occurs, and bfd_reloc_ok to indicate success. */
2002 static bfd_reloc_status_type
2003 mips_elf_calculate_relocation (abfd
, input_bfd
, input_section
, info
,
2004 relocation
, addend
, howto
, local_syms
,
2005 local_sections
, valuep
, namep
,
2009 asection
*input_section
;
2010 struct bfd_link_info
*info
;
2011 const Elf_Internal_Rela
*relocation
;
2013 reloc_howto_type
*howto
;
2014 Elf_Internal_Sym
*local_syms
;
2015 asection
**local_sections
;
2018 boolean
*require_jalxp
;
2020 /* The eventual value we will return. */
2022 /* The address of the symbol against which the relocation is
2025 /* The final GP value to be used for the relocatable, executable, or
2026 shared object file being produced. */
2027 bfd_vma gp
= MINUS_ONE
;
2028 /* The place (section offset or address) of the storage unit being
2031 /* The value of GP used to create the relocatable object. */
2032 bfd_vma gp0
= MINUS_ONE
;
2033 /* The offset into the global offset table at which the address of
2034 the relocation entry symbol, adjusted by the addend, resides
2035 during execution. */
2036 bfd_vma g
= MINUS_ONE
;
2037 /* The section in which the symbol referenced by the relocation is
2039 asection
*sec
= NULL
;
2040 struct mips_elf_link_hash_entry
*h
= NULL
;
2041 /* True if the symbol referred to by this relocation is a local
2044 /* True if the symbol referred to by this relocation is "_gp_disp". */
2045 boolean gp_disp_p
= false;
2046 Elf_Internal_Shdr
*symtab_hdr
;
2048 unsigned long r_symndx
;
2050 /* True if overflow occurred during the calculation of the
2051 relocation value. */
2052 boolean overflowed_p
;
2053 /* True if this relocation refers to a MIPS16 function. */
2054 boolean target_is_16_bit_code_p
= false;
2056 /* Parse the relocation. */
2057 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
2058 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
2059 p
= (input_section
->output_section
->vma
2060 + input_section
->output_offset
2061 + relocation
->r_offset
);
2063 /* Assume that there will be no overflow. */
2064 overflowed_p
= false;
2066 /* Figure out whether or not the symbol is local, and get the offset
2067 used in the array of hash table entries. */
2068 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2069 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
2070 local_sections
, false);
2071 if (! elf_bad_symtab (input_bfd
))
2072 extsymoff
= symtab_hdr
->sh_info
;
2075 /* The symbol table does not follow the rule that local symbols
2076 must come before globals. */
2080 /* Figure out the value of the symbol. */
2083 Elf_Internal_Sym
*sym
;
2085 sym
= local_syms
+ r_symndx
;
2086 sec
= local_sections
[r_symndx
];
2088 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2089 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
2090 || (sec
->flags
& SEC_MERGE
))
2091 symbol
+= sym
->st_value
;
2092 if ((sec
->flags
& SEC_MERGE
)
2093 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2095 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
2097 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
2100 /* MIPS16 text labels should be treated as odd. */
2101 if (sym
->st_other
== STO_MIPS16
)
2104 /* Record the name of this symbol, for our caller. */
2105 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
2106 symtab_hdr
->sh_link
,
2109 *namep
= bfd_section_name (input_bfd
, sec
);
2111 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
2115 /* For global symbols we look up the symbol in the hash-table. */
2116 h
= ((struct mips_elf_link_hash_entry
*)
2117 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
2118 /* Find the real hash-table entry for this symbol. */
2119 while (h
->root
.root
.type
== bfd_link_hash_indirect
2120 || h
->root
.root
.type
== bfd_link_hash_warning
)
2121 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2123 /* Record the name of this symbol, for our caller. */
2124 *namep
= h
->root
.root
.root
.string
;
2126 /* See if this is the special _gp_disp symbol. Note that such a
2127 symbol must always be a global symbol. */
2128 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0
2129 && ! NEWABI_P (input_bfd
))
2131 /* Relocations against _gp_disp are permitted only with
2132 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
2133 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
2134 return bfd_reloc_notsupported
;
2138 /* If this symbol is defined, calculate its address. Note that
2139 _gp_disp is a magic symbol, always implicitly defined by the
2140 linker, so it's inappropriate to check to see whether or not
2142 else if ((h
->root
.root
.type
== bfd_link_hash_defined
2143 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2144 && h
->root
.root
.u
.def
.section
)
2146 sec
= h
->root
.root
.u
.def
.section
;
2147 if (sec
->output_section
)
2148 symbol
= (h
->root
.root
.u
.def
.value
2149 + sec
->output_section
->vma
2150 + sec
->output_offset
);
2152 symbol
= h
->root
.root
.u
.def
.value
;
2154 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
2155 /* We allow relocations against undefined weak symbols, giving
2156 it the value zero, so that you can undefined weak functions
2157 and check to see if they exist by looking at their
2160 else if (info
->shared
2161 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
2162 && !info
->no_undefined
2163 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
2165 else if (strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINK") == 0 ||
2166 strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINKING") == 0)
2168 /* If this is a dynamic link, we should have created a
2169 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
2170 in in _bfd_mips_elf_create_dynamic_sections.
2171 Otherwise, we should define the symbol with a value of 0.
2172 FIXME: It should probably get into the symbol table
2174 BFD_ASSERT (! info
->shared
);
2175 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
2180 if (! ((*info
->callbacks
->undefined_symbol
)
2181 (info
, h
->root
.root
.root
.string
, input_bfd
,
2182 input_section
, relocation
->r_offset
,
2183 (!info
->shared
|| info
->no_undefined
2184 || ELF_ST_VISIBILITY (h
->root
.other
)))))
2185 return bfd_reloc_undefined
;
2189 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
2192 /* If this is a 32- or 64-bit call to a 16-bit function with a stub, we
2193 need to redirect the call to the stub, unless we're already *in*
2195 if (r_type
!= R_MIPS16_26
&& !info
->relocateable
2196 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
2197 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
2198 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
2199 && !mips_elf_stub_section_p (input_bfd
, input_section
))
2201 /* This is a 32- or 64-bit call to a 16-bit function. We should
2202 have already noticed that we were going to need the
2205 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
2208 BFD_ASSERT (h
->need_fn_stub
);
2212 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2214 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
2215 need to redirect the call to the stub. */
2216 else if (r_type
== R_MIPS16_26
&& !info
->relocateable
2218 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
2219 && !target_is_16_bit_code_p
)
2221 /* If both call_stub and call_fp_stub are defined, we can figure
2222 out which one to use by seeing which one appears in the input
2224 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
2229 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
2231 if (strncmp (bfd_get_section_name (input_bfd
, o
),
2232 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
2234 sec
= h
->call_fp_stub
;
2241 else if (h
->call_stub
!= NULL
)
2244 sec
= h
->call_fp_stub
;
2246 BFD_ASSERT (sec
->_raw_size
> 0);
2247 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2250 /* Calls from 16-bit code to 32-bit code and vice versa require the
2251 special jalx instruction. */
2252 *require_jalxp
= (!info
->relocateable
2253 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
2254 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
2256 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
2257 local_sections
, true);
2259 /* If we haven't already determined the GOT offset, or the GP value,
2260 and we're going to need it, get it now. */
2265 case R_MIPS_GOT_DISP
:
2266 case R_MIPS_GOT_HI16
:
2267 case R_MIPS_CALL_HI16
:
2268 case R_MIPS_GOT_LO16
:
2269 case R_MIPS_CALL_LO16
:
2270 /* Find the index into the GOT where this value is located. */
2273 BFD_ASSERT (addend
== 0);
2274 g
= mips_elf_global_got_index (elf_hash_table (info
)->dynobj
,
2275 (struct elf_link_hash_entry
*) h
);
2276 if (! elf_hash_table(info
)->dynamic_sections_created
2278 && (info
->symbolic
|| h
->root
.dynindx
== -1)
2279 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2281 /* This is a static link or a -Bsymbolic link. The
2282 symbol is defined locally, or was forced to be local.
2283 We must initialize this entry in the GOT. */
2284 bfd
*tmpbfd
= elf_hash_table (info
)->dynobj
;
2285 asection
*sgot
= mips_elf_got_section(tmpbfd
);
2286 MIPS_ELF_PUT_WORD (tmpbfd
, symbol
+ addend
, sgot
->contents
+ g
);
2289 else if (r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS_CALL16
)
2290 /* There's no need to create a local GOT entry here; the
2291 calculation for a local GOT16 entry does not involve G. */
2295 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
2297 return bfd_reloc_outofrange
;
2300 /* Convert GOT indices to actual offsets. */
2301 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2307 case R_MIPS16_GPREL
:
2308 case R_MIPS_GPREL16
:
2309 case R_MIPS_GPREL32
:
2310 case R_MIPS_LITERAL
:
2311 gp0
= _bfd_get_gp_value (input_bfd
);
2312 gp
= _bfd_get_gp_value (abfd
);
2319 /* Figure out what kind of relocation is being performed. */
2323 return bfd_reloc_continue
;
2326 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
2327 overflowed_p
= mips_elf_overflow_p (value
, 16);
2334 || (elf_hash_table (info
)->dynamic_sections_created
2336 && ((h
->root
.elf_link_hash_flags
2337 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
2338 && ((h
->root
.elf_link_hash_flags
2339 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2341 && (input_section
->flags
& SEC_ALLOC
) != 0)
2343 /* If we're creating a shared library, or this relocation is
2344 against a symbol in a shared library, then we can't know
2345 where the symbol will end up. So, we create a relocation
2346 record in the output, and leave the job up to the dynamic
2349 if (!mips_elf_create_dynamic_relocation (abfd
,
2357 return bfd_reloc_undefined
;
2361 if (r_type
!= R_MIPS_REL32
)
2362 value
= symbol
+ addend
;
2366 value
&= howto
->dst_mask
;
2371 case R_MIPS_GNU_REL_LO16
:
2372 value
= symbol
+ addend
- p
;
2373 value
&= howto
->dst_mask
;
2376 case R_MIPS_GNU_REL16_S2
:
2377 value
= symbol
+ mips_elf_sign_extend (addend
<< 2, 18) - p
;
2378 overflowed_p
= mips_elf_overflow_p (value
, 18);
2379 value
= (value
>> 2) & howto
->dst_mask
;
2382 case R_MIPS_GNU_REL_HI16
:
2383 /* Instead of subtracting 'p' here, we should be subtracting the
2384 equivalent value for the LO part of the reloc, since the value
2385 here is relative to that address. Because that's not easy to do,
2386 we adjust 'addend' in _bfd_mips_elf_relocate_section(). See also
2387 the comment there for more information. */
2388 value
= mips_elf_high (addend
+ symbol
- p
);
2389 value
&= howto
->dst_mask
;
2393 /* The calculation for R_MIPS16_26 is just the same as for an
2394 R_MIPS_26. It's only the storage of the relocated field into
2395 the output file that's different. That's handled in
2396 mips_elf_perform_relocation. So, we just fall through to the
2397 R_MIPS_26 case here. */
2400 value
= (((addend
<< 2) | ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
2402 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
2403 value
&= howto
->dst_mask
;
2409 value
= mips_elf_high (addend
+ symbol
);
2410 value
&= howto
->dst_mask
;
2414 value
= mips_elf_high (addend
+ gp
- p
);
2415 overflowed_p
= mips_elf_overflow_p (value
, 16);
2421 value
= (symbol
+ addend
) & howto
->dst_mask
;
2424 value
= addend
+ gp
- p
+ 4;
2425 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
2426 for overflow. But, on, say, IRIX5, relocations against
2427 _gp_disp are normally generated from the .cpload
2428 pseudo-op. It generates code that normally looks like
2431 lui $gp,%hi(_gp_disp)
2432 addiu $gp,$gp,%lo(_gp_disp)
2435 Here $t9 holds the address of the function being called,
2436 as required by the MIPS ELF ABI. The R_MIPS_LO16
2437 relocation can easily overflow in this situation, but the
2438 R_MIPS_HI16 relocation will handle the overflow.
2439 Therefore, we consider this a bug in the MIPS ABI, and do
2440 not check for overflow here. */
2444 case R_MIPS_LITERAL
:
2445 /* Because we don't merge literal sections, we can handle this
2446 just like R_MIPS_GPREL16. In the long run, we should merge
2447 shared literals, and then we will need to additional work
2452 case R_MIPS16_GPREL
:
2453 /* The R_MIPS16_GPREL performs the same calculation as
2454 R_MIPS_GPREL16, but stores the relocated bits in a different
2455 order. We don't need to do anything special here; the
2456 differences are handled in mips_elf_perform_relocation. */
2457 case R_MIPS_GPREL16
:
2459 value
= mips_elf_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
2461 value
= mips_elf_sign_extend (addend
, 16) + symbol
- gp
;
2462 overflowed_p
= mips_elf_overflow_p (value
, 16);
2471 /* The special case is when the symbol is forced to be local. We
2472 need the full address in the GOT since no R_MIPS_LO16 relocation
2474 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
2475 local_sections
, false);
2476 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
, forced
);
2477 if (value
== MINUS_ONE
)
2478 return bfd_reloc_outofrange
;
2480 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2482 overflowed_p
= mips_elf_overflow_p (value
, 16);
2488 case R_MIPS_GOT_DISP
:
2490 overflowed_p
= mips_elf_overflow_p (value
, 16);
2493 case R_MIPS_GPREL32
:
2494 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
2498 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
2499 overflowed_p
= mips_elf_overflow_p (value
, 16);
2500 value
= (bfd_vma
) ((bfd_signed_vma
) value
/ 4);
2503 case R_MIPS_GOT_HI16
:
2504 case R_MIPS_CALL_HI16
:
2505 /* We're allowed to handle these two relocations identically.
2506 The dynamic linker is allowed to handle the CALL relocations
2507 differently by creating a lazy evaluation stub. */
2509 value
= mips_elf_high (value
);
2510 value
&= howto
->dst_mask
;
2513 case R_MIPS_GOT_LO16
:
2514 case R_MIPS_CALL_LO16
:
2515 value
= g
& howto
->dst_mask
;
2518 case R_MIPS_GOT_PAGE
:
2519 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
2520 if (value
== MINUS_ONE
)
2521 return bfd_reloc_outofrange
;
2522 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2524 overflowed_p
= mips_elf_overflow_p (value
, 16);
2527 case R_MIPS_GOT_OFST
:
2528 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
2529 overflowed_p
= mips_elf_overflow_p (value
, 16);
2533 value
= symbol
- addend
;
2534 value
&= howto
->dst_mask
;
2538 value
= mips_elf_higher (addend
+ symbol
);
2539 value
&= howto
->dst_mask
;
2542 case R_MIPS_HIGHEST
:
2543 value
= mips_elf_highest (addend
+ symbol
);
2544 value
&= howto
->dst_mask
;
2547 case R_MIPS_SCN_DISP
:
2548 value
= symbol
+ addend
- sec
->output_offset
;
2549 value
&= howto
->dst_mask
;
2554 /* Both of these may be ignored. R_MIPS_JALR is an optimization
2555 hint; we could improve performance by honoring that hint. */
2556 return bfd_reloc_continue
;
2558 case R_MIPS_GNU_VTINHERIT
:
2559 case R_MIPS_GNU_VTENTRY
:
2560 /* We don't do anything with these at present. */
2561 return bfd_reloc_continue
;
2564 /* An unrecognized relocation type. */
2565 return bfd_reloc_notsupported
;
2568 /* Store the VALUE for our caller. */
2570 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
2573 /* Obtain the field relocated by RELOCATION. */
2576 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
2577 reloc_howto_type
*howto
;
2578 const Elf_Internal_Rela
*relocation
;
2583 bfd_byte
*location
= contents
+ relocation
->r_offset
;
2585 /* Obtain the bytes. */
2586 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
2588 if ((ELF_R_TYPE (input_bfd
, relocation
->r_info
) == R_MIPS16_26
2589 || ELF_R_TYPE (input_bfd
, relocation
->r_info
) == R_MIPS16_GPREL
)
2590 && bfd_little_endian (input_bfd
))
2591 /* The two 16-bit words will be reversed on a little-endian system.
2592 See mips_elf_perform_relocation for more details. */
2593 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
2598 /* It has been determined that the result of the RELOCATION is the
2599 VALUE. Use HOWTO to place VALUE into the output file at the
2600 appropriate position. The SECTION is the section to which the
2601 relocation applies. If REQUIRE_JALX is true, then the opcode used
2602 for the relocation must be either JAL or JALX, and it is
2603 unconditionally converted to JALX.
2605 Returns false if anything goes wrong. */
2608 mips_elf_perform_relocation (info
, howto
, relocation
, value
, input_bfd
,
2609 input_section
, contents
, require_jalx
)
2610 struct bfd_link_info
*info
;
2611 reloc_howto_type
*howto
;
2612 const Elf_Internal_Rela
*relocation
;
2615 asection
*input_section
;
2617 boolean require_jalx
;
2621 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
2623 /* Figure out where the relocation is occurring. */
2624 location
= contents
+ relocation
->r_offset
;
2626 /* Obtain the current value. */
2627 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
2629 /* Clear the field we are setting. */
2630 x
&= ~howto
->dst_mask
;
2632 /* If this is the R_MIPS16_26 relocation, we must store the
2633 value in a funny way. */
2634 if (r_type
== R_MIPS16_26
)
2636 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
2637 Most mips16 instructions are 16 bits, but these instructions
2640 The format of these instructions is:
2642 +--------------+--------------------------------+
2643 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
2644 +--------------+--------------------------------+
2646 +-----------------------------------------------+
2648 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
2649 Note that the immediate value in the first word is swapped.
2651 When producing a relocateable object file, R_MIPS16_26 is
2652 handled mostly like R_MIPS_26. In particular, the addend is
2653 stored as a straight 26-bit value in a 32-bit instruction.
2654 (gas makes life simpler for itself by never adjusting a
2655 R_MIPS16_26 reloc to be against a section, so the addend is
2656 always zero). However, the 32 bit instruction is stored as 2
2657 16-bit values, rather than a single 32-bit value. In a
2658 big-endian file, the result is the same; in a little-endian
2659 file, the two 16-bit halves of the 32 bit value are swapped.
2660 This is so that a disassembler can recognize the jal
2663 When doing a final link, R_MIPS16_26 is treated as a 32 bit
2664 instruction stored as two 16-bit values. The addend A is the
2665 contents of the targ26 field. The calculation is the same as
2666 R_MIPS_26. When storing the calculated value, reorder the
2667 immediate value as shown above, and don't forget to store the
2668 value as two 16-bit values.
2670 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
2674 +--------+----------------------+
2678 +--------+----------------------+
2681 +----------+------+-------------+
2685 +----------+--------------------+
2686 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
2687 ((sub1 << 16) | sub2)).
2689 When producing a relocateable object file, the calculation is
2690 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2691 When producing a fully linked file, the calculation is
2692 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2693 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
2695 if (!info
->relocateable
)
2696 /* Shuffle the bits according to the formula above. */
2697 value
= (((value
& 0x1f0000) << 5)
2698 | ((value
& 0x3e00000) >> 5)
2699 | (value
& 0xffff));
2701 else if (r_type
== R_MIPS16_GPREL
)
2703 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
2704 mode. A typical instruction will have a format like this:
2706 +--------------+--------------------------------+
2707 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
2708 +--------------+--------------------------------+
2709 ! Major ! rx ! ry ! Imm 4:0 !
2710 +--------------+--------------------------------+
2712 EXTEND is the five bit value 11110. Major is the instruction
2715 This is handled exactly like R_MIPS_GPREL16, except that the
2716 addend is retrieved and stored as shown in this diagram; that
2717 is, the Imm fields above replace the V-rel16 field.
2719 All we need to do here is shuffle the bits appropriately. As
2720 above, the two 16-bit halves must be swapped on a
2721 little-endian system. */
2722 value
= (((value
& 0x7e0) << 16)
2723 | ((value
& 0xf800) << 5)
2727 /* Set the field. */
2728 x
|= (value
& howto
->dst_mask
);
2730 /* If required, turn JAL into JALX. */
2734 bfd_vma opcode
= x
>> 26;
2735 bfd_vma jalx_opcode
;
2737 /* Check to see if the opcode is already JAL or JALX. */
2738 if (r_type
== R_MIPS16_26
)
2740 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
2745 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
2749 /* If the opcode is not JAL or JALX, there's a problem. */
2752 (*_bfd_error_handler
)
2753 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
2754 bfd_archive_filename (input_bfd
),
2755 input_section
->name
,
2756 (unsigned long) relocation
->r_offset
);
2757 bfd_set_error (bfd_error_bad_value
);
2761 /* Make this the JALX opcode. */
2762 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
2765 /* Swap the high- and low-order 16 bits on little-endian systems
2766 when doing a MIPS16 relocation. */
2767 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
2768 && bfd_little_endian (input_bfd
))
2769 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
2771 /* Put the value into the output. */
2772 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
2776 /* Returns true if SECTION is a MIPS16 stub section. */
2779 mips_elf_stub_section_p (abfd
, section
)
2780 bfd
*abfd ATTRIBUTE_UNUSED
;
2783 const char *name
= bfd_get_section_name (abfd
, section
);
2785 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
2786 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
2787 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
2790 /* Add room for N relocations to the .rel.dyn section in ABFD. */
2793 mips_elf_allocate_dynamic_relocations (abfd
, n
)
2799 s
= bfd_get_section_by_name (abfd
, ".rel.dyn");
2800 BFD_ASSERT (s
!= NULL
);
2802 if (s
->_raw_size
== 0)
2804 /* Make room for a null element. */
2805 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
2808 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
2811 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
2812 is the original relocation, which is now being transformed into a
2813 dynamic relocation. The ADDENDP is adjusted if necessary; the
2814 caller should store the result in place of the original addend. */
2817 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
, sec
,
2818 symbol
, addendp
, input_section
)
2820 struct bfd_link_info
*info
;
2821 const Elf_Internal_Rela
*rel
;
2822 struct mips_elf_link_hash_entry
*h
;
2826 asection
*input_section
;
2828 Elf_Internal_Rel outrel
[3];
2834 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
2835 dynobj
= elf_hash_table (info
)->dynobj
;
2836 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
2837 BFD_ASSERT (sreloc
!= NULL
);
2838 BFD_ASSERT (sreloc
->contents
!= NULL
);
2839 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
2840 < sreloc
->_raw_size
);
2843 outrel
[0].r_offset
=
2844 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
2845 outrel
[1].r_offset
=
2846 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
2847 outrel
[2].r_offset
=
2848 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
2851 /* We begin by assuming that the offset for the dynamic relocation
2852 is the same as for the original relocation. We'll adjust this
2853 later to reflect the correct output offsets. */
2854 if (elf_section_data (input_section
)->sec_info_type
!= ELF_INFO_TYPE_STABS
)
2856 outrel
[1].r_offset
= rel
[1].r_offset
;
2857 outrel
[2].r_offset
= rel
[2].r_offset
;
2861 /* Except that in a stab section things are more complex.
2862 Because we compress stab information, the offset given in the
2863 relocation may not be the one we want; we must let the stabs
2864 machinery tell us the offset. */
2865 outrel
[1].r_offset
= outrel
[0].r_offset
;
2866 outrel
[2].r_offset
= outrel
[0].r_offset
;
2867 /* If we didn't need the relocation at all, this value will be
2869 if (outrel
[0].r_offset
== (bfd_vma
) -1)
2874 if (outrel
[0].r_offset
== (bfd_vma
) -1)
2876 /* FIXME: For -2 runtime relocation needs to be skipped, but
2877 properly resolved statically and installed. */
2878 BFD_ASSERT (outrel
[0].r_offset
!= (bfd_vma
) -2);
2880 /* If we've decided to skip this relocation, just output an empty
2881 record. Note that R_MIPS_NONE == 0, so that this call to memset
2882 is a way of setting R_TYPE to R_MIPS_NONE. */
2884 memset (outrel
, 0, sizeof (Elf_Internal_Rel
) * 3);
2888 bfd_vma section_offset
;
2890 /* We must now calculate the dynamic symbol table index to use
2891 in the relocation. */
2893 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
2894 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2896 indx
= h
->root
.dynindx
;
2897 /* h->root.dynindx may be -1 if this symbol was marked to
2904 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
2906 else if (sec
== NULL
|| sec
->owner
== NULL
)
2908 bfd_set_error (bfd_error_bad_value
);
2913 indx
= elf_section_data (sec
->output_section
)->dynindx
;
2918 /* Figure out how far the target of the relocation is from
2919 the beginning of its section. */
2920 section_offset
= symbol
- sec
->output_section
->vma
;
2921 /* The relocation we're building is section-relative.
2922 Therefore, the original addend must be adjusted by the
2924 *addendp
+= section_offset
;
2925 /* Now, the relocation is just against the section. */
2926 symbol
= sec
->output_section
->vma
;
2929 /* If the relocation was previously an absolute relocation and
2930 this symbol will not be referred to by the relocation, we must
2931 adjust it by the value we give it in the dynamic symbol table.
2932 Otherwise leave the job up to the dynamic linker. */
2933 if (!indx
&& r_type
!= R_MIPS_REL32
)
2936 /* The relocation is always an REL32 relocation because we don't
2937 know where the shared library will wind up at load-time. */
2938 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
2941 /* Adjust the output offset of the relocation to reference the
2942 correct location in the output file. */
2943 outrel
[0].r_offset
+= (input_section
->output_section
->vma
2944 + input_section
->output_offset
);
2945 outrel
[1].r_offset
+= (input_section
->output_section
->vma
2946 + input_section
->output_offset
);
2947 outrel
[2].r_offset
+= (input_section
->output_section
->vma
2948 + input_section
->output_offset
);
2951 /* Put the relocation back out. We have to use the special
2952 relocation outputter in the 64-bit case since the 64-bit
2953 relocation format is non-standard. */
2954 if (ABI_64_P (output_bfd
))
2956 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2957 (output_bfd
, &outrel
[0],
2959 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
2962 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
[0],
2963 (((Elf32_External_Rel
*)
2965 + sreloc
->reloc_count
));
2967 /* Record the index of the first relocation referencing H. This
2968 information is later emitted in the .msym section. */
2970 && (h
->min_dyn_reloc_index
== 0
2971 || sreloc
->reloc_count
< h
->min_dyn_reloc_index
))
2972 h
->min_dyn_reloc_index
= sreloc
->reloc_count
;
2974 /* We've now added another relocation. */
2975 ++sreloc
->reloc_count
;
2977 /* Make sure the output section is writable. The dynamic linker
2978 will be writing to it. */
2979 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
2982 /* On IRIX5, make an entry of compact relocation info. */
2983 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
2985 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
2990 Elf32_crinfo cptrel
;
2992 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
2993 cptrel
.vaddr
= (rel
->r_offset
2994 + input_section
->output_section
->vma
2995 + input_section
->output_offset
);
2996 if (r_type
== R_MIPS_REL32
)
2997 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
2999 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
3000 mips_elf_set_cr_dist2to (cptrel
, 0);
3001 cptrel
.konst
= *addendp
;
3003 cr
= (scpt
->contents
3004 + sizeof (Elf32_External_compact_rel
));
3005 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
3006 ((Elf32_External_crinfo
*) cr
3007 + scpt
->reloc_count
));
3008 ++scpt
->reloc_count
;
3015 /* Return the ISA for a MIPS e_flags value. */
3018 elf_mips_isa (flags
)
3021 switch (flags
& EF_MIPS_ARCH
)
3033 case E_MIPS_ARCH_32
:
3035 case E_MIPS_ARCH_64
:
3041 /* Return the MACH for a MIPS e_flags value. */
3044 _bfd_elf_mips_mach (flags
)
3047 switch (flags
& EF_MIPS_MACH
)
3049 case E_MIPS_MACH_3900
:
3050 return bfd_mach_mips3900
;
3052 case E_MIPS_MACH_4010
:
3053 return bfd_mach_mips4010
;
3055 case E_MIPS_MACH_4100
:
3056 return bfd_mach_mips4100
;
3058 case E_MIPS_MACH_4111
:
3059 return bfd_mach_mips4111
;
3061 case E_MIPS_MACH_4650
:
3062 return bfd_mach_mips4650
;
3064 case E_MIPS_MACH_SB1
:
3065 return bfd_mach_mips_sb1
;
3068 switch (flags
& EF_MIPS_ARCH
)
3072 return bfd_mach_mips3000
;
3076 return bfd_mach_mips6000
;
3080 return bfd_mach_mips4000
;
3084 return bfd_mach_mips8000
;
3088 return bfd_mach_mips5
;
3091 case E_MIPS_ARCH_32
:
3092 return bfd_mach_mipsisa32
;
3095 case E_MIPS_ARCH_64
:
3096 return bfd_mach_mipsisa64
;
3104 /* Return printable name for ABI. */
3106 static INLINE
char *
3107 elf_mips_abi_name (abfd
)
3112 flags
= elf_elfheader (abfd
)->e_flags
;
3113 switch (flags
& EF_MIPS_ABI
)
3116 if (ABI_N32_P (abfd
))
3118 else if (ABI_64_P (abfd
))
3122 case E_MIPS_ABI_O32
:
3124 case E_MIPS_ABI_O64
:
3126 case E_MIPS_ABI_EABI32
:
3128 case E_MIPS_ABI_EABI64
:
3131 return "unknown abi";
3135 /* MIPS ELF uses two common sections. One is the usual one, and the
3136 other is for small objects. All the small objects are kept
3137 together, and then referenced via the gp pointer, which yields
3138 faster assembler code. This is what we use for the small common
3139 section. This approach is copied from ecoff.c. */
3140 static asection mips_elf_scom_section
;
3141 static asymbol mips_elf_scom_symbol
;
3142 static asymbol
*mips_elf_scom_symbol_ptr
;
3144 /* MIPS ELF also uses an acommon section, which represents an
3145 allocated common symbol which may be overridden by a
3146 definition in a shared library. */
3147 static asection mips_elf_acom_section
;
3148 static asymbol mips_elf_acom_symbol
;
3149 static asymbol
*mips_elf_acom_symbol_ptr
;
3151 /* Handle the special MIPS section numbers that a symbol may use.
3152 This is used for both the 32-bit and the 64-bit ABI. */
3155 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3159 elf_symbol_type
*elfsym
;
3161 elfsym
= (elf_symbol_type
*) asym
;
3162 switch (elfsym
->internal_elf_sym
.st_shndx
)
3164 case SHN_MIPS_ACOMMON
:
3165 /* This section is used in a dynamically linked executable file.
3166 It is an allocated common section. The dynamic linker can
3167 either resolve these symbols to something in a shared
3168 library, or it can just leave them here. For our purposes,
3169 we can consider these symbols to be in a new section. */
3170 if (mips_elf_acom_section
.name
== NULL
)
3172 /* Initialize the acommon section. */
3173 mips_elf_acom_section
.name
= ".acommon";
3174 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3175 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3176 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3177 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3178 mips_elf_acom_symbol
.name
= ".acommon";
3179 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3180 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3181 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3183 asym
->section
= &mips_elf_acom_section
;
3187 /* Common symbols less than the GP size are automatically
3188 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3189 if (asym
->value
> elf_gp_size (abfd
)
3190 || IRIX_COMPAT (abfd
) == ict_irix6
)
3193 case SHN_MIPS_SCOMMON
:
3194 if (mips_elf_scom_section
.name
== NULL
)
3196 /* Initialize the small common section. */
3197 mips_elf_scom_section
.name
= ".scommon";
3198 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3199 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3200 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3201 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3202 mips_elf_scom_symbol
.name
= ".scommon";
3203 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3204 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3205 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3207 asym
->section
= &mips_elf_scom_section
;
3208 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3211 case SHN_MIPS_SUNDEFINED
:
3212 asym
->section
= bfd_und_section_ptr
;
3215 #if 0 /* for SGI_COMPAT */
3217 asym
->section
= mips_elf_text_section_ptr
;
3221 asym
->section
= mips_elf_data_section_ptr
;
3227 /* Work over a section just before writing it out. This routine is
3228 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3229 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3233 _bfd_mips_elf_section_processing (abfd
, hdr
)
3235 Elf_Internal_Shdr
*hdr
;
3237 if (hdr
->sh_type
== SHT_MIPS_REGINFO
3238 && hdr
->sh_size
> 0)
3242 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
3243 BFD_ASSERT (hdr
->contents
== NULL
);
3246 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
3249 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3250 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3254 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
3255 && hdr
->bfd_section
!= NULL
3256 && elf_section_data (hdr
->bfd_section
) != NULL
3257 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
3259 bfd_byte
*contents
, *l
, *lend
;
3261 /* We stored the section contents in the elf_section_data tdata
3262 field in the set_section_contents routine. We save the
3263 section contents so that we don't have to read them again.
3264 At this point we know that elf_gp is set, so we can look
3265 through the section contents to see if there is an
3266 ODK_REGINFO structure. */
3268 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
3270 lend
= contents
+ hdr
->sh_size
;
3271 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3273 Elf_Internal_Options intopt
;
3275 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3277 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3284 + sizeof (Elf_External_Options
)
3285 + (sizeof (Elf64_External_RegInfo
) - 8)),
3288 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
3289 if (bfd_bwrite (buf
, (bfd_size_type
) 8, abfd
) != 8)
3292 else if (intopt
.kind
== ODK_REGINFO
)
3299 + sizeof (Elf_External_Options
)
3300 + (sizeof (Elf32_External_RegInfo
) - 4)),
3303 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3304 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3311 if (hdr
->bfd_section
!= NULL
)
3313 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3315 if (strcmp (name
, ".sdata") == 0
3316 || strcmp (name
, ".lit8") == 0
3317 || strcmp (name
, ".lit4") == 0)
3319 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3320 hdr
->sh_type
= SHT_PROGBITS
;
3322 else if (strcmp (name
, ".sbss") == 0)
3324 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3325 hdr
->sh_type
= SHT_NOBITS
;
3327 else if (strcmp (name
, ".srdata") == 0)
3329 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
3330 hdr
->sh_type
= SHT_PROGBITS
;
3332 else if (strcmp (name
, ".compact_rel") == 0)
3335 hdr
->sh_type
= SHT_PROGBITS
;
3337 else if (strcmp (name
, ".rtproc") == 0)
3339 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
3341 unsigned int adjust
;
3343 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
3345 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
3353 /* Handle a MIPS specific section when reading an object file. This
3354 is called when elfcode.h finds a section with an unknown type.
3355 This routine supports both the 32-bit and 64-bit ELF ABI.
3357 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
3361 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
3363 Elf_Internal_Shdr
*hdr
;
3368 /* There ought to be a place to keep ELF backend specific flags, but
3369 at the moment there isn't one. We just keep track of the
3370 sections by their name, instead. Fortunately, the ABI gives
3371 suggested names for all the MIPS specific sections, so we will
3372 probably get away with this. */
3373 switch (hdr
->sh_type
)
3375 case SHT_MIPS_LIBLIST
:
3376 if (strcmp (name
, ".liblist") != 0)
3380 if (strcmp (name
, ".msym") != 0)
3383 case SHT_MIPS_CONFLICT
:
3384 if (strcmp (name
, ".conflict") != 0)
3387 case SHT_MIPS_GPTAB
:
3388 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
3391 case SHT_MIPS_UCODE
:
3392 if (strcmp (name
, ".ucode") != 0)
3395 case SHT_MIPS_DEBUG
:
3396 if (strcmp (name
, ".mdebug") != 0)
3398 flags
= SEC_DEBUGGING
;
3400 case SHT_MIPS_REGINFO
:
3401 if (strcmp (name
, ".reginfo") != 0
3402 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
3404 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
3406 case SHT_MIPS_IFACE
:
3407 if (strcmp (name
, ".MIPS.interfaces") != 0)
3410 case SHT_MIPS_CONTENT
:
3411 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
3414 case SHT_MIPS_OPTIONS
:
3415 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
3418 case SHT_MIPS_DWARF
:
3419 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
3422 case SHT_MIPS_SYMBOL_LIB
:
3423 if (strcmp (name
, ".MIPS.symlib") != 0)
3426 case SHT_MIPS_EVENTS
:
3427 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
3428 && strncmp (name
, ".MIPS.post_rel",
3429 sizeof ".MIPS.post_rel" - 1) != 0)
3436 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
3441 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
3442 (bfd_get_section_flags (abfd
,
3448 /* FIXME: We should record sh_info for a .gptab section. */
3450 /* For a .reginfo section, set the gp value in the tdata information
3451 from the contents of this section. We need the gp value while
3452 processing relocs, so we just get it now. The .reginfo section
3453 is not used in the 64-bit MIPS ELF ABI. */
3454 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
3456 Elf32_External_RegInfo ext
;
3459 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
3461 (bfd_size_type
) sizeof ext
))
3463 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
3464 elf_gp (abfd
) = s
.ri_gp_value
;
3467 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
3468 set the gp value based on what we find. We may see both
3469 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
3470 they should agree. */
3471 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
3473 bfd_byte
*contents
, *l
, *lend
;
3475 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
3476 if (contents
== NULL
)
3478 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
3479 (file_ptr
) 0, hdr
->sh_size
))
3485 lend
= contents
+ hdr
->sh_size
;
3486 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3488 Elf_Internal_Options intopt
;
3490 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3492 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3494 Elf64_Internal_RegInfo intreg
;
3496 bfd_mips_elf64_swap_reginfo_in
3498 ((Elf64_External_RegInfo
*)
3499 (l
+ sizeof (Elf_External_Options
))),
3501 elf_gp (abfd
) = intreg
.ri_gp_value
;
3503 else if (intopt
.kind
== ODK_REGINFO
)
3505 Elf32_RegInfo intreg
;
3507 bfd_mips_elf32_swap_reginfo_in
3509 ((Elf32_External_RegInfo
*)
3510 (l
+ sizeof (Elf_External_Options
))),
3512 elf_gp (abfd
) = intreg
.ri_gp_value
;
3522 /* Set the correct type for a MIPS ELF section. We do this by the
3523 section name, which is a hack, but ought to work. This routine is
3524 used by both the 32-bit and the 64-bit ABI. */
3527 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
3529 Elf32_Internal_Shdr
*hdr
;
3532 register const char *name
;
3534 name
= bfd_get_section_name (abfd
, sec
);
3536 if (strcmp (name
, ".liblist") == 0)
3538 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
3539 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
3540 /* The sh_link field is set in final_write_processing. */
3542 else if (strcmp (name
, ".conflict") == 0)
3543 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
3544 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3546 hdr
->sh_type
= SHT_MIPS_GPTAB
;
3547 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
3548 /* The sh_info field is set in final_write_processing. */
3550 else if (strcmp (name
, ".ucode") == 0)
3551 hdr
->sh_type
= SHT_MIPS_UCODE
;
3552 else if (strcmp (name
, ".mdebug") == 0)
3554 hdr
->sh_type
= SHT_MIPS_DEBUG
;
3555 /* In a shared object on IRIX 5.3, the .mdebug section has an
3556 entsize of 0. FIXME: Does this matter? */
3557 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
3558 hdr
->sh_entsize
= 0;
3560 hdr
->sh_entsize
= 1;
3562 else if (strcmp (name
, ".reginfo") == 0)
3564 hdr
->sh_type
= SHT_MIPS_REGINFO
;
3565 /* In a shared object on IRIX 5.3, the .reginfo section has an
3566 entsize of 0x18. FIXME: Does this matter? */
3567 if (SGI_COMPAT (abfd
))
3569 if ((abfd
->flags
& DYNAMIC
) != 0)
3570 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3572 hdr
->sh_entsize
= 1;
3575 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3577 else if (SGI_COMPAT (abfd
)
3578 && (strcmp (name
, ".hash") == 0
3579 || strcmp (name
, ".dynamic") == 0
3580 || strcmp (name
, ".dynstr") == 0))
3582 if (SGI_COMPAT (abfd
))
3583 hdr
->sh_entsize
= 0;
3585 /* This isn't how the IRIX6 linker behaves. */
3586 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
3589 else if (strcmp (name
, ".got") == 0
3590 || strcmp (name
, ".srdata") == 0
3591 || strcmp (name
, ".sdata") == 0
3592 || strcmp (name
, ".sbss") == 0
3593 || strcmp (name
, ".lit4") == 0
3594 || strcmp (name
, ".lit8") == 0)
3595 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
3596 else if (strcmp (name
, ".MIPS.interfaces") == 0)
3598 hdr
->sh_type
= SHT_MIPS_IFACE
;
3599 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3601 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
3603 hdr
->sh_type
= SHT_MIPS_CONTENT
;
3604 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3605 /* The sh_info field is set in final_write_processing. */
3607 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3609 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
3610 hdr
->sh_entsize
= 1;
3611 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3613 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
3614 hdr
->sh_type
= SHT_MIPS_DWARF
;
3615 else if (strcmp (name
, ".MIPS.symlib") == 0)
3617 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
3618 /* The sh_link and sh_info fields are set in
3619 final_write_processing. */
3621 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
3622 || strncmp (name
, ".MIPS.post_rel",
3623 sizeof ".MIPS.post_rel" - 1) == 0)
3625 hdr
->sh_type
= SHT_MIPS_EVENTS
;
3626 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3627 /* The sh_link field is set in final_write_processing. */
3629 else if (strcmp (name
, ".msym") == 0)
3631 hdr
->sh_type
= SHT_MIPS_MSYM
;
3632 hdr
->sh_flags
|= SHF_ALLOC
;
3633 hdr
->sh_entsize
= 8;
3636 /* The generic elf_fake_sections will set up REL_HDR using the
3637 default kind of relocations. But, we may actually need both
3638 kinds of relocations, so we set up the second header here.
3640 This is not necessary for the O32 ABI since that only uses Elf32_Rel
3641 relocations (cf. System V ABI, MIPS RISC Processor Supplement,
3642 3rd Edition, p. 4-17). It breaks the IRIX 5/6 32-bit ld, since one
3643 of the resulting empty .rela.<section> sections starts with
3644 sh_offset == object size, and ld doesn't allow that. While the check
3645 is arguably bogus for empty or SHT_NOBITS sections, it can easily be
3646 avoided by not emitting those useless sections in the first place. */
3647 if ((IRIX_COMPAT (abfd
) != ict_irix5
&& (IRIX_COMPAT (abfd
) != ict_irix6
))
3648 && (sec
->flags
& SEC_RELOC
) != 0)
3650 struct bfd_elf_section_data
*esd
;
3651 bfd_size_type amt
= sizeof (Elf_Internal_Shdr
);
3653 esd
= elf_section_data (sec
);
3654 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
3655 esd
->rel_hdr2
= (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, amt
);
3658 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
3659 !elf_section_data (sec
)->use_rela_p
);
3665 /* Given a BFD section, try to locate the corresponding ELF section
3666 index. This is used by both the 32-bit and the 64-bit ABI.
3667 Actually, it's not clear to me that the 64-bit ABI supports these,
3668 but for non-PIC objects we will certainly want support for at least
3669 the .scommon section. */
3672 _bfd_mips_elf_section_from_bfd_section (abfd
, sec
, retval
)
3673 bfd
*abfd ATTRIBUTE_UNUSED
;
3677 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3679 *retval
= SHN_MIPS_SCOMMON
;
3682 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
3684 *retval
= SHN_MIPS_ACOMMON
;
3690 /* Hook called by the linker routine which adds symbols from an object
3691 file. We must handle the special MIPS section numbers here. */
3694 _bfd_mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3696 struct bfd_link_info
*info
;
3697 const Elf_Internal_Sym
*sym
;
3699 flagword
*flagsp ATTRIBUTE_UNUSED
;
3703 if (SGI_COMPAT (abfd
)
3704 && (abfd
->flags
& DYNAMIC
) != 0
3705 && strcmp (*namep
, "_rld_new_interface") == 0)
3707 /* Skip IRIX5 rld entry name. */
3712 switch (sym
->st_shndx
)
3715 /* Common symbols less than the GP size are automatically
3716 treated as SHN_MIPS_SCOMMON symbols. */
3717 if (sym
->st_size
> elf_gp_size (abfd
)
3718 || IRIX_COMPAT (abfd
) == ict_irix6
)
3721 case SHN_MIPS_SCOMMON
:
3722 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3723 (*secp
)->flags
|= SEC_IS_COMMON
;
3724 *valp
= sym
->st_size
;
3728 /* This section is used in a shared object. */
3729 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
3731 asymbol
*elf_text_symbol
;
3732 asection
*elf_text_section
;
3733 bfd_size_type amt
= sizeof (asection
);
3735 elf_text_section
= bfd_zalloc (abfd
, amt
);
3736 if (elf_text_section
== NULL
)
3739 amt
= sizeof (asymbol
);
3740 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
3741 if (elf_text_symbol
== NULL
)
3744 /* Initialize the section. */
3746 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
3747 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
3749 elf_text_section
->symbol
= elf_text_symbol
;
3750 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
3752 elf_text_section
->name
= ".text";
3753 elf_text_section
->flags
= SEC_NO_FLAGS
;
3754 elf_text_section
->output_section
= NULL
;
3755 elf_text_section
->owner
= abfd
;
3756 elf_text_symbol
->name
= ".text";
3757 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
3758 elf_text_symbol
->section
= elf_text_section
;
3760 /* This code used to do *secp = bfd_und_section_ptr if
3761 info->shared. I don't know why, and that doesn't make sense,
3762 so I took it out. */
3763 *secp
= elf_tdata (abfd
)->elf_text_section
;
3766 case SHN_MIPS_ACOMMON
:
3767 /* Fall through. XXX Can we treat this as allocated data? */
3769 /* This section is used in a shared object. */
3770 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
3772 asymbol
*elf_data_symbol
;
3773 asection
*elf_data_section
;
3774 bfd_size_type amt
= sizeof (asection
);
3776 elf_data_section
= bfd_zalloc (abfd
, amt
);
3777 if (elf_data_section
== NULL
)
3780 amt
= sizeof (asymbol
);
3781 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
3782 if (elf_data_symbol
== NULL
)
3785 /* Initialize the section. */
3787 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
3788 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
3790 elf_data_section
->symbol
= elf_data_symbol
;
3791 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
3793 elf_data_section
->name
= ".data";
3794 elf_data_section
->flags
= SEC_NO_FLAGS
;
3795 elf_data_section
->output_section
= NULL
;
3796 elf_data_section
->owner
= abfd
;
3797 elf_data_symbol
->name
= ".data";
3798 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
3799 elf_data_symbol
->section
= elf_data_section
;
3801 /* This code used to do *secp = bfd_und_section_ptr if
3802 info->shared. I don't know why, and that doesn't make sense,
3803 so I took it out. */
3804 *secp
= elf_tdata (abfd
)->elf_data_section
;
3807 case SHN_MIPS_SUNDEFINED
:
3808 *secp
= bfd_und_section_ptr
;
3812 if (SGI_COMPAT (abfd
)
3814 && info
->hash
->creator
== abfd
->xvec
3815 && strcmp (*namep
, "__rld_obj_head") == 0)
3817 struct elf_link_hash_entry
*h
;
3819 /* Mark __rld_obj_head as dynamic. */
3821 if (! (_bfd_generic_link_add_one_symbol
3822 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3823 (bfd_vma
) *valp
, (const char *) NULL
, false,
3824 get_elf_backend_data (abfd
)->collect
,
3825 (struct bfd_link_hash_entry
**) &h
)))
3827 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3828 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3829 h
->type
= STT_OBJECT
;
3831 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3834 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3837 /* If this is a mips16 text symbol, add 1 to the value to make it
3838 odd. This will cause something like .word SYM to come up with
3839 the right value when it is loaded into the PC. */
3840 if (sym
->st_other
== STO_MIPS16
)
3846 /* This hook function is called before the linker writes out a global
3847 symbol. We mark symbols as small common if appropriate. This is
3848 also where we undo the increment of the value for a mips16 symbol. */
3851 _bfd_mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
3852 bfd
*abfd ATTRIBUTE_UNUSED
;
3853 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3854 const char *name ATTRIBUTE_UNUSED
;
3855 Elf_Internal_Sym
*sym
;
3856 asection
*input_sec
;
3858 /* If we see a common symbol, which implies a relocatable link, then
3859 if a symbol was small common in an input file, mark it as small
3860 common in the output file. */
3861 if (sym
->st_shndx
== SHN_COMMON
3862 && strcmp (input_sec
->name
, ".scommon") == 0)
3863 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
3865 if (sym
->st_other
== STO_MIPS16
3866 && (sym
->st_value
& 1) != 0)
3872 /* Functions for the dynamic linker. */
3874 /* Create dynamic sections when linking against a dynamic object. */
3877 _bfd_mips_elf_create_dynamic_sections (abfd
, info
)
3879 struct bfd_link_info
*info
;
3881 struct elf_link_hash_entry
*h
;
3883 register asection
*s
;
3884 const char * const *namep
;
3886 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3887 | SEC_LINKER_CREATED
| SEC_READONLY
);
3889 /* Mips ABI requests the .dynamic section to be read only. */
3890 s
= bfd_get_section_by_name (abfd
, ".dynamic");
3893 if (! bfd_set_section_flags (abfd
, s
, flags
))
3897 /* We need to create .got section. */
3898 if (! mips_elf_create_got_section (abfd
, info
))
3901 /* Create the .msym section on IRIX6. It is used by the dynamic
3902 linker to speed up dynamic relocations, and to avoid computing
3903 the ELF hash for symbols. */
3904 if (IRIX_COMPAT (abfd
) == ict_irix6
3905 && !mips_elf_create_msym_section (abfd
))
3908 /* Create .stub section. */
3909 if (bfd_get_section_by_name (abfd
,
3910 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
3912 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
3914 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
3915 || ! bfd_set_section_alignment (abfd
, s
,
3916 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
3920 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
3922 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
3924 s
= bfd_make_section (abfd
, ".rld_map");
3926 || ! bfd_set_section_flags (abfd
, s
, flags
&~ (flagword
) SEC_READONLY
)
3927 || ! bfd_set_section_alignment (abfd
, s
,
3928 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
3932 /* On IRIX5, we adjust add some additional symbols and change the
3933 alignments of several sections. There is no ABI documentation
3934 indicating that this is necessary on IRIX6, nor any evidence that
3935 the linker takes such action. */
3936 if (IRIX_COMPAT (abfd
) == ict_irix5
)
3938 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
3941 if (! (_bfd_generic_link_add_one_symbol
3942 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
3943 (bfd_vma
) 0, (const char *) NULL
, false,
3944 get_elf_backend_data (abfd
)->collect
,
3945 (struct bfd_link_hash_entry
**) &h
)))
3947 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3948 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3949 h
->type
= STT_SECTION
;
3951 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3955 /* We need to create a .compact_rel section. */
3956 if (SGI_COMPAT (abfd
))
3958 if (!mips_elf_create_compact_rel_section (abfd
, info
))
3962 /* Change alignments of some sections. */
3963 s
= bfd_get_section_by_name (abfd
, ".hash");
3965 bfd_set_section_alignment (abfd
, s
, 4);
3966 s
= bfd_get_section_by_name (abfd
, ".dynsym");
3968 bfd_set_section_alignment (abfd
, s
, 4);
3969 s
= bfd_get_section_by_name (abfd
, ".dynstr");
3971 bfd_set_section_alignment (abfd
, s
, 4);
3972 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3974 bfd_set_section_alignment (abfd
, s
, 4);
3975 s
= bfd_get_section_by_name (abfd
, ".dynamic");
3977 bfd_set_section_alignment (abfd
, s
, 4);
3983 if (SGI_COMPAT (abfd
))
3985 if (!(_bfd_generic_link_add_one_symbol
3986 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
3987 (bfd_vma
) 0, (const char *) NULL
, false,
3988 get_elf_backend_data (abfd
)->collect
,
3989 (struct bfd_link_hash_entry
**) &h
)))
3994 /* For normal mips it is _DYNAMIC_LINKING. */
3995 if (!(_bfd_generic_link_add_one_symbol
3996 (info
, abfd
, "_DYNAMIC_LINKING", BSF_GLOBAL
,
3997 bfd_abs_section_ptr
, (bfd_vma
) 0, (const char *) NULL
, false,
3998 get_elf_backend_data (abfd
)->collect
,
3999 (struct bfd_link_hash_entry
**) &h
)))
4002 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4003 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4004 h
->type
= STT_SECTION
;
4006 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4009 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
4011 /* __rld_map is a four byte word located in the .data section
4012 and is filled in by the rtld to contain a pointer to
4013 the _r_debug structure. Its symbol value will be set in
4014 _bfd_mips_elf_finish_dynamic_symbol. */
4015 s
= bfd_get_section_by_name (abfd
, ".rld_map");
4016 BFD_ASSERT (s
!= NULL
);
4019 if (SGI_COMPAT (abfd
))
4021 if (!(_bfd_generic_link_add_one_symbol
4022 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
4023 (bfd_vma
) 0, (const char *) NULL
, false,
4024 get_elf_backend_data (abfd
)->collect
,
4025 (struct bfd_link_hash_entry
**) &h
)))
4030 /* For normal mips the symbol is __RLD_MAP. */
4031 if (!(_bfd_generic_link_add_one_symbol
4032 (info
, abfd
, "__RLD_MAP", BSF_GLOBAL
, s
,
4033 (bfd_vma
) 0, (const char *) NULL
, false,
4034 get_elf_backend_data (abfd
)->collect
,
4035 (struct bfd_link_hash_entry
**) &h
)))
4038 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4039 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4040 h
->type
= STT_OBJECT
;
4042 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4050 /* Look through the relocs for a section during the first phase, and
4051 allocate space in the global offset table. */
4054 _bfd_mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
4056 struct bfd_link_info
*info
;
4058 const Elf_Internal_Rela
*relocs
;
4062 Elf_Internal_Shdr
*symtab_hdr
;
4063 struct elf_link_hash_entry
**sym_hashes
;
4064 struct mips_got_info
*g
;
4066 const Elf_Internal_Rela
*rel
;
4067 const Elf_Internal_Rela
*rel_end
;
4070 struct elf_backend_data
*bed
;
4072 if (info
->relocateable
)
4075 dynobj
= elf_hash_table (info
)->dynobj
;
4076 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4077 sym_hashes
= elf_sym_hashes (abfd
);
4078 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
4080 /* Check for the mips16 stub sections. */
4082 name
= bfd_get_section_name (abfd
, sec
);
4083 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
4085 unsigned long r_symndx
;
4087 /* Look at the relocation information to figure out which symbol
4090 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
4092 if (r_symndx
< extsymoff
4093 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
4097 /* This stub is for a local symbol. This stub will only be
4098 needed if there is some relocation in this BFD, other
4099 than a 16 bit function call, which refers to this symbol. */
4100 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4102 Elf_Internal_Rela
*sec_relocs
;
4103 const Elf_Internal_Rela
*r
, *rend
;
4105 /* We can ignore stub sections when looking for relocs. */
4106 if ((o
->flags
& SEC_RELOC
) == 0
4107 || o
->reloc_count
== 0
4108 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
4109 sizeof FN_STUB
- 1) == 0
4110 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
4111 sizeof CALL_STUB
- 1) == 0
4112 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
4113 sizeof CALL_FP_STUB
- 1) == 0)
4116 sec_relocs
= (_bfd_elf32_link_read_relocs
4117 (abfd
, o
, (PTR
) NULL
,
4118 (Elf_Internal_Rela
*) NULL
,
4119 info
->keep_memory
));
4120 if (sec_relocs
== NULL
)
4123 rend
= sec_relocs
+ o
->reloc_count
;
4124 for (r
= sec_relocs
; r
< rend
; r
++)
4125 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
4126 && ELF_R_TYPE (abfd
, r
->r_info
) != R_MIPS16_26
)
4129 if (elf_section_data (o
)->relocs
!= sec_relocs
)
4138 /* There is no non-call reloc for this stub, so we do
4139 not need it. Since this function is called before
4140 the linker maps input sections to output sections, we
4141 can easily discard it by setting the SEC_EXCLUDE
4143 sec
->flags
|= SEC_EXCLUDE
;
4147 /* Record this stub in an array of local symbol stubs for
4149 if (elf_tdata (abfd
)->local_stubs
== NULL
)
4151 unsigned long symcount
;
4155 if (elf_bad_symtab (abfd
))
4156 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
4158 symcount
= symtab_hdr
->sh_info
;
4159 amt
= symcount
* sizeof (asection
*);
4160 n
= (asection
**) bfd_zalloc (abfd
, amt
);
4163 elf_tdata (abfd
)->local_stubs
= n
;
4166 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
4168 /* We don't need to set mips16_stubs_seen in this case.
4169 That flag is used to see whether we need to look through
4170 the global symbol table for stubs. We don't need to set
4171 it here, because we just have a local stub. */
4175 struct mips_elf_link_hash_entry
*h
;
4177 h
= ((struct mips_elf_link_hash_entry
*)
4178 sym_hashes
[r_symndx
- extsymoff
]);
4180 /* H is the symbol this stub is for. */
4183 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
4186 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
4187 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4189 unsigned long r_symndx
;
4190 struct mips_elf_link_hash_entry
*h
;
4193 /* Look at the relocation information to figure out which symbol
4196 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
4198 if (r_symndx
< extsymoff
4199 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
4201 /* This stub was actually built for a static symbol defined
4202 in the same file. We assume that all static symbols in
4203 mips16 code are themselves mips16, so we can simply
4204 discard this stub. Since this function is called before
4205 the linker maps input sections to output sections, we can
4206 easily discard it by setting the SEC_EXCLUDE flag. */
4207 sec
->flags
|= SEC_EXCLUDE
;
4211 h
= ((struct mips_elf_link_hash_entry
*)
4212 sym_hashes
[r_symndx
- extsymoff
]);
4214 /* H is the symbol this stub is for. */
4216 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4217 loc
= &h
->call_fp_stub
;
4219 loc
= &h
->call_stub
;
4221 /* If we already have an appropriate stub for this function, we
4222 don't need another one, so we can discard this one. Since
4223 this function is called before the linker maps input sections
4224 to output sections, we can easily discard it by setting the
4225 SEC_EXCLUDE flag. We can also discard this section if we
4226 happen to already know that this is a mips16 function; it is
4227 not necessary to check this here, as it is checked later, but
4228 it is slightly faster to check now. */
4229 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
4231 sec
->flags
|= SEC_EXCLUDE
;
4236 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
4246 sgot
= mips_elf_got_section (dynobj
);
4251 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4252 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4253 BFD_ASSERT (g
!= NULL
);
4258 bed
= get_elf_backend_data (abfd
);
4259 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
4260 for (rel
= relocs
; rel
< rel_end
; ++rel
)
4262 unsigned long r_symndx
;
4263 unsigned int r_type
;
4264 struct elf_link_hash_entry
*h
;
4266 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
4267 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
4269 if (r_symndx
< extsymoff
)
4271 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
4273 (*_bfd_error_handler
)
4274 (_("%s: Malformed reloc detected for section %s"),
4275 bfd_archive_filename (abfd
), name
);
4276 bfd_set_error (bfd_error_bad_value
);
4281 h
= sym_hashes
[r_symndx
- extsymoff
];
4283 /* This may be an indirect symbol created because of a version. */
4286 while (h
->root
.type
== bfd_link_hash_indirect
)
4287 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4291 /* Some relocs require a global offset table. */
4292 if (dynobj
== NULL
|| sgot
== NULL
)
4298 case R_MIPS_CALL_HI16
:
4299 case R_MIPS_CALL_LO16
:
4300 case R_MIPS_GOT_HI16
:
4301 case R_MIPS_GOT_LO16
:
4302 case R_MIPS_GOT_PAGE
:
4303 case R_MIPS_GOT_OFST
:
4304 case R_MIPS_GOT_DISP
:
4306 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4307 if (! mips_elf_create_got_section (dynobj
, info
))
4309 g
= mips_elf_got_info (dynobj
, &sgot
);
4316 && (info
->shared
|| h
!= NULL
)
4317 && (sec
->flags
& SEC_ALLOC
) != 0)
4318 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4326 if (!h
&& (r_type
== R_MIPS_CALL_LO16
4327 || r_type
== R_MIPS_GOT_LO16
4328 || r_type
== R_MIPS_GOT_DISP
))
4330 /* We may need a local GOT entry for this relocation. We
4331 don't count R_MIPS_GOT_PAGE because we can estimate the
4332 maximum number of pages needed by looking at the size of
4333 the segment. Similar comments apply to R_MIPS_GOT16 and
4334 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
4335 R_MIPS_CALL_HI16 because these are always followed by an
4336 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
4338 This estimation is very conservative since we can merge
4339 duplicate entries in the GOT. In order to be less
4340 conservative, we could actually build the GOT here,
4341 rather than in relocate_section. */
4343 sgot
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
4351 (*_bfd_error_handler
)
4352 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
4353 bfd_archive_filename (abfd
), (unsigned long) rel
->r_offset
);
4354 bfd_set_error (bfd_error_bad_value
);
4359 case R_MIPS_CALL_HI16
:
4360 case R_MIPS_CALL_LO16
:
4363 /* This symbol requires a global offset table entry. */
4364 if (! mips_elf_record_global_got_symbol (h
, info
, g
))
4367 /* We need a stub, not a plt entry for the undefined
4368 function. But we record it as if it needs plt. See
4369 elf_adjust_dynamic_symbol in elflink.h. */
4370 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4376 case R_MIPS_GOT_HI16
:
4377 case R_MIPS_GOT_LO16
:
4378 case R_MIPS_GOT_DISP
:
4379 /* This symbol requires a global offset table entry. */
4380 if (h
&& ! mips_elf_record_global_got_symbol (h
, info
, g
))
4387 if ((info
->shared
|| h
!= NULL
)
4388 && (sec
->flags
& SEC_ALLOC
) != 0)
4392 const char *dname
= ".rel.dyn";
4394 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
4397 sreloc
= bfd_make_section (dynobj
, dname
);
4399 || ! bfd_set_section_flags (dynobj
, sreloc
,
4404 | SEC_LINKER_CREATED
4406 || ! bfd_set_section_alignment (dynobj
, sreloc
,
4411 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
4414 /* When creating a shared object, we must copy these
4415 reloc types into the output file as R_MIPS_REL32
4416 relocs. We make room for this reloc in the
4417 .rel.dyn reloc section. */
4418 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
4419 if ((sec
->flags
& MIPS_READONLY_SECTION
)
4420 == MIPS_READONLY_SECTION
)
4421 /* We tell the dynamic linker that there are
4422 relocations against the text segment. */
4423 info
->flags
|= DF_TEXTREL
;
4427 struct mips_elf_link_hash_entry
*hmips
;
4429 /* We only need to copy this reloc if the symbol is
4430 defined in a dynamic object. */
4431 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4432 ++hmips
->possibly_dynamic_relocs
;
4433 if ((sec
->flags
& MIPS_READONLY_SECTION
)
4434 == MIPS_READONLY_SECTION
)
4435 /* We need it to tell the dynamic linker if there
4436 are relocations against the text segment. */
4437 hmips
->readonly_reloc
= true;
4440 /* Even though we don't directly need a GOT entry for
4441 this symbol, a symbol must have a dynamic symbol
4442 table index greater that DT_MIPS_GOTSYM if there are
4443 dynamic relocations against it. */
4445 && ! mips_elf_record_global_got_symbol (h
, info
, g
))
4449 if (SGI_COMPAT (abfd
))
4450 mips_elf_hash_table (info
)->compact_rel_size
+=
4451 sizeof (Elf32_External_crinfo
);
4455 case R_MIPS_GPREL16
:
4456 case R_MIPS_LITERAL
:
4457 case R_MIPS_GPREL32
:
4458 if (SGI_COMPAT (abfd
))
4459 mips_elf_hash_table (info
)->compact_rel_size
+=
4460 sizeof (Elf32_External_crinfo
);
4463 /* This relocation describes the C++ object vtable hierarchy.
4464 Reconstruct it for later use during GC. */
4465 case R_MIPS_GNU_VTINHERIT
:
4466 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4470 /* This relocation describes which C++ vtable entries are actually
4471 used. Record for later use during GC. */
4472 case R_MIPS_GNU_VTENTRY
:
4473 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
4481 /* We must not create a stub for a symbol that has relocations
4482 related to taking the function's address. */
4488 struct mips_elf_link_hash_entry
*mh
;
4490 mh
= (struct mips_elf_link_hash_entry
*) h
;
4491 mh
->no_fn_stub
= true;
4495 case R_MIPS_CALL_HI16
:
4496 case R_MIPS_CALL_LO16
:
4500 /* If this reloc is not a 16 bit call, and it has a global
4501 symbol, then we will need the fn_stub if there is one.
4502 References from a stub section do not count. */
4504 && r_type
!= R_MIPS16_26
4505 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
4506 sizeof FN_STUB
- 1) != 0
4507 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
4508 sizeof CALL_STUB
- 1) != 0
4509 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
4510 sizeof CALL_FP_STUB
- 1) != 0)
4512 struct mips_elf_link_hash_entry
*mh
;
4514 mh
= (struct mips_elf_link_hash_entry
*) h
;
4515 mh
->need_fn_stub
= true;
4522 /* Adjust a symbol defined by a dynamic object and referenced by a
4523 regular object. The current definition is in some section of the
4524 dynamic object, but we're not including those sections. We have to
4525 change the definition to something the rest of the link can
4529 _bfd_mips_elf_adjust_dynamic_symbol (info
, h
)
4530 struct bfd_link_info
*info
;
4531 struct elf_link_hash_entry
*h
;
4534 struct mips_elf_link_hash_entry
*hmips
;
4537 dynobj
= elf_hash_table (info
)->dynobj
;
4539 /* Make sure we know what is going on here. */
4540 BFD_ASSERT (dynobj
!= NULL
4541 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
4542 || h
->weakdef
!= NULL
4543 || ((h
->elf_link_hash_flags
4544 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4545 && (h
->elf_link_hash_flags
4546 & ELF_LINK_HASH_REF_REGULAR
) != 0
4547 && (h
->elf_link_hash_flags
4548 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
4550 /* If this symbol is defined in a dynamic object, we need to copy
4551 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
4553 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4554 if (! info
->relocateable
4555 && hmips
->possibly_dynamic_relocs
!= 0
4556 && (h
->root
.type
== bfd_link_hash_defweak
4557 || (h
->elf_link_hash_flags
4558 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4560 mips_elf_allocate_dynamic_relocations (dynobj
,
4561 hmips
->possibly_dynamic_relocs
);
4562 if (hmips
->readonly_reloc
)
4563 /* We tell the dynamic linker that there are relocations
4564 against the text segment. */
4565 info
->flags
|= DF_TEXTREL
;
4568 /* For a function, create a stub, if allowed. */
4569 if (! hmips
->no_fn_stub
4570 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4572 if (! elf_hash_table (info
)->dynamic_sections_created
)
4575 /* If this symbol is not defined in a regular file, then set
4576 the symbol to the stub location. This is required to make
4577 function pointers compare as equal between the normal
4578 executable and the shared library. */
4579 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4581 /* We need .stub section. */
4582 s
= bfd_get_section_by_name (dynobj
,
4583 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
4584 BFD_ASSERT (s
!= NULL
);
4586 h
->root
.u
.def
.section
= s
;
4587 h
->root
.u
.def
.value
= s
->_raw_size
;
4589 /* XXX Write this stub address somewhere. */
4590 h
->plt
.offset
= s
->_raw_size
;
4592 /* Make room for this stub code. */
4593 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4595 /* The last half word of the stub will be filled with the index
4596 of this symbol in .dynsym section. */
4600 else if ((h
->type
== STT_FUNC
)
4601 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
4603 /* This will set the entry for this symbol in the GOT to 0, and
4604 the dynamic linker will take care of this. */
4605 h
->root
.u
.def
.value
= 0;
4609 /* If this is a weak symbol, and there is a real definition, the
4610 processor independent code will have arranged for us to see the
4611 real definition first, and we can just use the same value. */
4612 if (h
->weakdef
!= NULL
)
4614 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4615 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4616 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4617 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4621 /* This is a reference to a symbol defined by a dynamic object which
4622 is not a function. */
4627 /* This function is called after all the input files have been read,
4628 and the input sections have been assigned to output sections. We
4629 check for any mips16 stub sections that we can discard. */
4632 _bfd_mips_elf_always_size_sections (output_bfd
, info
)
4634 struct bfd_link_info
*info
;
4638 /* The .reginfo section has a fixed size. */
4639 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
4641 bfd_set_section_size (output_bfd
, ri
,
4642 (bfd_size_type
) sizeof (Elf32_External_RegInfo
));
4644 if (info
->relocateable
4645 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
4648 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4649 mips_elf_check_mips16_stubs
,
4655 /* Set the sizes of the dynamic sections. */
4658 _bfd_mips_elf_size_dynamic_sections (output_bfd
, info
)
4660 struct bfd_link_info
*info
;
4665 struct mips_got_info
*g
= NULL
;
4667 dynobj
= elf_hash_table (info
)->dynobj
;
4668 BFD_ASSERT (dynobj
!= NULL
);
4670 if (elf_hash_table (info
)->dynamic_sections_created
)
4672 /* Set the contents of the .interp section to the interpreter. */
4675 s
= bfd_get_section_by_name (dynobj
, ".interp");
4676 BFD_ASSERT (s
!= NULL
);
4678 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
4680 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
4684 /* The check_relocs and adjust_dynamic_symbol entry points have
4685 determined the sizes of the various dynamic sections. Allocate
4688 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4693 /* It's OK to base decisions on the section name, because none
4694 of the dynobj section names depend upon the input files. */
4695 name
= bfd_get_section_name (dynobj
, s
);
4697 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4702 if (strncmp (name
, ".rel", 4) == 0)
4704 if (s
->_raw_size
== 0)
4706 /* We only strip the section if the output section name
4707 has the same name. Otherwise, there might be several
4708 input sections for this output section. FIXME: This
4709 code is probably not needed these days anyhow, since
4710 the linker now does not create empty output sections. */
4711 if (s
->output_section
!= NULL
4713 bfd_get_section_name (s
->output_section
->owner
,
4714 s
->output_section
)) == 0)
4719 const char *outname
;
4722 /* If this relocation section applies to a read only
4723 section, then we probably need a DT_TEXTREL entry.
4724 If the relocation section is .rel.dyn, we always
4725 assert a DT_TEXTREL entry rather than testing whether
4726 there exists a relocation to a read only section or
4728 outname
= bfd_get_section_name (output_bfd
,
4730 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
4732 && (target
->flags
& SEC_READONLY
) != 0
4733 && (target
->flags
& SEC_ALLOC
) != 0)
4734 || strcmp (outname
, ".rel.dyn") == 0)
4737 /* We use the reloc_count field as a counter if we need
4738 to copy relocs into the output file. */
4739 if (strcmp (name
, ".rel.dyn") != 0)
4743 else if (strncmp (name
, ".got", 4) == 0)
4746 bfd_size_type loadable_size
= 0;
4747 bfd_size_type local_gotno
;
4750 BFD_ASSERT (elf_section_data (s
) != NULL
);
4751 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
4752 BFD_ASSERT (g
!= NULL
);
4754 /* Calculate the total loadable size of the output. That
4755 will give us the maximum number of GOT_PAGE entries
4757 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
4759 asection
*subsection
;
4761 for (subsection
= sub
->sections
;
4763 subsection
= subsection
->next
)
4765 if ((subsection
->flags
& SEC_ALLOC
) == 0)
4767 loadable_size
+= ((subsection
->_raw_size
+ 0xf)
4768 &~ (bfd_size_type
) 0xf);
4771 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
4773 /* Assume there are two loadable segments consisting of
4774 contiguous sections. Is 5 enough? */
4775 local_gotno
= (loadable_size
>> 16) + 5;
4776 if (NEWABI_P (output_bfd
))
4777 /* It's possible we will need GOT_PAGE entries as well as
4778 GOT16 entries. Often, these will be able to share GOT
4779 entries, but not always. */
4782 g
->local_gotno
+= local_gotno
;
4783 s
->_raw_size
+= local_gotno
* MIPS_ELF_GOT_SIZE (dynobj
);
4785 /* There has to be a global GOT entry for every symbol with
4786 a dynamic symbol table index of DT_MIPS_GOTSYM or
4787 higher. Therefore, it make sense to put those symbols
4788 that need GOT entries at the end of the symbol table. We
4790 if (! mips_elf_sort_hash_table (info
, 1))
4793 if (g
->global_gotsym
!= NULL
)
4794 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
4796 /* If there are no global symbols, or none requiring
4797 relocations, then GLOBAL_GOTSYM will be NULL. */
4799 g
->global_gotno
= i
;
4800 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (dynobj
);
4802 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
4804 /* IRIX rld assumes that the function stub isn't at the end
4805 of .text section. So put a dummy. XXX */
4806 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4808 else if (! info
->shared
4809 && ! mips_elf_hash_table (info
)->use_rld_obj_head
4810 && strncmp (name
, ".rld_map", 8) == 0)
4812 /* We add a room for __rld_map. It will be filled in by the
4813 rtld to contain a pointer to the _r_debug structure. */
4816 else if (SGI_COMPAT (output_bfd
)
4817 && strncmp (name
, ".compact_rel", 12) == 0)
4818 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
4819 else if (strcmp (name
, ".msym") == 0)
4820 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
4821 * (elf_hash_table (info
)->dynsymcount
4822 + bfd_count_sections (output_bfd
)));
4823 else if (strncmp (name
, ".init", 5) != 0)
4825 /* It's not one of our sections, so don't allocate space. */
4831 _bfd_strip_section_from_output (info
, s
);
4835 /* Allocate memory for the section contents. */
4836 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4837 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
4839 bfd_set_error (bfd_error_no_memory
);
4844 if (elf_hash_table (info
)->dynamic_sections_created
)
4846 /* Add some entries to the .dynamic section. We fill in the
4847 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
4848 must add the entries now so that we get the correct size for
4849 the .dynamic section. The DT_DEBUG entry is filled in by the
4850 dynamic linker and used by the debugger. */
4853 /* SGI object has the equivalence of DT_DEBUG in the
4854 DT_MIPS_RLD_MAP entry. */
4855 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
4857 if (!SGI_COMPAT (output_bfd
))
4859 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
4865 /* Shared libraries on traditional mips have DT_DEBUG. */
4866 if (!SGI_COMPAT (output_bfd
))
4868 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
4873 if (reltext
&& SGI_COMPAT (output_bfd
))
4874 info
->flags
|= DF_TEXTREL
;
4876 if ((info
->flags
& DF_TEXTREL
) != 0)
4878 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
4882 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
4885 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
4887 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
4890 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
4893 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
4897 if (SGI_COMPAT (output_bfd
))
4899 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICTNO
, 0))
4903 if (SGI_COMPAT (output_bfd
))
4905 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLISTNO
, 0))
4909 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
4911 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICT
, 0))
4914 s
= bfd_get_section_by_name (dynobj
, ".liblist");
4915 BFD_ASSERT (s
!= NULL
);
4917 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLIST
, 0))
4921 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
4924 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
4928 /* Time stamps in executable files are a bad idea. */
4929 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
4934 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
4939 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
4943 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
4946 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
4949 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
4952 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
4955 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
4958 if (IRIX_COMPAT (dynobj
) == ict_irix5
4959 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
4962 if (IRIX_COMPAT (dynobj
) == ict_irix6
4963 && (bfd_get_section_by_name
4964 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
4965 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
4968 if (bfd_get_section_by_name (dynobj
, ".msym")
4969 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_MSYM
, 0))
4976 /* Relocate a MIPS ELF section. */
4979 _bfd_mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4980 contents
, relocs
, local_syms
, local_sections
)
4982 struct bfd_link_info
*info
;
4984 asection
*input_section
;
4986 Elf_Internal_Rela
*relocs
;
4987 Elf_Internal_Sym
*local_syms
;
4988 asection
**local_sections
;
4990 Elf_Internal_Rela
*rel
;
4991 const Elf_Internal_Rela
*relend
;
4993 boolean use_saved_addend_p
= false;
4994 struct elf_backend_data
*bed
;
4996 bed
= get_elf_backend_data (output_bfd
);
4997 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
4998 for (rel
= relocs
; rel
< relend
; ++rel
)
5002 reloc_howto_type
*howto
;
5003 boolean require_jalx
;
5004 /* True if the relocation is a RELA relocation, rather than a
5006 boolean rela_relocation_p
= true;
5007 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5008 const char * msg
= (const char *) NULL
;
5010 /* Find the relocation howto for this relocation. */
5011 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
5013 /* Some 32-bit code uses R_MIPS_64. In particular, people use
5014 64-bit code, but make sure all their addresses are in the
5015 lowermost or uppermost 32-bit section of the 64-bit address
5016 space. Thus, when they use an R_MIPS_64 they mean what is
5017 usually meant by R_MIPS_32, with the exception that the
5018 stored value is sign-extended to 64 bits. */
5019 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, false);
5021 /* On big-endian systems, we need to lie about the position
5023 if (bfd_big_endian (input_bfd
))
5027 /* NewABI defaults to RELA relocations. */
5028 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
5029 NEWABI_P (input_bfd
));
5031 if (!use_saved_addend_p
)
5033 Elf_Internal_Shdr
*rel_hdr
;
5035 /* If these relocations were originally of the REL variety,
5036 we must pull the addend out of the field that will be
5037 relocated. Otherwise, we simply use the contents of the
5038 RELA relocation. To determine which flavor or relocation
5039 this is, we depend on the fact that the INPUT_SECTION's
5040 REL_HDR is read before its REL_HDR2. */
5041 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
5042 if ((size_t) (rel
- relocs
)
5043 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
5044 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
5045 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
5047 /* Note that this is a REL relocation. */
5048 rela_relocation_p
= false;
5050 /* Get the addend, which is stored in the input file. */
5051 addend
= mips_elf_obtain_contents (howto
, rel
, input_bfd
,
5053 addend
&= howto
->src_mask
;
5054 addend
<<= howto
->rightshift
;
5056 /* For some kinds of relocations, the ADDEND is a
5057 combination of the addend stored in two different
5059 if (r_type
== R_MIPS_HI16
5060 || r_type
== R_MIPS_GNU_REL_HI16
5061 || (r_type
== R_MIPS_GOT16
5062 && mips_elf_local_relocation_p (input_bfd
, rel
,
5063 local_sections
, false)))
5066 const Elf_Internal_Rela
*lo16_relocation
;
5067 reloc_howto_type
*lo16_howto
;
5070 /* The combined value is the sum of the HI16 addend,
5071 left-shifted by sixteen bits, and the LO16
5072 addend, sign extended. (Usually, the code does
5073 a `lui' of the HI16 value, and then an `addiu' of
5076 Scan ahead to find a matching LO16 relocation. */
5077 if (r_type
== R_MIPS_GNU_REL_HI16
)
5078 lo
= R_MIPS_GNU_REL_LO16
;
5081 lo16_relocation
= mips_elf_next_relocation (input_bfd
, lo
,
5083 if (lo16_relocation
== NULL
)
5086 /* Obtain the addend kept there. */
5087 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, lo
, false);
5088 l
= mips_elf_obtain_contents (lo16_howto
, lo16_relocation
,
5089 input_bfd
, contents
);
5090 l
&= lo16_howto
->src_mask
;
5091 l
<<= lo16_howto
->rightshift
;
5092 l
= mips_elf_sign_extend (l
, 16);
5096 /* Compute the combined addend. */
5099 /* If PC-relative, subtract the difference between the
5100 address of the LO part of the reloc and the address of
5101 the HI part. The relocation is relative to the LO
5102 part, but mips_elf_calculate_relocation() doesn't
5103 know its address or the difference from the HI part, so
5104 we subtract that difference here. See also the
5105 comment in mips_elf_calculate_relocation(). */
5106 if (r_type
== R_MIPS_GNU_REL_HI16
)
5107 addend
-= (lo16_relocation
->r_offset
- rel
->r_offset
);
5109 else if (r_type
== R_MIPS16_GPREL
)
5111 /* The addend is scrambled in the object file. See
5112 mips_elf_perform_relocation for details on the
5114 addend
= (((addend
& 0x1f0000) >> 5)
5115 | ((addend
& 0x7e00000) >> 16)
5120 addend
= rel
->r_addend
;
5123 if (info
->relocateable
)
5125 Elf_Internal_Sym
*sym
;
5126 unsigned long r_symndx
;
5128 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
5129 && bfd_big_endian (input_bfd
))
5132 /* Since we're just relocating, all we need to do is copy
5133 the relocations back out to the object file, unless
5134 they're against a section symbol, in which case we need
5135 to adjust by the section offset, or unless they're GP
5136 relative in which case we need to adjust by the amount
5137 that we're adjusting GP in this relocateable object. */
5139 if (! mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
5141 /* There's nothing to do for non-local relocations. */
5144 if (r_type
== R_MIPS16_GPREL
5145 || r_type
== R_MIPS_GPREL16
5146 || r_type
== R_MIPS_GPREL32
5147 || r_type
== R_MIPS_LITERAL
)
5148 addend
-= (_bfd_get_gp_value (output_bfd
)
5149 - _bfd_get_gp_value (input_bfd
));
5151 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
5152 sym
= local_syms
+ r_symndx
;
5153 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
5154 /* Adjust the addend appropriately. */
5155 addend
+= local_sections
[r_symndx
]->output_offset
;
5157 if (howto
->partial_inplace
)
5159 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
5160 then we only want to write out the high-order 16 bits.
5161 The subsequent R_MIPS_LO16 will handle the low-order bits.
5163 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
5164 || r_type
== R_MIPS_GNU_REL_HI16
)
5165 addend
= mips_elf_high (addend
);
5166 else if (r_type
== R_MIPS_HIGHER
)
5167 addend
= mips_elf_higher (addend
);
5168 else if (r_type
== R_MIPS_HIGHEST
)
5169 addend
= mips_elf_highest (addend
);
5172 if (rela_relocation_p
)
5173 /* If this is a RELA relocation, just update the addend.
5174 We have to cast away constness for REL. */
5175 rel
->r_addend
= addend
;
5178 /* Otherwise, we have to write the value back out. Note
5179 that we use the source mask, rather than the
5180 destination mask because the place to which we are
5181 writing will be source of the addend in the final
5183 addend
>>= howto
->rightshift
;
5184 addend
&= howto
->src_mask
;
5186 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
5187 /* See the comment above about using R_MIPS_64 in the 32-bit
5188 ABI. Here, we need to update the addend. It would be
5189 possible to get away with just using the R_MIPS_32 reloc
5190 but for endianness. */
5196 if (addend
& ((bfd_vma
) 1 << 31))
5198 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
5205 /* If we don't know that we have a 64-bit type,
5206 do two separate stores. */
5207 if (bfd_big_endian (input_bfd
))
5209 /* Store the sign-bits (which are most significant)
5211 low_bits
= sign_bits
;
5217 high_bits
= sign_bits
;
5219 bfd_put_32 (input_bfd
, low_bits
,
5220 contents
+ rel
->r_offset
);
5221 bfd_put_32 (input_bfd
, high_bits
,
5222 contents
+ rel
->r_offset
+ 4);
5226 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
5227 input_bfd
, input_section
,
5232 /* Go on to the next relocation. */
5236 /* In the N32 and 64-bit ABIs there may be multiple consecutive
5237 relocations for the same offset. In that case we are
5238 supposed to treat the output of each relocation as the addend
5240 if (rel
+ 1 < relend
5241 && rel
->r_offset
== rel
[1].r_offset
5242 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
5243 use_saved_addend_p
= true;
5245 use_saved_addend_p
= false;
5247 addend
>>= howto
->rightshift
;
5249 /* Figure out what value we are supposed to relocate. */
5250 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
5251 input_section
, info
, rel
,
5252 addend
, howto
, local_syms
,
5253 local_sections
, &value
,
5254 &name
, &require_jalx
))
5256 case bfd_reloc_continue
:
5257 /* There's nothing to do. */
5260 case bfd_reloc_undefined
:
5261 /* mips_elf_calculate_relocation already called the
5262 undefined_symbol callback. There's no real point in
5263 trying to perform the relocation at this point, so we
5264 just skip ahead to the next relocation. */
5267 case bfd_reloc_notsupported
:
5268 msg
= _("internal error: unsupported relocation error");
5269 info
->callbacks
->warning
5270 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
5273 case bfd_reloc_overflow
:
5274 if (use_saved_addend_p
)
5275 /* Ignore overflow until we reach the last relocation for
5276 a given location. */
5280 BFD_ASSERT (name
!= NULL
);
5281 if (! ((*info
->callbacks
->reloc_overflow
)
5282 (info
, name
, howto
->name
, (bfd_vma
) 0,
5283 input_bfd
, input_section
, rel
->r_offset
)))
5296 /* If we've got another relocation for the address, keep going
5297 until we reach the last one. */
5298 if (use_saved_addend_p
)
5304 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
5305 /* See the comment above about using R_MIPS_64 in the 32-bit
5306 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
5307 that calculated the right value. Now, however, we
5308 sign-extend the 32-bit result to 64-bits, and store it as a
5309 64-bit value. We are especially generous here in that we
5310 go to extreme lengths to support this usage on systems with
5311 only a 32-bit VMA. */
5317 if (value
& ((bfd_vma
) 1 << 31))
5319 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
5326 /* If we don't know that we have a 64-bit type,
5327 do two separate stores. */
5328 if (bfd_big_endian (input_bfd
))
5330 /* Undo what we did above. */
5332 /* Store the sign-bits (which are most significant)
5334 low_bits
= sign_bits
;
5340 high_bits
= sign_bits
;
5342 bfd_put_32 (input_bfd
, low_bits
,
5343 contents
+ rel
->r_offset
);
5344 bfd_put_32 (input_bfd
, high_bits
,
5345 contents
+ rel
->r_offset
+ 4);
5349 /* Actually perform the relocation. */
5350 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
5351 input_bfd
, input_section
,
5352 contents
, require_jalx
))
5359 /* If NAME is one of the special IRIX6 symbols defined by the linker,
5360 adjust it appropriately now. */
5363 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
5364 bfd
*abfd ATTRIBUTE_UNUSED
;
5366 Elf_Internal_Sym
*sym
;
5368 /* The linker script takes care of providing names and values for
5369 these, but we must place them into the right sections. */
5370 static const char* const text_section_symbols
[] = {
5373 "__dso_displacement",
5375 "__program_header_table",
5379 static const char* const data_section_symbols
[] = {
5387 const char* const *p
;
5390 for (i
= 0; i
< 2; ++i
)
5391 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
5394 if (strcmp (*p
, name
) == 0)
5396 /* All of these symbols are given type STT_SECTION by the
5398 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5400 /* The IRIX linker puts these symbols in special sections. */
5402 sym
->st_shndx
= SHN_MIPS_TEXT
;
5404 sym
->st_shndx
= SHN_MIPS_DATA
;
5410 /* Finish up dynamic symbol handling. We set the contents of various
5411 dynamic sections here. */
5414 _bfd_mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5416 struct bfd_link_info
*info
;
5417 struct elf_link_hash_entry
*h
;
5418 Elf_Internal_Sym
*sym
;
5424 struct mips_got_info
*g
;
5426 struct mips_elf_link_hash_entry
*mh
;
5428 dynobj
= elf_hash_table (info
)->dynobj
;
5429 gval
= sym
->st_value
;
5430 mh
= (struct mips_elf_link_hash_entry
*) h
;
5432 if (h
->plt
.offset
!= (bfd_vma
) -1)
5435 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5437 /* This symbol has a stub. Set it up. */
5439 BFD_ASSERT (h
->dynindx
!= -1);
5441 s
= bfd_get_section_by_name (dynobj
,
5442 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
5443 BFD_ASSERT (s
!= NULL
);
5445 /* FIXME: Can h->dynindex be more than 64K? */
5446 if (h
->dynindx
& 0xffff0000)
5449 /* Fill the stub. */
5450 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
);
5451 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ 4);
5452 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ 8);
5453 bfd_put_32 (output_bfd
, STUB_LI16 (output_bfd
) + h
->dynindx
, stub
+ 12);
5455 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
5456 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5458 /* Mark the symbol as undefined. plt.offset != -1 occurs
5459 only for the referenced symbol. */
5460 sym
->st_shndx
= SHN_UNDEF
;
5462 /* The run-time linker uses the st_value field of the symbol
5463 to reset the global offset table entry for this external
5464 to its stub address when unlinking a shared object. */
5465 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
5466 sym
->st_value
= gval
;
5469 BFD_ASSERT (h
->dynindx
!= -1
5470 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
5472 sgot
= mips_elf_got_section (dynobj
);
5473 BFD_ASSERT (sgot
!= NULL
);
5474 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5475 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5476 BFD_ASSERT (g
!= NULL
);
5478 /* Run through the global symbol table, creating GOT entries for all
5479 the symbols that need them. */
5480 if (g
->global_gotsym
!= NULL
5481 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
5487 value
= sym
->st_value
;
5490 /* For an entity defined in a shared object, this will be
5491 NULL. (For functions in shared objects for
5492 which we have created stubs, ST_VALUE will be non-NULL.
5493 That's because such the functions are now no longer defined
5494 in a shared object.) */
5496 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
5499 value
= h
->root
.u
.def
.value
;
5501 offset
= mips_elf_global_got_index (dynobj
, h
);
5502 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
5505 /* Create a .msym entry, if appropriate. */
5506 smsym
= bfd_get_section_by_name (dynobj
, ".msym");
5509 Elf32_Internal_Msym msym
;
5511 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
5512 /* It is undocumented what the `1' indicates, but IRIX6 uses
5514 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
5515 bfd_mips_elf_swap_msym_out
5517 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
5520 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5521 name
= h
->root
.root
.string
;
5522 if (strcmp (name
, "_DYNAMIC") == 0
5523 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5524 sym
->st_shndx
= SHN_ABS
;
5525 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
5526 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
5528 sym
->st_shndx
= SHN_ABS
;
5529 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5532 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
5534 sym
->st_shndx
= SHN_ABS
;
5535 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5536 sym
->st_value
= elf_gp (output_bfd
);
5538 else if (SGI_COMPAT (output_bfd
))
5540 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
5541 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
5543 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5544 sym
->st_other
= STO_PROTECTED
;
5546 sym
->st_shndx
= SHN_MIPS_DATA
;
5548 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
5550 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5551 sym
->st_other
= STO_PROTECTED
;
5552 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
5553 sym
->st_shndx
= SHN_ABS
;
5555 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
5557 if (h
->type
== STT_FUNC
)
5558 sym
->st_shndx
= SHN_MIPS_TEXT
;
5559 else if (h
->type
== STT_OBJECT
)
5560 sym
->st_shndx
= SHN_MIPS_DATA
;
5564 /* Handle the IRIX6-specific symbols. */
5565 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
5566 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
5570 if (! mips_elf_hash_table (info
)->use_rld_obj_head
5571 && (strcmp (name
, "__rld_map") == 0
5572 || strcmp (name
, "__RLD_MAP") == 0))
5574 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
5575 BFD_ASSERT (s
!= NULL
);
5576 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
5577 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
5578 if (mips_elf_hash_table (info
)->rld_value
== 0)
5579 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5581 else if (mips_elf_hash_table (info
)->use_rld_obj_head
5582 && strcmp (name
, "__rld_obj_head") == 0)
5584 /* IRIX6 does not use a .rld_map section. */
5585 if (IRIX_COMPAT (output_bfd
) == ict_irix5
5586 || IRIX_COMPAT (output_bfd
) == ict_none
)
5587 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
5589 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5593 /* If this is a mips16 symbol, force the value to be even. */
5594 if (sym
->st_other
== STO_MIPS16
5595 && (sym
->st_value
& 1) != 0)
5601 /* Finish up the dynamic sections. */
5604 _bfd_mips_elf_finish_dynamic_sections (output_bfd
, info
)
5606 struct bfd_link_info
*info
;
5611 struct mips_got_info
*g
;
5613 dynobj
= elf_hash_table (info
)->dynobj
;
5615 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5617 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5622 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5623 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5624 BFD_ASSERT (g
!= NULL
);
5627 if (elf_hash_table (info
)->dynamic_sections_created
)
5631 BFD_ASSERT (sdyn
!= NULL
);
5632 BFD_ASSERT (g
!= NULL
);
5634 for (b
= sdyn
->contents
;
5635 b
< sdyn
->contents
+ sdyn
->_raw_size
;
5636 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
5638 Elf_Internal_Dyn dyn
;
5644 /* Read in the current dynamic entry. */
5645 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
5647 /* Assume that we're going to modify it and write it out. */
5653 s
= (bfd_get_section_by_name (dynobj
, ".rel.dyn"));
5654 BFD_ASSERT (s
!= NULL
);
5655 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
5659 /* Rewrite DT_STRSZ. */
5661 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
5667 case DT_MIPS_CONFLICT
:
5670 case DT_MIPS_LIBLIST
:
5673 s
= bfd_get_section_by_name (output_bfd
, name
);
5674 BFD_ASSERT (s
!= NULL
);
5675 dyn
.d_un
.d_ptr
= s
->vma
;
5678 case DT_MIPS_RLD_VERSION
:
5679 dyn
.d_un
.d_val
= 1; /* XXX */
5683 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5686 case DT_MIPS_CONFLICTNO
:
5688 elemsize
= sizeof (Elf32_Conflict
);
5691 case DT_MIPS_LIBLISTNO
:
5693 elemsize
= sizeof (Elf32_Lib
);
5695 s
= bfd_get_section_by_name (output_bfd
, name
);
5698 if (s
->_cooked_size
!= 0)
5699 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5701 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5707 case DT_MIPS_TIME_STAMP
:
5708 time ((time_t *) &dyn
.d_un
.d_val
);
5711 case DT_MIPS_ICHECKSUM
:
5716 case DT_MIPS_IVERSION
:
5721 case DT_MIPS_BASE_ADDRESS
:
5722 s
= output_bfd
->sections
;
5723 BFD_ASSERT (s
!= NULL
);
5724 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
5727 case DT_MIPS_LOCAL_GOTNO
:
5728 dyn
.d_un
.d_val
= g
->local_gotno
;
5731 case DT_MIPS_UNREFEXTNO
:
5732 /* The index into the dynamic symbol table which is the
5733 entry of the first external symbol that is not
5734 referenced within the same object. */
5735 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
5738 case DT_MIPS_GOTSYM
:
5739 if (g
->global_gotsym
)
5741 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
5744 /* In case if we don't have global got symbols we default
5745 to setting DT_MIPS_GOTSYM to the same value as
5746 DT_MIPS_SYMTABNO, so we just fall through. */
5748 case DT_MIPS_SYMTABNO
:
5750 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
5751 s
= bfd_get_section_by_name (output_bfd
, name
);
5752 BFD_ASSERT (s
!= NULL
);
5754 if (s
->_cooked_size
!= 0)
5755 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5757 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5760 case DT_MIPS_HIPAGENO
:
5761 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
5764 case DT_MIPS_RLD_MAP
:
5765 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
5768 case DT_MIPS_OPTIONS
:
5769 s
= (bfd_get_section_by_name
5770 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
5771 dyn
.d_un
.d_ptr
= s
->vma
;
5775 s
= (bfd_get_section_by_name (output_bfd
, ".msym"));
5776 dyn
.d_un
.d_ptr
= s
->vma
;
5785 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
5790 /* The first entry of the global offset table will be filled at
5791 runtime. The second entry will be used by some runtime loaders.
5792 This isn't the case of IRIX rld. */
5793 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
5795 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5796 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
5797 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
5801 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
5802 = MIPS_ELF_GOT_SIZE (output_bfd
);
5807 Elf32_compact_rel cpt
;
5809 /* ??? The section symbols for the output sections were set up in
5810 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
5811 symbols. Should we do so? */
5813 smsym
= bfd_get_section_by_name (dynobj
, ".msym");
5816 Elf32_Internal_Msym msym
;
5818 msym
.ms_hash_value
= 0;
5819 msym
.ms_info
= ELF32_MS_INFO (0, 1);
5821 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
5823 long dynindx
= elf_section_data (s
)->dynindx
;
5825 bfd_mips_elf_swap_msym_out
5827 (((Elf32_External_Msym
*) smsym
->contents
)
5832 if (SGI_COMPAT (output_bfd
))
5834 /* Write .compact_rel section out. */
5835 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5839 cpt
.num
= s
->reloc_count
;
5841 cpt
.offset
= (s
->output_section
->filepos
5842 + sizeof (Elf32_External_compact_rel
));
5845 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
5846 ((Elf32_External_compact_rel
*)
5849 /* Clean up a dummy stub function entry in .text. */
5850 s
= bfd_get_section_by_name (dynobj
,
5851 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
5854 file_ptr dummy_offset
;
5856 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
5857 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
5858 memset (s
->contents
+ dummy_offset
, 0,
5859 MIPS_FUNCTION_STUB_SIZE
);
5864 /* We need to sort the entries of the dynamic relocation section. */
5866 if (!ABI_64_P (output_bfd
))
5870 reldyn
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5871 if (reldyn
!= NULL
&& reldyn
->reloc_count
> 2)
5873 reldyn_sorting_bfd
= output_bfd
;
5874 qsort ((Elf32_External_Rel
*) reldyn
->contents
+ 1,
5875 (size_t) reldyn
->reloc_count
- 1,
5876 sizeof (Elf32_External_Rel
), sort_dynamic_relocs
);
5880 /* Clean up a first relocation in .rel.dyn. */
5881 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5882 if (s
!= NULL
&& s
->_raw_size
> 0)
5883 memset (s
->contents
, 0, MIPS_ELF_REL_SIZE (dynobj
));
5889 /* The final processing done just before writing out a MIPS ELF object
5890 file. This gets the MIPS architecture right based on the machine
5891 number. This is used by both the 32-bit and the 64-bit ABI. */
5894 _bfd_mips_elf_final_write_processing (abfd
, linker
)
5896 boolean linker ATTRIBUTE_UNUSED
;
5900 Elf_Internal_Shdr
**hdrpp
;
5904 switch (bfd_get_mach (abfd
))
5907 case bfd_mach_mips3000
:
5908 val
= E_MIPS_ARCH_1
;
5911 case bfd_mach_mips3900
:
5912 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
5915 case bfd_mach_mips6000
:
5916 val
= E_MIPS_ARCH_2
;
5919 case bfd_mach_mips4000
:
5920 case bfd_mach_mips4300
:
5921 case bfd_mach_mips4400
:
5922 case bfd_mach_mips4600
:
5923 val
= E_MIPS_ARCH_3
;
5926 case bfd_mach_mips4010
:
5927 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
5930 case bfd_mach_mips4100
:
5931 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
5934 case bfd_mach_mips4111
:
5935 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
5938 case bfd_mach_mips4650
:
5939 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
5942 case bfd_mach_mips5000
:
5943 case bfd_mach_mips8000
:
5944 case bfd_mach_mips10000
:
5945 case bfd_mach_mips12000
:
5946 val
= E_MIPS_ARCH_4
;
5949 case bfd_mach_mips5
:
5950 val
= E_MIPS_ARCH_5
;
5953 case bfd_mach_mips_sb1
:
5954 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
5957 case bfd_mach_mipsisa32
:
5958 val
= E_MIPS_ARCH_32
;
5961 case bfd_mach_mipsisa64
:
5962 val
= E_MIPS_ARCH_64
;
5965 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
5966 elf_elfheader (abfd
)->e_flags
|= val
;
5968 /* Set the sh_info field for .gptab sections and other appropriate
5969 info for each special section. */
5970 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
5971 i
< elf_numsections (abfd
);
5974 switch ((*hdrpp
)->sh_type
)
5977 case SHT_MIPS_LIBLIST
:
5978 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
5980 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
5983 case SHT_MIPS_GPTAB
:
5984 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
5985 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
5986 BFD_ASSERT (name
!= NULL
5987 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
5988 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
5989 BFD_ASSERT (sec
!= NULL
);
5990 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
5993 case SHT_MIPS_CONTENT
:
5994 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
5995 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
5996 BFD_ASSERT (name
!= NULL
5997 && strncmp (name
, ".MIPS.content",
5998 sizeof ".MIPS.content" - 1) == 0);
5999 sec
= bfd_get_section_by_name (abfd
,
6000 name
+ sizeof ".MIPS.content" - 1);
6001 BFD_ASSERT (sec
!= NULL
);
6002 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6005 case SHT_MIPS_SYMBOL_LIB
:
6006 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
6008 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6009 sec
= bfd_get_section_by_name (abfd
, ".liblist");
6011 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
6014 case SHT_MIPS_EVENTS
:
6015 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
6016 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
6017 BFD_ASSERT (name
!= NULL
);
6018 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
6019 sec
= bfd_get_section_by_name (abfd
,
6020 name
+ sizeof ".MIPS.events" - 1);
6023 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
6024 sizeof ".MIPS.post_rel" - 1) == 0);
6025 sec
= bfd_get_section_by_name (abfd
,
6027 + sizeof ".MIPS.post_rel" - 1));
6029 BFD_ASSERT (sec
!= NULL
);
6030 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6037 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
6041 _bfd_mips_elf_additional_program_headers (abfd
)
6047 /* See if we need a PT_MIPS_REGINFO segment. */
6048 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6049 if (s
&& (s
->flags
& SEC_LOAD
))
6052 /* See if we need a PT_MIPS_OPTIONS segment. */
6053 if (IRIX_COMPAT (abfd
) == ict_irix6
6054 && bfd_get_section_by_name (abfd
,
6055 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
6058 /* See if we need a PT_MIPS_RTPROC segment. */
6059 if (IRIX_COMPAT (abfd
) == ict_irix5
6060 && bfd_get_section_by_name (abfd
, ".dynamic")
6061 && bfd_get_section_by_name (abfd
, ".mdebug"))
6067 /* Modify the segment map for an IRIX5 executable. */
6070 _bfd_mips_elf_modify_segment_map (abfd
)
6074 struct elf_segment_map
*m
, **pm
;
6077 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
6079 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6080 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
6082 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
6083 if (m
->p_type
== PT_MIPS_REGINFO
)
6088 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6092 m
->p_type
= PT_MIPS_REGINFO
;
6096 /* We want to put it after the PHDR and INTERP segments. */
6097 pm
= &elf_tdata (abfd
)->segment_map
;
6099 && ((*pm
)->p_type
== PT_PHDR
6100 || (*pm
)->p_type
== PT_INTERP
))
6108 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
6109 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
6110 PT_OPTIONS segment immediately following the program header
6112 if (NEWABI_P (abfd
))
6114 for (s
= abfd
->sections
; s
; s
= s
->next
)
6115 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
6120 struct elf_segment_map
*options_segment
;
6122 /* Usually, there's a program header table. But, sometimes
6123 there's not (like when running the `ld' testsuite). So,
6124 if there's no program header table, we just put the
6125 options segment at the end. */
6126 for (pm
= &elf_tdata (abfd
)->segment_map
;
6129 if ((*pm
)->p_type
== PT_PHDR
)
6132 amt
= sizeof (struct elf_segment_map
);
6133 options_segment
= bfd_zalloc (abfd
, amt
);
6134 options_segment
->next
= *pm
;
6135 options_segment
->p_type
= PT_MIPS_OPTIONS
;
6136 options_segment
->p_flags
= PF_R
;
6137 options_segment
->p_flags_valid
= true;
6138 options_segment
->count
= 1;
6139 options_segment
->sections
[0] = s
;
6140 *pm
= options_segment
;
6145 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6147 /* If there are .dynamic and .mdebug sections, we make a room
6148 for the RTPROC header. FIXME: Rewrite without section names. */
6149 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
6150 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
6151 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
6153 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
6154 if (m
->p_type
== PT_MIPS_RTPROC
)
6159 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6163 m
->p_type
= PT_MIPS_RTPROC
;
6165 s
= bfd_get_section_by_name (abfd
, ".rtproc");
6170 m
->p_flags_valid
= 1;
6178 /* We want to put it after the DYNAMIC segment. */
6179 pm
= &elf_tdata (abfd
)->segment_map
;
6180 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
6190 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
6191 .dynstr, .dynsym, and .hash sections, and everything in
6193 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
6195 if ((*pm
)->p_type
== PT_DYNAMIC
)
6198 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
6200 /* For a normal mips executable the permissions for the PT_DYNAMIC
6201 segment are read, write and execute. We do that here since
6202 the code in elf.c sets only the read permission. This matters
6203 sometimes for the dynamic linker. */
6204 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
6206 m
->p_flags
= PF_R
| PF_W
| PF_X
;
6207 m
->p_flags_valid
= 1;
6211 && m
->count
== 1 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
6213 static const char *sec_names
[] =
6215 ".dynamic", ".dynstr", ".dynsym", ".hash"
6219 struct elf_segment_map
*n
;
6223 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
6225 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
6226 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
6232 sz
= s
->_cooked_size
;
6235 if (high
< s
->vma
+ sz
)
6241 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
6242 if ((s
->flags
& SEC_LOAD
) != 0
6245 + (s
->_cooked_size
!=
6246 0 ? s
->_cooked_size
: s
->_raw_size
)) <= high
))
6249 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
6250 n
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6257 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
6259 if ((s
->flags
& SEC_LOAD
) != 0
6262 + (s
->_cooked_size
!= 0 ?
6263 s
->_cooked_size
: s
->_raw_size
)) <= high
))
6277 /* Return the section that should be marked against GC for a given
6281 _bfd_mips_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
6283 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
6284 Elf_Internal_Rela
*rel
;
6285 struct elf_link_hash_entry
*h
;
6286 Elf_Internal_Sym
*sym
;
6288 /* ??? Do mips16 stub sections need to be handled special? */
6292 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
6294 case R_MIPS_GNU_VTINHERIT
:
6295 case R_MIPS_GNU_VTENTRY
:
6299 switch (h
->root
.type
)
6301 case bfd_link_hash_defined
:
6302 case bfd_link_hash_defweak
:
6303 return h
->root
.u
.def
.section
;
6305 case bfd_link_hash_common
:
6306 return h
->root
.u
.c
.p
->section
;
6314 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6319 /* Update the got entry reference counts for the section being removed. */
6322 _bfd_mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6323 bfd
*abfd ATTRIBUTE_UNUSED
;
6324 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
6325 asection
*sec ATTRIBUTE_UNUSED
;
6326 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
6329 Elf_Internal_Shdr
*symtab_hdr
;
6330 struct elf_link_hash_entry
**sym_hashes
;
6331 bfd_signed_vma
*local_got_refcounts
;
6332 const Elf_Internal_Rela
*rel
, *relend
;
6333 unsigned long r_symndx
;
6334 struct elf_link_hash_entry
*h
;
6336 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6337 sym_hashes
= elf_sym_hashes (abfd
);
6338 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6340 relend
= relocs
+ sec
->reloc_count
;
6341 for (rel
= relocs
; rel
< relend
; rel
++)
6342 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
6346 case R_MIPS_CALL_HI16
:
6347 case R_MIPS_CALL_LO16
:
6348 case R_MIPS_GOT_HI16
:
6349 case R_MIPS_GOT_LO16
:
6350 case R_MIPS_GOT_DISP
:
6351 case R_MIPS_GOT_PAGE
:
6352 case R_MIPS_GOT_OFST
:
6353 /* ??? It would seem that the existing MIPS code does no sort
6354 of reference counting or whatnot on its GOT and PLT entries,
6355 so it is not possible to garbage collect them at this time. */
6366 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
6367 hiding the old indirect symbol. Process additional relocation
6368 information. Also called for weakdefs, in which case we just let
6369 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
6372 _bfd_mips_elf_copy_indirect_symbol (bed
, dir
, ind
)
6373 struct elf_backend_data
*bed
;
6374 struct elf_link_hash_entry
*dir
, *ind
;
6376 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
6378 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
6380 if (ind
->root
.type
!= bfd_link_hash_indirect
)
6383 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
6384 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
6385 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
6386 if (indmips
->readonly_reloc
)
6387 dirmips
->readonly_reloc
= true;
6388 if (dirmips
->min_dyn_reloc_index
== 0
6389 || (indmips
->min_dyn_reloc_index
!= 0
6390 && indmips
->min_dyn_reloc_index
< dirmips
->min_dyn_reloc_index
))
6391 dirmips
->min_dyn_reloc_index
= indmips
->min_dyn_reloc_index
;
6392 if (indmips
->no_fn_stub
)
6393 dirmips
->no_fn_stub
= true;
6397 _bfd_mips_elf_hide_symbol (info
, entry
, force_local
)
6398 struct bfd_link_info
*info
;
6399 struct elf_link_hash_entry
*entry
;
6400 boolean force_local
;
6404 struct mips_got_info
*g
;
6405 struct mips_elf_link_hash_entry
*h
;
6407 h
= (struct mips_elf_link_hash_entry
*) entry
;
6408 if (h
->forced_local
)
6410 h
->forced_local
= true;
6412 dynobj
= elf_hash_table (info
)->dynobj
;
6413 got
= bfd_get_section_by_name (dynobj
, ".got");
6414 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
6416 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
6418 /* FIXME: Do we allocate too much GOT space here? */
6420 got
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
6426 _bfd_mips_elf_discard_info (abfd
, cookie
, info
)
6428 struct elf_reloc_cookie
*cookie
;
6429 struct bfd_link_info
*info
;
6432 boolean ret
= false;
6433 unsigned char *tdata
;
6436 o
= bfd_get_section_by_name (abfd
, ".pdr");
6439 if (o
->_raw_size
== 0)
6441 if (o
->_raw_size
% PDR_SIZE
!= 0)
6443 if (o
->output_section
!= NULL
6444 && bfd_is_abs_section (o
->output_section
))
6447 tdata
= bfd_zmalloc (o
->_raw_size
/ PDR_SIZE
);
6451 cookie
->rels
= _bfd_elf32_link_read_relocs (abfd
, o
, (PTR
) NULL
,
6452 (Elf_Internal_Rela
*) NULL
,
6460 cookie
->rel
= cookie
->rels
;
6461 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
6463 for (i
= 0, skip
= 0; i
< o
->_raw_size
; i
++)
6465 if (_bfd_elf32_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
6474 elf_section_data (o
)->tdata
= tdata
;
6475 o
->_cooked_size
= o
->_raw_size
- skip
* PDR_SIZE
;
6481 if (! info
->keep_memory
)
6482 free (cookie
->rels
);
6488 _bfd_mips_elf_ignore_discarded_relocs (sec
)
6491 if (strcmp (sec
->name
, ".pdr") == 0)
6497 _bfd_mips_elf_write_section (output_bfd
, sec
, contents
)
6502 bfd_byte
*to
, *from
, *end
;
6505 if (strcmp (sec
->name
, ".pdr") != 0)
6508 if (elf_section_data (sec
)->tdata
== NULL
)
6512 end
= contents
+ sec
->_raw_size
;
6513 for (from
= contents
, i
= 0;
6515 from
+= PDR_SIZE
, i
++)
6517 if (((unsigned char *) elf_section_data (sec
)->tdata
)[i
] == 1)
6520 memcpy (to
, from
, PDR_SIZE
);
6523 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
6524 (file_ptr
) sec
->output_offset
,
6529 /* MIPS ELF uses a special find_nearest_line routine in order the
6530 handle the ECOFF debugging information. */
6532 struct mips_elf_find_line
6534 struct ecoff_debug_info d
;
6535 struct ecoff_find_line i
;
6539 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
6540 functionname_ptr
, line_ptr
)
6545 const char **filename_ptr
;
6546 const char **functionname_ptr
;
6547 unsigned int *line_ptr
;
6551 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
6552 filename_ptr
, functionname_ptr
,
6556 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
6557 filename_ptr
, functionname_ptr
,
6559 (unsigned) (ABI_64_P (abfd
) ? 8 : 0),
6560 &elf_tdata (abfd
)->dwarf2_find_line_info
))
6563 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
6567 struct mips_elf_find_line
*fi
;
6568 const struct ecoff_debug_swap
* const swap
=
6569 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
6571 /* If we are called during a link, mips_elf_final_link may have
6572 cleared the SEC_HAS_CONTENTS field. We force it back on here
6573 if appropriate (which it normally will be). */
6574 origflags
= msec
->flags
;
6575 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
6576 msec
->flags
|= SEC_HAS_CONTENTS
;
6578 fi
= elf_tdata (abfd
)->find_line_info
;
6581 bfd_size_type external_fdr_size
;
6584 struct fdr
*fdr_ptr
;
6585 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
6587 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
6590 msec
->flags
= origflags
;
6594 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
6596 msec
->flags
= origflags
;
6600 /* Swap in the FDR information. */
6601 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
6602 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
6603 if (fi
->d
.fdr
== NULL
)
6605 msec
->flags
= origflags
;
6608 external_fdr_size
= swap
->external_fdr_size
;
6609 fdr_ptr
= fi
->d
.fdr
;
6610 fraw_src
= (char *) fi
->d
.external_fdr
;
6611 fraw_end
= (fraw_src
6612 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
6613 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
6614 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
6616 elf_tdata (abfd
)->find_line_info
= fi
;
6618 /* Note that we don't bother to ever free this information.
6619 find_nearest_line is either called all the time, as in
6620 objdump -l, so the information should be saved, or it is
6621 rarely called, as in ld error messages, so the memory
6622 wasted is unimportant. Still, it would probably be a
6623 good idea for free_cached_info to throw it away. */
6626 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
6627 &fi
->i
, filename_ptr
, functionname_ptr
,
6630 msec
->flags
= origflags
;
6634 msec
->flags
= origflags
;
6637 /* Fall back on the generic ELF find_nearest_line routine. */
6639 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
6640 filename_ptr
, functionname_ptr
,
6644 /* When are writing out the .options or .MIPS.options section,
6645 remember the bytes we are writing out, so that we can install the
6646 GP value in the section_processing routine. */
6649 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
6654 bfd_size_type count
;
6656 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
6660 if (elf_section_data (section
) == NULL
)
6662 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
6663 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
6664 if (elf_section_data (section
) == NULL
)
6667 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
6672 if (section
->_cooked_size
!= 0)
6673 size
= section
->_cooked_size
;
6675 size
= section
->_raw_size
;
6676 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
6679 elf_section_data (section
)->tdata
= (PTR
) c
;
6682 memcpy (c
+ offset
, location
, (size_t) count
);
6685 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
6689 /* This is almost identical to bfd_generic_get_... except that some
6690 MIPS relocations need to be handled specially. Sigh. */
6693 _bfd_elf_mips_get_relocated_section_contents (abfd
, link_info
, link_order
,
6694 data
, relocateable
, symbols
)
6696 struct bfd_link_info
*link_info
;
6697 struct bfd_link_order
*link_order
;
6699 boolean relocateable
;
6702 /* Get enough memory to hold the stuff */
6703 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
6704 asection
*input_section
= link_order
->u
.indirect
.section
;
6706 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
6707 arelent
**reloc_vector
= NULL
;
6713 reloc_vector
= (arelent
**) bfd_malloc ((bfd_size_type
) reloc_size
);
6714 if (reloc_vector
== NULL
&& reloc_size
!= 0)
6717 /* read in the section */
6718 if (!bfd_get_section_contents (input_bfd
,
6722 input_section
->_raw_size
))
6725 /* We're not relaxing the section, so just copy the size info */
6726 input_section
->_cooked_size
= input_section
->_raw_size
;
6727 input_section
->reloc_done
= true;
6729 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
6733 if (reloc_count
< 0)
6736 if (reloc_count
> 0)
6741 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
6744 struct bfd_hash_entry
*h
;
6745 struct bfd_link_hash_entry
*lh
;
6746 /* Skip all this stuff if we aren't mixing formats. */
6747 if (abfd
&& input_bfd
6748 && abfd
->xvec
== input_bfd
->xvec
)
6752 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
6753 lh
= (struct bfd_link_hash_entry
*) h
;
6760 case bfd_link_hash_undefined
:
6761 case bfd_link_hash_undefweak
:
6762 case bfd_link_hash_common
:
6765 case bfd_link_hash_defined
:
6766 case bfd_link_hash_defweak
:
6768 gp
= lh
->u
.def
.value
;
6770 case bfd_link_hash_indirect
:
6771 case bfd_link_hash_warning
:
6773 /* @@FIXME ignoring warning for now */
6775 case bfd_link_hash_new
:
6784 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
6787 char *error_message
= (char *) NULL
;
6788 bfd_reloc_status_type r
;
6790 /* Specific to MIPS: Deal with relocation types that require
6791 knowing the gp of the output bfd. */
6792 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
6793 if (bfd_is_abs_section (sym
->section
) && abfd
)
6795 /* The special_function wouldn't get called anyway. */
6799 /* The gp isn't there; let the special function code
6800 fall over on its own. */
6802 else if ((*parent
)->howto
->special_function
6803 == _bfd_mips_elf32_gprel16_reloc
)
6805 /* bypass special_function call */
6806 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
6807 input_section
, relocateable
,
6809 goto skip_bfd_perform_relocation
;
6811 /* end mips specific stuff */
6813 r
= bfd_perform_relocation (input_bfd
,
6817 relocateable
? abfd
: (bfd
*) NULL
,
6819 skip_bfd_perform_relocation
:
6823 asection
*os
= input_section
->output_section
;
6825 /* A partial link, so keep the relocs */
6826 os
->orelocation
[os
->reloc_count
] = *parent
;
6830 if (r
!= bfd_reloc_ok
)
6834 case bfd_reloc_undefined
:
6835 if (!((*link_info
->callbacks
->undefined_symbol
)
6836 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6837 input_bfd
, input_section
, (*parent
)->address
,
6841 case bfd_reloc_dangerous
:
6842 BFD_ASSERT (error_message
!= (char *) NULL
);
6843 if (!((*link_info
->callbacks
->reloc_dangerous
)
6844 (link_info
, error_message
, input_bfd
, input_section
,
6845 (*parent
)->address
)))
6848 case bfd_reloc_overflow
:
6849 if (!((*link_info
->callbacks
->reloc_overflow
)
6850 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6851 (*parent
)->howto
->name
, (*parent
)->addend
,
6852 input_bfd
, input_section
, (*parent
)->address
)))
6855 case bfd_reloc_outofrange
:
6864 if (reloc_vector
!= NULL
)
6865 free (reloc_vector
);
6869 if (reloc_vector
!= NULL
)
6870 free (reloc_vector
);
6874 /* Create a MIPS ELF linker hash table. */
6876 struct bfd_link_hash_table
*
6877 _bfd_mips_elf_link_hash_table_create (abfd
)
6880 struct mips_elf_link_hash_table
*ret
;
6881 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
6883 ret
= (struct mips_elf_link_hash_table
*) bfd_malloc (amt
);
6884 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
6887 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
6888 mips_elf_link_hash_newfunc
))
6895 /* We no longer use this. */
6896 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
6897 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
6899 ret
->procedure_count
= 0;
6900 ret
->compact_rel_size
= 0;
6901 ret
->use_rld_obj_head
= false;
6903 ret
->mips16_stubs_seen
= false;
6905 return &ret
->root
.root
;
6908 /* We need to use a special link routine to handle the .reginfo and
6909 the .mdebug sections. We need to merge all instances of these
6910 sections together, not write them all out sequentially. */
6913 _bfd_mips_elf_final_link (abfd
, info
)
6915 struct bfd_link_info
*info
;
6919 struct bfd_link_order
*p
;
6920 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
6921 asection
*rtproc_sec
;
6922 Elf32_RegInfo reginfo
;
6923 struct ecoff_debug_info debug
;
6924 const struct ecoff_debug_swap
*swap
6925 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
6926 HDRR
*symhdr
= &debug
.symbolic_header
;
6927 PTR mdebug_handle
= NULL
;
6933 static const char * const secname
[] =
6935 ".text", ".init", ".fini", ".data",
6936 ".rodata", ".sdata", ".sbss", ".bss"
6938 static const int sc
[] =
6940 scText
, scInit
, scFini
, scData
,
6941 scRData
, scSData
, scSBss
, scBss
6944 /* If all the things we linked together were PIC, but we're
6945 producing an executable (rather than a shared object), then the
6946 resulting file is CPIC (i.e., it calls PIC code.) */
6948 && !info
->relocateable
6949 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
6951 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
6952 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
6955 /* We'd carefully arranged the dynamic symbol indices, and then the
6956 generic size_dynamic_sections renumbered them out from under us.
6957 Rather than trying somehow to prevent the renumbering, just do
6959 if (elf_hash_table (info
)->dynamic_sections_created
)
6963 struct mips_got_info
*g
;
6965 /* When we resort, we must tell mips_elf_sort_hash_table what
6966 the lowest index it may use is. That's the number of section
6967 symbols we're going to add. The generic ELF linker only
6968 adds these symbols when building a shared object. Note that
6969 we count the sections after (possibly) removing the .options
6971 if (! mips_elf_sort_hash_table (info
, (info
->shared
6972 ? bfd_count_sections (abfd
) + 1
6976 /* Make sure we didn't grow the global .got region. */
6977 dynobj
= elf_hash_table (info
)->dynobj
;
6978 got
= bfd_get_section_by_name (dynobj
, ".got");
6979 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
6981 if (g
->global_gotsym
!= NULL
)
6982 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
6983 - g
->global_gotsym
->dynindx
)
6984 <= g
->global_gotno
);
6988 /* We want to set the GP value for ld -r. */
6989 /* On IRIX5, we omit the .options section. On IRIX6, however, we
6990 include it, even though we don't process it quite right. (Some
6991 entries are supposed to be merged.) Empirically, we seem to be
6992 better off including it then not. */
6993 if (IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
6994 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
6996 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
6998 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
6999 if (p
->type
== bfd_indirect_link_order
)
7000 p
->u
.indirect
.section
->flags
&= ~SEC_HAS_CONTENTS
;
7001 (*secpp
)->link_order_head
= NULL
;
7002 bfd_section_list_remove (abfd
, secpp
);
7003 --abfd
->section_count
;
7009 /* We include .MIPS.options, even though we don't process it quite right.
7010 (Some entries are supposed to be merged.) At IRIX6 empirically we seem
7011 to be better off including it than not. */
7012 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
7014 if (strcmp ((*secpp
)->name
, ".MIPS.options") == 0)
7016 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
7017 if (p
->type
== bfd_indirect_link_order
)
7018 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
7019 (*secpp
)->link_order_head
= NULL
;
7020 bfd_section_list_remove (abfd
, secpp
);
7021 --abfd
->section_count
;
7028 /* Get a value for the GP register. */
7029 if (elf_gp (abfd
) == 0)
7031 struct bfd_link_hash_entry
*h
;
7033 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
7034 if (h
!= (struct bfd_link_hash_entry
*) NULL
7035 && h
->type
== bfd_link_hash_defined
)
7036 elf_gp (abfd
) = (h
->u
.def
.value
7037 + h
->u
.def
.section
->output_section
->vma
7038 + h
->u
.def
.section
->output_offset
);
7039 else if (info
->relocateable
)
7041 bfd_vma lo
= MINUS_ONE
;
7043 /* Find the GP-relative section with the lowest offset. */
7044 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
7046 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
7049 /* And calculate GP relative to that. */
7050 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
7054 /* If the relocate_section function needs to do a reloc
7055 involving the GP value, it should make a reloc_dangerous
7056 callback to warn that GP is not defined. */
7060 /* Go through the sections and collect the .reginfo and .mdebug
7064 gptab_data_sec
= NULL
;
7065 gptab_bss_sec
= NULL
;
7066 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
7068 if (strcmp (o
->name
, ".reginfo") == 0)
7070 memset (®info
, 0, sizeof reginfo
);
7072 /* We have found the .reginfo section in the output file.
7073 Look through all the link_orders comprising it and merge
7074 the information together. */
7075 for (p
= o
->link_order_head
;
7076 p
!= (struct bfd_link_order
*) NULL
;
7079 asection
*input_section
;
7081 Elf32_External_RegInfo ext
;
7084 if (p
->type
!= bfd_indirect_link_order
)
7086 if (p
->type
== bfd_data_link_order
)
7091 input_section
= p
->u
.indirect
.section
;
7092 input_bfd
= input_section
->owner
;
7094 /* The linker emulation code has probably clobbered the
7095 size to be zero bytes. */
7096 if (input_section
->_raw_size
== 0)
7097 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
7099 if (! bfd_get_section_contents (input_bfd
, input_section
,
7102 (bfd_size_type
) sizeof ext
))
7105 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
7107 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
7108 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
7109 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
7110 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
7111 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
7113 /* ri_gp_value is set by the function
7114 mips_elf32_section_processing when the section is
7115 finally written out. */
7117 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7118 elf_link_input_bfd ignores this section. */
7119 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7122 /* Size has been set in _bfd_mips_elf_always_size_sections. */
7123 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
7125 /* Skip this section later on (I don't think this currently
7126 matters, but someday it might). */
7127 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7132 if (strcmp (o
->name
, ".mdebug") == 0)
7134 struct extsym_info einfo
;
7137 /* We have found the .mdebug section in the output file.
7138 Look through all the link_orders comprising it and merge
7139 the information together. */
7140 symhdr
->magic
= swap
->sym_magic
;
7141 /* FIXME: What should the version stamp be? */
7143 symhdr
->ilineMax
= 0;
7147 symhdr
->isymMax
= 0;
7148 symhdr
->ioptMax
= 0;
7149 symhdr
->iauxMax
= 0;
7151 symhdr
->issExtMax
= 0;
7154 symhdr
->iextMax
= 0;
7156 /* We accumulate the debugging information itself in the
7157 debug_info structure. */
7159 debug
.external_dnr
= NULL
;
7160 debug
.external_pdr
= NULL
;
7161 debug
.external_sym
= NULL
;
7162 debug
.external_opt
= NULL
;
7163 debug
.external_aux
= NULL
;
7165 debug
.ssext
= debug
.ssext_end
= NULL
;
7166 debug
.external_fdr
= NULL
;
7167 debug
.external_rfd
= NULL
;
7168 debug
.external_ext
= debug
.external_ext_end
= NULL
;
7170 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
7171 if (mdebug_handle
== (PTR
) NULL
)
7175 esym
.cobol_main
= 0;
7179 esym
.asym
.iss
= issNil
;
7180 esym
.asym
.st
= stLocal
;
7181 esym
.asym
.reserved
= 0;
7182 esym
.asym
.index
= indexNil
;
7184 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
7186 esym
.asym
.sc
= sc
[i
];
7187 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
7190 esym
.asym
.value
= s
->vma
;
7191 last
= s
->vma
+ s
->_raw_size
;
7194 esym
.asym
.value
= last
;
7195 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
7200 for (p
= o
->link_order_head
;
7201 p
!= (struct bfd_link_order
*) NULL
;
7204 asection
*input_section
;
7206 const struct ecoff_debug_swap
*input_swap
;
7207 struct ecoff_debug_info input_debug
;
7211 if (p
->type
!= bfd_indirect_link_order
)
7213 if (p
->type
== bfd_data_link_order
)
7218 input_section
= p
->u
.indirect
.section
;
7219 input_bfd
= input_section
->owner
;
7221 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
7222 || (get_elf_backend_data (input_bfd
)
7223 ->elf_backend_ecoff_debug_swap
) == NULL
)
7225 /* I don't know what a non MIPS ELF bfd would be
7226 doing with a .mdebug section, but I don't really
7227 want to deal with it. */
7231 input_swap
= (get_elf_backend_data (input_bfd
)
7232 ->elf_backend_ecoff_debug_swap
);
7234 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
7236 /* The ECOFF linking code expects that we have already
7237 read in the debugging information and set up an
7238 ecoff_debug_info structure, so we do that now. */
7239 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
7243 if (! (bfd_ecoff_debug_accumulate
7244 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
7245 &input_debug
, input_swap
, info
)))
7248 /* Loop through the external symbols. For each one with
7249 interesting information, try to find the symbol in
7250 the linker global hash table and save the information
7251 for the output external symbols. */
7252 eraw_src
= input_debug
.external_ext
;
7253 eraw_end
= (eraw_src
7254 + (input_debug
.symbolic_header
.iextMax
7255 * input_swap
->external_ext_size
));
7257 eraw_src
< eraw_end
;
7258 eraw_src
+= input_swap
->external_ext_size
)
7262 struct mips_elf_link_hash_entry
*h
;
7264 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
7265 if (ext
.asym
.sc
== scNil
7266 || ext
.asym
.sc
== scUndefined
7267 || ext
.asym
.sc
== scSUndefined
)
7270 name
= input_debug
.ssext
+ ext
.asym
.iss
;
7271 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
7272 name
, false, false, true);
7273 if (h
== NULL
|| h
->esym
.ifd
!= -2)
7279 < input_debug
.symbolic_header
.ifdMax
);
7280 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
7286 /* Free up the information we just read. */
7287 free (input_debug
.line
);
7288 free (input_debug
.external_dnr
);
7289 free (input_debug
.external_pdr
);
7290 free (input_debug
.external_sym
);
7291 free (input_debug
.external_opt
);
7292 free (input_debug
.external_aux
);
7293 free (input_debug
.ss
);
7294 free (input_debug
.ssext
);
7295 free (input_debug
.external_fdr
);
7296 free (input_debug
.external_rfd
);
7297 free (input_debug
.external_ext
);
7299 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7300 elf_link_input_bfd ignores this section. */
7301 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7304 if (SGI_COMPAT (abfd
) && info
->shared
)
7306 /* Create .rtproc section. */
7307 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
7308 if (rtproc_sec
== NULL
)
7310 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7311 | SEC_LINKER_CREATED
| SEC_READONLY
);
7313 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
7314 if (rtproc_sec
== NULL
7315 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
7316 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
7320 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
7326 /* Build the external symbol information. */
7329 einfo
.debug
= &debug
;
7331 einfo
.failed
= false;
7332 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7333 mips_elf_output_extsym
,
7338 /* Set the size of the .mdebug section. */
7339 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
7341 /* Skip this section later on (I don't think this currently
7342 matters, but someday it might). */
7343 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7348 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
7350 const char *subname
;
7353 Elf32_External_gptab
*ext_tab
;
7356 /* The .gptab.sdata and .gptab.sbss sections hold
7357 information describing how the small data area would
7358 change depending upon the -G switch. These sections
7359 not used in executables files. */
7360 if (! info
->relocateable
)
7362 for (p
= o
->link_order_head
;
7363 p
!= (struct bfd_link_order
*) NULL
;
7366 asection
*input_section
;
7368 if (p
->type
!= bfd_indirect_link_order
)
7370 if (p
->type
== bfd_data_link_order
)
7375 input_section
= p
->u
.indirect
.section
;
7377 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7378 elf_link_input_bfd ignores this section. */
7379 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7382 /* Skip this section later on (I don't think this
7383 currently matters, but someday it might). */
7384 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7386 /* Really remove the section. */
7387 for (secpp
= &abfd
->sections
;
7389 secpp
= &(*secpp
)->next
)
7391 bfd_section_list_remove (abfd
, secpp
);
7392 --abfd
->section_count
;
7397 /* There is one gptab for initialized data, and one for
7398 uninitialized data. */
7399 if (strcmp (o
->name
, ".gptab.sdata") == 0)
7401 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
7405 (*_bfd_error_handler
)
7406 (_("%s: illegal section name `%s'"),
7407 bfd_get_filename (abfd
), o
->name
);
7408 bfd_set_error (bfd_error_nonrepresentable_section
);
7412 /* The linker script always combines .gptab.data and
7413 .gptab.sdata into .gptab.sdata, and likewise for
7414 .gptab.bss and .gptab.sbss. It is possible that there is
7415 no .sdata or .sbss section in the output file, in which
7416 case we must change the name of the output section. */
7417 subname
= o
->name
+ sizeof ".gptab" - 1;
7418 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
7420 if (o
== gptab_data_sec
)
7421 o
->name
= ".gptab.data";
7423 o
->name
= ".gptab.bss";
7424 subname
= o
->name
+ sizeof ".gptab" - 1;
7425 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
7428 /* Set up the first entry. */
7430 amt
= c
* sizeof (Elf32_gptab
);
7431 tab
= (Elf32_gptab
*) bfd_malloc (amt
);
7434 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
7435 tab
[0].gt_header
.gt_unused
= 0;
7437 /* Combine the input sections. */
7438 for (p
= o
->link_order_head
;
7439 p
!= (struct bfd_link_order
*) NULL
;
7442 asection
*input_section
;
7446 bfd_size_type gpentry
;
7448 if (p
->type
!= bfd_indirect_link_order
)
7450 if (p
->type
== bfd_data_link_order
)
7455 input_section
= p
->u
.indirect
.section
;
7456 input_bfd
= input_section
->owner
;
7458 /* Combine the gptab entries for this input section one
7459 by one. We know that the input gptab entries are
7460 sorted by ascending -G value. */
7461 size
= bfd_section_size (input_bfd
, input_section
);
7463 for (gpentry
= sizeof (Elf32_External_gptab
);
7465 gpentry
+= sizeof (Elf32_External_gptab
))
7467 Elf32_External_gptab ext_gptab
;
7468 Elf32_gptab int_gptab
;
7474 if (! (bfd_get_section_contents
7475 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
7477 (bfd_size_type
) sizeof (Elf32_External_gptab
))))
7483 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
7485 val
= int_gptab
.gt_entry
.gt_g_value
;
7486 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
7489 for (look
= 1; look
< c
; look
++)
7491 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
7492 tab
[look
].gt_entry
.gt_bytes
+= add
;
7494 if (tab
[look
].gt_entry
.gt_g_value
== val
)
7500 Elf32_gptab
*new_tab
;
7503 /* We need a new table entry. */
7504 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
7505 new_tab
= (Elf32_gptab
*) bfd_realloc ((PTR
) tab
, amt
);
7506 if (new_tab
== NULL
)
7512 tab
[c
].gt_entry
.gt_g_value
= val
;
7513 tab
[c
].gt_entry
.gt_bytes
= add
;
7515 /* Merge in the size for the next smallest -G
7516 value, since that will be implied by this new
7519 for (look
= 1; look
< c
; look
++)
7521 if (tab
[look
].gt_entry
.gt_g_value
< val
7523 || (tab
[look
].gt_entry
.gt_g_value
7524 > tab
[max
].gt_entry
.gt_g_value
)))
7528 tab
[c
].gt_entry
.gt_bytes
+=
7529 tab
[max
].gt_entry
.gt_bytes
;
7534 last
= int_gptab
.gt_entry
.gt_bytes
;
7537 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7538 elf_link_input_bfd ignores this section. */
7539 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7542 /* The table must be sorted by -G value. */
7544 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
7546 /* Swap out the table. */
7547 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
7548 ext_tab
= (Elf32_External_gptab
*) bfd_alloc (abfd
, amt
);
7549 if (ext_tab
== NULL
)
7555 for (j
= 0; j
< c
; j
++)
7556 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
7559 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
7560 o
->contents
= (bfd_byte
*) ext_tab
;
7562 /* Skip this section later on (I don't think this currently
7563 matters, but someday it might). */
7564 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7568 /* Invoke the regular ELF backend linker to do all the work. */
7569 if (ABI_64_P (abfd
))
7572 if (!bfd_elf64_bfd_final_link (abfd
, info
))
7579 else if (!bfd_elf32_bfd_final_link (abfd
, info
))
7582 /* Now write out the computed sections. */
7584 if (reginfo_sec
!= (asection
*) NULL
)
7586 Elf32_External_RegInfo ext
;
7588 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
7589 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
7591 (bfd_size_type
) sizeof ext
))
7595 if (mdebug_sec
!= (asection
*) NULL
)
7597 BFD_ASSERT (abfd
->output_has_begun
);
7598 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
7600 mdebug_sec
->filepos
))
7603 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
7606 if (gptab_data_sec
!= (asection
*) NULL
)
7608 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
7609 gptab_data_sec
->contents
,
7611 gptab_data_sec
->_raw_size
))
7615 if (gptab_bss_sec
!= (asection
*) NULL
)
7617 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
7618 gptab_bss_sec
->contents
,
7620 gptab_bss_sec
->_raw_size
))
7624 if (SGI_COMPAT (abfd
))
7626 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
7627 if (rtproc_sec
!= NULL
)
7629 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
7630 rtproc_sec
->contents
,
7632 rtproc_sec
->_raw_size
))
7640 /* Merge backend specific data from an object file to the output
7641 object file when linking. */
7644 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
7651 boolean null_input_bfd
= true;
7654 /* Check if we have the same endianess */
7655 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
7658 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
7659 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
7662 new_flags
= elf_elfheader (ibfd
)->e_flags
;
7663 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
7664 old_flags
= elf_elfheader (obfd
)->e_flags
;
7666 if (! elf_flags_init (obfd
))
7668 elf_flags_init (obfd
) = true;
7669 elf_elfheader (obfd
)->e_flags
= new_flags
;
7670 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
7671 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
7673 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
7674 && bfd_get_arch_info (obfd
)->the_default
)
7676 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
7677 bfd_get_mach (ibfd
)))
7684 /* Check flag compatibility. */
7686 new_flags
&= ~EF_MIPS_NOREORDER
;
7687 old_flags
&= ~EF_MIPS_NOREORDER
;
7689 if (new_flags
== old_flags
)
7692 /* Check to see if the input BFD actually contains any sections.
7693 If not, its flags may not have been initialised either, but it cannot
7694 actually cause any incompatibility. */
7695 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7697 /* Ignore synthetic sections and empty .text, .data and .bss sections
7698 which are automatically generated by gas. */
7699 if (strcmp (sec
->name
, ".reginfo")
7700 && strcmp (sec
->name
, ".mdebug")
7701 && ((!strcmp (sec
->name
, ".text")
7702 || !strcmp (sec
->name
, ".data")
7703 || !strcmp (sec
->name
, ".bss"))
7704 && sec
->_raw_size
!= 0))
7706 null_input_bfd
= false;
7715 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
7717 new_flags
&= ~EF_MIPS_PIC
;
7718 old_flags
&= ~EF_MIPS_PIC
;
7719 (*_bfd_error_handler
)
7720 (_("%s: linking PIC files with non-PIC files"),
7721 bfd_archive_filename (ibfd
));
7725 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
7727 new_flags
&= ~EF_MIPS_CPIC
;
7728 old_flags
&= ~EF_MIPS_CPIC
;
7729 (*_bfd_error_handler
)
7730 (_("%s: linking abicalls files with non-abicalls files"),
7731 bfd_archive_filename (ibfd
));
7735 /* Compare the ISA's. */
7736 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
7737 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
7739 int new_mach
= new_flags
& EF_MIPS_MACH
;
7740 int old_mach
= old_flags
& EF_MIPS_MACH
;
7741 int new_isa
= elf_mips_isa (new_flags
);
7742 int old_isa
= elf_mips_isa (old_flags
);
7744 /* If either has no machine specified, just compare the general isa's.
7745 Some combinations of machines are ok, if the isa's match. */
7748 || new_mach
== old_mach
7751 /* Don't warn about mixing code using 32-bit ISAs, or mixing code
7752 using 64-bit ISAs. They will normally use the same data sizes
7753 and calling conventions. */
7755 if (( (new_isa
== 1 || new_isa
== 2 || new_isa
== 32)
7756 ^ (old_isa
== 1 || old_isa
== 2 || old_isa
== 32)) != 0)
7758 (*_bfd_error_handler
)
7759 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
7760 bfd_archive_filename (ibfd
), new_isa
, old_isa
);
7765 /* Do we need to update the mach field? */
7766 if (old_mach
== 0 && new_mach
!= 0)
7767 elf_elfheader (obfd
)->e_flags
|= new_mach
;
7769 /* Do we need to update the ISA field? */
7770 if (new_isa
> old_isa
)
7772 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_ARCH
;
7773 elf_elfheader (obfd
)->e_flags
7774 |= new_flags
& EF_MIPS_ARCH
;
7780 (*_bfd_error_handler
)
7781 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
7782 bfd_archive_filename (ibfd
),
7783 _bfd_elf_mips_mach (new_flags
),
7784 _bfd_elf_mips_mach (old_flags
));
7788 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
7789 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
7792 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
7793 does set EI_CLASS differently from any 32-bit ABI. */
7794 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
7795 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
7796 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
7798 /* Only error if both are set (to different values). */
7799 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
7800 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
7801 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
7803 (*_bfd_error_handler
)
7804 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
7805 bfd_archive_filename (ibfd
),
7806 elf_mips_abi_name (ibfd
),
7807 elf_mips_abi_name (obfd
));
7810 new_flags
&= ~EF_MIPS_ABI
;
7811 old_flags
&= ~EF_MIPS_ABI
;
7814 /* For now, allow arbitrary mixing of ASEs (retain the union). */
7815 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
7817 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
7819 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
7820 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
7823 /* Warn about any other mismatches */
7824 if (new_flags
!= old_flags
)
7826 (*_bfd_error_handler
)
7827 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
7828 bfd_archive_filename (ibfd
), (unsigned long) new_flags
,
7829 (unsigned long) old_flags
);
7835 bfd_set_error (bfd_error_bad_value
);
7842 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
7845 _bfd_mips_elf_set_private_flags (abfd
, flags
)
7849 BFD_ASSERT (!elf_flags_init (abfd
)
7850 || elf_elfheader (abfd
)->e_flags
== flags
);
7852 elf_elfheader (abfd
)->e_flags
= flags
;
7853 elf_flags_init (abfd
) = true;
7858 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
7862 FILE *file
= (FILE *) ptr
;
7864 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
7866 /* Print normal ELF private data. */
7867 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
7869 /* xgettext:c-format */
7870 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
7872 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
7873 fprintf (file
, _(" [abi=O32]"));
7874 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
7875 fprintf (file
, _(" [abi=O64]"));
7876 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
7877 fprintf (file
, _(" [abi=EABI32]"));
7878 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
7879 fprintf (file
, _(" [abi=EABI64]"));
7880 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
7881 fprintf (file
, _(" [abi unknown]"));
7882 else if (ABI_N32_P (abfd
))
7883 fprintf (file
, _(" [abi=N32]"));
7884 else if (ABI_64_P (abfd
))
7885 fprintf (file
, _(" [abi=64]"));
7887 fprintf (file
, _(" [no abi set]"));
7889 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
7890 fprintf (file
, _(" [mips1]"));
7891 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
7892 fprintf (file
, _(" [mips2]"));
7893 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
7894 fprintf (file
, _(" [mips3]"));
7895 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
7896 fprintf (file
, _(" [mips4]"));
7897 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
7898 fprintf (file
, _(" [mips5]"));
7899 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
7900 fprintf (file
, _(" [mips32]"));
7901 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
7902 fprintf (file
, _(" [mips64]"));
7904 fprintf (file
, _(" [unknown ISA]"));
7906 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
7907 fprintf (file
, _(" [mdmx]"));
7909 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
7910 fprintf (file
, _(" [mips16]"));
7912 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
7913 fprintf (file
, _(" [32bitmode]"));
7915 fprintf (file
, _(" [not 32bitmode]"));