1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
24 different MIPS ELF from other targets. This matters when linking.
25 This file supports both, switching at runtime. */
35 /* Get the ECOFF swapping routines. */
37 #include "coff/symconst.h"
38 #include "coff/internal.h"
39 #include "coff/ecoff.h"
40 #include "coff/mips.h"
42 #include "ecoffswap.h"
44 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
45 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
46 static void mips_info_to_howto_rel
47 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
48 static void bfd_mips_elf32_swap_gptab_in
49 PARAMS ((bfd
*, const Elf32_External_gptab
*, Elf32_gptab
*));
50 static void bfd_mips_elf32_swap_gptab_out
51 PARAMS ((bfd
*, const Elf32_gptab
*, Elf32_External_gptab
*));
52 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
53 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
54 static boolean mips_elf_create_procedure_table
55 PARAMS ((PTR
, bfd
*, struct bfd_link_info
*, asection
*,
56 struct ecoff_debug_info
*));
57 static int mips_elf_additional_program_headers
PARAMS ((bfd
*));
58 static boolean mips_elf_modify_segment_map
PARAMS ((bfd
*));
59 static boolean mips_elf32_section_from_shdr
60 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
61 static boolean mips_elf32_section_processing
62 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
63 static boolean mips_elf_is_local_label
64 PARAMS ((bfd
*, asymbol
*));
65 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
66 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
67 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
69 static int gptab_compare
PARAMS ((const void *, const void *));
70 static boolean mips_elf_final_link
71 PARAMS ((bfd
*, struct bfd_link_info
*));
72 static void mips_elf_relocate_hi16
73 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
75 static void mips_elf_relocate_got_local
76 PARAMS ((bfd
*, bfd
*, asection
*, Elf_Internal_Rela
*,
77 Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
78 static void mips_elf_relocate_global_got
79 PARAMS ((bfd
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_vma
));
80 static boolean mips_elf_adjust_dynindx
81 PARAMS ((struct elf_link_hash_entry
*, PTR
));
82 static boolean mips_elf_relocate_section
83 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
84 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
85 static boolean mips_elf_create_dynamic_sections
86 PARAMS ((bfd
*, struct bfd_link_info
*));
87 static boolean mips_elf_create_compact_rel_section
88 PARAMS ((bfd
*, struct bfd_link_info
*));
89 static boolean mips_elf_create_got_section
90 PARAMS ((bfd
*, struct bfd_link_info
*));
91 static boolean mips_elf_check_relocs
92 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
93 const Elf_Internal_Rela
*));
94 static boolean mips_elf_adjust_dynamic_symbol
95 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
96 static boolean mips_elf_size_dynamic_sections
97 PARAMS ((bfd
*, struct bfd_link_info
*));
98 static boolean mips_elf_finish_dynamic_symbol
99 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
100 Elf_Internal_Sym
*));
101 static boolean mips_elf_finish_dynamic_sections
102 PARAMS ((bfd
*, struct bfd_link_info
*));
103 static boolean mips_elf_add_symbol_hook
104 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
105 const char **, flagword
*, asection
**, bfd_vma
*));
106 static bfd_reloc_status_type mips_elf_final_gp
107 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
108 static bfd_byte
*elf32_mips_get_relocated_section_contents
109 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
110 bfd_byte
*, boolean
, asymbol
**));
112 /* This is true for Irix 5 executables, false for normal MIPS ELF ABI
113 executables. FIXME: At the moment, we default to always generating
114 Irix 5 executables. */
116 #define SGI_COMPAT(abfd) (1)
118 /* This structure is used to hold .got information when linking. It
119 is stored in the tdata field of the bfd_elf_section_data structure. */
123 /* The symbol index of the first global .got symbol. */
124 unsigned long global_gotsym
;
125 /* The number of local .got entries. */
126 unsigned int local_gotno
;
129 /* The number of local .got entries we reserve. */
130 #define MIPS_RESERVED_GOTNO (2)
132 /* Instructions which appear in a stub. For some reason the stub is
133 slightly different on an SGI system. */
134 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)
135 #define STUB_LW(abfd) \
137 ? 0x8f998010 /* lw t9,0x8010(gp) */ \
138 : 0x8f998000) /* lw t9,0x8000(gp) */
139 #define STUB_MOVE 0x03e07825 /* move t7,ra */
140 #define STUB_JALR 0x0320f809 /* jal t9 */
141 #define STUB_LI16 0x34180000 /* ori t8,zero,0 */
142 #define MIPS_FUNCTION_STUB_SIZE (16)
144 /* Names of sections which appear in the .dynsym section in an Irix 5
147 static const char * const mips_elf_dynsym_sec_names
[] =
160 #define SIZEOF_MIPS_DYNSYM_SECNAMES \
161 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])
163 /* The number of entries in mips_elf_dynsym_sec_names which go in the
166 #define MIPS_TEXT_DYNSYM_SECNO (3)
168 /* The names of the runtime procedure table symbols used on Irix 5. */
170 static const char * const mips_elf_dynsym_rtproc_names
[] =
173 "_procedure_string_table",
174 "_procedure_table_size",
178 /* These structures are used to generate the .compact_rel section on
183 unsigned long id1
; /* Always one? */
184 unsigned long num
; /* Number of compact relocation entries. */
185 unsigned long id2
; /* Always two? */
186 unsigned long offset
; /* The file offset of the first relocation. */
187 unsigned long reserved0
; /* Zero? */
188 unsigned long reserved1
; /* Zero? */
197 bfd_byte reserved0
[4];
198 bfd_byte reserved1
[4];
199 } Elf32_External_compact_rel
;
203 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
204 unsigned int rtype
: 4; /* Relocation types. See below. */
205 unsigned int dist2to
: 8;
206 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
207 unsigned long konst
; /* KONST field. See below. */
208 unsigned long vaddr
; /* VADDR to be relocated. */
213 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
214 unsigned int rtype
: 4; /* Relocation types. See below. */
215 unsigned int dist2to
: 8;
216 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
217 unsigned long konst
; /* KONST field. See below. */
225 } Elf32_External_crinfo
;
231 } Elf32_External_crinfo2
;
233 /* These are the constants used to swap the bitfields in a crinfo. */
235 #define CRINFO_CTYPE (0x1)
236 #define CRINFO_CTYPE_SH (31)
237 #define CRINFO_RTYPE (0xf)
238 #define CRINFO_RTYPE_SH (27)
239 #define CRINFO_DIST2TO (0xff)
240 #define CRINFO_DIST2TO_SH (19)
241 #define CRINFO_RELVADDR (0x7ffff)
242 #define CRINFO_RELVADDR_SH (0)
244 /* A compact relocation info has long (3 words) or short (2 words)
245 formats. A short format doesn't have VADDR field and relvaddr
246 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
247 #define CRF_MIPS_LONG 1
248 #define CRF_MIPS_SHORT 0
250 /* There are 4 types of compact relocation at least. The value KONST
251 has different meaning for each type:
254 CT_MIPS_REL32 Address in data
255 CT_MIPS_WORD Address in word (XXX)
256 CT_MIPS_GPHI_LO GP - vaddr
257 CT_MIPS_JMPAD Address to jump
260 #define CRT_MIPS_REL32 0xa
261 #define CRT_MIPS_WORD 0xb
262 #define CRT_MIPS_GPHI_LO 0xc
263 #define CRT_MIPS_JMPAD 0xd
265 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
266 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
267 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
268 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
270 static void bfd_elf32_swap_compact_rel_out
271 PARAMS ((bfd
*, const Elf32_compact_rel
*, Elf32_External_compact_rel
*));
272 static void bfd_elf32_swap_crinfo_out
273 PARAMS ((bfd
*, const Elf32_crinfo
*, Elf32_External_crinfo
*));
275 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
280 R_MIPS_16
, R_MIPS_32
,
281 R_MIPS_REL32
, R_MIPS_26
,
282 R_MIPS_HI16
, R_MIPS_LO16
,
283 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
284 R_MIPS_GOT16
, R_MIPS_PC16
,
285 R_MIPS_CALL16
, R_MIPS_GPREL32
,
286 /* The remaining relocs are defined on Irix, although they are not
287 in the MIPS ELF ABI. */
288 R_MIPS_UNUSED1
, R_MIPS_UNUSED2
,
290 R_MIPS_SHIFT5
, R_MIPS_SHIFT6
,
291 R_MIPS_64
, R_MIPS_GOT_DISP
,
292 R_MIPS_GOT_PAGE
, R_MIPS_GOT_OFST
,
293 R_MIPS_GOT_HI16
, R_MIPS_GOT_LO16
,
294 R_MIPS_SUB
, R_MIPS_INSERT_A
,
295 R_MIPS_INSERT_B
, R_MIPS_DELETE
,
296 R_MIPS_HIGHER
, R_MIPS_HIGHEST
,
297 R_MIPS_CALL_HI16
, R_MIPS_CALL_LO16
,
301 static reloc_howto_type elf_mips_howto_table
[] =
304 HOWTO (R_MIPS_NONE
, /* type */
306 0, /* size (0 = byte, 1 = short, 2 = long) */
308 false, /* pc_relative */
310 complain_overflow_dont
, /* complain_on_overflow */
311 bfd_elf_generic_reloc
, /* special_function */
312 "R_MIPS_NONE", /* name */
313 false, /* partial_inplace */
316 false), /* pcrel_offset */
318 /* 16 bit relocation. */
319 HOWTO (R_MIPS_16
, /* type */
321 1, /* size (0 = byte, 1 = short, 2 = long) */
323 false, /* pc_relative */
325 complain_overflow_bitfield
, /* complain_on_overflow */
326 bfd_elf_generic_reloc
, /* special_function */
327 "R_MIPS_16", /* name */
328 true, /* partial_inplace */
329 0xffff, /* src_mask */
330 0xffff, /* dst_mask */
331 false), /* pcrel_offset */
333 /* 32 bit relocation. */
334 HOWTO (R_MIPS_32
, /* type */
336 2, /* size (0 = byte, 1 = short, 2 = long) */
338 false, /* pc_relative */
340 complain_overflow_bitfield
, /* complain_on_overflow */
341 bfd_elf_generic_reloc
, /* special_function */
342 "R_MIPS_32", /* name */
343 true, /* partial_inplace */
344 0xffffffff, /* src_mask */
345 0xffffffff, /* dst_mask */
346 false), /* pcrel_offset */
348 /* 32 bit symbol relative relocation. */
349 HOWTO (R_MIPS_REL32
, /* type */
351 2, /* size (0 = byte, 1 = short, 2 = long) */
353 false, /* pc_relative */
355 complain_overflow_bitfield
, /* complain_on_overflow */
356 bfd_elf_generic_reloc
, /* special_function */
357 "R_MIPS_REL32", /* name */
358 true, /* partial_inplace */
359 0xffffffff, /* src_mask */
360 0xffffffff, /* dst_mask */
361 false), /* pcrel_offset */
363 /* 26 bit branch address. */
364 HOWTO (R_MIPS_26
, /* type */
366 2, /* size (0 = byte, 1 = short, 2 = long) */
368 false, /* pc_relative */
370 complain_overflow_dont
, /* complain_on_overflow */
371 /* This needs complex overflow
372 detection, because the upper four
373 bits must match the PC. */
374 bfd_elf_generic_reloc
, /* special_function */
375 "R_MIPS_26", /* name */
376 true, /* partial_inplace */
377 0x3ffffff, /* src_mask */
378 0x3ffffff, /* dst_mask */
379 false), /* pcrel_offset */
381 /* High 16 bits of symbol value. */
382 HOWTO (R_MIPS_HI16
, /* type */
384 2, /* size (0 = byte, 1 = short, 2 = long) */
386 false, /* pc_relative */
388 complain_overflow_dont
, /* complain_on_overflow */
389 _bfd_mips_elf_hi16_reloc
, /* special_function */
390 "R_MIPS_HI16", /* name */
391 true, /* partial_inplace */
392 0xffff, /* src_mask */
393 0xffff, /* dst_mask */
394 false), /* pcrel_offset */
396 /* Low 16 bits of symbol value. */
397 HOWTO (R_MIPS_LO16
, /* type */
399 2, /* size (0 = byte, 1 = short, 2 = long) */
401 false, /* pc_relative */
403 complain_overflow_dont
, /* complain_on_overflow */
404 _bfd_mips_elf_lo16_reloc
, /* special_function */
405 "R_MIPS_LO16", /* name */
406 true, /* partial_inplace */
407 0xffff, /* src_mask */
408 0xffff, /* dst_mask */
409 false), /* pcrel_offset */
411 /* GP relative reference. */
412 HOWTO (R_MIPS_GPREL16
, /* type */
414 2, /* size (0 = byte, 1 = short, 2 = long) */
416 false, /* pc_relative */
418 complain_overflow_signed
, /* complain_on_overflow */
419 _bfd_mips_elf_gprel16_reloc
, /* special_function */
420 "R_MIPS_GPREL16", /* name */
421 true, /* partial_inplace */
422 0xffff, /* src_mask */
423 0xffff, /* dst_mask */
424 false), /* pcrel_offset */
426 /* Reference to literal section. */
427 HOWTO (R_MIPS_LITERAL
, /* type */
429 2, /* size (0 = byte, 1 = short, 2 = long) */
431 false, /* pc_relative */
433 complain_overflow_signed
, /* complain_on_overflow */
434 _bfd_mips_elf_gprel16_reloc
, /* special_function */
435 "R_MIPS_LITERAL", /* name */
436 true, /* partial_inplace */
437 0xffff, /* src_mask */
438 0xffff, /* dst_mask */
439 false), /* pcrel_offset */
441 /* Reference to global offset table. */
442 HOWTO (R_MIPS_GOT16
, /* type */
444 2, /* size (0 = byte, 1 = short, 2 = long) */
446 false, /* pc_relative */
448 complain_overflow_signed
, /* complain_on_overflow */
449 _bfd_mips_elf_got16_reloc
, /* special_function */
450 "R_MIPS_GOT16", /* name */
451 false, /* partial_inplace */
453 0xffff, /* dst_mask */
454 false), /* pcrel_offset */
456 /* 16 bit PC relative reference. */
457 HOWTO (R_MIPS_PC16
, /* type */
459 2, /* size (0 = byte, 1 = short, 2 = long) */
461 true, /* pc_relative */
463 complain_overflow_signed
, /* complain_on_overflow */
464 bfd_elf_generic_reloc
, /* special_function */
465 "R_MIPS_PC16", /* name */
466 true, /* partial_inplace */
467 0xffff, /* src_mask */
468 0xffff, /* dst_mask */
469 false), /* pcrel_offset */
471 /* 16 bit call through global offset table. */
472 /* FIXME: This is not handled correctly. */
473 HOWTO (R_MIPS_CALL16
, /* type */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
477 false, /* pc_relative */
479 complain_overflow_signed
, /* complain_on_overflow */
480 bfd_elf_generic_reloc
, /* special_function */
481 "R_MIPS_CALL16", /* name */
482 false, /* partial_inplace */
484 0xffff, /* dst_mask */
485 false), /* pcrel_offset */
487 /* 32 bit GP relative reference. */
488 HOWTO (R_MIPS_GPREL32
, /* type */
490 2, /* size (0 = byte, 1 = short, 2 = long) */
492 false, /* pc_relative */
494 complain_overflow_bitfield
, /* complain_on_overflow */
495 _bfd_mips_elf_gprel32_reloc
, /* special_function */
496 "R_MIPS_GPREL32", /* name */
497 true, /* partial_inplace */
498 0xffffffff, /* src_mask */
499 0xffffffff, /* dst_mask */
500 false), /* pcrel_offset */
502 /* The remaining relocs are defined on Irix 5, although they are
503 not defined by the ABI. */
508 /* A 5 bit shift field. */
509 HOWTO (R_MIPS_SHIFT5
, /* type */
511 2, /* size (0 = byte, 1 = short, 2 = long) */
513 false, /* pc_relative */
515 complain_overflow_bitfield
, /* complain_on_overflow */
516 bfd_elf_generic_reloc
, /* special_function */
517 "R_MIPS_SHIFT5", /* name */
518 true, /* partial_inplace */
519 0x000007c0, /* src_mask */
520 0x000007c0, /* dst_mask */
521 false), /* pcrel_offset */
523 /* A 6 bit shift field. */
524 /* FIXME: This is not handled correctly; a special function is
525 needed to put the most significant bit in the right place. */
526 HOWTO (R_MIPS_SHIFT6
, /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 false, /* pc_relative */
532 complain_overflow_bitfield
, /* complain_on_overflow */
533 bfd_elf_generic_reloc
, /* special_function */
534 "R_MIPS_SHIFT6", /* name */
535 true, /* partial_inplace */
536 0x000007c4, /* src_mask */
537 0x000007c4, /* dst_mask */
538 false), /* pcrel_offset */
540 /* A 64 bit relocation. Presumably not used in 32 bit ELF. */
543 /* Displacement in the global offset table. */
544 /* FIXME: Not handled correctly. */
545 HOWTO (R_MIPS_GOT_DISP
, /* type */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
549 false, /* pc_relative */
551 complain_overflow_bitfield
, /* complain_on_overflow */
552 bfd_elf_generic_reloc
, /* special_function */
553 "R_MIPS_GOT_DISP", /* name */
554 true, /* partial_inplace */
555 0x0000ffff, /* src_mask */
556 0x0000ffff, /* dst_mask */
557 false), /* pcrel_offset */
559 /* Displacement to page pointer in the global offset table. */
560 /* FIXME: Not handled correctly. */
561 HOWTO (R_MIPS_GOT_PAGE
, /* type */
563 2, /* size (0 = byte, 1 = short, 2 = long) */
565 false, /* pc_relative */
567 complain_overflow_bitfield
, /* complain_on_overflow */
568 bfd_elf_generic_reloc
, /* special_function */
569 "R_MIPS_GOT_PAGE", /* name */
570 true, /* partial_inplace */
571 0x0000ffff, /* src_mask */
572 0x0000ffff, /* dst_mask */
573 false), /* pcrel_offset */
575 /* Offset from page pointer in the global offset table. */
576 /* FIXME: Not handled correctly. */
577 HOWTO (R_MIPS_GOT_OFST
, /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 false, /* pc_relative */
583 complain_overflow_bitfield
, /* complain_on_overflow */
584 bfd_elf_generic_reloc
, /* special_function */
585 "R_MIPS_GOT_OFST", /* name */
586 true, /* partial_inplace */
587 0x0000ffff, /* src_mask */
588 0x0000ffff, /* dst_mask */
589 false), /* pcrel_offset */
591 /* High 16 bits of displacement in global offset table. */
592 /* FIXME: Not handled correctly. */
593 HOWTO (R_MIPS_GOT_HI16
, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 false, /* pc_relative */
599 complain_overflow_dont
, /* complain_on_overflow */
600 bfd_elf_generic_reloc
, /* special_function */
601 "R_MIPS_GOT_HI16", /* name */
602 true, /* partial_inplace */
603 0x0000ffff, /* src_mask */
604 0x0000ffff, /* dst_mask */
605 false), /* pcrel_offset */
607 /* Low 16 bits of displacement in global offset table. */
608 /* FIXME: Not handled correctly. */
609 HOWTO (R_MIPS_GOT_LO16
, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 false, /* pc_relative */
615 complain_overflow_dont
, /* complain_on_overflow */
616 bfd_elf_generic_reloc
, /* special_function */
617 "R_MIPS_GOT_LO16", /* name */
618 true, /* partial_inplace */
619 0x0000ffff, /* src_mask */
620 0x0000ffff, /* dst_mask */
621 false), /* pcrel_offset */
623 /* 64 bit subtraction. Presumably not used in 32 bit ELF. */
626 /* Used to cause the linker to insert and delete instructions? */
631 /* Get the higher values of a 64 bit addend. Presumably not used in
636 /* High 16 bits of displacement in global offset table. */
637 /* FIXME: Not handled correctly. */
638 HOWTO (R_MIPS_CALL_HI16
, /* type */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
642 false, /* pc_relative */
644 complain_overflow_dont
, /* complain_on_overflow */
645 bfd_elf_generic_reloc
, /* special_function */
646 "R_MIPS_CALL_HI16", /* name */
647 true, /* partial_inplace */
648 0x0000ffff, /* src_mask */
649 0x0000ffff, /* dst_mask */
650 false), /* pcrel_offset */
652 /* Low 16 bits of displacement in global offset table. */
653 /* FIXME: Not handled correctly. */
654 HOWTO (R_MIPS_CALL_LO16
, /* type */
656 2, /* size (0 = byte, 1 = short, 2 = long) */
658 false, /* pc_relative */
660 complain_overflow_dont
, /* complain_on_overflow */
661 bfd_elf_generic_reloc
, /* special_function */
662 "R_MIPS_CALL_LO16", /* name */
663 true, /* partial_inplace */
664 0x0000ffff, /* src_mask */
665 0x0000ffff, /* dst_mask */
666 false) /* pcrel_offset */
669 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
670 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
671 the HI16. Here we just save the information we need; we do the
672 actual relocation when we see the LO16. MIPS ELF requires that the
673 LO16 immediately follow the HI16. As a GNU extension, we permit an
674 arbitrary number of HI16 relocs to be associated with a single LO16
675 reloc. This extension permits gcc to output the HI and LO relocs
680 struct mips_hi16
*next
;
685 /* FIXME: This should not be a static variable. */
687 static struct mips_hi16
*mips_hi16_list
;
689 bfd_reloc_status_type
690 _bfd_mips_elf_hi16_reloc (abfd
,
698 arelent
*reloc_entry
;
701 asection
*input_section
;
703 char **error_message
;
705 bfd_reloc_status_type ret
;
709 /* If we're relocating, and this an external symbol, we don't want
710 to change anything. */
711 if (output_bfd
!= (bfd
*) NULL
712 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
713 && reloc_entry
->addend
== 0)
715 reloc_entry
->address
+= input_section
->output_offset
;
721 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
723 boolean relocateable
;
726 if (ret
== bfd_reloc_undefined
)
729 if (output_bfd
!= NULL
)
733 relocateable
= false;
734 output_bfd
= symbol
->section
->output_section
->owner
;
737 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
739 if (ret
!= bfd_reloc_ok
)
742 relocation
= gp
- reloc_entry
->address
;
746 if (bfd_is_und_section (symbol
->section
)
747 && output_bfd
== (bfd
*) NULL
)
748 ret
= bfd_reloc_undefined
;
750 if (bfd_is_com_section (symbol
->section
))
753 relocation
= symbol
->value
;
756 relocation
+= symbol
->section
->output_section
->vma
;
757 relocation
+= symbol
->section
->output_offset
;
758 relocation
+= reloc_entry
->addend
;
760 if (reloc_entry
->address
> input_section
->_cooked_size
)
761 return bfd_reloc_outofrange
;
763 /* Save the information, and let LO16 do the actual relocation. */
764 n
= (struct mips_hi16
*) bfd_malloc (sizeof *n
);
766 return bfd_reloc_outofrange
;
767 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
768 n
->addend
= relocation
;
769 n
->next
= mips_hi16_list
;
772 if (output_bfd
!= (bfd
*) NULL
)
773 reloc_entry
->address
+= input_section
->output_offset
;
778 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
779 inplace relocation; this function exists in order to do the
780 R_MIPS_HI16 relocation described above. */
782 bfd_reloc_status_type
783 _bfd_mips_elf_lo16_reloc (abfd
,
791 arelent
*reloc_entry
;
794 asection
*input_section
;
796 char **error_message
;
798 arelent gp_disp_relent
;
800 if (mips_hi16_list
!= NULL
)
810 struct mips_hi16
*next
;
812 /* Do the HI16 relocation. Note that we actually don't need
813 to know anything about the LO16 itself, except where to
814 find the low 16 bits of the addend needed by the LO16. */
815 insn
= bfd_get_32 (abfd
, l
->addr
);
816 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
818 val
= ((insn
& 0xffff) << 16) + vallo
;
821 /* The low order 16 bits are always treated as a signed
822 value. Therefore, a negative value in the low order bits
823 requires an adjustment in the high order bits. We need
824 to make this adjustment in two ways: once for the bits we
825 took from the data, and once for the bits we are putting
826 back in to the data. */
827 if ((vallo
& 0x8000) != 0)
829 if ((val
& 0x8000) != 0)
832 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
833 bfd_put_32 (abfd
, insn
, l
->addr
);
835 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
837 gp_disp_relent
= *reloc_entry
;
838 reloc_entry
= &gp_disp_relent
;
839 reloc_entry
->addend
= l
->addend
;
847 mips_hi16_list
= NULL
;
849 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
851 bfd_reloc_status_type ret
;
852 bfd_vma gp
, relocation
;
854 /* FIXME: Does this case ever occur? */
856 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
857 if (ret
!= bfd_reloc_ok
)
860 relocation
= gp
- reloc_entry
->address
;
861 relocation
+= symbol
->section
->output_section
->vma
;
862 relocation
+= symbol
->section
->output_offset
;
863 relocation
+= reloc_entry
->addend
;
865 if (reloc_entry
->address
> input_section
->_cooked_size
)
866 return bfd_reloc_outofrange
;
868 gp_disp_relent
= *reloc_entry
;
869 reloc_entry
= &gp_disp_relent
;
870 reloc_entry
->addend
= relocation
- 4;
873 /* Now do the LO16 reloc in the usual way. */
874 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
875 input_section
, output_bfd
, error_message
);
878 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
879 table used for PIC code. If the symbol is an external symbol, the
880 instruction is modified to contain the offset of the appropriate
881 entry in the global offset table. If the symbol is a section
882 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
883 addends are combined to form the real addend against the section
884 symbol; the GOT16 is modified to contain the offset of an entry in
885 the global offset table, and the LO16 is modified to offset it
886 appropriately. Thus an offset larger than 16 bits requires a
887 modified value in the global offset table.
889 This implementation suffices for the assembler, but the linker does
890 not yet know how to create global offset tables. */
892 bfd_reloc_status_type
893 _bfd_mips_elf_got16_reloc (abfd
,
901 arelent
*reloc_entry
;
904 asection
*input_section
;
906 char **error_message
;
908 /* If we're relocating, and this an external symbol, we don't want
909 to change anything. */
910 if (output_bfd
!= (bfd
*) NULL
911 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
912 && reloc_entry
->addend
== 0)
914 reloc_entry
->address
+= input_section
->output_offset
;
918 /* If we're relocating, and this is a local symbol, we can handle it
920 if (output_bfd
!= (bfd
*) NULL
921 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
922 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
923 input_section
, output_bfd
, error_message
);
928 /* We have to figure out the gp value, so that we can adjust the
929 symbol value correctly. We look up the symbol _gp in the output
930 BFD. If we can't find it, we're stuck. We cache it in the ELF
931 target data. We don't need to adjust the symbol value for an
932 external symbol if we are producing relocateable output. */
934 static bfd_reloc_status_type
935 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
938 boolean relocateable
;
939 char **error_message
;
942 if (bfd_is_und_section (symbol
->section
)
946 return bfd_reloc_undefined
;
949 *pgp
= _bfd_get_gp_value (output_bfd
);
952 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
956 /* Make up a value. */
957 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
958 _bfd_set_gp_value (output_bfd
, *pgp
);
966 count
= bfd_get_symcount (output_bfd
);
967 sym
= bfd_get_outsymbols (output_bfd
);
969 if (sym
== (asymbol
**) NULL
)
973 for (i
= 0; i
< count
; i
++, sym
++)
975 register CONST
char *name
;
977 name
= bfd_asymbol_name (*sym
);
978 if (*name
== '_' && strcmp (name
, "_gp") == 0)
980 *pgp
= bfd_asymbol_value (*sym
);
981 _bfd_set_gp_value (output_bfd
, *pgp
);
989 /* Only get the error once. */
991 _bfd_set_gp_value (output_bfd
, *pgp
);
993 (char *) "GP relative relocation when _gp not defined";
994 return bfd_reloc_dangerous
;
1002 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1003 become the offset from the gp register. This function also handles
1004 R_MIPS_LITERAL relocations, although those can be handled more
1005 cleverly because the entries in the .lit8 and .lit4 sections can be
1008 static bfd_reloc_status_type gprel16_with_gp
PARAMS ((bfd
*, asymbol
*,
1009 arelent
*, asection
*,
1010 boolean
, PTR
, bfd_vma
));
1012 bfd_reloc_status_type
1013 _bfd_mips_elf_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1014 output_bfd
, error_message
)
1016 arelent
*reloc_entry
;
1019 asection
*input_section
;
1021 char **error_message
;
1023 boolean relocateable
;
1024 bfd_reloc_status_type ret
;
1027 /* If we're relocating, and this is an external symbol with no
1028 addend, we don't want to change anything. We will only have an
1029 addend if this is a newly created reloc, not read from an ELF
1031 if (output_bfd
!= (bfd
*) NULL
1032 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1033 && reloc_entry
->addend
== 0)
1035 reloc_entry
->address
+= input_section
->output_offset
;
1036 return bfd_reloc_ok
;
1039 if (output_bfd
!= (bfd
*) NULL
)
1040 relocateable
= true;
1043 relocateable
= false;
1044 output_bfd
= symbol
->section
->output_section
->owner
;
1047 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1049 if (ret
!= bfd_reloc_ok
)
1052 return gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1053 relocateable
, data
, gp
);
1056 static bfd_reloc_status_type
1057 gprel16_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1061 arelent
*reloc_entry
;
1062 asection
*input_section
;
1063 boolean relocateable
;
1071 if (bfd_is_com_section (symbol
->section
))
1074 relocation
= symbol
->value
;
1076 relocation
+= symbol
->section
->output_section
->vma
;
1077 relocation
+= symbol
->section
->output_offset
;
1079 if (reloc_entry
->address
> input_section
->_cooked_size
)
1080 return bfd_reloc_outofrange
;
1082 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1084 /* Set val to the offset into the section or symbol. */
1085 if (reloc_entry
->howto
->src_mask
== 0)
1087 /* This case occurs with the 64-bit MIPS ELF ABI. */
1088 val
= reloc_entry
->addend
;
1092 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1097 /* Adjust val for the final section location and GP value. If we
1098 are producing relocateable output, we don't want to do this for
1099 an external symbol. */
1101 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1102 val
+= relocation
- gp
;
1104 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1105 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1108 reloc_entry
->address
+= input_section
->output_offset
;
1110 /* Make sure it fit in 16 bits. */
1111 if (val
>= 0x8000 && val
< 0xffff8000)
1112 return bfd_reloc_overflow
;
1114 return bfd_reloc_ok
;
1117 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset
1118 from the gp register? XXX */
1120 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1121 arelent
*, asection
*,
1122 boolean
, PTR
, bfd_vma
));
1124 bfd_reloc_status_type
1125 _bfd_mips_elf_gprel32_reloc (abfd
,
1133 arelent
*reloc_entry
;
1136 asection
*input_section
;
1138 char **error_message
;
1140 boolean relocateable
;
1141 bfd_reloc_status_type ret
;
1144 /* If we're relocating, and this is an external symbol with no
1145 addend, we don't want to change anything. We will only have an
1146 addend if this is a newly created reloc, not read from an ELF
1148 if (output_bfd
!= (bfd
*) NULL
1149 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1150 && reloc_entry
->addend
== 0)
1152 *error_message
= (char *)
1153 "32bits gp relative relocation occurs for an external symbol";
1154 return bfd_reloc_outofrange
;
1157 if (output_bfd
!= (bfd
*) NULL
)
1159 relocateable
= true;
1160 gp
= _bfd_get_gp_value (output_bfd
);
1164 relocateable
= false;
1165 output_bfd
= symbol
->section
->output_section
->owner
;
1167 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1168 error_message
, &gp
);
1169 if (ret
!= bfd_reloc_ok
)
1173 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1174 relocateable
, data
, gp
);
1177 static bfd_reloc_status_type
1178 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1182 arelent
*reloc_entry
;
1183 asection
*input_section
;
1184 boolean relocateable
;
1191 if (bfd_is_com_section (symbol
->section
))
1194 relocation
= symbol
->value
;
1196 relocation
+= symbol
->section
->output_section
->vma
;
1197 relocation
+= symbol
->section
->output_offset
;
1199 if (reloc_entry
->address
> input_section
->_cooked_size
)
1200 return bfd_reloc_outofrange
;
1202 if (reloc_entry
->howto
->src_mask
== 0)
1204 /* This case arises with the 64-bit MIPS ELF ABI. */
1208 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1210 /* Set val to the offset into the section or symbol. */
1211 val
+= reloc_entry
->addend
;
1213 /* Adjust val for the final section location and GP value. If we
1214 are producing relocateable output, we don't want to do this for
1215 an external symbol. */
1217 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1218 val
+= relocation
- gp
;
1220 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1223 reloc_entry
->address
+= input_section
->output_offset
;
1225 return bfd_reloc_ok
;
1228 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1230 struct elf_reloc_map
{
1231 bfd_reloc_code_real_type bfd_reloc_val
;
1232 enum reloc_type elf_reloc_val
;
1235 static CONST
struct elf_reloc_map mips_reloc_map
[] =
1237 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1238 { BFD_RELOC_16
, R_MIPS_16
},
1239 { BFD_RELOC_32
, R_MIPS_32
},
1240 { BFD_RELOC_CTOR
, R_MIPS_32
},
1241 { BFD_RELOC_32_PCREL
, R_MIPS_REL32
},
1242 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1243 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1244 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1245 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1246 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1247 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1248 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1249 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1250 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1251 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1252 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1253 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1254 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
}
1257 /* Given a BFD reloc type, return a howto structure. */
1259 static reloc_howto_type
*
1260 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1262 bfd_reloc_code_real_type code
;
1266 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1268 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1269 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1274 /* Given a MIPS reloc type, fill in an arelent structure. */
1277 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1280 Elf32_Internal_Rel
*dst
;
1282 unsigned int r_type
;
1284 r_type
= ELF32_R_TYPE (dst
->r_info
);
1285 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1286 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1288 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1289 value for the object file. We get the addend now, rather than
1290 when we do the relocation, because the symbol manipulations done
1291 by the linker may cause us to lose track of the input BFD. */
1292 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1293 && (r_type
== (unsigned int) R_MIPS_GPREL16
1294 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1295 cache_ptr
->addend
= elf_gp (abfd
);
1298 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1299 routines swap this structure in and out. They are used outside of
1300 BFD, so they are globally visible. */
1303 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1305 const Elf32_External_RegInfo
*ex
;
1308 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1309 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1310 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1311 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1312 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1313 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1317 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1319 const Elf32_RegInfo
*in
;
1320 Elf32_External_RegInfo
*ex
;
1322 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1323 (bfd_byte
*) ex
->ri_gprmask
);
1324 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1325 (bfd_byte
*) ex
->ri_cprmask
[0]);
1326 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1327 (bfd_byte
*) ex
->ri_cprmask
[1]);
1328 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1329 (bfd_byte
*) ex
->ri_cprmask
[2]);
1330 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1331 (bfd_byte
*) ex
->ri_cprmask
[3]);
1332 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1333 (bfd_byte
*) ex
->ri_gp_value
);
1336 /* Swap an entry in a .gptab section. Note that these routines rely
1337 on the equivalence of the two elements of the union. */
1340 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1342 const Elf32_External_gptab
*ex
;
1345 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1346 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1350 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1352 const Elf32_gptab
*in
;
1353 Elf32_External_gptab
*ex
;
1355 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1356 ex
->gt_entry
.gt_g_value
);
1357 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1358 ex
->gt_entry
.gt_bytes
);
1362 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1364 const Elf32_compact_rel
*in
;
1365 Elf32_External_compact_rel
*ex
;
1367 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1368 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1369 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1370 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1371 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1372 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1376 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1378 const Elf32_crinfo
*in
;
1379 Elf32_External_crinfo
*ex
;
1383 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1384 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1385 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1386 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1387 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1388 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1389 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1392 /* Swap in an options header. */
1395 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1397 const Elf_External_Options
*ex
;
1398 Elf_Internal_Options
*in
;
1400 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1401 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1402 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1403 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1406 /* Swap out an options header. */
1409 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1411 const Elf_Internal_Options
*in
;
1412 Elf_External_Options
*ex
;
1414 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1415 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1416 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1417 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1420 /* Determine whether a symbol is global for the purposes of splitting
1421 the symbol table into global symbols and local symbols. At least
1422 on Irix 5, this split must be between section symbols and all other
1423 symbols. On most ELF targets the split is between static symbols
1424 and externally visible symbols. */
1428 mips_elf_sym_is_global (abfd
, sym
)
1432 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1435 /* Set the right machine number for a MIPS ELF file. This is used for
1436 both the 32-bit and the 64-bit ABI. */
1439 _bfd_mips_elf_object_p (abfd
)
1442 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
1446 /* Just use the default, which was set in elfcode.h. */
1450 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 6000);
1454 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 4000);
1458 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 8000);
1465 /* Set the right machine number for a 32-bit MIPS ELF file. */
1468 mips_elf32_object_p (abfd
)
1471 /* Irix 5 is broken. Object file symbol tables are not always
1472 sorted correctly such that local symbols precede global symbols,
1473 and the sh_info field in the symbol table is not always right. */
1474 elf_bad_symtab (abfd
) = true;
1476 return _bfd_mips_elf_object_p (abfd
);
1479 /* The final processing done just before writing out a MIPS ELF object
1480 file. This gets the MIPS architecture right based on the machine
1481 number. This is used by both the 32-bit and the 64-bit ABI. */
1485 _bfd_mips_elf_final_write_processing (abfd
, linker
)
1491 Elf_Internal_Shdr
**hdrpp
;
1493 switch (bfd_get_mach (abfd
))
1496 val
= E_MIPS_ARCH_1
;
1500 val
= E_MIPS_ARCH_2
;
1504 val
= E_MIPS_ARCH_3
;
1508 val
= E_MIPS_ARCH_4
;
1516 elf_elfheader (abfd
)->e_flags
&=~ EF_MIPS_ARCH
;
1517 elf_elfheader (abfd
)->e_flags
|= val
;
1519 /* Set the sh_info field for .gptab sections. */
1520 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
1521 i
< elf_elfheader (abfd
)->e_shnum
;
1524 if ((*hdrpp
)->sh_type
== SHT_MIPS_GPTAB
)
1529 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1530 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1531 BFD_ASSERT (name
!= NULL
1532 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
1533 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
1534 BFD_ASSERT (sec
!= NULL
);
1535 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1540 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1543 _bfd_mips_elf_set_private_flags (abfd
, flags
)
1547 BFD_ASSERT (!elf_flags_init (abfd
)
1548 || elf_elfheader (abfd
)->e_flags
== flags
);
1550 elf_elfheader (abfd
)->e_flags
= flags
;
1551 elf_flags_init (abfd
) = true;
1555 /* Copy backend specific data from one object module to another */
1558 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
1562 /* This function is selected based on the input vector. We only
1563 want to copy information over if the output BFD also uses Elf
1565 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1568 BFD_ASSERT (!elf_flags_init (obfd
)
1569 || (elf_elfheader (obfd
)->e_flags
1570 == elf_elfheader (ibfd
)->e_flags
));
1572 elf_gp (obfd
) = elf_gp (ibfd
);
1573 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1574 elf_flags_init (obfd
) = true;
1578 /* Merge backend specific data from an object file to the output
1579 object file when linking. */
1582 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
1589 /* Check if we have the same endianess */
1590 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1591 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1593 (*_bfd_error_handler
)
1594 ("%s: compiled for a %s endian system and target is %s endian",
1595 bfd_get_filename (ibfd
),
1596 bfd_big_endian (ibfd
) ? "big" : "little",
1597 bfd_big_endian (obfd
) ? "big" : "little");
1599 bfd_set_error (bfd_error_wrong_format
);
1603 /* This function is selected based on the input vector. We only
1604 want to copy information over if the output BFD also uses Elf
1606 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1609 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1610 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
1611 old_flags
= elf_elfheader (obfd
)->e_flags
;
1613 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1615 elf_flags_init (obfd
) = true;
1616 elf_elfheader (obfd
)->e_flags
= new_flags
;
1618 else if (((new_flags
^ old_flags
) & ~EF_MIPS_NOREORDER
)
1619 == 0) /* Compatible flags are ok */
1621 else /* Incompatible flags */
1623 /* Warn about -fPIC mismatch */
1624 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
1626 new_flags
&= ~EF_MIPS_PIC
;
1627 (*_bfd_error_handler
)
1628 ("%s: needs all files compiled with -fPIC",
1629 bfd_get_filename (ibfd
));
1632 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
1634 new_flags
&= ~EF_MIPS_CPIC
;
1635 (*_bfd_error_handler
)
1636 ("%s: needs all files compiled with -mabicalls",
1637 bfd_get_filename (ibfd
));
1640 /* Warn about any other mismatches */
1641 if (new_flags
!= old_flags
)
1642 (*_bfd_error_handler
)
1643 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1644 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
1645 (unsigned long) old_flags
);
1647 bfd_set_error (bfd_error_bad_value
);
1654 /* Handle a MIPS specific section when reading an object file. This
1655 is called when elfcode.h finds a section with an unknown type.
1656 This routine supports both the 32-bit and 64-bit ELF ABI.
1658 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1662 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
1664 Elf_Internal_Shdr
*hdr
;
1667 /* There ought to be a place to keep ELF backend specific flags, but
1668 at the moment there isn't one. We just keep track of the
1669 sections by their name, instead. Fortunately, the ABI gives
1670 suggested names for all the MIPS specific sections, so we will
1671 probably get away with this. */
1672 switch (hdr
->sh_type
)
1674 case SHT_MIPS_LIBLIST
:
1675 if (strcmp (name
, ".liblist") != 0)
1679 if (strcmp (name
, ".msym") != 0)
1682 case SHT_MIPS_CONFLICT
:
1683 if (strcmp (name
, ".conflict") != 0)
1686 case SHT_MIPS_GPTAB
:
1687 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
1690 case SHT_MIPS_UCODE
:
1691 if (strcmp (name
, ".ucode") != 0)
1694 case SHT_MIPS_DEBUG
:
1695 if (strcmp (name
, ".mdebug") != 0)
1698 case SHT_MIPS_REGINFO
:
1699 if (strcmp (name
, ".reginfo") != 0
1700 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
1703 case SHT_MIPS_OPTIONS
:
1704 if (strcmp (name
, ".options") != 0
1705 && strcmp (name
, ".MIPS.options") != 0)
1708 case SHT_MIPS_DWARF
:
1709 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
1712 case SHT_MIPS_EVENTS
:
1713 if (strncmp (name
, ".MIPS.events.", sizeof ".MIPS.events." - 1) != 0)
1720 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1723 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
1725 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
1726 (bfd_get_section_flags (abfd
,
1735 /* Handle a 32-bit MIPS ELF specific section. */
1738 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
1740 Elf_Internal_Shdr
*hdr
;
1743 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
1746 /* FIXME: We should record sh_info for a .gptab section. */
1748 /* For a .reginfo section, set the gp value in the tdata information
1749 from the contents of this section. We need the gp value while
1750 processing relocs, so we just get it now. The .reginfo section
1751 is not used in the 64-bit MIPS ELF ABI. */
1752 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
1754 Elf32_External_RegInfo ext
;
1757 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
1758 (file_ptr
) 0, sizeof ext
))
1760 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
1761 elf_gp (abfd
) = s
.ri_gp_value
;
1764 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
1765 set the gp value based on what we find. We may see both
1766 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
1767 they should agree. */
1768 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
1770 bfd_byte
*contents
, *l
, *lend
;
1772 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
1773 if (contents
== NULL
)
1775 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
1776 (file_ptr
) 0, hdr
->sh_size
))
1782 lend
= contents
+ hdr
->sh_size
;
1783 while (l
+ sizeof (Elf_External_Options
) <= lend
)
1785 Elf_Internal_Options intopt
;
1787 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
1789 if (intopt
.kind
== ODK_REGINFO
)
1791 Elf32_RegInfo intreg
;
1793 bfd_mips_elf32_swap_reginfo_in
1795 ((Elf32_External_RegInfo
*)
1796 (l
+ sizeof (Elf_External_Options
))),
1798 elf_gp (abfd
) = intreg
.ri_gp_value
;
1808 /* Set the correct type for a MIPS ELF section. We do this by the
1809 section name, which is a hack, but ought to work. This routine is
1810 used by both the 32-bit and the 64-bit ABI. */
1813 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
1815 Elf32_Internal_Shdr
*hdr
;
1818 register const char *name
;
1820 name
= bfd_get_section_name (abfd
, sec
);
1822 if (strcmp (name
, ".liblist") == 0)
1824 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
1825 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
1826 /* FIXME: Set the sh_link field. */
1828 else if (strcmp (name
, ".msym") == 0)
1830 hdr
->sh_type
= SHT_MIPS_MSYM
;
1831 hdr
->sh_entsize
= 8;
1832 /* FIXME: Set the sh_info field. */
1834 else if (strcmp (name
, ".conflict") == 0)
1835 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
1836 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
1838 hdr
->sh_type
= SHT_MIPS_GPTAB
;
1839 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
1840 /* The sh_info field is set in final_write_processing. */
1842 else if (strcmp (name
, ".ucode") == 0)
1843 hdr
->sh_type
= SHT_MIPS_UCODE
;
1844 else if (strcmp (name
, ".mdebug") == 0)
1846 hdr
->sh_type
= SHT_MIPS_DEBUG
;
1847 /* In a shared object on Irix 5.3, the .mdebug section has an
1848 entsize of 0. FIXME: Does this matter? */
1849 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1850 hdr
->sh_entsize
= 0;
1852 hdr
->sh_entsize
= 1;
1854 else if (strcmp (name
, ".reginfo") == 0)
1856 hdr
->sh_type
= SHT_MIPS_REGINFO
;
1857 /* In a shared object on Irix 5.3, the .reginfo section has an
1858 entsize of 0x18. FIXME: Does this matter? */
1859 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1860 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
1862 hdr
->sh_entsize
= 1;
1864 /* Force the section size to the correct value, even if the
1865 linker thinks it is larger. The link routine below will only
1866 write out this much data for .reginfo. */
1867 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
1869 else if (SGI_COMPAT (abfd
)
1870 && (strcmp (name
, ".hash") == 0
1871 || strcmp (name
, ".dynamic") == 0
1872 || strcmp (name
, ".dynstr") == 0))
1874 hdr
->sh_entsize
= 0;
1875 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
1877 else if (strcmp (name
, ".got") == 0
1878 || strcmp (name
, ".sdata") == 0
1879 || strcmp (name
, ".sbss") == 0
1880 || strcmp (name
, ".lit4") == 0
1881 || strcmp (name
, ".lit8") == 0)
1882 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
1883 else if (strcmp (name
, ".options") == 0
1884 || strcmp (name
, ".MIPS.options") == 0)
1886 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
1887 hdr
->sh_entsize
= 1;
1889 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
1890 hdr
->sh_type
= SHT_MIPS_DWARF
;
1891 else if (strncmp (name
, ".MIPS.events.", sizeof ".MIPS.events." - 1) == 0)
1892 hdr
->sh_type
= SHT_MIPS_EVENTS
;
1897 /* Given a BFD section, try to locate the corresponding ELF section
1898 index. This is used by both the 32-bit and the 64-bit ABI.
1899 Actually, it's not clear to me that the 64-bit ABI supports these,
1900 but for non-PIC objects we will certainly want support for at least
1901 the .scommon section. */
1904 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
1906 Elf32_Internal_Shdr
*hdr
;
1910 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
1912 *retval
= SHN_MIPS_SCOMMON
;
1915 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
1917 *retval
= SHN_MIPS_ACOMMON
;
1923 /* When are writing out the .options or .MIPS.options section,
1924 remember the bytes we are writing out, so that we can install the
1925 GP value in the section_processing routine. */
1928 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
1933 bfd_size_type count
;
1935 if (strcmp (section
->name
, ".options") == 0
1936 || strcmp (section
->name
, ".MIPS.options") == 0)
1940 if (elf_section_data (section
) == NULL
)
1942 section
->used_by_bfd
=
1943 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
1944 if (elf_section_data (section
) == NULL
)
1947 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
1952 if (section
->_cooked_size
!= 0)
1953 size
= section
->_cooked_size
;
1955 size
= section
->_raw_size
;
1956 c
= (PTR
) bfd_zalloc (abfd
, size
);
1959 elf_section_data (section
)->tdata
= (PTR
) c
;
1962 memcpy (c
+ offset
, location
, count
);
1965 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
1969 /* Work over a section just before writing it out. This routine is
1970 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
1971 sections that need the SHF_MIPS_GPREL flag by name; there has to be
1975 _bfd_mips_elf_section_processing (abfd
, hdr
)
1977 Elf_Internal_Shdr
*hdr
;
1979 if (hdr
->bfd_section
!= NULL
)
1981 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
1983 if (strcmp (name
, ".sdata") == 0)
1985 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1986 hdr
->sh_type
= SHT_PROGBITS
;
1988 else if (strcmp (name
, ".sbss") == 0)
1990 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1991 hdr
->sh_type
= SHT_NOBITS
;
1993 else if (strcmp (name
, ".lit8") == 0
1994 || strcmp (name
, ".lit4") == 0)
1996 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1997 hdr
->sh_type
= SHT_PROGBITS
;
1999 else if (strcmp (name
, ".compact_rel") == 0)
2002 hdr
->sh_type
= SHT_PROGBITS
;
2004 else if (strcmp (name
, ".rtproc") == 0)
2006 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2008 unsigned int adjust
;
2010 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2012 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2020 /* Work over a section just before writing it out. We update the GP
2021 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2022 on the value we are using. */
2025 mips_elf32_section_processing (abfd
, hdr
)
2027 Elf32_Internal_Shdr
*hdr
;
2029 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2033 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2034 BFD_ASSERT (hdr
->contents
== NULL
);
2037 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2040 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2041 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2045 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2046 && hdr
->bfd_section
!= NULL
2047 && elf_section_data (hdr
->bfd_section
) != NULL
2048 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2050 bfd_byte
*contents
, *l
, *lend
;
2052 /* We stored the section contents in the elf_section_data tdata
2053 field in the set_section_contents routine. We save the
2054 section contents so that we don't have to read them again.
2055 At this point we know that elf_gp is set, so we can look
2056 through the section contents to see if there is an
2057 ODK_REGINFO structure. */
2059 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2061 lend
= contents
+ hdr
->sh_size
;
2062 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2064 Elf_Internal_Options intopt
;
2066 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2068 if (intopt
.kind
== ODK_REGINFO
)
2075 + sizeof (Elf_External_Options
)
2076 + (sizeof (Elf32_External_RegInfo
) - 4)),
2079 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2080 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2087 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2090 /* MIPS ELF uses two common sections. One is the usual one, and the
2091 other is for small objects. All the small objects are kept
2092 together, and then referenced via the gp pointer, which yields
2093 faster assembler code. This is what we use for the small common
2094 section. This approach is copied from ecoff.c. */
2095 static asection mips_elf_scom_section
;
2096 static asymbol mips_elf_scom_symbol
;
2097 static asymbol
*mips_elf_scom_symbol_ptr
;
2099 /* MIPS ELF also uses an acommon section, which represents an
2100 allocated common symbol which may be overridden by a
2101 definition in a shared library. */
2102 static asection mips_elf_acom_section
;
2103 static asymbol mips_elf_acom_symbol
;
2104 static asymbol
*mips_elf_acom_symbol_ptr
;
2106 /* The Irix 5 support uses two virtual sections, which represent
2107 text/data symbols defined in dynamic objects. */
2108 static asection mips_elf_text_section
;
2109 static asection
*mips_elf_text_section_ptr
;
2110 static asymbol mips_elf_text_symbol
;
2111 static asymbol
*mips_elf_text_symbol_ptr
;
2113 static asection mips_elf_data_section
;
2114 static asection
*mips_elf_data_section_ptr
;
2115 static asymbol mips_elf_data_symbol
;
2116 static asymbol
*mips_elf_data_symbol_ptr
;
2118 /* Handle the special MIPS section numbers that a symbol may use.
2119 This is used for both the 32-bit and the 64-bit ABI. */
2122 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2126 elf_symbol_type
*elfsym
;
2128 elfsym
= (elf_symbol_type
*) asym
;
2129 switch (elfsym
->internal_elf_sym
.st_shndx
)
2131 case SHN_MIPS_ACOMMON
:
2132 /* This section is used in a dynamically linked executable file.
2133 It is an allocated common section. The dynamic linker can
2134 either resolve these symbols to something in a shared
2135 library, or it can just leave them here. For our purposes,
2136 we can consider these symbols to be in a new section. */
2137 if (mips_elf_acom_section
.name
== NULL
)
2139 /* Initialize the acommon section. */
2140 mips_elf_acom_section
.name
= ".acommon";
2141 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2142 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2143 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2144 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2145 mips_elf_acom_symbol
.name
= ".acommon";
2146 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2147 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2148 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2150 asym
->section
= &mips_elf_acom_section
;
2154 /* Common symbols less than the GP size are automatically
2155 treated as SHN_MIPS_SCOMMON symbols. */
2156 if (asym
->value
> elf_gp_size (abfd
))
2159 case SHN_MIPS_SCOMMON
:
2160 if (mips_elf_scom_section
.name
== NULL
)
2162 /* Initialize the small common section. */
2163 mips_elf_scom_section
.name
= ".scommon";
2164 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2165 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2166 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2167 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2168 mips_elf_scom_symbol
.name
= ".scommon";
2169 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2170 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2171 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2173 asym
->section
= &mips_elf_scom_section
;
2174 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2177 case SHN_MIPS_SUNDEFINED
:
2178 asym
->section
= bfd_und_section_ptr
;
2181 #if 0 /* for SGI_COMPAT */
2183 asym
->section
= mips_elf_text_section_ptr
;
2187 asym
->section
= mips_elf_data_section_ptr
;
2193 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2197 mips_elf_additional_program_headers (abfd
)
2205 if (! SGI_COMPAT (abfd
))
2208 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2209 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2211 /* We need a PT_MIPS_REGINFO segment. */
2215 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2216 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2218 /* We need a PT_MIPS_RTPROC segment. */
2225 /* Modify the segment map for an Irix 5 executable. */
2228 mips_elf_modify_segment_map (abfd
)
2232 struct elf_segment_map
*m
, **pm
;
2234 if (! SGI_COMPAT (abfd
))
2237 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2239 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2240 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2242 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2243 if (m
->p_type
== PT_MIPS_REGINFO
)
2247 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2251 m
->p_type
= PT_MIPS_REGINFO
;
2255 /* We want to put it after the PHDR and INTERP segments. */
2256 pm
= &elf_tdata (abfd
)->segment_map
;
2258 && ((*pm
)->p_type
== PT_PHDR
2259 || (*pm
)->p_type
== PT_INTERP
))
2267 /* If there are .dynamic and .mdebug sections, we make a room for
2268 the RTPROC header. FIXME: Rewrite without section names. */
2269 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2270 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2271 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2273 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2274 if (m
->p_type
== PT_MIPS_RTPROC
)
2278 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2282 m
->p_type
= PT_MIPS_RTPROC
;
2284 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2289 m
->p_flags_valid
= 1;
2297 /* We want to put it after the DYNAMIC segment. */
2298 pm
= &elf_tdata (abfd
)->segment_map
;
2299 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2309 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2310 .dynsym, and .hash sections, and everything in between. */
2311 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2312 if ((*pm
)->p_type
== PT_DYNAMIC
)
2317 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2319 static const char *sec_names
[] =
2320 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2323 struct elf_segment_map
*n
;
2327 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
2329 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
2330 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2336 sz
= s
->_cooked_size
;
2339 if (high
< s
->vma
+ sz
)
2345 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2346 if ((s
->flags
& SEC_LOAD
) != 0
2349 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2353 n
= ((struct elf_segment_map
*)
2354 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
2361 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2363 if ((s
->flags
& SEC_LOAD
) != 0
2366 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2380 /* The structure of the runtime procedure descriptor created by the
2381 loader for use by the static exception system. */
2383 typedef struct runtime_pdr
{
2384 bfd_vma adr
; /* memory address of start of procedure */
2385 long regmask
; /* save register mask */
2386 long regoffset
; /* save register offset */
2387 long fregmask
; /* save floating point register mask */
2388 long fregoffset
; /* save floating point register offset */
2389 long frameoffset
; /* frame size */
2390 short framereg
; /* frame pointer register */
2391 short pcreg
; /* offset or reg of return pc */
2392 long irpss
; /* index into the runtime string table */
2394 struct exception_info
*exception_info
;/* pointer to exception array */
2396 #define cbRPDR sizeof(RPDR)
2397 #define rpdNil ((pRPDR) 0)
2399 /* Swap RPDR (runtime procedure table entry) for output. */
2401 static void ecoff_swap_rpdr_out
2402 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
2405 ecoff_swap_rpdr_out (abfd
, in
, ex
)
2408 struct rpdr_ext
*ex
;
2410 /* ecoff_put_off was defined in ecoffswap.h. */
2411 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
2412 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
2413 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
2414 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
2415 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
2416 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
2418 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
2419 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
2421 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
2423 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
2427 /* Read ECOFF debugging information from a .mdebug section into a
2428 ecoff_debug_info structure. */
2431 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
2434 struct ecoff_debug_info
*debug
;
2437 const struct ecoff_debug_swap
*swap
;
2438 char *ext_hdr
= NULL
;
2440 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2442 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
2443 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2446 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2447 swap
->external_hdr_size
)
2451 symhdr
= &debug
->symbolic_header
;
2452 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2454 /* The symbolic header contains absolute file offsets and sizes to
2456 #define READ(ptr, offset, count, size, type) \
2457 if (symhdr->count == 0) \
2458 debug->ptr = NULL; \
2461 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2462 if (debug->ptr == NULL) \
2463 goto error_return; \
2464 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2465 || (bfd_read (debug->ptr, size, symhdr->count, \
2466 abfd) != size * symhdr->count)) \
2467 goto error_return; \
2470 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2471 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2472 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2473 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2474 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2475 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2477 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2478 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2479 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2480 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2481 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2485 debug
->adjust
= NULL
;
2490 if (ext_hdr
!= NULL
)
2492 if (debug
->line
!= NULL
)
2494 if (debug
->external_dnr
!= NULL
)
2495 free (debug
->external_dnr
);
2496 if (debug
->external_pdr
!= NULL
)
2497 free (debug
->external_pdr
);
2498 if (debug
->external_sym
!= NULL
)
2499 free (debug
->external_sym
);
2500 if (debug
->external_opt
!= NULL
)
2501 free (debug
->external_opt
);
2502 if (debug
->external_aux
!= NULL
)
2503 free (debug
->external_aux
);
2504 if (debug
->ss
!= NULL
)
2506 if (debug
->ssext
!= NULL
)
2507 free (debug
->ssext
);
2508 if (debug
->external_fdr
!= NULL
)
2509 free (debug
->external_fdr
);
2510 if (debug
->external_rfd
!= NULL
)
2511 free (debug
->external_rfd
);
2512 if (debug
->external_ext
!= NULL
)
2513 free (debug
->external_ext
);
2517 /* MIPS ELF local labels start with '$', not 'L'. */
2521 mips_elf_is_local_label (abfd
, symbol
)
2525 return symbol
->name
[0] == '$';
2528 /* MIPS ELF uses a special find_nearest_line routine in order the
2529 handle the ECOFF debugging information. */
2531 struct mips_elf_find_line
2533 struct ecoff_debug_info d
;
2534 struct ecoff_find_line i
;
2538 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2539 functionname_ptr
, line_ptr
)
2544 const char **filename_ptr
;
2545 const char **functionname_ptr
;
2546 unsigned int *line_ptr
;
2550 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2554 struct mips_elf_find_line
*fi
;
2555 const struct ecoff_debug_swap
* const swap
=
2556 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2558 /* If we are called during a link, mips_elf_final_link may have
2559 cleared the SEC_HAS_CONTENTS field. We force it back on here
2560 if appropriate (which it normally will be). */
2561 origflags
= msec
->flags
;
2562 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2563 msec
->flags
|= SEC_HAS_CONTENTS
;
2565 fi
= elf_tdata (abfd
)->find_line_info
;
2568 bfd_size_type external_fdr_size
;
2571 struct fdr
*fdr_ptr
;
2573 fi
= ((struct mips_elf_find_line
*)
2574 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
2577 msec
->flags
= origflags
;
2581 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
2583 msec
->flags
= origflags
;
2587 /* Swap in the FDR information. */
2588 fi
->d
.fdr
= ((struct fdr
*)
2590 (fi
->d
.symbolic_header
.ifdMax
*
2591 sizeof (struct fdr
))));
2592 if (fi
->d
.fdr
== NULL
)
2594 msec
->flags
= origflags
;
2597 external_fdr_size
= swap
->external_fdr_size
;
2598 fdr_ptr
= fi
->d
.fdr
;
2599 fraw_src
= (char *) fi
->d
.external_fdr
;
2600 fraw_end
= (fraw_src
2601 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2602 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2603 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2605 elf_tdata (abfd
)->find_line_info
= fi
;
2607 /* Note that we don't bother to ever free this information.
2608 find_nearest_line is either called all the time, as in
2609 objdump -l, so the information should be saved, or it is
2610 rarely called, as in ld error messages, so the memory
2611 wasted is unimportant. Still, it would probably be a
2612 good idea for free_cached_info to throw it away. */
2615 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2616 &fi
->i
, filename_ptr
, functionname_ptr
,
2619 msec
->flags
= origflags
;
2623 msec
->flags
= origflags
;
2626 /* Fall back on the generic ELF find_nearest_line routine. */
2628 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2629 filename_ptr
, functionname_ptr
,
2633 /* The MIPS ELF linker needs additional information for each symbol in
2634 the global hash table. */
2636 struct mips_elf_link_hash_entry
2638 struct elf_link_hash_entry root
;
2640 /* External symbol information. */
2643 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
2644 unsigned int mips_32_relocs
;
2647 /* MIPS ELF linker hash table. */
2649 struct mips_elf_link_hash_table
2651 struct elf_link_hash_table root
;
2652 /* String section indices for the dynamic section symbols. */
2653 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
2654 /* The number of .rtproc entries. */
2655 bfd_size_type procedure_count
;
2656 /* The size of the .compact_rel section (if SGI_COMPAT). */
2657 bfd_size_type compact_rel_size
;
2660 /* Look up an entry in a MIPS ELF linker hash table. */
2662 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
2663 ((struct mips_elf_link_hash_entry *) \
2664 elf_link_hash_lookup (&(table)->root, (string), (create), \
2667 /* Traverse a MIPS ELF linker hash table. */
2669 #define mips_elf_link_hash_traverse(table, func, info) \
2670 (elf_link_hash_traverse \
2672 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
2675 /* Get the MIPS ELF linker hash table from a link_info structure. */
2677 #define mips_elf_hash_table(p) \
2678 ((struct mips_elf_link_hash_table *) ((p)->hash))
2680 static boolean mips_elf_output_extsym
2681 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
2683 /* Create an entry in a MIPS ELF linker hash table. */
2685 static struct bfd_hash_entry
*
2686 mips_elf_link_hash_newfunc (entry
, table
, string
)
2687 struct bfd_hash_entry
*entry
;
2688 struct bfd_hash_table
*table
;
2691 struct mips_elf_link_hash_entry
*ret
=
2692 (struct mips_elf_link_hash_entry
*) entry
;
2694 /* Allocate the structure if it has not already been allocated by a
2696 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2697 ret
= ((struct mips_elf_link_hash_entry
*)
2698 bfd_hash_allocate (table
,
2699 sizeof (struct mips_elf_link_hash_entry
)));
2700 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2701 return (struct bfd_hash_entry
*) ret
;
2703 /* Call the allocation method of the superclass. */
2704 ret
= ((struct mips_elf_link_hash_entry
*)
2705 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2707 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
2709 /* Set local fields. */
2710 memset (&ret
->esym
, 0, sizeof (EXTR
));
2711 /* We use -2 as a marker to indicate that the information has
2712 not been set. -1 means there is no associated ifd. */
2714 ret
->mips_32_relocs
= 0;
2717 return (struct bfd_hash_entry
*) ret
;
2720 /* Create a MIPS ELF linker hash table. */
2722 static struct bfd_link_hash_table
*
2723 mips_elf_link_hash_table_create (abfd
)
2726 struct mips_elf_link_hash_table
*ret
;
2729 ret
= ((struct mips_elf_link_hash_table
*)
2730 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
2731 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
2734 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
2735 mips_elf_link_hash_newfunc
))
2737 bfd_release (abfd
, ret
);
2741 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
2742 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
2743 ret
->procedure_count
= 0;
2744 ret
->compact_rel_size
= 0;
2746 return &ret
->root
.root
;
2749 /* Hook called by the linker routine which adds symbols from an object
2750 file. We must handle the special MIPS section numbers here. */
2754 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2756 struct bfd_link_info
*info
;
2757 const Elf_Internal_Sym
*sym
;
2763 if (SGI_COMPAT (abfd
)
2764 && (abfd
->flags
& DYNAMIC
) != 0
2765 && strcmp (*namep
, "_rld_new_interface") == 0)
2767 /* Skip Irix 5 rld entry name. */
2772 switch (sym
->st_shndx
)
2775 /* Common symbols less than the GP size are automatically
2776 treated as SHN_MIPS_SCOMMON symbols. */
2777 if (sym
->st_size
> elf_gp_size (abfd
))
2780 case SHN_MIPS_SCOMMON
:
2781 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2782 (*secp
)->flags
|= SEC_IS_COMMON
;
2783 *valp
= sym
->st_size
;
2787 /* This section is used in a shared object. */
2788 if (mips_elf_text_section_ptr
== NULL
)
2790 /* Initialize the section. */
2791 mips_elf_text_section
.name
= ".text";
2792 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
2793 mips_elf_text_section
.output_section
= NULL
;
2794 mips_elf_text_section
.owner
= abfd
;
2795 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
2796 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
2797 mips_elf_text_symbol
.name
= ".text";
2798 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
2799 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
2800 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
2801 mips_elf_text_section_ptr
= &mips_elf_text_section
;
2804 *secp
= bfd_und_section_ptr
;
2806 *secp
= mips_elf_text_section_ptr
;
2809 case SHN_MIPS_ACOMMON
:
2810 /* Fall through. XXX Can we treat this as allocated data? */
2812 /* This section is used in a shared object. */
2813 if (mips_elf_data_section_ptr
== NULL
)
2815 /* Initialize the section. */
2816 mips_elf_data_section
.name
= ".data";
2817 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
2818 mips_elf_data_section
.output_section
= NULL
;
2819 mips_elf_data_section
.owner
= abfd
;
2820 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
2821 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
2822 mips_elf_data_symbol
.name
= ".data";
2823 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
2824 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
2825 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
2826 mips_elf_data_section_ptr
= &mips_elf_data_section
;
2829 *secp
= bfd_und_section_ptr
;
2831 *secp
= mips_elf_data_section_ptr
;
2834 case SHN_MIPS_SUNDEFINED
:
2835 *secp
= bfd_und_section_ptr
;
2842 /* Structure used to pass information to mips_elf_output_extsym. */
2847 struct bfd_link_info
*info
;
2848 struct ecoff_debug_info
*debug
;
2849 const struct ecoff_debug_swap
*swap
;
2853 /* This routine is used to write out ECOFF debugging external symbol
2854 information. It is called via mips_elf_link_hash_traverse. The
2855 ECOFF external symbol information must match the ELF external
2856 symbol information. Unfortunately, at this point we don't know
2857 whether a symbol is required by reloc information, so the two
2858 tables may wind up being different. We must sort out the external
2859 symbol information before we can set the final size of the .mdebug
2860 section, and we must set the size of the .mdebug section before we
2861 can relocate any sections, and we can't know which symbols are
2862 required by relocation until we relocate the sections.
2863 Fortunately, it is relatively unlikely that any symbol will be
2864 stripped but required by a reloc. In particular, it can not happen
2865 when generating a final executable. */
2868 mips_elf_output_extsym (h
, data
)
2869 struct mips_elf_link_hash_entry
*h
;
2872 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
2874 asection
*sec
, *output_section
;
2876 if (h
->root
.indx
== -2)
2878 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2879 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
2880 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2881 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
2883 else if (einfo
->info
->strip
== strip_all
2884 || (einfo
->info
->strip
== strip_some
2885 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2886 h
->root
.root
.root
.string
,
2887 false, false) == NULL
))
2895 if (h
->esym
.ifd
== -2)
2898 h
->esym
.cobol_main
= 0;
2899 h
->esym
.weakext
= 0;
2900 h
->esym
.reserved
= 0;
2901 h
->esym
.ifd
= ifdNil
;
2902 h
->esym
.asym
.value
= 0;
2903 h
->esym
.asym
.st
= stGlobal
;
2905 if (SGI_COMPAT (einfo
->abfd
)
2906 && (h
->root
.root
.type
== bfd_link_hash_undefined
2907 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
2911 /* Use undefined class. Also, set class and type for some
2913 name
= h
->root
.root
.root
.string
;
2914 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2915 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2917 h
->esym
.asym
.sc
= scData
;
2918 h
->esym
.asym
.st
= stLabel
;
2919 h
->esym
.asym
.value
= 0;
2921 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2923 h
->esym
.asym
.sc
= scAbs
;
2924 h
->esym
.asym
.st
= stLabel
;
2925 h
->esym
.asym
.value
=
2926 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2928 else if (strcmp (name
, "_gp_disp") == 0)
2930 h
->esym
.asym
.sc
= scAbs
;
2931 h
->esym
.asym
.st
= stLabel
;
2932 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2935 h
->esym
.asym
.sc
= scUndefined
;
2937 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2938 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2939 h
->esym
.asym
.sc
= scAbs
;
2944 sec
= h
->root
.root
.u
.def
.section
;
2945 output_section
= sec
->output_section
;
2947 /* When making a shared library and symbol h is the one from
2948 the another shared library, OUTPUT_SECTION may be null. */
2949 if (output_section
== NULL
)
2950 h
->esym
.asym
.sc
= scUndefined
;
2953 name
= bfd_section_name (output_section
->owner
, output_section
);
2955 if (strcmp (name
, ".text") == 0)
2956 h
->esym
.asym
.sc
= scText
;
2957 else if (strcmp (name
, ".data") == 0)
2958 h
->esym
.asym
.sc
= scData
;
2959 else if (strcmp (name
, ".sdata") == 0)
2960 h
->esym
.asym
.sc
= scSData
;
2961 else if (strcmp (name
, ".rodata") == 0
2962 || strcmp (name
, ".rdata") == 0)
2963 h
->esym
.asym
.sc
= scRData
;
2964 else if (strcmp (name
, ".bss") == 0)
2965 h
->esym
.asym
.sc
= scBss
;
2966 else if (strcmp (name
, ".sbss") == 0)
2967 h
->esym
.asym
.sc
= scSBss
;
2968 else if (strcmp (name
, ".init") == 0)
2969 h
->esym
.asym
.sc
= scInit
;
2970 else if (strcmp (name
, ".fini") == 0)
2971 h
->esym
.asym
.sc
= scFini
;
2973 h
->esym
.asym
.sc
= scAbs
;
2977 h
->esym
.asym
.reserved
= 0;
2978 h
->esym
.asym
.index
= indexNil
;
2981 if (h
->root
.root
.type
== bfd_link_hash_common
)
2982 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2983 else if (h
->root
.root
.type
== bfd_link_hash_defined
2984 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2986 if (h
->esym
.asym
.sc
== scCommon
)
2987 h
->esym
.asym
.sc
= scBss
;
2988 else if (h
->esym
.asym
.sc
== scSCommon
)
2989 h
->esym
.asym
.sc
= scSBss
;
2991 sec
= h
->root
.root
.u
.def
.section
;
2992 output_section
= sec
->output_section
;
2993 if (output_section
!= NULL
)
2994 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2995 + sec
->output_offset
2996 + output_section
->vma
);
2998 h
->esym
.asym
.value
= 0;
3000 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3002 /* Set type and value for a symbol with a function stub. */
3003 h
->esym
.asym
.st
= stProc
;
3004 sec
= h
->root
.root
.u
.def
.section
;
3006 h
->esym
.asym
.value
= 0;
3009 output_section
= sec
->output_section
;
3010 if (output_section
!= NULL
)
3011 h
->esym
.asym
.value
= (h
->root
.plt_offset
3012 + sec
->output_offset
3013 + output_section
->vma
);
3015 h
->esym
.asym
.value
= 0;
3022 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3023 h
->root
.root
.root
.string
,
3026 einfo
->failed
= true;
3033 /* Create a runtime procedure table from the .mdebug section. */
3036 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3039 struct bfd_link_info
*info
;
3041 struct ecoff_debug_info
*debug
;
3043 const struct ecoff_debug_swap
*swap
;
3044 HDRR
*hdr
= &debug
->symbolic_header
;
3046 struct rpdr_ext
*erp
;
3048 struct pdr_ext
*epdr
;
3049 struct sym_ext
*esym
;
3052 unsigned long size
, count
;
3053 unsigned long sindex
;
3057 const char *no_name_func
= "static procedure (no name)";
3065 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3067 sindex
= strlen (no_name_func
) + 1;
3068 count
= hdr
->ipdMax
;
3071 size
= swap
->external_pdr_size
;
3073 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3077 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3080 size
= sizeof (RPDR
);
3081 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3085 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3089 count
= hdr
->isymMax
;
3090 size
= swap
->external_sym_size
;
3091 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3095 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3098 count
= hdr
->issMax
;
3099 ss
= (char *) bfd_malloc (count
);
3102 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3105 count
= hdr
->ipdMax
;
3106 for (i
= 0; i
< count
; i
++, rp
++)
3108 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
3109 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
3110 rp
->adr
= sym
.value
;
3111 rp
->regmask
= pdr
.regmask
;
3112 rp
->regoffset
= pdr
.regoffset
;
3113 rp
->fregmask
= pdr
.fregmask
;
3114 rp
->fregoffset
= pdr
.fregoffset
;
3115 rp
->frameoffset
= pdr
.frameoffset
;
3116 rp
->framereg
= pdr
.framereg
;
3117 rp
->pcreg
= pdr
.pcreg
;
3119 sv
[i
] = ss
+ sym
.iss
;
3120 sindex
+= strlen (sv
[i
]) + 1;
3124 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
3125 size
= BFD_ALIGN (size
, 16);
3126 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
3129 mips_elf_hash_table (info
)->procedure_count
= 0;
3133 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
3135 erp
= (struct rpdr_ext
*) rtproc
;
3136 memset (erp
, 0, sizeof (struct rpdr_ext
));
3138 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
3139 strcpy (str
, no_name_func
);
3140 str
+= strlen (no_name_func
) + 1;
3141 for (i
= 0; i
< count
; i
++)
3143 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
3144 strcpy (str
, sv
[i
]);
3145 str
+= strlen (sv
[i
]) + 1;
3147 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
3149 /* Set the size and contents of .rtproc section. */
3150 s
->_raw_size
= size
;
3151 s
->contents
= rtproc
;
3153 /* Skip this section later on (I don't think this currently
3154 matters, but someday it might). */
3155 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
3184 /* A comparison routine used to sort .gptab entries. */
3187 gptab_compare (p1
, p2
)
3191 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
3192 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
3194 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3197 /* We need to use a special link routine to handle the .reginfo and
3198 the .mdebug sections. We need to merge all instances of these
3199 sections together, not write them all out sequentially. */
3202 mips_elf_final_link (abfd
, info
)
3204 struct bfd_link_info
*info
;
3208 struct bfd_link_order
*p
;
3209 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3210 asection
*rtproc_sec
;
3211 Elf32_RegInfo reginfo
;
3212 struct ecoff_debug_info debug
;
3213 const struct ecoff_debug_swap
*swap
3214 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3215 HDRR
*symhdr
= &debug
.symbolic_header
;
3216 PTR mdebug_handle
= NULL
;
3218 /* Drop the .options section, since it has special semantics which I
3219 haven't bothered to figure out. */
3220 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
3222 if (strcmp ((*secpp
)->name
, ".options") == 0)
3224 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
3225 if (p
->type
== bfd_indirect_link_order
)
3226 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
3227 (*secpp
)->link_order_head
= NULL
;
3228 *secpp
= (*secpp
)->next
;
3229 --abfd
->section_count
;
3234 /* Get a value for the GP register. */
3235 if (elf_gp (abfd
) == 0)
3237 struct bfd_link_hash_entry
*h
;
3239 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3240 if (h
!= (struct bfd_link_hash_entry
*) NULL
3241 && h
->type
== bfd_link_hash_defined
)
3242 elf_gp (abfd
) = (h
->u
.def
.value
3243 + h
->u
.def
.section
->output_section
->vma
3244 + h
->u
.def
.section
->output_offset
);
3245 else if (info
->relocateable
)
3249 /* Make up a value. */
3251 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3254 && (strcmp (o
->name
, ".sbss") == 0
3255 || strcmp (o
->name
, ".sdata") == 0
3256 || strcmp (o
->name
, ".lit4") == 0
3257 || strcmp (o
->name
, ".lit8") == 0))
3260 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
3264 /* If the relocate_section function needs to do a reloc
3265 involving the GP value, it should make a reloc_dangerous
3266 callback to warn that GP is not defined. */
3270 /* Go through the sections and collect the .reginfo and .mdebug
3274 gptab_data_sec
= NULL
;
3275 gptab_bss_sec
= NULL
;
3276 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3278 if (strcmp (o
->name
, ".reginfo") == 0)
3280 memset (®info
, 0, sizeof reginfo
);
3282 /* We have found the .reginfo section in the output file.
3283 Look through all the link_orders comprising it and merge
3284 the information together. */
3285 for (p
= o
->link_order_head
;
3286 p
!= (struct bfd_link_order
*) NULL
;
3289 asection
*input_section
;
3291 Elf32_External_RegInfo ext
;
3294 if (p
->type
!= bfd_indirect_link_order
)
3296 if (p
->type
== bfd_fill_link_order
)
3301 input_section
= p
->u
.indirect
.section
;
3302 input_bfd
= input_section
->owner
;
3304 /* The linker emulation code has probably clobbered the
3305 size to be zero bytes. */
3306 if (input_section
->_raw_size
== 0)
3307 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3309 if (! bfd_get_section_contents (input_bfd
, input_section
,
3315 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3317 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3318 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3319 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3320 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3321 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3323 /* ri_gp_value is set by the function
3324 mips_elf32_section_processing when the section is
3325 finally written out. */
3327 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3328 elf_link_input_bfd ignores this section. */
3329 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3332 /* Force the section size to the value we want. */
3333 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3335 /* Skip this section later on (I don't think this currently
3336 matters, but someday it might). */
3337 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3342 if (strcmp (o
->name
, ".mdebug") == 0)
3344 struct extsym_info einfo
;
3346 /* We have found the .mdebug section in the output file.
3347 Look through all the link_orders comprising it and merge
3348 the information together. */
3349 symhdr
->magic
= swap
->sym_magic
;
3350 /* FIXME: What should the version stamp be? */
3352 symhdr
->ilineMax
= 0;
3356 symhdr
->isymMax
= 0;
3357 symhdr
->ioptMax
= 0;
3358 symhdr
->iauxMax
= 0;
3360 symhdr
->issExtMax
= 0;
3363 symhdr
->iextMax
= 0;
3365 /* We accumulate the debugging information itself in the
3366 debug_info structure. */
3368 debug
.external_dnr
= NULL
;
3369 debug
.external_pdr
= NULL
;
3370 debug
.external_sym
= NULL
;
3371 debug
.external_opt
= NULL
;
3372 debug
.external_aux
= NULL
;
3374 debug
.ssext
= debug
.ssext_end
= NULL
;
3375 debug
.external_fdr
= NULL
;
3376 debug
.external_rfd
= NULL
;
3377 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3379 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3380 if (mdebug_handle
== (PTR
) NULL
)
3383 if (SGI_COMPAT (abfd
))
3389 static const char * const name
[] =
3390 { ".text", ".init", ".fini", ".data",
3391 ".rodata", ".sdata", ".sbss", ".bss" };
3392 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3393 scRData
, scSData
, scSBss
, scBss
};
3396 esym
.cobol_main
= 0;
3400 esym
.asym
.iss
= issNil
;
3401 esym
.asym
.st
= stLocal
;
3402 esym
.asym
.reserved
= 0;
3403 esym
.asym
.index
= indexNil
;
3404 for (i
= 0; i
< 8; i
++)
3406 esym
.asym
.sc
= sc
[i
];
3407 s
= bfd_get_section_by_name (abfd
, name
[i
]);
3410 esym
.asym
.value
= s
->vma
;
3411 last
= s
->vma
+ s
->_raw_size
;
3414 esym
.asym
.value
= last
;
3416 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
3422 for (p
= o
->link_order_head
;
3423 p
!= (struct bfd_link_order
*) NULL
;
3426 asection
*input_section
;
3428 const struct ecoff_debug_swap
*input_swap
;
3429 struct ecoff_debug_info input_debug
;
3433 if (p
->type
!= bfd_indirect_link_order
)
3435 if (p
->type
== bfd_fill_link_order
)
3440 input_section
= p
->u
.indirect
.section
;
3441 input_bfd
= input_section
->owner
;
3443 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
3444 || (get_elf_backend_data (input_bfd
)
3445 ->elf_backend_ecoff_debug_swap
) == NULL
)
3447 /* I don't know what a non MIPS ELF bfd would be
3448 doing with a .mdebug section, but I don't really
3449 want to deal with it. */
3453 input_swap
= (get_elf_backend_data (input_bfd
)
3454 ->elf_backend_ecoff_debug_swap
);
3456 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
3458 /* The ECOFF linking code expects that we have already
3459 read in the debugging information and set up an
3460 ecoff_debug_info structure, so we do that now. */
3461 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
3465 if (! (bfd_ecoff_debug_accumulate
3466 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
3467 &input_debug
, input_swap
, info
)))
3470 /* Loop through the external symbols. For each one with
3471 interesting information, try to find the symbol in
3472 the linker global hash table and save the information
3473 for the output external symbols. */
3474 eraw_src
= input_debug
.external_ext
;
3475 eraw_end
= (eraw_src
3476 + (input_debug
.symbolic_header
.iextMax
3477 * input_swap
->external_ext_size
));
3479 eraw_src
< eraw_end
;
3480 eraw_src
+= input_swap
->external_ext_size
)
3484 struct mips_elf_link_hash_entry
*h
;
3486 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
3487 if (ext
.asym
.sc
== scNil
3488 || ext
.asym
.sc
== scUndefined
3489 || ext
.asym
.sc
== scSUndefined
)
3492 name
= input_debug
.ssext
+ ext
.asym
.iss
;
3493 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
3494 name
, false, false, true);
3495 if (h
== NULL
|| h
->esym
.ifd
!= -2)
3501 < input_debug
.symbolic_header
.ifdMax
);
3502 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
3508 /* Free up the information we just read. */
3509 free (input_debug
.line
);
3510 free (input_debug
.external_dnr
);
3511 free (input_debug
.external_pdr
);
3512 free (input_debug
.external_sym
);
3513 free (input_debug
.external_opt
);
3514 free (input_debug
.external_aux
);
3515 free (input_debug
.ss
);
3516 free (input_debug
.ssext
);
3517 free (input_debug
.external_fdr
);
3518 free (input_debug
.external_rfd
);
3519 free (input_debug
.external_ext
);
3521 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3522 elf_link_input_bfd ignores this section. */
3523 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3526 if (SGI_COMPAT (abfd
) && info
->shared
)
3528 /* Create .rtproc section. */
3529 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3530 if (rtproc_sec
== NULL
)
3532 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3535 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
3536 if (rtproc_sec
== NULL
3537 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
3538 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
3542 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
3543 info
, rtproc_sec
, &debug
))
3547 /* Build the external symbol information. */
3550 einfo
.debug
= &debug
;
3552 einfo
.failed
= false;
3553 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
3554 mips_elf_output_extsym
,
3559 /* Set the size of the .mdebug section. */
3560 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
3562 /* Skip this section later on (I don't think this currently
3563 matters, but someday it might). */
3564 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3569 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3571 const char *subname
;
3574 Elf32_External_gptab
*ext_tab
;
3577 /* The .gptab.sdata and .gptab.sbss sections hold
3578 information describing how the small data area would
3579 change depending upon the -G switch. These sections
3580 not used in executables files. */
3581 if (! info
->relocateable
)
3585 for (p
= o
->link_order_head
;
3586 p
!= (struct bfd_link_order
*) NULL
;
3589 asection
*input_section
;
3591 if (p
->type
!= bfd_indirect_link_order
)
3593 if (p
->type
== bfd_fill_link_order
)
3598 input_section
= p
->u
.indirect
.section
;
3600 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3601 elf_link_input_bfd ignores this section. */
3602 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3605 /* Skip this section later on (I don't think this
3606 currently matters, but someday it might). */
3607 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3609 /* Really remove the section. */
3610 for (secpp
= &abfd
->sections
;
3612 secpp
= &(*secpp
)->next
)
3614 *secpp
= (*secpp
)->next
;
3615 --abfd
->section_count
;
3620 /* There is one gptab for initialized data, and one for
3621 uninitialized data. */
3622 if (strcmp (o
->name
, ".gptab.sdata") == 0)
3624 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
3628 (*_bfd_error_handler
)
3629 ("%s: illegal section name `%s'",
3630 bfd_get_filename (abfd
), o
->name
);
3631 bfd_set_error (bfd_error_nonrepresentable_section
);
3635 /* The linker script always combines .gptab.data and
3636 .gptab.sdata into .gptab.sdata, and likewise for
3637 .gptab.bss and .gptab.sbss. It is possible that there is
3638 no .sdata or .sbss section in the output file, in which
3639 case we must change the name of the output section. */
3640 subname
= o
->name
+ sizeof ".gptab" - 1;
3641 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
3643 if (o
== gptab_data_sec
)
3644 o
->name
= ".gptab.data";
3646 o
->name
= ".gptab.bss";
3647 subname
= o
->name
+ sizeof ".gptab" - 1;
3648 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
3651 /* Set up the first entry. */
3653 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
3656 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
3657 tab
[0].gt_header
.gt_unused
= 0;
3659 /* Combine the input sections. */
3660 for (p
= o
->link_order_head
;
3661 p
!= (struct bfd_link_order
*) NULL
;
3664 asection
*input_section
;
3668 bfd_size_type gpentry
;
3670 if (p
->type
!= bfd_indirect_link_order
)
3672 if (p
->type
== bfd_fill_link_order
)
3677 input_section
= p
->u
.indirect
.section
;
3678 input_bfd
= input_section
->owner
;
3680 /* Combine the gptab entries for this input section one
3681 by one. We know that the input gptab entries are
3682 sorted by ascending -G value. */
3683 size
= bfd_section_size (input_bfd
, input_section
);
3685 for (gpentry
= sizeof (Elf32_External_gptab
);
3687 gpentry
+= sizeof (Elf32_External_gptab
))
3689 Elf32_External_gptab ext_gptab
;
3690 Elf32_gptab int_gptab
;
3696 if (! (bfd_get_section_contents
3697 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
3698 gpentry
, sizeof (Elf32_External_gptab
))))
3704 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
3706 val
= int_gptab
.gt_entry
.gt_g_value
;
3707 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
3710 for (look
= 1; look
< c
; look
++)
3712 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
3713 tab
[look
].gt_entry
.gt_bytes
+= add
;
3715 if (tab
[look
].gt_entry
.gt_g_value
== val
)
3721 Elf32_gptab
*new_tab
;
3724 /* We need a new table entry. */
3725 new_tab
= ((Elf32_gptab
*)
3726 bfd_realloc ((PTR
) tab
,
3727 (c
+ 1) * sizeof (Elf32_gptab
)));
3728 if (new_tab
== NULL
)
3734 tab
[c
].gt_entry
.gt_g_value
= val
;
3735 tab
[c
].gt_entry
.gt_bytes
= add
;
3737 /* Merge in the size for the next smallest -G
3738 value, since that will be implied by this new
3741 for (look
= 1; look
< c
; look
++)
3743 if (tab
[look
].gt_entry
.gt_g_value
< val
3745 || (tab
[look
].gt_entry
.gt_g_value
3746 > tab
[max
].gt_entry
.gt_g_value
)))
3750 tab
[c
].gt_entry
.gt_bytes
+=
3751 tab
[max
].gt_entry
.gt_bytes
;
3756 last
= int_gptab
.gt_entry
.gt_bytes
;
3759 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3760 elf_link_input_bfd ignores this section. */
3761 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3764 /* The table must be sorted by -G value. */
3766 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
3768 /* Swap out the table. */
3769 ext_tab
= ((Elf32_External_gptab
*)
3770 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
3771 if (ext_tab
== NULL
)
3777 for (i
= 0; i
< c
; i
++)
3778 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
3781 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
3782 o
->contents
= (bfd_byte
*) ext_tab
;
3784 /* Skip this section later on (I don't think this currently
3785 matters, but someday it might). */
3786 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3790 /* Invoke the regular ELF backend linker to do all the work. */
3791 if (! bfd_elf32_bfd_final_link (abfd
, info
))
3794 /* Now write out the computed sections. */
3796 if (reginfo_sec
!= (asection
*) NULL
)
3798 Elf32_External_RegInfo ext
;
3800 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
3801 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
3802 (file_ptr
) 0, sizeof ext
))
3806 if (mdebug_sec
!= (asection
*) NULL
)
3808 BFD_ASSERT (abfd
->output_has_begun
);
3809 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
3811 mdebug_sec
->filepos
))
3814 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
3817 if (gptab_data_sec
!= (asection
*) NULL
)
3819 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
3820 gptab_data_sec
->contents
,
3822 gptab_data_sec
->_raw_size
))
3826 if (gptab_bss_sec
!= (asection
*) NULL
)
3828 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
3829 gptab_bss_sec
->contents
,
3831 gptab_bss_sec
->_raw_size
))
3835 if (SGI_COMPAT (abfd
))
3837 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3838 if (rtproc_sec
!= NULL
)
3840 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
3841 rtproc_sec
->contents
,
3843 rtproc_sec
->_raw_size
))
3851 /* Handle a MIPS ELF HI16 reloc. */
3854 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
3856 Elf_Internal_Rela
*relhi
;
3857 Elf_Internal_Rela
*rello
;
3864 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
3866 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
3869 addend
+= ((insn
& 0xffff) << 16) + addlo
;
3871 if ((addlo
& 0x8000) != 0)
3873 if ((addend
& 0x8000) != 0)
3876 bfd_put_32 (input_bfd
,
3877 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
3878 contents
+ relhi
->r_offset
);
3881 /* Handle a MIPS ELF local GOT16 reloc. */
3884 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
3889 Elf_Internal_Rela
*relhi
;
3890 Elf_Internal_Rela
*rello
;
3900 bfd_byte
*got_contents
;
3901 struct mips_got_info
*g
;
3903 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
3905 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
3908 addend
+= ((insn
& 0xffff) << 16) + addlo
;
3910 if ((addlo
& 0x8000) != 0)
3912 if ((addend
& 0x8000) != 0)
3915 /* Get a got entry representing requested hipage. */
3916 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
3917 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
3918 BFD_ASSERT (g
!= NULL
);
3920 local_gotno
= g
->local_gotno
;
3921 got_contents
= sgot
->contents
;
3922 hipage
= addend
& 0xffff0000;
3924 for (i
= MIPS_RESERVED_GOTNO
; i
< local_gotno
; i
++)
3926 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
3927 if (hipage
== (address
& 0xffff0000))
3929 if (address
== (bfd_vma
) 0)
3931 bfd_put_32 (input_bfd
, hipage
, got_contents
+ i
* 4);
3936 BFD_ASSERT (i
< local_gotno
);
3938 if (i
== local_gotno
)
3939 (*_bfd_error_handler
)
3940 ("ELF MIPS linker: more got entries are needed for hipage: %x",
3944 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
3945 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
3946 contents
+ relhi
->r_offset
);
3949 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
3952 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
3954 Elf_Internal_Rela
*rel
;
3960 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3961 bfd_put_32 (input_bfd
,
3962 (insn
& 0xffff0000) | (offset
& 0xffff),
3963 contents
+ rel
->r_offset
);
3966 /* Relocate a MIPS ELF section. */
3969 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3970 contents
, relocs
, local_syms
, local_sections
)
3972 struct bfd_link_info
*info
;
3974 asection
*input_section
;
3976 Elf_Internal_Rela
*relocs
;
3977 Elf_Internal_Sym
*local_syms
;
3978 asection
**local_sections
;
3980 Elf_Internal_Shdr
*symtab_hdr
;
3983 asection
*sgot
, *sreloc
, *scpt
;
3986 Elf_Internal_Rela
*rel
;
3987 Elf_Internal_Rela
*relend
;
3988 struct mips_got_info
*g
;
3990 dynobj
= elf_hash_table (info
)->dynobj
;
3991 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3995 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
3998 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4001 if (elf_bad_symtab (input_bfd
))
4003 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4008 locsymcount
= symtab_hdr
->sh_info
;
4009 extsymoff
= symtab_hdr
->sh_info
;
4012 gp
= _bfd_get_gp_value (output_bfd
);
4015 relend
= relocs
+ input_section
->reloc_count
;
4016 for (; rel
< relend
; rel
++)
4019 reloc_howto_type
*howto
;
4020 unsigned long r_symndx
;
4022 struct elf_link_hash_entry
*h
;
4024 Elf_Internal_Sym
*sym
;
4025 bfd_reloc_status_type r
;
4027 r_type
= ELF32_R_TYPE (rel
->r_info
);
4028 if (r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4030 bfd_set_error (bfd_error_bad_value
);
4033 howto
= elf_mips_howto_table
+ r_type
;
4036 && (r_type
== R_MIPS_CALL16
4037 || r_type
== R_MIPS_GOT16
4038 || r_type
== R_MIPS_CALL_HI16
4039 || r_type
== R_MIPS_CALL_LO16
4040 || r_type
== R_MIPS_GOT_HI16
4041 || r_type
== R_MIPS_GOT_LO16
))
4043 /* We need the .got section. */
4046 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4047 BFD_ASSERT (sgot
!= NULL
);
4048 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4049 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4050 BFD_ASSERT (g
!= NULL
);
4054 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4056 /* Mix in the change in GP address for a GP relative reloc. */
4057 if (r_type
!= R_MIPS_GPREL16
4058 && r_type
!= R_MIPS_LITERAL
4059 && r_type
!= R_MIPS_GPREL32
)
4065 if (! ((*info
->callbacks
->reloc_dangerous
)
4067 "GP relative relocation when GP not defined",
4068 input_bfd
, input_section
,
4071 /* Only give the error once per link. */
4073 _bfd_set_gp_value (output_bfd
, gp
);
4076 if (r_symndx
< extsymoff
4077 || (elf_bad_symtab (input_bfd
)
4078 && local_sections
[r_symndx
] != NULL
))
4080 /* This is a relocation against a section. The current
4081 addend in the instruction is the difference between
4082 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4083 must change this to be the difference between the
4084 final definition (which will end up in RELOCATION)
4085 and the GP value of OUTPUT_BFD (which is in GP). */
4086 addend
= elf_gp (input_bfd
) - gp
;
4088 else if (! info
->relocateable
)
4090 /* We are doing a final link. The current addend in the
4091 instruction is simply the desired offset into the
4092 symbol (normally zero). We want the instruction to
4093 hold the difference between the final definition of
4094 the symbol (which will end up in RELOCATION) and the
4095 GP value of OUTPUT_BFD (which is in GP). */
4100 /* We are generating relocateable output, and we aren't
4101 going to define this symbol, so we just leave the
4102 instruction alone. */
4110 if (info
->relocateable
)
4112 /* This is a relocateable link. We don't have to change
4113 anything, unless the reloc is against a section symbol,
4114 in which case we have to adjust according to where the
4115 section symbol winds up in the output section. */
4116 if (r_symndx
>= locsymcount
4117 || (elf_bad_symtab (input_bfd
)
4118 && local_sections
[r_symndx
] == NULL
))
4122 sym
= local_syms
+ r_symndx
;
4123 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4127 sec
= local_sections
[r_symndx
];
4129 /* It would be logical to add sym->st_value here,
4130 but Irix 5 sometimes generates a garbage symbol
4132 addend
+= sec
->output_offset
;
4134 /* If this is HI16 or GOT16 with an associated LO16,
4135 adjust the addend accordingly. Otherwise, just
4137 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
4138 r
= _bfd_relocate_contents (howto
, input_bfd
,
4140 contents
+ rel
->r_offset
);
4143 Elf_Internal_Rela
*lorel
;
4145 /* As a GNU extension, permit an arbitrary
4146 number of R_MIPS_HI16 relocs before the
4147 R_MIPS_LO16 reloc. This permits gcc to emit
4148 the HI and LO relocs itself. */
4149 if (r_type
== R_MIPS_GOT16
)
4153 for (lorel
= rel
+ 1;
4155 && (ELF32_R_TYPE (lorel
->r_info
)
4161 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4163 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4168 r
= _bfd_relocate_contents (howto
, input_bfd
,
4170 contents
+ rel
->r_offset
);
4180 /* This is a final link. */
4182 if (r_symndx
< extsymoff
4183 || (elf_bad_symtab (input_bfd
)
4184 && local_sections
[r_symndx
] != NULL
))
4187 sym
= local_syms
+ r_symndx
;
4188 sec
= local_sections
[r_symndx
];
4189 relocation
= (sec
->output_section
->vma
4190 + sec
->output_offset
);
4192 /* It would be logical to always add sym->st_value here,
4193 but Irix 5 sometimes generates a garbage symbol
4195 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4196 relocation
+= sym
->st_value
;
4203 indx
= r_symndx
- extsymoff
;
4204 h
= elf_sym_hashes (input_bfd
)[indx
];
4205 while (h
->root
.type
== bfd_link_hash_indirect
4206 || h
->root
.type
== bfd_link_hash_warning
)
4207 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4208 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
4212 if (! ((*info
->callbacks
->reloc_dangerous
)
4214 "_gp_disp used when GP not defined",
4215 input_bfd
, input_section
,
4218 /* Only give the error once per link. */
4220 _bfd_set_gp_value (output_bfd
, gp
);
4225 sec
= input_section
;
4226 if (sec
->output_section
!= NULL
)
4229 + sec
->output_section
->vma
4230 + sec
->output_offset
));
4232 relocation
= gp
- rel
->r_offset
;
4233 if (r_type
== R_MIPS_LO16
)
4237 else if (h
->root
.type
== bfd_link_hash_defined
4238 || h
->root
.type
== bfd_link_hash_defweak
)
4240 sec
= h
->root
.u
.def
.section
;
4241 if (sec
->output_section
== NULL
)
4244 relocation
= (h
->root
.u
.def
.value
4245 + sec
->output_section
->vma
4246 + sec
->output_offset
);
4248 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4250 else if (info
->shared
&& ! info
->symbolic
)
4252 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4254 /* If this is a dynamic link, we should have created
4255 a _DYNAMIC_LINK symbol in
4256 mips_elf_create_dynamic_sections. Otherwise, we
4257 should define the symbol with a value of 0.
4258 FIXME: It should probably get into the symbol
4259 table somehow as well. */
4260 BFD_ASSERT (! info
->shared
);
4261 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4262 ".dynamic") == NULL
);
4267 if (! ((*info
->callbacks
->undefined_symbol
)
4268 (info
, h
->root
.root
.string
, input_bfd
,
4269 input_section
, rel
->r_offset
)))
4275 if (r_type
== R_MIPS_HI16
)
4277 Elf_Internal_Rela
*lorel
;
4279 /* As a GNU extension, permit an arbitrary number of
4280 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
4281 This permits gcc to emit the HI and LO relocs itself. */
4282 for (lorel
= rel
+ 1;
4284 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
4288 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4290 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4291 contents
, relocation
+ addend
);
4295 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4296 contents
, rel
->r_offset
,
4297 relocation
, addend
);
4299 else if (r_type
== R_MIPS_GOT16
&& local
)
4301 /* GOT16 must also have an associated LO16 in the local
4302 case. In this case, the addend is extracted and the
4303 section in which the referenced object is determined.
4304 Then the final address of the object is computed and
4305 the GOT entry for the hipage (an aligned 64kb chunk)
4306 is added to .got section if needed. The offset field
4307 of the GOT16-relocated instruction is replaced by the
4308 index of this GOT entry for the hipage. */
4309 if ((rel
+ 1) < relend
4310 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
4312 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
,
4315 relocation
+ addend
);
4319 r
= bfd_reloc_outofrange
;
4321 else if (r_type
== R_MIPS_CALL16
4322 || r_type
== R_MIPS_GOT16
4323 || r_type
== R_MIPS_CALL_LO16
4324 || r_type
== R_MIPS_GOT_LO16
)
4328 /* This symbol must be registered as a global symbol
4329 having the corresponding got entry. */
4330 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
4332 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4333 BFD_ASSERT (g
->local_gotno
<= offset
4334 && offset
< sgot
->_raw_size
);
4335 bfd_put_32 (output_bfd
, relocation
+ addend
,
4336 sgot
->contents
+ offset
);
4337 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4339 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
4343 else if (r_type
== R_MIPS_CALL_HI16
4344 || r_type
== R_MIPS_GOT_HI16
)
4348 /* This must be a global symbol with a got entry. The
4349 next reloc must be the corresponding LO16 reloc. */
4350 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
4351 BFD_ASSERT ((rel
+ 1) < relend
);
4352 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
4353 == (r_type
== R_MIPS_CALL_HI16
4355 : R_MIPS_GOT_LO16
));
4357 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4358 BFD_ASSERT (g
->local_gotno
<= offset
4359 && offset
< sgot
->_raw_size
);
4360 bfd_put_32 (output_bfd
, relocation
+ addend
,
4361 sgot
->contents
+ offset
);
4362 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4364 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
4368 else if (r_type
== R_MIPS_REL32
4369 || r_type
== R_MIPS_32
)
4371 Elf_Internal_Rel outrel
;
4372 Elf32_crinfo cptrel
;
4377 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
4379 && (input_section
->flags
& SEC_ALLOC
) != 0)
4381 /* When generating a shared object, these
4382 relocations are copied into the output file to be
4383 resolved at run time. */
4386 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
4387 BFD_ASSERT (sreloc
!= NULL
);
4390 outrel
.r_offset
= (rel
->r_offset
4391 + input_section
->output_section
->vma
4392 + input_section
->output_offset
);
4394 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4397 && (! info
->symbolic
4398 || (h
->elf_link_hash_flags
4399 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4401 BFD_ASSERT (h
->dynindx
!= -1);
4402 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
4403 sec
= input_section
;
4410 sec
= local_sections
[r_symndx
];
4413 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
4415 == bfd_link_hash_defweak
));
4416 sec
= h
->root
.u
.def
.section
;
4418 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
4420 else if (sec
== NULL
|| sec
->owner
== NULL
)
4422 bfd_set_error (bfd_error_bad_value
);
4429 osec
= sec
->output_section
;
4430 indx
= elf_section_data (osec
)->dynindx
;
4435 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
4436 addend
+= relocation
;
4439 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
4440 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
4441 (((Elf32_External_Rel
*)
4443 + sreloc
->reloc_count
));
4444 ++sreloc
->reloc_count
;
4446 if (SGI_COMPAT (output_bfd
))
4451 /* Make an entry of compact relocation info. */
4452 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4453 cptrel
.vaddr
= (rel
->r_offset
4454 + input_section
->output_section
->vma
4455 + input_section
->output_offset
);
4456 if (r_type
== R_MIPS_REL32
)
4457 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
4459 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
4460 mips_elf_set_cr_dist2to (cptrel
, 0);
4461 cptrel
.konst
= addend
;
4463 cr
= (scpt
->contents
4464 + sizeof (Elf32_External_compact_rel
));
4465 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4466 ((Elf32_External_crinfo
*) cr
4467 + scpt
->reloc_count
));
4468 ++scpt
->reloc_count
;
4471 /* This reloc will be computed at runtime, so
4472 there's no need to do anything now. */
4476 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4477 contents
, rel
->r_offset
,
4478 relocation
, addend
);
4481 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4482 contents
, rel
->r_offset
,
4483 relocation
, addend
);
4485 if (SGI_COMPAT (abfd
)
4487 && (input_section
->flags
& SEC_ALLOC
) != 0)
4489 Elf32_crinfo cptrel
;
4492 /* Make an entry of compact relocation info. */
4493 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4494 cptrel
.vaddr
= (rel
->r_offset
4495 + input_section
->output_section
->vma
4496 + input_section
->output_offset
);
4501 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
4502 /* XXX How should we set dist2to in this case. */
4503 mips_elf_set_cr_dist2to (cptrel
, 8);
4504 cptrel
.konst
= addend
+ relocation
;
4505 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4506 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4507 ((Elf32_External_crinfo
*) cr
4508 + scpt
->reloc_count
));
4509 ++scpt
->reloc_count
;
4512 case R_MIPS_GPREL16
:
4513 case R_MIPS_LITERAL
:
4514 case R_MIPS_GPREL32
:
4515 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
4516 cptrel
.konst
= gp
- cptrel
.vaddr
;
4517 mips_elf_set_cr_dist2to (cptrel
, 4);
4518 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4519 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4520 ((Elf32_External_crinfo
*) cr
4521 + scpt
->reloc_count
));
4522 ++scpt
->reloc_count
;
4531 if (r
!= bfd_reloc_ok
)
4536 case bfd_reloc_outofrange
:
4538 case bfd_reloc_overflow
:
4543 name
= h
->root
.root
.string
;
4546 name
= bfd_elf_string_from_elf_section (input_bfd
,
4547 symtab_hdr
->sh_link
,
4552 name
= bfd_section_name (input_bfd
, sec
);
4554 if (! ((*info
->callbacks
->reloc_overflow
)
4555 (info
, name
, howto
->name
, (bfd_vma
) 0,
4556 input_bfd
, input_section
, rel
->r_offset
)))
4567 /* Functions for the dynamic linker. */
4569 /* The name of the dynamic interpreter. This is put in the .interp
4572 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
4574 /* Create dynamic sections when linking against a dynamic object. */
4577 mips_elf_create_dynamic_sections (abfd
, info
)
4579 struct bfd_link_info
*info
;
4581 struct elf_link_hash_entry
*h
;
4583 register asection
*s
;
4584 const char * const *namep
;
4586 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4589 /* Mips ABI requests the .dynamic section to be read only. */
4590 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4593 if (! bfd_set_section_flags (abfd
, s
, flags
))
4597 /* We need to create .got section. */
4598 if (! mips_elf_create_got_section (abfd
, info
))
4601 /* Create .stub section. */
4602 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
4604 s
= bfd_make_section (abfd
, ".stub");
4606 || ! bfd_set_section_flags (abfd
, s
, flags
)
4607 || ! bfd_set_section_alignment (abfd
, s
, 2))
4611 if (SGI_COMPAT (abfd
))
4613 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
4616 if (! (_bfd_generic_link_add_one_symbol
4617 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
4618 (bfd_vma
) 0, (const char *) NULL
, false,
4619 get_elf_backend_data (abfd
)->collect
,
4620 (struct bfd_link_hash_entry
**) &h
)))
4622 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4623 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4624 h
->type
= STT_SECTION
;
4626 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4630 /* We need to create a .compact_rel section. */
4631 if (! mips_elf_create_compact_rel_section (abfd
, info
))
4634 /* Change aligments of some sections. */
4635 s
= bfd_get_section_by_name (abfd
, ".hash");
4637 bfd_set_section_alignment (abfd
, s
, 4);
4638 s
= bfd_get_section_by_name (abfd
, ".dynsym");
4640 bfd_set_section_alignment (abfd
, s
, 4);
4641 s
= bfd_get_section_by_name (abfd
, ".dynstr");
4643 bfd_set_section_alignment (abfd
, s
, 4);
4644 s
= bfd_get_section_by_name (abfd
, ".reginfo");
4646 bfd_set_section_alignment (abfd
, s
, 4);
4647 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4649 bfd_set_section_alignment (abfd
, s
, 4);
4655 if (! (_bfd_generic_link_add_one_symbol
4656 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
4657 (bfd_vma
) 0, (const char *) NULL
, false,
4658 get_elf_backend_data (abfd
)->collect
,
4659 (struct bfd_link_hash_entry
**) &h
)))
4661 h
->elf_link_hash_flags
^=~ ELF_LINK_NON_ELF
;
4662 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4663 h
->type
= STT_SECTION
;
4665 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4672 /* Create the .compact_rel section. */
4675 mips_elf_create_compact_rel_section (abfd
, info
)
4677 struct bfd_link_info
*info
;
4680 register asection
*s
;
4682 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4684 flags
= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_READONLY
;
4686 s
= bfd_make_section (abfd
, ".compact_rel");
4688 || ! bfd_set_section_flags (abfd
, s
, flags
)
4689 || ! bfd_set_section_alignment (abfd
, s
, 2))
4692 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
4698 /* Create the .got section to hold the global offset table. */
4701 mips_elf_create_got_section (abfd
, info
)
4703 struct bfd_link_info
*info
;
4706 register asection
*s
;
4707 struct elf_link_hash_entry
*h
;
4708 struct mips_got_info
*g
;
4710 /* This function may be called more than once. */
4711 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
4714 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
4716 s
= bfd_make_section (abfd
, ".got");
4718 || ! bfd_set_section_flags (abfd
, s
, flags
)
4719 || ! bfd_set_section_alignment (abfd
, s
, 4))
4722 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4723 linker script because we don't want to define the symbol if we
4724 are not creating a global offset table. */
4726 if (! (_bfd_generic_link_add_one_symbol
4727 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4728 (bfd_vma
) 0, (const char *) NULL
, false,
4729 get_elf_backend_data (abfd
)->collect
,
4730 (struct bfd_link_hash_entry
**) &h
)))
4732 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4733 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4734 h
->type
= STT_OBJECT
;
4737 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4740 /* The first several global offset table entries are reserved. */
4741 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
4743 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
4744 sizeof (struct mips_got_info
));
4747 g
->global_gotsym
= 0;
4748 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
4749 if (elf_section_data (s
) == NULL
)
4752 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
4753 if (elf_section_data (s
) == NULL
)
4756 elf_section_data (s
)->tdata
= (PTR
) g
;
4761 /* Look through the relocs for a section during the first phase, and
4762 allocate space in the global offset table. */
4765 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
4767 struct bfd_link_info
*info
;
4769 const Elf_Internal_Rela
*relocs
;
4772 Elf_Internal_Shdr
*symtab_hdr
;
4773 struct elf_link_hash_entry
**sym_hashes
;
4774 struct mips_got_info
*g
;
4776 const Elf_Internal_Rela
*rel
;
4777 const Elf_Internal_Rela
*rel_end
;
4781 if (info
->relocateable
)
4784 dynobj
= elf_hash_table (info
)->dynobj
;
4785 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4786 sym_hashes
= elf_sym_hashes (abfd
);
4787 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
4792 rel_end
= relocs
+ sec
->reloc_count
;
4793 for (rel
= relocs
; rel
< rel_end
; rel
++)
4795 unsigned long r_symndx
;
4796 struct elf_link_hash_entry
*h
;
4798 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4800 if (r_symndx
< extsymoff
)
4803 h
= sym_hashes
[r_symndx
- extsymoff
];
4805 /* Some relocs require a global offset table. */
4808 switch (ELF32_R_TYPE (rel
->r_info
))
4812 case R_MIPS_CALL_HI16
:
4813 case R_MIPS_CALL_LO16
:
4814 case R_MIPS_GOT_HI16
:
4815 case R_MIPS_GOT_LO16
:
4816 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4817 if (! mips_elf_create_got_section (dynobj
, info
))
4826 switch (ELF32_R_TYPE (rel
->r_info
))
4829 case R_MIPS_CALL_HI16
:
4830 case R_MIPS_CALL_LO16
:
4831 /* This symbol requires a global offset table entry. */
4834 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4835 BFD_ASSERT (sgot
!= NULL
);
4836 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4837 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4838 BFD_ASSERT (g
!= NULL
);
4841 BFD_ASSERT (h
!= NULL
);
4843 /* Make sure this symbol is output as a dynamic symbol. */
4844 if (h
->dynindx
== -1)
4846 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4850 if (h
->got_offset
!= (bfd_vma
) -1)
4852 /* We have already allocated space in the .got. */
4856 /* Note the index of the first global got symbol in .dynsym. */
4857 if (g
->global_gotsym
== 0
4858 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
4859 g
->global_gotsym
= h
->dynindx
;
4861 /* Make this symbol to have the corresponding got entry. */
4864 /* We need a stub, not a plt entry for the undefined
4865 function. But we record it as if it needs plt. See
4866 elf_adjust_dynamic_symbol in elflink.h. */
4867 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4873 case R_MIPS_GOT_HI16
:
4874 case R_MIPS_GOT_LO16
:
4875 /* This symbol requires a global offset table entry. */
4878 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4879 BFD_ASSERT (sgot
!= NULL
);
4880 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4881 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4882 BFD_ASSERT (g
!= NULL
);
4887 /* Make sure this symbol is output as a dynamic symbol. */
4888 if (h
->dynindx
== -1)
4890 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4894 if (h
->got_offset
!= (bfd_vma
) -1)
4896 /* We have already allocated space in the .got. */
4899 /* Note the index of the first global got symbol in
4901 if (g
->global_gotsym
== 0
4902 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
4903 g
->global_gotsym
= h
->dynindx
;
4905 /* Make this symbol to be the global got symbol. */
4913 if ((info
->shared
|| h
!= NULL
)
4914 && (sec
->flags
& SEC_ALLOC
) != 0)
4916 /* When creating a shared object, we must copy these
4917 reloc types into the output file as R_MIPS_REL32
4918 relocs. We create the .rel.dyn reloc section in
4919 dynobj and make room for this reloc. */
4922 const char *name
= ".rel.dyn";
4924 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4927 sreloc
= bfd_make_section (dynobj
, name
);
4929 || ! bfd_set_section_flags (dynobj
, sreloc
,
4935 || ! bfd_set_section_alignment (dynobj
, sreloc
, 4))
4938 /* Add a null element. */
4939 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
4940 ++sreloc
->reloc_count
;
4945 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
4948 struct mips_elf_link_hash_entry
*hmips
;
4950 /* We only need to copy this reloc if the symbol is
4951 defined in a dynamic object. */
4952 hmips
= (struct mips_elf_link_hash_entry
*) h
;
4953 ++hmips
->mips_32_relocs
;
4957 if (SGI_COMPAT (abfd
))
4958 mips_elf_hash_table (info
)->compact_rel_size
+=
4959 sizeof (Elf32_External_crinfo
);
4964 case R_MIPS_GPREL16
:
4965 case R_MIPS_LITERAL
:
4966 case R_MIPS_GPREL32
:
4967 if (SGI_COMPAT (abfd
))
4968 mips_elf_hash_table (info
)->compact_rel_size
+=
4969 sizeof (Elf32_External_crinfo
);
4980 /* Adjust a symbol defined by a dynamic object and referenced by a
4981 regular object. The current definition is in some section of the
4982 dynamic object, but we're not including those sections. We have to
4983 change the definition to something the rest of the link can
4987 mips_elf_adjust_dynamic_symbol (info
, h
)
4988 struct bfd_link_info
*info
;
4989 struct elf_link_hash_entry
*h
;
4992 struct mips_elf_link_hash_entry
*hmips
;
4995 dynobj
= elf_hash_table (info
)->dynobj
;
4997 /* Make sure we know what is going on here. */
4998 BFD_ASSERT (dynobj
!= NULL
4999 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
5000 || h
->weakdef
!= NULL
5001 || ((h
->elf_link_hash_flags
5002 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5003 && (h
->elf_link_hash_flags
5004 & ELF_LINK_HASH_REF_REGULAR
) != 0
5005 && (h
->elf_link_hash_flags
5006 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
5008 /* If this symbol is defined in a dynamic object, we need to copy
5009 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
5011 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5012 if (! info
->relocateable
5013 && hmips
->mips_32_relocs
!= 0
5014 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5016 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5017 BFD_ASSERT (s
!= NULL
);
5019 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
5022 /* For a function, create a stub, if needed. */
5023 if (h
->type
== STT_FUNC
5024 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
5026 if (! elf_hash_table (info
)->dynamic_sections_created
)
5029 /* If this symbol is not defined in a regular file, then set
5030 the symbol to the stub location. This is required to make
5031 function pointers compare as equal between the normal
5032 executable and the shared library. */
5033 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5035 /* We need .stub section. */
5036 s
= bfd_get_section_by_name (dynobj
, ".stub");
5037 BFD_ASSERT (s
!= NULL
);
5039 h
->root
.u
.def
.section
= s
;
5040 h
->root
.u
.def
.value
= s
->_raw_size
;
5042 /* XXX Write this stub address somewhere. */
5043 h
->plt_offset
= s
->_raw_size
;
5045 /* Make room for this stub code. */
5046 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5048 /* The last half word of the stub will be filled with the index
5049 of this symbol in .dynsym section. */
5054 /* If this is a weak symbol, and there is a real definition, the
5055 processor independent code will have arranged for us to see the
5056 real definition first, and we can just use the same value. */
5057 if (h
->weakdef
!= NULL
)
5059 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
5060 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
5061 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
5062 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
5066 /* This is a reference to a symbol defined by a dynamic object which
5067 is not a function. */
5072 /* Set the sizes of the dynamic sections. */
5075 mips_elf_size_dynamic_sections (output_bfd
, info
)
5077 struct bfd_link_info
*info
;
5083 struct mips_got_info
*g
;
5085 dynobj
= elf_hash_table (info
)->dynobj
;
5086 BFD_ASSERT (dynobj
!= NULL
);
5088 if (elf_hash_table (info
)->dynamic_sections_created
)
5090 /* Set the contents of the .interp section to the interpreter. */
5093 s
= bfd_get_section_by_name (dynobj
, ".interp");
5094 BFD_ASSERT (s
!= NULL
);
5095 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5096 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5100 /* Recompute the size of .got for local entires (reserved and
5101 hipages) if needed. To estimate it, get the upper bound of total
5102 size of loadable sections. */
5103 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5107 bfd_size_type loadable_size
= 0;
5108 bfd_size_type local_gotno
;
5111 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5112 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5113 BFD_ASSERT (g
!= NULL
);
5115 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
5116 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
5118 if ((s
->flags
& SEC_ALLOC
) == 0)
5120 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
5123 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
5125 /* Assume there are two loadable segments consisting of
5126 contiguous sections. Is 5 enough? */
5127 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
5128 g
->local_gotno
= local_gotno
;
5129 sgot
->_raw_size
+= local_gotno
* 4;
5132 /* The check_relocs and adjust_dynamic_symbol entry points have
5133 determined the sizes of the various dynamic sections. Allocate
5136 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5141 /* It's OK to base decisions on the section name, because none
5142 of the dynobj section names depend upon the input files. */
5143 name
= bfd_get_section_name (dynobj
, s
);
5145 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
5150 if (strncmp (name
, ".rel", 4) == 0)
5152 if (s
->_raw_size
== 0)
5158 /* If this relocation section applies to a read only
5159 section, then we probably need a DT_TEXTREL entry.
5160 If the relocation section is .rel.dyn, we always
5161 assert a DT_TEXTREL entry rather than testing whether
5162 there exists a relocation to a read only section or
5164 target
= bfd_get_section_by_name (output_bfd
, name
+ 4);
5165 if ((target
!= NULL
&& (target
->flags
& SEC_READONLY
) != 0)
5166 || strcmp (name
, ".rel.dyn") == 0)
5169 /* We use the reloc_count field as a counter if we need
5170 to copy relocs into the output file. */
5171 if (strcmp (name
, ".rel.dyn") != 0)
5175 else if (strncmp (name
, ".got", 4) == 0)
5179 BFD_ASSERT (elf_section_data (s
) != NULL
);
5180 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5181 BFD_ASSERT (g
!= NULL
);
5183 /* Fix the size of .got section for the correspondence of
5184 global symbols and got entries. This adds some useless
5185 got entries. Is this required by ABI really? */
5186 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
5187 s
->_raw_size
+= i
* 4;
5189 else if (strncmp (name
, ".stub", 5) == 0)
5191 /* Irix rld assumes that the function stub isn't at the end
5192 of .text section. So put a dummy. XXX */
5193 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5195 else if (SGI_COMPAT (output_bfd
)
5196 && strncmp (name
, ".compact_rel", 12) == 0)
5197 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
5198 else if (strncmp (name
, ".init", 5) != 0)
5200 /* It's not one of our sections, so don't allocate space. */
5208 for (spp
= &s
->output_section
->owner
->sections
;
5209 *spp
!= s
->output_section
;
5210 spp
= &(*spp
)->next
)
5212 *spp
= s
->output_section
->next
;
5213 --s
->output_section
->owner
->section_count
;
5218 /* Allocate memory for the section contents. */
5219 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
5220 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
5222 bfd_set_error (bfd_error_no_memory
);
5225 memset (s
->contents
, 0, s
->_raw_size
);
5228 if (elf_hash_table (info
)->dynamic_sections_created
)
5230 /* Add some entries to the .dynamic section. We fill in the
5231 values later, in elf_mips_finish_dynamic_sections, but we
5232 must add the entries now so that we get the correct size for
5233 the .dynamic section. The DT_DEBUG entry is filled in by the
5234 dynamic linker and used by the debugger. */
5237 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
5243 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
5247 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5250 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
5252 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
5255 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
5258 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
5262 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
5265 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
5268 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
5270 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
5273 s
= bfd_get_section_by_name (dynobj
, ".liblist");
5274 BFD_ASSERT (s
!= NULL
);
5276 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
5280 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
5283 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
5287 /* Time stamps in executable files are a bad idea. */
5288 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
5293 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
5298 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
5302 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
5305 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
5308 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
5311 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
5314 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
5317 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
5320 #if 0 /* (SGI_COMPAT) */
5321 if (! bfd_get_section_by_name (dynobj
, ".init"))
5322 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
5325 if (! bfd_get_section_by_name (dynobj
, ".fini"))
5326 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
5331 /* If we use dynamic linking, we generate a section symbol for each
5332 output section. These are local symbols, which means that they
5333 must come first in the dynamic symbol table.
5334 That means we must increment the dynamic symbol index of every
5335 other dynamic symbol. */
5337 const char * const *namep
;
5339 bfd_size_type strindex
;
5340 struct bfd_strtab_hash
*dynstr
;
5341 struct mips_got_info
*g
;
5343 if (elf_hash_table (info
)->dynamic_sections_created
)
5345 if (SGI_COMPAT (output_bfd
))
5347 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
5348 elf_link_hash_traverse (elf_hash_table (info
),
5349 mips_elf_adjust_dynindx
,
5351 elf_hash_table (info
)->dynsymcount
+= c
;
5353 dynstr
= elf_hash_table (info
)->dynstr
;
5354 BFD_ASSERT (dynstr
!= NULL
);
5356 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
5360 s
= bfd_get_section_by_name (output_bfd
, *namep
);
5362 elf_section_data (s
)->dynindx
= i
;
5364 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
5365 if (strindex
== (bfd_size_type
) -1)
5368 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
5373 c
= bfd_count_sections (output_bfd
);
5374 elf_link_hash_traverse (elf_hash_table (info
),
5375 mips_elf_adjust_dynindx
,
5377 elf_hash_table (info
)->dynsymcount
+= c
;
5379 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
5381 elf_section_data (s
)->dynindx
= i
;
5382 /* These symbols will have no names, so we don't need to
5383 fiddle with dynstr_index. */
5388 s
= bfd_get_section_by_name (dynobj
, ".got");
5389 BFD_ASSERT (s
!= NULL
);
5390 BFD_ASSERT (elf_section_data (s
) != NULL
);
5391 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5392 BFD_ASSERT (g
!= NULL
);
5394 /* If there are no global got symbols, fake the last symbol so for
5396 if (g
->global_gotsym
)
5397 g
->global_gotsym
+= c
;
5399 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
5405 /* Increment the index of a dynamic symbol by a given amount. Called
5406 via elf_link_hash_traverse. */
5409 mips_elf_adjust_dynindx (h
, cparg
)
5410 struct elf_link_hash_entry
*h
;
5413 unsigned int *cp
= (unsigned int *) cparg
;
5415 if (h
->dynindx
!= -1)
5420 /* Finish up dynamic symbol handling. We set the contents of various
5421 dynamic sections here. */
5424 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5426 struct bfd_link_info
*info
;
5427 struct elf_link_hash_entry
*h
;
5428 Elf_Internal_Sym
*sym
;
5433 struct mips_got_info
*g
;
5436 dynobj
= elf_hash_table (info
)->dynobj
;
5437 gval
= sym
->st_value
;
5439 if (h
->plt_offset
!= (bfd_vma
) -1)
5443 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5445 /* This symbol has a stub. Set it up. */
5447 BFD_ASSERT (h
->dynindx
!= -1);
5449 s
= bfd_get_section_by_name (dynobj
, ".stub");
5450 BFD_ASSERT (s
!= NULL
);
5452 /* Fill the stub. */
5454 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
5456 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
5459 /* FIXME: Can h->dynindex be more than 64K? */
5460 if (h
->dynindx
& 0xffff0000)
5463 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
5465 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
5467 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
5468 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5470 /* Mark the symbol as undefined. plt_offset != -1 occurs
5471 only for the referenced symbol. */
5472 sym
->st_shndx
= SHN_UNDEF
;
5474 /* The run-time linker uses the st_value field of the symbol
5475 to reset the global offset table entry for this external
5476 to its stub address when unlinking a shared object. */
5477 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
5478 sym
->st_value
= gval
;
5481 BFD_ASSERT (h
->dynindx
!= -1);
5483 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5484 BFD_ASSERT (sgot
!= NULL
);
5485 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5486 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5487 BFD_ASSERT (g
!= NULL
);
5489 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
5491 bfd_size_type offset
;
5493 /* This symbol has an entry in the global offset table. Set its
5494 value to the corresponding got entry, if needed. */
5495 if (h
->got_offset
== (bfd_vma
) -1)
5497 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5498 BFD_ASSERT (g
->local_gotno
* 4 <= offset
5499 && offset
< sgot
->_raw_size
);
5500 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
5504 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5505 name
= h
->root
.root
.string
;
5506 if (strcmp (name
, "_DYNAMIC") == 0
5507 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5508 sym
->st_shndx
= SHN_ABS
;
5509 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
5511 sym
->st_shndx
= SHN_ABS
;
5512 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5515 else if (SGI_COMPAT (output_bfd
))
5517 if (strcmp (name
, "_gp_disp") == 0)
5519 sym
->st_shndx
= SHN_ABS
;
5520 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5521 sym
->st_value
= elf_gp (output_bfd
);
5523 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
5524 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
5526 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5527 sym
->st_other
= STO_PROTECTED
;
5529 sym
->st_shndx
= SHN_MIPS_DATA
;
5531 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
5533 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5534 sym
->st_other
= STO_PROTECTED
;
5535 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
5536 sym
->st_shndx
= SHN_ABS
;
5538 else if (sym
->st_shndx
!= SHN_UNDEF
)
5540 if (h
->type
== STT_FUNC
)
5541 sym
->st_shndx
= SHN_MIPS_TEXT
;
5542 else if (h
->type
== STT_OBJECT
)
5543 sym
->st_shndx
= SHN_MIPS_DATA
;
5550 /* Finish up the dynamic sections. */
5553 mips_elf_finish_dynamic_sections (output_bfd
, info
)
5555 struct bfd_link_info
*info
;
5560 struct mips_got_info
*g
;
5562 dynobj
= elf_hash_table (info
)->dynobj
;
5564 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5566 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5567 BFD_ASSERT (sgot
!= NULL
);
5569 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5570 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5571 BFD_ASSERT (g
!= NULL
);
5573 if (elf_hash_table (info
)->dynamic_sections_created
)
5575 Elf32_External_Dyn
*dyncon
, *dynconend
;
5577 BFD_ASSERT (sdyn
!= NULL
);
5579 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5580 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5581 for (; dyncon
< dynconend
; dyncon
++)
5583 Elf_Internal_Dyn dyn
;
5588 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5596 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5597 BFD_ASSERT (s
!= NULL
);
5598 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
5599 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5603 /* Rewrite DT_STRSZ. */
5605 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
5606 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5612 case DT_MIPS_CONFLICT
:
5615 case DT_MIPS_LIBLIST
:
5618 s
= bfd_get_section_by_name (output_bfd
, name
);
5619 BFD_ASSERT (s
!= NULL
);
5620 dyn
.d_un
.d_ptr
= s
->vma
;
5621 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5624 case DT_MIPS_RLD_VERSION
:
5625 dyn
.d_un
.d_val
= 1; /* XXX */
5626 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5630 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5631 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5634 case DT_MIPS_CONFLICTNO
:
5636 elemsize
= sizeof (Elf32_Conflict
);
5639 case DT_MIPS_LIBLISTNO
:
5641 elemsize
= sizeof (Elf32_Lib
);
5643 s
= bfd_get_section_by_name (output_bfd
, name
);
5646 if (s
->_cooked_size
!= 0)
5647 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5649 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5654 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5657 case DT_MIPS_TIME_STAMP
:
5658 time ((time_t *) &dyn
.d_un
.d_val
);
5659 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5662 case DT_MIPS_ICHECKSUM
:
5666 case DT_MIPS_IVERSION
:
5670 case DT_MIPS_BASE_ADDRESS
:
5671 s
= output_bfd
->sections
;
5672 BFD_ASSERT (s
!= NULL
);
5673 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
5674 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5677 case DT_MIPS_LOCAL_GOTNO
:
5678 dyn
.d_un
.d_val
= g
->local_gotno
;
5679 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5682 case DT_MIPS_SYMTABNO
:
5684 elemsize
= sizeof (Elf32_External_Sym
);
5685 s
= bfd_get_section_by_name (output_bfd
, name
);
5686 BFD_ASSERT (s
!= NULL
);
5688 if (s
->_cooked_size
!= 0)
5689 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5691 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5692 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5695 case DT_MIPS_UNREFEXTNO
:
5697 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
5698 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5701 case DT_MIPS_GOTSYM
:
5702 dyn
.d_un
.d_val
= g
->global_gotsym
;
5703 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5706 case DT_MIPS_HIPAGENO
:
5707 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
5708 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5715 /* The first entry of the global offset table will be filled at
5716 runtime. The second entry will be used by some runtime loaders.
5717 This isn't the case of Irix rld. */
5718 if (sgot
->_raw_size
> 0)
5720 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5721 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
5724 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5731 Elf_Internal_Sym sym
;
5734 const char * const * namep
= mips_elf_dynsym_sec_names
;
5735 Elf32_compact_rel cpt
;
5737 /* Set up the section symbols for the output sections. SGI sets
5738 the STT_NOTYPE attribute for these symbols. Should we do so? */
5740 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
5741 if (sdynsym
!= NULL
)
5743 if (SGI_COMPAT (output_bfd
))
5747 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
5751 while ((name
= *namep
++) != NULL
)
5753 s
= bfd_get_section_by_name (output_bfd
, name
);
5756 sym
.st_value
= s
->vma
;
5757 dindx
= elf_section_data (s
)->dynindx
;
5758 last
= s
->vma
+ s
->_raw_size
;
5762 sym
.st_value
= last
;
5766 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
5771 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
5773 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
5774 (((Elf32_External_Sym
*)
5779 /* Set the sh_info field of the output .dynsym section to
5780 the index of the first global symbol. */
5781 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
5782 SIZEOF_MIPS_DYNSYM_SECNAMES
;
5788 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
5791 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
5795 sym
.st_value
= s
->vma
;
5797 indx
= elf_section_data (s
)->this_idx
;
5798 BFD_ASSERT (indx
> 0);
5799 sym
.st_shndx
= indx
;
5801 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
5802 (((Elf32_External_Sym
*)
5804 + elf_section_data (s
)->dynindx
));
5807 /* Set the sh_info field of the output .dynsym section to
5808 the index of the first global symbol. */
5809 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
5810 bfd_count_sections (output_bfd
) + 1;
5814 if (SGI_COMPAT (output_bfd
))
5816 /* Write .compact_rel section out. */
5817 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5821 cpt
.num
= s
->reloc_count
;
5823 cpt
.offset
= (s
->output_section
->filepos
5824 + sizeof (Elf32_External_compact_rel
));
5827 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
5828 ((Elf32_External_compact_rel
*)
5831 /* Clean up a dummy stub function entry in .text. */
5832 s
= bfd_get_section_by_name (dynobj
, ".stub");
5835 file_ptr dummy_offset
;
5837 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
5838 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
5839 memset (s
->contents
+ dummy_offset
, 0,
5840 MIPS_FUNCTION_STUB_SIZE
);
5845 /* Clean up a first relocation in .rel.dyn. */
5846 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5848 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
5854 /* This is almost identical to bfd_generic_get_... except that some
5855 MIPS relocations need to be handled specially. Sigh. */
5858 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
5859 relocateable
, symbols
)
5861 struct bfd_link_info
*link_info
;
5862 struct bfd_link_order
*link_order
;
5864 boolean relocateable
;
5867 /* Get enough memory to hold the stuff */
5868 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
5869 asection
*input_section
= link_order
->u
.indirect
.section
;
5871 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
5872 arelent
**reloc_vector
= NULL
;
5878 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
5879 if (reloc_vector
== NULL
&& reloc_size
!= 0)
5882 /* read in the section */
5883 if (!bfd_get_section_contents (input_bfd
,
5887 input_section
->_raw_size
))
5890 /* We're not relaxing the section, so just copy the size info */
5891 input_section
->_cooked_size
= input_section
->_raw_size
;
5892 input_section
->reloc_done
= true;
5894 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
5898 if (reloc_count
< 0)
5901 if (reloc_count
> 0)
5906 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
5909 struct bfd_hash_entry
*h
;
5910 struct bfd_link_hash_entry
*lh
;
5911 /* Skip all this stuff if we aren't mixing formats. */
5912 if (abfd
&& input_bfd
5913 && abfd
->xvec
== input_bfd
->xvec
)
5917 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
5918 lh
= (struct bfd_link_hash_entry
*) h
;
5925 case bfd_link_hash_undefined
:
5926 case bfd_link_hash_undefweak
:
5927 case bfd_link_hash_common
:
5930 case bfd_link_hash_defined
:
5931 case bfd_link_hash_defweak
:
5933 gp
= lh
->u
.def
.value
;
5935 case bfd_link_hash_indirect
:
5936 case bfd_link_hash_warning
:
5938 /* @@FIXME ignoring warning for now */
5940 case bfd_link_hash_new
:
5949 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
5952 char *error_message
= (char *) NULL
;
5953 bfd_reloc_status_type r
;
5955 /* Specific to MIPS: Deal with relocation types that require
5956 knowing the gp of the output bfd. */
5957 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
5958 if (bfd_is_abs_section (sym
->section
) && abfd
)
5960 /* The special_function wouldn't get called anyways. */
5964 /* The gp isn't there; let the special function code
5965 fall over on its own. */
5967 else if ((*parent
)->howto
->special_function
5968 == _bfd_mips_elf_gprel16_reloc
)
5970 /* bypass special_function call */
5971 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
5972 relocateable
, (PTR
) data
, gp
);
5973 goto skip_bfd_perform_relocation
;
5975 /* end mips specific stuff */
5977 r
= bfd_perform_relocation (input_bfd
,
5981 relocateable
? abfd
: (bfd
*) NULL
,
5983 skip_bfd_perform_relocation
:
5987 asection
*os
= input_section
->output_section
;
5989 /* A partial link, so keep the relocs */
5990 os
->orelocation
[os
->reloc_count
] = *parent
;
5994 if (r
!= bfd_reloc_ok
)
5998 case bfd_reloc_undefined
:
5999 if (!((*link_info
->callbacks
->undefined_symbol
)
6000 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6001 input_bfd
, input_section
, (*parent
)->address
)))
6004 case bfd_reloc_dangerous
:
6005 BFD_ASSERT (error_message
!= (char *) NULL
);
6006 if (!((*link_info
->callbacks
->reloc_dangerous
)
6007 (link_info
, error_message
, input_bfd
, input_section
,
6008 (*parent
)->address
)))
6011 case bfd_reloc_overflow
:
6012 if (!((*link_info
->callbacks
->reloc_overflow
)
6013 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6014 (*parent
)->howto
->name
, (*parent
)->addend
,
6015 input_bfd
, input_section
, (*parent
)->address
)))
6018 case bfd_reloc_outofrange
:
6027 if (reloc_vector
!= NULL
)
6028 free (reloc_vector
);
6032 if (reloc_vector
!= NULL
)
6033 free (reloc_vector
);
6036 #define bfd_elf32_bfd_get_relocated_section_contents \
6037 elf32_mips_get_relocated_section_contents
6039 /* ECOFF swapping routines. These are used when dealing with the
6040 .mdebug section, which is in the ECOFF debugging format. */
6041 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
6043 /* Symbol table magic number. */
6045 /* Alignment of debugging information. E.g., 4. */
6047 /* Sizes of external symbolic information. */
6048 sizeof (struct hdr_ext
),
6049 sizeof (struct dnr_ext
),
6050 sizeof (struct pdr_ext
),
6051 sizeof (struct sym_ext
),
6052 sizeof (struct opt_ext
),
6053 sizeof (struct fdr_ext
),
6054 sizeof (struct rfd_ext
),
6055 sizeof (struct ext_ext
),
6056 /* Functions to swap in external symbolic data. */
6065 _bfd_ecoff_swap_tir_in
,
6066 _bfd_ecoff_swap_rndx_in
,
6067 /* Functions to swap out external symbolic data. */
6076 _bfd_ecoff_swap_tir_out
,
6077 _bfd_ecoff_swap_rndx_out
,
6078 /* Function to read in symbolic data. */
6079 _bfd_mips_elf_read_ecoff_info
6082 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
6083 #define TARGET_LITTLE_NAME "elf32-littlemips"
6084 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
6085 #define TARGET_BIG_NAME "elf32-bigmips"
6086 #define ELF_ARCH bfd_arch_mips
6087 #define ELF_MACHINE_CODE EM_MIPS
6088 #define ELF_MAXPAGESIZE 0x10000
6089 #define elf_backend_collect true
6090 #define elf_backend_type_change_ok true
6091 #define elf_info_to_howto 0
6092 #define elf_info_to_howto_rel mips_info_to_howto_rel
6093 #define elf_backend_sym_is_global mips_elf_sym_is_global
6094 #define elf_backend_object_p mips_elf32_object_p
6095 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
6096 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
6097 #define elf_backend_section_from_bfd_section \
6098 _bfd_mips_elf_section_from_bfd_section
6099 #define elf_backend_section_processing mips_elf32_section_processing
6100 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
6101 #define elf_backend_additional_program_headers \
6102 mips_elf_additional_program_headers
6103 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
6104 #define elf_backend_final_write_processing \
6105 _bfd_mips_elf_final_write_processing
6106 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
6108 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
6109 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
6110 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
6111 #define bfd_elf32_bfd_link_hash_table_create \
6112 mips_elf_link_hash_table_create
6113 #define bfd_elf32_bfd_final_link mips_elf_final_link
6114 #define bfd_elf32_bfd_copy_private_bfd_data \
6115 _bfd_mips_elf_copy_private_bfd_data
6116 #define bfd_elf32_bfd_merge_private_bfd_data \
6117 _bfd_mips_elf_merge_private_bfd_data
6118 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
6119 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
6120 #define elf_backend_create_dynamic_sections \
6121 mips_elf_create_dynamic_sections
6122 #define elf_backend_check_relocs mips_elf_check_relocs
6123 #define elf_backend_adjust_dynamic_symbol \
6124 mips_elf_adjust_dynamic_symbol
6125 #define elf_backend_size_dynamic_sections \
6126 mips_elf_size_dynamic_sections
6127 #define elf_backend_relocate_section mips_elf_relocate_section
6128 #define elf_backend_finish_dynamic_symbol \
6129 mips_elf_finish_dynamic_symbol
6130 #define elf_backend_finish_dynamic_sections \
6131 mips_elf_finish_dynamic_sections
6133 #include "elf32-target.h"