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_MIPS_JMP
, R_MIPS_26
},
1242 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1243 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1244 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
1245 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1246 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1247 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1248 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1249 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
},
1250 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1251 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1252 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1253 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
}
1256 /* Given a BFD reloc type, return a howto structure. */
1258 static reloc_howto_type
*
1259 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1261 bfd_reloc_code_real_type code
;
1265 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1267 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
1268 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
1273 /* Given a MIPS reloc type, fill in an arelent structure. */
1276 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1279 Elf32_Internal_Rel
*dst
;
1281 unsigned int r_type
;
1283 r_type
= ELF32_R_TYPE (dst
->r_info
);
1284 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1285 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
1287 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1288 value for the object file. We get the addend now, rather than
1289 when we do the relocation, because the symbol manipulations done
1290 by the linker may cause us to lose track of the input BFD. */
1291 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1292 && (r_type
== (unsigned int) R_MIPS_GPREL16
1293 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1294 cache_ptr
->addend
= elf_gp (abfd
);
1297 /* A .reginfo section holds a single Elf32_RegInfo structure. These
1298 routines swap this structure in and out. They are used outside of
1299 BFD, so they are globally visible. */
1302 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
1304 const Elf32_External_RegInfo
*ex
;
1307 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1308 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1309 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1310 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1311 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1312 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1316 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
1318 const Elf32_RegInfo
*in
;
1319 Elf32_External_RegInfo
*ex
;
1321 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1322 (bfd_byte
*) ex
->ri_gprmask
);
1323 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1324 (bfd_byte
*) ex
->ri_cprmask
[0]);
1325 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1326 (bfd_byte
*) ex
->ri_cprmask
[1]);
1327 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1328 (bfd_byte
*) ex
->ri_cprmask
[2]);
1329 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1330 (bfd_byte
*) ex
->ri_cprmask
[3]);
1331 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1332 (bfd_byte
*) ex
->ri_gp_value
);
1335 /* In the 64 bit ABI, the .MIPS.options section holds register
1336 information in an Elf64_Reginfo structure. These routines swap
1337 them in and out. They are globally visible because they are used
1338 outside of BFD. These routines are here so that gas can call them
1339 without worrying about whether the 64 bit ABI has been included. */
1342 bfd_mips_elf64_swap_reginfo_in (abfd
, ex
, in
)
1344 const Elf64_External_RegInfo
*ex
;
1345 Elf64_Internal_RegInfo
*in
;
1347 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
1348 in
->ri_pad
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_pad
);
1349 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
1350 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
1351 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
1352 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
1353 in
->ri_gp_value
= bfd_h_get_64 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
1357 bfd_mips_elf64_swap_reginfo_out (abfd
, in
, ex
)
1359 const Elf64_Internal_RegInfo
*in
;
1360 Elf64_External_RegInfo
*ex
;
1362 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
1363 (bfd_byte
*) ex
->ri_gprmask
);
1364 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_pad
,
1365 (bfd_byte
*) ex
->ri_pad
);
1366 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
1367 (bfd_byte
*) ex
->ri_cprmask
[0]);
1368 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
1369 (bfd_byte
*) ex
->ri_cprmask
[1]);
1370 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
1371 (bfd_byte
*) ex
->ri_cprmask
[2]);
1372 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
1373 (bfd_byte
*) ex
->ri_cprmask
[3]);
1374 bfd_h_put_64 (abfd
, (bfd_vma
) in
->ri_gp_value
,
1375 (bfd_byte
*) ex
->ri_gp_value
);
1378 /* Swap an entry in a .gptab section. Note that these routines rely
1379 on the equivalence of the two elements of the union. */
1382 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
1384 const Elf32_External_gptab
*ex
;
1387 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
1388 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
1392 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
1394 const Elf32_gptab
*in
;
1395 Elf32_External_gptab
*ex
;
1397 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
1398 ex
->gt_entry
.gt_g_value
);
1399 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
1400 ex
->gt_entry
.gt_bytes
);
1404 bfd_elf32_swap_compact_rel_out (abfd
, in
, ex
)
1406 const Elf32_compact_rel
*in
;
1407 Elf32_External_compact_rel
*ex
;
1409 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id1
, ex
->id1
);
1410 bfd_h_put_32 (abfd
, (bfd_vma
) in
->num
, ex
->num
);
1411 bfd_h_put_32 (abfd
, (bfd_vma
) in
->id2
, ex
->id2
);
1412 bfd_h_put_32 (abfd
, (bfd_vma
) in
->offset
, ex
->offset
);
1413 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved0
, ex
->reserved0
);
1414 bfd_h_put_32 (abfd
, (bfd_vma
) in
->reserved1
, ex
->reserved1
);
1418 bfd_elf32_swap_crinfo_out (abfd
, in
, ex
)
1420 const Elf32_crinfo
*in
;
1421 Elf32_External_crinfo
*ex
;
1425 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
1426 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
1427 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
1428 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
1429 bfd_h_put_32 (abfd
, (bfd_vma
) l
, ex
->info
);
1430 bfd_h_put_32 (abfd
, (bfd_vma
) in
->konst
, ex
->konst
);
1431 bfd_h_put_32 (abfd
, (bfd_vma
) in
->vaddr
, ex
->vaddr
);
1434 /* Swap in an options header. */
1437 bfd_mips_elf_swap_options_in (abfd
, ex
, in
)
1439 const Elf_External_Options
*ex
;
1440 Elf_Internal_Options
*in
;
1442 in
->kind
= bfd_h_get_8 (abfd
, ex
->kind
);
1443 in
->size
= bfd_h_get_8 (abfd
, ex
->size
);
1444 in
->section
= bfd_h_get_16 (abfd
, ex
->section
);
1445 in
->info
= bfd_h_get_32 (abfd
, ex
->info
);
1448 /* Swap out an options header. */
1451 bfd_mips_elf_swap_options_out (abfd
, in
, ex
)
1453 const Elf_Internal_Options
*in
;
1454 Elf_External_Options
*ex
;
1456 bfd_h_put_8 (abfd
, in
->kind
, ex
->kind
);
1457 bfd_h_put_8 (abfd
, in
->size
, ex
->size
);
1458 bfd_h_put_16 (abfd
, in
->section
, ex
->section
);
1459 bfd_h_put_32 (abfd
, in
->info
, ex
->info
);
1462 /* Determine whether a symbol is global for the purposes of splitting
1463 the symbol table into global symbols and local symbols. At least
1464 on Irix 5, this split must be between section symbols and all other
1465 symbols. On most ELF targets the split is between static symbols
1466 and externally visible symbols. */
1470 mips_elf_sym_is_global (abfd
, sym
)
1474 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
1477 /* Set the right machine number for a MIPS ELF file. This is used for
1478 both the 32-bit and the 64-bit ABI. */
1481 _bfd_mips_elf_object_p (abfd
)
1484 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
1488 /* Just use the default, which was set in elfcode.h. */
1492 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 6000);
1496 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 4000);
1500 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 8000);
1507 /* Set the right machine number for a 32-bit MIPS ELF file. */
1510 mips_elf32_object_p (abfd
)
1513 /* Irix 5 is broken. Object file symbol tables are not always
1514 sorted correctly such that local symbols precede global symbols,
1515 and the sh_info field in the symbol table is not always right. */
1516 elf_bad_symtab (abfd
) = true;
1518 return _bfd_mips_elf_object_p (abfd
);
1521 /* The final processing done just before writing out a MIPS ELF object
1522 file. This gets the MIPS architecture right based on the machine
1523 number. This is used by both the 32-bit and the 64-bit ABI. */
1527 _bfd_mips_elf_final_write_processing (abfd
, linker
)
1533 Elf_Internal_Shdr
**hdrpp
;
1535 switch (bfd_get_mach (abfd
))
1538 val
= E_MIPS_ARCH_1
;
1542 val
= E_MIPS_ARCH_2
;
1546 val
= E_MIPS_ARCH_3
;
1550 val
= E_MIPS_ARCH_4
;
1558 elf_elfheader (abfd
)->e_flags
&=~ EF_MIPS_ARCH
;
1559 elf_elfheader (abfd
)->e_flags
|= val
;
1561 /* Set the sh_info field for .gptab sections. */
1562 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
1563 i
< elf_elfheader (abfd
)->e_shnum
;
1566 if ((*hdrpp
)->sh_type
== SHT_MIPS_GPTAB
)
1571 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
1572 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
1573 BFD_ASSERT (name
!= NULL
1574 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
1575 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
1576 BFD_ASSERT (sec
!= NULL
);
1577 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
1582 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
1585 _bfd_mips_elf_set_private_flags (abfd
, flags
)
1589 BFD_ASSERT (!elf_flags_init (abfd
)
1590 || elf_elfheader (abfd
)->e_flags
== flags
);
1592 elf_elfheader (abfd
)->e_flags
= flags
;
1593 elf_flags_init (abfd
) = true;
1597 /* Copy backend specific data from one object module to another */
1600 _bfd_mips_elf_copy_private_bfd_data (ibfd
, obfd
)
1604 /* This function is selected based on the input vector. We only
1605 want to copy information over if the output BFD also uses Elf
1607 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1610 BFD_ASSERT (!elf_flags_init (obfd
)
1611 || (elf_elfheader (obfd
)->e_flags
1612 == elf_elfheader (ibfd
)->e_flags
));
1614 elf_gp (obfd
) = elf_gp (ibfd
);
1615 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1616 elf_flags_init (obfd
) = true;
1620 /* Merge backend specific data from an object file to the output
1621 object file when linking. */
1624 _bfd_mips_elf_merge_private_bfd_data (ibfd
, obfd
)
1631 /* Check if we have the same endianess */
1632 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1633 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1635 (*_bfd_error_handler
)
1636 ("%s: compiled for a %s endian system and target is %s endian",
1637 bfd_get_filename (ibfd
),
1638 bfd_big_endian (ibfd
) ? "big" : "little",
1639 bfd_big_endian (obfd
) ? "big" : "little");
1641 bfd_set_error (bfd_error_wrong_format
);
1645 /* This function is selected based on the input vector. We only
1646 want to copy information over if the output BFD also uses Elf
1648 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1651 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1652 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
1653 old_flags
= elf_elfheader (obfd
)->e_flags
;
1655 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1657 elf_flags_init (obfd
) = true;
1658 elf_elfheader (obfd
)->e_flags
= new_flags
;
1660 else if (((new_flags
^ old_flags
) & ~EF_MIPS_NOREORDER
)
1661 == 0) /* Compatible flags are ok */
1663 else /* Incompatible flags */
1665 /* Warn about -fPIC mismatch */
1666 if ((new_flags
& EF_MIPS_PIC
) != (old_flags
& EF_MIPS_PIC
))
1668 new_flags
&= ~EF_MIPS_PIC
;
1669 (*_bfd_error_handler
)
1670 ("%s: needs all files compiled with -fPIC",
1671 bfd_get_filename (ibfd
));
1674 if ((new_flags
& EF_MIPS_CPIC
) != (old_flags
& EF_MIPS_CPIC
))
1676 new_flags
&= ~EF_MIPS_CPIC
;
1677 (*_bfd_error_handler
)
1678 ("%s: needs all files compiled with -mabicalls",
1679 bfd_get_filename (ibfd
));
1682 /* Warn about any other mismatches */
1683 if (new_flags
!= old_flags
)
1684 (*_bfd_error_handler
)
1685 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1686 bfd_get_filename (ibfd
), (unsigned long) new_flags
,
1687 (unsigned long) old_flags
);
1689 bfd_set_error (bfd_error_bad_value
);
1696 /* Handle a MIPS specific section when reading an object file. This
1697 is called when elfcode.h finds a section with an unknown type.
1698 This routine supports both the 32-bit and 64-bit ELF ABI.
1700 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1704 _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
)
1706 Elf_Internal_Shdr
*hdr
;
1709 /* There ought to be a place to keep ELF backend specific flags, but
1710 at the moment there isn't one. We just keep track of the
1711 sections by their name, instead. Fortunately, the ABI gives
1712 suggested names for all the MIPS specific sections, so we will
1713 probably get away with this. */
1714 switch (hdr
->sh_type
)
1716 case SHT_MIPS_LIBLIST
:
1717 if (strcmp (name
, ".liblist") != 0)
1721 if (strcmp (name
, ".msym") != 0)
1724 case SHT_MIPS_CONFLICT
:
1725 if (strcmp (name
, ".conflict") != 0)
1728 case SHT_MIPS_GPTAB
:
1729 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
1732 case SHT_MIPS_UCODE
:
1733 if (strcmp (name
, ".ucode") != 0)
1736 case SHT_MIPS_DEBUG
:
1737 if (strcmp (name
, ".mdebug") != 0)
1740 case SHT_MIPS_REGINFO
:
1741 if (strcmp (name
, ".reginfo") != 0
1742 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
1745 case SHT_MIPS_OPTIONS
:
1746 if (strcmp (name
, ".options") != 0
1747 && strcmp (name
, ".MIPS.options") != 0)
1750 case SHT_MIPS_DWARF
:
1751 if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) != 0)
1754 case SHT_MIPS_EVENTS
:
1755 if (strncmp (name
, ".MIPS.events.", sizeof ".MIPS.events." - 1) != 0)
1762 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1765 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
1767 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
1768 (bfd_get_section_flags (abfd
,
1777 /* Handle a 32-bit MIPS ELF specific section. */
1780 mips_elf32_section_from_shdr (abfd
, hdr
, name
)
1782 Elf_Internal_Shdr
*hdr
;
1785 if (! _bfd_mips_elf_section_from_shdr (abfd
, hdr
, name
))
1788 /* FIXME: We should record sh_info for a .gptab section. */
1790 /* For a .reginfo section, set the gp value in the tdata information
1791 from the contents of this section. We need the gp value while
1792 processing relocs, so we just get it now. The .reginfo section
1793 is not used in the 64-bit MIPS ELF ABI. */
1794 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
1796 Elf32_External_RegInfo ext
;
1799 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, (PTR
) &ext
,
1800 (file_ptr
) 0, sizeof ext
))
1802 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
1803 elf_gp (abfd
) = s
.ri_gp_value
;
1806 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
1807 set the gp value based on what we find. We may see both
1808 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
1809 they should agree. */
1810 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
1812 bfd_byte
*contents
, *l
, *lend
;
1814 contents
= (bfd_byte
*) bfd_malloc (hdr
->sh_size
);
1815 if (contents
== NULL
)
1817 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
1818 (file_ptr
) 0, hdr
->sh_size
))
1824 lend
= contents
+ hdr
->sh_size
;
1825 while (l
+ sizeof (Elf_External_Options
) <= lend
)
1827 Elf_Internal_Options intopt
;
1829 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
1831 if (intopt
.kind
== ODK_REGINFO
)
1833 Elf32_RegInfo intreg
;
1835 bfd_mips_elf32_swap_reginfo_in
1837 ((Elf32_External_RegInfo
*)
1838 (l
+ sizeof (Elf_External_Options
))),
1840 elf_gp (abfd
) = intreg
.ri_gp_value
;
1850 /* Set the correct type for a MIPS ELF section. We do this by the
1851 section name, which is a hack, but ought to work. This routine is
1852 used by both the 32-bit and the 64-bit ABI. */
1855 _bfd_mips_elf_fake_sections (abfd
, hdr
, sec
)
1857 Elf32_Internal_Shdr
*hdr
;
1860 register const char *name
;
1862 name
= bfd_get_section_name (abfd
, sec
);
1864 if (strcmp (name
, ".liblist") == 0)
1866 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
1867 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
1868 /* FIXME: Set the sh_link field. */
1870 else if (strcmp (name
, ".msym") == 0)
1872 hdr
->sh_type
= SHT_MIPS_MSYM
;
1873 hdr
->sh_entsize
= 8;
1874 /* FIXME: Set the sh_info field. */
1876 else if (strcmp (name
, ".conflict") == 0)
1877 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
1878 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
1880 hdr
->sh_type
= SHT_MIPS_GPTAB
;
1881 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
1882 /* The sh_info field is set in final_write_processing. */
1884 else if (strcmp (name
, ".ucode") == 0)
1885 hdr
->sh_type
= SHT_MIPS_UCODE
;
1886 else if (strcmp (name
, ".mdebug") == 0)
1888 hdr
->sh_type
= SHT_MIPS_DEBUG
;
1889 /* In a shared object on Irix 5.3, the .mdebug section has an
1890 entsize of 0. FIXME: Does this matter? */
1891 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1892 hdr
->sh_entsize
= 0;
1894 hdr
->sh_entsize
= 1;
1896 else if (strcmp (name
, ".reginfo") == 0)
1898 hdr
->sh_type
= SHT_MIPS_REGINFO
;
1899 /* In a shared object on Irix 5.3, the .reginfo section has an
1900 entsize of 0x18. FIXME: Does this matter? */
1901 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
1902 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
1904 hdr
->sh_entsize
= 1;
1906 /* Force the section size to the correct value, even if the
1907 linker thinks it is larger. The link routine below will only
1908 write out this much data for .reginfo. */
1909 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
1911 else if (SGI_COMPAT (abfd
)
1912 && (strcmp (name
, ".hash") == 0
1913 || strcmp (name
, ".dynamic") == 0
1914 || strcmp (name
, ".dynstr") == 0))
1916 hdr
->sh_entsize
= 0;
1917 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
1919 else if (strcmp (name
, ".got") == 0
1920 || strcmp (name
, ".sdata") == 0
1921 || strcmp (name
, ".sbss") == 0
1922 || strcmp (name
, ".lit4") == 0
1923 || strcmp (name
, ".lit8") == 0)
1924 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
1925 else if (strcmp (name
, ".options") == 0
1926 || strcmp (name
, ".MIPS.options") == 0)
1928 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
1929 hdr
->sh_entsize
= 1;
1931 else if (strncmp (name
, ".debug_", sizeof ".debug_" - 1) == 0)
1932 hdr
->sh_type
= SHT_MIPS_DWARF
;
1933 else if (strncmp (name
, ".MIPS.events.", sizeof ".MIPS.events." - 1) == 0)
1934 hdr
->sh_type
= SHT_MIPS_EVENTS
;
1939 /* Given a BFD section, try to locate the corresponding ELF section
1940 index. This is used by both the 32-bit and the 64-bit ABI.
1941 Actually, it's not clear to me that the 64-bit ABI supports these,
1942 but for non-PIC objects we will certainly want support for at least
1943 the .scommon section. */
1946 _bfd_mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
1948 Elf32_Internal_Shdr
*hdr
;
1952 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
1954 *retval
= SHN_MIPS_SCOMMON
;
1957 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
1959 *retval
= SHN_MIPS_ACOMMON
;
1965 /* When are writing out the .options or .MIPS.options section,
1966 remember the bytes we are writing out, so that we can install the
1967 GP value in the section_processing routine. */
1970 _bfd_mips_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
1975 bfd_size_type count
;
1977 if (strcmp (section
->name
, ".options") == 0
1978 || strcmp (section
->name
, ".MIPS.options") == 0)
1982 if (elf_section_data (section
) == NULL
)
1984 section
->used_by_bfd
=
1985 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
1986 if (elf_section_data (section
) == NULL
)
1989 c
= (bfd_byte
*) elf_section_data (section
)->tdata
;
1994 if (section
->_cooked_size
!= 0)
1995 size
= section
->_cooked_size
;
1997 size
= section
->_raw_size
;
1998 c
= (PTR
) bfd_zalloc (abfd
, size
);
2001 elf_section_data (section
)->tdata
= (PTR
) c
;
2004 memcpy (c
+ offset
, location
, count
);
2007 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
2011 /* Work over a section just before writing it out. This routine is
2012 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
2013 sections that need the SHF_MIPS_GPREL flag by name; there has to be
2017 _bfd_mips_elf_section_processing (abfd
, hdr
)
2019 Elf_Internal_Shdr
*hdr
;
2021 if (hdr
->bfd_section
!= NULL
)
2023 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
2025 if (strcmp (name
, ".sdata") == 0)
2027 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2028 hdr
->sh_type
= SHT_PROGBITS
;
2030 else if (strcmp (name
, ".sbss") == 0)
2032 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2033 hdr
->sh_type
= SHT_NOBITS
;
2035 else if (strcmp (name
, ".lit8") == 0
2036 || strcmp (name
, ".lit4") == 0)
2038 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
2039 hdr
->sh_type
= SHT_PROGBITS
;
2041 else if (strcmp (name
, ".compact_rel") == 0)
2044 hdr
->sh_type
= SHT_PROGBITS
;
2046 else if (strcmp (name
, ".rtproc") == 0)
2048 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
2050 unsigned int adjust
;
2052 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
2054 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
2062 /* Work over a section just before writing it out. We update the GP
2063 value in the SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS sections based
2064 on the value we are using. */
2067 mips_elf32_section_processing (abfd
, hdr
)
2069 Elf32_Internal_Shdr
*hdr
;
2071 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
2075 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
2076 BFD_ASSERT (hdr
->contents
== NULL
);
2079 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
2082 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
2083 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
2087 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
2088 && hdr
->bfd_section
!= NULL
2089 && elf_section_data (hdr
->bfd_section
) != NULL
2090 && elf_section_data (hdr
->bfd_section
)->tdata
!= NULL
)
2092 bfd_byte
*contents
, *l
, *lend
;
2094 /* We stored the section contents in the elf_section_data tdata
2095 field in the set_section_contents routine. We save the
2096 section contents so that we don't have to read them again.
2097 At this point we know that elf_gp is set, so we can look
2098 through the section contents to see if there is an
2099 ODK_REGINFO structure. */
2101 contents
= (bfd_byte
*) elf_section_data (hdr
->bfd_section
)->tdata
;
2103 lend
= contents
+ hdr
->sh_size
;
2104 while (l
+ sizeof (Elf_External_Options
) <= lend
)
2106 Elf_Internal_Options intopt
;
2108 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
2110 if (intopt
.kind
== ODK_REGINFO
)
2117 + sizeof (Elf_External_Options
)
2118 + (sizeof (Elf32_External_RegInfo
) - 4)),
2121 bfd_h_put_32 (abfd
, elf_gp (abfd
), buf
);
2122 if (bfd_write (buf
, 1, 4, abfd
) != 4)
2129 return _bfd_mips_elf_section_processing (abfd
, hdr
);
2132 /* MIPS ELF uses two common sections. One is the usual one, and the
2133 other is for small objects. All the small objects are kept
2134 together, and then referenced via the gp pointer, which yields
2135 faster assembler code. This is what we use for the small common
2136 section. This approach is copied from ecoff.c. */
2137 static asection mips_elf_scom_section
;
2138 static asymbol mips_elf_scom_symbol
;
2139 static asymbol
*mips_elf_scom_symbol_ptr
;
2141 /* MIPS ELF also uses an acommon section, which represents an
2142 allocated common symbol which may be overridden by a
2143 definition in a shared library. */
2144 static asection mips_elf_acom_section
;
2145 static asymbol mips_elf_acom_symbol
;
2146 static asymbol
*mips_elf_acom_symbol_ptr
;
2148 /* The Irix 5 support uses two virtual sections, which represent
2149 text/data symbols defined in dynamic objects. */
2150 static asection mips_elf_text_section
;
2151 static asection
*mips_elf_text_section_ptr
;
2152 static asymbol mips_elf_text_symbol
;
2153 static asymbol
*mips_elf_text_symbol_ptr
;
2155 static asection mips_elf_data_section
;
2156 static asection
*mips_elf_data_section_ptr
;
2157 static asymbol mips_elf_data_symbol
;
2158 static asymbol
*mips_elf_data_symbol_ptr
;
2160 /* Handle the special MIPS section numbers that a symbol may use.
2161 This is used for both the 32-bit and the 64-bit ABI. */
2164 _bfd_mips_elf_symbol_processing (abfd
, asym
)
2168 elf_symbol_type
*elfsym
;
2170 elfsym
= (elf_symbol_type
*) asym
;
2171 switch (elfsym
->internal_elf_sym
.st_shndx
)
2173 case SHN_MIPS_ACOMMON
:
2174 /* This section is used in a dynamically linked executable file.
2175 It is an allocated common section. The dynamic linker can
2176 either resolve these symbols to something in a shared
2177 library, or it can just leave them here. For our purposes,
2178 we can consider these symbols to be in a new section. */
2179 if (mips_elf_acom_section
.name
== NULL
)
2181 /* Initialize the acommon section. */
2182 mips_elf_acom_section
.name
= ".acommon";
2183 mips_elf_acom_section
.flags
= SEC_ALLOC
;
2184 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
2185 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
2186 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
2187 mips_elf_acom_symbol
.name
= ".acommon";
2188 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
2189 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
2190 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
2192 asym
->section
= &mips_elf_acom_section
;
2196 /* Common symbols less than the GP size are automatically
2197 treated as SHN_MIPS_SCOMMON symbols. */
2198 if (asym
->value
> elf_gp_size (abfd
))
2201 case SHN_MIPS_SCOMMON
:
2202 if (mips_elf_scom_section
.name
== NULL
)
2204 /* Initialize the small common section. */
2205 mips_elf_scom_section
.name
= ".scommon";
2206 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
2207 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
2208 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
2209 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
2210 mips_elf_scom_symbol
.name
= ".scommon";
2211 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2212 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
2213 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
2215 asym
->section
= &mips_elf_scom_section
;
2216 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2219 case SHN_MIPS_SUNDEFINED
:
2220 asym
->section
= bfd_und_section_ptr
;
2223 #if 0 /* for SGI_COMPAT */
2225 asym
->section
= mips_elf_text_section_ptr
;
2229 asym
->section
= mips_elf_data_section_ptr
;
2235 /* When creating an Irix 5 executable, we need REGINFO and RTPROC
2239 mips_elf_additional_program_headers (abfd
)
2247 if (! SGI_COMPAT (abfd
))
2250 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2251 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2253 /* We need a PT_MIPS_REGINFO segment. */
2257 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2258 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2260 /* We need a PT_MIPS_RTPROC segment. */
2267 /* Modify the segment map for an Irix 5 executable. */
2270 mips_elf_modify_segment_map (abfd
)
2274 struct elf_segment_map
*m
, **pm
;
2276 if (! SGI_COMPAT (abfd
))
2279 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
2281 s
= bfd_get_section_by_name (abfd
, ".reginfo");
2282 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2284 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2285 if (m
->p_type
== PT_MIPS_REGINFO
)
2289 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2293 m
->p_type
= PT_MIPS_REGINFO
;
2297 /* We want to put it after the PHDR and INTERP segments. */
2298 pm
= &elf_tdata (abfd
)->segment_map
;
2300 && ((*pm
)->p_type
== PT_PHDR
2301 || (*pm
)->p_type
== PT_INTERP
))
2309 /* If there are .dynamic and .mdebug sections, we make a room for
2310 the RTPROC header. FIXME: Rewrite without section names. */
2311 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
2312 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
2313 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
2315 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2316 if (m
->p_type
== PT_MIPS_RTPROC
)
2320 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
2324 m
->p_type
= PT_MIPS_RTPROC
;
2326 s
= bfd_get_section_by_name (abfd
, ".rtproc");
2331 m
->p_flags_valid
= 1;
2339 /* We want to put it after the DYNAMIC segment. */
2340 pm
= &elf_tdata (abfd
)->segment_map
;
2341 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
2351 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr,
2352 .dynsym, and .hash sections, and everything in between. */
2353 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
2354 if ((*pm
)->p_type
== PT_DYNAMIC
)
2359 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
2361 static const char *sec_names
[] =
2362 { ".dynamic", ".dynstr", ".dynsym", ".hash" };
2365 struct elf_segment_map
*n
;
2369 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
2371 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
2372 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
2378 sz
= s
->_cooked_size
;
2381 if (high
< s
->vma
+ sz
)
2387 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2388 if ((s
->flags
& SEC_LOAD
) != 0
2391 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2395 n
= ((struct elf_segment_map
*)
2396 bfd_zalloc (abfd
, sizeof *n
+ (c
- 1) * sizeof (asection
*)));
2403 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2405 if ((s
->flags
& SEC_LOAD
) != 0
2408 + (s
->_cooked_size
!= 0 ? s
->_cooked_size
: s
->_raw_size
))
2422 /* The structure of the runtime procedure descriptor created by the
2423 loader for use by the static exception system. */
2425 typedef struct runtime_pdr
{
2426 bfd_vma adr
; /* memory address of start of procedure */
2427 long regmask
; /* save register mask */
2428 long regoffset
; /* save register offset */
2429 long fregmask
; /* save floating point register mask */
2430 long fregoffset
; /* save floating point register offset */
2431 long frameoffset
; /* frame size */
2432 short framereg
; /* frame pointer register */
2433 short pcreg
; /* offset or reg of return pc */
2434 long irpss
; /* index into the runtime string table */
2436 struct exception_info
*exception_info
;/* pointer to exception array */
2438 #define cbRPDR sizeof(RPDR)
2439 #define rpdNil ((pRPDR) 0)
2441 /* Swap RPDR (runtime procedure table entry) for output. */
2443 static void ecoff_swap_rpdr_out
2444 PARAMS ((bfd
*, const RPDR
*, struct rpdr_ext
*));
2447 ecoff_swap_rpdr_out (abfd
, in
, ex
)
2450 struct rpdr_ext
*ex
;
2452 /* ecoff_put_off was defined in ecoffswap.h. */
2453 ecoff_put_off (abfd
, in
->adr
, (bfd_byte
*) ex
->p_adr
);
2454 bfd_h_put_32 (abfd
, in
->regmask
, (bfd_byte
*) ex
->p_regmask
);
2455 bfd_h_put_32 (abfd
, in
->regoffset
, (bfd_byte
*) ex
->p_regoffset
);
2456 bfd_h_put_32 (abfd
, in
->fregmask
, (bfd_byte
*) ex
->p_fregmask
);
2457 bfd_h_put_32 (abfd
, in
->fregoffset
, (bfd_byte
*) ex
->p_fregoffset
);
2458 bfd_h_put_32 (abfd
, in
->frameoffset
, (bfd_byte
*) ex
->p_frameoffset
);
2460 bfd_h_put_16 (abfd
, in
->framereg
, (bfd_byte
*) ex
->p_framereg
);
2461 bfd_h_put_16 (abfd
, in
->pcreg
, (bfd_byte
*) ex
->p_pcreg
);
2463 bfd_h_put_32 (abfd
, in
->irpss
, (bfd_byte
*) ex
->p_irpss
);
2465 ecoff_put_off (abfd
, in
->exception_info
, (bfd_byte
*) ex
->p_exception_info
);
2469 /* Read ECOFF debugging information from a .mdebug section into a
2470 ecoff_debug_info structure. */
2473 _bfd_mips_elf_read_ecoff_info (abfd
, section
, debug
)
2476 struct ecoff_debug_info
*debug
;
2479 const struct ecoff_debug_swap
*swap
;
2480 char *ext_hdr
= NULL
;
2482 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2484 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
2485 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2488 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2489 swap
->external_hdr_size
)
2493 symhdr
= &debug
->symbolic_header
;
2494 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2496 /* The symbolic header contains absolute file offsets and sizes to
2498 #define READ(ptr, offset, count, size, type) \
2499 if (symhdr->count == 0) \
2500 debug->ptr = NULL; \
2503 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
2504 if (debug->ptr == NULL) \
2505 goto error_return; \
2506 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2507 || (bfd_read (debug->ptr, size, symhdr->count, \
2508 abfd) != size * symhdr->count)) \
2509 goto error_return; \
2512 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2513 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2514 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2515 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2516 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2517 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2519 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2520 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2521 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2522 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2523 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2527 debug
->adjust
= NULL
;
2532 if (ext_hdr
!= NULL
)
2534 if (debug
->line
!= NULL
)
2536 if (debug
->external_dnr
!= NULL
)
2537 free (debug
->external_dnr
);
2538 if (debug
->external_pdr
!= NULL
)
2539 free (debug
->external_pdr
);
2540 if (debug
->external_sym
!= NULL
)
2541 free (debug
->external_sym
);
2542 if (debug
->external_opt
!= NULL
)
2543 free (debug
->external_opt
);
2544 if (debug
->external_aux
!= NULL
)
2545 free (debug
->external_aux
);
2546 if (debug
->ss
!= NULL
)
2548 if (debug
->ssext
!= NULL
)
2549 free (debug
->ssext
);
2550 if (debug
->external_fdr
!= NULL
)
2551 free (debug
->external_fdr
);
2552 if (debug
->external_rfd
!= NULL
)
2553 free (debug
->external_rfd
);
2554 if (debug
->external_ext
!= NULL
)
2555 free (debug
->external_ext
);
2559 /* MIPS ELF local labels start with '$', not 'L'. */
2563 mips_elf_is_local_label (abfd
, symbol
)
2567 return symbol
->name
[0] == '$';
2570 /* MIPS ELF uses a special find_nearest_line routine in order the
2571 handle the ECOFF debugging information. */
2573 struct mips_elf_find_line
2575 struct ecoff_debug_info d
;
2576 struct ecoff_find_line i
;
2580 _bfd_mips_elf_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2581 functionname_ptr
, line_ptr
)
2586 const char **filename_ptr
;
2587 const char **functionname_ptr
;
2588 unsigned int *line_ptr
;
2592 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2596 struct mips_elf_find_line
*fi
;
2597 const struct ecoff_debug_swap
* const swap
=
2598 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2600 /* If we are called during a link, mips_elf_final_link may have
2601 cleared the SEC_HAS_CONTENTS field. We force it back on here
2602 if appropriate (which it normally will be). */
2603 origflags
= msec
->flags
;
2604 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2605 msec
->flags
|= SEC_HAS_CONTENTS
;
2607 fi
= elf_tdata (abfd
)->find_line_info
;
2610 bfd_size_type external_fdr_size
;
2613 struct fdr
*fdr_ptr
;
2615 fi
= ((struct mips_elf_find_line
*)
2616 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
2619 msec
->flags
= origflags
;
2623 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
2625 msec
->flags
= origflags
;
2629 /* Swap in the FDR information. */
2630 fi
->d
.fdr
= ((struct fdr
*)
2632 (fi
->d
.symbolic_header
.ifdMax
*
2633 sizeof (struct fdr
))));
2634 if (fi
->d
.fdr
== NULL
)
2636 msec
->flags
= origflags
;
2639 external_fdr_size
= swap
->external_fdr_size
;
2640 fdr_ptr
= fi
->d
.fdr
;
2641 fraw_src
= (char *) fi
->d
.external_fdr
;
2642 fraw_end
= (fraw_src
2643 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2644 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2645 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2647 elf_tdata (abfd
)->find_line_info
= fi
;
2649 /* Note that we don't bother to ever free this information.
2650 find_nearest_line is either called all the time, as in
2651 objdump -l, so the information should be saved, or it is
2652 rarely called, as in ld error messages, so the memory
2653 wasted is unimportant. Still, it would probably be a
2654 good idea for free_cached_info to throw it away. */
2657 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2658 &fi
->i
, filename_ptr
, functionname_ptr
,
2661 msec
->flags
= origflags
;
2665 msec
->flags
= origflags
;
2668 /* Fall back on the generic ELF find_nearest_line routine. */
2670 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2671 filename_ptr
, functionname_ptr
,
2675 /* The MIPS ELF linker needs additional information for each symbol in
2676 the global hash table. */
2678 struct mips_elf_link_hash_entry
2680 struct elf_link_hash_entry root
;
2682 /* External symbol information. */
2685 /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */
2686 unsigned int mips_32_relocs
;
2689 /* MIPS ELF linker hash table. */
2691 struct mips_elf_link_hash_table
2693 struct elf_link_hash_table root
;
2694 /* String section indices for the dynamic section symbols. */
2695 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
2696 /* The number of .rtproc entries. */
2697 bfd_size_type procedure_count
;
2698 /* The size of the .compact_rel section (if SGI_COMPAT). */
2699 bfd_size_type compact_rel_size
;
2700 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
2701 entry is set to the address of __rld_obj_head as in Irix 5. */
2702 boolean use_rld_obj_head
;
2703 /* This is the value of the __rld_map or __rld_obj_head symbol. */
2707 /* Look up an entry in a MIPS ELF linker hash table. */
2709 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
2710 ((struct mips_elf_link_hash_entry *) \
2711 elf_link_hash_lookup (&(table)->root, (string), (create), \
2714 /* Traverse a MIPS ELF linker hash table. */
2716 #define mips_elf_link_hash_traverse(table, func, info) \
2717 (elf_link_hash_traverse \
2719 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
2722 /* Get the MIPS ELF linker hash table from a link_info structure. */
2724 #define mips_elf_hash_table(p) \
2725 ((struct mips_elf_link_hash_table *) ((p)->hash))
2727 static boolean mips_elf_output_extsym
2728 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
2730 /* Create an entry in a MIPS ELF linker hash table. */
2732 static struct bfd_hash_entry
*
2733 mips_elf_link_hash_newfunc (entry
, table
, string
)
2734 struct bfd_hash_entry
*entry
;
2735 struct bfd_hash_table
*table
;
2738 struct mips_elf_link_hash_entry
*ret
=
2739 (struct mips_elf_link_hash_entry
*) entry
;
2741 /* Allocate the structure if it has not already been allocated by a
2743 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2744 ret
= ((struct mips_elf_link_hash_entry
*)
2745 bfd_hash_allocate (table
,
2746 sizeof (struct mips_elf_link_hash_entry
)));
2747 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
2748 return (struct bfd_hash_entry
*) ret
;
2750 /* Call the allocation method of the superclass. */
2751 ret
= ((struct mips_elf_link_hash_entry
*)
2752 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2754 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
2756 /* Set local fields. */
2757 memset (&ret
->esym
, 0, sizeof (EXTR
));
2758 /* We use -2 as a marker to indicate that the information has
2759 not been set. -1 means there is no associated ifd. */
2761 ret
->mips_32_relocs
= 0;
2764 return (struct bfd_hash_entry
*) ret
;
2767 /* Create a MIPS ELF linker hash table. */
2769 static struct bfd_link_hash_table
*
2770 mips_elf_link_hash_table_create (abfd
)
2773 struct mips_elf_link_hash_table
*ret
;
2776 ret
= ((struct mips_elf_link_hash_table
*)
2777 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
2778 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
2781 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
2782 mips_elf_link_hash_newfunc
))
2784 bfd_release (abfd
, ret
);
2788 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
2789 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
2790 ret
->procedure_count
= 0;
2791 ret
->compact_rel_size
= 0;
2792 ret
->use_rld_obj_head
= false;
2795 return &ret
->root
.root
;
2798 /* Hook called by the linker routine which adds symbols from an object
2799 file. We must handle the special MIPS section numbers here. */
2803 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2805 struct bfd_link_info
*info
;
2806 const Elf_Internal_Sym
*sym
;
2812 if (SGI_COMPAT (abfd
)
2813 && (abfd
->flags
& DYNAMIC
) != 0
2814 && strcmp (*namep
, "_rld_new_interface") == 0)
2816 /* Skip Irix 5 rld entry name. */
2821 switch (sym
->st_shndx
)
2824 /* Common symbols less than the GP size are automatically
2825 treated as SHN_MIPS_SCOMMON symbols. */
2826 if (sym
->st_size
> elf_gp_size (abfd
))
2829 case SHN_MIPS_SCOMMON
:
2830 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2831 (*secp
)->flags
|= SEC_IS_COMMON
;
2832 *valp
= sym
->st_size
;
2836 /* This section is used in a shared object. */
2837 if (mips_elf_text_section_ptr
== NULL
)
2839 /* Initialize the section. */
2840 mips_elf_text_section
.name
= ".text";
2841 mips_elf_text_section
.flags
= SEC_NO_FLAGS
;
2842 mips_elf_text_section
.output_section
= NULL
;
2843 mips_elf_text_section
.owner
= abfd
;
2844 mips_elf_text_section
.symbol
= &mips_elf_text_symbol
;
2845 mips_elf_text_section
.symbol_ptr_ptr
= &mips_elf_text_symbol_ptr
;
2846 mips_elf_text_symbol
.name
= ".text";
2847 mips_elf_text_symbol
.flags
= BSF_SECTION_SYM
;
2848 mips_elf_text_symbol
.section
= &mips_elf_text_section
;
2849 mips_elf_text_symbol_ptr
= &mips_elf_text_symbol
;
2850 mips_elf_text_section_ptr
= &mips_elf_text_section
;
2853 *secp
= bfd_und_section_ptr
;
2855 *secp
= mips_elf_text_section_ptr
;
2858 case SHN_MIPS_ACOMMON
:
2859 /* Fall through. XXX Can we treat this as allocated data? */
2861 /* This section is used in a shared object. */
2862 if (mips_elf_data_section_ptr
== NULL
)
2864 /* Initialize the section. */
2865 mips_elf_data_section
.name
= ".data";
2866 mips_elf_data_section
.flags
= SEC_NO_FLAGS
;
2867 mips_elf_data_section
.output_section
= NULL
;
2868 mips_elf_data_section
.owner
= abfd
;
2869 mips_elf_data_section
.symbol
= &mips_elf_data_symbol
;
2870 mips_elf_data_section
.symbol_ptr_ptr
= &mips_elf_data_symbol_ptr
;
2871 mips_elf_data_symbol
.name
= ".data";
2872 mips_elf_data_symbol
.flags
= BSF_SECTION_SYM
;
2873 mips_elf_data_symbol
.section
= &mips_elf_data_section
;
2874 mips_elf_data_symbol_ptr
= &mips_elf_data_symbol
;
2875 mips_elf_data_section_ptr
= &mips_elf_data_section
;
2878 *secp
= bfd_und_section_ptr
;
2880 *secp
= mips_elf_data_section_ptr
;
2883 case SHN_MIPS_SUNDEFINED
:
2884 *secp
= bfd_und_section_ptr
;
2888 if (SGI_COMPAT (abfd
)
2890 && info
->hash
->creator
== abfd
->xvec
2891 && strcmp (*namep
, "__rld_obj_head") == 0)
2893 struct elf_link_hash_entry
*h
;
2895 /* Mark __rld_obj_head as dynamic. */
2897 if (! (_bfd_generic_link_add_one_symbol
2898 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
,
2899 (bfd_vma
) *valp
, (const char *) NULL
, false,
2900 get_elf_backend_data (abfd
)->collect
,
2901 (struct bfd_link_hash_entry
**) &h
)))
2903 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
2904 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2905 h
->type
= STT_OBJECT
;
2907 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2910 mips_elf_hash_table (info
)->use_rld_obj_head
= true;
2916 /* Structure used to pass information to mips_elf_output_extsym. */
2921 struct bfd_link_info
*info
;
2922 struct ecoff_debug_info
*debug
;
2923 const struct ecoff_debug_swap
*swap
;
2927 /* This routine is used to write out ECOFF debugging external symbol
2928 information. It is called via mips_elf_link_hash_traverse. The
2929 ECOFF external symbol information must match the ELF external
2930 symbol information. Unfortunately, at this point we don't know
2931 whether a symbol is required by reloc information, so the two
2932 tables may wind up being different. We must sort out the external
2933 symbol information before we can set the final size of the .mdebug
2934 section, and we must set the size of the .mdebug section before we
2935 can relocate any sections, and we can't know which symbols are
2936 required by relocation until we relocate the sections.
2937 Fortunately, it is relatively unlikely that any symbol will be
2938 stripped but required by a reloc. In particular, it can not happen
2939 when generating a final executable. */
2942 mips_elf_output_extsym (h
, data
)
2943 struct mips_elf_link_hash_entry
*h
;
2946 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
2948 asection
*sec
, *output_section
;
2950 if (h
->root
.indx
== -2)
2952 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2953 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
2954 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2955 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
2957 else if (einfo
->info
->strip
== strip_all
2958 || (einfo
->info
->strip
== strip_some
2959 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2960 h
->root
.root
.root
.string
,
2961 false, false) == NULL
))
2969 if (h
->esym
.ifd
== -2)
2972 h
->esym
.cobol_main
= 0;
2973 h
->esym
.weakext
= 0;
2974 h
->esym
.reserved
= 0;
2975 h
->esym
.ifd
= ifdNil
;
2976 h
->esym
.asym
.value
= 0;
2977 h
->esym
.asym
.st
= stGlobal
;
2979 if (SGI_COMPAT (einfo
->abfd
)
2980 && (h
->root
.root
.type
== bfd_link_hash_undefined
2981 || h
->root
.root
.type
== bfd_link_hash_undefweak
))
2985 /* Use undefined class. Also, set class and type for some
2987 name
= h
->root
.root
.root
.string
;
2988 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2989 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2991 h
->esym
.asym
.sc
= scData
;
2992 h
->esym
.asym
.st
= stLabel
;
2993 h
->esym
.asym
.value
= 0;
2995 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2997 h
->esym
.asym
.sc
= scAbs
;
2998 h
->esym
.asym
.st
= stLabel
;
2999 h
->esym
.asym
.value
=
3000 mips_elf_hash_table (einfo
->info
)->procedure_count
;
3002 else if (strcmp (name
, "_gp_disp") == 0)
3004 h
->esym
.asym
.sc
= scAbs
;
3005 h
->esym
.asym
.st
= stLabel
;
3006 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
3009 h
->esym
.asym
.sc
= scUndefined
;
3011 else if (h
->root
.root
.type
!= bfd_link_hash_defined
3012 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
3013 h
->esym
.asym
.sc
= scAbs
;
3018 sec
= h
->root
.root
.u
.def
.section
;
3019 output_section
= sec
->output_section
;
3021 /* When making a shared library and symbol h is the one from
3022 the another shared library, OUTPUT_SECTION may be null. */
3023 if (output_section
== NULL
)
3024 h
->esym
.asym
.sc
= scUndefined
;
3027 name
= bfd_section_name (output_section
->owner
, output_section
);
3029 if (strcmp (name
, ".text") == 0)
3030 h
->esym
.asym
.sc
= scText
;
3031 else if (strcmp (name
, ".data") == 0)
3032 h
->esym
.asym
.sc
= scData
;
3033 else if (strcmp (name
, ".sdata") == 0)
3034 h
->esym
.asym
.sc
= scSData
;
3035 else if (strcmp (name
, ".rodata") == 0
3036 || strcmp (name
, ".rdata") == 0)
3037 h
->esym
.asym
.sc
= scRData
;
3038 else if (strcmp (name
, ".bss") == 0)
3039 h
->esym
.asym
.sc
= scBss
;
3040 else if (strcmp (name
, ".sbss") == 0)
3041 h
->esym
.asym
.sc
= scSBss
;
3042 else if (strcmp (name
, ".init") == 0)
3043 h
->esym
.asym
.sc
= scInit
;
3044 else if (strcmp (name
, ".fini") == 0)
3045 h
->esym
.asym
.sc
= scFini
;
3047 h
->esym
.asym
.sc
= scAbs
;
3051 h
->esym
.asym
.reserved
= 0;
3052 h
->esym
.asym
.index
= indexNil
;
3055 if (h
->root
.root
.type
== bfd_link_hash_common
)
3056 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
3057 else if (h
->root
.root
.type
== bfd_link_hash_defined
3058 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3060 if (h
->esym
.asym
.sc
== scCommon
)
3061 h
->esym
.asym
.sc
= scBss
;
3062 else if (h
->esym
.asym
.sc
== scSCommon
)
3063 h
->esym
.asym
.sc
= scSBss
;
3065 sec
= h
->root
.root
.u
.def
.section
;
3066 output_section
= sec
->output_section
;
3067 if (output_section
!= NULL
)
3068 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
3069 + sec
->output_offset
3070 + output_section
->vma
);
3072 h
->esym
.asym
.value
= 0;
3074 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3076 /* Set type and value for a symbol with a function stub. */
3077 h
->esym
.asym
.st
= stProc
;
3078 sec
= h
->root
.root
.u
.def
.section
;
3080 h
->esym
.asym
.value
= 0;
3083 output_section
= sec
->output_section
;
3084 if (output_section
!= NULL
)
3085 h
->esym
.asym
.value
= (h
->root
.plt_offset
3086 + sec
->output_offset
3087 + output_section
->vma
);
3089 h
->esym
.asym
.value
= 0;
3096 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
3097 h
->root
.root
.root
.string
,
3100 einfo
->failed
= true;
3107 /* Create a runtime procedure table from the .mdebug section. */
3110 mips_elf_create_procedure_table (handle
, abfd
, info
, s
, debug
)
3113 struct bfd_link_info
*info
;
3115 struct ecoff_debug_info
*debug
;
3117 const struct ecoff_debug_swap
*swap
;
3118 HDRR
*hdr
= &debug
->symbolic_header
;
3120 struct rpdr_ext
*erp
;
3122 struct pdr_ext
*epdr
;
3123 struct sym_ext
*esym
;
3126 unsigned long size
, count
;
3127 unsigned long sindex
;
3131 const char *no_name_func
= "static procedure (no name)";
3139 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3141 sindex
= strlen (no_name_func
) + 1;
3142 count
= hdr
->ipdMax
;
3145 size
= swap
->external_pdr_size
;
3147 epdr
= (struct pdr_ext
*) bfd_malloc (size
* count
);
3151 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (PTR
) epdr
))
3154 size
= sizeof (RPDR
);
3155 rp
= rpdr
= (RPDR
*) bfd_malloc (size
* count
);
3159 sv
= (char **) bfd_malloc (sizeof (char *) * count
);
3163 count
= hdr
->isymMax
;
3164 size
= swap
->external_sym_size
;
3165 esym
= (struct sym_ext
*) bfd_malloc (size
* count
);
3169 if (! _bfd_ecoff_get_accumulated_sym (handle
, (PTR
) esym
))
3172 count
= hdr
->issMax
;
3173 ss
= (char *) bfd_malloc (count
);
3176 if (! _bfd_ecoff_get_accumulated_ss (handle
, (PTR
) ss
))
3179 count
= hdr
->ipdMax
;
3180 for (i
= 0; i
< count
; i
++, rp
++)
3182 (*swap
->swap_pdr_in
) (abfd
, (PTR
) (epdr
+ i
), &pdr
);
3183 (*swap
->swap_sym_in
) (abfd
, (PTR
) &esym
[pdr
.isym
], &sym
);
3184 rp
->adr
= sym
.value
;
3185 rp
->regmask
= pdr
.regmask
;
3186 rp
->regoffset
= pdr
.regoffset
;
3187 rp
->fregmask
= pdr
.fregmask
;
3188 rp
->fregoffset
= pdr
.fregoffset
;
3189 rp
->frameoffset
= pdr
.frameoffset
;
3190 rp
->framereg
= pdr
.framereg
;
3191 rp
->pcreg
= pdr
.pcreg
;
3193 sv
[i
] = ss
+ sym
.iss
;
3194 sindex
+= strlen (sv
[i
]) + 1;
3198 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
3199 size
= BFD_ALIGN (size
, 16);
3200 rtproc
= (PTR
) bfd_alloc (abfd
, size
);
3203 mips_elf_hash_table (info
)->procedure_count
= 0;
3207 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
3209 erp
= (struct rpdr_ext
*) rtproc
;
3210 memset (erp
, 0, sizeof (struct rpdr_ext
));
3212 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
3213 strcpy (str
, no_name_func
);
3214 str
+= strlen (no_name_func
) + 1;
3215 for (i
= 0; i
< count
; i
++)
3217 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
3218 strcpy (str
, sv
[i
]);
3219 str
+= strlen (sv
[i
]) + 1;
3221 ecoff_put_off (abfd
, (bfd_vma
) -1, (bfd_byte
*) (erp
+ count
)->p_adr
);
3223 /* Set the size and contents of .rtproc section. */
3224 s
->_raw_size
= size
;
3225 s
->contents
= rtproc
;
3227 /* Skip this section later on (I don't think this currently
3228 matters, but someday it might). */
3229 s
->link_order_head
= (struct bfd_link_order
*) NULL
;
3258 /* A comparison routine used to sort .gptab entries. */
3261 gptab_compare (p1
, p2
)
3265 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
3266 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
3268 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
3271 /* We need to use a special link routine to handle the .reginfo and
3272 the .mdebug sections. We need to merge all instances of these
3273 sections together, not write them all out sequentially. */
3276 mips_elf_final_link (abfd
, info
)
3278 struct bfd_link_info
*info
;
3282 struct bfd_link_order
*p
;
3283 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3284 asection
*rtproc_sec
;
3285 Elf32_RegInfo reginfo
;
3286 struct ecoff_debug_info debug
;
3287 const struct ecoff_debug_swap
*swap
3288 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3289 HDRR
*symhdr
= &debug
.symbolic_header
;
3290 PTR mdebug_handle
= NULL
;
3292 /* Drop the .options section, since it has special semantics which I
3293 haven't bothered to figure out. */
3294 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
3296 if (strcmp ((*secpp
)->name
, ".options") == 0)
3298 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
3299 if (p
->type
== bfd_indirect_link_order
)
3300 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
3301 (*secpp
)->link_order_head
= NULL
;
3302 *secpp
= (*secpp
)->next
;
3303 --abfd
->section_count
;
3308 /* Get a value for the GP register. */
3309 if (elf_gp (abfd
) == 0)
3311 struct bfd_link_hash_entry
*h
;
3313 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3314 if (h
!= (struct bfd_link_hash_entry
*) NULL
3315 && h
->type
== bfd_link_hash_defined
)
3316 elf_gp (abfd
) = (h
->u
.def
.value
3317 + h
->u
.def
.section
->output_section
->vma
3318 + h
->u
.def
.section
->output_offset
);
3319 else if (info
->relocateable
)
3323 /* Make up a value. */
3325 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3328 && (strcmp (o
->name
, ".sbss") == 0
3329 || strcmp (o
->name
, ".sdata") == 0
3330 || strcmp (o
->name
, ".lit4") == 0
3331 || strcmp (o
->name
, ".lit8") == 0))
3334 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (abfd
);
3338 /* If the relocate_section function needs to do a reloc
3339 involving the GP value, it should make a reloc_dangerous
3340 callback to warn that GP is not defined. */
3344 /* Go through the sections and collect the .reginfo and .mdebug
3348 gptab_data_sec
= NULL
;
3349 gptab_bss_sec
= NULL
;
3350 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3352 if (strcmp (o
->name
, ".reginfo") == 0)
3354 memset (®info
, 0, sizeof reginfo
);
3356 /* We have found the .reginfo section in the output file.
3357 Look through all the link_orders comprising it and merge
3358 the information together. */
3359 for (p
= o
->link_order_head
;
3360 p
!= (struct bfd_link_order
*) NULL
;
3363 asection
*input_section
;
3365 Elf32_External_RegInfo ext
;
3368 if (p
->type
!= bfd_indirect_link_order
)
3370 if (p
->type
== bfd_fill_link_order
)
3375 input_section
= p
->u
.indirect
.section
;
3376 input_bfd
= input_section
->owner
;
3378 /* The linker emulation code has probably clobbered the
3379 size to be zero bytes. */
3380 if (input_section
->_raw_size
== 0)
3381 input_section
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3383 if (! bfd_get_section_contents (input_bfd
, input_section
,
3389 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3391 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3392 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3393 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3394 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3395 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3397 /* ri_gp_value is set by the function
3398 mips_elf32_section_processing when the section is
3399 finally written out. */
3401 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3402 elf_link_input_bfd ignores this section. */
3403 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3406 /* Force the section size to the value we want. */
3407 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
3409 /* Skip this section later on (I don't think this currently
3410 matters, but someday it might). */
3411 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3416 if (strcmp (o
->name
, ".mdebug") == 0)
3418 struct extsym_info einfo
;
3420 /* We have found the .mdebug section in the output file.
3421 Look through all the link_orders comprising it and merge
3422 the information together. */
3423 symhdr
->magic
= swap
->sym_magic
;
3424 /* FIXME: What should the version stamp be? */
3426 symhdr
->ilineMax
= 0;
3430 symhdr
->isymMax
= 0;
3431 symhdr
->ioptMax
= 0;
3432 symhdr
->iauxMax
= 0;
3434 symhdr
->issExtMax
= 0;
3437 symhdr
->iextMax
= 0;
3439 /* We accumulate the debugging information itself in the
3440 debug_info structure. */
3442 debug
.external_dnr
= NULL
;
3443 debug
.external_pdr
= NULL
;
3444 debug
.external_sym
= NULL
;
3445 debug
.external_opt
= NULL
;
3446 debug
.external_aux
= NULL
;
3448 debug
.ssext
= debug
.ssext_end
= NULL
;
3449 debug
.external_fdr
= NULL
;
3450 debug
.external_rfd
= NULL
;
3451 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3453 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3454 if (mdebug_handle
== (PTR
) NULL
)
3457 if (SGI_COMPAT (abfd
))
3463 static const char * const name
[] =
3464 { ".text", ".init", ".fini", ".data",
3465 ".rodata", ".sdata", ".sbss", ".bss" };
3466 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3467 scRData
, scSData
, scSBss
, scBss
};
3470 esym
.cobol_main
= 0;
3474 esym
.asym
.iss
= issNil
;
3475 esym
.asym
.st
= stLocal
;
3476 esym
.asym
.reserved
= 0;
3477 esym
.asym
.index
= indexNil
;
3478 for (i
= 0; i
< 8; i
++)
3480 esym
.asym
.sc
= sc
[i
];
3481 s
= bfd_get_section_by_name (abfd
, name
[i
]);
3484 esym
.asym
.value
= s
->vma
;
3485 last
= s
->vma
+ s
->_raw_size
;
3488 esym
.asym
.value
= last
;
3490 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
3496 for (p
= o
->link_order_head
;
3497 p
!= (struct bfd_link_order
*) NULL
;
3500 asection
*input_section
;
3502 const struct ecoff_debug_swap
*input_swap
;
3503 struct ecoff_debug_info input_debug
;
3507 if (p
->type
!= bfd_indirect_link_order
)
3509 if (p
->type
== bfd_fill_link_order
)
3514 input_section
= p
->u
.indirect
.section
;
3515 input_bfd
= input_section
->owner
;
3517 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
3518 || (get_elf_backend_data (input_bfd
)
3519 ->elf_backend_ecoff_debug_swap
) == NULL
)
3521 /* I don't know what a non MIPS ELF bfd would be
3522 doing with a .mdebug section, but I don't really
3523 want to deal with it. */
3527 input_swap
= (get_elf_backend_data (input_bfd
)
3528 ->elf_backend_ecoff_debug_swap
);
3530 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
3532 /* The ECOFF linking code expects that we have already
3533 read in the debugging information and set up an
3534 ecoff_debug_info structure, so we do that now. */
3535 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
3539 if (! (bfd_ecoff_debug_accumulate
3540 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
3541 &input_debug
, input_swap
, info
)))
3544 /* Loop through the external symbols. For each one with
3545 interesting information, try to find the symbol in
3546 the linker global hash table and save the information
3547 for the output external symbols. */
3548 eraw_src
= input_debug
.external_ext
;
3549 eraw_end
= (eraw_src
3550 + (input_debug
.symbolic_header
.iextMax
3551 * input_swap
->external_ext_size
));
3553 eraw_src
< eraw_end
;
3554 eraw_src
+= input_swap
->external_ext_size
)
3558 struct mips_elf_link_hash_entry
*h
;
3560 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
3561 if (ext
.asym
.sc
== scNil
3562 || ext
.asym
.sc
== scUndefined
3563 || ext
.asym
.sc
== scSUndefined
)
3566 name
= input_debug
.ssext
+ ext
.asym
.iss
;
3567 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
3568 name
, false, false, true);
3569 if (h
== NULL
|| h
->esym
.ifd
!= -2)
3575 < input_debug
.symbolic_header
.ifdMax
);
3576 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
3582 /* Free up the information we just read. */
3583 free (input_debug
.line
);
3584 free (input_debug
.external_dnr
);
3585 free (input_debug
.external_pdr
);
3586 free (input_debug
.external_sym
);
3587 free (input_debug
.external_opt
);
3588 free (input_debug
.external_aux
);
3589 free (input_debug
.ss
);
3590 free (input_debug
.ssext
);
3591 free (input_debug
.external_fdr
);
3592 free (input_debug
.external_rfd
);
3593 free (input_debug
.external_ext
);
3595 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3596 elf_link_input_bfd ignores this section. */
3597 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3600 if (SGI_COMPAT (abfd
) && info
->shared
)
3602 /* Create .rtproc section. */
3603 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3604 if (rtproc_sec
== NULL
)
3606 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3609 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
3610 if (rtproc_sec
== NULL
3611 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
3612 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
3616 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
3617 info
, rtproc_sec
, &debug
))
3621 /* Build the external symbol information. */
3624 einfo
.debug
= &debug
;
3626 einfo
.failed
= false;
3627 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
3628 mips_elf_output_extsym
,
3633 /* Set the size of the .mdebug section. */
3634 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
3636 /* Skip this section later on (I don't think this currently
3637 matters, but someday it might). */
3638 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3643 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3645 const char *subname
;
3648 Elf32_External_gptab
*ext_tab
;
3651 /* The .gptab.sdata and .gptab.sbss sections hold
3652 information describing how the small data area would
3653 change depending upon the -G switch. These sections
3654 not used in executables files. */
3655 if (! info
->relocateable
)
3659 for (p
= o
->link_order_head
;
3660 p
!= (struct bfd_link_order
*) NULL
;
3663 asection
*input_section
;
3665 if (p
->type
!= bfd_indirect_link_order
)
3667 if (p
->type
== bfd_fill_link_order
)
3672 input_section
= p
->u
.indirect
.section
;
3674 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3675 elf_link_input_bfd ignores this section. */
3676 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3679 /* Skip this section later on (I don't think this
3680 currently matters, but someday it might). */
3681 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3683 /* Really remove the section. */
3684 for (secpp
= &abfd
->sections
;
3686 secpp
= &(*secpp
)->next
)
3688 *secpp
= (*secpp
)->next
;
3689 --abfd
->section_count
;
3694 /* There is one gptab for initialized data, and one for
3695 uninitialized data. */
3696 if (strcmp (o
->name
, ".gptab.sdata") == 0)
3698 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
3702 (*_bfd_error_handler
)
3703 ("%s: illegal section name `%s'",
3704 bfd_get_filename (abfd
), o
->name
);
3705 bfd_set_error (bfd_error_nonrepresentable_section
);
3709 /* The linker script always combines .gptab.data and
3710 .gptab.sdata into .gptab.sdata, and likewise for
3711 .gptab.bss and .gptab.sbss. It is possible that there is
3712 no .sdata or .sbss section in the output file, in which
3713 case we must change the name of the output section. */
3714 subname
= o
->name
+ sizeof ".gptab" - 1;
3715 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
3717 if (o
== gptab_data_sec
)
3718 o
->name
= ".gptab.data";
3720 o
->name
= ".gptab.bss";
3721 subname
= o
->name
+ sizeof ".gptab" - 1;
3722 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
3725 /* Set up the first entry. */
3727 tab
= (Elf32_gptab
*) bfd_malloc (c
* sizeof (Elf32_gptab
));
3730 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
3731 tab
[0].gt_header
.gt_unused
= 0;
3733 /* Combine the input sections. */
3734 for (p
= o
->link_order_head
;
3735 p
!= (struct bfd_link_order
*) NULL
;
3738 asection
*input_section
;
3742 bfd_size_type gpentry
;
3744 if (p
->type
!= bfd_indirect_link_order
)
3746 if (p
->type
== bfd_fill_link_order
)
3751 input_section
= p
->u
.indirect
.section
;
3752 input_bfd
= input_section
->owner
;
3754 /* Combine the gptab entries for this input section one
3755 by one. We know that the input gptab entries are
3756 sorted by ascending -G value. */
3757 size
= bfd_section_size (input_bfd
, input_section
);
3759 for (gpentry
= sizeof (Elf32_External_gptab
);
3761 gpentry
+= sizeof (Elf32_External_gptab
))
3763 Elf32_External_gptab ext_gptab
;
3764 Elf32_gptab int_gptab
;
3770 if (! (bfd_get_section_contents
3771 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
3772 gpentry
, sizeof (Elf32_External_gptab
))))
3778 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
3780 val
= int_gptab
.gt_entry
.gt_g_value
;
3781 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
3784 for (look
= 1; look
< c
; look
++)
3786 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
3787 tab
[look
].gt_entry
.gt_bytes
+= add
;
3789 if (tab
[look
].gt_entry
.gt_g_value
== val
)
3795 Elf32_gptab
*new_tab
;
3798 /* We need a new table entry. */
3799 new_tab
= ((Elf32_gptab
*)
3800 bfd_realloc ((PTR
) tab
,
3801 (c
+ 1) * sizeof (Elf32_gptab
)));
3802 if (new_tab
== NULL
)
3808 tab
[c
].gt_entry
.gt_g_value
= val
;
3809 tab
[c
].gt_entry
.gt_bytes
= add
;
3811 /* Merge in the size for the next smallest -G
3812 value, since that will be implied by this new
3815 for (look
= 1; look
< c
; look
++)
3817 if (tab
[look
].gt_entry
.gt_g_value
< val
3819 || (tab
[look
].gt_entry
.gt_g_value
3820 > tab
[max
].gt_entry
.gt_g_value
)))
3824 tab
[c
].gt_entry
.gt_bytes
+=
3825 tab
[max
].gt_entry
.gt_bytes
;
3830 last
= int_gptab
.gt_entry
.gt_bytes
;
3833 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3834 elf_link_input_bfd ignores this section. */
3835 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3838 /* The table must be sorted by -G value. */
3840 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
3842 /* Swap out the table. */
3843 ext_tab
= ((Elf32_External_gptab
*)
3844 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
3845 if (ext_tab
== NULL
)
3851 for (i
= 0; i
< c
; i
++)
3852 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
3855 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
3856 o
->contents
= (bfd_byte
*) ext_tab
;
3858 /* Skip this section later on (I don't think this currently
3859 matters, but someday it might). */
3860 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3864 /* Invoke the regular ELF backend linker to do all the work. */
3865 if (! bfd_elf32_bfd_final_link (abfd
, info
))
3868 /* Now write out the computed sections. */
3870 if (reginfo_sec
!= (asection
*) NULL
)
3872 Elf32_External_RegInfo ext
;
3874 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
3875 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
3876 (file_ptr
) 0, sizeof ext
))
3880 if (mdebug_sec
!= (asection
*) NULL
)
3882 BFD_ASSERT (abfd
->output_has_begun
);
3883 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
3885 mdebug_sec
->filepos
))
3888 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
3891 if (gptab_data_sec
!= (asection
*) NULL
)
3893 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
3894 gptab_data_sec
->contents
,
3896 gptab_data_sec
->_raw_size
))
3900 if (gptab_bss_sec
!= (asection
*) NULL
)
3902 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
3903 gptab_bss_sec
->contents
,
3905 gptab_bss_sec
->_raw_size
))
3909 if (SGI_COMPAT (abfd
))
3911 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3912 if (rtproc_sec
!= NULL
)
3914 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
3915 rtproc_sec
->contents
,
3917 rtproc_sec
->_raw_size
))
3925 /* Handle a MIPS ELF HI16 reloc. */
3928 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
3930 Elf_Internal_Rela
*relhi
;
3931 Elf_Internal_Rela
*rello
;
3938 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
3940 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
3943 addend
+= ((insn
& 0xffff) << 16) + addlo
;
3945 if ((addlo
& 0x8000) != 0)
3947 if ((addend
& 0x8000) != 0)
3950 bfd_put_32 (input_bfd
,
3951 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
3952 contents
+ relhi
->r_offset
);
3955 /* Handle a MIPS ELF local GOT16 reloc. */
3958 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
, relhi
, rello
,
3963 Elf_Internal_Rela
*relhi
;
3964 Elf_Internal_Rela
*rello
;
3974 bfd_byte
*got_contents
;
3975 struct mips_got_info
*g
;
3977 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
3979 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
3982 addend
+= ((insn
& 0xffff) << 16) + addlo
;
3984 if ((addlo
& 0x8000) != 0)
3986 if ((addend
& 0x8000) != 0)
3989 /* Get a got entry representing requested hipage. */
3990 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
3991 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
3992 BFD_ASSERT (g
!= NULL
);
3994 local_gotno
= g
->local_gotno
;
3995 got_contents
= sgot
->contents
;
3996 hipage
= addend
& 0xffff0000;
3998 for (i
= MIPS_RESERVED_GOTNO
; i
< local_gotno
; i
++)
4000 address
= bfd_get_32 (input_bfd
, got_contents
+ i
* 4);
4001 if (hipage
== (address
& 0xffff0000))
4003 if (address
== (bfd_vma
) 0)
4005 bfd_put_32 (input_bfd
, hipage
, got_contents
+ i
* 4);
4010 BFD_ASSERT (i
< local_gotno
);
4012 if (i
== local_gotno
)
4013 (*_bfd_error_handler
)
4014 ("ELF MIPS linker: more got entries are needed for hipage: %x",
4018 i
= - ELF_MIPS_GP_OFFSET (output_bfd
) + i
* 4;
4019 bfd_put_32 (input_bfd
, (insn
& 0xffff0000) | (i
& 0xffff),
4020 contents
+ relhi
->r_offset
);
4023 /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */
4026 mips_elf_relocate_global_got (input_bfd
, rel
, contents
, offset
)
4028 Elf_Internal_Rela
*rel
;
4034 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4035 bfd_put_32 (input_bfd
,
4036 (insn
& 0xffff0000) | (offset
& 0xffff),
4037 contents
+ rel
->r_offset
);
4040 /* Relocate a MIPS ELF section. */
4043 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4044 contents
, relocs
, local_syms
, local_sections
)
4046 struct bfd_link_info
*info
;
4048 asection
*input_section
;
4050 Elf_Internal_Rela
*relocs
;
4051 Elf_Internal_Sym
*local_syms
;
4052 asection
**local_sections
;
4054 Elf_Internal_Shdr
*symtab_hdr
;
4057 asection
*sgot
, *sreloc
, *scpt
;
4060 Elf_Internal_Rela
*rel
;
4061 Elf_Internal_Rela
*relend
;
4062 struct mips_got_info
*g
;
4064 dynobj
= elf_hash_table (info
)->dynobj
;
4065 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4069 if (dynobj
== NULL
|| ! SGI_COMPAT (output_bfd
))
4072 scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
4075 if (elf_bad_symtab (input_bfd
))
4077 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4082 locsymcount
= symtab_hdr
->sh_info
;
4083 extsymoff
= symtab_hdr
->sh_info
;
4086 gp
= _bfd_get_gp_value (output_bfd
);
4089 relend
= relocs
+ input_section
->reloc_count
;
4090 for (; rel
< relend
; rel
++)
4093 reloc_howto_type
*howto
;
4094 unsigned long r_symndx
;
4096 struct elf_link_hash_entry
*h
;
4098 Elf_Internal_Sym
*sym
;
4099 bfd_reloc_status_type r
;
4101 r_type
= ELF32_R_TYPE (rel
->r_info
);
4102 if (r_type
< 0 || r_type
>= (int) R_MIPS_max
)
4104 bfd_set_error (bfd_error_bad_value
);
4107 howto
= elf_mips_howto_table
+ r_type
;
4110 && (r_type
== R_MIPS_CALL16
4111 || r_type
== R_MIPS_GOT16
4112 || r_type
== R_MIPS_CALL_HI16
4113 || r_type
== R_MIPS_CALL_LO16
4114 || r_type
== R_MIPS_GOT_HI16
4115 || r_type
== R_MIPS_GOT_LO16
))
4117 /* We need the .got section. */
4120 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4121 BFD_ASSERT (sgot
!= NULL
);
4122 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4123 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4124 BFD_ASSERT (g
!= NULL
);
4128 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4130 /* Mix in the change in GP address for a GP relative reloc. */
4131 if (r_type
!= R_MIPS_GPREL16
4132 && r_type
!= R_MIPS_LITERAL
4133 && r_type
!= R_MIPS_GPREL32
)
4139 if (! ((*info
->callbacks
->reloc_dangerous
)
4141 "GP relative relocation when GP not defined",
4142 input_bfd
, input_section
,
4145 /* Only give the error once per link. */
4147 _bfd_set_gp_value (output_bfd
, gp
);
4150 if (r_symndx
< extsymoff
4151 || (elf_bad_symtab (input_bfd
)
4152 && local_sections
[r_symndx
] != NULL
))
4154 /* This is a relocation against a section. The current
4155 addend in the instruction is the difference between
4156 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
4157 must change this to be the difference between the
4158 final definition (which will end up in RELOCATION)
4159 and the GP value of OUTPUT_BFD (which is in GP). */
4160 addend
= elf_gp (input_bfd
) - gp
;
4162 else if (! info
->relocateable
)
4164 /* We are doing a final link. The current addend in the
4165 instruction is simply the desired offset into the
4166 symbol (normally zero). We want the instruction to
4167 hold the difference between the final definition of
4168 the symbol (which will end up in RELOCATION) and the
4169 GP value of OUTPUT_BFD (which is in GP). */
4174 /* We are generating relocateable output, and we aren't
4175 going to define this symbol, so we just leave the
4176 instruction alone. */
4184 if (info
->relocateable
)
4186 /* This is a relocateable link. We don't have to change
4187 anything, unless the reloc is against a section symbol,
4188 in which case we have to adjust according to where the
4189 section symbol winds up in the output section. */
4190 if (r_symndx
>= locsymcount
4191 || (elf_bad_symtab (input_bfd
)
4192 && local_sections
[r_symndx
] == NULL
))
4196 sym
= local_syms
+ r_symndx
;
4197 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4201 sec
= local_sections
[r_symndx
];
4203 /* It would be logical to add sym->st_value here,
4204 but Irix 5 sometimes generates a garbage symbol
4206 addend
+= sec
->output_offset
;
4208 /* If this is HI16 or GOT16 with an associated LO16,
4209 adjust the addend accordingly. Otherwise, just
4211 if (r_type
!= R_MIPS_HI16
&& r_type
!= R_MIPS_GOT16
)
4212 r
= _bfd_relocate_contents (howto
, input_bfd
,
4214 contents
+ rel
->r_offset
);
4217 Elf_Internal_Rela
*lorel
;
4219 /* As a GNU extension, permit an arbitrary
4220 number of R_MIPS_HI16 relocs before the
4221 R_MIPS_LO16 reloc. This permits gcc to emit
4222 the HI and LO relocs itself. */
4223 if (r_type
== R_MIPS_GOT16
)
4227 for (lorel
= rel
+ 1;
4229 && (ELF32_R_TYPE (lorel
->r_info
)
4235 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4237 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4242 r
= _bfd_relocate_contents (howto
, input_bfd
,
4244 contents
+ rel
->r_offset
);
4254 /* This is a final link. */
4256 if (r_symndx
< extsymoff
4257 || (elf_bad_symtab (input_bfd
)
4258 && local_sections
[r_symndx
] != NULL
))
4261 sym
= local_syms
+ r_symndx
;
4262 sec
= local_sections
[r_symndx
];
4263 relocation
= (sec
->output_section
->vma
4264 + sec
->output_offset
);
4266 /* It would be logical to always add sym->st_value here,
4267 but Irix 5 sometimes generates a garbage symbol
4269 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4270 relocation
+= sym
->st_value
;
4277 indx
= r_symndx
- extsymoff
;
4278 h
= elf_sym_hashes (input_bfd
)[indx
];
4279 while (h
->root
.type
== bfd_link_hash_indirect
4280 || h
->root
.type
== bfd_link_hash_warning
)
4281 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4282 if (strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
4286 if (! ((*info
->callbacks
->reloc_dangerous
)
4288 "_gp_disp used when GP not defined",
4289 input_bfd
, input_section
,
4292 /* Only give the error once per link. */
4294 _bfd_set_gp_value (output_bfd
, gp
);
4299 sec
= input_section
;
4300 if (sec
->output_section
!= NULL
)
4303 + sec
->output_section
->vma
4304 + sec
->output_offset
));
4306 relocation
= gp
- rel
->r_offset
;
4307 if (r_type
== R_MIPS_LO16
)
4311 else if (h
->root
.type
== bfd_link_hash_defined
4312 || h
->root
.type
== bfd_link_hash_defweak
)
4314 sec
= h
->root
.u
.def
.section
;
4315 if (sec
->output_section
== NULL
)
4318 relocation
= (h
->root
.u
.def
.value
4319 + sec
->output_section
->vma
4320 + sec
->output_offset
);
4322 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4324 else if (info
->shared
&& ! info
->symbolic
)
4326 else if (strcmp (h
->root
.root
.string
, "_DYNAMIC_LINK") == 0)
4328 /* If this is a dynamic link, we should have created
4329 a _DYNAMIC_LINK symbol in
4330 mips_elf_create_dynamic_sections. Otherwise, we
4331 should define the symbol with a value of 0.
4332 FIXME: It should probably get into the symbol
4333 table somehow as well. */
4334 BFD_ASSERT (! info
->shared
);
4335 BFD_ASSERT (bfd_get_section_by_name (output_bfd
,
4336 ".dynamic") == NULL
);
4341 if (! ((*info
->callbacks
->undefined_symbol
)
4342 (info
, h
->root
.root
.string
, input_bfd
,
4343 input_section
, rel
->r_offset
)))
4349 if (r_type
== R_MIPS_HI16
)
4351 Elf_Internal_Rela
*lorel
;
4353 /* As a GNU extension, permit an arbitrary number of
4354 R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc.
4355 This permits gcc to emit the HI and LO relocs itself. */
4356 for (lorel
= rel
+ 1;
4358 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_HI16
);
4362 && ELF32_R_TYPE (lorel
->r_info
) == R_MIPS_LO16
)
4364 mips_elf_relocate_hi16 (input_bfd
, rel
, lorel
,
4365 contents
, relocation
+ addend
);
4369 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4370 contents
, rel
->r_offset
,
4371 relocation
, addend
);
4373 else if (r_type
== R_MIPS_GOT16
&& local
)
4375 /* GOT16 must also have an associated LO16 in the local
4376 case. In this case, the addend is extracted and the
4377 section in which the referenced object is determined.
4378 Then the final address of the object is computed and
4379 the GOT entry for the hipage (an aligned 64kb chunk)
4380 is added to .got section if needed. The offset field
4381 of the GOT16-relocated instruction is replaced by the
4382 index of this GOT entry for the hipage. */
4383 if ((rel
+ 1) < relend
4384 && ELF32_R_TYPE ((rel
+ 1)->r_info
) == R_MIPS_LO16
)
4386 mips_elf_relocate_got_local (output_bfd
, input_bfd
, sgot
,
4389 relocation
+ addend
);
4393 r
= bfd_reloc_outofrange
;
4395 else if (r_type
== R_MIPS_CALL16
4396 || r_type
== R_MIPS_GOT16
4397 || r_type
== R_MIPS_CALL_LO16
4398 || r_type
== R_MIPS_GOT_LO16
)
4402 /* This symbol must be registered as a global symbol
4403 having the corresponding got entry. */
4404 BFD_ASSERT (h
->got_offset
!= (bfd_vma
) -1);
4406 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4407 BFD_ASSERT (g
->local_gotno
<= offset
4408 && offset
< sgot
->_raw_size
);
4409 bfd_put_32 (output_bfd
, relocation
+ addend
,
4410 sgot
->contents
+ offset
);
4411 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4413 mips_elf_relocate_global_got (input_bfd
, rel
, contents
,
4417 else if (r_type
== R_MIPS_CALL_HI16
4418 || r_type
== R_MIPS_GOT_HI16
)
4422 /* This must be a global symbol with a got entry. The
4423 next reloc must be the corresponding LO16 reloc. */
4424 BFD_ASSERT (h
!= NULL
&& h
->got_offset
!= (bfd_vma
) -1);
4425 BFD_ASSERT ((rel
+ 1) < relend
);
4426 BFD_ASSERT (ELF32_R_TYPE ((rel
+ 1)->r_info
)
4427 == (r_type
== R_MIPS_CALL_HI16
4429 : R_MIPS_GOT_LO16
));
4431 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
4432 BFD_ASSERT (g
->local_gotno
<= offset
4433 && offset
< sgot
->_raw_size
);
4434 bfd_put_32 (output_bfd
, relocation
+ addend
,
4435 sgot
->contents
+ offset
);
4436 offset
= (sgot
->output_section
->vma
+ sgot
->output_offset
4438 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1, contents
,
4442 else if (r_type
== R_MIPS_REL32
4443 || r_type
== R_MIPS_32
)
4445 Elf_Internal_Rel outrel
;
4446 Elf32_crinfo cptrel
;
4450 || (elf_hash_table (info
)->dynamic_sections_created
4452 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
4454 && (input_section
->flags
& SEC_ALLOC
) != 0)
4456 /* When generating a shared object, these
4457 relocations are copied into the output file to be
4458 resolved at run time. */
4461 sreloc
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
4462 BFD_ASSERT (sreloc
!= NULL
);
4465 outrel
.r_offset
= (rel
->r_offset
4466 + input_section
->output_section
->vma
4467 + input_section
->output_offset
);
4469 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4472 && (! info
->symbolic
4473 || (h
->elf_link_hash_flags
4474 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4476 BFD_ASSERT (h
->dynindx
!= -1);
4477 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_REL32
);
4478 sec
= input_section
;
4485 sec
= local_sections
[r_symndx
];
4488 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
4490 == bfd_link_hash_defweak
));
4491 sec
= h
->root
.u
.def
.section
;
4493 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
4495 else if (sec
== NULL
|| sec
->owner
== NULL
)
4497 bfd_set_error (bfd_error_bad_value
);
4504 osec
= sec
->output_section
;
4505 indx
= elf_section_data (osec
)->dynindx
;
4510 outrel
.r_info
= ELF32_R_INFO (indx
, R_MIPS_REL32
);
4511 addend
+= relocation
;
4514 bfd_put_32 (output_bfd
, addend
, contents
+ rel
->r_offset
);
4515 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
4516 (((Elf32_External_Rel
*)
4518 + sreloc
->reloc_count
));
4519 ++sreloc
->reloc_count
;
4521 if (SGI_COMPAT (output_bfd
))
4526 /* Make an entry of compact relocation info. */
4527 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4528 cptrel
.vaddr
= (rel
->r_offset
4529 + input_section
->output_section
->vma
4530 + input_section
->output_offset
);
4531 if (r_type
== R_MIPS_REL32
)
4532 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
4534 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
4535 mips_elf_set_cr_dist2to (cptrel
, 0);
4536 cptrel
.konst
= addend
;
4538 cr
= (scpt
->contents
4539 + sizeof (Elf32_External_compact_rel
));
4540 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4541 ((Elf32_External_crinfo
*) cr
4542 + scpt
->reloc_count
));
4543 ++scpt
->reloc_count
;
4546 /* This reloc will be computed at runtime, so
4547 there's no need to do anything now. */
4551 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4552 contents
, rel
->r_offset
,
4553 relocation
, addend
);
4556 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4557 contents
, rel
->r_offset
,
4558 relocation
, addend
);
4560 if (SGI_COMPAT (abfd
)
4562 && (input_section
->flags
& SEC_ALLOC
) != 0)
4564 Elf32_crinfo cptrel
;
4567 /* Make an entry of compact relocation info. */
4568 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
4569 cptrel
.vaddr
= (rel
->r_offset
4570 + input_section
->output_section
->vma
4571 + input_section
->output_offset
);
4576 mips_elf_set_cr_type (cptrel
, CRT_MIPS_JMPAD
);
4577 /* XXX How should we set dist2to in this case. */
4578 mips_elf_set_cr_dist2to (cptrel
, 8);
4579 cptrel
.konst
= addend
+ relocation
;
4580 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4581 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4582 ((Elf32_External_crinfo
*) cr
4583 + scpt
->reloc_count
));
4584 ++scpt
->reloc_count
;
4587 case R_MIPS_GPREL16
:
4588 case R_MIPS_LITERAL
:
4589 case R_MIPS_GPREL32
:
4590 mips_elf_set_cr_type (cptrel
, CRT_MIPS_GPHI_LO
);
4591 cptrel
.konst
= gp
- cptrel
.vaddr
;
4592 mips_elf_set_cr_dist2to (cptrel
, 4);
4593 cr
= scpt
->contents
+ sizeof (Elf32_External_compact_rel
);
4594 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
4595 ((Elf32_External_crinfo
*) cr
4596 + scpt
->reloc_count
));
4597 ++scpt
->reloc_count
;
4606 if (r
!= bfd_reloc_ok
)
4611 case bfd_reloc_outofrange
:
4613 case bfd_reloc_overflow
:
4618 name
= h
->root
.root
.string
;
4621 name
= bfd_elf_string_from_elf_section (input_bfd
,
4622 symtab_hdr
->sh_link
,
4627 name
= bfd_section_name (input_bfd
, sec
);
4629 if (! ((*info
->callbacks
->reloc_overflow
)
4630 (info
, name
, howto
->name
, (bfd_vma
) 0,
4631 input_bfd
, input_section
, rel
->r_offset
)))
4642 /* Functions for the dynamic linker. */
4644 /* The name of the dynamic interpreter. This is put in the .interp
4647 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
4649 /* Create dynamic sections when linking against a dynamic object. */
4652 mips_elf_create_dynamic_sections (abfd
, info
)
4654 struct bfd_link_info
*info
;
4656 struct elf_link_hash_entry
*h
;
4658 register asection
*s
;
4659 const char * const *namep
;
4661 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4664 /* Mips ABI requests the .dynamic section to be read only. */
4665 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4668 if (! bfd_set_section_flags (abfd
, s
, flags
))
4672 /* We need to create .got section. */
4673 if (! mips_elf_create_got_section (abfd
, info
))
4676 /* Create .stub section. */
4677 if (bfd_get_section_by_name (abfd
, ".stub") == NULL
)
4679 s
= bfd_make_section (abfd
, ".stub");
4681 || ! bfd_set_section_flags (abfd
, s
, flags
)
4682 || ! bfd_set_section_alignment (abfd
, s
, 2))
4686 if (SGI_COMPAT (abfd
)
4688 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
4690 s
= bfd_make_section (abfd
, ".rld_map");
4692 || ! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_READONLY
)
4693 || ! bfd_set_section_alignment (abfd
, s
, 2))
4697 if (SGI_COMPAT (abfd
))
4699 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
4702 if (! (_bfd_generic_link_add_one_symbol
4703 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
,
4704 (bfd_vma
) 0, (const char *) NULL
, false,
4705 get_elf_backend_data (abfd
)->collect
,
4706 (struct bfd_link_hash_entry
**) &h
)))
4708 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4709 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4710 h
->type
= STT_SECTION
;
4712 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4716 /* We need to create a .compact_rel section. */
4717 if (! mips_elf_create_compact_rel_section (abfd
, info
))
4720 /* Change aligments of some sections. */
4721 s
= bfd_get_section_by_name (abfd
, ".hash");
4723 bfd_set_section_alignment (abfd
, s
, 4);
4724 s
= bfd_get_section_by_name (abfd
, ".dynsym");
4726 bfd_set_section_alignment (abfd
, s
, 4);
4727 s
= bfd_get_section_by_name (abfd
, ".dynstr");
4729 bfd_set_section_alignment (abfd
, s
, 4);
4730 s
= bfd_get_section_by_name (abfd
, ".reginfo");
4732 bfd_set_section_alignment (abfd
, s
, 4);
4733 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4735 bfd_set_section_alignment (abfd
, s
, 4);
4741 if (! (_bfd_generic_link_add_one_symbol
4742 (info
, abfd
, "_DYNAMIC_LINK", BSF_GLOBAL
, bfd_abs_section_ptr
,
4743 (bfd_vma
) 0, (const char *) NULL
, false,
4744 get_elf_backend_data (abfd
)->collect
,
4745 (struct bfd_link_hash_entry
**) &h
)))
4747 h
->elf_link_hash_flags
^=~ ELF_LINK_NON_ELF
;
4748 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4749 h
->type
= STT_SECTION
;
4751 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4754 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
4756 /* __rld_map is a four byte word located in the .data section
4757 and is filled in by the rtld to contain a pointer to
4758 the _r_debug structure. Its symbol value will be set in
4759 mips_elf_finish_dynamic_symbol. */
4760 s
= bfd_get_section_by_name (abfd
, ".rld_map");
4761 BFD_ASSERT (s
!= NULL
);
4764 if (! (_bfd_generic_link_add_one_symbol
4765 (info
, abfd
, "__rld_map", BSF_GLOBAL
, s
,
4766 (bfd_vma
) 0, (const char *) NULL
, false,
4767 get_elf_backend_data (abfd
)->collect
,
4768 (struct bfd_link_hash_entry
**) &h
)))
4770 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4771 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4772 h
->type
= STT_OBJECT
;
4774 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4782 /* Create the .compact_rel section. */
4785 mips_elf_create_compact_rel_section (abfd
, info
)
4787 struct bfd_link_info
*info
;
4790 register asection
*s
;
4792 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4794 flags
= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_READONLY
;
4796 s
= bfd_make_section (abfd
, ".compact_rel");
4798 || ! bfd_set_section_flags (abfd
, s
, flags
)
4799 || ! bfd_set_section_alignment (abfd
, s
, 2))
4802 s
->_raw_size
= sizeof (Elf32_External_compact_rel
);
4808 /* Create the .got section to hold the global offset table. */
4811 mips_elf_create_got_section (abfd
, info
)
4813 struct bfd_link_info
*info
;
4816 register asection
*s
;
4817 struct elf_link_hash_entry
*h
;
4818 struct mips_got_info
*g
;
4820 /* This function may be called more than once. */
4821 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
4824 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
4826 s
= bfd_make_section (abfd
, ".got");
4828 || ! bfd_set_section_flags (abfd
, s
, flags
)
4829 || ! bfd_set_section_alignment (abfd
, s
, 4))
4832 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4833 linker script because we don't want to define the symbol if we
4834 are not creating a global offset table. */
4836 if (! (_bfd_generic_link_add_one_symbol
4837 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4838 (bfd_vma
) 0, (const char *) NULL
, false,
4839 get_elf_backend_data (abfd
)->collect
,
4840 (struct bfd_link_hash_entry
**) &h
)))
4842 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
4843 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4844 h
->type
= STT_OBJECT
;
4847 && ! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4850 /* The first several global offset table entries are reserved. */
4851 s
->_raw_size
= MIPS_RESERVED_GOTNO
* 4;
4853 g
= (struct mips_got_info
*) bfd_alloc (abfd
,
4854 sizeof (struct mips_got_info
));
4857 g
->global_gotsym
= 0;
4858 g
->local_gotno
= MIPS_RESERVED_GOTNO
;
4859 if (elf_section_data (s
) == NULL
)
4862 (PTR
) bfd_zalloc (abfd
, sizeof (struct bfd_elf_section_data
));
4863 if (elf_section_data (s
) == NULL
)
4866 elf_section_data (s
)->tdata
= (PTR
) g
;
4871 /* Look through the relocs for a section during the first phase, and
4872 allocate space in the global offset table. */
4875 mips_elf_check_relocs (abfd
, info
, sec
, relocs
)
4877 struct bfd_link_info
*info
;
4879 const Elf_Internal_Rela
*relocs
;
4882 Elf_Internal_Shdr
*symtab_hdr
;
4883 struct elf_link_hash_entry
**sym_hashes
;
4884 struct mips_got_info
*g
;
4886 const Elf_Internal_Rela
*rel
;
4887 const Elf_Internal_Rela
*rel_end
;
4891 if (info
->relocateable
)
4894 dynobj
= elf_hash_table (info
)->dynobj
;
4895 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4896 sym_hashes
= elf_sym_hashes (abfd
);
4897 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
4902 rel_end
= relocs
+ sec
->reloc_count
;
4903 for (rel
= relocs
; rel
< rel_end
; rel
++)
4905 unsigned long r_symndx
;
4906 struct elf_link_hash_entry
*h
;
4908 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4910 if (r_symndx
< extsymoff
)
4913 h
= sym_hashes
[r_symndx
- extsymoff
];
4915 /* Some relocs require a global offset table. */
4918 switch (ELF32_R_TYPE (rel
->r_info
))
4922 case R_MIPS_CALL_HI16
:
4923 case R_MIPS_CALL_LO16
:
4924 case R_MIPS_GOT_HI16
:
4925 case R_MIPS_GOT_LO16
:
4926 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
4927 if (! mips_elf_create_got_section (dynobj
, info
))
4936 switch (ELF32_R_TYPE (rel
->r_info
))
4939 case R_MIPS_CALL_HI16
:
4940 case R_MIPS_CALL_LO16
:
4941 /* This symbol requires a global offset table entry. */
4944 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4945 BFD_ASSERT (sgot
!= NULL
);
4946 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4947 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4948 BFD_ASSERT (g
!= NULL
);
4951 BFD_ASSERT (h
!= NULL
);
4953 /* Make sure this symbol is output as a dynamic symbol. */
4954 if (h
->dynindx
== -1)
4956 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4960 if (h
->got_offset
!= (bfd_vma
) -1)
4962 /* We have already allocated space in the .got. */
4966 /* Note the index of the first global got symbol in .dynsym. */
4967 if (g
->global_gotsym
== 0
4968 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
4969 g
->global_gotsym
= h
->dynindx
;
4971 /* Make this symbol to have the corresponding got entry. */
4974 /* We need a stub, not a plt entry for the undefined
4975 function. But we record it as if it needs plt. See
4976 elf_adjust_dynamic_symbol in elflink.h. */
4977 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4983 case R_MIPS_GOT_HI16
:
4984 case R_MIPS_GOT_LO16
:
4985 /* This symbol requires a global offset table entry. */
4988 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4989 BFD_ASSERT (sgot
!= NULL
);
4990 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
4991 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
4992 BFD_ASSERT (g
!= NULL
);
4997 /* Make sure this symbol is output as a dynamic symbol. */
4998 if (h
->dynindx
== -1)
5000 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5004 if (h
->got_offset
!= (bfd_vma
) -1)
5006 /* We have already allocated space in the .got. */
5009 /* Note the index of the first global got symbol in
5011 if (g
->global_gotsym
== 0
5012 || g
->global_gotsym
> (unsigned long) h
->dynindx
)
5013 g
->global_gotsym
= h
->dynindx
;
5015 /* Make this symbol to be the global got symbol. */
5023 if ((info
->shared
|| h
!= NULL
)
5024 && (sec
->flags
& SEC_ALLOC
) != 0)
5028 /* When creating a shared object, we must copy these
5029 reloc types into the output file as R_MIPS_REL32
5030 relocs. We create the .rel.dyn reloc section in
5031 dynobj and make room for this reloc. */
5034 const char *name
= ".rel.dyn";
5036 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5039 sreloc
= bfd_make_section (dynobj
, name
);
5041 || ! bfd_set_section_flags (dynobj
, sreloc
,
5047 || ! bfd_set_section_alignment (dynobj
, sreloc
,
5051 /* Add a null element. */
5052 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
5053 ++sreloc
->reloc_count
;
5057 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
5061 struct mips_elf_link_hash_entry
*hmips
;
5063 /* We only need to copy this reloc if the symbol is
5064 defined in a dynamic object. */
5065 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5066 ++hmips
->mips_32_relocs
;
5070 if (SGI_COMPAT (abfd
))
5071 mips_elf_hash_table (info
)->compact_rel_size
+=
5072 sizeof (Elf32_External_crinfo
);
5077 case R_MIPS_GPREL16
:
5078 case R_MIPS_LITERAL
:
5079 case R_MIPS_GPREL32
:
5080 if (SGI_COMPAT (abfd
))
5081 mips_elf_hash_table (info
)->compact_rel_size
+=
5082 sizeof (Elf32_External_crinfo
);
5093 /* Adjust a symbol defined by a dynamic object and referenced by a
5094 regular object. The current definition is in some section of the
5095 dynamic object, but we're not including those sections. We have to
5096 change the definition to something the rest of the link can
5100 mips_elf_adjust_dynamic_symbol (info
, h
)
5101 struct bfd_link_info
*info
;
5102 struct elf_link_hash_entry
*h
;
5105 struct mips_elf_link_hash_entry
*hmips
;
5108 dynobj
= elf_hash_table (info
)->dynobj
;
5110 /* Make sure we know what is going on here. */
5111 BFD_ASSERT (dynobj
!= NULL
5112 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
5113 || h
->weakdef
!= NULL
5114 || ((h
->elf_link_hash_flags
5115 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5116 && (h
->elf_link_hash_flags
5117 & ELF_LINK_HASH_REF_REGULAR
) != 0
5118 && (h
->elf_link_hash_flags
5119 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
5121 /* If this symbol is defined in a dynamic object, we need to copy
5122 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output
5124 hmips
= (struct mips_elf_link_hash_entry
*) h
;
5125 if (! info
->relocateable
5126 && hmips
->mips_32_relocs
!= 0
5127 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5129 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5130 BFD_ASSERT (s
!= NULL
);
5132 s
->_raw_size
+= hmips
->mips_32_relocs
* sizeof (Elf32_External_Rel
);
5135 /* For a function, create a stub, if needed. */
5136 if (h
->type
== STT_FUNC
5137 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
5139 if (! elf_hash_table (info
)->dynamic_sections_created
)
5142 /* If this symbol is not defined in a regular file, then set
5143 the symbol to the stub location. This is required to make
5144 function pointers compare as equal between the normal
5145 executable and the shared library. */
5146 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5148 /* We need .stub section. */
5149 s
= bfd_get_section_by_name (dynobj
, ".stub");
5150 BFD_ASSERT (s
!= NULL
);
5152 h
->root
.u
.def
.section
= s
;
5153 h
->root
.u
.def
.value
= s
->_raw_size
;
5155 /* XXX Write this stub address somewhere. */
5156 h
->plt_offset
= s
->_raw_size
;
5158 /* Make room for this stub code. */
5159 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5161 /* The last half word of the stub will be filled with the index
5162 of this symbol in .dynsym section. */
5167 /* If this is a weak symbol, and there is a real definition, the
5168 processor independent code will have arranged for us to see the
5169 real definition first, and we can just use the same value. */
5170 if (h
->weakdef
!= NULL
)
5172 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
5173 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
5174 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
5175 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
5179 /* This is a reference to a symbol defined by a dynamic object which
5180 is not a function. */
5185 /* Set the sizes of the dynamic sections. */
5188 mips_elf_size_dynamic_sections (output_bfd
, info
)
5190 struct bfd_link_info
*info
;
5196 struct mips_got_info
*g
;
5198 dynobj
= elf_hash_table (info
)->dynobj
;
5199 BFD_ASSERT (dynobj
!= NULL
);
5201 if (elf_hash_table (info
)->dynamic_sections_created
)
5203 /* Set the contents of the .interp section to the interpreter. */
5206 s
= bfd_get_section_by_name (dynobj
, ".interp");
5207 BFD_ASSERT (s
!= NULL
);
5208 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5209 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5213 /* Recompute the size of .got for local entires (reserved and
5214 hipages) if needed. To estimate it, get the upper bound of total
5215 size of loadable sections. */
5216 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5220 bfd_size_type loadable_size
= 0;
5221 bfd_size_type local_gotno
;
5224 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5225 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5226 BFD_ASSERT (g
!= NULL
);
5228 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
5229 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
5231 if ((s
->flags
& SEC_ALLOC
) == 0)
5233 loadable_size
+= (s
->_raw_size
+ 0xf) & ~0xf;
5236 loadable_size
+= MIPS_FUNCTION_STUB_SIZE
;
5238 /* Assume there are two loadable segments consisting of
5239 contiguous sections. Is 5 enough? */
5240 local_gotno
= (loadable_size
>> 16) + 5 + MIPS_RESERVED_GOTNO
;
5241 g
->local_gotno
= local_gotno
;
5242 sgot
->_raw_size
+= local_gotno
* 4;
5245 /* The check_relocs and adjust_dynamic_symbol entry points have
5246 determined the sizes of the various dynamic sections. Allocate
5249 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5254 /* It's OK to base decisions on the section name, because none
5255 of the dynobj section names depend upon the input files. */
5256 name
= bfd_get_section_name (dynobj
, s
);
5258 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
5263 if (strncmp (name
, ".rel", 4) == 0)
5265 if (s
->_raw_size
== 0)
5271 /* If this relocation section applies to a read only
5272 section, then we probably need a DT_TEXTREL entry.
5273 If the relocation section is .rel.dyn, we always
5274 assert a DT_TEXTREL entry rather than testing whether
5275 there exists a relocation to a read only section or
5277 target
= bfd_get_section_by_name (output_bfd
, name
+ 4);
5278 if ((target
!= NULL
&& (target
->flags
& SEC_READONLY
) != 0)
5279 || strcmp (name
, ".rel.dyn") == 0)
5282 /* We use the reloc_count field as a counter if we need
5283 to copy relocs into the output file. */
5284 if (strcmp (name
, ".rel.dyn") != 0)
5288 else if (strncmp (name
, ".got", 4) == 0)
5292 BFD_ASSERT (elf_section_data (s
) != NULL
);
5293 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5294 BFD_ASSERT (g
!= NULL
);
5296 /* Fix the size of .got section for the correspondence of
5297 global symbols and got entries. This adds some useless
5298 got entries. Is this required by ABI really? */
5299 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
;
5300 s
->_raw_size
+= i
* 4;
5302 else if (strncmp (name
, ".stub", 5) == 0)
5304 /* Irix rld assumes that the function stub isn't at the end
5305 of .text section. So put a dummy. XXX */
5306 s
->_raw_size
+= MIPS_FUNCTION_STUB_SIZE
;
5308 else if (! info
->shared
5309 && ! mips_elf_hash_table (info
)->use_rld_obj_head
5310 && strncmp (name
, ".rld_map", 8) == 0)
5312 /* We add a room for __rld_map. It will be filled in by the
5313 rtld to contain a pointer to the _r_debug structure. */
5316 else if (SGI_COMPAT (output_bfd
)
5317 && strncmp (name
, ".compact_rel", 12) == 0)
5318 s
->_raw_size
+= mips_elf_hash_table (info
)->compact_rel_size
;
5319 else if (strncmp (name
, ".init", 5) != 0)
5321 /* It's not one of our sections, so don't allocate space. */
5329 for (spp
= &s
->output_section
->owner
->sections
;
5330 *spp
!= s
->output_section
;
5331 spp
= &(*spp
)->next
)
5333 *spp
= s
->output_section
->next
;
5334 --s
->output_section
->owner
->section_count
;
5339 /* Allocate memory for the section contents. */
5340 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
5341 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
5343 bfd_set_error (bfd_error_no_memory
);
5346 memset (s
->contents
, 0, s
->_raw_size
);
5349 if (elf_hash_table (info
)->dynamic_sections_created
)
5351 /* Add some entries to the .dynamic section. We fill in the
5352 values later, in elf_mips_finish_dynamic_sections, but we
5353 must add the entries now so that we get the correct size for
5354 the .dynamic section. The DT_DEBUG entry is filled in by the
5355 dynamic linker and used by the debugger. */
5358 if (SGI_COMPAT (output_bfd
))
5360 /* SGI object has the equivalence of DT_DEBUG in the
5361 DT_MIPS_RLD_MAP entry. */
5362 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_MAP
, 0))
5366 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
5372 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
5376 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
5379 if (bfd_get_section_by_name (dynobj
, ".rel.dyn"))
5381 if (! bfd_elf32_add_dynamic_entry (info
, DT_REL
, 0))
5384 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELSZ
, 0))
5387 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
, 0))
5391 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICTNO
, 0))
5394 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLISTNO
, 0))
5397 if (bfd_get_section_by_name (dynobj
, ".conflict") != NULL
)
5399 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_CONFLICT
, 0))
5402 s
= bfd_get_section_by_name (dynobj
, ".liblist");
5403 BFD_ASSERT (s
!= NULL
);
5405 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LIBLIST
, 0))
5409 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_RLD_VERSION
, 0))
5412 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_FLAGS
, 0))
5416 /* Time stamps in executable files are a bad idea. */
5417 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_TIME_STAMP
, 0))
5422 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_ICHECKSUM
, 0))
5427 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_IVERSION
, 0))
5431 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_BASE_ADDRESS
, 0))
5434 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_LOCAL_GOTNO
, 0))
5437 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_SYMTABNO
, 0))
5440 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_UNREFEXTNO
, 0))
5443 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_GOTSYM
, 0))
5446 if (! bfd_elf32_add_dynamic_entry (info
, DT_MIPS_HIPAGENO
, 0))
5449 #if 0 /* (SGI_COMPAT) */
5450 if (! bfd_get_section_by_name (dynobj
, ".init"))
5451 if (! bfd_elf32_add_dynamic_entry (info
, DT_INIT
, 0))
5454 if (! bfd_get_section_by_name (dynobj
, ".fini"))
5455 if (! bfd_elf32_add_dynamic_entry (info
, DT_FINI
, 0))
5460 /* If we use dynamic linking, we generate a section symbol for each
5461 output section. These are local symbols, which means that they
5462 must come first in the dynamic symbol table.
5463 That means we must increment the dynamic symbol index of every
5464 other dynamic symbol. */
5466 const char * const *namep
;
5468 bfd_size_type strindex
;
5469 struct bfd_strtab_hash
*dynstr
;
5470 struct mips_got_info
*g
;
5473 if (elf_hash_table (info
)->dynamic_sections_created
)
5475 if (SGI_COMPAT (output_bfd
))
5477 c
= SIZEOF_MIPS_DYNSYM_SECNAMES
- 1;
5478 elf_link_hash_traverse (elf_hash_table (info
),
5479 mips_elf_adjust_dynindx
,
5481 elf_hash_table (info
)->dynsymcount
+= c
;
5483 dynstr
= elf_hash_table (info
)->dynstr
;
5484 BFD_ASSERT (dynstr
!= NULL
);
5486 for (i
= 1, namep
= mips_elf_dynsym_sec_names
;
5490 s
= bfd_get_section_by_name (output_bfd
, *namep
);
5492 elf_section_data (s
)->dynindx
= i
;
5494 strindex
= _bfd_stringtab_add (dynstr
, *namep
, true, false);
5495 if (strindex
== (bfd_size_type
) -1)
5498 mips_elf_hash_table (info
)->dynsym_sec_strindex
[i
] = strindex
;
5503 c
= bfd_count_sections (output_bfd
);
5504 elf_link_hash_traverse (elf_hash_table (info
),
5505 mips_elf_adjust_dynindx
,
5507 elf_hash_table (info
)->dynsymcount
+= c
;
5509 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
5511 elf_section_data (s
)->dynindx
= i
;
5512 /* These symbols will have no names, so we don't need to
5513 fiddle with dynstr_index. */
5518 s
= bfd_get_section_by_name (dynobj
, ".got");
5519 BFD_ASSERT (s
!= NULL
);
5520 BFD_ASSERT (elf_section_data (s
) != NULL
);
5521 g
= (struct mips_got_info
*) elf_section_data (s
)->tdata
;
5522 BFD_ASSERT (g
!= NULL
);
5524 /* If there are no global got symbols, fake the last symbol so for
5526 if (g
->global_gotsym
)
5527 g
->global_gotsym
+= c
;
5529 g
->global_gotsym
= elf_hash_table (info
)->dynsymcount
- 1;
5535 /* Increment the index of a dynamic symbol by a given amount. Called
5536 via elf_link_hash_traverse. */
5539 mips_elf_adjust_dynindx (h
, cparg
)
5540 struct elf_link_hash_entry
*h
;
5543 unsigned int *cp
= (unsigned int *) cparg
;
5545 if (h
->dynindx
!= -1)
5550 /* Finish up dynamic symbol handling. We set the contents of various
5551 dynamic sections here. */
5554 mips_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5556 struct bfd_link_info
*info
;
5557 struct elf_link_hash_entry
*h
;
5558 Elf_Internal_Sym
*sym
;
5563 struct mips_got_info
*g
;
5566 dynobj
= elf_hash_table (info
)->dynobj
;
5567 gval
= sym
->st_value
;
5569 if (h
->plt_offset
!= (bfd_vma
) -1)
5573 bfd_byte stub
[MIPS_FUNCTION_STUB_SIZE
];
5575 /* This symbol has a stub. Set it up. */
5577 BFD_ASSERT (h
->dynindx
!= -1);
5579 s
= bfd_get_section_by_name (dynobj
, ".stub");
5580 BFD_ASSERT (s
!= NULL
);
5582 /* Fill the stub. */
5584 bfd_put_32 (output_bfd
, STUB_LW(output_bfd
), p
);
5586 bfd_put_32 (output_bfd
, STUB_MOVE
, p
);
5589 /* FIXME: Can h->dynindex be more than 64K? */
5590 if (h
->dynindx
& 0xffff0000)
5593 bfd_put_32 (output_bfd
, STUB_JALR
, p
);
5595 bfd_put_32 (output_bfd
, STUB_LI16
+ h
->dynindx
, p
);
5597 BFD_ASSERT (h
->plt_offset
<= s
->_raw_size
);
5598 memcpy (s
->contents
+ h
->plt_offset
, stub
, MIPS_FUNCTION_STUB_SIZE
);
5600 /* Mark the symbol as undefined. plt_offset != -1 occurs
5601 only for the referenced symbol. */
5602 sym
->st_shndx
= SHN_UNDEF
;
5604 /* The run-time linker uses the st_value field of the symbol
5605 to reset the global offset table entry for this external
5606 to its stub address when unlinking a shared object. */
5607 gval
= s
->output_section
->vma
+ s
->output_offset
+ h
->plt_offset
;
5608 sym
->st_value
= gval
;
5611 BFD_ASSERT (h
->dynindx
!= -1);
5613 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5614 BFD_ASSERT (sgot
!= NULL
);
5615 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5616 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5617 BFD_ASSERT (g
!= NULL
);
5619 if ((unsigned long) h
->dynindx
>= g
->global_gotsym
)
5621 bfd_size_type offset
;
5623 /* This symbol has an entry in the global offset table. Set its
5624 value to the corresponding got entry, if needed. */
5625 if (h
->got_offset
== (bfd_vma
) -1)
5627 offset
= (h
->dynindx
- g
->global_gotsym
+ g
->local_gotno
) * 4;
5628 BFD_ASSERT (g
->local_gotno
* 4 <= offset
5629 && offset
< sgot
->_raw_size
);
5630 bfd_put_32 (output_bfd
, gval
, sgot
->contents
+ offset
);
5634 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5635 name
= h
->root
.root
.string
;
5636 if (strcmp (name
, "_DYNAMIC") == 0
5637 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
5638 sym
->st_shndx
= SHN_ABS
;
5639 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
5641 sym
->st_shndx
= SHN_ABS
;
5642 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5645 else if (SGI_COMPAT (output_bfd
))
5647 if (strcmp (name
, "_gp_disp") == 0)
5649 sym
->st_shndx
= SHN_ABS
;
5650 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5651 sym
->st_value
= elf_gp (output_bfd
);
5653 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
5654 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
5656 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5657 sym
->st_other
= STO_PROTECTED
;
5659 sym
->st_shndx
= SHN_MIPS_DATA
;
5661 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
5663 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
5664 sym
->st_other
= STO_PROTECTED
;
5665 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
5666 sym
->st_shndx
= SHN_ABS
;
5668 else if (sym
->st_shndx
!= SHN_UNDEF
)
5670 if (h
->type
== STT_FUNC
)
5671 sym
->st_shndx
= SHN_MIPS_TEXT
;
5672 else if (h
->type
== STT_OBJECT
)
5673 sym
->st_shndx
= SHN_MIPS_DATA
;
5677 if (SGI_COMPAT (output_bfd
)
5680 if (! mips_elf_hash_table (info
)->use_rld_obj_head
5681 && strcmp (name
, "__rld_map") == 0)
5683 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
5684 BFD_ASSERT (s
!= NULL
);
5685 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
5686 bfd_put_32 (output_bfd
, (bfd_vma
) 0, s
->contents
);
5687 if (mips_elf_hash_table (info
)->rld_value
== 0)
5688 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5690 else if (mips_elf_hash_table (info
)->use_rld_obj_head
5691 && strcmp (name
, "__rld_obj_head") == 0)
5693 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
5694 BFD_ASSERT (s
!= NULL
);
5695 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
5702 /* Finish up the dynamic sections. */
5705 mips_elf_finish_dynamic_sections (output_bfd
, info
)
5707 struct bfd_link_info
*info
;
5712 struct mips_got_info
*g
;
5714 dynobj
= elf_hash_table (info
)->dynobj
;
5716 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5718 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5719 BFD_ASSERT (sgot
!= NULL
);
5721 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
5722 g
= (struct mips_got_info
*) elf_section_data (sgot
)->tdata
;
5723 BFD_ASSERT (g
!= NULL
);
5725 if (elf_hash_table (info
)->dynamic_sections_created
)
5727 Elf32_External_Dyn
*dyncon
, *dynconend
;
5729 BFD_ASSERT (sdyn
!= NULL
);
5731 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5732 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5733 for (; dyncon
< dynconend
; dyncon
++)
5735 Elf_Internal_Dyn dyn
;
5740 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5748 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
5749 BFD_ASSERT (s
!= NULL
);
5750 dyn
.d_un
.d_val
= sizeof (Elf32_External_Rel
);
5751 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5755 /* Rewrite DT_STRSZ. */
5757 _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
5758 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5764 case DT_MIPS_CONFLICT
:
5767 case DT_MIPS_LIBLIST
:
5770 s
= bfd_get_section_by_name (output_bfd
, name
);
5771 BFD_ASSERT (s
!= NULL
);
5772 dyn
.d_un
.d_ptr
= s
->vma
;
5773 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5776 case DT_MIPS_RLD_VERSION
:
5777 dyn
.d_un
.d_val
= 1; /* XXX */
5778 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5782 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
5783 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5786 case DT_MIPS_CONFLICTNO
:
5788 elemsize
= sizeof (Elf32_Conflict
);
5791 case DT_MIPS_LIBLISTNO
:
5793 elemsize
= sizeof (Elf32_Lib
);
5795 s
= bfd_get_section_by_name (output_bfd
, name
);
5798 if (s
->_cooked_size
!= 0)
5799 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5801 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5806 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5809 case DT_MIPS_TIME_STAMP
:
5810 time ((time_t *) &dyn
.d_un
.d_val
);
5811 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5814 case DT_MIPS_ICHECKSUM
:
5818 case DT_MIPS_IVERSION
:
5822 case DT_MIPS_BASE_ADDRESS
:
5823 s
= output_bfd
->sections
;
5824 BFD_ASSERT (s
!= NULL
);
5825 dyn
.d_un
.d_ptr
= s
->vma
& ~(0xffff);
5826 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5829 case DT_MIPS_LOCAL_GOTNO
:
5830 dyn
.d_un
.d_val
= g
->local_gotno
;
5831 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5834 case DT_MIPS_SYMTABNO
:
5836 elemsize
= sizeof (Elf32_External_Sym
);
5837 s
= bfd_get_section_by_name (output_bfd
, name
);
5838 BFD_ASSERT (s
!= NULL
);
5840 if (s
->_cooked_size
!= 0)
5841 dyn
.d_un
.d_val
= s
->_cooked_size
/ elemsize
;
5843 dyn
.d_un
.d_val
= s
->_raw_size
/ elemsize
;
5844 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5847 case DT_MIPS_UNREFEXTNO
:
5849 dyn
.d_un
.d_val
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
5850 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5853 case DT_MIPS_GOTSYM
:
5854 dyn
.d_un
.d_val
= g
->global_gotsym
;
5855 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5858 case DT_MIPS_HIPAGENO
:
5859 dyn
.d_un
.d_val
= g
->local_gotno
- MIPS_RESERVED_GOTNO
;
5860 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5863 case DT_MIPS_RLD_MAP
:
5864 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
5865 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5872 /* The first entry of the global offset table will be filled at
5873 runtime. The second entry will be used by some runtime loaders.
5874 This isn't the case of Irix rld. */
5875 if (sgot
->_raw_size
> 0)
5877 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5878 bfd_put_32 (output_bfd
, (bfd_vma
) 0x80000000, sgot
->contents
+ 4);
5881 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5888 Elf_Internal_Sym sym
;
5891 const char * const * namep
= mips_elf_dynsym_sec_names
;
5892 Elf32_compact_rel cpt
;
5894 /* Set up the section symbols for the output sections. SGI sets
5895 the STT_NOTYPE attribute for these symbols. Should we do so? */
5897 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
5898 if (sdynsym
!= NULL
)
5900 if (SGI_COMPAT (output_bfd
))
5904 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
5908 while ((name
= *namep
++) != NULL
)
5910 s
= bfd_get_section_by_name (output_bfd
, name
);
5913 sym
.st_value
= s
->vma
;
5914 dindx
= elf_section_data (s
)->dynindx
;
5915 last
= s
->vma
+ s
->_raw_size
;
5919 sym
.st_value
= last
;
5923 sym
.st_shndx
= (i
< MIPS_TEXT_DYNSYM_SECNO
5928 mips_elf_hash_table (info
)->dynsym_sec_strindex
[dindx
];
5930 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
5931 (((Elf32_External_Sym
*)
5936 /* Set the sh_info field of the output .dynsym section to
5937 the index of the first global symbol. */
5938 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
5939 SIZEOF_MIPS_DYNSYM_SECNAMES
;
5945 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
5948 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
5952 sym
.st_value
= s
->vma
;
5954 indx
= elf_section_data (s
)->this_idx
;
5955 BFD_ASSERT (indx
> 0);
5956 sym
.st_shndx
= indx
;
5958 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
5959 (((Elf32_External_Sym
*)
5961 + elf_section_data (s
)->dynindx
));
5964 /* Set the sh_info field of the output .dynsym section to
5965 the index of the first global symbol. */
5966 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
5967 bfd_count_sections (output_bfd
) + 1;
5971 if (SGI_COMPAT (output_bfd
))
5973 /* Write .compact_rel section out. */
5974 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5978 cpt
.num
= s
->reloc_count
;
5980 cpt
.offset
= (s
->output_section
->filepos
5981 + sizeof (Elf32_External_compact_rel
));
5984 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
5985 ((Elf32_External_compact_rel
*)
5988 /* Clean up a dummy stub function entry in .text. */
5989 s
= bfd_get_section_by_name (dynobj
, ".stub");
5992 file_ptr dummy_offset
;
5994 BFD_ASSERT (s
->_raw_size
>= MIPS_FUNCTION_STUB_SIZE
);
5995 dummy_offset
= s
->_raw_size
- MIPS_FUNCTION_STUB_SIZE
;
5996 memset (s
->contents
+ dummy_offset
, 0,
5997 MIPS_FUNCTION_STUB_SIZE
);
6002 /* Clean up a first relocation in .rel.dyn. */
6003 s
= bfd_get_section_by_name (dynobj
, ".rel.dyn");
6005 memset (s
->contents
, 0, sizeof (Elf32_External_Rel
));
6011 /* This is almost identical to bfd_generic_get_... except that some
6012 MIPS relocations need to be handled specially. Sigh. */
6015 elf32_mips_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
6016 relocateable
, symbols
)
6018 struct bfd_link_info
*link_info
;
6019 struct bfd_link_order
*link_order
;
6021 boolean relocateable
;
6024 /* Get enough memory to hold the stuff */
6025 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
6026 asection
*input_section
= link_order
->u
.indirect
.section
;
6028 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
6029 arelent
**reloc_vector
= NULL
;
6035 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
6036 if (reloc_vector
== NULL
&& reloc_size
!= 0)
6039 /* read in the section */
6040 if (!bfd_get_section_contents (input_bfd
,
6044 input_section
->_raw_size
))
6047 /* We're not relaxing the section, so just copy the size info */
6048 input_section
->_cooked_size
= input_section
->_raw_size
;
6049 input_section
->reloc_done
= true;
6051 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
6055 if (reloc_count
< 0)
6058 if (reloc_count
> 0)
6063 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
6066 struct bfd_hash_entry
*h
;
6067 struct bfd_link_hash_entry
*lh
;
6068 /* Skip all this stuff if we aren't mixing formats. */
6069 if (abfd
&& input_bfd
6070 && abfd
->xvec
== input_bfd
->xvec
)
6074 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", false, false);
6075 lh
= (struct bfd_link_hash_entry
*) h
;
6082 case bfd_link_hash_undefined
:
6083 case bfd_link_hash_undefweak
:
6084 case bfd_link_hash_common
:
6087 case bfd_link_hash_defined
:
6088 case bfd_link_hash_defweak
:
6090 gp
= lh
->u
.def
.value
;
6092 case bfd_link_hash_indirect
:
6093 case bfd_link_hash_warning
:
6095 /* @@FIXME ignoring warning for now */
6097 case bfd_link_hash_new
:
6106 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
6109 char *error_message
= (char *) NULL
;
6110 bfd_reloc_status_type r
;
6112 /* Specific to MIPS: Deal with relocation types that require
6113 knowing the gp of the output bfd. */
6114 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
6115 if (bfd_is_abs_section (sym
->section
) && abfd
)
6117 /* The special_function wouldn't get called anyways. */
6121 /* The gp isn't there; let the special function code
6122 fall over on its own. */
6124 else if ((*parent
)->howto
->special_function
6125 == _bfd_mips_elf_gprel16_reloc
)
6127 /* bypass special_function call */
6128 r
= gprel16_with_gp (input_bfd
, sym
, *parent
, input_section
,
6129 relocateable
, (PTR
) data
, gp
);
6130 goto skip_bfd_perform_relocation
;
6132 /* end mips specific stuff */
6134 r
= bfd_perform_relocation (input_bfd
,
6138 relocateable
? abfd
: (bfd
*) NULL
,
6140 skip_bfd_perform_relocation
:
6144 asection
*os
= input_section
->output_section
;
6146 /* A partial link, so keep the relocs */
6147 os
->orelocation
[os
->reloc_count
] = *parent
;
6151 if (r
!= bfd_reloc_ok
)
6155 case bfd_reloc_undefined
:
6156 if (!((*link_info
->callbacks
->undefined_symbol
)
6157 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6158 input_bfd
, input_section
, (*parent
)->address
)))
6161 case bfd_reloc_dangerous
:
6162 BFD_ASSERT (error_message
!= (char *) NULL
);
6163 if (!((*link_info
->callbacks
->reloc_dangerous
)
6164 (link_info
, error_message
, input_bfd
, input_section
,
6165 (*parent
)->address
)))
6168 case bfd_reloc_overflow
:
6169 if (!((*link_info
->callbacks
->reloc_overflow
)
6170 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
6171 (*parent
)->howto
->name
, (*parent
)->addend
,
6172 input_bfd
, input_section
, (*parent
)->address
)))
6175 case bfd_reloc_outofrange
:
6184 if (reloc_vector
!= NULL
)
6185 free (reloc_vector
);
6189 if (reloc_vector
!= NULL
)
6190 free (reloc_vector
);
6193 #define bfd_elf32_bfd_get_relocated_section_contents \
6194 elf32_mips_get_relocated_section_contents
6196 /* ECOFF swapping routines. These are used when dealing with the
6197 .mdebug section, which is in the ECOFF debugging format. */
6198 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
=
6200 /* Symbol table magic number. */
6202 /* Alignment of debugging information. E.g., 4. */
6204 /* Sizes of external symbolic information. */
6205 sizeof (struct hdr_ext
),
6206 sizeof (struct dnr_ext
),
6207 sizeof (struct pdr_ext
),
6208 sizeof (struct sym_ext
),
6209 sizeof (struct opt_ext
),
6210 sizeof (struct fdr_ext
),
6211 sizeof (struct rfd_ext
),
6212 sizeof (struct ext_ext
),
6213 /* Functions to swap in external symbolic data. */
6222 _bfd_ecoff_swap_tir_in
,
6223 _bfd_ecoff_swap_rndx_in
,
6224 /* Functions to swap out external symbolic data. */
6233 _bfd_ecoff_swap_tir_out
,
6234 _bfd_ecoff_swap_rndx_out
,
6235 /* Function to read in symbolic data. */
6236 _bfd_mips_elf_read_ecoff_info
6239 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
6240 #define TARGET_LITTLE_NAME "elf32-littlemips"
6241 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
6242 #define TARGET_BIG_NAME "elf32-bigmips"
6243 #define ELF_ARCH bfd_arch_mips
6244 #define ELF_MACHINE_CODE EM_MIPS
6246 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
6247 a value of 0x1000, and we are compatible. */
6248 #define ELF_MAXPAGESIZE 0x1000
6250 #define elf_backend_collect true
6251 #define elf_backend_type_change_ok true
6252 #define elf_info_to_howto 0
6253 #define elf_info_to_howto_rel mips_info_to_howto_rel
6254 #define elf_backend_sym_is_global mips_elf_sym_is_global
6255 #define elf_backend_object_p mips_elf32_object_p
6256 #define elf_backend_section_from_shdr mips_elf32_section_from_shdr
6257 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
6258 #define elf_backend_section_from_bfd_section \
6259 _bfd_mips_elf_section_from_bfd_section
6260 #define elf_backend_section_processing mips_elf32_section_processing
6261 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
6262 #define elf_backend_additional_program_headers \
6263 mips_elf_additional_program_headers
6264 #define elf_backend_modify_segment_map mips_elf_modify_segment_map
6265 #define elf_backend_final_write_processing \
6266 _bfd_mips_elf_final_write_processing
6267 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
6269 #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label
6270 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
6271 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
6272 #define bfd_elf32_bfd_link_hash_table_create \
6273 mips_elf_link_hash_table_create
6274 #define bfd_elf32_bfd_final_link mips_elf_final_link
6275 #define bfd_elf32_bfd_copy_private_bfd_data \
6276 _bfd_mips_elf_copy_private_bfd_data
6277 #define bfd_elf32_bfd_merge_private_bfd_data \
6278 _bfd_mips_elf_merge_private_bfd_data
6279 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
6280 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
6281 #define elf_backend_create_dynamic_sections \
6282 mips_elf_create_dynamic_sections
6283 #define elf_backend_check_relocs mips_elf_check_relocs
6284 #define elf_backend_adjust_dynamic_symbol \
6285 mips_elf_adjust_dynamic_symbol
6286 #define elf_backend_size_dynamic_sections \
6287 mips_elf_size_dynamic_sections
6288 #define elf_backend_relocate_section mips_elf_relocate_section
6289 #define elf_backend_finish_dynamic_symbol \
6290 mips_elf_finish_dynamic_symbol
6291 #define elf_backend_finish_dynamic_sections \
6292 mips_elf_finish_dynamic_sections
6294 #include "elf32-target.h"