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 64-bit ABI. */
377 #define ABI_64_P(abfd) \
378 ((get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64) != 0)
380 #define IRIX_COMPAT(abfd) \
381 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
383 #define NEWABI_P(abfd) (ABI_N32_P(abfd) || ABI_64_P(abfd))
385 /* Whether we are trying to be compatible with IRIX at all. */
386 #define SGI_COMPAT(abfd) \
387 (IRIX_COMPAT (abfd) != ict_none)
389 /* The name of the options section. */
390 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
391 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options")
393 /* The name of the stub section. */
394 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \
395 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub")
397 /* The size of an external REL relocation. */
398 #define MIPS_ELF_REL_SIZE(abfd) \
399 (get_elf_backend_data (abfd)->s->sizeof_rel)
401 /* The size of an external dynamic table entry. */
402 #define MIPS_ELF_DYN_SIZE(abfd) \
403 (get_elf_backend_data (abfd)->s->sizeof_dyn)
405 /* The size of a GOT entry. */
406 #define MIPS_ELF_GOT_SIZE(abfd) \
407 (get_elf_backend_data (abfd)->s->arch_size / 8)
409 /* The size of a symbol-table entry. */
410 #define MIPS_ELF_SYM_SIZE(abfd) \
411 (get_elf_backend_data (abfd)->s->sizeof_sym)
413 /* The default alignment for sections, as a power of two. */
414 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
415 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2)
417 /* Get word-sized data. */
418 #define MIPS_ELF_GET_WORD(abfd, ptr) \
419 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
421 /* Put out word-sized data. */
422 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
424 ? bfd_put_64 (abfd, val, ptr) \
425 : bfd_put_32 (abfd, val, ptr))
427 /* Add a dynamic symbol table-entry. */
429 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
430 (ABI_64_P (elf_hash_table (info)->dynobj) \
431 ? bfd_elf64_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val) \
432 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
434 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
435 (ABI_64_P (elf_hash_table (info)->dynobj) \
436 ? (boolean) (abort (), false) \
437 : bfd_elf32_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
440 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
441 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
443 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
444 from smaller values. Start with zero, widen, *then* decrement. */
445 #define MINUS_ONE (((bfd_vma)0) - 1)
447 /* The number of local .got entries we reserve. */
448 #define MIPS_RESERVED_GOTNO (2)
450 /* Instructions which appear in a stub. For some reason the stub is
451 slightly different on an SGI system. */
452 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
453 #define STUB_LW(abfd) \
456 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
457 : 0x8f998010) /* lw t9,0x8010(gp) */ \
458 : 0x8f998010) /* lw t9,0x8000(gp) */
459 #define STUB_MOVE(abfd) \
460 (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */
461 #define STUB_JALR 0x0320f809 /* jal t9 */
462 #define STUB_LI16(abfd) \
463 (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */
464 #define MIPS_FUNCTION_STUB_SIZE (16)
466 /* The name of the dynamic interpreter. This is put in the .interp
469 #define ELF_DYNAMIC_INTERPRETER(abfd) \
470 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
471 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
472 : "/usr/lib/libc.so.1")
475 #define ELF_R_SYM(bfd, i) \
476 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
477 #define ELF_R_TYPE(bfd, i) \
478 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
479 #define ELF_R_INFO(bfd, s, t) \
480 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
482 #define ELF_R_SYM(bfd, i) \
484 #define ELF_R_TYPE(bfd, i) \
486 #define ELF_R_INFO(bfd, s, t) \
487 (ELF32_R_INFO (s, t))
490 /* The mips16 compiler uses a couple of special sections to handle
491 floating point arguments.
493 Section names that look like .mips16.fn.FNNAME contain stubs that
494 copy floating point arguments from the fp regs to the gp regs and
495 then jump to FNNAME. If any 32 bit function calls FNNAME, the
496 call should be redirected to the stub instead. If no 32 bit
497 function calls FNNAME, the stub should be discarded. We need to
498 consider any reference to the function, not just a call, because
499 if the address of the function is taken we will need the stub,
500 since the address might be passed to a 32 bit function.
502 Section names that look like .mips16.call.FNNAME contain stubs
503 that copy floating point arguments from the gp regs to the fp
504 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
505 then any 16 bit function that calls FNNAME should be redirected
506 to the stub instead. If FNNAME is not a 32 bit function, the
507 stub should be discarded.
509 .mips16.call.fp.FNNAME sections are similar, but contain stubs
510 which call FNNAME and then copy the return value from the fp regs
511 to the gp regs. These stubs store the return value in $18 while
512 calling FNNAME; any function which might call one of these stubs
513 must arrange to save $18 around the call. (This case is not
514 needed for 32 bit functions that call 16 bit functions, because
515 16 bit functions always return floating point values in both
518 Note that in all cases FNNAME might be defined statically.
519 Therefore, FNNAME is not used literally. Instead, the relocation
520 information will indicate which symbol the section is for.
522 We record any stubs that we find in the symbol table. */
524 #define FN_STUB ".mips16.fn."
525 #define CALL_STUB ".mips16.call."
526 #define CALL_FP_STUB ".mips16.call.fp."
528 /* Look up an entry in a MIPS ELF linker hash table. */
530 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
531 ((struct mips_elf_link_hash_entry *) \
532 elf_link_hash_lookup (&(table)->root, (string), (create), \
535 /* Traverse a MIPS ELF linker hash table. */
537 #define mips_elf_link_hash_traverse(table, func, info) \
538 (elf_link_hash_traverse \
540 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
543 /* Get the MIPS ELF linker hash table from a link_info structure. */
545 #define mips_elf_hash_table(p) \
546 ((struct mips_elf_link_hash_table *) ((p)->hash))
548 /* Create an entry in a MIPS ELF linker hash table. */
550 static struct bfd_hash_entry
*
551 mips_elf_link_hash_newfunc (entry
, table
, string
)
552 struct bfd_hash_entry
*entry
;
553 struct bfd_hash_table
*table
;
556 struct mips_elf_link_hash_entry
*ret
=
557 (struct mips_elf_link_hash_entry
*) entry
;
559 /* Allocate the structure if it has not already been allocated by a
561 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
562 ret
= ((struct mips_elf_link_hash_entry
*)
563 bfd_hash_allocate (table
,
564 sizeof (struct mips_elf_link_hash_entry
)));
565 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
566 return (struct bfd_hash_entry
*) ret
;
568 /* Call the allocation method of the superclass. */
569 ret
= ((struct mips_elf_link_hash_entry
*)
570 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
572 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
574 /* Set local fields. */
575 memset (&ret
->esym
, 0, sizeof (EXTR
));
576 /* We use -2 as a marker to indicate that the information has
577 not been set. -1 means there is no associated ifd. */
579 ret
->possibly_dynamic_relocs
= 0;
580 ret
->readonly_reloc
= false;
581 ret
->min_dyn_reloc_index
= 0;
582 ret
->no_fn_stub
= false;
584 ret
->need_fn_stub
= false;
585 ret
->call_stub
= NULL
;
586 ret
->call_fp_stub
= NULL
;
587 ret
->forced_local
= false;
590 return (struct bfd_hash_entry
*) ret
;
593 /* Read ECOFF debugging information from a .mdebug section into a
594 ecoff_debug_info structure. */
597 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
600 struct ecoff_debug_info
*debug
;
603 const struct ecoff_debug_swap
*swap
;
604 char *ext_hdr
= NULL
;
606 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
607 memset (debug
, 0, sizeof (*debug
));
609 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
610 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
613 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
614 swap
->external_hdr_size
))
617 symhdr
= &debug
->symbolic_header
;
618 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
620 /* The symbolic header contains absolute file offsets and sizes to
622 #define READ(ptr, offset, count, size, type) \
623 if (symhdr->count == 0) \
627 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
628 debug->ptr = (type) bfd_malloc (amt); \
629 if (debug->ptr == NULL) \
631 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
632 || bfd_bread (debug->ptr, amt, abfd) != amt) \
636 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
637 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
638 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
639 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
640 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
641 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
643 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
644 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
645 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
646 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
647 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
651 debug
->adjust
= NULL
;
658 if (debug
->line
!= NULL
)
660 if (debug
->external_dnr
!= NULL
)
661 free (debug
->external_dnr
);
662 if (debug
->external_pdr
!= NULL
)
663 free (debug
->external_pdr
);
664 if (debug
->external_sym
!= NULL
)
665 free (debug
->external_sym
);
666 if (debug
->external_opt
!= NULL
)
667 free (debug
->external_opt
);
668 if (debug
->external_aux
!= NULL
)
669 free (debug
->external_aux
);
670 if (debug
->ss
!= NULL
)
672 if (debug
->ssext
!= NULL
)
674 if (debug
->external_fdr
!= NULL
)
675 free (debug
->external_fdr
);
676 if (debug
->external_rfd
!= NULL
)
677 free (debug
->external_rfd
);
678 if (debug
->external_ext
!= NULL
)
679 free (debug
->external_ext
);
683 /* Swap RPDR (runtime procedure table entry) for output. */
686 ecoff_swap_rpdr_out (abfd
, in
, ex
)
691 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
692 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
693 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
694 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
695 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
696 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
698 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
699 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
701 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
703 H_PUT_S32 (abfd
, in
->exception_info
, ex
->p_exception_info
);
707 /* Create a runtime procedure table from the .mdebug section. */
710 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
713 struct bfd_link_info
*info
;
715 struct ecoff_debug_info
*debug
;
717 const struct ecoff_debug_swap
*swap
;
718 HDRR
*hdr
= &debug
->symbolic_header
;
720 struct rpdr_ext
*erp
;
722 struct pdr_ext
*epdr
;
723 struct sym_ext
*esym
;
728 unsigned long sindex
;
732 const char *no_name_func
= _("static procedure (no name)");
740 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
742 sindex
= strlen (no_name_func
) + 1;
746 size
= swap
->external_pdr_size
;
748 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
752 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
755 size
= sizeof (RPDR
);
756 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
760 size
= sizeof (char *);
761 sv
= (char **) bfd_malloc (size
* count
);
765 count
= hdr
->isymMax
;
766 size
= swap
->external_sym_size
;
767 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
771 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
775 ss
= (char *) bfd_malloc (count
);
778 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
782 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
784 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
785 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
787 rp
->regmask
= pdr
.regmask
;
788 rp
->regoffset
= pdr
.regoffset
;
789 rp
->fregmask
= pdr
.fregmask
;
790 rp
->fregoffset
= pdr
.fregoffset
;
791 rp
->frameoffset
= pdr
.frameoffset
;
792 rp
->framereg
= pdr
.framereg
;
793 rp
->pcreg
= pdr
.pcreg
;
795 sv
[i
] = ss
+ sym
.iss
;
796 sindex
+= strlen (sv
[i
]) + 1;
800 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
801 size
= BFD_ALIGN (size
, 16);
802 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
805 mips_elf_hash_table (info
)->procedure_count
= 0;
809 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
811 erp
= (struct rpdr_ext
*) rtproc
;
812 memset (erp
, 0, sizeof (struct rpdr_ext
));
814 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
815 strcpy (str
, no_name_func
);
816 str
+= strlen (no_name_func
) + 1;
817 for (i
= 0; i
< count
; i
++)
819 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
821 str
+= strlen (sv
[i
]) + 1;
823 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
825 /* Set the size and contents of .rtproc section. */
827 s
->contents
= (bfd_byte
*) rtproc
;
829 /* Skip this section later on (I don't think this currently
830 matters, but someday it might). */
831 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
860 /* Check the mips16 stubs for a particular symbol, and see if we can
864 mips_elf_check_mips16_stubs (h
, data
)
865 struct mips_elf_link_hash_entry
*h
;
866 PTR data ATTRIBUTE_UNUSED
;
868 if (h
->root
.root
.type
== bfd_link_hash_warning
)
869 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
871 if (h
->fn_stub
!= NULL
872 && ! h
->need_fn_stub
)
874 /* We don't need the fn_stub; the only references to this symbol
875 are 16 bit calls. Clobber the size to 0 to prevent it from
876 being included in the link. */
877 h
->fn_stub
->_raw_size
= 0;
878 h
->fn_stub
->_cooked_size
= 0;
879 h
->fn_stub
->flags
&= ~SEC_RELOC
;
880 h
->fn_stub
->reloc_count
= 0;
881 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
884 if (h
->call_stub
!= NULL
885 && h
->root
.other
== STO_MIPS16
)
887 /* We don't need the call_stub; this is a 16 bit function, so
888 calls from other 16 bit functions are OK. Clobber the size
889 to 0 to prevent it from being included in the link. */
890 h
->call_stub
->_raw_size
= 0;
891 h
->call_stub
->_cooked_size
= 0;
892 h
->call_stub
->flags
&= ~SEC_RELOC
;
893 h
->call_stub
->reloc_count
= 0;
894 h
->call_stub
->flags
|= SEC_EXCLUDE
;
897 if (h
->call_fp_stub
!= NULL
898 && h
->root
.other
== STO_MIPS16
)
900 /* We don't need the call_stub; this is a 16 bit function, so
901 calls from other 16 bit functions are OK. Clobber the size
902 to 0 to prevent it from being included in the link. */
903 h
->call_fp_stub
->_raw_size
= 0;
904 h
->call_fp_stub
->_cooked_size
= 0;
905 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
906 h
->call_fp_stub
->reloc_count
= 0;
907 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
913 bfd_reloc_status_type
914 _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
915 relocateable
, data
, gp
)
918 arelent
*reloc_entry
;
919 asection
*input_section
;
920 boolean relocateable
;
928 if (bfd_is_com_section (symbol
->section
))
931 relocation
= symbol
->value
;
933 relocation
+= symbol
->section
->output_section
->vma
;
934 relocation
+= symbol
->section
->output_offset
;
936 if (reloc_entry
->address
> input_section
->_cooked_size
)
937 return bfd_reloc_outofrange
;
939 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
941 /* Set val to the offset into the section or symbol. */
942 if (reloc_entry
->howto
->src_mask
== 0)
944 /* This case occurs with the 64-bit MIPS ELF ABI. */
945 val
= reloc_entry
->addend
;
949 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
954 /* Adjust val for the final section location and GP value. If we
955 are producing relocateable output, we don't want to do this for
956 an external symbol. */
958 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
959 val
+= relocation
- gp
;
961 insn
= (insn
& ~0xffff) | (val
& 0xffff);
962 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
965 reloc_entry
->address
+= input_section
->output_offset
;
967 else if ((long) val
>= 0x8000 || (long) val
< -0x8000)
968 return bfd_reloc_overflow
;
973 /* Swap an entry in a .gptab section. Note that these routines rely
974 on the equivalence of the two elements of the union. */
977 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
979 const Elf32_External_gptab
*ex
;
982 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
983 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
987 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
989 const Elf32_gptab
*in
;
990 Elf32_External_gptab
*ex
;
992 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
993 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
997 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
999 const Elf32_compact_rel
*in
;
1000 Elf32_External_compact_rel
*ex
;
1002 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
1003 H_PUT_32 (abfd
, in
->num
, ex
->num
);
1004 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
1005 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
1006 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
1007 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
1011 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1013 const Elf32_crinfo
*in
;
1014 Elf32_External_crinfo
*ex
;
1018 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1019 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1020 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1021 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1022 H_PUT_32 (abfd
, l
, ex
->info
);
1023 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
1024 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
1028 /* Swap in an MSYM entry. */
1031 bfd_mips_elf_swap_msym_in (abfd
, ex
, in
)
1033 const Elf32_External_Msym
*ex
;
1034 Elf32_Internal_Msym
*in
;
1036 in
->ms_hash_value
= H_GET_32 (abfd
, ex
->ms_hash_value
);
1037 in
->ms_info
= H_GET_32 (abfd
, ex
->ms_info
);
1040 /* Swap out an MSYM entry. */
1043 bfd_mips_elf_swap_msym_out (abfd
, in
, ex
)
1045 const Elf32_Internal_Msym
*in
;
1046 Elf32_External_Msym
*ex
;
1048 H_PUT_32 (abfd
, in
->ms_hash_value
, ex
->ms_hash_value
);
1049 H_PUT_32 (abfd
, in
->ms_info
, ex
->ms_info
);
1052 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1053 routines swap this structure in and out. They are used outside of
1054 BFD, so they are globally visible. */
1057 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1059 const Elf32_External_RegInfo
*ex
;
1062 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1063 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1064 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1065 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1066 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1067 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
1071 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1073 const Elf32_RegInfo
*in
;
1074 Elf32_External_RegInfo
*ex
;
1076 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1077 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1078 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1079 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1080 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1081 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1084 /* In the 64 bit ABI, the .MIPS.options section holds register
1085 information in an Elf64_Reginfo structure. These routines swap
1086 them in and out. They are globally visible because they are used
1087 outside of BFD. These routines are here so that gas can call them
1088 without worrying about whether the 64 bit ABI has been included. */
1091 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1093 const Elf64_External_RegInfo
*ex
;
1094 Elf64_Internal_RegInfo
*in
;
1096 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
1097 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
1098 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
1099 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
1100 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
1101 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
1102 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
1106 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1108 const Elf64_Internal_RegInfo
*in
;
1109 Elf64_External_RegInfo
*ex
;
1111 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
1112 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
1113 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
1114 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
1115 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
1116 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
1117 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
1120 /* Swap in an options header. */
1123 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1125 const Elf_External_Options
*ex
;
1126 Elf_Internal_Options
*in
;
1128 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
1129 in
->size
= H_GET_8 (abfd
, ex
->size
);
1130 in
->section
= H_GET_16 (abfd
, ex
->section
);
1131 in
->info
= H_GET_32 (abfd
, ex
->info
);
1134 /* Swap out an options header. */
1137 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1139 const Elf_Internal_Options
*in
;
1140 Elf_External_Options
*ex
;
1142 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
1143 H_PUT_8 (abfd
, in
->size
, ex
->size
);
1144 H_PUT_16 (abfd
, in
->section
, ex
->section
);
1145 H_PUT_32 (abfd
, in
->info
, ex
->info
);
1148 /* This function is called via qsort() to sort the dynamic relocation
1149 entries by increasing r_symndx value. */
1152 sort_dynamic_relocs (arg1
, arg2
)
1156 const Elf32_External_Rel
*ext_reloc1
= (const Elf32_External_Rel
*) arg1
;
1157 const Elf32_External_Rel
*ext_reloc2
= (const Elf32_External_Rel
*) arg2
;
1159 Elf_Internal_Rel int_reloc1
;
1160 Elf_Internal_Rel int_reloc2
;
1162 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, ext_reloc1
, &int_reloc1
);
1163 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, ext_reloc2
, &int_reloc2
);
1165 return (ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
));
1168 /* This routine is used to write out ECOFF debugging external symbol
1169 information. It is called via mips_elf_link_hash_traverse. The
1170 ECOFF external symbol information must match the ELF external
1171 symbol information. Unfortunately, at this point we don't know
1172 whether a symbol is required by reloc information, so the two
1173 tables may wind up being different. We must sort out the external
1174 symbol information before we can set the final size of the .mdebug
1175 section, and we must set the size of the .mdebug section before we
1176 can relocate any sections, and we can't know which symbols are
1177 required by relocation until we relocate the sections.
1178 Fortunately, it is relatively unlikely that any symbol will be
1179 stripped but required by a reloc. In particular, it can not happen
1180 when generating a final executable. */
1183 mips_elf_output_extsym (h
, data
)
1184 struct mips_elf_link_hash_entry
*h
;
1187 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
1189 asection
*sec
, *output_section
;
1191 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1192 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1194 if (h
->root
.indx
== -2)
1196 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1197 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
1198 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
1199 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
1201 else if (einfo
->info
->strip
== strip_all
1202 || (einfo
->info
->strip
== strip_some
1203 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1204 h
->root
.root
.root
.string
,
1205 false, false) == NULL
))
1213 if (h
->esym
.ifd
== -2)
1216 h
->esym
.cobol_main
= 0;
1217 h
->esym
.weakext
= 0;
1218 h
->esym
.reserved
= 0;
1219 h
->esym
.ifd
= ifdNil
;
1220 h
->esym
.asym
.value
= 0;
1221 h
->esym
.asym
.st
= stGlobal
;
1223 if (h
->root
.root
.type
== bfd_link_hash_undefined
1224 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
1228 /* Use undefined class. Also, set class and type for some
1230 name
= h
->root
.root
.root
.string
;
1231 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
1232 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
1234 h
->esym
.asym
.sc
= scData
;
1235 h
->esym
.asym
.st
= stLabel
;
1236 h
->esym
.asym
.value
= 0;
1238 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
1240 h
->esym
.asym
.sc
= scAbs
;
1241 h
->esym
.asym
.st
= stLabel
;
1242 h
->esym
.asym
.value
=
1243 mips_elf_hash_table (einfo
->info
)->procedure_count
;
1245 else if (strcmp (name
, "_gp_disp") == 0)
1247 h
->esym
.asym
.sc
= scAbs
;
1248 h
->esym
.asym
.st
= stLabel
;
1249 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
1252 h
->esym
.asym
.sc
= scUndefined
;
1254 else if (h
->root
.root
.type
!= bfd_link_hash_defined
1255 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1256 h
->esym
.asym
.sc
= scAbs
;
1261 sec
= h
->root
.root
.u
.def
.section
;
1262 output_section
= sec
->output_section
;
1264 /* When making a shared library and symbol h is the one from
1265 the another shared library, OUTPUT_SECTION may be null. */
1266 if (output_section
== NULL
)
1267 h
->esym
.asym
.sc
= scUndefined
;
1270 name
= bfd_section_name (output_section
->owner
, output_section
);
1272 if (strcmp (name
, ".text") == 0)
1273 h
->esym
.asym
.sc
= scText
;
1274 else if (strcmp (name
, ".data") == 0)
1275 h
->esym
.asym
.sc
= scData
;
1276 else if (strcmp (name
, ".sdata") == 0)
1277 h
->esym
.asym
.sc
= scSData
;
1278 else if (strcmp (name
, ".rodata") == 0
1279 || strcmp (name
, ".rdata") == 0)
1280 h
->esym
.asym
.sc
= scRData
;
1281 else if (strcmp (name
, ".bss") == 0)
1282 h
->esym
.asym
.sc
= scBss
;
1283 else if (strcmp (name
, ".sbss") == 0)
1284 h
->esym
.asym
.sc
= scSBss
;
1285 else if (strcmp (name
, ".init") == 0)
1286 h
->esym
.asym
.sc
= scInit
;
1287 else if (strcmp (name
, ".fini") == 0)
1288 h
->esym
.asym
.sc
= scFini
;
1290 h
->esym
.asym
.sc
= scAbs
;
1294 h
->esym
.asym
.reserved
= 0;
1295 h
->esym
.asym
.index
= indexNil
;
1298 if (h
->root
.root
.type
== bfd_link_hash_common
)
1299 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1300 else if (h
->root
.root
.type
== bfd_link_hash_defined
1301 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1303 if (h
->esym
.asym
.sc
== scCommon
)
1304 h
->esym
.asym
.sc
= scBss
;
1305 else if (h
->esym
.asym
.sc
== scSCommon
)
1306 h
->esym
.asym
.sc
= scSBss
;
1308 sec
= h
->root
.root
.u
.def
.section
;
1309 output_section
= sec
->output_section
;
1310 if (output_section
!= NULL
)
1311 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1312 + sec
->output_offset
1313 + output_section
->vma
);
1315 h
->esym
.asym
.value
= 0;
1317 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1319 struct mips_elf_link_hash_entry
*hd
= h
;
1320 boolean no_fn_stub
= h
->no_fn_stub
;
1322 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
1324 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
1325 no_fn_stub
= no_fn_stub
|| hd
->no_fn_stub
;
1330 /* Set type and value for a symbol with a function stub. */
1331 h
->esym
.asym
.st
= stProc
;
1332 sec
= hd
->root
.root
.u
.def
.section
;
1334 h
->esym
.asym
.value
= 0;
1337 output_section
= sec
->output_section
;
1338 if (output_section
!= NULL
)
1339 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
1340 + sec
->output_offset
1341 + output_section
->vma
);
1343 h
->esym
.asym
.value
= 0;
1351 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1352 h
->root
.root
.root
.string
,
1355 einfo
->failed
= true;
1362 /* A comparison routine used to sort .gptab entries. */
1365 gptab_compare (p1
, p2
)
1369 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
1370 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
1372 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
1375 /* Returns the GOT section for ABFD. */
1378 mips_elf_got_section (abfd
)
1381 return bfd_get_section_by_name (abfd
, ".got");
1384 /* Returns the GOT information associated with the link indicated by
1385 INFO. If SGOTP is non-NULL, it is filled in with the GOT
1388 static struct mips_got_info
*
1389 mips_elf_got_info (abfd
, sgotp
)
1394 struct mips_got_info
*g
;
1396 sgot
= mips_elf_got_section (abfd
);
1397 BFD_ASSERT (sgot
!= NULL
);
1398 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
1399 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
1400 BFD_ASSERT (g
!= NULL
);
1407 /* Returns the GOT offset at which the indicated address can be found.
1408 If there is not yet a GOT entry for this value, create one. Returns
1409 -1 if no satisfactory GOT offset can be found. */
1412 mips_elf_local_got_index (abfd
, info
, value
)
1414 struct bfd_link_info
*info
;
1418 struct mips_got_info
*g
;
1421 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1423 /* Look to see if we already have an appropriate entry. */
1424 for (entry
= (sgot
->contents
1425 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
1426 entry
!= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
1427 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
1429 bfd_vma address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1430 if (address
== value
)
1431 return entry
- sgot
->contents
;
1434 return mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1437 /* Returns the GOT index for the global symbol indicated by H. */
1440 mips_elf_global_got_index (abfd
, h
)
1442 struct elf_link_hash_entry
*h
;
1446 struct mips_got_info
*g
;
1448 g
= mips_elf_got_info (abfd
, &sgot
);
1450 /* Once we determine the global GOT entry with the lowest dynamic
1451 symbol table index, we must put all dynamic symbols with greater
1452 indices into the GOT. That makes it easy to calculate the GOT
1454 BFD_ASSERT (h
->dynindx
>= g
->global_gotsym
->dynindx
);
1455 index
= ((h
->dynindx
- g
->global_gotsym
->dynindx
+ g
->local_gotno
)
1456 * MIPS_ELF_GOT_SIZE (abfd
));
1457 BFD_ASSERT (index
< sgot
->_raw_size
);
1462 /* Find a GOT entry that is within 32KB of the VALUE. These entries
1463 are supposed to be placed at small offsets in the GOT, i.e.,
1464 within 32KB of GP. Return the index into the GOT for this page,
1465 and store the offset from this entry to the desired address in
1466 OFFSETP, if it is non-NULL. */
1469 mips_elf_got_page (abfd
, info
, value
, offsetp
)
1471 struct bfd_link_info
*info
;
1476 struct mips_got_info
*g
;
1478 bfd_byte
*last_entry
;
1482 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1484 /* Look to see if we aleady have an appropriate entry. */
1485 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
1486 for (entry
= (sgot
->contents
1487 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
1488 entry
!= last_entry
;
1489 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
1491 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1493 if (!mips_elf_overflow_p (value
- address
, 16))
1495 /* This entry will serve as the page pointer. We can add a
1496 16-bit number to it to get the actual address. */
1497 index
= entry
- sgot
->contents
;
1502 /* If we didn't have an appropriate entry, we create one now. */
1503 if (entry
== last_entry
)
1504 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1508 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1509 *offsetp
= value
- address
;
1515 /* Find a GOT entry whose higher-order 16 bits are the same as those
1516 for value. Return the index into the GOT for this entry. */
1519 mips_elf_got16_entry (abfd
, info
, value
, external
)
1521 struct bfd_link_info
*info
;
1526 struct mips_got_info
*g
;
1528 bfd_byte
*last_entry
;
1534 /* Although the ABI says that it is "the high-order 16 bits" that we
1535 want, it is really the %high value. The complete value is
1536 calculated with a `addiu' of a LO16 relocation, just as with a
1538 value
= mips_elf_high (value
) << 16;
1541 g
= mips_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1543 /* Look to see if we already have an appropriate entry. */
1544 last_entry
= sgot
->contents
+ MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
;
1545 for (entry
= (sgot
->contents
1546 + MIPS_ELF_GOT_SIZE (abfd
) * MIPS_RESERVED_GOTNO
);
1547 entry
!= last_entry
;
1548 entry
+= MIPS_ELF_GOT_SIZE (abfd
))
1550 address
= MIPS_ELF_GET_WORD (abfd
, entry
);
1551 if (address
== value
)
1553 /* This entry has the right high-order 16 bits, and the low-order
1554 16 bits are set to zero. */
1555 index
= entry
- sgot
->contents
;
1560 /* If we didn't have an appropriate entry, we create one now. */
1561 if (entry
== last_entry
)
1562 index
= mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
);
1567 /* Returns the offset for the entry at the INDEXth position
1571 mips_elf_got_offset_from_index (dynobj
, output_bfd
, index
)
1579 sgot
= mips_elf_got_section (dynobj
);
1580 gp
= _bfd_get_gp_value (output_bfd
);
1581 return (sgot
->output_section
->vma
+ sgot
->output_offset
+ index
-
1585 /* Create a local GOT entry for VALUE. Return the index of the entry,
1586 or -1 if it could not be created. */
1589 mips_elf_create_local_got_entry (abfd
, g
, sgot
, value
)
1591 struct mips_got_info
*g
;
1595 if (g
->assigned_gotno
>= g
->local_gotno
)
1597 /* We didn't allocate enough space in the GOT. */
1598 (*_bfd_error_handler
)
1599 (_("not enough GOT space for local GOT entries"));
1600 bfd_set_error (bfd_error_bad_value
);
1601 return (bfd_vma
) -1;
1604 MIPS_ELF_PUT_WORD (abfd
, value
,
1606 + MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
));
1607 return MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
1610 /* Sort the dynamic symbol table so that symbols that need GOT entries
1611 appear towards the end. This reduces the amount of GOT space
1612 required. MAX_LOCAL is used to set the number of local symbols
1613 known to be in the dynamic symbol table. During
1614 _bfd_mips_elf_size_dynamic_sections, this value is 1. Afterward, the
1615 section symbols are added and the count is higher. */
1618 mips_elf_sort_hash_table (info
, max_local
)
1619 struct bfd_link_info
*info
;
1620 unsigned long max_local
;
1622 struct mips_elf_hash_sort_data hsd
;
1623 struct mips_got_info
*g
;
1626 dynobj
= elf_hash_table (info
)->dynobj
;
1629 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
;
1630 hsd
.max_non_got_dynindx
= max_local
;
1631 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
1632 elf_hash_table (info
)),
1633 mips_elf_sort_hash_table_f
,
1636 /* There should have been enough room in the symbol table to
1637 accomodate both the GOT and non-GOT symbols. */
1638 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
1640 /* Now we know which dynamic symbol has the lowest dynamic symbol
1641 table index in the GOT. */
1642 g
= mips_elf_got_info (dynobj
, NULL
);
1643 g
->global_gotsym
= hsd
.low
;
1648 /* If H needs a GOT entry, assign it the highest available dynamic
1649 index. Otherwise, assign it the lowest available dynamic
1653 mips_elf_sort_hash_table_f (h
, data
)
1654 struct mips_elf_link_hash_entry
*h
;
1657 struct mips_elf_hash_sort_data
*hsd
1658 = (struct mips_elf_hash_sort_data
*) data
;
1660 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1661 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1663 /* Symbols without dynamic symbol table entries aren't interesting
1665 if (h
->root
.dynindx
== -1)
1668 if (h
->root
.got
.offset
!= 1)
1669 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
1672 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
1673 hsd
->low
= (struct elf_link_hash_entry
*) h
;
1679 /* If H is a symbol that needs a global GOT entry, but has a dynamic
1680 symbol table index lower than any we've seen to date, record it for
1684 mips_elf_record_global_got_symbol (h
, info
, g
)
1685 struct elf_link_hash_entry
*h
;
1686 struct bfd_link_info
*info
;
1687 struct mips_got_info
*g ATTRIBUTE_UNUSED
;
1689 /* A global symbol in the GOT must also be in the dynamic symbol
1691 if (h
->dynindx
== -1)
1693 switch (ELF_ST_VISIBILITY (h
->other
))
1697 _bfd_mips_elf_hide_symbol (info
, h
, true);
1700 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
1704 /* If we've already marked this entry as needing GOT space, we don't
1705 need to do it again. */
1706 if (h
->got
.offset
!= MINUS_ONE
)
1709 /* By setting this to a value other than -1, we are indicating that
1710 there needs to be a GOT entry for H. Avoid using zero, as the
1711 generic ELF copy_indirect_symbol tests for <= 0. */
1717 /* Returns the first relocation of type r_type found, beginning with
1718 RELOCATION. RELEND is one-past-the-end of the relocation table. */
1720 static const Elf_Internal_Rela
*
1721 mips_elf_next_relocation (abfd
, r_type
, relocation
, relend
)
1722 bfd
*abfd ATTRIBUTE_UNUSED
;
1723 unsigned int r_type
;
1724 const Elf_Internal_Rela
*relocation
;
1725 const Elf_Internal_Rela
*relend
;
1727 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be
1728 immediately following. However, for the IRIX6 ABI, the next
1729 relocation may be a composed relocation consisting of several
1730 relocations for the same address. In that case, the R_MIPS_LO16
1731 relocation may occur as one of these. We permit a similar
1732 extension in general, as that is useful for GCC. */
1733 while (relocation
< relend
)
1735 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
)
1741 /* We didn't find it. */
1742 bfd_set_error (bfd_error_bad_value
);
1746 /* Return whether a relocation is against a local symbol. */
1749 mips_elf_local_relocation_p (input_bfd
, relocation
, local_sections
,
1752 const Elf_Internal_Rela
*relocation
;
1753 asection
**local_sections
;
1754 boolean check_forced
;
1756 unsigned long r_symndx
;
1757 Elf_Internal_Shdr
*symtab_hdr
;
1758 struct mips_elf_link_hash_entry
*h
;
1761 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
1762 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1763 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
1765 if (r_symndx
< extsymoff
)
1767 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
1772 /* Look up the hash table to check whether the symbol
1773 was forced local. */
1774 h
= (struct mips_elf_link_hash_entry
*)
1775 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
1776 /* Find the real hash-table entry for this symbol. */
1777 while (h
->root
.root
.type
== bfd_link_hash_indirect
1778 || h
->root
.root
.type
== bfd_link_hash_warning
)
1779 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1780 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
1787 /* Sign-extend VALUE, which has the indicated number of BITS. */
1790 mips_elf_sign_extend (value
, bits
)
1794 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
1795 /* VALUE is negative. */
1796 value
|= ((bfd_vma
) - 1) << bits
;
1801 /* Return non-zero if the indicated VALUE has overflowed the maximum
1802 range expressable by a signed number with the indicated number of
1806 mips_elf_overflow_p (value
, bits
)
1810 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
1812 if (svalue
> (1 << (bits
- 1)) - 1)
1813 /* The value is too big. */
1815 else if (svalue
< -(1 << (bits
- 1)))
1816 /* The value is too small. */
1823 /* Calculate the %high function. */
1826 mips_elf_high (value
)
1829 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
1832 /* Calculate the %higher function. */
1835 mips_elf_higher (value
)
1836 bfd_vma value ATTRIBUTE_UNUSED
;
1839 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
1842 return (bfd_vma
) -1;
1846 /* Calculate the %highest function. */
1849 mips_elf_highest (value
)
1850 bfd_vma value ATTRIBUTE_UNUSED
;
1853 return ((value
+ (bfd_vma
) 0x800080008000) >> 48) & 0xffff;
1856 return (bfd_vma
) -1;
1860 /* Create the .compact_rel section. */
1863 mips_elf_create_compact_rel_section (abfd
, info
)
1865 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1868 register asection
*s
;
1870 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
1872 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
1875 s
= bfd_make_section (abfd
, ".compact_rel");
1877 || ! bfd_set_section_flags (abfd
, s
, flags
)
1878 || ! bfd_set_section_alignment (abfd
, s
,
1879 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
1882 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
1888 /* Create the .got section to hold the global offset table. */
1891 mips_elf_create_got_section (abfd
, info
)
1893 struct bfd_link_info
*info
;
1896 register asection
*s
;
1897 struct elf_link_hash_entry
*h
;
1898 struct mips_got_info
*g
;
1901 /* This function may be called more than once. */
1902 if (mips_elf_got_section (abfd
))
1905 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1906 | SEC_LINKER_CREATED
);
1908 s
= bfd_make_section (abfd
, ".got");
1910 || ! bfd_set_section_flags (abfd
, s
, flags
)
1911 || ! bfd_set_section_alignment (abfd
, s
, 4))
1914 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
1915 linker script because we don't want to define the symbol if we
1916 are not creating a global offset table. */
1918 if (! (_bfd_generic_link_add_one_symbol
1919 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
1920 (bfd_vma
) 0, (const char *) NULL
, false,
1921 get_elf_backend_data (abfd
)->collect
,
1922 (struct bfd_link_hash_entry
**) &h
)))
1924 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
1925 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1926 h
->type
= STT_OBJECT
;
1929 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1932 /* The first several global offset table entries are reserved. */
1933 s
->_raw_size
= MIPS_RESERVED_GOTNO
* MIPS_ELF_GOT_SIZE (abfd
);
1935 amt
= sizeof (struct mips_got_info
);
1936 g
= (struct mips_got_info
*) bfd_alloc (abfd
, amt
);
1939 g
->global_gotsym
= NULL
;
1940 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
1941 g
->assigned_gotno
= MIPS_RESERVED_GOTNO
;
1942 if (elf_section_data (s
) == NULL
)
1944 amt
= sizeof (struct bfd_elf_section_data
);
1945 s
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
1946 if (elf_section_data (s
) == NULL
)
1949 elf_section_data (s
)->tdata
= (PTR
) g
;
1950 elf_section_data (s
)->this_hdr
.sh_flags
1951 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1956 /* Returns the .msym section for ABFD, creating it if it does not
1957 already exist. Returns NULL to indicate error. */
1960 mips_elf_create_msym_section (abfd
)
1965 s
= bfd_get_section_by_name (abfd
, ".msym");
1968 s
= bfd_make_section (abfd
, ".msym");
1970 || !bfd_set_section_flags (abfd
, s
,
1974 | SEC_LINKER_CREATED
1976 || !bfd_set_section_alignment (abfd
, s
,
1977 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
1984 /* Calculate the value produced by the RELOCATION (which comes from
1985 the INPUT_BFD). The ADDEND is the addend to use for this
1986 RELOCATION; RELOCATION->R_ADDEND is ignored.
1988 The result of the relocation calculation is stored in VALUEP.
1989 REQUIRE_JALXP indicates whether or not the opcode used with this
1990 relocation must be JALX.
1992 This function returns bfd_reloc_continue if the caller need take no
1993 further action regarding this relocation, bfd_reloc_notsupported if
1994 something goes dramatically wrong, bfd_reloc_overflow if an
1995 overflow occurs, and bfd_reloc_ok to indicate success. */
1997 static bfd_reloc_status_type
1998 mips_elf_calculate_relocation (abfd
, input_bfd
, input_section
, info
,
1999 relocation
, addend
, howto
, local_syms
,
2000 local_sections
, valuep
, namep
,
2004 asection
*input_section
;
2005 struct bfd_link_info
*info
;
2006 const Elf_Internal_Rela
*relocation
;
2008 reloc_howto_type
*howto
;
2009 Elf_Internal_Sym
*local_syms
;
2010 asection
**local_sections
;
2013 boolean
*require_jalxp
;
2015 /* The eventual value we will return. */
2017 /* The address of the symbol against which the relocation is
2020 /* The final GP value to be used for the relocatable, executable, or
2021 shared object file being produced. */
2022 bfd_vma gp
= MINUS_ONE
;
2023 /* The place (section offset or address) of the storage unit being
2026 /* The value of GP used to create the relocatable object. */
2027 bfd_vma gp0
= MINUS_ONE
;
2028 /* The offset into the global offset table at which the address of
2029 the relocation entry symbol, adjusted by the addend, resides
2030 during execution. */
2031 bfd_vma g
= MINUS_ONE
;
2032 /* The section in which the symbol referenced by the relocation is
2034 asection
*sec
= NULL
;
2035 struct mips_elf_link_hash_entry
*h
= NULL
;
2036 /* True if the symbol referred to by this relocation is a local
2039 /* True if the symbol referred to by this relocation is "_gp_disp". */
2040 boolean gp_disp_p
= false;
2041 Elf_Internal_Shdr
*symtab_hdr
;
2043 unsigned long r_symndx
;
2045 /* True if overflow occurred during the calculation of the
2046 relocation value. */
2047 boolean overflowed_p
;
2048 /* True if this relocation refers to a MIPS16 function. */
2049 boolean target_is_16_bit_code_p
= false;
2051 /* Parse the relocation. */
2052 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
2053 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
2054 p
= (input_section
->output_section
->vma
2055 + input_section
->output_offset
2056 + relocation
->r_offset
);
2058 /* Assume that there will be no overflow. */
2059 overflowed_p
= false;
2061 /* Figure out whether or not the symbol is local, and get the offset
2062 used in the array of hash table entries. */
2063 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2064 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
2065 local_sections
, false);
2066 if (! elf_bad_symtab (input_bfd
))
2067 extsymoff
= symtab_hdr
->sh_info
;
2070 /* The symbol table does not follow the rule that local symbols
2071 must come before globals. */
2075 /* Figure out the value of the symbol. */
2078 Elf_Internal_Sym
*sym
;
2080 sym
= local_syms
+ r_symndx
;
2081 sec
= local_sections
[r_symndx
];
2083 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2084 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
2085 || (sec
->flags
& SEC_MERGE
))
2086 symbol
+= sym
->st_value
;
2087 if ((sec
->flags
& SEC_MERGE
)
2088 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2090 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
2092 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
2095 /* MIPS16 text labels should be treated as odd. */
2096 if (sym
->st_other
== STO_MIPS16
)
2099 /* Record the name of this symbol, for our caller. */
2100 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
2101 symtab_hdr
->sh_link
,
2104 *namep
= bfd_section_name (input_bfd
, sec
);
2106 target_is_16_bit_code_p
= (sym
->st_other
== STO_MIPS16
);
2110 /* For global symbols we look up the symbol in the hash-table. */
2111 h
= ((struct mips_elf_link_hash_entry
*)
2112 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
2113 /* Find the real hash-table entry for this symbol. */
2114 while (h
->root
.root
.type
== bfd_link_hash_indirect
2115 || h
->root
.root
.type
== bfd_link_hash_warning
)
2116 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2118 /* Record the name of this symbol, for our caller. */
2119 *namep
= h
->root
.root
.root
.string
;
2121 /* See if this is the special _gp_disp symbol. Note that such a
2122 symbol must always be a global symbol. */
2123 if (strcmp (h
->root
.root
.root
.string
, "_gp_disp") == 0
2124 && ! NEWABI_P (input_bfd
))
2126 /* Relocations against _gp_disp are permitted only with
2127 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
2128 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_LO16
)
2129 return bfd_reloc_notsupported
;
2133 /* If this symbol is defined, calculate its address. Note that
2134 _gp_disp is a magic symbol, always implicitly defined by the
2135 linker, so it's inappropriate to check to see whether or not
2137 else if ((h
->root
.root
.type
== bfd_link_hash_defined
2138 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2139 && h
->root
.root
.u
.def
.section
)
2141 sec
= h
->root
.root
.u
.def
.section
;
2142 if (sec
->output_section
)
2143 symbol
= (h
->root
.root
.u
.def
.value
2144 + sec
->output_section
->vma
2145 + sec
->output_offset
);
2147 symbol
= h
->root
.root
.u
.def
.value
;
2149 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
2150 /* We allow relocations against undefined weak symbols, giving
2151 it the value zero, so that you can undefined weak functions
2152 and check to see if they exist by looking at their
2155 else if (info
->shared
2156 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
2157 && !info
->no_undefined
2158 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
2160 else if (strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINK") == 0 ||
2161 strcmp (h
->root
.root
.root
.string
, "_DYNAMIC_LINKING") == 0)
2163 /* If this is a dynamic link, we should have created a
2164 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
2165 in in _bfd_mips_elf_create_dynamic_sections.
2166 Otherwise, we should define the symbol with a value of 0.
2167 FIXME: It should probably get into the symbol table
2169 BFD_ASSERT (! info
->shared
);
2170 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
2175 if (! ((*info
->callbacks
->undefined_symbol
)
2176 (info
, h
->root
.root
.root
.string
, input_bfd
,
2177 input_section
, relocation
->r_offset
,
2178 (!info
->shared
|| info
->no_undefined
2179 || ELF_ST_VISIBILITY (h
->root
.other
)))))
2180 return bfd_reloc_undefined
;
2184 target_is_16_bit_code_p
= (h
->root
.other
== STO_MIPS16
);
2187 /* If this is a 32- or 64-bit call to a 16-bit function with a stub, we
2188 need to redirect the call to the stub, unless we're already *in*
2190 if (r_type
!= R_MIPS16_26
&& !info
->relocateable
2191 && ((h
!= NULL
&& h
->fn_stub
!= NULL
)
2192 || (local_p
&& elf_tdata (input_bfd
)->local_stubs
!= NULL
2193 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
2194 && !mips_elf_stub_section_p (input_bfd
, input_section
))
2196 /* This is a 32- or 64-bit call to a 16-bit function. We should
2197 have already noticed that we were going to need the
2200 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
2203 BFD_ASSERT (h
->need_fn_stub
);
2207 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2209 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
2210 need to redirect the call to the stub. */
2211 else if (r_type
== R_MIPS16_26
&& !info
->relocateable
2213 && (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
)
2214 && !target_is_16_bit_code_p
)
2216 /* If both call_stub and call_fp_stub are defined, we can figure
2217 out which one to use by seeing which one appears in the input
2219 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
2224 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
2226 if (strncmp (bfd_get_section_name (input_bfd
, o
),
2227 CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
2229 sec
= h
->call_fp_stub
;
2236 else if (h
->call_stub
!= NULL
)
2239 sec
= h
->call_fp_stub
;
2241 BFD_ASSERT (sec
->_raw_size
> 0);
2242 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
2245 /* Calls from 16-bit code to 32-bit code and vice versa require the
2246 special jalx instruction. */
2247 *require_jalxp
= (!info
->relocateable
2248 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
2249 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
2251 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
2252 local_sections
, true);
2254 /* If we haven't already determined the GOT offset, or the GP value,
2255 and we're going to need it, get it now. */
2260 case R_MIPS_GOT_DISP
:
2261 case R_MIPS_GOT_HI16
:
2262 case R_MIPS_CALL_HI16
:
2263 case R_MIPS_GOT_LO16
:
2264 case R_MIPS_CALL_LO16
:
2265 /* Find the index into the GOT where this value is located. */
2268 BFD_ASSERT (addend
== 0);
2269 g
= mips_elf_global_got_index (elf_hash_table (info
)->dynobj
,
2270 (struct elf_link_hash_entry
*) h
);
2271 if (! elf_hash_table(info
)->dynamic_sections_created
2273 && (info
->symbolic
|| h
->root
.dynindx
== -1)
2274 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2276 /* This is a static link or a -Bsymbolic link. The
2277 symbol is defined locally, or was forced to be local.
2278 We must initialize this entry in the GOT. */
2279 bfd
*tmpbfd
= elf_hash_table (info
)->dynobj
;
2280 asection
*sgot
= mips_elf_got_section(tmpbfd
);
2281 MIPS_ELF_PUT_WORD (tmpbfd
, symbol
+ addend
, sgot
->contents
+ g
);
2284 else if (r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS_CALL16
)
2285 /* There's no need to create a local GOT entry here; the
2286 calculation for a local GOT16 entry does not involve G. */
2290 g
= mips_elf_local_got_index (abfd
, info
, symbol
+ addend
);
2292 return bfd_reloc_outofrange
;
2295 /* Convert GOT indices to actual offsets. */
2296 g
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2302 case R_MIPS16_GPREL
:
2303 case R_MIPS_GPREL16
:
2304 case R_MIPS_GPREL32
:
2305 case R_MIPS_LITERAL
:
2306 gp0
= _bfd_get_gp_value (input_bfd
);
2307 gp
= _bfd_get_gp_value (abfd
);
2314 /* Figure out what kind of relocation is being performed. */
2318 return bfd_reloc_continue
;
2321 value
= symbol
+ mips_elf_sign_extend (addend
, 16);
2322 overflowed_p
= mips_elf_overflow_p (value
, 16);
2329 || (elf_hash_table (info
)->dynamic_sections_created
2331 && ((h
->root
.elf_link_hash_flags
2332 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
2333 && ((h
->root
.elf_link_hash_flags
2334 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2336 && (input_section
->flags
& SEC_ALLOC
) != 0)
2338 /* If we're creating a shared library, or this relocation is
2339 against a symbol in a shared library, then we can't know
2340 where the symbol will end up. So, we create a relocation
2341 record in the output, and leave the job up to the dynamic
2344 if (!mips_elf_create_dynamic_relocation (abfd
,
2352 return bfd_reloc_undefined
;
2356 if (r_type
!= R_MIPS_REL32
)
2357 value
= symbol
+ addend
;
2361 value
&= howto
->dst_mask
;
2366 case R_MIPS_GNU_REL_LO16
:
2367 value
= symbol
+ addend
- p
;
2368 value
&= howto
->dst_mask
;
2371 case R_MIPS_GNU_REL16_S2
:
2372 value
= symbol
+ mips_elf_sign_extend (addend
<< 2, 18) - p
;
2373 overflowed_p
= mips_elf_overflow_p (value
, 18);
2374 value
= (value
>> 2) & howto
->dst_mask
;
2377 case R_MIPS_GNU_REL_HI16
:
2378 /* Instead of subtracting 'p' here, we should be subtracting the
2379 equivalent value for the LO part of the reloc, since the value
2380 here is relative to that address. Because that's not easy to do,
2381 we adjust 'addend' in _bfd_mips_elf_relocate_section(). See also
2382 the comment there for more information. */
2383 value
= mips_elf_high (addend
+ symbol
- p
);
2384 value
&= howto
->dst_mask
;
2388 /* The calculation for R_MIPS16_26 is just the same as for an
2389 R_MIPS_26. It's only the storage of the relocated field into
2390 the output file that's different. That's handled in
2391 mips_elf_perform_relocation. So, we just fall through to the
2392 R_MIPS_26 case here. */
2395 value
= (((addend
<< 2) | ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
2397 value
= (mips_elf_sign_extend (addend
<< 2, 28) + symbol
) >> 2;
2398 value
&= howto
->dst_mask
;
2404 value
= mips_elf_high (addend
+ symbol
);
2405 value
&= howto
->dst_mask
;
2409 value
= mips_elf_high (addend
+ gp
- p
);
2410 overflowed_p
= mips_elf_overflow_p (value
, 16);
2416 value
= (symbol
+ addend
) & howto
->dst_mask
;
2419 value
= addend
+ gp
- p
+ 4;
2420 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
2421 for overflow. But, on, say, IRIX5, relocations against
2422 _gp_disp are normally generated from the .cpload
2423 pseudo-op. It generates code that normally looks like
2426 lui $gp,%hi(_gp_disp)
2427 addiu $gp,$gp,%lo(_gp_disp)
2430 Here $t9 holds the address of the function being called,
2431 as required by the MIPS ELF ABI. The R_MIPS_LO16
2432 relocation can easily overflow in this situation, but the
2433 R_MIPS_HI16 relocation will handle the overflow.
2434 Therefore, we consider this a bug in the MIPS ABI, and do
2435 not check for overflow here. */
2439 case R_MIPS_LITERAL
:
2440 /* Because we don't merge literal sections, we can handle this
2441 just like R_MIPS_GPREL16. In the long run, we should merge
2442 shared literals, and then we will need to additional work
2447 case R_MIPS16_GPREL
:
2448 /* The R_MIPS16_GPREL performs the same calculation as
2449 R_MIPS_GPREL16, but stores the relocated bits in a different
2450 order. We don't need to do anything special here; the
2451 differences are handled in mips_elf_perform_relocation. */
2452 case R_MIPS_GPREL16
:
2454 value
= mips_elf_sign_extend (addend
, 16) + symbol
+ gp0
- gp
;
2456 value
= mips_elf_sign_extend (addend
, 16) + symbol
- gp
;
2457 overflowed_p
= mips_elf_overflow_p (value
, 16);
2466 /* The special case is when the symbol is forced to be local. We
2467 need the full address in the GOT since no R_MIPS_LO16 relocation
2469 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
2470 local_sections
, false);
2471 value
= mips_elf_got16_entry (abfd
, info
, symbol
+ addend
, forced
);
2472 if (value
== MINUS_ONE
)
2473 return bfd_reloc_outofrange
;
2475 = mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2478 overflowed_p
= mips_elf_overflow_p (value
, 16);
2484 case R_MIPS_GOT_DISP
:
2486 overflowed_p
= mips_elf_overflow_p (value
, 16);
2489 case R_MIPS_GPREL32
:
2490 value
= (addend
+ symbol
+ gp0
- gp
) & howto
->dst_mask
;
2494 value
= mips_elf_sign_extend (addend
, 16) + symbol
- p
;
2495 overflowed_p
= mips_elf_overflow_p (value
, 16);
2496 value
= (bfd_vma
) ((bfd_signed_vma
) value
/ 4);
2499 case R_MIPS_GOT_HI16
:
2500 case R_MIPS_CALL_HI16
:
2501 /* We're allowed to handle these two relocations identically.
2502 The dynamic linker is allowed to handle the CALL relocations
2503 differently by creating a lazy evaluation stub. */
2505 value
= mips_elf_high (value
);
2506 value
&= howto
->dst_mask
;
2509 case R_MIPS_GOT_LO16
:
2510 case R_MIPS_CALL_LO16
:
2511 value
= g
& howto
->dst_mask
;
2514 case R_MIPS_GOT_PAGE
:
2515 value
= mips_elf_got_page (abfd
, info
, symbol
+ addend
, NULL
);
2516 if (value
== MINUS_ONE
)
2517 return bfd_reloc_outofrange
;
2518 value
= mips_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2521 overflowed_p
= mips_elf_overflow_p (value
, 16);
2524 case R_MIPS_GOT_OFST
:
2525 mips_elf_got_page (abfd
, info
, symbol
+ addend
, &value
);
2526 overflowed_p
= mips_elf_overflow_p (value
, 16);
2530 value
= symbol
- addend
;
2531 value
&= howto
->dst_mask
;
2535 value
= mips_elf_higher (addend
+ symbol
);
2536 value
&= howto
->dst_mask
;
2539 case R_MIPS_HIGHEST
:
2540 value
= mips_elf_highest (addend
+ symbol
);
2541 value
&= howto
->dst_mask
;
2544 case R_MIPS_SCN_DISP
:
2545 value
= symbol
+ addend
- sec
->output_offset
;
2546 value
&= howto
->dst_mask
;
2551 /* Both of these may be ignored. R_MIPS_JALR is an optimization
2552 hint; we could improve performance by honoring that hint. */
2553 return bfd_reloc_continue
;
2555 case R_MIPS_GNU_VTINHERIT
:
2556 case R_MIPS_GNU_VTENTRY
:
2557 /* We don't do anything with these at present. */
2558 return bfd_reloc_continue
;
2561 /* An unrecognized relocation type. */
2562 return bfd_reloc_notsupported
;
2565 /* Store the VALUE for our caller. */
2567 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
2570 /* Obtain the field relocated by RELOCATION. */
2573 mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
)
2574 reloc_howto_type
*howto
;
2575 const Elf_Internal_Rela
*relocation
;
2580 bfd_byte
*location
= contents
+ relocation
->r_offset
;
2582 /* Obtain the bytes. */
2583 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
2585 if ((ELF_R_TYPE (input_bfd
, relocation
->r_info
) == R_MIPS16_26
2586 || ELF_R_TYPE (input_bfd
, relocation
->r_info
) == R_MIPS16_GPREL
)
2587 && bfd_little_endian (input_bfd
))
2588 /* The two 16-bit words will be reversed on a little-endian system.
2589 See mips_elf_perform_relocation for more details. */
2590 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
2595 /* It has been determined that the result of the RELOCATION is the
2596 VALUE. Use HOWTO to place VALUE into the output file at the
2597 appropriate position. The SECTION is the section to which the
2598 relocation applies. If REQUIRE_JALX is true, then the opcode used
2599 for the relocation must be either JAL or JALX, and it is
2600 unconditionally converted to JALX.
2602 Returns false if anything goes wrong. */
2605 mips_elf_perform_relocation (info
, howto
, relocation
, value
, input_bfd
,
2606 input_section
, contents
, require_jalx
)
2607 struct bfd_link_info
*info
;
2608 reloc_howto_type
*howto
;
2609 const Elf_Internal_Rela
*relocation
;
2612 asection
*input_section
;
2614 boolean require_jalx
;
2618 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
2620 /* Figure out where the relocation is occurring. */
2621 location
= contents
+ relocation
->r_offset
;
2623 /* Obtain the current value. */
2624 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
2626 /* Clear the field we are setting. */
2627 x
&= ~howto
->dst_mask
;
2629 /* If this is the R_MIPS16_26 relocation, we must store the
2630 value in a funny way. */
2631 if (r_type
== R_MIPS16_26
)
2633 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
2634 Most mips16 instructions are 16 bits, but these instructions
2637 The format of these instructions is:
2639 +--------------+--------------------------------+
2640 ! JALX ! X! Imm 20:16 ! Imm 25:21 !
2641 +--------------+--------------------------------+
2643 +-----------------------------------------------+
2645 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
2646 Note that the immediate value in the first word is swapped.
2648 When producing a relocateable object file, R_MIPS16_26 is
2649 handled mostly like R_MIPS_26. In particular, the addend is
2650 stored as a straight 26-bit value in a 32-bit instruction.
2651 (gas makes life simpler for itself by never adjusting a
2652 R_MIPS16_26 reloc to be against a section, so the addend is
2653 always zero). However, the 32 bit instruction is stored as 2
2654 16-bit values, rather than a single 32-bit value. In a
2655 big-endian file, the result is the same; in a little-endian
2656 file, the two 16-bit halves of the 32 bit value are swapped.
2657 This is so that a disassembler can recognize the jal
2660 When doing a final link, R_MIPS16_26 is treated as a 32 bit
2661 instruction stored as two 16-bit values. The addend A is the
2662 contents of the targ26 field. The calculation is the same as
2663 R_MIPS_26. When storing the calculated value, reorder the
2664 immediate value as shown above, and don't forget to store the
2665 value as two 16-bit values.
2667 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
2671 +--------+----------------------+
2675 +--------+----------------------+
2678 +----------+------+-------------+
2682 +----------+--------------------+
2683 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
2684 ((sub1 << 16) | sub2)).
2686 When producing a relocateable object file, the calculation is
2687 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2688 When producing a fully linked file, the calculation is
2689 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
2690 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */
2692 if (!info
->relocateable
)
2693 /* Shuffle the bits according to the formula above. */
2694 value
= (((value
& 0x1f0000) << 5)
2695 | ((value
& 0x3e00000) >> 5)
2696 | (value
& 0xffff));
2698 else if (r_type
== R_MIPS16_GPREL
)
2700 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16
2701 mode. A typical instruction will have a format like this:
2703 +--------------+--------------------------------+
2704 ! EXTEND ! Imm 10:5 ! Imm 15:11 !
2705 +--------------+--------------------------------+
2706 ! Major ! rx ! ry ! Imm 4:0 !
2707 +--------------+--------------------------------+
2709 EXTEND is the five bit value 11110. Major is the instruction
2712 This is handled exactly like R_MIPS_GPREL16, except that the
2713 addend is retrieved and stored as shown in this diagram; that
2714 is, the Imm fields above replace the V-rel16 field.
2716 All we need to do here is shuffle the bits appropriately. As
2717 above, the two 16-bit halves must be swapped on a
2718 little-endian system. */
2719 value
= (((value
& 0x7e0) << 16)
2720 | ((value
& 0xf800) << 5)
2724 /* Set the field. */
2725 x
|= (value
& howto
->dst_mask
);
2727 /* If required, turn JAL into JALX. */
2731 bfd_vma opcode
= x
>> 26;
2732 bfd_vma jalx_opcode
;
2734 /* Check to see if the opcode is already JAL or JALX. */
2735 if (r_type
== R_MIPS16_26
)
2737 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
2742 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
2746 /* If the opcode is not JAL or JALX, there's a problem. */
2749 (*_bfd_error_handler
)
2750 (_("%s: %s+0x%lx: jump to stub routine which is not jal"),
2751 bfd_archive_filename (input_bfd
),
2752 input_section
->name
,
2753 (unsigned long) relocation
->r_offset
);
2754 bfd_set_error (bfd_error_bad_value
);
2758 /* Make this the JALX opcode. */
2759 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
2762 /* Swap the high- and low-order 16 bits on little-endian systems
2763 when doing a MIPS16 relocation. */
2764 if ((r_type
== R_MIPS16_GPREL
|| r_type
== R_MIPS16_26
)
2765 && bfd_little_endian (input_bfd
))
2766 x
= (((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16));
2768 /* Put the value into the output. */
2769 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
2773 /* Returns true if SECTION is a MIPS16 stub section. */
2776 mips_elf_stub_section_p (abfd
, section
)
2777 bfd
*abfd ATTRIBUTE_UNUSED
;
2780 const char *name
= bfd_get_section_name (abfd
, section
);
2782 return (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0
2783 || strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
2784 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0);
2787 /* Add room for N relocations to the .rel.dyn section in ABFD. */
2790 mips_elf_allocate_dynamic_relocations (abfd
, n
)
2796 s
= bfd_get_section_by_name (abfd
, ".rel.dyn");
2797 BFD_ASSERT (s
!= NULL
);
2799 if (s
->_raw_size
== 0)
2801 /* Make room for a null element. */
2802 s
->_raw_size
+= MIPS_ELF_REL_SIZE (abfd
);
2805 s
->_raw_size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
2808 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
2809 is the original relocation, which is now being transformed into a
2810 dynamic relocation. The ADDENDP is adjusted if necessary; the
2811 caller should store the result in place of the original addend. */
2814 mips_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
, sec
,
2815 symbol
, addendp
, input_section
)
2817 struct bfd_link_info
*info
;
2818 const Elf_Internal_Rela
*rel
;
2819 struct mips_elf_link_hash_entry
*h
;
2823 asection
*input_section
;
2825 Elf_Internal_Rel outrel
[3];
2831 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
2832 dynobj
= elf_hash_table (info
)->dynobj
;
2834 = bfd_get_section_by_name (dynobj
, ".rel.dyn");
2835 BFD_ASSERT (sreloc
!= NULL
);
2836 BFD_ASSERT (sreloc
->contents
!= NULL
);
2837 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
2838 < sreloc
->_raw_size
);
2841 outrel
[0].r_offset
=
2842 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
2843 outrel
[1].r_offset
=
2844 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
2845 outrel
[2].r_offset
=
2846 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
2849 /* We begin by assuming that the offset for the dynamic relocation
2850 is the same as for the original relocation. We'll adjust this
2851 later to reflect the correct output offsets. */
2852 if (elf_section_data (input_section
)->sec_info_type
!= ELF_INFO_TYPE_STABS
)
2854 outrel
[1].r_offset
= rel
[1].r_offset
;
2855 outrel
[2].r_offset
= rel
[2].r_offset
;
2859 /* Except that in a stab section things are more complex.
2860 Because we compress stab information, the offset given in the
2861 relocation may not be the one we want; we must let the stabs
2862 machinery tell us the offset. */
2863 outrel
[1].r_offset
= outrel
[0].r_offset
;
2864 outrel
[2].r_offset
= outrel
[0].r_offset
;
2865 /* If we didn't need the relocation at all, this value will be
2867 if (outrel
[0].r_offset
== (bfd_vma
) -1)
2872 if (outrel
[0].r_offset
== (bfd_vma
) -1)
2874 /* FIXME: For -2 runtime relocation needs to be skipped, but
2875 properly resolved statically and installed. */
2876 BFD_ASSERT (outrel
[0].r_offset
!= (bfd_vma
) -2);
2878 /* If we've decided to skip this relocation, just output an empty
2879 record. Note that R_MIPS_NONE == 0, so that this call to memset
2880 is a way of setting R_TYPE to R_MIPS_NONE. */
2882 memset (outrel
, 0, sizeof (Elf_Internal_Rel
) * 3);
2886 bfd_vma section_offset
;
2888 /* We must now calculate the dynamic symbol table index to use
2889 in the relocation. */
2891 && (! info
->symbolic
|| (h
->root
.elf_link_hash_flags
2892 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2894 indx
= h
->root
.dynindx
;
2895 /* h->root.dynindx may be -1 if this symbol was marked to
2902 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
2904 else if (sec
== NULL
|| sec
->owner
== NULL
)
2906 bfd_set_error (bfd_error_bad_value
);
2911 indx
= elf_section_data (sec
->output_section
)->dynindx
;
2916 /* Figure out how far the target of the relocation is from
2917 the beginning of its section. */
2918 section_offset
= symbol
- sec
->output_section
->vma
;
2919 /* The relocation we're building is section-relative.
2920 Therefore, the original addend must be adjusted by the
2922 *addendp
+= section_offset
;
2923 /* Now, the relocation is just against the section. */
2924 symbol
= sec
->output_section
->vma
;
2927 /* If the relocation was previously an absolute relocation and
2928 this symbol will not be referred to by the relocation, we must
2929 adjust it by the value we give it in the dynamic symbol table.
2930 Otherwise leave the job up to the dynamic linker. */
2931 if (!indx
&& r_type
!= R_MIPS_REL32
)
2934 /* The relocation is always an REL32 relocation because we don't
2935 know where the shared library will wind up at load-time. */
2936 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, R_MIPS_REL32
);
2938 /* Adjust the output offset of the relocation to reference the
2939 correct location in the output file. */
2940 outrel
[0].r_offset
+= (input_section
->output_section
->vma
2941 + input_section
->output_offset
);
2942 outrel
[1].r_offset
+= (input_section
->output_section
->vma
2943 + input_section
->output_offset
);
2944 outrel
[2].r_offset
+= (input_section
->output_section
->vma
2945 + input_section
->output_offset
);
2948 /* Put the relocation back out. We have to use the special
2949 relocation outputter in the 64-bit case since the 64-bit
2950 relocation format is non-standard. */
2951 if (ABI_64_P (output_bfd
))
2953 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2954 (output_bfd
, &outrel
[0],
2956 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
2959 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
[0],
2960 (((Elf32_External_Rel
*)
2962 + sreloc
->reloc_count
));
2964 /* Record the index of the first relocation referencing H. This
2965 information is later emitted in the .msym section. */
2967 && (h
->min_dyn_reloc_index
== 0
2968 || sreloc
->reloc_count
< h
->min_dyn_reloc_index
))
2969 h
->min_dyn_reloc_index
= sreloc
->reloc_count
;
2971 /* We've now added another relocation. */
2972 ++sreloc
->reloc_count
;
2974 /* Make sure the output section is writable. The dynamic linker
2975 will be writing to it. */
2976 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
2979 /* On IRIX5, make an entry of compact relocation info. */
2980 if (! skip
&& IRIX_COMPAT (output_bfd
) == ict_irix5
)
2982 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
2987 Elf32_crinfo cptrel
;
2989 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
2990 cptrel
.vaddr
= (rel
->r_offset
2991 + input_section
->output_section
->vma
2992 + input_section
->output_offset
);
2993 if (r_type
== R_MIPS_REL32
)
2994 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
2996 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
2997 mips_elf_set_cr_dist2to (cptrel
, 0);
2998 cptrel
.konst
= *addendp
;
3000 cr
= (scpt
->contents
3001 + sizeof (Elf32_External_compact_rel
));
3002 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
3003 ((Elf32_External_crinfo
*) cr
3004 + scpt
->reloc_count
));
3005 ++scpt
->reloc_count
;
3012 /* Return the ISA for a MIPS e_flags value. */
3015 elf_mips_isa (flags
)
3018 switch (flags
& EF_MIPS_ARCH
)
3030 case E_MIPS_ARCH_32
:
3032 case E_MIPS_ARCH_64
:
3038 /* Return the MACH for a MIPS e_flags value. */
3041 _bfd_elf_mips_mach (flags
)
3044 switch (flags
& EF_MIPS_MACH
)
3046 case E_MIPS_MACH_3900
:
3047 return bfd_mach_mips3900
;
3049 case E_MIPS_MACH_4010
:
3050 return bfd_mach_mips4010
;
3052 case E_MIPS_MACH_4100
:
3053 return bfd_mach_mips4100
;
3055 case E_MIPS_MACH_4111
:
3056 return bfd_mach_mips4111
;
3058 case E_MIPS_MACH_4650
:
3059 return bfd_mach_mips4650
;
3061 case E_MIPS_MACH_SB1
:
3062 return bfd_mach_mips_sb1
;
3065 switch (flags
& EF_MIPS_ARCH
)
3069 return bfd_mach_mips3000
;
3073 return bfd_mach_mips6000
;
3077 return bfd_mach_mips4000
;
3081 return bfd_mach_mips8000
;
3085 return bfd_mach_mips5
;
3088 case E_MIPS_ARCH_32
:
3089 return bfd_mach_mipsisa32
;
3092 case E_MIPS_ARCH_64
:
3093 return bfd_mach_mipsisa64
;
3101 /* Return printable name for ABI. */
3103 static INLINE
char *
3104 elf_mips_abi_name (abfd
)
3109 flags
= elf_elfheader (abfd
)->e_flags
;
3110 switch (flags
& EF_MIPS_ABI
)
3113 if (ABI_N32_P (abfd
))
3115 else if (ABI_64_P (abfd
))
3119 case E_MIPS_ABI_O32
:
3121 case E_MIPS_ABI_O64
:
3123 case E_MIPS_ABI_EABI32
:
3125 case E_MIPS_ABI_EABI64
:
3128 return "unknown abi";
3132 /* MIPS ELF uses two common sections. One is the usual one, and the
3133 other is for small objects. All the small objects are kept
3134 together, and then referenced via the gp pointer, which yields
3135 faster assembler code. This is what we use for the small common
3136 section. This approach is copied from ecoff.c. */
3137 static asection mips_elf_scom_section
;
3138 static asymbol mips_elf_scom_symbol
;
3139 static asymbol
*mips_elf_scom_symbol_ptr
;
3141 /* MIPS ELF also uses an acommon section, which represents an
3142 allocated common symbol which may be overridden by a
3143 definition in a shared library. */
3144 static asection mips_elf_acom_section
;
3145 static asymbol mips_elf_acom_symbol
;
3146 static asymbol
*mips_elf_acom_symbol_ptr
;
3148 /* Handle the special MIPS section numbers that a symbol may use.
3149 This is used for both the 32-bit and the 64-bit ABI. */
3152 _bfd_mips_elf_symbol_processing (abfd
, asym
)
3156 elf_symbol_type
*elfsym
;
3158 elfsym
= (elf_symbol_type
*) asym
;
3159 switch (elfsym
->internal_elf_sym
.st_shndx
)
3161 case SHN_MIPS_ACOMMON
:
3162 /* This section is used in a dynamically linked executable file.
3163 It is an allocated common section. The dynamic linker can
3164 either resolve these symbols to something in a shared
3165 library, or it can just leave them here. For our purposes,
3166 we can consider these symbols to be in a new section. */
3167 if (mips_elf_acom_section
.name
== NULL
)
3169 /* Initialize the acommon section. */
3170 mips_elf_acom_section
.name
= ".acommon";
3171 mips_elf_acom_section
.flags
= SEC_ALLOC
;
3172 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
3173 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
3174 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
3175 mips_elf_acom_symbol
.name
= ".acommon";
3176 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
3177 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
3178 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
3180 asym
->section
= &mips_elf_acom_section
;
3184 /* Common symbols less than the GP size are automatically
3185 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
3186 if (asym
->value
> elf_gp_size (abfd
)
3187 || IRIX_COMPAT (abfd
) == ict_irix6
)
3190 case SHN_MIPS_SCOMMON
:
3191 if (mips_elf_scom_section
.name
== NULL
)
3193 /* Initialize the small common section. */
3194 mips_elf_scom_section
.name
= ".scommon";
3195 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
3196 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
3197 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
3198 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
3199 mips_elf_scom_symbol
.name
= ".scommon";
3200 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
3201 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
3202 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
3204 asym
->section
= &mips_elf_scom_section
;
3205 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
3208 case SHN_MIPS_SUNDEFINED
:
3209 asym
->section
= bfd_und_section_ptr
;
3212 #if 0 /* for SGI_COMPAT */
3214 asym
->section
= mips_elf_text_section_ptr
;
3218 asym
->section
= mips_elf_data_section_ptr
;
3224 /* Work over a section just before writing it out. This routine is
3225 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
3226 sections that need the SHF_MIPS_GPREL flag by name; there has to be
3230 _bfd_mips_elf_section_processing (abfd
, hdr
)
3232 Elf_Internal_Shdr
*hdr
;
3234 if (hdr
->sh_type
== SHT_MIPS_REGINFO
3235 && hdr
->sh_size
> 0)
3239 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
3240 BFD_ASSERT (hdr
->contents
== NULL
);
3243 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
3246 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3247 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3251 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
3252 && hdr
->bfd_section
!= NULL
3253 && elf_section_data (hdr
->bfd_section
) != NULL
3254 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
3256 bfd_byte
*contents
, *l
, *lend
;
3258 /* We stored the section contents in the elf_section_data tdata
3259 field in the set_section_contents routine. We save the
3260 section contents so that we don't have to read them again.
3261 At this point we know that elf_gp is set, so we can look
3262 through the section contents to see if there is an
3263 ODK_REGINFO structure. */
3265 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
3267 lend
= contents
+ hdr
->sh_size
;
3268 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3270 Elf_Internal_Options intopt
;
3272 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3274 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3281 + sizeof (Elf_External_Options
)
3282 + (sizeof (Elf64_External_RegInfo
) - 8)),
3285 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
3286 if (bfd_bwrite (buf
, (bfd_size_type
) 8, abfd
) != 8)
3289 else if (intopt
.kind
== ODK_REGINFO
)
3296 + sizeof (Elf_External_Options
)
3297 + (sizeof (Elf32_External_RegInfo
) - 4)),
3300 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
3301 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
3308 if (hdr
->bfd_section
!= NULL
)
3310 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3312 if (strcmp (name
, ".sdata") == 0
3313 || strcmp (name
, ".lit8") == 0
3314 || strcmp (name
, ".lit4") == 0)
3316 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3317 hdr
->sh_type
= SHT_PROGBITS
;
3319 else if (strcmp (name
, ".sbss") == 0)
3321 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
3322 hdr
->sh_type
= SHT_NOBITS
;
3324 else if (strcmp (name
, ".srdata") == 0)
3326 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
3327 hdr
->sh_type
= SHT_PROGBITS
;
3329 else if (strcmp (name
, ".compact_rel") == 0)
3332 hdr
->sh_type
= SHT_PROGBITS
;
3334 else if (strcmp (name
, ".rtproc") == 0)
3336 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
3338 unsigned int adjust
;
3340 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
3342 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
3350 /* Handle a MIPS specific section when reading an object file. This
3351 is called when elfcode.h finds a section with an unknown type.
3352 This routine supports both the 32-bit and 64-bit ELF ABI.
3354 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
3358 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
3360 Elf_Internal_Shdr
*hdr
;
3365 /* There ought to be a place to keep ELF backend specific flags, but
3366 at the moment there isn't one. We just keep track of the
3367 sections by their name, instead. Fortunately, the ABI gives
3368 suggested names for all the MIPS specific sections, so we will
3369 probably get away with this. */
3370 switch (hdr
->sh_type
)
3372 case SHT_MIPS_LIBLIST
:
3373 if (strcmp (name
, ".liblist") != 0)
3377 if (strcmp (name
, ".msym") != 0)
3380 case SHT_MIPS_CONFLICT
:
3381 if (strcmp (name
, ".conflict") != 0)
3384 case SHT_MIPS_GPTAB
:
3385 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
3388 case SHT_MIPS_UCODE
:
3389 if (strcmp (name
, ".ucode") != 0)
3392 case SHT_MIPS_DEBUG
:
3393 if (strcmp (name
, ".mdebug") != 0)
3395 flags
= SEC_DEBUGGING
;
3397 case SHT_MIPS_REGINFO
:
3398 if (strcmp (name
, ".reginfo") != 0
3399 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
3401 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
3403 case SHT_MIPS_IFACE
:
3404 if (strcmp (name
, ".MIPS.interfaces") != 0)
3407 case SHT_MIPS_CONTENT
:
3408 if (strncmp (name
, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0)
3411 case SHT_MIPS_OPTIONS
:
3412 if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) != 0)
3415 case SHT_MIPS_DWARF
:
3416 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
3419 case SHT_MIPS_SYMBOL_LIB
:
3420 if (strcmp (name
, ".MIPS.symlib") != 0)
3423 case SHT_MIPS_EVENTS
:
3424 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0
3425 && strncmp (name
, ".MIPS.post_rel",
3426 sizeof ".MIPS.post_rel" - 1) != 0)
3433 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
3438 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
3439 (bfd_get_section_flags (abfd
,
3445 /* FIXME: We should record sh_info for a .gptab section. */
3447 /* For a .reginfo section, set the gp value in the tdata information
3448 from the contents of this section. We need the gp value while
3449 processing relocs, so we just get it now. The .reginfo section
3450 is not used in the 64-bit MIPS ELF ABI. */
3451 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
3453 Elf32_External_RegInfo ext
;
3456 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
3458 (bfd_size_type
) sizeof ext
))
3460 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
3461 elf_gp (abfd
) = s
.ri_gp_value
;
3464 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
3465 set the gp value based on what we find. We may see both
3466 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
3467 they should agree. */
3468 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
3470 bfd_byte
*contents
, *l
, *lend
;
3472 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
3473 if (contents
== NULL
)
3475 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
3476 (file_ptr
) 0, hdr
->sh_size
))
3482 lend
= contents
+ hdr
->sh_size
;
3483 while (l
+ sizeof (Elf_External_Options
) <= lend
)
3485 Elf_Internal_Options intopt
;
3487 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
3489 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
3491 Elf64_Internal_RegInfo intreg
;
3493 bfd_mips_elf64_swap_reginfo_in
3495 ((Elf64_External_RegInfo
*)
3496 (l
+ sizeof (Elf_External_Options
))),
3498 elf_gp (abfd
) = intreg
.ri_gp_value
;
3500 else if (intopt
.kind
== ODK_REGINFO
)
3502 Elf32_RegInfo intreg
;
3504 bfd_mips_elf32_swap_reginfo_in
3506 ((Elf32_External_RegInfo
*)
3507 (l
+ sizeof (Elf_External_Options
))),
3509 elf_gp (abfd
) = intreg
.ri_gp_value
;
3519 /* Set the correct type for a MIPS ELF section. We do this by the
3520 section name, which is a hack, but ought to work. This routine is
3521 used by both the 32-bit and the 64-bit ABI. */
3524 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
3526 Elf32_Internal_Shdr
*hdr
;
3529 register const char *name
;
3531 name
= bfd_get_section_name (abfd
, sec
);
3533 if (strcmp (name
, ".liblist") == 0)
3535 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
3536 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
3537 /* The sh_link field is set in final_write_processing. */
3539 else if (strcmp (name
, ".conflict") == 0)
3540 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
3541 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3543 hdr
->sh_type
= SHT_MIPS_GPTAB
;
3544 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
3545 /* The sh_info field is set in final_write_processing. */
3547 else if (strcmp (name
, ".ucode") == 0)
3548 hdr
->sh_type
= SHT_MIPS_UCODE
;
3549 else if (strcmp (name
, ".mdebug") == 0)
3551 hdr
->sh_type
= SHT_MIPS_DEBUG
;
3552 /* In a shared object on IRIX 5.3, the .mdebug section has an
3553 entsize of 0. FIXME: Does this matter? */
3554 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
3555 hdr
->sh_entsize
= 0;
3557 hdr
->sh_entsize
= 1;
3559 else if (strcmp (name
, ".reginfo") == 0)
3561 hdr
->sh_type
= SHT_MIPS_REGINFO
;
3562 /* In a shared object on IRIX 5.3, the .reginfo section has an
3563 entsize of 0x18. FIXME: Does this matter? */
3564 if (SGI_COMPAT (abfd
))
3566 if ((abfd
->flags
& DYNAMIC
) != 0)
3567 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3569 hdr
->sh_entsize
= 1;
3572 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
3574 else if (SGI_COMPAT (abfd
)
3575 && (strcmp (name
, ".hash") == 0
3576 || strcmp (name
, ".dynamic") == 0
3577 || strcmp (name
, ".dynstr") == 0))
3579 if (SGI_COMPAT (abfd
))
3580 hdr
->sh_entsize
= 0;
3582 /* This isn't how the IRIX6 linker behaves. */
3583 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
3586 else if (strcmp (name
, ".got") == 0
3587 || strcmp (name
, ".srdata") == 0
3588 || strcmp (name
, ".sdata") == 0
3589 || strcmp (name
, ".sbss") == 0
3590 || strcmp (name
, ".lit4") == 0
3591 || strcmp (name
, ".lit8") == 0)
3592 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
3593 else if (strcmp (name
, ".MIPS.interfaces") == 0)
3595 hdr
->sh_type
= SHT_MIPS_IFACE
;
3596 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3598 else if (strncmp (name
, ".MIPS.content", strlen (".MIPS.content")) == 0)
3600 hdr
->sh_type
= SHT_MIPS_CONTENT
;
3601 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3602 /* The sh_info field is set in final_write_processing. */
3604 else if (strcmp (name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
3606 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
3607 hdr
->sh_entsize
= 1;
3608 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3610 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
3611 hdr
->sh_type
= SHT_MIPS_DWARF
;
3612 else if (strcmp (name
, ".MIPS.symlib") == 0)
3614 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
3615 /* The sh_link and sh_info fields are set in
3616 final_write_processing. */
3618 else if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0
3619 || strncmp (name
, ".MIPS.post_rel",
3620 sizeof ".MIPS.post_rel" - 1) == 0)
3622 hdr
->sh_type
= SHT_MIPS_EVENTS
;
3623 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
3624 /* The sh_link field is set in final_write_processing. */
3626 else if (strcmp (name
, ".msym") == 0)
3628 hdr
->sh_type
= SHT_MIPS_MSYM
;
3629 hdr
->sh_flags
|= SHF_ALLOC
;
3630 hdr
->sh_entsize
= 8;
3633 /* The generic elf_fake_sections will set up REL_HDR using the
3634 default kind of relocations. But, we may actually need both
3635 kinds of relocations, so we set up the second header here.
3637 This is not necessary for the O32 ABI since that only uses Elf32_Rel
3638 relocations (cf. System V ABI, MIPS RISC Processor Supplement,
3639 3rd Edition, p. 4-17). It breaks the IRIX 5/6 32-bit ld, since one
3640 of the resulting empty .rela.<section> sections starts with
3641 sh_offset == object size, and ld doesn't allow that. While the check
3642 is arguably bogus for empty or SHT_NOBITS sections, it can easily be
3643 avoided by not emitting those useless sections in the first place. */
3644 if (IRIX_COMPAT (abfd
) != ict_irix5
&& (sec
->flags
& SEC_RELOC
) != 0)
3646 struct bfd_elf_section_data
*esd
;
3647 bfd_size_type amt
= sizeof (Elf_Internal_Shdr
);
3649 esd
= elf_section_data (sec
);
3650 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
3651 esd
->rel_hdr2
= (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, amt
);
3654 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
3655 !elf_section_data (sec
)->use_rela_p
);
3661 /* Given a BFD section, try to locate the corresponding ELF section
3662 index. This is used by both the 32-bit and the 64-bit ABI.
3663 Actually, it's not clear to me that the 64-bit ABI supports these,
3664 but for non-PIC objects we will certainly want support for at least
3665 the .scommon section. */
3668 _bfd_mips_elf_section_from_bfd_section (abfd
, sec
, retval
)
3669 bfd
*abfd ATTRIBUTE_UNUSED
;
3673 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
3675 *retval
= SHN_MIPS_SCOMMON
;
3678 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
3680 *retval
= SHN_MIPS_ACOMMON
;
3686 /* Hook called by the linker routine which adds symbols from an object
3687 file. We must handle the special MIPS section numbers here. */
3690 _bfd_mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
3692 struct bfd_link_info
*info
;
3693 const Elf_Internal_Sym
*sym
;
3695 flagword
*flagsp ATTRIBUTE_UNUSED
;
3699 if (SGI_COMPAT (abfd
)
3700 && (abfd
->flags
& DYNAMIC
) != 0
3701 && strcmp (*namep
, "_rld_new_interface") == 0)
3703 /* Skip IRIX5 rld entry name. */
3708 switch (sym
->st_shndx
)
3711 /* Common symbols less than the GP size are automatically
3712 treated as SHN_MIPS_SCOMMON symbols. */
3713 if (sym
->st_size
> elf_gp_size (abfd
)
3714 || IRIX_COMPAT (abfd
) == ict_irix6
)
3717 case SHN_MIPS_SCOMMON
:
3718 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
3719 (*secp
)->flags
|= SEC_IS_COMMON
;
3720 *valp
= sym
->st_size
;
3724 /* This section is used in a shared object. */
3725 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
3727 asymbol
*elf_text_symbol
;
3728 asection
*elf_text_section
;
3729 bfd_size_type amt
= sizeof (asection
);
3731 elf_text_section
= bfd_zalloc (abfd
, amt
);
3732 if (elf_text_section
== NULL
)
3735 amt
= sizeof (asymbol
);
3736 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
3737 if (elf_text_symbol
== NULL
)
3740 /* Initialize the section. */
3742 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
3743 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
3745 elf_text_section
->symbol
= elf_text_symbol
;
3746 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
3748 elf_text_section
->name
= ".text";
3749 elf_text_section
->flags
= SEC_NO_FLAGS
;
3750 elf_text_section
->output_section
= NULL
;
3751 elf_text_section
->owner
= abfd
;
3752 elf_text_symbol
->name
= ".text";
3753 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
3754 elf_text_symbol
->section
= elf_text_section
;
3756 /* This code used to do *secp = bfd_und_section_ptr if
3757 info->shared. I don't know why, and that doesn't make sense,
3758 so I took it out. */
3759 *secp
= elf_tdata (abfd
)->elf_text_section
;
3762 case SHN_MIPS_ACOMMON
:
3763 /* Fall through. XXX Can we treat this as allocated data? */
3765 /* This section is used in a shared object. */
3766 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
3768 asymbol
*elf_data_symbol
;
3769 asection
*elf_data_section
;
3770 bfd_size_type amt
= sizeof (asection
);
3772 elf_data_section
= bfd_zalloc (abfd
, amt
);
3773 if (elf_data_section
== NULL
)
3776 amt
= sizeof (asymbol
);
3777 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
3778 if (elf_data_symbol
== NULL
)
3781 /* Initialize the section. */
3783 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
3784 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
3786 elf_data_section
->symbol
= elf_data_symbol
;
3787 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
3789 elf_data_section
->name
= ".data";
3790 elf_data_section
->flags
= SEC_NO_FLAGS
;
3791 elf_data_section
->output_section
= NULL
;
3792 elf_data_section
->owner
= abfd
;
3793 elf_data_symbol
->name
= ".data";
3794 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
3795 elf_data_symbol
->section
= elf_data_section
;
3797 /* This code used to do *secp = bfd_und_section_ptr if
3798 info->shared. I don't know why, and that doesn't make sense,
3799 so I took it out. */
3800 *secp
= elf_tdata (abfd
)->elf_data_section
;
3803 case SHN_MIPS_SUNDEFINED
:
3804 *secp
= bfd_und_section_ptr
;
3808 if (SGI_COMPAT (abfd
)
3810 && info
->hash
->creator
== abfd
->xvec
3811 && strcmp (*namep
, "__rld_obj_head") == 0)
3813 struct elf_link_hash_entry
*h
;
3815 /* Mark __rld_obj_head as dynamic. */
3817 if (! (_bfd_generic_link_add_one_symbol
3818 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
3819 (bfd_vma
) *valp
, (const char *) NULL
, false,
3820 get_elf_backend_data (abfd
)->collect
,
3821 (struct bfd_link_hash_entry
**) &h
)))
3823 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3824 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3825 h
->type
= STT_OBJECT
;
3827 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3830 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
3833 /* If this is a mips16 text symbol, add 1 to the value to make it
3834 odd. This will cause something like .word SYM to come up with
3835 the right value when it is loaded into the PC. */
3836 if (sym
->st_other
== STO_MIPS16
)
3842 /* This hook function is called before the linker writes out a global
3843 symbol. We mark symbols as small common if appropriate. This is
3844 also where we undo the increment of the value for a mips16 symbol. */
3847 _bfd_mips_elf_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
3848 bfd
*abfd ATTRIBUTE_UNUSED
;
3849 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3850 const char *name ATTRIBUTE_UNUSED
;
3851 Elf_Internal_Sym
*sym
;
3852 asection
*input_sec
;
3854 /* If we see a common symbol, which implies a relocatable link, then
3855 if a symbol was small common in an input file, mark it as small
3856 common in the output file. */
3857 if (sym
->st_shndx
== SHN_COMMON
3858 && strcmp (input_sec
->name
, ".scommon") == 0)
3859 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
3861 if (sym
->st_other
== STO_MIPS16
3862 && (sym
->st_value
& 1) != 0)
3868 /* Functions for the dynamic linker. */
3870 /* Create dynamic sections when linking against a dynamic object. */
3873 _bfd_mips_elf_create_dynamic_sections (abfd
, info
)
3875 struct bfd_link_info
*info
;
3877 struct elf_link_hash_entry
*h
;
3879 register asection
*s
;
3880 const char * const *namep
;
3882 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3883 | SEC_LINKER_CREATED
| SEC_READONLY
);
3885 /* Mips ABI requests the .dynamic section to be read only. */
3886 s
= bfd_get_section_by_name (abfd
, ".dynamic");
3889 if (! bfd_set_section_flags (abfd
, s
, flags
))
3893 /* We need to create .got section. */
3894 if (! mips_elf_create_got_section (abfd
, info
))
3897 /* Create the .msym section on IRIX6. It is used by the dynamic
3898 linker to speed up dynamic relocations, and to avoid computing
3899 the ELF hash for symbols. */
3900 if (IRIX_COMPAT (abfd
) == ict_irix6
3901 && !mips_elf_create_msym_section (abfd
))
3904 /* Create .stub section. */
3905 if (bfd_get_section_by_name (abfd
,
3906 MIPS_ELF_STUB_SECTION_NAME (abfd
)) == NULL
)
3908 s
= bfd_make_section (abfd
, MIPS_ELF_STUB_SECTION_NAME (abfd
));
3910 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_CODE
)
3911 || ! bfd_set_section_alignment (abfd
, s
,
3912 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
3916 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
3918 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
3920 s
= bfd_make_section (abfd
, ".rld_map");
3922 || ! bfd_set_section_flags (abfd
, s
, flags
&~ (flagword
) SEC_READONLY
)
3923 || ! bfd_set_section_alignment (abfd
, s
,
3924 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
3928 /* On IRIX5, we adjust add some additional symbols and change the
3929 alignments of several sections. There is no ABI documentation
3930 indicating that this is necessary on IRIX6, nor any evidence that
3931 the linker takes such action. */
3932 if (IRIX_COMPAT (abfd
) == ict_irix5
)
3934 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
3937 if (! (_bfd_generic_link_add_one_symbol
3938 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
3939 (bfd_vma
) 0, (const char *) NULL
, false,
3940 get_elf_backend_data (abfd
)->collect
,
3941 (struct bfd_link_hash_entry
**) &h
)))
3943 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3944 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3945 h
->type
= STT_SECTION
;
3947 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3951 /* We need to create a .compact_rel section. */
3952 if (SGI_COMPAT (abfd
))
3954 if (!mips_elf_create_compact_rel_section (abfd
, info
))
3958 /* Change aligments of some sections. */
3959 s
= bfd_get_section_by_name (abfd
, ".hash");
3961 bfd_set_section_alignment (abfd
, s
, 4);
3962 s
= bfd_get_section_by_name (abfd
, ".dynsym");
3964 bfd_set_section_alignment (abfd
, s
, 4);
3965 s
= bfd_get_section_by_name (abfd
, ".dynstr");
3967 bfd_set_section_alignment (abfd
, s
, 4);
3968 s
= bfd_get_section_by_name (abfd
, ".reginfo");
3970 bfd_set_section_alignment (abfd
, s
, 4);
3971 s
= bfd_get_section_by_name (abfd
, ".dynamic");
3973 bfd_set_section_alignment (abfd
, s
, 4);
3979 if (SGI_COMPAT (abfd
))
3981 if (!(_bfd_generic_link_add_one_symbol
3982 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
3983 (bfd_vma
) 0, (const char *) NULL
, false,
3984 get_elf_backend_data (abfd
)->collect
,
3985 (struct bfd_link_hash_entry
**) &h
)))
3990 /* For normal mips it is _DYNAMIC_LINKING. */
3991 if (!(_bfd_generic_link_add_one_symbol
3992 (info
, abfd
, "_DYNAMIC_LINKING", BSF_GLOBAL
,
3993 bfd_abs_section_ptr
, (bfd_vma
) 0, (const char *) NULL
, false,
3994 get_elf_backend_data (abfd
)->collect
,
3995 (struct bfd_link_hash_entry
**) &h
)))
3998 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3999 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4000 h
->type
= STT_SECTION
;
4002 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4005 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
4007 /* __rld_map is a four byte word located in the .data section
4008 and is filled in by the rtld to contain a pointer to
4009 the _r_debug structure. Its symbol value will be set in
4010 _bfd_mips_elf_finish_dynamic_symbol. */
4011 s
= bfd_get_section_by_name (abfd
, ".rld_map");
4012 BFD_ASSERT (s
!= NULL
);
4015 if (SGI_COMPAT (abfd
))
4017 if (!(_bfd_generic_link_add_one_symbol
4018 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
4019 (bfd_vma
) 0, (const char *) NULL
, false,
4020 get_elf_backend_data (abfd
)->collect
,
4021 (struct bfd_link_hash_entry
**) &h
)))
4026 /* For normal mips the symbol is __RLD_MAP. */
4027 if (!(_bfd_generic_link_add_one_symbol
4028 (info
, abfd
, "__RLD_MAP", BSF_GLOBAL
, s
,
4029 (bfd_vma
) 0, (const char *) NULL
, false,
4030 get_elf_backend_data (abfd
)->collect
,
4031 (struct bfd_link_hash_entry
**) &h
)))
4034 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4035 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4036 h
->type
= STT_OBJECT
;
4038 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4046 /* Look through the relocs for a section during the first phase, and
4047 allocate space in the global offset table. */
4050 _bfd_mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
4052 struct bfd_link_info
*info
;
4054 const Elf_Internal_Rela
*relocs
;
4058 Elf_Internal_Shdr
*symtab_hdr
;
4059 struct elf_link_hash_entry
**sym_hashes
;
4060 struct mips_got_info
*g
;
4062 const Elf_Internal_Rela
*rel
;
4063 const Elf_Internal_Rela
*rel_end
;
4066 struct elf_backend_data
*bed
;
4068 if (info
->relocateable
)
4071 dynobj
= elf_hash_table (info
)->dynobj
;
4072 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4073 sym_hashes
= elf_sym_hashes (abfd
);
4074 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
4076 /* Check for the mips16 stub sections. */
4078 name
= bfd_get_section_name (abfd
, sec
);
4079 if (strncmp (name
, FN_STUB
, sizeof FN_STUB
- 1) == 0)
4081 unsigned long r_symndx
;
4083 /* Look at the relocation information to figure out which symbol
4086 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
4088 if (r_symndx
< extsymoff
4089 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
4093 /* This stub is for a local symbol. This stub will only be
4094 needed if there is some relocation in this BFD, other
4095 than a 16 bit function call, which refers to this symbol. */
4096 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4098 Elf_Internal_Rela
*sec_relocs
;
4099 const Elf_Internal_Rela
*r
, *rend
;
4101 /* We can ignore stub sections when looking for relocs. */
4102 if ((o
->flags
& SEC_RELOC
) == 0
4103 || o
->reloc_count
== 0
4104 || strncmp (bfd_get_section_name (abfd
, o
), FN_STUB
,
4105 sizeof FN_STUB
- 1) == 0
4106 || strncmp (bfd_get_section_name (abfd
, o
), CALL_STUB
,
4107 sizeof CALL_STUB
- 1) == 0
4108 || strncmp (bfd_get_section_name (abfd
, o
), CALL_FP_STUB
,
4109 sizeof CALL_FP_STUB
- 1) == 0)
4112 sec_relocs
= (_bfd_elf32_link_read_relocs
4113 (abfd
, o
, (PTR
) NULL
,
4114 (Elf_Internal_Rela
*) NULL
,
4115 info
->keep_memory
));
4116 if (sec_relocs
== NULL
)
4119 rend
= sec_relocs
+ o
->reloc_count
;
4120 for (r
= sec_relocs
; r
< rend
; r
++)
4121 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
4122 && ELF_R_TYPE (abfd
, r
->r_info
) != R_MIPS16_26
)
4125 if (! info
->keep_memory
)
4134 /* There is no non-call reloc for this stub, so we do
4135 not need it. Since this function is called before
4136 the linker maps input sections to output sections, we
4137 can easily discard it by setting the SEC_EXCLUDE
4139 sec
->flags
|= SEC_EXCLUDE
;
4143 /* Record this stub in an array of local symbol stubs for
4145 if (elf_tdata (abfd
)->local_stubs
== NULL
)
4147 unsigned long symcount
;
4151 if (elf_bad_symtab (abfd
))
4152 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
4154 symcount
= symtab_hdr
->sh_info
;
4155 amt
= symcount
* sizeof (asection
*);
4156 n
= (asection
**) bfd_zalloc (abfd
, amt
);
4159 elf_tdata (abfd
)->local_stubs
= n
;
4162 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
4164 /* We don't need to set mips16_stubs_seen in this case.
4165 That flag is used to see whether we need to look through
4166 the global symbol table for stubs. We don't need to set
4167 it here, because we just have a local stub. */
4171 struct mips_elf_link_hash_entry
*h
;
4173 h
= ((struct mips_elf_link_hash_entry
*)
4174 sym_hashes
[r_symndx
- extsymoff
]);
4176 /* H is the symbol this stub is for. */
4179 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
4182 else if (strncmp (name
, CALL_STUB
, sizeof CALL_STUB
- 1) == 0
4183 || strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4185 unsigned long r_symndx
;
4186 struct mips_elf_link_hash_entry
*h
;
4189 /* Look at the relocation information to figure out which symbol
4192 r_symndx
= ELF_R_SYM (abfd
, relocs
->r_info
);
4194 if (r_symndx
< extsymoff
4195 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
4197 /* This stub was actually built for a static symbol defined
4198 in the same file. We assume that all static symbols in
4199 mips16 code are themselves mips16, so we can simply
4200 discard this stub. Since this function is called before
4201 the linker maps input sections to output sections, we can
4202 easily discard it by setting the SEC_EXCLUDE flag. */
4203 sec
->flags
|= SEC_EXCLUDE
;
4207 h
= ((struct mips_elf_link_hash_entry
*)
4208 sym_hashes
[r_symndx
- extsymoff
]);
4210 /* H is the symbol this stub is for. */
4212 if (strncmp (name
, CALL_FP_STUB
, sizeof CALL_FP_STUB
- 1) == 0)
4213 loc
= &h
->call_fp_stub
;
4215 loc
= &h
->call_stub
;
4217 /* If we already have an appropriate stub for this function, we
4218 don't need another one, so we can discard this one. Since
4219 this function is called before the linker maps input sections
4220 to output sections, we can easily discard it by setting the
4221 SEC_EXCLUDE flag. We can also discard this section if we
4222 happen to already know that this is a mips16 function; it is
4223 not necessary to check this here, as it is checked later, but
4224 it is slightly faster to check now. */
4225 if (*loc
!= NULL
|| h
->root
.other
== STO_MIPS16
)
4227 sec
->flags
|= SEC_EXCLUDE
;
4232 mips_elf_hash_table (info
)->mips16_stubs_seen
= true;
4242 sgot
= mips_elf_got_section (dynobj
);
4247 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4248 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4249 BFD_ASSERT (g
!= NULL
);
4254 bed
= get_elf_backend_data (abfd
);
4255 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
4256 for (rel
= relocs
; rel
< rel_end
; ++rel
)
4258 unsigned long r_symndx
;
4259 unsigned int r_type
;
4260 struct elf_link_hash_entry
*h
;
4262 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
4263 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
4265 if (r_symndx
< extsymoff
)
4267 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
4269 (*_bfd_error_handler
)
4270 (_("%s: Malformed reloc detected for section %s"),
4271 bfd_archive_filename (abfd
), name
);
4272 bfd_set_error (bfd_error_bad_value
);
4277 h
= sym_hashes
[r_symndx
- extsymoff
];
4279 /* This may be an indirect symbol created because of a version. */
4282 while (h
->root
.type
== bfd_link_hash_indirect
)
4283 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4287 /* Some relocs require a global offset table. */
4288 if (dynobj
== NULL
|| sgot
== NULL
)
4294 case R_MIPS_CALL_HI16
:
4295 case R_MIPS_CALL_LO16
:
4296 case R_MIPS_GOT_HI16
:
4297 case R_MIPS_GOT_LO16
:
4298 case R_MIPS_GOT_PAGE
:
4299 case R_MIPS_GOT_OFST
:
4300 case R_MIPS_GOT_DISP
:
4302 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4303 if (! mips_elf_create_got_section (dynobj
, info
))
4305 g
= mips_elf_got_info (dynobj
, &sgot
);
4312 && (info
->shared
|| h
!= NULL
)
4313 && (sec
->flags
& SEC_ALLOC
) != 0)
4314 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4322 if (!h
&& (r_type
== R_MIPS_CALL_LO16
4323 || r_type
== R_MIPS_GOT_LO16
4324 || r_type
== R_MIPS_GOT_DISP
))
4326 /* We may need a local GOT entry for this relocation. We
4327 don't count R_MIPS_GOT_PAGE because we can estimate the
4328 maximum number of pages needed by looking at the size of
4329 the segment. Similar comments apply to R_MIPS_GOT16 and
4330 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or
4331 R_MIPS_CALL_HI16 because these are always followed by an
4332 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16.
4334 This estimation is very conservative since we can merge
4335 duplicate entries in the GOT. In order to be less
4336 conservative, we could actually build the GOT here,
4337 rather than in relocate_section. */
4339 sgot
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
4347 (*_bfd_error_handler
)
4348 (_("%s: CALL16 reloc at 0x%lx not against global symbol"),
4349 bfd_archive_filename (abfd
), (unsigned long) rel
->r_offset
);
4350 bfd_set_error (bfd_error_bad_value
);
4355 case R_MIPS_CALL_HI16
:
4356 case R_MIPS_CALL_LO16
:
4359 /* This symbol requires a global offset table entry. */
4360 if (! mips_elf_record_global_got_symbol (h
, info
, g
))
4363 /* We need a stub, not a plt entry for the undefined
4364 function. But we record it as if it needs plt. See
4365 elf_adjust_dynamic_symbol in elflink.h. */
4366 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4372 case R_MIPS_GOT_HI16
:
4373 case R_MIPS_GOT_LO16
:
4374 case R_MIPS_GOT_DISP
:
4375 /* This symbol requires a global offset table entry. */
4376 if (h
&& ! mips_elf_record_global_got_symbol (h
, info
, g
))
4383 if ((info
->shared
|| h
!= NULL
)
4384 && (sec
->flags
& SEC_ALLOC
) != 0)
4388 const char *dname
= ".rel.dyn";
4390 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
4393 sreloc
= bfd_make_section (dynobj
, dname
);
4395 || ! bfd_set_section_flags (dynobj
, sreloc
,
4400 | SEC_LINKER_CREATED
4402 || ! bfd_set_section_alignment (dynobj
, sreloc
,
4407 #define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
4410 /* When creating a shared object, we must copy these
4411 reloc types into the output file as R_MIPS_REL32
4412 relocs. We make room for this reloc in the
4413 .rel.dyn reloc section. */
4414 mips_elf_allocate_dynamic_relocations (dynobj
, 1);
4415 if ((sec
->flags
& MIPS_READONLY_SECTION
)
4416 == MIPS_READONLY_SECTION
)
4417 /* We tell the dynamic linker that there are
4418 relocations against the text segment. */
4419 info
->flags
|= DF_TEXTREL
;
4423 struct mips_elf_link_hash_entry
*hmips
;
4425 /* We only need to copy this reloc if the symbol is
4426 defined in a dynamic object. */
4427 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4428 ++hmips
->possibly_dynamic_relocs
;
4429 if ((sec
->flags
& MIPS_READONLY_SECTION
)
4430 == MIPS_READONLY_SECTION
)
4431 /* We need it to tell the dynamic linker if there
4432 are relocations against the text segment. */
4433 hmips
->readonly_reloc
= true;
4436 /* Even though we don't directly need a GOT entry for
4437 this symbol, a symbol must have a dynamic symbol
4438 table index greater that DT_MIPS_GOTSYM if there are
4439 dynamic relocations against it. */
4441 && ! mips_elf_record_global_got_symbol (h
, info
, g
))
4445 if (SGI_COMPAT (abfd
))
4446 mips_elf_hash_table (info
)->compact_rel_size
+=
4447 sizeof (Elf32_External_crinfo
);
4451 case R_MIPS_GPREL16
:
4452 case R_MIPS_LITERAL
:
4453 case R_MIPS_GPREL32
:
4454 if (SGI_COMPAT (abfd
))
4455 mips_elf_hash_table (info
)->compact_rel_size
+=
4456 sizeof (Elf32_External_crinfo
);
4459 /* This relocation describes the C++ object vtable hierarchy.
4460 Reconstruct it for later use during GC. */
4461 case R_MIPS_GNU_VTINHERIT
:
4462 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4466 /* This relocation describes which C++ vtable entries are actually
4467 used. Record for later use during GC. */
4468 case R_MIPS_GNU_VTENTRY
:
4469 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
4477 /* We must not create a stub for a symbol that has relocations
4478 related to taking the function's address. */
4484 struct mips_elf_link_hash_entry
*mh
;
4486 mh
= (struct mips_elf_link_hash_entry
*) h
;
4487 mh
->no_fn_stub
= true;
4491 case R_MIPS_CALL_HI16
:
4492 case R_MIPS_CALL_LO16
:
4496 /* If this reloc is not a 16 bit call, and it has a global
4497 symbol, then we will need the fn_stub if there is one.
4498 References from a stub section do not count. */
4500 && r_type
!= R_MIPS16_26
4501 && strncmp (bfd_get_section_name (abfd
, sec
), FN_STUB
,
4502 sizeof FN_STUB
- 1) != 0
4503 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_STUB
,
4504 sizeof CALL_STUB
- 1) != 0
4505 && strncmp (bfd_get_section_name (abfd
, sec
), CALL_FP_STUB
,
4506 sizeof CALL_FP_STUB
- 1) != 0)
4508 struct mips_elf_link_hash_entry
*mh
;
4510 mh
= (struct mips_elf_link_hash_entry
*) h
;
4511 mh
->need_fn_stub
= true;
4518 /* Adjust a symbol defined by a dynamic object and referenced by a
4519 regular object. The current definition is in some section of the
4520 dynamic object, but we're not including those sections. We have to
4521 change the definition to something the rest of the link can
4525 _bfd_mips_elf_adjust_dynamic_symbol (info
, h
)
4526 struct bfd_link_info
*info
;
4527 struct elf_link_hash_entry
*h
;
4530 struct mips_elf_link_hash_entry
*hmips
;
4533 dynobj
= elf_hash_table (info
)->dynobj
;
4535 /* Make sure we know what is going on here. */
4536 BFD_ASSERT (dynobj
!= NULL
4537 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
4538 || h
->weakdef
!= NULL
4539 || ((h
->elf_link_hash_flags
4540 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4541 && (h
->elf_link_hash_flags
4542 & ELF_LINK_HASH_REF_REGULAR
) != 0
4543 && (h
->elf_link_hash_flags
4544 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
4546 /* If this symbol is defined in a dynamic object, we need to copy
4547 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
4549 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4550 if (! info
->relocateable
4551 && hmips
->possibly_dynamic_relocs
!= 0
4552 && (h
->root
.type
== bfd_link_hash_defweak
4553 || (h
->elf_link_hash_flags
4554 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4556 mips_elf_allocate_dynamic_relocations (dynobj
,
4557 hmips
->possibly_dynamic_relocs
);
4558 if (hmips
->readonly_reloc
)
4559 /* We tell the dynamic linker that there are relocations
4560 against the text segment. */
4561 info
->flags
|= DF_TEXTREL
;
4564 /* For a function, create a stub, if allowed. */
4565 if (! hmips
->no_fn_stub
4566 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4568 if (! elf_hash_table (info
)->dynamic_sections_created
)
4571 /* If this symbol is not defined in a regular file, then set
4572 the symbol to the stub location. This is required to make
4573 function pointers compare as equal between the normal
4574 executable and the shared library. */
4575 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4577 /* We need .stub section. */
4578 s
= bfd_get_section_by_name (dynobj
,
4579 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
4580 BFD_ASSERT (s
!= NULL
);
4582 h
->root
.u
.def
.section
= s
;
4583 h
->root
.u
.def
.value
= s
->_raw_size
;
4585 /* XXX Write this stub address somewhere. */
4586 h
->plt
.offset
= s
->_raw_size
;
4588 /* Make room for this stub code. */
4589 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4591 /* The last half word of the stub will be filled with the index
4592 of this symbol in .dynsym section. */
4596 else if ((h
->type
== STT_FUNC
)
4597 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
4599 /* This will set the entry for this symbol in the GOT to 0, and
4600 the dynamic linker will take care of this. */
4601 h
->root
.u
.def
.value
= 0;
4605 /* If this is a weak symbol, and there is a real definition, the
4606 processor independent code will have arranged for us to see the
4607 real definition first, and we can just use the same value. */
4608 if (h
->weakdef
!= NULL
)
4610 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4611 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4612 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4613 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4617 /* This is a reference to a symbol defined by a dynamic object which
4618 is not a function. */
4623 /* This function is called after all the input files have been read,
4624 and the input sections have been assigned to output sections. We
4625 check for any mips16 stub sections that we can discard. */
4628 _bfd_mips_elf_always_size_sections (output_bfd
, info
)
4630 struct bfd_link_info
*info
;
4634 /* The .reginfo section has a fixed size. */
4635 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
4637 bfd_set_section_size (output_bfd
, ri
,
4638 (bfd_size_type
) sizeof (Elf32_External_RegInfo
));
4640 if (info
->relocateable
4641 || ! mips_elf_hash_table (info
)->mips16_stubs_seen
)
4644 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
4645 mips_elf_check_mips16_stubs
,
4651 /* Set the sizes of the dynamic sections. */
4654 _bfd_mips_elf_size_dynamic_sections (output_bfd
, info
)
4656 struct bfd_link_info
*info
;
4661 struct mips_got_info
*g
= NULL
;
4663 dynobj
= elf_hash_table (info
)->dynobj
;
4664 BFD_ASSERT (dynobj
!= NULL
);
4666 if (elf_hash_table (info
)->dynamic_sections_created
)
4668 /* Set the contents of the .interp section to the interpreter. */
4671 s
= bfd_get_section_by_name (dynobj
, ".interp");
4672 BFD_ASSERT (s
!= NULL
);
4674 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
4676 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
4680 /* The check_relocs and adjust_dynamic_symbol entry points have
4681 determined the sizes of the various dynamic sections. Allocate
4684 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4689 /* It's OK to base decisions on the section name, because none
4690 of the dynobj section names depend upon the input files. */
4691 name
= bfd_get_section_name (dynobj
, s
);
4693 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4698 if (strncmp (name
, ".rel", 4) == 0)
4700 if (s
->_raw_size
== 0)
4702 /* We only strip the section if the output section name
4703 has the same name. Otherwise, there might be several
4704 input sections for this output section. FIXME: This
4705 code is probably not needed these days anyhow, since
4706 the linker now does not create empty output sections. */
4707 if (s
->output_section
!= NULL
4709 bfd_get_section_name (s
->output_section
->owner
,
4710 s
->output_section
)) == 0)
4715 const char *outname
;
4718 /* If this relocation section applies to a read only
4719 section, then we probably need a DT_TEXTREL entry.
4720 If the relocation section is .rel.dyn, we always
4721 assert a DT_TEXTREL entry rather than testing whether
4722 there exists a relocation to a read only section or
4724 outname
= bfd_get_section_name (output_bfd
,
4726 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
4728 && (target
->flags
& SEC_READONLY
) != 0
4729 && (target
->flags
& SEC_ALLOC
) != 0)
4730 || strcmp (outname
, ".rel.dyn") == 0)
4733 /* We use the reloc_count field as a counter if we need
4734 to copy relocs into the output file. */
4735 if (strcmp (name
, ".rel.dyn") != 0)
4739 else if (strncmp (name
, ".got", 4) == 0)
4742 bfd_size_type loadable_size
= 0;
4743 bfd_size_type local_gotno
;
4746 BFD_ASSERT (elf_section_data (s
) != NULL
);
4747 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
4748 BFD_ASSERT (g
!= NULL
);
4750 /* Calculate the total loadable size of the output. That
4751 will give us the maximum number of GOT_PAGE entries
4753 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
4755 asection
*subsection
;
4757 for (subsection
= sub
->sections
;
4759 subsection
= subsection
->next
)
4761 if ((subsection
->flags
& SEC_ALLOC
) == 0)
4763 loadable_size
+= ((subsection
->_raw_size
+ 0xf)
4764 &~ (bfd_size_type
) 0xf);
4767 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
4769 /* Assume there are two loadable segments consisting of
4770 contiguous sections. Is 5 enough? */
4771 local_gotno
= (loadable_size
>> 16) + 5;
4772 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
4773 /* It's possible we will need GOT_PAGE entries as well as
4774 GOT16 entries. Often, these will be able to share GOT
4775 entries, but not always. */
4778 g
->local_gotno
+= local_gotno
;
4779 s
->_raw_size
+= local_gotno
* MIPS_ELF_GOT_SIZE (dynobj
);
4781 /* There has to be a global GOT entry for every symbol with
4782 a dynamic symbol table index of DT_MIPS_GOTSYM or
4783 higher. Therefore, it make sense to put those symbols
4784 that need GOT entries at the end of the symbol table. We
4786 if (! mips_elf_sort_hash_table (info
, 1))
4789 if (g
->global_gotsym
!= NULL
)
4790 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
4792 /* If there are no global symbols, or none requiring
4793 relocations, then GLOBAL_GOTSYM will be NULL. */
4795 g
->global_gotno
= i
;
4796 s
->_raw_size
+= i
* MIPS_ELF_GOT_SIZE (dynobj
);
4798 else if (strcmp (name
, MIPS_ELF_STUB_SECTION_NAME (output_bfd
)) == 0)
4800 /* IRIX rld assumes that the function stub isn't at the end
4801 of .text section. So put a dummy. XXX */
4802 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
4804 else if (! info
->shared
4805 && ! mips_elf_hash_table (info
)->use_rld_obj_head
4806 && strncmp (name
, ".rld_map", 8) == 0)
4808 /* We add a room for __rld_map. It will be filled in by the
4809 rtld to contain a pointer to the _r_debug structure. */
4812 else if (SGI_COMPAT (output_bfd
)
4813 && strncmp (name
, ".compact_rel", 12) == 0)
4814 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
4815 else if (strcmp (name
, ".msym") == 0)
4816 s
->_raw_size
= (sizeof (Elf32_External_Msym
)
4817 * (elf_hash_table (info
)->dynsymcount
4818 + bfd_count_sections (output_bfd
)));
4819 else if (strncmp (name
, ".init", 5) != 0)
4821 /* It's not one of our sections, so don't allocate space. */
4827 _bfd_strip_section_from_output (info
, s
);
4831 /* Allocate memory for the section contents. */
4832 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4833 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
4835 bfd_set_error (bfd_error_no_memory
);
4840 if (elf_hash_table (info
)->dynamic_sections_created
)
4842 /* Add some entries to the .dynamic section. We fill in the
4843 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
4844 must add the entries now so that we get the correct size for
4845 the .dynamic section. The DT_DEBUG entry is filled in by the
4846 dynamic linker and used by the debugger. */
4849 /* SGI object has the equivalence of DT_DEBUG in the
4850 DT_MIPS_RLD_MAP entry. */
4851 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
4853 if (!SGI_COMPAT (output_bfd
))
4855 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
4861 /* Shared libraries on traditional mips have DT_DEBUG. */
4862 if (!SGI_COMPAT (output_bfd
))
4864 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
4869 if (reltext
&& SGI_COMPAT (output_bfd
))
4870 info
->flags
|= DF_TEXTREL
;
4872 if ((info
->flags
& DF_TEXTREL
) != 0)
4874 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
4878 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
4881 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
4883 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
4886 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
4889 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
4893 if (SGI_COMPAT (output_bfd
))
4895 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICTNO
, 0))
4899 if (SGI_COMPAT (output_bfd
))
4901 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLISTNO
, 0))
4905 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
4907 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_CONFLICT
, 0))
4910 s
= bfd_get_section_by_name (dynobj
, ".liblist");
4911 BFD_ASSERT (s
!= NULL
);
4913 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LIBLIST
, 0))
4917 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
4920 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
4924 /* Time stamps in executable files are a bad idea. */
4925 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_TIME_STAMP
, 0))
4930 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_ICHECKSUM
, 0))
4935 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_IVERSION
, 0))
4939 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
4942 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
4945 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
4948 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
4951 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
4954 if (IRIX_COMPAT (dynobj
) == ict_irix5
4955 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
4958 if (IRIX_COMPAT (dynobj
) == ict_irix6
4959 && (bfd_get_section_by_name
4960 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
4961 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
4964 if (bfd_get_section_by_name (dynobj
, ".msym")
4965 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_MSYM
, 0))
4972 /* Relocate a MIPS ELF section. */
4975 _bfd_mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4976 contents
, relocs
, local_syms
, local_sections
)
4978 struct bfd_link_info
*info
;
4980 asection
*input_section
;
4982 Elf_Internal_Rela
*relocs
;
4983 Elf_Internal_Sym
*local_syms
;
4984 asection
**local_sections
;
4986 Elf_Internal_Rela
*rel
;
4987 const Elf_Internal_Rela
*relend
;
4989 boolean use_saved_addend_p
= false;
4990 struct elf_backend_data
*bed
;
4992 bed
= get_elf_backend_data (output_bfd
);
4993 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
4994 for (rel
= relocs
; rel
< relend
; ++rel
)
4998 reloc_howto_type
*howto
;
4999 boolean require_jalx
;
5000 /* True if the relocation is a RELA relocation, rather than a
5002 boolean rela_relocation_p
= true;
5003 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5004 const char * msg
= (const char *) NULL
;
5006 /* Find the relocation howto for this relocation. */
5007 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
5009 /* Some 32-bit code uses R_MIPS_64. In particular, people use
5010 64-bit code, but make sure all their addresses are in the
5011 lowermost or uppermost 32-bit section of the 64-bit address
5012 space. Thus, when they use an R_MIPS_64 they mean what is
5013 usually meant by R_MIPS_32, with the exception that the
5014 stored value is sign-extended to 64 bits. */
5015 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, false);
5017 /* On big-endian systems, we need to lie about the position
5019 if (bfd_big_endian (input_bfd
))
5023 /* NewABI defaults to RELA relocations. */
5024 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
5025 NEWABI_P (input_bfd
));
5027 if (!use_saved_addend_p
)
5029 Elf_Internal_Shdr
*rel_hdr
;
5031 /* If these relocations were originally of the REL variety,
5032 we must pull the addend out of the field that will be
5033 relocated. Otherwise, we simply use the contents of the
5034 RELA relocation. To determine which flavor or relocation
5035 this is, we depend on the fact that the INPUT_SECTION's
5036 REL_HDR is read before its REL_HDR2. */
5037 rel_hdr
= &elf_section_data (input_section
)->rel_hdr
;
5038 if ((size_t) (rel
- relocs
)
5039 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
5040 rel_hdr
= elf_section_data (input_section
)->rel_hdr2
;
5041 if (rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (input_bfd
))
5043 /* Note that this is a REL relocation. */
5044 rela_relocation_p
= false;
5046 /* Get the addend, which is stored in the input file. */
5047 addend
= mips_elf_obtain_contents (howto
, rel
, input_bfd
,
5049 addend
&= howto
->src_mask
;
5050 addend
<<= howto
->rightshift
;
5052 /* For some kinds of relocations, the ADDEND is a
5053 combination of the addend stored in two different
5055 if (r_type
== R_MIPS_HI16
5056 || r_type
== R_MIPS_GNU_REL_HI16
5057 || (r_type
== R_MIPS_GOT16
5058 && mips_elf_local_relocation_p (input_bfd
, rel
,
5059 local_sections
, false)))
5062 const Elf_Internal_Rela
*lo16_relocation
;
5063 reloc_howto_type
*lo16_howto
;
5066 /* The combined value is the sum of the HI16 addend,
5067 left-shifted by sixteen bits, and the LO16
5068 addend, sign extended. (Usually, the code does
5069 a `lui' of the HI16 value, and then an `addiu' of
5072 Scan ahead to find a matching LO16 relocation. */
5073 if (r_type
== R_MIPS_GNU_REL_HI16
)
5074 lo
= R_MIPS_GNU_REL_LO16
;
5077 lo16_relocation
= mips_elf_next_relocation (input_bfd
, lo
,
5079 if (lo16_relocation
== NULL
)
5082 /* Obtain the addend kept there. */
5083 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, lo
, false);
5084 l
= mips_elf_obtain_contents (lo16_howto
, lo16_relocation
,
5085 input_bfd
, contents
);
5086 l
&= lo16_howto
->src_mask
;
5087 l
<<= lo16_howto
->rightshift
;
5088 l
= mips_elf_sign_extend (l
, 16);
5092 /* Compute the combined addend. */
5095 /* If PC-relative, subtract the difference between the
5096 address of the LO part of the reloc and the address of
5097 the HI part. The relocation is relative to the LO
5098 part, but mips_elf_calculate_relocation() doesn't
5099 know its address or the difference from the HI part, so
5100 we subtract that difference here. See also the
5101 comment in mips_elf_calculate_relocation(). */
5102 if (r_type
== R_MIPS_GNU_REL_HI16
)
5103 addend
-= (lo16_relocation
->r_offset
- rel
->r_offset
);
5105 else if (r_type
== R_MIPS16_GPREL
)
5107 /* The addend is scrambled in the object file. See
5108 mips_elf_perform_relocation for details on the
5110 addend
= (((addend
& 0x1f0000) >> 5)
5111 | ((addend
& 0x7e00000) >> 16)
5116 addend
= rel
->r_addend
;
5119 if (info
->relocateable
)
5121 Elf_Internal_Sym
*sym
;
5122 unsigned long r_symndx
;
5124 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
)
5125 && bfd_big_endian (input_bfd
))
5128 /* Since we're just relocating, all we need to do is copy
5129 the relocations back out to the object file, unless
5130 they're against a section symbol, in which case we need
5131 to adjust by the section offset, or unless they're GP
5132 relative in which case we need to adjust by the amount
5133 that we're adjusting GP in this relocateable object. */
5135 if (! mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
,
5137 /* There's nothing to do for non-local relocations. */
5140 if (r_type
== R_MIPS16_GPREL
5141 || r_type
== R_MIPS_GPREL16
5142 || r_type
== R_MIPS_GPREL32
5143 || r_type
== R_MIPS_LITERAL
)
5144 addend
-= (_bfd_get_gp_value (output_bfd
)
5145 - _bfd_get_gp_value (input_bfd
));
5147 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
5148 sym
= local_syms
+ r_symndx
;
5149 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
5150 /* Adjust the addend appropriately. */
5151 addend
+= local_sections
[r_symndx
]->output_offset
;
5153 if (howto
->partial_inplace
)
5155 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16,
5156 then we only want to write out the high-order 16 bits.
5157 The subsequent R_MIPS_LO16 will handle the low-order bits.
5159 if (r_type
== R_MIPS_HI16
|| r_type
== R_MIPS_GOT16
5160 || r_type
== R_MIPS_GNU_REL_HI16
)
5161 addend
= mips_elf_high (addend
);
5162 else if (r_type
== R_MIPS_HIGHER
)
5163 addend
= mips_elf_higher (addend
);
5164 else if (r_type
== R_MIPS_HIGHEST
)
5165 addend
= mips_elf_highest (addend
);
5168 if (rela_relocation_p
)
5169 /* If this is a RELA relocation, just update the addend.
5170 We have to cast away constness for REL. */
5171 rel
->r_addend
= addend
;
5174 /* Otherwise, we have to write the value back out. Note
5175 that we use the source mask, rather than the
5176 destination mask because the place to which we are
5177 writing will be source of the addend in the final
5179 addend
>>= howto
->rightshift
;
5180 addend
&= howto
->src_mask
;
5182 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
5183 /* See the comment above about using R_MIPS_64 in the 32-bit
5184 ABI. Here, we need to update the addend. It would be
5185 possible to get away with just using the R_MIPS_32 reloc
5186 but for endianness. */
5192 if (addend
& ((bfd_vma
) 1 << 31))
5194 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
5201 /* If we don't know that we have a 64-bit type,
5202 do two separate stores. */
5203 if (bfd_big_endian (input_bfd
))
5205 /* Store the sign-bits (which are most significant)
5207 low_bits
= sign_bits
;
5213 high_bits
= sign_bits
;
5215 bfd_put_32 (input_bfd
, low_bits
,
5216 contents
+ rel
->r_offset
);
5217 bfd_put_32 (input_bfd
, high_bits
,
5218 contents
+ rel
->r_offset
+ 4);
5222 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
5223 input_bfd
, input_section
,
5228 /* Go on to the next relocation. */
5232 /* In the N32 and 64-bit ABIs there may be multiple consecutive
5233 relocations for the same offset. In that case we are
5234 supposed to treat the output of each relocation as the addend
5236 if (rel
+ 1 < relend
5237 && rel
->r_offset
== rel
[1].r_offset
5238 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
5239 use_saved_addend_p
= true;
5241 use_saved_addend_p
= false;
5243 addend
>>= howto
->rightshift
;
5245 /* Figure out what value we are supposed to relocate. */
5246 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
5247 input_section
, info
, rel
,
5248 addend
, howto
, local_syms
,
5249 local_sections
, &value
,
5250 &name
, &require_jalx
))
5252 case bfd_reloc_continue
:
5253 /* There's nothing to do. */
5256 case bfd_reloc_undefined
:
5257 /* mips_elf_calculate_relocation already called the
5258 undefined_symbol callback. There's no real point in
5259 trying to perform the relocation at this point, so we
5260 just skip ahead to the next relocation. */
5263 case bfd_reloc_notsupported
:
5264 msg
= _("internal error: unsupported relocation error");
5265 info
->callbacks
->warning
5266 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
5269 case bfd_reloc_overflow
:
5270 if (use_saved_addend_p
)
5271 /* Ignore overflow until we reach the last relocation for
5272 a given location. */
5276 BFD_ASSERT (name
!= NULL
);
5277 if (! ((*info
->callbacks
->reloc_overflow
)
5278 (info
, name
, howto
->name
, (bfd_vma
) 0,
5279 input_bfd
, input_section
, rel
->r_offset
)))
5292 /* If we've got another relocation for the address, keep going
5293 until we reach the last one. */
5294 if (use_saved_addend_p
)
5300 if (r_type
== R_MIPS_64
&& !ABI_64_P (output_bfd
))
5301 /* See the comment above about using R_MIPS_64 in the 32-bit
5302 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
5303 that calculated the right value. Now, however, we
5304 sign-extend the 32-bit result to 64-bits, and store it as a
5305 64-bit value. We are especially generous here in that we
5306 go to extreme lengths to support this usage on systems with
5307 only a 32-bit VMA. */
5313 if (value
& ((bfd_vma
) 1 << 31))
5315 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
5322 /* If we don't know that we have a 64-bit type,
5323 do two separate stores. */
5324 if (bfd_big_endian (input_bfd
))
5326 /* Undo what we did above. */
5328 /* Store the sign-bits (which are most significant)
5330 low_bits
= sign_bits
;
5336 high_bits
= sign_bits
;
5338 bfd_put_32 (input_bfd
, low_bits
,
5339 contents
+ rel
->r_offset
);
5340 bfd_put_32 (input_bfd
, high_bits
,
5341 contents
+ rel
->r_offset
+ 4);
5345 /* Actually perform the relocation. */
5346 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
5347 input_bfd
, input_section
,
5348 contents
, require_jalx
))
5355 /* If NAME is one of the special IRIX6 symbols defined by the linker,
5356 adjust it appropriately now. */
5359 mips_elf_irix6_finish_dynamic_symbol (abfd
, name
, sym
)
5360 bfd
*abfd ATTRIBUTE_UNUSED
;
5362 Elf_Internal_Sym
*sym
;
5364 /* The linker script takes care of providing names and values for
5365 these, but we must place them into the right sections. */
5366 static const char* const text_section_symbols
[] = {
5369 "__dso_displacement",
5371 "__program_header_table",
5375 static const char* const data_section_symbols
[] = {
5383 const char* const *p
;
5386 for (i
= 0; i
< 2; ++i
)
5387 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
5390 if (strcmp (*p
, name
) == 0)
5392 /* All of these symbols are given type STT_SECTION by the
5394 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5396 /* The IRIX linker puts these symbols in special sections. */
5398 sym
->st_shndx
= SHN_MIPS_TEXT
;
5400 sym
->st_shndx
= SHN_MIPS_DATA
;
5406 /* Finish up dynamic symbol handling. We set the contents of various
5407 dynamic sections here. */
5410 _bfd_mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5412 struct bfd_link_info
*info
;
5413 struct elf_link_hash_entry
*h
;
5414 Elf_Internal_Sym
*sym
;
5420 struct mips_got_info
*g
;
5422 struct mips_elf_link_hash_entry
*mh
;
5424 dynobj
= elf_hash_table (info
)->dynobj
;
5425 gval
= sym
->st_value
;
5426 mh
= (struct mips_elf_link_hash_entry
*) h
;
5428 if (h
->plt
.offset
!= (bfd_vma
) -1)
5431 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5433 /* This symbol has a stub. Set it up. */
5435 BFD_ASSERT (h
->dynindx
!= -1);
5437 s
= bfd_get_section_by_name (dynobj
,
5438 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
5439 BFD_ASSERT (s
!= NULL
);
5441 /* FIXME: Can h->dynindex be more than 64K? */
5442 if (h
->dynindx
& 0xffff0000)
5445 /* Fill the stub. */
5446 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
);
5447 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ 4);
5448 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ 8);
5449 bfd_put_32 (output_bfd
, STUB_LI16 (output_bfd
) + h
->dynindx
, stub
+ 12);
5451 BFD_ASSERT (h
->plt
.offset
<= s
->_raw_size
);
5452 memcpy (s
->contents
+ h
->plt
.offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5454 /* Mark the symbol as undefined. plt.offset != -1 occurs
5455 only for the referenced symbol. */
5456 sym
->st_shndx
= SHN_UNDEF
;
5458 /* The run-time linker uses the st_value field of the symbol
5459 to reset the global offset table entry for this external
5460 to its stub address when unlinking a shared object. */
5461 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
;
5462 sym
->st_value
= gval
;
5465 BFD_ASSERT (h
->dynindx
!= -1
5466 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0);
5468 sgot
= mips_elf_got_section (dynobj
);
5469 BFD_ASSERT (sgot
!= NULL
);
5470 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5471 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5472 BFD_ASSERT (g
!= NULL
);
5474 /* Run through the global symbol table, creating GOT entries for all
5475 the symbols that need them. */
5476 if (g
->global_gotsym
!= NULL
5477 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
5483 value
= sym
->st_value
;
5486 /* For an entity defined in a shared object, this will be
5487 NULL. (For functions in shared objects for
5488 which we have created stubs, ST_VALUE will be non-NULL.
5489 That's because such the functions are now no longer defined
5490 in a shared object.) */
5492 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
5495 value
= h
->root
.u
.def
.value
;
5497 offset
= mips_elf_global_got_index (dynobj
, h
);
5498 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
5501 /* Create a .msym entry, if appropriate. */
5502 smsym
= bfd_get_section_by_name (dynobj
, ".msym");
5505 Elf32_Internal_Msym msym
;
5507 msym
.ms_hash_value
= bfd_elf_hash (h
->root
.root
.string
);
5508 /* It is undocumented what the `1' indicates, but IRIX6 uses
5510 msym
.ms_info
= ELF32_MS_INFO (mh
->min_dyn_reloc_index
, 1);
5511 bfd_mips_elf_swap_msym_out
5513 ((Elf32_External_Msym
*) smsym
->contents
) + h
->dynindx
);
5516 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5517 name
= h
->root
.root
.string
;
5518 if (strcmp (name
, "_DYNAMIC") == 0
5519 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5520 sym
->st_shndx
= SHN_ABS
;
5521 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
5522 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
5524 sym
->st_shndx
= SHN_ABS
;
5525 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5528 else if (strcmp (name
, "_gp_disp") == 0)
5530 sym
->st_shndx
= SHN_ABS
;
5531 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5532 sym
->st_value
= elf_gp (output_bfd
);
5534 else if (SGI_COMPAT (output_bfd
))
5536 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
5537 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
5539 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5540 sym
->st_other
= STO_PROTECTED
;
5542 sym
->st_shndx
= SHN_MIPS_DATA
;
5544 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
5546 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5547 sym
->st_other
= STO_PROTECTED
;
5548 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
5549 sym
->st_shndx
= SHN_ABS
;
5551 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
5553 if (h
->type
== STT_FUNC
)
5554 sym
->st_shndx
= SHN_MIPS_TEXT
;
5555 else if (h
->type
== STT_OBJECT
)
5556 sym
->st_shndx
= SHN_MIPS_DATA
;
5560 /* Handle the IRIX6-specific symbols. */
5561 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
5562 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
5566 if (! mips_elf_hash_table (info
)->use_rld_obj_head
5567 && (strcmp (name
, "__rld_map") == 0
5568 || strcmp (name
, "__RLD_MAP") == 0))
5570 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
5571 BFD_ASSERT (s
!= NULL
);
5572 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
5573 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
5574 if (mips_elf_hash_table (info
)->rld_value
== 0)
5575 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5577 else if (mips_elf_hash_table (info
)->use_rld_obj_head
5578 && strcmp (name
, "__rld_obj_head") == 0)
5580 /* IRIX6 does not use a .rld_map section. */
5581 if (IRIX_COMPAT (output_bfd
) == ict_irix5
5582 || IRIX_COMPAT (output_bfd
) == ict_none
)
5583 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
5585 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5589 /* If this is a mips16 symbol, force the value to be even. */
5590 if (sym
->st_other
== STO_MIPS16
5591 && (sym
->st_value
& 1) != 0)
5597 /* Finish up the dynamic sections. */
5600 _bfd_mips_elf_finish_dynamic_sections (output_bfd
, info
)
5602 struct bfd_link_info
*info
;
5607 struct mips_got_info
*g
;
5609 dynobj
= elf_hash_table (info
)->dynobj
;
5611 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5613 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5618 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5619 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5620 BFD_ASSERT (g
!= NULL
);
5623 if (elf_hash_table (info
)->dynamic_sections_created
)
5627 BFD_ASSERT (sdyn
!= NULL
);
5628 BFD_ASSERT (g
!= NULL
);
5630 for (b
= sdyn
->contents
;
5631 b
< sdyn
->contents
+ sdyn
->_raw_size
;
5632 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
5634 Elf_Internal_Dyn dyn
;
5640 /* Read in the current dynamic entry. */
5641 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
5643 /* Assume that we're going to modify it and write it out. */
5649 s
= (bfd_get_section_by_name (dynobj
, ".rel.dyn"));
5650 BFD_ASSERT (s
!= NULL
);
5651 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
5655 /* Rewrite DT_STRSZ. */
5657 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
5663 case DT_MIPS_CONFLICT
:
5666 case DT_MIPS_LIBLIST
:
5669 s
= bfd_get_section_by_name (output_bfd
, name
);
5670 BFD_ASSERT (s
!= NULL
);
5671 dyn
.d_un
.d_ptr
= s
->vma
;
5674 case DT_MIPS_RLD_VERSION
:
5675 dyn
.d_un
.d_val
= 1; /* XXX */
5679 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5682 case DT_MIPS_CONFLICTNO
:
5684 elemsize
= sizeof (Elf32_Conflict
);
5687 case DT_MIPS_LIBLISTNO
:
5689 elemsize
= sizeof (Elf32_Lib
);
5691 s
= bfd_get_section_by_name (output_bfd
, name
);
5694 if (s
->_cooked_size
!= 0)
5695 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5697 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5703 case DT_MIPS_TIME_STAMP
:
5704 time ((time_t *) &dyn
.d_un
.d_val
);
5707 case DT_MIPS_ICHECKSUM
:
5712 case DT_MIPS_IVERSION
:
5717 case DT_MIPS_BASE_ADDRESS
:
5718 s
= output_bfd
->sections
;
5719 BFD_ASSERT (s
!= NULL
);
5720 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
5723 case DT_MIPS_LOCAL_GOTNO
:
5724 dyn
.d_un
.d_val
= g
->local_gotno
;
5727 case DT_MIPS_UNREFEXTNO
:
5728 /* The index into the dynamic symbol table which is the
5729 entry of the first external symbol that is not
5730 referenced within the same object. */
5731 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
5734 case DT_MIPS_GOTSYM
:
5735 if (g
->global_gotsym
)
5737 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
5740 /* In case if we don't have global got symbols we default
5741 to setting DT_MIPS_GOTSYM to the same value as
5742 DT_MIPS_SYMTABNO, so we just fall through. */
5744 case DT_MIPS_SYMTABNO
:
5746 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
5747 s
= bfd_get_section_by_name (output_bfd
, name
);
5748 BFD_ASSERT (s
!= NULL
);
5750 if (s
->_cooked_size
!= 0)
5751 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5753 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5756 case DT_MIPS_HIPAGENO
:
5757 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
5760 case DT_MIPS_RLD_MAP
:
5761 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
5764 case DT_MIPS_OPTIONS
:
5765 s
= (bfd_get_section_by_name
5766 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
5767 dyn
.d_un
.d_ptr
= s
->vma
;
5771 s
= (bfd_get_section_by_name (output_bfd
, ".msym"));
5772 dyn
.d_un
.d_ptr
= s
->vma
;
5781 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
5786 /* The first entry of the global offset table will be filled at
5787 runtime. The second entry will be used by some runtime loaders.
5788 This isn't the case of IRIX rld. */
5789 if (sgot
!= NULL
&& sgot
->_raw_size
> 0)
5791 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5792 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0x80000000,
5793 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
5797 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
5798 = MIPS_ELF_GOT_SIZE (output_bfd
);
5803 Elf32_compact_rel cpt
;
5805 /* ??? The section symbols for the output sections were set up in
5806 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these
5807 symbols. Should we do so? */
5809 smsym
= bfd_get_section_by_name (dynobj
, ".msym");
5812 Elf32_Internal_Msym msym
;
5814 msym
.ms_hash_value
= 0;
5815 msym
.ms_info
= ELF32_MS_INFO (0, 1);
5817 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
5819 long dynindx
= elf_section_data (s
)->dynindx
;
5821 bfd_mips_elf_swap_msym_out
5823 (((Elf32_External_Msym
*) smsym
->contents
)
5828 if (SGI_COMPAT (output_bfd
))
5830 /* Write .compact_rel section out. */
5831 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5835 cpt
.num
= s
->reloc_count
;
5837 cpt
.offset
= (s
->output_section
->filepos
5838 + sizeof (Elf32_External_compact_rel
));
5841 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
5842 ((Elf32_External_compact_rel
*)
5845 /* Clean up a dummy stub function entry in .text. */
5846 s
= bfd_get_section_by_name (dynobj
,
5847 MIPS_ELF_STUB_SECTION_NAME (dynobj
));
5850 file_ptr dummy_offset
;
5852 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
5853 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
5854 memset (s
->contents
+ dummy_offset
, 0,
5855 MIPS_FUNCTION_STUB_SIZE
);
5860 /* We need to sort the entries of the dynamic relocation section. */
5862 if (!ABI_64_P (output_bfd
))
5866 reldyn
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5867 if (reldyn
!= NULL
&& reldyn
->reloc_count
> 2)
5869 reldyn_sorting_bfd
= output_bfd
;
5870 qsort ((Elf32_External_Rel
*) reldyn
->contents
+ 1,
5871 (size_t) reldyn
->reloc_count
- 1,
5872 sizeof (Elf32_External_Rel
), sort_dynamic_relocs
);
5876 /* Clean up a first relocation in .rel.dyn. */
5877 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5878 if (s
!= NULL
&& s
->_raw_size
> 0)
5879 memset (s
->contents
, 0, MIPS_ELF_REL_SIZE (dynobj
));
5885 /* The final processing done just before writing out a MIPS ELF object
5886 file. This gets the MIPS architecture right based on the machine
5887 number. This is used by both the 32-bit and the 64-bit ABI. */
5890 _bfd_mips_elf_final_write_processing (abfd
, linker
)
5892 boolean linker ATTRIBUTE_UNUSED
;
5896 Elf_Internal_Shdr
**hdrpp
;
5900 switch (bfd_get_mach (abfd
))
5903 case bfd_mach_mips3000
:
5904 val
= E_MIPS_ARCH_1
;
5907 case bfd_mach_mips3900
:
5908 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
5911 case bfd_mach_mips6000
:
5912 val
= E_MIPS_ARCH_2
;
5915 case bfd_mach_mips4000
:
5916 case bfd_mach_mips4300
:
5917 case bfd_mach_mips4400
:
5918 case bfd_mach_mips4600
:
5919 val
= E_MIPS_ARCH_3
;
5922 case bfd_mach_mips4010
:
5923 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
5926 case bfd_mach_mips4100
:
5927 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
5930 case bfd_mach_mips4111
:
5931 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
5934 case bfd_mach_mips4650
:
5935 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
5938 case bfd_mach_mips5000
:
5939 case bfd_mach_mips8000
:
5940 case bfd_mach_mips10000
:
5941 case bfd_mach_mips12000
:
5942 val
= E_MIPS_ARCH_4
;
5945 case bfd_mach_mips5
:
5946 val
= E_MIPS_ARCH_5
;
5949 case bfd_mach_mips_sb1
:
5950 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
5953 case bfd_mach_mipsisa32
:
5954 val
= E_MIPS_ARCH_32
;
5957 case bfd_mach_mipsisa64
:
5958 val
= E_MIPS_ARCH_64
;
5961 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
5962 elf_elfheader (abfd
)->e_flags
|= val
;
5964 /* Set the sh_info field for .gptab sections and other appropriate
5965 info for each special section. */
5966 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
5967 i
< elf_numsections (abfd
);
5970 switch ((*hdrpp
)->sh_type
)
5973 case SHT_MIPS_LIBLIST
:
5974 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
5976 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
5979 case SHT_MIPS_GPTAB
:
5980 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
5981 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
5982 BFD_ASSERT (name
!= NULL
5983 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
5984 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
5985 BFD_ASSERT (sec
!= NULL
);
5986 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
5989 case SHT_MIPS_CONTENT
:
5990 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
5991 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
5992 BFD_ASSERT (name
!= NULL
5993 && strncmp (name
, ".MIPS.content",
5994 sizeof ".MIPS.content" - 1) == 0);
5995 sec
= bfd_get_section_by_name (abfd
,
5996 name
+ sizeof ".MIPS.content" - 1);
5997 BFD_ASSERT (sec
!= NULL
);
5998 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6001 case SHT_MIPS_SYMBOL_LIB
:
6002 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
6004 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6005 sec
= bfd_get_section_by_name (abfd
, ".liblist");
6007 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
6010 case SHT_MIPS_EVENTS
:
6011 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
6012 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
6013 BFD_ASSERT (name
!= NULL
);
6014 if (strncmp (name
, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0)
6015 sec
= bfd_get_section_by_name (abfd
,
6016 name
+ sizeof ".MIPS.events" - 1);
6019 BFD_ASSERT (strncmp (name
, ".MIPS.post_rel",
6020 sizeof ".MIPS.post_rel" - 1) == 0);
6021 sec
= bfd_get_section_by_name (abfd
,
6023 + sizeof ".MIPS.post_rel" - 1));
6025 BFD_ASSERT (sec
!= NULL
);
6026 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
6033 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
6037 _bfd_mips_elf_additional_program_headers (abfd
)
6043 /* See if we need a PT_MIPS_REGINFO segment. */
6044 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6045 if (s
&& (s
->flags
& SEC_LOAD
))
6048 /* See if we need a PT_MIPS_OPTIONS segment. */
6049 if (IRIX_COMPAT (abfd
) == ict_irix6
6050 && bfd_get_section_by_name (abfd
,
6051 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
6054 /* See if we need a PT_MIPS_RTPROC segment. */
6055 if (IRIX_COMPAT (abfd
) == ict_irix5
6056 && bfd_get_section_by_name (abfd
, ".dynamic")
6057 && bfd_get_section_by_name (abfd
, ".mdebug"))
6063 /* Modify the segment map for an IRIX5 executable. */
6066 _bfd_mips_elf_modify_segment_map (abfd
)
6070 struct elf_segment_map
*m
, **pm
;
6073 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
6075 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6076 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
6078 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
6079 if (m
->p_type
== PT_MIPS_REGINFO
)
6084 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6088 m
->p_type
= PT_MIPS_REGINFO
;
6092 /* We want to put it after the PHDR and INTERP segments. */
6093 pm
= &elf_tdata (abfd
)->segment_map
;
6095 && ((*pm
)->p_type
== PT_PHDR
6096 || (*pm
)->p_type
== PT_INTERP
))
6104 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
6105 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
6106 PT_OPTIONS segement immediately following the program header
6108 if (IRIX_COMPAT (abfd
) == ict_irix6
)
6110 for (s
= abfd
->sections
; s
; s
= s
->next
)
6111 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
6116 struct elf_segment_map
*options_segment
;
6118 /* Usually, there's a program header table. But, sometimes
6119 there's not (like when running the `ld' testsuite). So,
6120 if there's no program header table, we just put the
6121 options segement at the end. */
6122 for (pm
= &elf_tdata (abfd
)->segment_map
;
6125 if ((*pm
)->p_type
== PT_PHDR
)
6128 amt
= sizeof (struct elf_segment_map
);
6129 options_segment
= bfd_zalloc (abfd
, amt
);
6130 options_segment
->next
= *pm
;
6131 options_segment
->p_type
= PT_MIPS_OPTIONS
;
6132 options_segment
->p_flags
= PF_R
;
6133 options_segment
->p_flags_valid
= true;
6134 options_segment
->count
= 1;
6135 options_segment
->sections
[0] = s
;
6136 *pm
= options_segment
;
6141 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6143 /* If there are .dynamic and .mdebug sections, we make a room
6144 for the RTPROC header. FIXME: Rewrite without section names. */
6145 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
6146 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
6147 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
6149 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
6150 if (m
->p_type
== PT_MIPS_RTPROC
)
6155 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6159 m
->p_type
= PT_MIPS_RTPROC
;
6161 s
= bfd_get_section_by_name (abfd
, ".rtproc");
6166 m
->p_flags_valid
= 1;
6174 /* We want to put it after the DYNAMIC segment. */
6175 pm
= &elf_tdata (abfd
)->segment_map
;
6176 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
6186 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
6187 .dynstr, .dynsym, and .hash sections, and everything in
6189 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
6191 if ((*pm
)->p_type
== PT_DYNAMIC
)
6194 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
6196 /* For a normal mips executable the permissions for the PT_DYNAMIC
6197 segment are read, write and execute. We do that here since
6198 the code in elf.c sets only the read permission. This matters
6199 sometimes for the dynamic linker. */
6200 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
6202 m
->p_flags
= PF_R
| PF_W
| PF_X
;
6203 m
->p_flags_valid
= 1;
6207 && m
->count
== 1 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
6209 static const char *sec_names
[] =
6211 ".dynamic", ".dynstr", ".dynsym", ".hash"
6215 struct elf_segment_map
*n
;
6219 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
6221 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
6222 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
6228 sz
= s
->_cooked_size
;
6231 if (high
< s
->vma
+ sz
)
6237 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
6238 if ((s
->flags
& SEC_LOAD
) != 0
6241 + (s
->_cooked_size
!=
6242 0 ? s
->_cooked_size
: s
->_raw_size
)) <= high
))
6245 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
6246 n
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
6253 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
6255 if ((s
->flags
& SEC_LOAD
) != 0
6258 + (s
->_cooked_size
!= 0 ?
6259 s
->_cooked_size
: s
->_raw_size
)) <= high
))
6273 /* Return the section that should be marked against GC for a given
6277 _bfd_mips_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
6279 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
6280 Elf_Internal_Rela
*rel
;
6281 struct elf_link_hash_entry
*h
;
6282 Elf_Internal_Sym
*sym
;
6284 /* ??? Do mips16 stub sections need to be handled special? */
6288 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
6290 case R_MIPS_GNU_VTINHERIT
:
6291 case R_MIPS_GNU_VTENTRY
:
6295 switch (h
->root
.type
)
6297 case bfd_link_hash_defined
:
6298 case bfd_link_hash_defweak
:
6299 return h
->root
.u
.def
.section
;
6301 case bfd_link_hash_common
:
6302 return h
->root
.u
.c
.p
->section
;
6310 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6315 /* Update the got entry reference counts for the section being removed. */
6318 _bfd_mips_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
6319 bfd
*abfd ATTRIBUTE_UNUSED
;
6320 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
6321 asection
*sec ATTRIBUTE_UNUSED
;
6322 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
6325 Elf_Internal_Shdr
*symtab_hdr
;
6326 struct elf_link_hash_entry
**sym_hashes
;
6327 bfd_signed_vma
*local_got_refcounts
;
6328 const Elf_Internal_Rela
*rel
, *relend
;
6329 unsigned long r_symndx
;
6330 struct elf_link_hash_entry
*h
;
6332 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6333 sym_hashes
= elf_sym_hashes (abfd
);
6334 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6336 relend
= relocs
+ sec
->reloc_count
;
6337 for (rel
= relocs
; rel
< relend
; rel
++)
6338 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
6342 case R_MIPS_CALL_HI16
:
6343 case R_MIPS_CALL_LO16
:
6344 case R_MIPS_GOT_HI16
:
6345 case R_MIPS_GOT_LO16
:
6346 /* ??? It would seem that the existing MIPS code does no sort
6347 of reference counting or whatnot on its GOT and PLT entries,
6348 so it is not possible to garbage collect them at this time. */
6359 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
6360 hiding the old indirect symbol. Process additional relocation
6361 information. Also called for weakdefs, in which case we just let
6362 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
6365 _bfd_mips_elf_copy_indirect_symbol (dir
, ind
)
6366 struct elf_link_hash_entry
*dir
, *ind
;
6368 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
6370 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
6372 if (ind
->root
.type
!= bfd_link_hash_indirect
)
6375 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
6376 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
6377 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
6378 if (indmips
->readonly_reloc
)
6379 dirmips
->readonly_reloc
= true;
6380 if (dirmips
->min_dyn_reloc_index
== 0
6381 || (indmips
->min_dyn_reloc_index
!= 0
6382 && indmips
->min_dyn_reloc_index
< dirmips
->min_dyn_reloc_index
))
6383 dirmips
->min_dyn_reloc_index
= indmips
->min_dyn_reloc_index
;
6384 if (indmips
->no_fn_stub
)
6385 dirmips
->no_fn_stub
= true;
6389 _bfd_mips_elf_hide_symbol (info
, entry
, force_local
)
6390 struct bfd_link_info
*info
;
6391 struct elf_link_hash_entry
*entry
;
6392 boolean force_local
;
6396 struct mips_got_info
*g
;
6397 struct mips_elf_link_hash_entry
*h
;
6399 h
= (struct mips_elf_link_hash_entry
*) entry
;
6400 if (h
->forced_local
)
6402 h
->forced_local
= true;
6404 dynobj
= elf_hash_table (info
)->dynobj
;
6405 got
= bfd_get_section_by_name (dynobj
, ".got");
6406 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
6408 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
6410 /* FIXME: Do we allocate too much GOT space here? */
6412 got
->_raw_size
+= MIPS_ELF_GOT_SIZE (dynobj
);
6416 _bfd_mips_elf_ignore_discarded_relocs (sec
)
6419 if (strcmp (sec
->name
, ".pdr") == 0)
6424 /* MIPS ELF uses a special find_nearest_line routine in order the
6425 handle the ECOFF debugging information. */
6427 struct mips_elf_find_line
6429 struct ecoff_debug_info d
;
6430 struct ecoff_find_line i
;
6434 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
6435 functionname_ptr
, line_ptr
)
6440 const char **filename_ptr
;
6441 const char **functionname_ptr
;
6442 unsigned int *line_ptr
;
6446 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
6447 filename_ptr
, functionname_ptr
,
6451 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
6452 filename_ptr
, functionname_ptr
,
6454 (unsigned) (ABI_64_P (abfd
) ? 8 : 0),
6455 &elf_tdata (abfd
)->dwarf2_find_line_info
))
6458 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
6462 struct mips_elf_find_line
*fi
;
6463 const struct ecoff_debug_swap
* const swap
=
6464 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
6466 /* If we are called during a link, mips_elf_final_link may have
6467 cleared the SEC_HAS_CONTENTS field. We force it back on here
6468 if appropriate (which it normally will be). */
6469 origflags
= msec
->flags
;
6470 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
6471 msec
->flags
|= SEC_HAS_CONTENTS
;
6473 fi
= elf_tdata (abfd
)->find_line_info
;
6476 bfd_size_type external_fdr_size
;
6479 struct fdr
*fdr_ptr
;
6480 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
6482 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
6485 msec
->flags
= origflags
;
6489 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
6491 msec
->flags
= origflags
;
6495 /* Swap in the FDR information. */
6496 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
6497 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
6498 if (fi
->d
.fdr
== NULL
)
6500 msec
->flags
= origflags
;
6503 external_fdr_size
= swap
->external_fdr_size
;
6504 fdr_ptr
= fi
->d
.fdr
;
6505 fraw_src
= (char *) fi
->d
.external_fdr
;
6506 fraw_end
= (fraw_src
6507 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
6508 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
6509 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
6511 elf_tdata (abfd
)->find_line_info
= fi
;
6513 /* Note that we don't bother to ever free this information.
6514 find_nearest_line is either called all the time, as in
6515 objdump -l, so the information should be saved, or it is
6516 rarely called, as in ld error messages, so the memory
6517 wasted is unimportant. Still, it would probably be a
6518 good idea for free_cached_info to throw it away. */
6521 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
6522 &fi
->i
, filename_ptr
, functionname_ptr
,
6525 msec
->flags
= origflags
;
6529 msec
->flags
= origflags
;
6532 /* Fall back on the generic ELF find_nearest_line routine. */
6534 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
6535 filename_ptr
, functionname_ptr
,
6539 /* When are writing out the .options or .MIPS.options section,
6540 remember the bytes we are writing out, so that we can install the
6541 GP value in the section_processing routine. */
6544 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
6549 bfd_size_type count
;
6551 if (strcmp (section
->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
6555 if (elf_section_data (section
) == NULL
)
6557 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
6558 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
6559 if (elf_section_data (section
) == NULL
)
6562 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
6567 if (section
->_cooked_size
!= 0)
6568 size
= section
->_cooked_size
;
6570 size
= section
->_raw_size
;
6571 c
= (bfd_byte
*) bfd_zalloc (abfd
, size
);
6574 elf_section_data (section
)->tdata
= (PTR
) c
;
6577 memcpy (c
+ offset
, location
, (size_t) count
);
6580 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
6584 /* This is almost identical to bfd_generic_get_... except that some
6585 MIPS relocations need to be handled specially. Sigh. */
6588 _bfd_elf_mips_get_relocated_section_contents (abfd
, link_info
, link_order
,
6589 data
, relocateable
, symbols
)
6591 struct bfd_link_info
*link_info
;
6592 struct bfd_link_order
*link_order
;
6594 boolean relocateable
;
6597 /* Get enough memory to hold the stuff */
6598 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
6599 asection
*input_section
= link_order
->u
.indirect
.section
;
6601 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
6602 arelent
**reloc_vector
= NULL
;
6608 reloc_vector
= (arelent
**) bfd_malloc ((bfd_size_type
) reloc_size
);
6609 if (reloc_vector
== NULL
&& reloc_size
!= 0)
6612 /* read in the section */
6613 if (!bfd_get_section_contents (input_bfd
,
6617 input_section
->_raw_size
))
6620 /* We're not relaxing the section, so just copy the size info */
6621 input_section
->_cooked_size
= input_section
->_raw_size
;
6622 input_section
->reloc_done
= true;
6624 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
6628 if (reloc_count
< 0)
6631 if (reloc_count
> 0)
6636 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
6639 struct bfd_hash_entry
*h
;
6640 struct bfd_link_hash_entry
*lh
;
6641 /* Skip all this stuff if we aren't mixing formats. */
6642 if (abfd
&& input_bfd
6643 && abfd
->xvec
== input_bfd
->xvec
)
6647 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
6648 lh
= (struct bfd_link_hash_entry
*) h
;
6655 case bfd_link_hash_undefined
:
6656 case bfd_link_hash_undefweak
:
6657 case bfd_link_hash_common
:
6660 case bfd_link_hash_defined
:
6661 case bfd_link_hash_defweak
:
6663 gp
= lh
->u
.def
.value
;
6665 case bfd_link_hash_indirect
:
6666 case bfd_link_hash_warning
:
6668 /* @@FIXME ignoring warning for now */
6670 case bfd_link_hash_new
:
6679 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
6682 char *error_message
= (char *) NULL
;
6683 bfd_reloc_status_type r
;
6685 /* Specific to MIPS: Deal with relocation types that require
6686 knowing the gp of the output bfd. */
6687 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
6688 if (bfd_is_abs_section (sym
->section
) && abfd
)
6690 /* The special_function wouldn't get called anyways. */
6694 /* The gp isn't there; let the special function code
6695 fall over on its own. */
6697 else if ((*parent
)->howto
->special_function
6698 == _bfd_mips_elf32_gprel16_reloc
)
6700 /* bypass special_function call */
6701 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
6702 input_section
, relocateable
,
6704 goto skip_bfd_perform_relocation
;
6706 /* end mips specific stuff */
6708 r
= bfd_perform_relocation (input_bfd
,
6712 relocateable
? abfd
: (bfd
*) NULL
,
6714 skip_bfd_perform_relocation
:
6718 asection
*os
= input_section
->output_section
;
6720 /* A partial link, so keep the relocs */
6721 os
->orelocation
[os
->reloc_count
] = *parent
;
6725 if (r
!= bfd_reloc_ok
)
6729 case bfd_reloc_undefined
:
6730 if (!((*link_info
->callbacks
->undefined_symbol
)
6731 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6732 input_bfd
, input_section
, (*parent
)->address
,
6736 case bfd_reloc_dangerous
:
6737 BFD_ASSERT (error_message
!= (char *) NULL
);
6738 if (!((*link_info
->callbacks
->reloc_dangerous
)
6739 (link_info
, error_message
, input_bfd
, input_section
,
6740 (*parent
)->address
)))
6743 case bfd_reloc_overflow
:
6744 if (!((*link_info
->callbacks
->reloc_overflow
)
6745 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6746 (*parent
)->howto
->name
, (*parent
)->addend
,
6747 input_bfd
, input_section
, (*parent
)->address
)))
6750 case bfd_reloc_outofrange
:
6759 if (reloc_vector
!= NULL
)
6760 free (reloc_vector
);
6764 if (reloc_vector
!= NULL
)
6765 free (reloc_vector
);
6769 /* Create a MIPS ELF linker hash table. */
6771 struct bfd_link_hash_table
*
6772 _bfd_mips_elf_link_hash_table_create (abfd
)
6775 struct mips_elf_link_hash_table
*ret
;
6776 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
6778 ret
= (struct mips_elf_link_hash_table
*) bfd_malloc (amt
);
6779 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
6782 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
6783 mips_elf_link_hash_newfunc
))
6790 /* We no longer use this. */
6791 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
6792 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
6794 ret
->procedure_count
= 0;
6795 ret
->compact_rel_size
= 0;
6796 ret
->use_rld_obj_head
= false;
6798 ret
->mips16_stubs_seen
= false;
6800 return &ret
->root
.root
;
6803 /* We need to use a special link routine to handle the .reginfo and
6804 the .mdebug sections. We need to merge all instances of these
6805 sections together, not write them all out sequentially. */
6808 _bfd_mips_elf_final_link (abfd
, info
)
6810 struct bfd_link_info
*info
;
6814 struct bfd_link_order
*p
;
6815 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
6816 asection
*rtproc_sec
;
6817 Elf32_RegInfo reginfo
;
6818 struct ecoff_debug_info debug
;
6819 const struct ecoff_debug_swap
*swap
6820 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
6821 HDRR
*symhdr
= &debug
.symbolic_header
;
6822 PTR mdebug_handle
= NULL
;
6828 static const char * const secname
[] =
6830 ".text", ".init", ".fini", ".data",
6831 ".rodata", ".sdata", ".sbss", ".bss"
6833 static const int sc
[] =
6835 scText
, scInit
, scFini
, scData
,
6836 scRData
, scSData
, scSBss
, scBss
6839 /* If all the things we linked together were PIC, but we're
6840 producing an executable (rather than a shared object), then the
6841 resulting file is CPIC (i.e., it calls PIC code.) */
6843 && !info
->relocateable
6844 && elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
6846 elf_elfheader (abfd
)->e_flags
&= ~EF_MIPS_PIC
;
6847 elf_elfheader (abfd
)->e_flags
|= EF_MIPS_CPIC
;
6850 /* We'd carefully arranged the dynamic symbol indices, and then the
6851 generic size_dynamic_sections renumbered them out from under us.
6852 Rather than trying somehow to prevent the renumbering, just do
6854 if (elf_hash_table (info
)->dynamic_sections_created
)
6858 struct mips_got_info
*g
;
6860 /* When we resort, we must tell mips_elf_sort_hash_table what
6861 the lowest index it may use is. That's the number of section
6862 symbols we're going to add. The generic ELF linker only
6863 adds these symbols when building a shared object. Note that
6864 we count the sections after (possibly) removing the .options
6866 if (! mips_elf_sort_hash_table (info
, (info
->shared
6867 ? bfd_count_sections (abfd
) + 1
6871 /* Make sure we didn't grow the global .got region. */
6872 dynobj
= elf_hash_table (info
)->dynobj
;
6873 got
= bfd_get_section_by_name (dynobj
, ".got");
6874 g
= (struct mips_got_info
*) elf_section_data (got
)->tdata
;
6876 if (g
->global_gotsym
!= NULL
)
6877 BFD_ASSERT ((elf_hash_table (info
)->dynsymcount
6878 - g
->global_gotsym
->dynindx
)
6879 <= g
->global_gotno
);
6882 /* On IRIX5, we omit the .options section. On IRIX6, however, we
6883 include it, even though we don't process it quite right. (Some
6884 entries are supposed to be merged.) Empirically, we seem to be
6885 better off including it then not. */
6886 if (IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
6887 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
6889 if (strcmp ((*secpp
)->name
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)) == 0)
6891 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
6892 if (p
->type
== bfd_indirect_link_order
)
6893 p
->u
.indirect
.section
->flags
&= ~SEC_HAS_CONTENTS
;
6894 (*secpp
)->link_order_head
= NULL
;
6895 bfd_section_list_remove (abfd
, secpp
);
6896 --abfd
->section_count
;
6902 /* We include .MIPS.options, even though we don't process it quite right.
6903 (Some entries are supposed to be merged.) At IRIX6 empirically we seem
6904 to be better off including it than not. */
6905 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
6907 if (strcmp ((*secpp
)->name
, ".MIPS.options") == 0)
6909 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
6910 if (p
->type
== bfd_indirect_link_order
)
6911 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
6912 (*secpp
)->link_order_head
= NULL
;
6913 bfd_section_list_remove (abfd
, secpp
);
6914 --abfd
->section_count
;
6920 /* Get a value for the GP register. */
6921 if (elf_gp (abfd
) == 0)
6923 struct bfd_link_hash_entry
*h
;
6925 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
6926 if (h
!= (struct bfd_link_hash_entry
*) NULL
6927 && h
->type
== bfd_link_hash_defined
)
6928 elf_gp (abfd
) = (h
->u
.def
.value
6929 + h
->u
.def
.section
->output_section
->vma
6930 + h
->u
.def
.section
->output_offset
);
6931 else if (info
->relocateable
)
6933 bfd_vma lo
= MINUS_ONE
;
6935 /* Find the GP-relative section with the lowest offset. */
6936 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
6938 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
6941 /* And calculate GP relative to that. */
6942 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
6946 /* If the relocate_section function needs to do a reloc
6947 involving the GP value, it should make a reloc_dangerous
6948 callback to warn that GP is not defined. */
6952 /* Go through the sections and collect the .reginfo and .mdebug
6956 gptab_data_sec
= NULL
;
6957 gptab_bss_sec
= NULL
;
6958 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
6960 if (strcmp (o
->name
, ".reginfo") == 0)
6962 memset (®info
, 0, sizeof reginfo
);
6964 /* We have found the .reginfo section in the output file.
6965 Look through all the link_orders comprising it and merge
6966 the information together. */
6967 for (p
= o
->link_order_head
;
6968 p
!= (struct bfd_link_order
*) NULL
;
6971 asection
*input_section
;
6973 Elf32_External_RegInfo ext
;
6976 if (p
->type
!= bfd_indirect_link_order
)
6978 if (p
->type
== bfd_data_link_order
)
6983 input_section
= p
->u
.indirect
.section
;
6984 input_bfd
= input_section
->owner
;
6986 /* The linker emulation code has probably clobbered the
6987 size to be zero bytes. */
6988 if (input_section
->_raw_size
== 0)
6989 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
6991 if (! bfd_get_section_contents (input_bfd
, input_section
,
6994 (bfd_size_type
) sizeof ext
))
6997 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
6999 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
7000 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
7001 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
7002 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
7003 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
7005 /* ri_gp_value is set by the function
7006 mips_elf32_section_processing when the section is
7007 finally written out. */
7009 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7010 elf_link_input_bfd ignores this section. */
7011 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7014 /* Size has been set in _bfd_mips_elf_always_size_sections. */
7015 BFD_ASSERT(o
->_raw_size
== sizeof (Elf32_External_RegInfo
));
7017 /* Skip this section later on (I don't think this currently
7018 matters, but someday it might). */
7019 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7024 if (strcmp (o
->name
, ".mdebug") == 0)
7026 struct extsym_info einfo
;
7029 /* We have found the .mdebug section in the output file.
7030 Look through all the link_orders comprising it and merge
7031 the information together. */
7032 symhdr
->magic
= swap
->sym_magic
;
7033 /* FIXME: What should the version stamp be? */
7035 symhdr
->ilineMax
= 0;
7039 symhdr
->isymMax
= 0;
7040 symhdr
->ioptMax
= 0;
7041 symhdr
->iauxMax
= 0;
7043 symhdr
->issExtMax
= 0;
7046 symhdr
->iextMax
= 0;
7048 /* We accumulate the debugging information itself in the
7049 debug_info structure. */
7051 debug
.external_dnr
= NULL
;
7052 debug
.external_pdr
= NULL
;
7053 debug
.external_sym
= NULL
;
7054 debug
.external_opt
= NULL
;
7055 debug
.external_aux
= NULL
;
7057 debug
.ssext
= debug
.ssext_end
= NULL
;
7058 debug
.external_fdr
= NULL
;
7059 debug
.external_rfd
= NULL
;
7060 debug
.external_ext
= debug
.external_ext_end
= NULL
;
7062 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
7063 if (mdebug_handle
== (PTR
) NULL
)
7067 esym
.cobol_main
= 0;
7071 esym
.asym
.iss
= issNil
;
7072 esym
.asym
.st
= stLocal
;
7073 esym
.asym
.reserved
= 0;
7074 esym
.asym
.index
= indexNil
;
7076 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
7078 esym
.asym
.sc
= sc
[i
];
7079 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
7082 esym
.asym
.value
= s
->vma
;
7083 last
= s
->vma
+ s
->_raw_size
;
7086 esym
.asym
.value
= last
;
7087 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
7092 for (p
= o
->link_order_head
;
7093 p
!= (struct bfd_link_order
*) NULL
;
7096 asection
*input_section
;
7098 const struct ecoff_debug_swap
*input_swap
;
7099 struct ecoff_debug_info input_debug
;
7103 if (p
->type
!= bfd_indirect_link_order
)
7105 if (p
->type
== bfd_data_link_order
)
7110 input_section
= p
->u
.indirect
.section
;
7111 input_bfd
= input_section
->owner
;
7113 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
7114 || (get_elf_backend_data (input_bfd
)
7115 ->elf_backend_ecoff_debug_swap
) == NULL
)
7117 /* I don't know what a non MIPS ELF bfd would be
7118 doing with a .mdebug section, but I don't really
7119 want to deal with it. */
7123 input_swap
= (get_elf_backend_data (input_bfd
)
7124 ->elf_backend_ecoff_debug_swap
);
7126 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
7128 /* The ECOFF linking code expects that we have already
7129 read in the debugging information and set up an
7130 ecoff_debug_info structure, so we do that now. */
7131 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
7135 if (! (bfd_ecoff_debug_accumulate
7136 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
7137 &input_debug
, input_swap
, info
)))
7140 /* Loop through the external symbols. For each one with
7141 interesting information, try to find the symbol in
7142 the linker global hash table and save the information
7143 for the output external symbols. */
7144 eraw_src
= input_debug
.external_ext
;
7145 eraw_end
= (eraw_src
7146 + (input_debug
.symbolic_header
.iextMax
7147 * input_swap
->external_ext_size
));
7149 eraw_src
< eraw_end
;
7150 eraw_src
+= input_swap
->external_ext_size
)
7154 struct mips_elf_link_hash_entry
*h
;
7156 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
7157 if (ext
.asym
.sc
== scNil
7158 || ext
.asym
.sc
== scUndefined
7159 || ext
.asym
.sc
== scSUndefined
)
7162 name
= input_debug
.ssext
+ ext
.asym
.iss
;
7163 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
7164 name
, false, false, true);
7165 if (h
== NULL
|| h
->esym
.ifd
!= -2)
7171 < input_debug
.symbolic_header
.ifdMax
);
7172 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
7178 /* Free up the information we just read. */
7179 free (input_debug
.line
);
7180 free (input_debug
.external_dnr
);
7181 free (input_debug
.external_pdr
);
7182 free (input_debug
.external_sym
);
7183 free (input_debug
.external_opt
);
7184 free (input_debug
.external_aux
);
7185 free (input_debug
.ss
);
7186 free (input_debug
.ssext
);
7187 free (input_debug
.external_fdr
);
7188 free (input_debug
.external_rfd
);
7189 free (input_debug
.external_ext
);
7191 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7192 elf_link_input_bfd ignores this section. */
7193 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7196 if (SGI_COMPAT (abfd
) && info
->shared
)
7198 /* Create .rtproc section. */
7199 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
7200 if (rtproc_sec
== NULL
)
7202 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7203 | SEC_LINKER_CREATED
| SEC_READONLY
);
7205 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
7206 if (rtproc_sec
== NULL
7207 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
7208 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
7212 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
7218 /* Build the external symbol information. */
7221 einfo
.debug
= &debug
;
7223 einfo
.failed
= false;
7224 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
7225 mips_elf_output_extsym
,
7230 /* Set the size of the .mdebug section. */
7231 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
7233 /* Skip this section later on (I don't think this currently
7234 matters, but someday it might). */
7235 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7240 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
7242 const char *subname
;
7245 Elf32_External_gptab
*ext_tab
;
7248 /* The .gptab.sdata and .gptab.sbss sections hold
7249 information describing how the small data area would
7250 change depending upon the -G switch. These sections
7251 not used in executables files. */
7252 if (! info
->relocateable
)
7254 for (p
= o
->link_order_head
;
7255 p
!= (struct bfd_link_order
*) NULL
;
7258 asection
*input_section
;
7260 if (p
->type
!= bfd_indirect_link_order
)
7262 if (p
->type
== bfd_data_link_order
)
7267 input_section
= p
->u
.indirect
.section
;
7269 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7270 elf_link_input_bfd ignores this section. */
7271 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7274 /* Skip this section later on (I don't think this
7275 currently matters, but someday it might). */
7276 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7278 /* Really remove the section. */
7279 for (secpp
= &abfd
->sections
;
7281 secpp
= &(*secpp
)->next
)
7283 bfd_section_list_remove (abfd
, secpp
);
7284 --abfd
->section_count
;
7289 /* There is one gptab for initialized data, and one for
7290 uninitialized data. */
7291 if (strcmp (o
->name
, ".gptab.sdata") == 0)
7293 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
7297 (*_bfd_error_handler
)
7298 (_("%s: illegal section name `%s'"),
7299 bfd_get_filename (abfd
), o
->name
);
7300 bfd_set_error (bfd_error_nonrepresentable_section
);
7304 /* The linker script always combines .gptab.data and
7305 .gptab.sdata into .gptab.sdata, and likewise for
7306 .gptab.bss and .gptab.sbss. It is possible that there is
7307 no .sdata or .sbss section in the output file, in which
7308 case we must change the name of the output section. */
7309 subname
= o
->name
+ sizeof ".gptab" - 1;
7310 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
7312 if (o
== gptab_data_sec
)
7313 o
->name
= ".gptab.data";
7315 o
->name
= ".gptab.bss";
7316 subname
= o
->name
+ sizeof ".gptab" - 1;
7317 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
7320 /* Set up the first entry. */
7322 amt
= c
* sizeof (Elf32_gptab
);
7323 tab
= (Elf32_gptab
*) bfd_malloc (amt
);
7326 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
7327 tab
[0].gt_header
.gt_unused
= 0;
7329 /* Combine the input sections. */
7330 for (p
= o
->link_order_head
;
7331 p
!= (struct bfd_link_order
*) NULL
;
7334 asection
*input_section
;
7338 bfd_size_type gpentry
;
7340 if (p
->type
!= bfd_indirect_link_order
)
7342 if (p
->type
== bfd_data_link_order
)
7347 input_section
= p
->u
.indirect
.section
;
7348 input_bfd
= input_section
->owner
;
7350 /* Combine the gptab entries for this input section one
7351 by one. We know that the input gptab entries are
7352 sorted by ascending -G value. */
7353 size
= bfd_section_size (input_bfd
, input_section
);
7355 for (gpentry
= sizeof (Elf32_External_gptab
);
7357 gpentry
+= sizeof (Elf32_External_gptab
))
7359 Elf32_External_gptab ext_gptab
;
7360 Elf32_gptab int_gptab
;
7366 if (! (bfd_get_section_contents
7367 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
7369 (bfd_size_type
) sizeof (Elf32_External_gptab
))))
7375 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
7377 val
= int_gptab
.gt_entry
.gt_g_value
;
7378 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
7381 for (look
= 1; look
< c
; look
++)
7383 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
7384 tab
[look
].gt_entry
.gt_bytes
+= add
;
7386 if (tab
[look
].gt_entry
.gt_g_value
== val
)
7392 Elf32_gptab
*new_tab
;
7395 /* We need a new table entry. */
7396 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
7397 new_tab
= (Elf32_gptab
*) bfd_realloc ((PTR
) tab
, amt
);
7398 if (new_tab
== NULL
)
7404 tab
[c
].gt_entry
.gt_g_value
= val
;
7405 tab
[c
].gt_entry
.gt_bytes
= add
;
7407 /* Merge in the size for the next smallest -G
7408 value, since that will be implied by this new
7411 for (look
= 1; look
< c
; look
++)
7413 if (tab
[look
].gt_entry
.gt_g_value
< val
7415 || (tab
[look
].gt_entry
.gt_g_value
7416 > tab
[max
].gt_entry
.gt_g_value
)))
7420 tab
[c
].gt_entry
.gt_bytes
+=
7421 tab
[max
].gt_entry
.gt_bytes
;
7426 last
= int_gptab
.gt_entry
.gt_bytes
;
7429 /* Hack: reset the SEC_HAS_CONTENTS flag so that
7430 elf_link_input_bfd ignores this section. */
7431 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
7434 /* The table must be sorted by -G value. */
7436 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
7438 /* Swap out the table. */
7439 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
7440 ext_tab
= (Elf32_External_gptab
*) bfd_alloc (abfd
, amt
);
7441 if (ext_tab
== NULL
)
7447 for (j
= 0; j
< c
; j
++)
7448 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
7451 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
7452 o
->contents
= (bfd_byte
*) ext_tab
;
7454 /* Skip this section later on (I don't think this currently
7455 matters, but someday it might). */
7456 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
7460 /* Invoke the regular ELF backend linker to do all the work. */
7461 if (ABI_64_P (abfd
))
7464 if (!bfd_elf64_bfd_final_link (abfd
, info
))
7471 else if (!bfd_elf32_bfd_final_link (abfd
, info
))
7474 /* Now write out the computed sections. */
7476 if (reginfo_sec
!= (asection
*) NULL
)
7478 Elf32_External_RegInfo ext
;
7480 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
7481 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
7483 (bfd_size_type
) sizeof ext
))
7487 if (mdebug_sec
!= (asection
*) NULL
)
7489 BFD_ASSERT (abfd
->output_has_begun
);
7490 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
7492 mdebug_sec
->filepos
))
7495 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
7498 if (gptab_data_sec
!= (asection
*) NULL
)
7500 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
7501 gptab_data_sec
->contents
,
7503 gptab_data_sec
->_raw_size
))
7507 if (gptab_bss_sec
!= (asection
*) NULL
)
7509 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
7510 gptab_bss_sec
->contents
,
7512 gptab_bss_sec
->_raw_size
))
7516 if (SGI_COMPAT (abfd
))
7518 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
7519 if (rtproc_sec
!= NULL
)
7521 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
7522 rtproc_sec
->contents
,
7524 rtproc_sec
->_raw_size
))
7532 /* Merge backend specific data from an object file to the output
7533 object file when linking. */
7536 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
7543 boolean null_input_bfd
= true;
7546 /* Check if we have the same endianess */
7547 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
7550 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
7551 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
7554 new_flags
= elf_elfheader (ibfd
)->e_flags
;
7555 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
7556 old_flags
= elf_elfheader (obfd
)->e_flags
;
7558 if (! elf_flags_init (obfd
))
7560 elf_flags_init (obfd
) = true;
7561 elf_elfheader (obfd
)->e_flags
= new_flags
;
7562 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
7563 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
7565 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
7566 && bfd_get_arch_info (obfd
)->the_default
)
7568 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
7569 bfd_get_mach (ibfd
)))
7576 /* Check flag compatibility. */
7578 new_flags
&= ~EF_MIPS_NOREORDER
;
7579 old_flags
&= ~EF_MIPS_NOREORDER
;
7581 if (new_flags
== old_flags
)
7584 /* Check to see if the input BFD actually contains any sections.
7585 If not, its flags may not have been initialised either, but it cannot
7586 actually cause any incompatibility. */
7587 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7589 /* Ignore synthetic sections and empty .text, .data and .bss sections
7590 which are automatically generated by gas. */
7591 if (strcmp (sec
->name
, ".reginfo")
7592 && strcmp (sec
->name
, ".mdebug")
7593 && ((!strcmp (sec
->name
, ".text")
7594 || !strcmp (sec
->name
, ".data")
7595 || !strcmp (sec
->name
, ".bss"))
7596 && sec
->_raw_size
!= 0))
7598 null_input_bfd
= false;
7607 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
7609 new_flags
&= ~EF_MIPS_PIC
;
7610 old_flags
&= ~EF_MIPS_PIC
;
7611 (*_bfd_error_handler
)
7612 (_("%s: linking PIC files with non-PIC files"),
7613 bfd_archive_filename (ibfd
));
7617 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
7619 new_flags
&= ~EF_MIPS_CPIC
;
7620 old_flags
&= ~EF_MIPS_CPIC
;
7621 (*_bfd_error_handler
)
7622 (_("%s: linking abicalls files with non-abicalls files"),
7623 bfd_archive_filename (ibfd
));
7627 /* Compare the ISA's. */
7628 if ((new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
))
7629 != (old_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
)))
7631 int new_mach
= new_flags
& EF_MIPS_MACH
;
7632 int old_mach
= old_flags
& EF_MIPS_MACH
;
7633 int new_isa
= elf_mips_isa (new_flags
);
7634 int old_isa
= elf_mips_isa (old_flags
);
7636 /* If either has no machine specified, just compare the general isa's.
7637 Some combinations of machines are ok, if the isa's match. */
7640 || new_mach
== old_mach
7643 /* Don't warn about mixing code using 32-bit ISAs, or mixing code
7644 using 64-bit ISAs. They will normally use the same data sizes
7645 and calling conventions. */
7647 if (( (new_isa
== 1 || new_isa
== 2 || new_isa
== 32)
7648 ^ (old_isa
== 1 || old_isa
== 2 || old_isa
== 32)) != 0)
7650 (*_bfd_error_handler
)
7651 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"),
7652 bfd_archive_filename (ibfd
), new_isa
, old_isa
);
7657 /* Do we need to update the mach field? */
7658 if (old_mach
== 0 && new_mach
!= 0)
7659 elf_elfheader (obfd
)->e_flags
|= new_mach
;
7661 /* Do we need to update the ISA field? */
7662 if (new_isa
> old_isa
)
7664 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_ARCH
;
7665 elf_elfheader (obfd
)->e_flags
7666 |= new_flags
& EF_MIPS_ARCH
;
7672 (*_bfd_error_handler
)
7673 (_("%s: ISA mismatch (%d) with previous modules (%d)"),
7674 bfd_archive_filename (ibfd
),
7675 _bfd_elf_mips_mach (new_flags
),
7676 _bfd_elf_mips_mach (old_flags
));
7680 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
7681 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
7684 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it
7685 does set EI_CLASS differently from any 32-bit ABI. */
7686 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
7687 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
7688 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
7690 /* Only error if both are set (to different values). */
7691 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
7692 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
7693 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
7695 (*_bfd_error_handler
)
7696 (_("%s: ABI mismatch: linking %s module with previous %s modules"),
7697 bfd_archive_filename (ibfd
),
7698 elf_mips_abi_name (ibfd
),
7699 elf_mips_abi_name (obfd
));
7702 new_flags
&= ~EF_MIPS_ABI
;
7703 old_flags
&= ~EF_MIPS_ABI
;
7706 /* Warn about any other mismatches */
7707 if (new_flags
!= old_flags
)
7709 (*_bfd_error_handler
)
7710 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
7711 bfd_archive_filename (ibfd
), (unsigned long) new_flags
,
7712 (unsigned long) old_flags
);
7718 bfd_set_error (bfd_error_bad_value
);
7725 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
7728 _bfd_mips_elf_set_private_flags (abfd
, flags
)
7732 BFD_ASSERT (!elf_flags_init (abfd
)
7733 || elf_elfheader (abfd
)->e_flags
== flags
);
7735 elf_elfheader (abfd
)->e_flags
= flags
;
7736 elf_flags_init (abfd
) = true;
7741 _bfd_mips_elf_print_private_bfd_data (abfd
, ptr
)
7745 FILE *file
= (FILE *) ptr
;
7747 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
7749 /* Print normal ELF private data. */
7750 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
7752 /* xgettext:c-format */
7753 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
7755 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
7756 fprintf (file
, _(" [abi=O32]"));
7757 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
7758 fprintf (file
, _(" [abi=O64]"));
7759 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
7760 fprintf (file
, _(" [abi=EABI32]"));
7761 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
7762 fprintf (file
, _(" [abi=EABI64]"));
7763 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
7764 fprintf (file
, _(" [abi unknown]"));
7765 else if (ABI_N32_P (abfd
))
7766 fprintf (file
, _(" [abi=N32]"));
7767 else if (ABI_64_P (abfd
))
7768 fprintf (file
, _(" [abi=64]"));
7770 fprintf (file
, _(" [no abi set]"));
7772 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
7773 fprintf (file
, _(" [mips1]"));
7774 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
7775 fprintf (file
, _(" [mips2]"));
7776 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
7777 fprintf (file
, _(" [mips3]"));
7778 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
7779 fprintf (file
, _(" [mips4]"));
7780 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
7781 fprintf (file
, _(" [mips5]"));
7782 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
7783 fprintf (file
, _(" [mips32]"));
7784 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
7785 fprintf (file
, _(" [mips64]"));
7787 fprintf (file
, _(" [unknown ISA]"));
7789 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
7790 fprintf (file
, _(" [mdmx]"));
7792 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
7793 fprintf (file
, _(" [mips16]"));
7795 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
7796 fprintf (file
, _(" [32bitmode]"));
7798 fprintf (file
, _(" [not 32bitmode]"));