1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 /* Get the ECOFF swapping routines. */
33 #include "coff/symconst.h"
34 #include "coff/internal.h"
35 #include "coff/ecoff.h"
36 #include "coff/mips.h"
38 #include "ecoffswap.h"
40 static bfd_reloc_status_type mips_elf_hi16_reloc
PARAMS ((bfd
*abfd
,
47 static bfd_reloc_status_type mips_elf_got16_reloc
PARAMS ((bfd
*abfd
,
54 static bfd_reloc_status_type mips_elf_lo16_reloc
PARAMS ((bfd
*abfd
,
61 static bfd_reloc_status_type mips_elf_gprel16_reloc
PARAMS ((bfd
*abfd
,
68 static const struct reloc_howto_struct
*bfd_elf32_bfd_reloc_type_lookup
69 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
70 static void mips_info_to_howto_rel
71 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
72 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
73 static boolean mips_elf_object_p
PARAMS ((bfd
*));
74 static void mips_elf_final_write_processing
75 PARAMS ((bfd
*, boolean
));
76 static boolean mips_elf_section_from_shdr
77 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
78 static boolean mips_elf_fake_sections
79 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*));
80 static boolean mips_elf_section_from_bfd_section
81 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*, int *));
82 static boolean mips_elf_section_processing
83 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
84 static void mips_elf_symbol_processing
PARAMS ((bfd
*, asymbol
*));
85 static boolean mips_elf_read_ecoff_info
86 PARAMS ((bfd
*, asection
*, struct ecoff_debug_info
*));
87 static struct bfd_hash_entry
*mips_elf_link_hash_newfunc
88 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
89 static struct bfd_link_hash_table
*mips_elf_link_hash_table_create
91 static int gptab_compare
PARAMS ((const void *, const void *));
92 static boolean mips_elf_final_link
93 PARAMS ((bfd
*, struct bfd_link_info
*));
94 static void mips_elf_relocate_hi16
95 PARAMS ((bfd
*, Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_byte
*,
97 static boolean mips_elf_relocate_section
98 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
99 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**, char *));
100 static boolean mips_elf_add_symbol_hook
101 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
102 const char **, flagword
*, asection
**, bfd_vma
*));
104 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
109 R_MIPS_16
, R_MIPS_32
,
110 R_MIPS_REL32
, R_MIPS_26
,
111 R_MIPS_HI16
, R_MIPS_LO16
,
112 R_MIPS_GPREL16
, R_MIPS_LITERAL
,
113 R_MIPS_GOT16
, R_MIPS_PC16
,
114 R_MIPS_CALL16
, R_MIPS_GPREL32
,
118 static reloc_howto_type elf_mips_howto_table
[] =
121 HOWTO (R_MIPS_NONE
, /* type */
123 0, /* size (0 = byte, 1 = short, 2 = long) */
125 false, /* pc_relative */
127 complain_overflow_dont
, /* complain_on_overflow */
128 bfd_elf_generic_reloc
, /* special_function */
129 "R_MIPS_NONE", /* name */
130 false, /* partial_inplace */
133 false), /* pcrel_offset */
135 /* 16 bit relocation. */
136 HOWTO (R_MIPS_16
, /* type */
138 1, /* size (0 = byte, 1 = short, 2 = long) */
140 false, /* pc_relative */
142 complain_overflow_bitfield
, /* complain_on_overflow */
143 bfd_elf_generic_reloc
, /* special_function */
144 "R_MIPS_16", /* name */
145 true, /* partial_inplace */
146 0xffff, /* src_mask */
147 0xffff, /* dst_mask */
148 false), /* pcrel_offset */
150 /* 32 bit relocation. */
151 HOWTO (R_MIPS_32
, /* type */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
155 false, /* pc_relative */
157 complain_overflow_bitfield
, /* complain_on_overflow */
158 bfd_elf_generic_reloc
, /* special_function */
159 "R_MIPS_32", /* name */
160 true, /* partial_inplace */
161 0xffffffff, /* src_mask */
162 0xffffffff, /* dst_mask */
163 false), /* pcrel_offset */
165 /* 32 bit symbol relative relocation. */
166 HOWTO (R_MIPS_REL32
, /* type */
168 2, /* size (0 = byte, 1 = short, 2 = long) */
170 false, /* pc_relative */
172 complain_overflow_bitfield
, /* complain_on_overflow */
173 bfd_elf_generic_reloc
, /* special_function */
174 "R_MIPS_REL32", /* name */
175 true, /* partial_inplace */
176 0xffffffff, /* src_mask */
177 0xffffffff, /* dst_mask */
178 false), /* pcrel_offset */
180 /* 26 bit branch address. */
181 HOWTO (R_MIPS_26
, /* type */
183 2, /* size (0 = byte, 1 = short, 2 = long) */
185 false, /* pc_relative */
187 complain_overflow_dont
, /* complain_on_overflow */
188 /* This needs complex overflow
189 detection, because the upper four
190 bits must match the PC. */
191 bfd_elf_generic_reloc
, /* special_function */
192 "R_MIPS_26", /* name */
193 true, /* partial_inplace */
194 0x3ffffff, /* src_mask */
195 0x3ffffff, /* dst_mask */
196 false), /* pcrel_offset */
198 /* High 16 bits of symbol value. */
199 HOWTO (R_MIPS_HI16
, /* type */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
203 false, /* pc_relative */
205 complain_overflow_dont
, /* complain_on_overflow */
206 mips_elf_hi16_reloc
, /* special_function */
207 "R_MIPS_HI16", /* name */
208 true, /* partial_inplace */
209 0xffff, /* src_mask */
210 0xffff, /* dst_mask */
211 false), /* pcrel_offset */
213 /* Low 16 bits of symbol value. */
214 HOWTO (R_MIPS_LO16
, /* type */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
218 false, /* pc_relative */
220 complain_overflow_dont
, /* complain_on_overflow */
221 mips_elf_lo16_reloc
, /* special_function */
222 "R_MIPS_LO16", /* name */
223 true, /* partial_inplace */
224 0xffff, /* src_mask */
225 0xffff, /* dst_mask */
226 false), /* pcrel_offset */
228 /* GP relative reference. */
229 HOWTO (R_MIPS_GPREL16
, /* type */
231 2, /* size (0 = byte, 1 = short, 2 = long) */
233 false, /* pc_relative */
235 complain_overflow_signed
, /* complain_on_overflow */
236 mips_elf_gprel16_reloc
, /* special_function */
237 "R_MIPS_GPREL16", /* name */
238 true, /* partial_inplace */
239 0xffff, /* src_mask */
240 0xffff, /* dst_mask */
241 false), /* pcrel_offset */
243 /* Reference to literal section. */
244 HOWTO (R_MIPS_LITERAL
, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 false, /* pc_relative */
250 complain_overflow_signed
, /* complain_on_overflow */
251 mips_elf_gprel16_reloc
, /* special_function */
252 "R_MIPS_LITERAL", /* name */
253 true, /* partial_inplace */
254 0xffff, /* src_mask */
255 0xffff, /* dst_mask */
256 false), /* pcrel_offset */
258 /* Reference to global offset table. */
259 /* FIXME: This is not handled correctly. */
260 HOWTO (R_MIPS_GOT16
, /* type */
262 2, /* size (0 = byte, 1 = short, 2 = long) */
264 false, /* pc_relative */
266 complain_overflow_signed
, /* complain_on_overflow */
267 mips_elf_got16_reloc
, /* special_function */
268 "R_MIPS_GOT16", /* name */
269 false, /* partial_inplace */
271 0xffff, /* dst_mask */
272 false), /* pcrel_offset */
274 /* 16 bit PC relative reference. */
275 HOWTO (R_MIPS_PC16
, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 true, /* pc_relative */
281 complain_overflow_signed
, /* complain_on_overflow */
282 bfd_elf_generic_reloc
, /* special_function */
283 "R_MIPS_PC16", /* name */
284 true, /* partial_inplace */
285 0xffff, /* src_mask */
286 0xffff, /* dst_mask */
287 false), /* pcrel_offset */
289 /* 16 bit call through global offset table. */
290 /* FIXME: This is not handled correctly. */
291 HOWTO (R_MIPS_CALL16
, /* type */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
295 false, /* pc_relative */
297 complain_overflow_signed
, /* complain_on_overflow */
298 bfd_elf_generic_reloc
, /* special_function */
299 "R_MIPS_CALL16", /* name */
300 false, /* partial_inplace */
302 0xffff, /* dst_mask */
303 false), /* pcrel_offset */
305 /* 32 bit GP relative reference. */
306 /* FIXME: This is not handled correctly. */
307 HOWTO (R_MIPS_GPREL32
, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 false, /* pc_relative */
313 complain_overflow_bitfield
, /* complain_on_overflow */
314 bfd_elf_generic_reloc
, /* special_function */
315 "R_MIPS_GPREL32", /* name */
316 true, /* partial_inplace */
317 0xffffffff, /* src_mask */
318 0xffffffff, /* dst_mask */
319 false) /* pcrel_offset */
322 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
323 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
324 the HI16. Here we just save the information we need; we do the
325 actual relocation when we see the LO16. MIPS ELF requires that the
326 LO16 immediately follow the HI16, so this ought to work. */
328 static bfd_byte
*mips_hi16_addr
;
329 static bfd_vma mips_hi16_addend
;
331 static bfd_reloc_status_type
332 mips_elf_hi16_reloc (abfd
,
340 arelent
*reloc_entry
;
343 asection
*input_section
;
345 char **error_message
;
347 bfd_reloc_status_type ret
;
350 /* If we're relocating, and this an external symbol, we don't want
351 to change anything. */
352 if (output_bfd
!= (bfd
*) NULL
353 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
354 && reloc_entry
->addend
== 0)
356 reloc_entry
->address
+= input_section
->output_offset
;
360 /* FIXME: The symbol _gp_disp requires special handling, which we do
362 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
366 if (bfd_is_und_section (symbol
->section
)
367 && output_bfd
== (bfd
*) NULL
)
368 ret
= bfd_reloc_undefined
;
370 if (bfd_is_com_section (symbol
->section
))
373 relocation
= symbol
->value
;
375 relocation
+= symbol
->section
->output_section
->vma
;
376 relocation
+= symbol
->section
->output_offset
;
377 relocation
+= reloc_entry
->addend
;
379 if (reloc_entry
->address
> input_section
->_cooked_size
)
380 return bfd_reloc_outofrange
;
382 /* Save the information, and let LO16 do the actual relocation. */
383 mips_hi16_addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
384 mips_hi16_addend
= relocation
;
386 if (output_bfd
!= (bfd
*) NULL
)
387 reloc_entry
->address
+= input_section
->output_offset
;
392 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
393 inplace relocation; this function exists in order to do the
394 R_MIPS_HI16 relocation described above. */
396 static bfd_reloc_status_type
397 mips_elf_lo16_reloc (abfd
,
405 arelent
*reloc_entry
;
408 asection
*input_section
;
410 char **error_message
;
412 /* FIXME: The symbol _gp_disp requires special handling, which we do
414 if (output_bfd
== (bfd
*) NULL
415 && strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
418 if (mips_hi16_addr
!= (bfd_byte
*) NULL
)
424 /* Do the HI16 relocation. Note that we actually don't need to
425 know anything about the LO16 itself, except where to find the
426 low 16 bits of the addend needed by the LO16. */
427 insn
= bfd_get_32 (abfd
, mips_hi16_addr
);
428 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
430 val
= ((insn
& 0xffff) << 16) + vallo
;
431 val
+= mips_hi16_addend
;
433 /* The low order 16 bits are always treated as a signed value.
434 Therefore, a negative value in the low order bits requires an
435 adjustment in the high order bits. We need to make this
436 adjustment in two ways: once for the bits we took from the
437 data, and once for the bits we are putting back in to the
439 if ((vallo
& 0x8000) != 0)
441 if ((val
& 0x8000) != 0)
444 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
445 bfd_put_32 (abfd
, insn
, mips_hi16_addr
);
447 mips_hi16_addr
= (bfd_byte
*) NULL
;
450 /* Now do the LO16 reloc in the usual way. */
451 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
452 input_section
, output_bfd
, error_message
);
455 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
456 table used for PIC code. If the symbol is an external symbol, the
457 instruction is modified to contain the offset of the appropriate
458 entry in the global offset table. If the symbol is a section
459 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
460 addends are combined to form the real addend against the section
461 symbol; the GOT16 is modified to contain the offset of an entry in
462 the global offset table, and the LO16 is modified to offset it
463 appropriately. Thus an offset larger than 16 bits requires a
464 modified value in the global offset table.
466 This implementation suffices for the assembler, but the linker does
467 not yet know how to create global offset tables. */
469 static bfd_reloc_status_type
470 mips_elf_got16_reloc (abfd
,
478 arelent
*reloc_entry
;
481 asection
*input_section
;
483 char **error_message
;
485 /* If we're relocating, and this an external symbol, we don't want
486 to change anything. */
487 if (output_bfd
!= (bfd
*) NULL
488 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
489 && reloc_entry
->addend
== 0)
491 reloc_entry
->address
+= input_section
->output_offset
;
495 /* If we're relocating, and this is a local symbol, we can handle it
497 if (output_bfd
!= (bfd
*) NULL
498 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
499 return mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
500 input_section
, output_bfd
, error_message
);
505 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
506 become the offset from the gp register. This function also handles
507 R_MIPS_LITERAL relocations, although those can be handled more
508 cleverly because the entries in the .lit8 and .lit4 sections can be
511 static bfd_reloc_status_type
512 mips_elf_gprel16_reloc (abfd
,
520 arelent
*reloc_entry
;
523 asection
*input_section
;
525 char **error_message
;
527 boolean relocateable
;
532 /* If we're relocating, and this is an external symbol with no
533 addend, we don't want to change anything. We will only have an
534 addend if this is a newly created reloc, not read from an ELF
536 if (output_bfd
!= (bfd
*) NULL
537 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
538 && reloc_entry
->addend
== 0)
540 reloc_entry
->address
+= input_section
->output_offset
;
544 if (output_bfd
!= (bfd
*) NULL
)
548 relocateable
= false;
549 output_bfd
= symbol
->section
->output_section
->owner
;
552 if (bfd_is_und_section (symbol
->section
)
553 && relocateable
== false)
554 return bfd_reloc_undefined
;
556 /* We have to figure out the gp value, so that we can adjust the
557 symbol value correctly. We look up the symbol _gp in the output
558 BFD. If we can't find it, we're stuck. We cache it in the ELF
559 target data. We don't need to adjust the symbol value for an
560 external symbol if we are producing relocateable output. */
561 if (elf_gp (output_bfd
) == 0
562 && (relocateable
== false
563 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
565 if (relocateable
!= false)
567 /* Make up a value. */
568 elf_gp (output_bfd
) =
569 symbol
->section
->output_section
->vma
+ 0x4000;
577 count
= bfd_get_symcount (output_bfd
);
578 sym
= bfd_get_outsymbols (output_bfd
);
580 if (sym
== (asymbol
**) NULL
)
584 for (i
= 0; i
< count
; i
++, sym
++)
586 register CONST
char *name
;
588 name
= bfd_asymbol_name (*sym
);
589 if (*name
== '_' && strcmp (name
, "_gp") == 0)
591 elf_gp (output_bfd
) = bfd_asymbol_value (*sym
);
599 /* Only get the error once. */
600 elf_gp (output_bfd
) = 4;
602 (char *) "GP relative relocation when _gp not defined";
603 return bfd_reloc_dangerous
;
608 if (bfd_is_com_section (symbol
->section
))
611 relocation
= symbol
->value
;
613 relocation
+= symbol
->section
->output_section
->vma
;
614 relocation
+= symbol
->section
->output_offset
;
616 if (reloc_entry
->address
> input_section
->_cooked_size
)
617 return bfd_reloc_outofrange
;
619 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
621 /* Set val to the offset into the section or symbol. */
622 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
626 /* Adjust val for the final section location and GP value. If we
627 are producing relocateable output, we don't want to do this for
628 an external symbol. */
629 if (relocateable
== false
630 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
631 val
+= relocation
- elf_gp (output_bfd
);
633 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
634 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
636 if (relocateable
!= false)
637 reloc_entry
->address
+= input_section
->output_offset
;
639 /* Make sure it fit in 16 bits. */
640 if (val
>= 0x8000 && val
< 0xffff8000)
641 return bfd_reloc_overflow
;
646 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
648 struct elf_reloc_map
{
649 bfd_reloc_code_real_type bfd_reloc_val
;
650 enum reloc_type elf_reloc_val
;
653 static CONST
struct elf_reloc_map mips_reloc_map
[] =
655 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
656 { BFD_RELOC_16
, R_MIPS_16
},
657 { BFD_RELOC_32
, R_MIPS_32
},
658 { BFD_RELOC_CTOR
, R_MIPS_32
},
659 { BFD_RELOC_32_PCREL
, R_MIPS_REL32
},
660 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
661 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
662 { BFD_RELOC_LO16
, R_MIPS_LO16
},
663 { BFD_RELOC_MIPS_GPREL
, R_MIPS_GPREL16
},
664 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
665 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
666 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
667 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
668 { BFD_RELOC_MIPS_GPREL32
, R_MIPS_GPREL32
}
671 /* Given a BFD reloc type, return a howto structure. */
673 static const struct reloc_howto_struct
*
674 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
676 bfd_reloc_code_real_type code
;
680 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
682 if (mips_reloc_map
[i
].bfd_reloc_val
== code
)
683 return &elf_mips_howto_table
[(int) mips_reloc_map
[i
].elf_reloc_val
];
688 /* Given a MIPS reloc type, fill in an arelent structure. */
691 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
694 Elf32_Internal_Rel
*dst
;
698 r_type
= ELF32_R_TYPE (dst
->r_info
);
699 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
700 cache_ptr
->howto
= &elf_mips_howto_table
[r_type
];
702 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
703 value for the object file. We get the addend now, rather than
704 when we do the relocation, because the symbol manipulations done
705 by the linker may cause us to lose track of the input BFD. */
706 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
707 && (r_type
== (unsigned int) R_MIPS_GPREL16
708 || r_type
== (unsigned int) R_MIPS_LITERAL
))
709 cache_ptr
->addend
= elf_gp (abfd
);
712 /* A .reginfo section holds a single Elf32_RegInfo structure. These
713 routines swap this structure in and out. They are used outside of
714 BFD, so they are globally visible. */
717 bfd_mips_elf32_swap_reginfo_in (abfd
, ex
, in
)
719 const Elf32_External_RegInfo
*ex
;
722 in
->ri_gprmask
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gprmask
);
723 in
->ri_cprmask
[0] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[0]);
724 in
->ri_cprmask
[1] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[1]);
725 in
->ri_cprmask
[2] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[2]);
726 in
->ri_cprmask
[3] = bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_cprmask
[3]);
727 in
->ri_gp_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ex
->ri_gp_value
);
731 bfd_mips_elf32_swap_reginfo_out (abfd
, in
, ex
)
733 const Elf32_RegInfo
*in
;
734 Elf32_External_RegInfo
*ex
;
736 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gprmask
,
737 (bfd_byte
*) ex
->ri_gprmask
);
738 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[0],
739 (bfd_byte
*) ex
->ri_cprmask
[0]);
740 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[1],
741 (bfd_byte
*) ex
->ri_cprmask
[1]);
742 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[2],
743 (bfd_byte
*) ex
->ri_cprmask
[2]);
744 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_cprmask
[3],
745 (bfd_byte
*) ex
->ri_cprmask
[3]);
746 bfd_h_put_32 (abfd
, (bfd_vma
) in
->ri_gp_value
,
747 (bfd_byte
*) ex
->ri_gp_value
);
750 /* Swap an entry in a .gptab section. Note that these routines rely
751 on the equivalence of the two elements of the union. */
754 bfd_mips_elf32_swap_gptab_in (abfd
, ex
, in
)
756 const Elf32_External_gptab
*ex
;
759 in
->gt_entry
.gt_g_value
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_g_value
);
760 in
->gt_entry
.gt_bytes
= bfd_h_get_32 (abfd
, ex
->gt_entry
.gt_bytes
);
764 bfd_mips_elf32_swap_gptab_out (abfd
, in
, ex
)
766 const Elf32_gptab
*in
;
767 Elf32_External_gptab
*ex
;
769 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_g_value
,
770 ex
->gt_entry
.gt_g_value
);
771 bfd_h_put_32 (abfd
, (bfd_vma
) in
->gt_entry
.gt_bytes
,
772 ex
->gt_entry
.gt_bytes
);
775 /* Determine whether a symbol is global for the purposes of splitting
776 the symbol table into global symbols and local symbols. At least
777 on Irix 5, this split must be between section symbols and all other
778 symbols. On most ELF targets the split is between static symbols
779 and externally visible symbols. */
783 mips_elf_sym_is_global (abfd
, sym
)
787 return (sym
->flags
& BSF_SECTION_SYM
) == 0 ? true : false;
790 /* Set the right machine number for a MIPS ELF file. */
793 mips_elf_object_p (abfd
)
796 switch (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
)
800 /* Just use the default, which was set in elfcode.h. */
804 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 6000);
808 (void) bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, 4000);
812 /* Irix 5 is broken. Object file symbol tables are not always
813 sorted correctly such that local symbols precede global symbols,
814 and the sh_info field in the symbol table is not always right.
815 We try to quickly check whether the symbol table is broken for
816 this BFD, and, if it is, we set elf_bad_symtab in tdata. */
817 if (elf_onesymtab (abfd
) != 0)
819 Elf_Internal_Shdr
*symtab_hdr
;
820 Elf32_External_Sym esym
;
822 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
824 (symtab_hdr
->sh_offset
825 + symtab_hdr
->sh_size
826 - sizeof (Elf32_External_Sym
)),
828 || (bfd_read ((PTR
) &esym
, 1, sizeof (Elf32_External_Sym
), abfd
)
829 != sizeof (Elf32_External_Sym
)))
831 if (ELF_ST_BIND (bfd_h_get_8 (abfd
, (bfd_byte
*) esym
.st_info
))
833 elf_bad_symtab (abfd
) = true;
839 /* The final processing done just before writing out a MIPS ELF object
840 file. This gets the MIPS architecture right based on the machine
845 mips_elf_final_write_processing (abfd
, linker
)
851 Elf_Internal_Shdr
**hdrpp
;
853 switch (bfd_get_mach (abfd
))
871 elf_elfheader (abfd
)->e_flags
&=~ EF_MIPS_ARCH
;
872 elf_elfheader (abfd
)->e_flags
|= val
;
874 /* Set the sh_info field for .gptab sections. */
875 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
876 i
< elf_elfheader (abfd
)->e_shnum
;
879 if ((*hdrpp
)->sh_type
== SHT_MIPS_GPTAB
)
884 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
885 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
886 BFD_ASSERT (name
!= NULL
887 && strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0);
888 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
889 BFD_ASSERT (sec
!= NULL
);
890 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
895 /* Handle a MIPS specific section when reading an object file. This
896 is called when elfcode.h finds a section with an unknown type.
897 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
901 mips_elf_section_from_shdr (abfd
, hdr
, name
)
903 Elf32_Internal_Shdr
*hdr
;
908 /* There ought to be a place to keep ELF backend specific flags, but
909 at the moment there isn't one. We just keep track of the
910 sections by their name, instead. Fortunately, the ABI gives
911 suggested names for all the MIPS specific sections, so we will
912 probably get away with this. */
913 switch (hdr
->sh_type
)
915 case SHT_MIPS_LIBLIST
:
916 if (strcmp (name
, ".liblist") != 0)
919 case SHT_MIPS_CONFLICT
:
920 if (strcmp (name
, ".conflict") != 0)
924 if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) != 0)
928 if (strcmp (name
, ".ucode") != 0)
932 if (strcmp (name
, ".mdebug") != 0)
935 case SHT_MIPS_REGINFO
:
936 if (strcmp (name
, ".reginfo") != 0
937 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
940 case SHT_MIPS_OPTIONS
:
941 if (strcmp (name
, ".options") != 0)
948 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
950 newsect
= hdr
->bfd_section
;
952 if (hdr
->sh_type
== SHT_MIPS_DEBUG
)
954 if (! bfd_set_section_flags (abfd
, newsect
,
955 (bfd_get_section_flags (abfd
, newsect
)
960 /* FIXME: We should record sh_info for a .gptab section. */
962 /* For a .reginfo section, set the gp value in the tdata information
963 from the contents of this section. We need the gp value while
964 processing relocs, so we just get it now. */
965 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
967 Elf32_External_RegInfo ext
;
970 if (! bfd_get_section_contents (abfd
, newsect
, (PTR
) &ext
,
971 (file_ptr
) 0, sizeof ext
))
973 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
974 elf_gp (abfd
) = s
.ri_gp_value
;
980 /* Set the correct type for a MIPS ELF section. We do this by the
981 section name, which is a hack, but ought to work. */
984 mips_elf_fake_sections (abfd
, hdr
, sec
)
986 Elf32_Internal_Shdr
*hdr
;
989 register const char *name
;
991 name
= bfd_get_section_name (abfd
, sec
);
993 if (strcmp (name
, ".liblist") == 0)
995 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
996 hdr
->sh_info
= sec
->_raw_size
/ sizeof (Elf32_Lib
);
997 /* FIXME: Set the sh_link field. */
999 else if (strcmp (name
, ".conflict") == 0)
1000 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
1001 else if (strncmp (name
, ".gptab.", sizeof ".gptab." - 1) == 0)
1003 hdr
->sh_type
= SHT_MIPS_GPTAB
;
1004 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
1005 /* The sh_info field is set in mips_elf_final_write_processing. */
1007 else if (strcmp (name
, ".ucode") == 0)
1008 hdr
->sh_type
= SHT_MIPS_UCODE
;
1009 else if (strcmp (name
, ".mdebug") == 0)
1011 hdr
->sh_type
= SHT_MIPS_DEBUG
;
1012 hdr
->sh_entsize
= 1;
1014 else if (strcmp (name
, ".reginfo") == 0)
1016 hdr
->sh_type
= SHT_MIPS_REGINFO
;
1017 hdr
->sh_entsize
= 1;
1019 /* Force the section size to the correct value, even if the
1020 linker thinks it is larger. The link routine below will only
1021 write out this much data for .reginfo. */
1022 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf32_External_RegInfo
);
1024 else if (strcmp (name
, ".options") == 0)
1026 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
1027 hdr
->sh_entsize
= 1;
1033 /* Given a BFD section, try to locate the corresponding ELF section
1037 mips_elf_section_from_bfd_section (abfd
, hdr
, sec
, retval
)
1039 Elf32_Internal_Shdr
*hdr
;
1043 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
1045 *retval
= SHN_MIPS_SCOMMON
;
1051 /* Work over a section just before writing it out. We update the GP
1052 value in the .reginfo section based on the value we are using.
1053 FIXME: We recognize sections that need the SHF_MIPS_GPREL flag by
1054 name; there has to be a better way. */
1057 mips_elf_section_processing (abfd
, hdr
)
1059 Elf32_Internal_Shdr
*hdr
;
1061 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
1065 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
1066 BFD_ASSERT (hdr
->contents
== NULL
);
1069 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
1072 bfd_h_put_32 (abfd
, (bfd_vma
) elf_gp (abfd
), buf
);
1073 if (bfd_write (buf
, (bfd_size_type
) 1, (bfd_size_type
) 4, abfd
) != 4)
1077 if (hdr
->bfd_section
!= NULL
)
1079 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
1081 if (strcmp (name
, ".sdata") == 0)
1083 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1084 hdr
->sh_type
= SHT_PROGBITS
;
1086 else if (strcmp (name
, ".sbss") == 0)
1088 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1089 hdr
->sh_type
= SHT_NOBITS
;
1091 else if (strcmp (name
, ".lit8") == 0
1092 || strcmp (name
, ".lit4") == 0)
1094 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
1095 hdr
->sh_type
= SHT_PROGBITS
;
1102 /* MIPS ELF uses two common sections. One is the usual one, and the
1103 other is for small objects. All the small objects are kept
1104 together, and then referenced via the gp pointer, which yields
1105 faster assembler code. This is what we use for the small common
1106 section. This approach is copied from ecoff.c. */
1107 static asection mips_elf_scom_section
;
1108 static asymbol mips_elf_scom_symbol
;
1109 static asymbol
*mips_elf_scom_symbol_ptr
;
1111 /* MIPS ELF also uses an acommon section, which represents an
1112 allocated common symbol which may be overridden by a
1113 definition in a shared library. */
1114 static asection mips_elf_acom_section
;
1115 static asymbol mips_elf_acom_symbol
;
1116 static asymbol
*mips_elf_acom_symbol_ptr
;
1118 /* Handle the special MIPS section numbers that a symbol may use. */
1121 mips_elf_symbol_processing (abfd
, asym
)
1125 elf_symbol_type
*elfsym
;
1127 elfsym
= (elf_symbol_type
*) asym
;
1128 switch (elfsym
->internal_elf_sym
.st_shndx
)
1130 case SHN_MIPS_ACOMMON
:
1131 /* This section is used in a dynamically linked executable file.
1132 It is an allocated common section. The dynamic linker can
1133 either resolve these symbols to something in a shared
1134 library, or it can just leave them here. For our purposes,
1135 we can consider these symbols to be in a new section. */
1136 if (mips_elf_acom_section
.name
== NULL
)
1138 /* Initialize the acommon section. */
1139 mips_elf_acom_section
.name
= ".acommon";
1140 mips_elf_acom_section
.flags
= SEC_NO_FLAGS
;
1141 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
1142 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
1143 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
1144 mips_elf_acom_symbol
.name
= ".acommon";
1145 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
1146 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
1147 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
1149 asym
->section
= &mips_elf_acom_section
;
1153 /* Common symbols less than the GP size are automatically
1154 treated as SHN_MIPS_SCOMMON symbols. */
1155 if (asym
->value
> elf_gp_size (abfd
))
1158 case SHN_MIPS_SCOMMON
:
1159 if (mips_elf_scom_section
.name
== NULL
)
1161 /* Initialize the small common section. */
1162 mips_elf_scom_section
.name
= ".scommon";
1163 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
1164 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
1165 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
1166 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
1167 mips_elf_scom_symbol
.name
= ".scommon";
1168 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
1169 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
1170 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
1172 asym
->section
= &mips_elf_scom_section
;
1173 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
1176 case SHN_MIPS_SUNDEFINED
:
1177 asym
->section
= bfd_und_section_ptr
;
1182 /* Read ECOFF debugging information from a .mdebug section into a
1183 ecoff_debug_info structure. */
1186 mips_elf_read_ecoff_info (abfd
, section
, debug
)
1189 struct ecoff_debug_info
*debug
;
1192 const struct ecoff_debug_swap
*swap
;
1193 char *ext_hdr
= NULL
;
1195 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1197 ext_hdr
= (char *) malloc (swap
->external_hdr_size
);
1198 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1200 bfd_set_error (bfd_error_no_memory
);
1204 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
1205 swap
->external_hdr_size
)
1209 symhdr
= &debug
->symbolic_header
;
1210 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1212 /* The symbolic header contains absolute file offsets and sizes to
1214 #define READ(ptr, offset, count, size, type) \
1215 if (symhdr->count == 0) \
1216 debug->ptr = NULL; \
1219 debug->ptr = (type) malloc (size * symhdr->count); \
1220 if (debug->ptr == NULL) \
1222 bfd_set_error (bfd_error_no_memory); \
1223 goto error_return; \
1225 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1226 || (bfd_read (debug->ptr, size, symhdr->count, \
1227 abfd) != size * symhdr->count)) \
1228 goto error_return; \
1231 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1232 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
1233 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
1234 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
1235 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
1236 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1238 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1239 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1240 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
1241 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
1242 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
1246 debug
->adjust
= NULL
;
1251 if (ext_hdr
!= NULL
)
1253 if (debug
->line
!= NULL
)
1255 if (debug
->external_dnr
!= NULL
)
1256 free (debug
->external_dnr
);
1257 if (debug
->external_pdr
!= NULL
)
1258 free (debug
->external_pdr
);
1259 if (debug
->external_sym
!= NULL
)
1260 free (debug
->external_sym
);
1261 if (debug
->external_opt
!= NULL
)
1262 free (debug
->external_opt
);
1263 if (debug
->external_aux
!= NULL
)
1264 free (debug
->external_aux
);
1265 if (debug
->ss
!= NULL
)
1267 if (debug
->ssext
!= NULL
)
1268 free (debug
->ssext
);
1269 if (debug
->external_fdr
!= NULL
)
1270 free (debug
->external_fdr
);
1271 if (debug
->external_rfd
!= NULL
)
1272 free (debug
->external_rfd
);
1273 if (debug
->external_ext
!= NULL
)
1274 free (debug
->external_ext
);
1278 /* The MIPS ELF linker needs additional information for each symbol in
1279 the global hash table. */
1281 struct mips_elf_link_hash_entry
1283 struct elf_link_hash_entry root
;
1285 /* External symbol information. */
1289 /* MIPS ELF linker hash table. */
1291 struct mips_elf_link_hash_table
1293 struct elf_link_hash_table root
;
1296 /* Look up an entry in a MIPS ELF linker hash table. */
1298 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
1299 ((struct mips_elf_link_hash_entry *) \
1300 elf_link_hash_lookup (&(table)->root, (string), (create), \
1303 /* Traverse a MIPS ELF linker hash table. */
1305 #define mips_elf_link_hash_traverse(table, func, info) \
1306 (elf_link_hash_traverse \
1308 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
1311 /* Get the MIPS ELF linker hash table from a link_info structure. */
1313 #define mips_elf_hash_table(p) \
1314 ((struct mips_elf_link_hash_table *) ((p)->hash))
1316 static boolean mips_elf_output_extsym
1317 PARAMS ((struct mips_elf_link_hash_entry
*, PTR
));
1319 /* Create an entry in a MIPS ELF linker hash table. */
1321 static struct bfd_hash_entry
*
1322 mips_elf_link_hash_newfunc (entry
, table
, string
)
1323 struct bfd_hash_entry
*entry
;
1324 struct bfd_hash_table
*table
;
1327 struct mips_elf_link_hash_entry
*ret
=
1328 (struct mips_elf_link_hash_entry
*) entry
;
1330 /* Allocate the structure if it has not already been allocated by a
1332 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
1333 ret
= ((struct mips_elf_link_hash_entry
*)
1334 bfd_hash_allocate (table
,
1335 sizeof (struct mips_elf_link_hash_entry
)));
1336 if (ret
== (struct mips_elf_link_hash_entry
*) NULL
)
1338 bfd_set_error (bfd_error_no_memory
);
1339 return (struct bfd_hash_entry
*) ret
;
1342 /* Call the allocation method of the superclass. */
1343 ret
= ((struct mips_elf_link_hash_entry
*)
1344 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1346 if (ret
!= (struct mips_elf_link_hash_entry
*) NULL
)
1348 /* Set local fields. */
1349 memset (&ret
->esym
, 0, sizeof (EXTR
));
1350 /* We use -2 as a marker to indicate that the information has
1351 not been set. -1 means there is no associated ifd. */
1355 return (struct bfd_hash_entry
*) ret
;
1358 /* Create a MIPS ELF linker hash table. */
1360 static struct bfd_link_hash_table
*
1361 mips_elf_link_hash_table_create (abfd
)
1364 struct mips_elf_link_hash_table
*ret
;
1366 ret
= ((struct mips_elf_link_hash_table
*)
1367 bfd_alloc (abfd
, sizeof (struct mips_elf_link_hash_table
)));
1368 if (ret
== (struct mips_elf_link_hash_table
*) NULL
)
1370 bfd_set_error (bfd_error_no_memory
);
1374 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
1375 mips_elf_link_hash_newfunc
))
1377 bfd_release (abfd
, ret
);
1381 return &ret
->root
.root
;
1384 /* Hook called by the linker routine which adds symbols from an object
1385 file. We must handle the special MIPS section numbers here. */
1389 mips_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1391 struct bfd_link_info
*info
;
1392 const Elf_Internal_Sym
*sym
;
1398 switch (sym
->st_shndx
)
1401 /* Common symbols less than the GP size are automatically
1402 treated as SHN_MIPS_SCOMMON symbols. */
1403 if (sym
->st_size
> elf_gp_size (abfd
))
1406 case SHN_MIPS_SCOMMON
:
1407 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
1408 (*secp
)->flags
|= SEC_IS_COMMON
;
1409 *valp
= sym
->st_size
;
1412 case SHN_MIPS_SUNDEFINED
:
1413 *secp
= bfd_und_section_ptr
;
1420 /* Structure used to pass information to mips_elf_output_extsym. */
1425 struct bfd_link_info
*info
;
1426 struct ecoff_debug_info
*debug
;
1427 const struct ecoff_debug_swap
*swap
;
1431 /* This routine is used to write out ECOFF debugging external symbol
1432 information. It is called via mips_elf_link_hash_traverse. The
1433 ECOFF external symbol information must match the ELF external
1434 symbol information. Unfortunately, at this point we don't know
1435 whether a symbol is required by reloc information, so the two
1436 tables may wind up being different. We must sort out the external
1437 symbol information before we can set the final size of the .mdebug
1438 section, and we must set the size of the .mdebug section before we
1439 can relocate any sections, and we can't know which symbols are
1440 required by relocation until we relocate the sections.
1441 Fortunately, it is relatively unlikely that any symbol will be
1442 stripped but required by a reloc. In particular, it can not happen
1443 when generating a final executable. */
1446 mips_elf_output_extsym (h
, data
)
1447 struct mips_elf_link_hash_entry
*h
;
1450 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
1453 if (h
->root
.indx
== -2)
1455 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1456 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
1457 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
1458 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
1460 else if (einfo
->info
->strip
== strip_all
1461 || (einfo
->info
->strip
== strip_some
1462 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1463 h
->root
.root
.root
.string
,
1464 false, false) == NULL
))
1472 if (h
->esym
.ifd
== -2)
1475 h
->esym
.cobol_main
= 0;
1476 h
->esym
.weakext
= 0;
1477 h
->esym
.reserved
= 0;
1478 h
->esym
.ifd
= ifdNil
;
1479 h
->esym
.asym
.value
= 0;
1480 h
->esym
.asym
.st
= stGlobal
;
1482 if (h
->root
.root
.type
!= bfd_link_hash_defined
)
1483 h
->esym
.asym
.sc
= scAbs
;
1486 asection
*output_section
;
1489 output_section
= h
->root
.root
.u
.def
.section
->output_section
;
1490 name
= bfd_section_name (output_section
->owner
, output_section
);
1492 if (strcmp (name
, ".text") == 0)
1493 h
->esym
.asym
.sc
= scText
;
1494 else if (strcmp (name
, ".data") == 0)
1495 h
->esym
.asym
.sc
= scData
;
1496 else if (strcmp (name
, ".sdata") == 0)
1497 h
->esym
.asym
.sc
= scSData
;
1498 else if (strcmp (name
, ".rodata") == 0
1499 || strcmp (name
, ".rdata") == 0)
1500 h
->esym
.asym
.sc
= scRData
;
1501 else if (strcmp (name
, ".bss") == 0)
1502 h
->esym
.asym
.sc
= scBss
;
1503 else if (strcmp (name
, ".sbss") == 0)
1504 h
->esym
.asym
.sc
= scSBss
;
1505 else if (strcmp (name
, ".init") == 0)
1506 h
->esym
.asym
.sc
= scInit
;
1507 else if (strcmp (name
, ".fini") == 0)
1508 h
->esym
.asym
.sc
= scFini
;
1510 h
->esym
.asym
.sc
= scAbs
;
1513 h
->esym
.asym
.reserved
= 0;
1514 h
->esym
.asym
.index
= indexNil
;
1518 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1519 h
->root
.root
.root
.string
,
1522 einfo
->failed
= true;
1529 /* A comparison routine used to sort .gptab entries. */
1532 gptab_compare (p1
, p2
)
1536 const Elf32_gptab
*a1
= (const Elf32_gptab
*) p1
;
1537 const Elf32_gptab
*a2
= (const Elf32_gptab
*) p2
;
1539 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
1542 /* We need to use a special link routine to handle the .reginfo and
1543 the .mdebug sections. We need to merge all instances of these
1544 sections together, not write them all out sequentially. */
1547 mips_elf_final_link (abfd
, info
)
1549 struct bfd_link_info
*info
;
1553 struct bfd_link_order
*p
;
1554 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
1555 Elf32_RegInfo reginfo
;
1556 struct ecoff_debug_info debug
;
1557 const struct ecoff_debug_swap
*swap
1558 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1559 HDRR
*symhdr
= &debug
.symbolic_header
;
1560 PTR mdebug_handle
= NULL
;
1562 /* Drop the .options section, since it has special semantics which I
1563 haven't bothered to figure out. */
1564 for (secpp
= &abfd
->sections
; *secpp
!= NULL
; secpp
= &(*secpp
)->next
)
1566 if (strcmp ((*secpp
)->name
, ".options") == 0)
1568 for (p
= (*secpp
)->link_order_head
; p
!= NULL
; p
= p
->next
)
1569 if (p
->type
== bfd_indirect_link_order
)
1570 p
->u
.indirect
.section
->flags
&=~ SEC_HAS_CONTENTS
;
1571 (*secpp
)->link_order_head
= NULL
;
1572 *secpp
= (*secpp
)->next
;
1573 --abfd
->section_count
;
1578 /* Go through the sections and collect the .reginfo and .mdebug
1582 gptab_data_sec
= NULL
;
1583 gptab_bss_sec
= NULL
;
1584 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
1586 if (strcmp (o
->name
, ".reginfo") == 0)
1588 memset (®info
, 0, sizeof reginfo
);
1590 /* We have found the .reginfo section in the output file.
1591 Look through all the link_orders comprising it and merge
1592 the information together. */
1593 for (p
= o
->link_order_head
;
1594 p
!= (struct bfd_link_order
*) NULL
;
1597 asection
*input_section
;
1599 Elf32_External_RegInfo ext
;
1602 if (p
->type
!= bfd_indirect_link_order
)
1604 if (p
->type
== bfd_fill_link_order
)
1609 input_section
= p
->u
.indirect
.section
;
1610 input_bfd
= input_section
->owner
;
1611 BFD_ASSERT (input_section
->_raw_size
1612 == sizeof (Elf32_External_RegInfo
));
1613 if (! bfd_get_section_contents (input_bfd
, input_section
,
1619 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
1621 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
1622 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
1623 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
1624 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
1625 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
1627 /* ri_gp_value is set by the function
1628 mips_elf_section_processing when the section is
1629 finally written out. */
1631 /* Hack: reset the SEC_HAS_CONTENTS flag so that
1632 elf_link_input_bfd ignores this section. */
1633 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
1636 /* Force the section size to the value we want. */
1637 o
->_raw_size
= sizeof (Elf32_External_RegInfo
);
1639 /* Skip this section later on (I don't think this currently
1640 matters, but someday it might). */
1641 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
1646 if (strcmp (o
->name
, ".mdebug") == 0)
1648 struct extsym_info einfo
;
1650 /* We have found the .mdebug section in the output file.
1651 Look through all the link_orders comprising it and merge
1652 the information together. */
1653 symhdr
->magic
= swap
->sym_magic
;
1654 /* FIXME: What should the version stamp be? */
1656 symhdr
->ilineMax
= 0;
1660 symhdr
->isymMax
= 0;
1661 symhdr
->ioptMax
= 0;
1662 symhdr
->iauxMax
= 0;
1664 symhdr
->issExtMax
= 0;
1667 symhdr
->iextMax
= 0;
1669 /* We accumulate the debugging information itself in the
1670 debug_info structure. */
1672 debug
.external_dnr
= NULL
;
1673 debug
.external_pdr
= NULL
;
1674 debug
.external_sym
= NULL
;
1675 debug
.external_opt
= NULL
;
1676 debug
.external_aux
= NULL
;
1678 debug
.ssext
= debug
.ssext_end
= NULL
;
1679 debug
.external_fdr
= NULL
;
1680 debug
.external_rfd
= NULL
;
1681 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1683 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
1684 if (mdebug_handle
== (PTR
) NULL
)
1687 for (p
= o
->link_order_head
;
1688 p
!= (struct bfd_link_order
*) NULL
;
1691 asection
*input_section
;
1693 const struct ecoff_debug_swap
*input_swap
;
1694 struct ecoff_debug_info input_debug
;
1698 if (p
->type
!= bfd_indirect_link_order
)
1700 if (p
->type
== bfd_fill_link_order
)
1705 input_section
= p
->u
.indirect
.section
;
1706 input_bfd
= input_section
->owner
;
1708 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
1709 || (get_elf_backend_data (input_bfd
)
1710 ->elf_backend_ecoff_debug_swap
) == NULL
)
1712 /* I don't know what a non MIPS ELF bfd would be
1713 doing with a .mdebug section, but I don't really
1714 want to deal with it. */
1718 input_swap
= (get_elf_backend_data (input_bfd
)
1719 ->elf_backend_ecoff_debug_swap
);
1721 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
1723 /* The ECOFF linking code expects that we have already
1724 read in the debugging information and set up an
1725 ecoff_debug_info structure, so we do that now. */
1726 if (! mips_elf_read_ecoff_info (input_bfd
, input_section
,
1730 if (! (bfd_ecoff_debug_accumulate
1731 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
1732 &input_debug
, input_swap
, info
)))
1735 /* Loop through the external symbols. For each one with
1736 interesting information, try to find the symbol in
1737 the linker global hash table and save the information
1738 for the output external symbols. */
1739 eraw_src
= input_debug
.external_ext
;
1740 eraw_end
= (eraw_src
1741 + (input_debug
.symbolic_header
.iextMax
1742 * input_swap
->external_ext_size
));
1744 eraw_src
< eraw_end
;
1745 eraw_src
+= input_swap
->external_ext_size
)
1749 struct mips_elf_link_hash_entry
*h
;
1751 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
1752 if (ext
.asym
.sc
== scNil
1753 || ext
.asym
.sc
== scUndefined
1754 || ext
.asym
.sc
== scSUndefined
)
1757 name
= input_debug
.ssext
+ ext
.asym
.iss
;
1758 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
1759 name
, false, false, true);
1760 if (h
== NULL
|| h
->esym
.ifd
!= -2)
1766 < input_debug
.symbolic_header
.ifdMax
);
1767 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
1773 /* Free up the information we just read. */
1774 free (input_debug
.line
);
1775 free (input_debug
.external_dnr
);
1776 free (input_debug
.external_pdr
);
1777 free (input_debug
.external_sym
);
1778 free (input_debug
.external_opt
);
1779 free (input_debug
.external_aux
);
1780 free (input_debug
.ss
);
1781 free (input_debug
.ssext
);
1782 free (input_debug
.external_fdr
);
1783 free (input_debug
.external_rfd
);
1784 free (input_debug
.external_ext
);
1786 /* Hack: reset the SEC_HAS_CONTENTS flag so that
1787 elf_link_input_bfd ignores this section. */
1788 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
1791 /* Build the external symbol information. */
1794 einfo
.debug
= &debug
;
1796 einfo
.failed
= false;
1797 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
1798 mips_elf_output_extsym
,
1803 /* Set the size of the .mdebug section. */
1804 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
1806 /* Skip this section later on (I don't think this currently
1807 matters, but someday it might). */
1808 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
1813 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
1815 const char *subname
;
1818 Elf32_External_gptab
*ext_tab
;
1821 /* The .gptab.sdata and .gptab.sbss sections hold
1822 information describing how the small data area would
1823 change depending upon the -G switch. These sections
1824 not used in executables files. */
1825 if (! info
->relocateable
)
1829 for (p
= o
->link_order_head
;
1830 p
!= (struct bfd_link_order
*) NULL
;
1833 asection
*input_section
;
1835 if (p
->type
!= bfd_indirect_link_order
)
1837 if (p
->type
== bfd_fill_link_order
)
1842 input_section
= p
->u
.indirect
.section
;
1844 /* Hack: reset the SEC_HAS_CONTENTS flag so that
1845 elf_link_input_bfd ignores this section. */
1846 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
1849 /* Skip this section later on (I don't think this
1850 currently matters, but someday it might). */
1851 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
1853 /* Really remove the section. */
1854 for (secpp
= &abfd
->sections
;
1856 secpp
= &(*secpp
)->next
)
1858 *secpp
= (*secpp
)->next
;
1859 --abfd
->section_count
;
1864 /* There is one gptab for initialized data, and one for
1865 uninitialized data. */
1866 if (strcmp (o
->name
, ".gptab.sdata") == 0)
1868 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
1872 bfd_set_error (bfd_error_nonrepresentable_section
);
1876 /* The linker script always combines .gptab.data and
1877 .gptab.sdata into .gptab.sdata, and likewise for
1878 .gptab.bss and .gptab.sbss. It is possible that there is
1879 no .sdata or .sbss section in the output file, in which
1880 case we must change the name of the output section. */
1881 subname
= o
->name
+ sizeof ".gptab" - 1;
1882 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
1884 if (o
== gptab_data_sec
)
1885 o
->name
= ".gptab.data";
1887 o
->name
= ".gptab.bss";
1888 subname
= o
->name
+ sizeof ".gptab" - 1;
1889 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
1892 /* Set up the first entry. */
1894 tab
= (Elf32_gptab
*) malloc (c
* sizeof (Elf32_gptab
));
1897 bfd_set_error (bfd_error_no_memory
);
1900 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
1901 tab
[0].gt_header
.gt_unused
= 0;
1903 /* Combine the input sections. */
1904 for (p
= o
->link_order_head
;
1905 p
!= (struct bfd_link_order
*) NULL
;
1908 asection
*input_section
;
1912 bfd_size_type gpentry
;
1914 if (p
->type
!= bfd_indirect_link_order
)
1916 if (p
->type
== bfd_fill_link_order
)
1921 input_section
= p
->u
.indirect
.section
;
1922 input_bfd
= input_section
->owner
;
1924 /* Combine the gptab entries for this input section one
1925 by one. We know that the input gptab entries are
1926 sorted by ascending -G value. */
1927 size
= bfd_section_size (input_bfd
, input_section
);
1929 for (gpentry
= sizeof (Elf32_External_gptab
);
1931 gpentry
+= sizeof (Elf32_External_gptab
))
1933 Elf32_External_gptab ext_gptab
;
1934 Elf32_gptab int_gptab
;
1940 if (! (bfd_get_section_contents
1941 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
1942 gpentry
, sizeof (Elf32_External_gptab
))))
1948 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
1950 val
= int_gptab
.gt_entry
.gt_g_value
;
1951 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
1954 for (look
= 1; look
< c
; look
++)
1956 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
1957 tab
[look
].gt_entry
.gt_bytes
+= add
;
1959 if (tab
[look
].gt_entry
.gt_g_value
== val
)
1965 Elf32_gptab
*new_tab
;
1968 /* We need a new table entry. */
1969 new_tab
= ((Elf32_gptab
*)
1971 (c
+ 1) * sizeof (Elf32_gptab
)));
1972 if (new_tab
== NULL
)
1974 bfd_set_error (bfd_error_no_memory
);
1979 tab
[c
].gt_entry
.gt_g_value
= val
;
1980 tab
[c
].gt_entry
.gt_bytes
= add
;
1982 /* Merge in the size for the next smallest -G
1983 value, since that will be implied by this new
1986 for (look
= 1; look
< c
; look
++)
1988 if (tab
[look
].gt_entry
.gt_g_value
< val
1990 || (tab
[look
].gt_entry
.gt_g_value
1991 > tab
[max
].gt_entry
.gt_g_value
)))
1995 tab
[c
].gt_entry
.gt_bytes
+=
1996 tab
[max
].gt_entry
.gt_bytes
;
2001 last
= int_gptab
.gt_entry
.gt_bytes
;
2004 /* Hack: reset the SEC_HAS_CONTENTS flag so that
2005 elf_link_input_bfd ignores this section. */
2006 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
2009 /* The table must be sorted by -G value. */
2011 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
2013 /* Swap out the table. */
2014 ext_tab
= ((Elf32_External_gptab
*)
2015 bfd_alloc (abfd
, c
* sizeof (Elf32_External_gptab
)));
2016 if (ext_tab
== NULL
)
2018 bfd_set_error (bfd_error_no_memory
);
2023 for (i
= 0; i
< c
; i
++)
2024 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
2027 o
->_raw_size
= c
* sizeof (Elf32_External_gptab
);
2028 o
->contents
= (bfd_byte
*) ext_tab
;
2030 /* Skip this section later on (I don't think this currently
2031 matters, but someday it might). */
2032 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
2036 /* Get a value for the GP register. */
2037 if (elf_gp (abfd
) == 0)
2039 struct bfd_link_hash_entry
*h
;
2041 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
2042 if (h
!= (struct bfd_link_hash_entry
*) NULL
2043 && h
->type
== bfd_link_hash_defined
)
2044 elf_gp (abfd
) = (h
->u
.def
.value
2045 + h
->u
.def
.section
->output_section
->vma
2046 + h
->u
.def
.section
->output_offset
);
2047 else if (info
->relocateable
)
2051 /* Make up a value. */
2053 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2056 && (strcmp (o
->name
, ".sbss") == 0
2057 || strcmp (o
->name
, ".sdata") == 0
2058 || strcmp (o
->name
, ".lit4") == 0
2059 || strcmp (o
->name
, ".lit8") == 0))
2062 elf_gp (abfd
) = lo
+ 0x8000;
2066 /* If the relocate_section function needs to do a reloc
2067 involving the GP value, it should make a reloc_dangerous
2068 callback to warn that GP is not defined. */
2072 /* Invoke the regular ELF backend linker to do all the work. */
2073 if (! bfd_elf32_bfd_final_link (abfd
, info
))
2076 /* Now write out the computed sections. */
2078 if (reginfo_sec
!= (asection
*) NULL
)
2080 Elf32_External_RegInfo ext
;
2082 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
2083 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
2084 (file_ptr
) 0, sizeof ext
))
2088 if (mdebug_sec
!= (asection
*) NULL
)
2090 BFD_ASSERT (abfd
->output_has_begun
);
2091 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
2093 mdebug_sec
->filepos
))
2096 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
2099 if (gptab_data_sec
!= (asection
*) NULL
)
2101 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
2102 gptab_data_sec
->contents
,
2104 gptab_data_sec
->_raw_size
))
2108 if (gptab_bss_sec
!= (asection
*) NULL
)
2110 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
2111 gptab_bss_sec
->contents
,
2113 gptab_bss_sec
->_raw_size
))
2120 /* Handle a MIPS ELF HI16 reloc. */
2123 mips_elf_relocate_hi16 (input_bfd
, relhi
, rello
, contents
, addend
)
2125 Elf_Internal_Rela
*relhi
;
2126 Elf_Internal_Rela
*rello
;
2133 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
2135 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
2138 addend
+= ((insn
& 0xffff) << 16) + addlo
;
2140 if ((addlo
& 0x8000) != 0)
2142 if ((addend
& 0x8000) != 0)
2145 bfd_put_32 (input_bfd
,
2146 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
2147 contents
+ relhi
->r_offset
);
2150 /* Relocate a MIPS ELF section. */
2153 mips_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2154 contents
, relocs
, local_syms
, local_sections
,
2157 struct bfd_link_info
*info
;
2159 asection
*input_section
;
2161 Elf_Internal_Rela
*relocs
;
2162 Elf_Internal_Sym
*local_syms
;
2163 asection
**local_sections
;
2166 Elf_Internal_Shdr
*symtab_hdr
;
2169 Elf_Internal_Rela
*rel
;
2170 Elf_Internal_Rela
*relend
;
2172 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2174 if (elf_bad_symtab (input_bfd
))
2176 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
2181 locsymcount
= symtab_hdr
->sh_info
;
2182 extsymoff
= symtab_hdr
->sh_info
;
2186 relend
= relocs
+ input_section
->reloc_count
;
2187 for (; rel
< relend
; rel
++)
2190 const reloc_howto_type
*howto
;
2193 struct elf_link_hash_entry
*h
;
2195 Elf_Internal_Sym
*sym
;
2196 bfd_reloc_status_type r
;
2198 r_type
= ELF32_R_TYPE (rel
->r_info
);
2199 if (r_type
< 0 || r_type
>= (int) R_MIPS_max
)
2201 bfd_set_error (bfd_error_bad_value
);
2204 howto
= elf_mips_howto_table
+ r_type
;
2206 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2208 /* Mix in the change in GP address for a GP relative reloc. */
2209 if (r_type
!= R_MIPS_GPREL16
2210 && r_type
!= R_MIPS_LITERAL
2211 && r_type
!= R_MIPS_GPREL32
)
2215 if (elf_gp (output_bfd
) == 0)
2217 if (! ((*info
->callbacks
->reloc_dangerous
)
2219 "GP relative relocation when GP not defined",
2220 input_bfd
, input_section
,
2223 /* Only give the error once per link. */
2224 elf_gp (output_bfd
) = 4;
2227 if (r_symndx
< extsymoff
2228 || (elf_bad_symtab (input_bfd
)
2229 && local_sections
[r_symndx
] != NULL
))
2231 /* This is a relocation against a section. The current
2232 addend in the instruction is the difference between
2233 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
2234 must change this to be the difference between the
2235 final definition (which will end up in RELOCATION)
2236 and the GP value of OUTPUT_BFD (which is in GP). */
2237 addend
= elf_gp (input_bfd
) - elf_gp (output_bfd
);
2239 else if (! info
->relocateable
)
2241 /* We are doing a final link. The current addend in the
2242 instruction is simply the desired offset into the
2243 symbol (normally zero). We want the instruction to
2244 hold the difference between the final definition of
2245 the symbol (which will end up in RELOCATION) and the
2246 GP value of OUTPUT_BFD (which is in GP). */
2247 addend
= - elf_gp (output_bfd
);
2251 /* We are generating relocateable output, and we aren't
2252 going to define this symbol, so we just leave the
2253 instruction alone. */
2261 if (info
->relocateable
)
2263 /* This is a relocateable link. We don't have to change
2264 anything, unless the reloc is against a section symbol,
2265 in which case we have to adjust according to where the
2266 section symbol winds up in the output section. */
2267 if (r_symndx
>= locsymcount
2268 || (elf_bad_symtab (input_bfd
)
2269 && local_sections
[r_symndx
] == NULL
))
2273 sym
= local_syms
+ r_symndx
;
2274 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2278 sec
= local_sections
[r_symndx
];
2280 /* It would be logical to add sym->st_value here,
2281 but Irix 5 sometimes generates a garbage symbol
2283 addend
+= sec
->output_offset
;
2285 /* If this is HI16 with an associated LO16, adjust
2286 the addend accordingly. Otherwise, just
2288 if (r_type
!= R_MIPS_HI16
2289 || (rel
+ 1) >= relend
2290 || ELF32_R_TYPE ((rel
+ 1)->r_info
) != R_MIPS_LO16
)
2291 r
= _bfd_relocate_contents (howto
, input_bfd
,
2293 contents
+ rel
->r_offset
);
2296 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1,
2307 /* This is a final link. */
2309 if (r_symndx
< extsymoff
2310 || (elf_bad_symtab (input_bfd
)
2311 && local_sections
[r_symndx
] != NULL
))
2313 sym
= local_syms
+ r_symndx
;
2314 sec
= local_sections
[r_symndx
];
2315 relocation
= (sec
->output_section
->vma
2316 + sec
->output_offset
);
2318 /* It would be logical to always add sym->st_value here,
2319 but Irix 5 sometimes generates a garbage symbol
2321 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2322 relocation
+= sym
->st_value
;
2328 indx
= r_symndx
- extsymoff
;
2329 h
= elf_sym_hashes (input_bfd
)[indx
];
2330 if (h
->root
.type
== bfd_link_hash_defined
)
2332 sec
= h
->root
.u
.def
.section
;
2333 relocation
= (h
->root
.u
.def
.value
2334 + sec
->output_section
->vma
2335 + sec
->output_offset
);
2337 else if (h
->root
.type
== bfd_link_hash_weak
)
2341 if (! ((*info
->callbacks
->undefined_symbol
)
2342 (info
, h
->root
.root
.string
, input_bfd
,
2343 input_section
, rel
->r_offset
)))
2349 if (r_type
!= R_MIPS_HI16
2350 || (rel
+ 1) >= relend
2351 || ELF32_R_TYPE ((rel
+ 1)->r_info
) != R_MIPS_LO16
)
2352 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2353 contents
, rel
->r_offset
,
2354 relocation
, addend
);
2357 mips_elf_relocate_hi16 (input_bfd
, rel
, rel
+ 1,
2358 contents
, relocation
+ addend
);
2363 if (r
!= bfd_reloc_ok
)
2368 case bfd_reloc_outofrange
:
2370 case bfd_reloc_overflow
:
2375 name
= h
->root
.root
.string
;
2378 name
= output_names
+ sym
->st_name
;
2382 name
= bfd_section_name (input_bfd
, sec
);
2384 if (! ((*info
->callbacks
->reloc_overflow
)
2385 (info
, name
, howto
->name
, (bfd_vma
) 0,
2386 input_bfd
, input_section
, rel
->r_offset
)))
2397 /* ECOFF swapping routines. These are used when dealing with the
2398 .mdebug section, which is in the ECOFF debugging format. */
2399 static const struct ecoff_debug_swap mips_elf_ecoff_debug_swap
=
2401 /* Symbol table magic number. */
2403 /* Alignment of debugging information. E.g., 4. */
2405 /* Sizes of external symbolic information. */
2406 sizeof (struct hdr_ext
),
2407 sizeof (struct dnr_ext
),
2408 sizeof (struct pdr_ext
),
2409 sizeof (struct sym_ext
),
2410 sizeof (struct opt_ext
),
2411 sizeof (struct fdr_ext
),
2412 sizeof (struct rfd_ext
),
2413 sizeof (struct ext_ext
),
2414 /* Functions to swap in external symbolic data. */
2423 _bfd_ecoff_swap_tir_in
,
2424 _bfd_ecoff_swap_rndx_in
,
2425 /* Functions to swap out external symbolic data. */
2434 _bfd_ecoff_swap_tir_out
,
2435 _bfd_ecoff_swap_rndx_out
,
2436 /* Function to read in symbolic data. */
2437 mips_elf_read_ecoff_info
2440 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
2441 #define TARGET_LITTLE_NAME "elf32-littlemips"
2442 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
2443 #define TARGET_BIG_NAME "elf32-bigmips"
2444 #define ELF_ARCH bfd_arch_mips
2445 #define ELF_MACHINE_CODE EM_MIPS
2446 #define ELF_MAXPAGESIZE 0x10000
2447 #define elf_backend_collect true
2448 #define elf_info_to_howto 0
2449 #define elf_info_to_howto_rel mips_info_to_howto_rel
2450 #define elf_backend_sym_is_global mips_elf_sym_is_global
2451 #define elf_backend_object_p mips_elf_object_p
2452 #define elf_backend_section_from_shdr mips_elf_section_from_shdr
2453 #define elf_backend_fake_sections mips_elf_fake_sections
2454 #define elf_backend_section_from_bfd_section \
2455 mips_elf_section_from_bfd_section
2456 #define elf_backend_section_processing mips_elf_section_processing
2457 #define elf_backend_symbol_processing mips_elf_symbol_processing
2458 #define elf_backend_final_write_processing \
2459 mips_elf_final_write_processing
2460 #define elf_backend_ecoff_debug_swap &mips_elf_ecoff_debug_swap
2462 #define bfd_elf32_bfd_link_hash_table_create \
2463 mips_elf_link_hash_table_create
2464 #define bfd_elf32_bfd_final_link mips_elf_final_link
2465 #define elf_backend_relocate_section mips_elf_relocate_section
2466 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
2468 #include "elf32-target.h"