* config/*/*.mt (TDEPFILES): Remove refs to *-pinsn.o.
[deliverable/binutils-gdb.git] / bfd / elf32-mips.c
CommitLineData
b3c0fc57 1/* MIPS-specific support for 32-bit ELF
9783e04a 2 Copyright 1993, 1994 Free Software Foundation, Inc.
6b4b4d17 3
b3c0fc57
ILT
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
5 <ian@cygnus.com>.
6
6b4b4d17
JK
7This file is part of BFD, the Binary File Descriptor library.
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22
23#include "bfd.h"
24#include "sysdep.h"
25#include "libbfd.h"
6e07e54f
ILT
26#include "bfdlink.h"
27#include "genlink.h"
6b4b4d17 28#include "libelf.h"
b3c0fc57
ILT
29#include "elf/mips.h"
30
6e07e54f
ILT
31/* Get the ECOFF swapping routines. */
32#include "coff/sym.h"
33#include "coff/symconst.h"
34#include "coff/internal.h"
35#include "coff/ecoff.h"
36#include "coff/mips.h"
37#define ECOFF_32
38#include "ecoffswap.h"
39
b3c0fc57
ILT
40static bfd_reloc_status_type mips_elf_hi16_reloc PARAMS ((bfd *abfd,
41 arelent *reloc,
42 asymbol *symbol,
43 PTR data,
44 asection *section,
6e07e54f
ILT
45 bfd *output_bfd,
46 char **error));
47static bfd_reloc_status_type mips_elf_got16_reloc PARAMS ((bfd *abfd,
48 arelent *reloc,
49 asymbol *symbol,
50 PTR data,
51 asection *section,
52 bfd *output_bfd,
53 char **error));
b3c0fc57
ILT
54static bfd_reloc_status_type mips_elf_lo16_reloc PARAMS ((bfd *abfd,
55 arelent *reloc,
56 asymbol *symbol,
57 PTR data,
58 asection *section,
6e07e54f
ILT
59 bfd *output_bfd,
60 char **error));
b3c0fc57
ILT
61static bfd_reloc_status_type mips_elf_gprel16_reloc PARAMS ((bfd *abfd,
62 arelent *reloc,
63 asymbol *symbol,
64 PTR data,
65 asection *section,
6e07e54f
ILT
66 bfd *output_bfd,
67 char **error));
aac6b32f
ILT
68static const struct reloc_howto_struct *bfd_elf32_bfd_reloc_type_lookup
69 PARAMS ((bfd *, bfd_reloc_code_real_type));
70static void mips_info_to_howto_rel
71 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
72static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
73static boolean mips_elf_object_p PARAMS ((bfd *));
24f13b03
ILT
74static void mips_elf_final_write_processing
75 PARAMS ((bfd *, boolean));
aac6b32f
ILT
76static boolean mips_elf_section_from_shdr
77 PARAMS ((bfd *, Elf32_Internal_Shdr *, char *));
78static boolean mips_elf_fake_sections
79 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
80static boolean mips_elf_section_from_bfd_section
81 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *));
82static boolean mips_elf_section_processing
83 PARAMS ((bfd *, Elf32_Internal_Shdr *));
84static void mips_elf_symbol_processing PARAMS ((bfd *, asymbol *));
85static boolean mips_elf_read_ecoff_info
86 PARAMS ((bfd *, asection *, struct ecoff_debug_info *));
87static struct bfd_hash_entry *mips_elf_link_hash_newfunc
88 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
89static struct bfd_link_hash_table *mips_elf_link_hash_table_create
90 PARAMS ((bfd *));
91static int gptab_compare PARAMS ((const void *, const void *));
92static boolean mips_elf_final_link
93 PARAMS ((bfd *, struct bfd_link_info *));
94static void mips_elf_relocate_hi16
95 PARAMS ((bfd *, Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_byte *,
96 bfd_vma));
97static boolean mips_elf_relocate_section
98 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
82b1edf7 99 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
aac6b32f
ILT
100static boolean mips_elf_add_symbol_hook
101 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
102 const char **, flagword *, asection **, bfd_vma *));
b3c0fc57
ILT
103
104#define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
105
106enum reloc_type
107{
108 R_MIPS_NONE = 0,
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,
115 R_MIPS_max
116};
117
118static reloc_howto_type elf_mips_howto_table[] =
119{
120 /* No relocation. */
121 HOWTO (R_MIPS_NONE, /* type */
122 0, /* rightshift */
123 0, /* size (0 = byte, 1 = short, 2 = long) */
124 0, /* bitsize */
125 false, /* pc_relative */
126 0, /* bitpos */
127 complain_overflow_dont, /* complain_on_overflow */
128 bfd_elf_generic_reloc, /* special_function */
129 "R_MIPS_NONE", /* name */
130 false, /* partial_inplace */
131 0, /* src_mask */
132 0, /* dst_mask */
133 false), /* pcrel_offset */
134
135 /* 16 bit relocation. */
136 HOWTO (R_MIPS_16, /* type */
137 0, /* rightshift */
138 1, /* size (0 = byte, 1 = short, 2 = long) */
139 16, /* bitsize */
140 false, /* pc_relative */
141 0, /* bitpos */
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 */
149
150 /* 32 bit relocation. */
151 HOWTO (R_MIPS_32, /* type */
152 0, /* rightshift */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
154 32, /* bitsize */
155 false, /* pc_relative */
156 0, /* bitpos */
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 */
164
165 /* 32 bit symbol relative relocation. */
166 HOWTO (R_MIPS_REL32, /* type */
167 0, /* rightshift */
168 2, /* size (0 = byte, 1 = short, 2 = long) */
169 32, /* bitsize */
170 false, /* pc_relative */
171 0, /* bitpos */
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 */
179
180 /* 26 bit branch address. */
181 HOWTO (R_MIPS_26, /* type */
182 2, /* rightshift */
183 2, /* size (0 = byte, 1 = short, 2 = long) */
184 26, /* bitsize */
185 false, /* pc_relative */
186 0, /* bitpos */
6e07e54f
ILT
187 complain_overflow_dont, /* complain_on_overflow */
188 /* This needs complex overflow
189 detection, because the upper four
190 bits must match the PC. */
b3c0fc57
ILT
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 */
197
198 /* High 16 bits of symbol value. */
199 HOWTO (R_MIPS_HI16, /* type */
200 0, /* rightshift */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
202 16, /* bitsize */
203 false, /* pc_relative */
204 0, /* bitpos */
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 */
212
213 /* Low 16 bits of symbol value. */
214 HOWTO (R_MIPS_LO16, /* type */
215 0, /* rightshift */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
217 16, /* bitsize */
218 false, /* pc_relative */
219 0, /* bitpos */
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 */
227
228 /* GP relative reference. */
229 HOWTO (R_MIPS_GPREL16, /* type */
230 0, /* rightshift */
231 2, /* size (0 = byte, 1 = short, 2 = long) */
232 16, /* bitsize */
233 false, /* pc_relative */
234 0, /* bitpos */
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 */
242
243 /* Reference to literal section. */
244 HOWTO (R_MIPS_LITERAL, /* type */
245 0, /* rightshift */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
247 16, /* bitsize */
248 false, /* pc_relative */
249 0, /* bitpos */
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 */
257
258 /* Reference to global offset table. */
259 /* FIXME: This is not handled correctly. */
260 HOWTO (R_MIPS_GOT16, /* type */
261 0, /* rightshift */
262 2, /* size (0 = byte, 1 = short, 2 = long) */
263 16, /* bitsize */
264 false, /* pc_relative */
265 0, /* bitpos */
266 complain_overflow_signed, /* complain_on_overflow */
6e07e54f 267 mips_elf_got16_reloc, /* special_function */
b3c0fc57
ILT
268 "R_MIPS_GOT16", /* name */
269 false, /* partial_inplace */
270 0, /* src_mask */
271 0xffff, /* dst_mask */
272 false), /* pcrel_offset */
273
274 /* 16 bit PC relative reference. */
275 HOWTO (R_MIPS_PC16, /* type */
276 0, /* rightshift */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
278 16, /* bitsize */
279 true, /* pc_relative */
280 0, /* bitpos */
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 */
288
289 /* 16 bit call through global offset table. */
290 /* FIXME: This is not handled correctly. */
291 HOWTO (R_MIPS_CALL16, /* type */
292 0, /* rightshift */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
294 16, /* bitsize */
295 false, /* pc_relative */
296 0, /* bitpos */
297 complain_overflow_signed, /* complain_on_overflow */
298 bfd_elf_generic_reloc, /* special_function */
299 "R_MIPS_CALL16", /* name */
300 false, /* partial_inplace */
301 0, /* src_mask */
302 0xffff, /* dst_mask */
303 false), /* pcrel_offset */
304
305 /* 32 bit GP relative reference. */
306 /* FIXME: This is not handled correctly. */
307 HOWTO (R_MIPS_GPREL32, /* type */
308 0, /* rightshift */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
310 32, /* bitsize */
311 false, /* pc_relative */
312 0, /* bitpos */
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 */
320};
321
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. */
327
328static bfd_byte *mips_hi16_addr;
329static bfd_vma mips_hi16_addend;
330
331static bfd_reloc_status_type
332mips_elf_hi16_reloc (abfd,
333 reloc_entry,
334 symbol,
335 data,
336 input_section,
6e07e54f
ILT
337 output_bfd,
338 error_message)
b3c0fc57
ILT
339 bfd *abfd;
340 arelent *reloc_entry;
341 asymbol *symbol;
342 PTR data;
343 asection *input_section;
344 bfd *output_bfd;
6e07e54f 345 char **error_message;
b3c0fc57
ILT
346{
347 bfd_reloc_status_type ret;
348 bfd_vma relocation;
349
b3c0fc57
ILT
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)
355 {
356 reloc_entry->address += input_section->output_offset;
357 return bfd_reloc_ok;
358 }
359
6e07e54f
ILT
360 /* FIXME: The symbol _gp_disp requires special handling, which we do
361 not do. */
362 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
363 abort ();
364
b3c0fc57 365 ret = bfd_reloc_ok;
24f13b03 366 if (bfd_is_und_section (symbol->section)
b3c0fc57
ILT
367 && output_bfd == (bfd *) NULL)
368 ret = bfd_reloc_undefined;
369
370 if (bfd_is_com_section (symbol->section))
371 relocation = 0;
372 else
373 relocation = symbol->value;
374
375 relocation += symbol->section->output_section->vma;
376 relocation += symbol->section->output_offset;
377 relocation += reloc_entry->addend;
378
379 if (reloc_entry->address > input_section->_cooked_size)
380 return bfd_reloc_outofrange;
381
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;
385
386 if (output_bfd != (bfd *) NULL)
387 reloc_entry->address += input_section->output_offset;
388
389 return ret;
390}
391
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. */
395
396static bfd_reloc_status_type
397mips_elf_lo16_reloc (abfd,
398 reloc_entry,
399 symbol,
400 data,
401 input_section,
6e07e54f
ILT
402 output_bfd,
403 error_message)
b3c0fc57
ILT
404 bfd *abfd;
405 arelent *reloc_entry;
406 asymbol *symbol;
407 PTR data;
408 asection *input_section;
409 bfd *output_bfd;
6e07e54f 410 char **error_message;
b3c0fc57
ILT
411{
412 /* FIXME: The symbol _gp_disp requires special handling, which we do
413 not do. */
6e07e54f
ILT
414 if (output_bfd == (bfd *) NULL
415 && strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
b3c0fc57
ILT
416 abort ();
417
418 if (mips_hi16_addr != (bfd_byte *) NULL)
419 {
420 unsigned long insn;
421 unsigned long val;
422 unsigned long vallo;
423
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)
429 & 0xffff);
430 val = ((insn & 0xffff) << 16) + vallo;
431 val += mips_hi16_addend;
432
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
438 data. */
439 if ((vallo & 0x8000) != 0)
440 val -= 0x10000;
441 if ((val & 0x8000) != 0)
442 val += 0x10000;
443
444 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
445 bfd_put_32 (abfd, insn, mips_hi16_addr);
446
447 mips_hi16_addr = (bfd_byte *) NULL;
448 }
449
450 /* Now do the LO16 reloc in the usual way. */
451 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
6e07e54f
ILT
452 input_section, output_bfd, error_message);
453}
454
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.
465
466 This implementation suffices for the assembler, but the linker does
467 not yet know how to create global offset tables. */
468
469static bfd_reloc_status_type
470mips_elf_got16_reloc (abfd,
471 reloc_entry,
472 symbol,
473 data,
474 input_section,
475 output_bfd,
476 error_message)
477 bfd *abfd;
478 arelent *reloc_entry;
479 asymbol *symbol;
480 PTR data;
481 asection *input_section;
482 bfd *output_bfd;
483 char **error_message;
484{
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)
490 {
491 reloc_entry->address += input_section->output_offset;
492 return bfd_reloc_ok;
493 }
494
495 /* If we're relocating, and this is a local symbol, we can handle it
496 just like HI16. */
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);
501
502 abort ();
b3c0fc57
ILT
503}
504
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
509 merged. */
510
511static bfd_reloc_status_type
512mips_elf_gprel16_reloc (abfd,
513 reloc_entry,
514 symbol,
515 data,
516 input_section,
6e07e54f
ILT
517 output_bfd,
518 error_message)
b3c0fc57
ILT
519 bfd *abfd;
520 arelent *reloc_entry;
521 asymbol *symbol;
522 PTR data;
523 asection *input_section;
524 bfd *output_bfd;
6e07e54f 525 char **error_message;
b3c0fc57
ILT
526{
527 boolean relocateable;
528 bfd_vma relocation;
529 unsigned long val;
530 unsigned long insn;
531
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
535 file. */
536 if (output_bfd != (bfd *) NULL
537 && (symbol->flags & BSF_SECTION_SYM) == 0
538 && reloc_entry->addend == 0)
539 {
540 reloc_entry->address += input_section->output_offset;
541 return bfd_reloc_ok;
542 }
543
544 if (output_bfd != (bfd *) NULL)
545 relocateable = true;
546 else
547 {
548 relocateable = false;
549 output_bfd = symbol->section->output_section->owner;
550 }
551
24f13b03 552 if (bfd_is_und_section (symbol->section)
b3c0fc57
ILT
553 && relocateable == false)
554 return bfd_reloc_undefined;
555
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))
564 {
565 if (relocateable != false)
566 {
567 /* Make up a value. */
568 elf_gp (output_bfd) =
569 symbol->section->output_section->vma + 0x4000;
570 }
571 else
572 {
573 unsigned int count;
574 asymbol **sym;
575 unsigned int i;
576
577 count = bfd_get_symcount (output_bfd);
578 sym = bfd_get_outsymbols (output_bfd);
579
580 if (sym == (asymbol **) NULL)
581 i = count;
582 else
583 {
584 for (i = 0; i < count; i++, sym++)
585 {
586 register CONST char *name;
587
588 name = bfd_asymbol_name (*sym);
589 if (*name == '_' && strcmp (name, "_gp") == 0)
590 {
591 elf_gp (output_bfd) = bfd_asymbol_value (*sym);
592 break;
593 }
594 }
595 }
596
597 if (i >= count)
598 {
599 /* Only get the error once. */
600 elf_gp (output_bfd) = 4;
6e07e54f
ILT
601 *error_message =
602 (char *) "GP relative relocation when _gp not defined";
b3c0fc57
ILT
603 return bfd_reloc_dangerous;
604 }
605 }
606 }
607
608 if (bfd_is_com_section (symbol->section))
609 relocation = 0;
610 else
611 relocation = symbol->value;
612
613 relocation += symbol->section->output_section->vma;
614 relocation += symbol->section->output_offset;
615
616 if (reloc_entry->address > input_section->_cooked_size)
617 return bfd_reloc_outofrange;
618
619 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
620
621 /* Set val to the offset into the section or symbol. */
622 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
623 if (val & 0x8000)
624 val -= 0x10000;
625
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);
632
633 insn = (insn &~ 0xffff) | (val & 0xffff);
634 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
635
636 if (relocateable != false)
637 reloc_entry->address += input_section->output_offset;
638
639 /* Make sure it fit in 16 bits. */
640 if (val >= 0x8000 && val < 0xffff8000)
6e07e54f 641 return bfd_reloc_overflow;
b3c0fc57
ILT
642
643 return bfd_reloc_ok;
644}
6b4b4d17 645
b3c0fc57 646/* A mapping from BFD reloc types to MIPS ELF reloc types. */
6b4b4d17 647
b3c0fc57
ILT
648struct elf_reloc_map {
649 bfd_reloc_code_real_type bfd_reloc_val;
650 enum reloc_type elf_reloc_val;
651};
652
653static CONST struct elf_reloc_map mips_reloc_map[] =
654{
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 }
669};
670
671/* Given a BFD reloc type, return a howto structure. */
672
aac6b32f 673static const struct reloc_howto_struct *
b3c0fc57
ILT
674bfd_elf32_bfd_reloc_type_lookup (abfd, code)
675 bfd *abfd;
676 bfd_reloc_code_real_type code;
677{
678 int i;
679
680 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
681 {
682 if (mips_reloc_map[i].bfd_reloc_val == code)
683 return &elf_mips_howto_table[(int) mips_reloc_map[i].elf_reloc_val];
684 }
685 return NULL;
686}
687
688/* Given a MIPS reloc type, fill in an arelent structure. */
689
690static void
691mips_info_to_howto_rel (abfd, cache_ptr, dst)
692 bfd *abfd;
693 arelent *cache_ptr;
694 Elf32_Internal_Rel *dst;
695{
696 unsigned int r_type;
697
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];
701
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);
710}
711\f
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. */
715
716void
717bfd_mips_elf32_swap_reginfo_in (abfd, ex, in)
718 bfd *abfd;
719 const Elf32_External_RegInfo *ex;
720 Elf32_RegInfo *in;
721{
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);
728}
729
730void
731bfd_mips_elf32_swap_reginfo_out (abfd, in, ex)
732 bfd *abfd;
733 const Elf32_RegInfo *in;
734 Elf32_External_RegInfo *ex;
735{
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);
748}
aac6b32f
ILT
749
750/* Swap an entry in a .gptab section. Note that these routines rely
751 on the equivalence of the two elements of the union. */
752
753static void
754bfd_mips_elf32_swap_gptab_in (abfd, ex, in)
755 bfd *abfd;
756 const Elf32_External_gptab *ex;
757 Elf32_gptab *in;
758{
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);
761}
762
763static void
764bfd_mips_elf32_swap_gptab_out (abfd, in, ex)
765 bfd *abfd;
766 const Elf32_gptab *in;
767 Elf32_External_gptab *ex;
768{
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);
773}
b3c0fc57 774\f
6e07e54f
ILT
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. */
780
781/*ARGSUSED*/
782static boolean
783mips_elf_sym_is_global (abfd, sym)
784 bfd *abfd;
785 asymbol *sym;
786{
787 return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false;
788}
789\f
790/* Set the right machine number for a MIPS ELF file. */
791
792static boolean
793mips_elf_object_p (abfd)
794 bfd *abfd;
795{
796 switch (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH)
797 {
798 default:
799 case E_MIPS_ARCH_1:
800 /* Just use the default, which was set in elfcode.h. */
801 break;
802
803 case E_MIPS_ARCH_2:
804 (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 6000);
805 break;
806
807 case E_MIPS_ARCH_3:
808 (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 4000);
809 break;
810 }
811
aac6b32f
ILT
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)
818 {
819 Elf_Internal_Shdr *symtab_hdr;
820 Elf32_External_Sym esym;
821
822 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
823 if (bfd_seek (abfd,
824 (symtab_hdr->sh_offset
825 + symtab_hdr->sh_size
826 - sizeof (Elf32_External_Sym)),
827 SEEK_SET) != 0
828 || (bfd_read ((PTR) &esym, 1, sizeof (Elf32_External_Sym), abfd)
829 != sizeof (Elf32_External_Sym)))
830 return false;
831 if (ELF_ST_BIND (bfd_h_get_8 (abfd, (bfd_byte *) esym.st_info))
832 == STB_LOCAL)
833 elf_bad_symtab (abfd) = true;
834 }
835
6e07e54f
ILT
836 return true;
837}
838
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
841 number. */
842
24f13b03 843/*ARGSUSED*/
6e07e54f 844static void
24f13b03 845mips_elf_final_write_processing (abfd, linker)
6e07e54f 846 bfd *abfd;
24f13b03 847 boolean linker;
6e07e54f
ILT
848{
849 unsigned long val;
aac6b32f
ILT
850 unsigned int i;
851 Elf_Internal_Shdr **hdrpp;
6e07e54f
ILT
852
853 switch (bfd_get_mach (abfd))
854 {
855 case 3000:
856 val = E_MIPS_ARCH_1;
857 break;
858
859 case 6000:
860 val = E_MIPS_ARCH_2;
861 break;
862
863 case 4000:
864 val = E_MIPS_ARCH_3;
865 break;
866
867 default:
868 return;
869 }
870
871 elf_elfheader (abfd)->e_flags &=~ EF_MIPS_ARCH;
872 elf_elfheader (abfd)->e_flags |= val;
aac6b32f
ILT
873
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;
877 i++, hdrpp++)
878 {
879 if ((*hdrpp)->sh_type == SHT_MIPS_GPTAB)
880 {
881 const char *name;
882 asection *sec;
883
24f13b03
ILT
884 BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
885 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
aac6b32f
ILT
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;
891 }
892 }
6e07e54f
ILT
893}
894\f
b3c0fc57
ILT
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
898 how to. */
899
900static boolean
901mips_elf_section_from_shdr (abfd, hdr, name)
902 bfd *abfd;
903 Elf32_Internal_Shdr *hdr;
904 char *name;
905{
497c5434
ILT
906 asection *newsect;
907
b3c0fc57
ILT
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)
914 {
915 case SHT_MIPS_LIBLIST:
916 if (strcmp (name, ".liblist") != 0)
917 return false;
918 break;
919 case SHT_MIPS_CONFLICT:
920 if (strcmp (name, ".conflict") != 0)
921 return false;
922 break;
923 case SHT_MIPS_GPTAB:
924 if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) != 0)
925 return false;
926 break;
927 case SHT_MIPS_UCODE:
928 if (strcmp (name, ".ucode") != 0)
929 return false;
930 break;
931 case SHT_MIPS_DEBUG:
932 if (strcmp (name, ".mdebug") != 0)
933 return false;
934 break;
935 case SHT_MIPS_REGINFO:
936 if (strcmp (name, ".reginfo") != 0
937 || hdr->sh_size != sizeof (Elf32_External_RegInfo))
938 return false;
939 break;
6e07e54f
ILT
940 case SHT_MIPS_OPTIONS:
941 if (strcmp (name, ".options") != 0)
942 return false;
943 break;
b3c0fc57
ILT
944 default:
945 return false;
946 }
947
497c5434
ILT
948 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
949 return false;
24f13b03 950 newsect = hdr->bfd_section;
b3c0fc57 951
497c5434
ILT
952 if (hdr->sh_type == SHT_MIPS_DEBUG)
953 {
954 if (! bfd_set_section_flags (abfd, newsect,
955 (bfd_get_section_flags (abfd, newsect)
956 | SEC_DEBUGGING)))
957 return false;
958 }
b3c0fc57 959
497c5434 960 /* FIXME: We should record sh_info for a .gptab section. */
b3c0fc57 961
497c5434
ILT
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)
966 {
967 Elf32_External_RegInfo ext;
968 Elf32_RegInfo s;
b3c0fc57 969
497c5434
ILT
970 if (! bfd_get_section_contents (abfd, newsect, (PTR) &ext,
971 (file_ptr) 0, sizeof ext))
972 return false;
973 bfd_mips_elf32_swap_reginfo_in (abfd, &ext, &s);
974 elf_gp (abfd) = s.ri_gp_value;
b3c0fc57
ILT
975 }
976
977 return true;
978}
979
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. */
982
983static boolean
984mips_elf_fake_sections (abfd, hdr, sec)
985 bfd *abfd;
986 Elf32_Internal_Shdr *hdr;
987 asection *sec;
988{
989 register const char *name;
990
991 name = bfd_get_section_name (abfd, sec);
992
993 if (strcmp (name, ".liblist") == 0)
994 {
995 hdr->sh_type = SHT_MIPS_LIBLIST;
996 hdr->sh_info = sec->_raw_size / sizeof (Elf32_Lib);
997 /* FIXME: Set the sh_link field. */
998 }
999 else if (strcmp (name, ".conflict") == 0)
1000 hdr->sh_type = SHT_MIPS_CONFLICT;
1001 else if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0)
1002 {
1003 hdr->sh_type = SHT_MIPS_GPTAB;
aac6b32f
ILT
1004 hdr->sh_entsize = sizeof (Elf32_External_gptab);
1005 /* The sh_info field is set in mips_elf_final_write_processing. */
b3c0fc57
ILT
1006 }
1007 else if (strcmp (name, ".ucode") == 0)
1008 hdr->sh_type = SHT_MIPS_UCODE;
1009 else if (strcmp (name, ".mdebug") == 0)
6e07e54f
ILT
1010 {
1011 hdr->sh_type = SHT_MIPS_DEBUG;
1012 hdr->sh_entsize = 1;
1013 }
b3c0fc57
ILT
1014 else if (strcmp (name, ".reginfo") == 0)
1015 {
1016 hdr->sh_type = SHT_MIPS_REGINFO;
6e07e54f 1017 hdr->sh_entsize = 1;
b3c0fc57
ILT
1018
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);
1023 }
6e07e54f
ILT
1024 else if (strcmp (name, ".options") == 0)
1025 {
1026 hdr->sh_type = SHT_MIPS_OPTIONS;
1027 hdr->sh_entsize = 1;
1028 }
b3c0fc57
ILT
1029
1030 return true;
1031}
1032
1033/* Given a BFD section, try to locate the corresponding ELF section
1034 index. */
1035
1036static boolean
1037mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
1038 bfd *abfd;
1039 Elf32_Internal_Shdr *hdr;
1040 asection *sec;
1041 int *retval;
1042{
1043 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
1044 {
1045 *retval = SHN_MIPS_SCOMMON;
1046 return true;
1047 }
82b1edf7
KR
1048 if (strcmp (bfd_get_section_name (abfd, sec), ".acommon") == 0)
1049 {
1050 *retval = SHN_MIPS_ACOMMON;
1051 return true;
1052 }
b3c0fc57
ILT
1053 return false;
1054}
1055
1056/* Work over a section just before writing it out. We update the GP
1057 value in the .reginfo section based on the value we are using.
1058 FIXME: We recognize sections that need the SHF_MIPS_GPREL flag by
1059 name; there has to be a better way. */
1060
1061static boolean
1062mips_elf_section_processing (abfd, hdr)
1063 bfd *abfd;
1064 Elf32_Internal_Shdr *hdr;
1065{
1066 if (hdr->sh_type == SHT_MIPS_REGINFO)
1067 {
1068 bfd_byte buf[4];
1069
1070 BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo));
1071 BFD_ASSERT (hdr->contents == NULL);
1072
1073 if (bfd_seek (abfd,
1074 hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4,
1075 SEEK_SET) == -1)
1076 return false;
1077 bfd_h_put_32 (abfd, (bfd_vma) elf_gp (abfd), buf);
1078 if (bfd_write (buf, (bfd_size_type) 1, (bfd_size_type) 4, abfd) != 4)
1079 return false;
1080 }
1081
24f13b03 1082 if (hdr->bfd_section != NULL)
b3c0fc57 1083 {
24f13b03 1084 const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
b3c0fc57
ILT
1085
1086 if (strcmp (name, ".sdata") == 0)
1087 {
1088 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1089 hdr->sh_type = SHT_PROGBITS;
1090 }
1091 else if (strcmp (name, ".sbss") == 0)
1092 {
1093 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1094 hdr->sh_type = SHT_NOBITS;
1095 }
1096 else if (strcmp (name, ".lit8") == 0
1097 || strcmp (name, ".lit4") == 0)
1098 {
1099 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1100 hdr->sh_type = SHT_PROGBITS;
1101 }
1102 }
1103
1104 return true;
1105}
1106\f
aac6b32f
ILT
1107/* MIPS ELF uses two common sections. One is the usual one, and the
1108 other is for small objects. All the small objects are kept
1109 together, and then referenced via the gp pointer, which yields
1110 faster assembler code. This is what we use for the small common
1111 section. This approach is copied from ecoff.c. */
1112static asection mips_elf_scom_section;
1113static asymbol mips_elf_scom_symbol;
1114static asymbol *mips_elf_scom_symbol_ptr;
1115
1116/* MIPS ELF also uses an acommon section, which represents an
1117 allocated common symbol which may be overridden by a
1118 definition in a shared library. */
1119static asection mips_elf_acom_section;
1120static asymbol mips_elf_acom_symbol;
1121static asymbol *mips_elf_acom_symbol_ptr;
1122
1123/* Handle the special MIPS section numbers that a symbol may use. */
1124
1125static void
1126mips_elf_symbol_processing (abfd, asym)
1127 bfd *abfd;
1128 asymbol *asym;
1129{
1130 elf_symbol_type *elfsym;
1131
1132 elfsym = (elf_symbol_type *) asym;
1133 switch (elfsym->internal_elf_sym.st_shndx)
1134 {
1135 case SHN_MIPS_ACOMMON:
1136 /* This section is used in a dynamically linked executable file.
1137 It is an allocated common section. The dynamic linker can
1138 either resolve these symbols to something in a shared
1139 library, or it can just leave them here. For our purposes,
1140 we can consider these symbols to be in a new section. */
1141 if (mips_elf_acom_section.name == NULL)
1142 {
1143 /* Initialize the acommon section. */
1144 mips_elf_acom_section.name = ".acommon";
1145 mips_elf_acom_section.flags = SEC_NO_FLAGS;
1146 mips_elf_acom_section.output_section = &mips_elf_acom_section;
1147 mips_elf_acom_section.symbol = &mips_elf_acom_symbol;
1148 mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr;
1149 mips_elf_acom_symbol.name = ".acommon";
1150 mips_elf_acom_symbol.flags = BSF_SECTION_SYM;
1151 mips_elf_acom_symbol.section = &mips_elf_acom_section;
1152 mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol;
1153 }
1154 asym->section = &mips_elf_acom_section;
1155 break;
1156
1157 case SHN_COMMON:
1158 /* Common symbols less than the GP size are automatically
1159 treated as SHN_MIPS_SCOMMON symbols. */
1160 if (asym->value > elf_gp_size (abfd))
1161 break;
1162 /* Fall through. */
1163 case SHN_MIPS_SCOMMON:
1164 if (mips_elf_scom_section.name == NULL)
1165 {
1166 /* Initialize the small common section. */
1167 mips_elf_scom_section.name = ".scommon";
1168 mips_elf_scom_section.flags = SEC_IS_COMMON;
1169 mips_elf_scom_section.output_section = &mips_elf_scom_section;
1170 mips_elf_scom_section.symbol = &mips_elf_scom_symbol;
1171 mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr;
1172 mips_elf_scom_symbol.name = ".scommon";
1173 mips_elf_scom_symbol.flags = BSF_SECTION_SYM;
1174 mips_elf_scom_symbol.section = &mips_elf_scom_section;
1175 mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol;
1176 }
1177 asym->section = &mips_elf_scom_section;
1178 asym->value = elfsym->internal_elf_sym.st_size;
1179 break;
1180
1181 case SHN_MIPS_SUNDEFINED:
24f13b03 1182 asym->section = bfd_und_section_ptr;
aac6b32f
ILT
1183 break;
1184 }
1185}
1186\f
6e07e54f
ILT
1187/* Read ECOFF debugging information from a .mdebug section into a
1188 ecoff_debug_info structure. */
b3c0fc57
ILT
1189
1190static boolean
6e07e54f 1191mips_elf_read_ecoff_info (abfd, section, debug)
b3c0fc57 1192 bfd *abfd;
6e07e54f
ILT
1193 asection *section;
1194 struct ecoff_debug_info *debug;
b3c0fc57 1195{
6e07e54f
ILT
1196 HDRR *symhdr;
1197 const struct ecoff_debug_swap *swap;
a3a33af3 1198 char *ext_hdr = NULL;
6e07e54f
ILT
1199
1200 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1201
a3a33af3
ILT
1202 ext_hdr = (char *) malloc (swap->external_hdr_size);
1203 if (ext_hdr == NULL && swap->external_hdr_size != 0)
1204 {
1205 bfd_set_error (bfd_error_no_memory);
1206 goto error_return;
1207 }
6e07e54f
ILT
1208
1209 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
1210 swap->external_hdr_size)
1211 == false)
a3a33af3 1212 goto error_return;
6e07e54f
ILT
1213
1214 symhdr = &debug->symbolic_header;
1215 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
1216
1217 /* The symbolic header contains absolute file offsets and sizes to
1218 read. */
1219#define READ(ptr, offset, count, size, type) \
1220 if (symhdr->count == 0) \
1221 debug->ptr = NULL; \
1222 else \
1223 { \
1224 debug->ptr = (type) malloc (size * symhdr->count); \
1225 if (debug->ptr == NULL) \
1226 { \
a3a33af3
ILT
1227 bfd_set_error (bfd_error_no_memory); \
1228 goto error_return; \
6e07e54f
ILT
1229 } \
1230 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1231 || (bfd_read (debug->ptr, size, symhdr->count, \
1232 abfd) != size * symhdr->count)) \
a3a33af3 1233 goto error_return; \
6e07e54f
ILT
1234 }
1235
1236 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
1237 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
1238 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
1239 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
1240 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
1241 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
1242 union aux_ext *);
1243 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
1244 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
1245 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
1246 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
aac6b32f
ILT
1247 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
1248#undef READ
9783e04a
DM
1249
1250 debug->fdr = NULL;
a3a33af3 1251 debug->adjust = NULL;
6e07e54f
ILT
1252
1253 return true;
a3a33af3
ILT
1254
1255 error_return:
1256 if (ext_hdr != NULL)
1257 free (ext_hdr);
a3a33af3
ILT
1258 if (debug->line != NULL)
1259 free (debug->line);
1260 if (debug->external_dnr != NULL)
1261 free (debug->external_dnr);
1262 if (debug->external_pdr != NULL)
1263 free (debug->external_pdr);
1264 if (debug->external_sym != NULL)
1265 free (debug->external_sym);
1266 if (debug->external_opt != NULL)
1267 free (debug->external_opt);
1268 if (debug->external_aux != NULL)
1269 free (debug->external_aux);
1270 if (debug->ss != NULL)
1271 free (debug->ss);
1272 if (debug->ssext != NULL)
1273 free (debug->ssext);
1274 if (debug->external_fdr != NULL)
1275 free (debug->external_fdr);
1276 if (debug->external_rfd != NULL)
1277 free (debug->external_rfd);
aac6b32f
ILT
1278 if (debug->external_ext != NULL)
1279 free (debug->external_ext);
a3a33af3 1280 return false;
6e07e54f
ILT
1281}
1282
aac6b32f
ILT
1283/* The MIPS ELF linker needs additional information for each symbol in
1284 the global hash table. */
1285
1286struct mips_elf_link_hash_entry
1287{
1288 struct elf_link_hash_entry root;
6e07e54f 1289
aac6b32f
ILT
1290 /* External symbol information. */
1291 EXTR esym;
1292};
1293
1294/* MIPS ELF linker hash table. */
1295
1296struct mips_elf_link_hash_table
1297{
1298 struct elf_link_hash_table root;
1299};
1300
1301/* Look up an entry in a MIPS ELF linker hash table. */
1302
1303#define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
1304 ((struct mips_elf_link_hash_entry *) \
1305 elf_link_hash_lookup (&(table)->root, (string), (create), \
1306 (copy), (follow)))
1307
1308/* Traverse a MIPS ELF linker hash table. */
1309
1310#define mips_elf_link_hash_traverse(table, func, info) \
1311 (elf_link_hash_traverse \
1312 (&(table)->root, \
1313 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
1314 (info)))
1315
1316/* Get the MIPS ELF linker hash table from a link_info structure. */
1317
1318#define mips_elf_hash_table(p) \
1319 ((struct mips_elf_link_hash_table *) ((p)->hash))
1320
1321static boolean mips_elf_output_extsym
1322 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
1323
1324/* Create an entry in a MIPS ELF linker hash table. */
1325
1326static struct bfd_hash_entry *
1327mips_elf_link_hash_newfunc (entry, table, string)
1328 struct bfd_hash_entry *entry;
1329 struct bfd_hash_table *table;
1330 const char *string;
1331{
1332 struct mips_elf_link_hash_entry *ret =
1333 (struct mips_elf_link_hash_entry *) entry;
1334
1335 /* Allocate the structure if it has not already been allocated by a
1336 subclass. */
1337 if (ret == (struct mips_elf_link_hash_entry *) NULL)
1338 ret = ((struct mips_elf_link_hash_entry *)
1339 bfd_hash_allocate (table,
1340 sizeof (struct mips_elf_link_hash_entry)));
1341 if (ret == (struct mips_elf_link_hash_entry *) NULL)
1342 {
1343 bfd_set_error (bfd_error_no_memory);
1344 return (struct bfd_hash_entry *) ret;
1345 }
1346
1347 /* Call the allocation method of the superclass. */
1348 ret = ((struct mips_elf_link_hash_entry *)
1349 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1350 table, string));
1351 if (ret != (struct mips_elf_link_hash_entry *) NULL)
1352 {
1353 /* Set local fields. */
1354 memset (&ret->esym, 0, sizeof (EXTR));
1355 /* We use -2 as a marker to indicate that the information has
1356 not been set. -1 means there is no associated ifd. */
1357 ret->esym.ifd = -2;
1358 }
1359
1360 return (struct bfd_hash_entry *) ret;
1361}
1362
1363/* Create a MIPS ELF linker hash table. */
1364
1365static struct bfd_link_hash_table *
1366mips_elf_link_hash_table_create (abfd)
1367 bfd *abfd;
1368{
1369 struct mips_elf_link_hash_table *ret;
1370
1371 ret = ((struct mips_elf_link_hash_table *)
1372 bfd_alloc (abfd, sizeof (struct mips_elf_link_hash_table)));
1373 if (ret == (struct mips_elf_link_hash_table *) NULL)
1374 {
1375 bfd_set_error (bfd_error_no_memory);
1376 return NULL;
1377 }
1378
1379 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
1380 mips_elf_link_hash_newfunc))
1381 {
1382 bfd_release (abfd, ret);
1383 return NULL;
1384 }
1385
1386 return &ret->root.root;
1387}
1388
1389/* Hook called by the linker routine which adds symbols from an object
1390 file. We must handle the special MIPS section numbers here. */
1391
1392/*ARGSUSED*/
6e07e54f 1393static boolean
aac6b32f
ILT
1394mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
1395 bfd *abfd;
1396 struct bfd_link_info *info;
1397 const Elf_Internal_Sym *sym;
1398 const char **namep;
1399 flagword *flagsp;
1400 asection **secp;
1401 bfd_vma *valp;
1402{
1403 switch (sym->st_shndx)
1404 {
1405 case SHN_COMMON:
1406 /* Common symbols less than the GP size are automatically
1407 treated as SHN_MIPS_SCOMMON symbols. */
1408 if (sym->st_size > elf_gp_size (abfd))
1409 break;
1410 /* Fall through. */
1411 case SHN_MIPS_SCOMMON:
1412 *secp = bfd_make_section_old_way (abfd, ".scommon");
1413 (*secp)->flags |= SEC_IS_COMMON;
1414 *valp = sym->st_size;
1415 break;
1416
1417 case SHN_MIPS_SUNDEFINED:
24f13b03 1418 *secp = bfd_und_section_ptr;
aac6b32f
ILT
1419 break;
1420 }
1421
1422 return true;
1423}
1424
1425/* Structure used to pass information to mips_elf_output_extsym. */
1426
1427struct extsym_info
6e07e54f 1428{
aac6b32f
ILT
1429 bfd *abfd;
1430 struct bfd_link_info *info;
1431 struct ecoff_debug_info *debug;
9783e04a 1432 const struct ecoff_debug_swap *swap;
aac6b32f
ILT
1433 boolean failed;
1434};
9783e04a 1435
aac6b32f
ILT
1436/* This routine is used to write out ECOFF debugging external symbol
1437 information. It is called via mips_elf_link_hash_traverse. The
1438 ECOFF external symbol information must match the ELF external
1439 symbol information. Unfortunately, at this point we don't know
1440 whether a symbol is required by reloc information, so the two
1441 tables may wind up being different. We must sort out the external
1442 symbol information before we can set the final size of the .mdebug
1443 section, and we must set the size of the .mdebug section before we
1444 can relocate any sections, and we can't know which symbols are
1445 required by relocation until we relocate the sections.
1446 Fortunately, it is relatively unlikely that any symbol will be
1447 stripped but required by a reloc. In particular, it can not happen
1448 when generating a final executable. */
1449
1450static boolean
1451mips_elf_output_extsym (h, data)
1452 struct mips_elf_link_hash_entry *h;
1453 PTR data;
1454{
1455 struct extsym_info *einfo = (struct extsym_info *) data;
1456 boolean strip;
1457
1458 if (h->root.indx == -2)
1459 strip = false;
1460 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1461 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
1462 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
1463 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
1464 strip = true;
1465 else if (einfo->info->strip == strip_all
1466 || (einfo->info->strip == strip_some
1467 && bfd_hash_lookup (einfo->info->keep_hash,
1468 h->root.root.root.string,
1469 false, false) == NULL))
1470 strip = true;
1471 else
1472 strip = false;
1473
1474 if (strip)
1475 return true;
6e07e54f 1476
aac6b32f 1477 if (h->esym.ifd == -2)
6e07e54f 1478 {
aac6b32f
ILT
1479 h->esym.jmptbl = 0;
1480 h->esym.cobol_main = 0;
1481 h->esym.weakext = 0;
1482 h->esym.reserved = 0;
1483 h->esym.ifd = ifdNil;
1484 h->esym.asym.value = 0;
1485 h->esym.asym.st = stGlobal;
1486
1487 if (h->root.root.type != bfd_link_hash_defined)
1488 h->esym.asym.sc = scAbs;
1489 else
1490 {
1491 asection *output_section;
1492 const char *name;
1493
1494 output_section = h->root.root.u.def.section->output_section;
1495 name = bfd_section_name (output_section->owner, output_section);
1496
1497 if (strcmp (name, ".text") == 0)
1498 h->esym.asym.sc = scText;
1499 else if (strcmp (name, ".data") == 0)
1500 h->esym.asym.sc = scData;
1501 else if (strcmp (name, ".sdata") == 0)
1502 h->esym.asym.sc = scSData;
1503 else if (strcmp (name, ".rodata") == 0
1504 || strcmp (name, ".rdata") == 0)
1505 h->esym.asym.sc = scRData;
1506 else if (strcmp (name, ".bss") == 0)
1507 h->esym.asym.sc = scBss;
1508 else if (strcmp (name, ".sbss") == 0)
1509 h->esym.asym.sc = scSBss;
1510 else if (strcmp (name, ".init") == 0)
1511 h->esym.asym.sc = scInit;
1512 else if (strcmp (name, ".fini") == 0)
1513 h->esym.asym.sc = scFini;
1514 else
1515 h->esym.asym.sc = scAbs;
1516 }
1517
1518 h->esym.asym.reserved = 0;
1519 h->esym.asym.index = indexNil;
6e07e54f
ILT
1520 }
1521
aac6b32f
ILT
1522
1523 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
1524 h->root.root.root.string,
1525 &h->esym))
1526 {
1527 einfo->failed = true;
1528 return false;
1529 }
6e07e54f
ILT
1530
1531 return true;
1532}
1533
aac6b32f 1534/* A comparison routine used to sort .gptab entries. */
6e07e54f 1535
aac6b32f
ILT
1536static int
1537gptab_compare (p1, p2)
1538 const PTR p1;
1539 const PTR p2;
6e07e54f 1540{
aac6b32f
ILT
1541 const Elf32_gptab *a1 = (const Elf32_gptab *) p1;
1542 const Elf32_gptab *a2 = (const Elf32_gptab *) p2;
1543
1544 return a1->gt_entry.gt_g_value - a2->gt_entry.gt_g_value;
6e07e54f
ILT
1545}
1546
1547/* We need to use a special link routine to handle the .reginfo and
1548 the .mdebug sections. We need to merge all instances of these
1549 sections together, not write them all out sequentially. */
1550
1551static boolean
1552mips_elf_final_link (abfd, info)
1553 bfd *abfd;
1554 struct bfd_link_info *info;
1555{
6e07e54f
ILT
1556 asection **secpp;
1557 asection *o;
1558 struct bfd_link_order *p;
aac6b32f 1559 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
b3c0fc57 1560 Elf32_RegInfo reginfo;
6e07e54f
ILT
1561 struct ecoff_debug_info debug;
1562 const struct ecoff_debug_swap *swap
1563 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1564 HDRR *symhdr = &debug.symbolic_header;
9783e04a 1565 PTR mdebug_handle = NULL;
6e07e54f 1566
497c5434 1567 /* Drop the .options section, since it has special semantics which I
aac6b32f
ILT
1568 haven't bothered to figure out. */
1569 for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next)
6e07e54f 1570 {
aac6b32f 1571 if (strcmp ((*secpp)->name, ".options") == 0)
6e07e54f 1572 {
aac6b32f
ILT
1573 for (p = (*secpp)->link_order_head; p != NULL; p = p->next)
1574 if (p->type == bfd_indirect_link_order)
1575 p->u.indirect.section->flags &=~ SEC_HAS_CONTENTS;
1576 (*secpp)->link_order_head = NULL;
6e07e54f
ILT
1577 *secpp = (*secpp)->next;
1578 --abfd->section_count;
aac6b32f 1579 break;
6e07e54f 1580 }
6e07e54f 1581 }
b3c0fc57 1582
6e07e54f 1583 /* Go through the sections and collect the .reginfo and .mdebug
aac6b32f 1584 information. */
9783e04a
DM
1585 reginfo_sec = NULL;
1586 mdebug_sec = NULL;
aac6b32f
ILT
1587 gptab_data_sec = NULL;
1588 gptab_bss_sec = NULL;
6e07e54f 1589 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
b3c0fc57 1590 {
6e07e54f 1591 if (strcmp (o->name, ".reginfo") == 0)
b3c0fc57 1592 {
6e07e54f 1593 memset (&reginfo, 0, sizeof reginfo);
b3c0fc57
ILT
1594
1595 /* We have found the .reginfo section in the output file.
6e07e54f
ILT
1596 Look through all the link_orders comprising it and merge
1597 the information together. */
1598 for (p = o->link_order_head;
1599 p != (struct bfd_link_order *) NULL;
b3c0fc57
ILT
1600 p = p->next)
1601 {
6e07e54f
ILT
1602 asection *input_section;
1603 bfd *input_bfd;
1604 Elf32_External_RegInfo ext;
1605 Elf32_RegInfo sub;
1606
1607 if (p->type != bfd_indirect_link_order)
aac6b32f
ILT
1608 {
1609 if (p->type == bfd_fill_link_order)
1610 continue;
1611 abort ();
1612 }
6e07e54f
ILT
1613
1614 input_section = p->u.indirect.section;
1615 input_bfd = input_section->owner;
1616 BFD_ASSERT (input_section->_raw_size
1617 == sizeof (Elf32_External_RegInfo));
1618 if (! bfd_get_section_contents (input_bfd, input_section,
1619 (PTR) &ext,
1620 (file_ptr) 0,
1621 sizeof ext))
1622 return false;
1623
1624 bfd_mips_elf32_swap_reginfo_in (input_bfd, &ext, &sub);
1625
1626 reginfo.ri_gprmask |= sub.ri_gprmask;
1627 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
1628 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
1629 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
1630 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
1631
1632 /* ri_gp_value is set by the function
1633 mips_elf_section_processing when the section is
1634 finally written out. */
aac6b32f
ILT
1635
1636 /* Hack: reset the SEC_HAS_CONTENTS flag so that
1637 elf_link_input_bfd ignores this section. */
1638 input_section->flags &=~ SEC_HAS_CONTENTS;
6e07e54f
ILT
1639 }
1640
1641 /* Force the section size to the value we want. */
1642 o->_raw_size = sizeof (Elf32_External_RegInfo);
1643
aac6b32f
ILT
1644 /* Skip this section later on (I don't think this currently
1645 matters, but someday it might). */
6e07e54f
ILT
1646 o->link_order_head = (struct bfd_link_order *) NULL;
1647
1648 reginfo_sec = o;
1649 }
1650
1651 if (strcmp (o->name, ".mdebug") == 0)
1652 {
aac6b32f
ILT
1653 struct extsym_info einfo;
1654
6e07e54f
ILT
1655 /* We have found the .mdebug section in the output file.
1656 Look through all the link_orders comprising it and merge
1657 the information together. */
1658 symhdr->magic = swap->sym_magic;
1659 /* FIXME: What should the version stamp be? */
1660 symhdr->vstamp = 0;
1661 symhdr->ilineMax = 0;
1662 symhdr->cbLine = 0;
1663 symhdr->idnMax = 0;
1664 symhdr->ipdMax = 0;
1665 symhdr->isymMax = 0;
1666 symhdr->ioptMax = 0;
1667 symhdr->iauxMax = 0;
1668 symhdr->issMax = 0;
1669 symhdr->issExtMax = 0;
1670 symhdr->ifdMax = 0;
1671 symhdr->crfd = 0;
1672 symhdr->iextMax = 0;
1673
1674 /* We accumulate the debugging information itself in the
1675 debug_info structure. */
9783e04a
DM
1676 debug.line = NULL;
1677 debug.external_dnr = NULL;
1678 debug.external_pdr = NULL;
1679 debug.external_sym = NULL;
1680 debug.external_opt = NULL;
1681 debug.external_aux = NULL;
1682 debug.ss = NULL;
6e07e54f 1683 debug.ssext = debug.ssext_end = NULL;
9783e04a
DM
1684 debug.external_fdr = NULL;
1685 debug.external_rfd = NULL;
6e07e54f
ILT
1686 debug.external_ext = debug.external_ext_end = NULL;
1687
9783e04a
DM
1688 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
1689 if (mdebug_handle == (PTR) NULL)
1690 return false;
1691
6e07e54f
ILT
1692 for (p = o->link_order_head;
1693 p != (struct bfd_link_order *) NULL;
1694 p = p->next)
1695 {
1696 asection *input_section;
1697 bfd *input_bfd;
1698 const struct ecoff_debug_swap *input_swap;
1699 struct ecoff_debug_info input_debug;
aac6b32f
ILT
1700 char *eraw_src;
1701 char *eraw_end;
6e07e54f
ILT
1702
1703 if (p->type != bfd_indirect_link_order)
aac6b32f
ILT
1704 {
1705 if (p->type == bfd_fill_link_order)
1706 continue;
1707 abort ();
1708 }
6e07e54f
ILT
1709
1710 input_section = p->u.indirect.section;
1711 input_bfd = input_section->owner;
1712
1713 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
1714 || (get_elf_backend_data (input_bfd)
1715 ->elf_backend_ecoff_debug_swap) == NULL)
b3c0fc57 1716 {
6e07e54f
ILT
1717 /* I don't know what a non MIPS ELF bfd would be
1718 doing with a .mdebug section, but I don't really
1719 want to deal with it. */
1720 continue;
b3c0fc57 1721 }
6e07e54f
ILT
1722
1723 input_swap = (get_elf_backend_data (input_bfd)
1724 ->elf_backend_ecoff_debug_swap);
1725
1726 BFD_ASSERT (p->size == input_section->_raw_size);
1727
1728 /* The ECOFF linking code expects that we have already
1729 read in the debugging information and set up an
1730 ecoff_debug_info structure, so we do that now. */
1731 if (! mips_elf_read_ecoff_info (input_bfd, input_section,
1732 &input_debug))
1733 return false;
1734
1735 if (! (bfd_ecoff_debug_accumulate
9783e04a
DM
1736 (mdebug_handle, abfd, &debug, swap, input_bfd,
1737 &input_debug, input_swap, info)))
6e07e54f
ILT
1738 return false;
1739
1740 /* Loop through the external symbols. For each one with
aac6b32f
ILT
1741 interesting information, try to find the symbol in
1742 the linker global hash table and save the information
1743 for the output external symbols. */
1744 eraw_src = input_debug.external_ext;
1745 eraw_end = (eraw_src
1746 + (input_debug.symbolic_header.iextMax
1747 * input_swap->external_ext_size));
1748 for (;
1749 eraw_src < eraw_end;
1750 eraw_src += input_swap->external_ext_size)
6e07e54f 1751 {
aac6b32f
ILT
1752 EXTR ext;
1753 const char *name;
1754 struct mips_elf_link_hash_entry *h;
1755
1756 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
1757 if (ext.asym.sc == scNil
1758 || ext.asym.sc == scUndefined
1759 || ext.asym.sc == scSUndefined)
1760 continue;
1761
1762 name = input_debug.ssext + ext.asym.iss;
1763 h = mips_elf_link_hash_lookup (mips_elf_hash_table (info),
1764 name, false, false, true);
1765 if (h == NULL || h->esym.ifd != -2)
1766 continue;
1767
1768 if (ext.ifd != -1)
6e07e54f 1769 {
aac6b32f
ILT
1770 BFD_ASSERT (ext.ifd
1771 < input_debug.symbolic_header.ifdMax);
1772 ext.ifd = input_debug.ifdmap[ext.ifd];
6e07e54f 1773 }
aac6b32f
ILT
1774
1775 h->esym = ext;
6e07e54f
ILT
1776 }
1777
aac6b32f 1778 /* Free up the information we just read. */
6e07e54f
ILT
1779 free (input_debug.line);
1780 free (input_debug.external_dnr);
1781 free (input_debug.external_pdr);
1782 free (input_debug.external_sym);
1783 free (input_debug.external_opt);
1784 free (input_debug.external_aux);
1785 free (input_debug.ss);
1786 free (input_debug.ssext);
1787 free (input_debug.external_fdr);
1788 free (input_debug.external_rfd);
aac6b32f
ILT
1789 free (input_debug.external_ext);
1790
1791 /* Hack: reset the SEC_HAS_CONTENTS flag so that
1792 elf_link_input_bfd ignores this section. */
1793 input_section->flags &=~ SEC_HAS_CONTENTS;
b3c0fc57
ILT
1794 }
1795
6e07e54f 1796 /* Build the external symbol information. */
aac6b32f
ILT
1797 einfo.abfd = abfd;
1798 einfo.info = info;
1799 einfo.debug = &debug;
1800 einfo.swap = swap;
1801 einfo.failed = false;
1802 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
1803 mips_elf_output_extsym,
1804 (PTR) &einfo);
1805 if (einfo.failed)
b3c0fc57
ILT
1806 return false;
1807
aac6b32f 1808 /* Set the size of the .mdebug section. */
6e07e54f
ILT
1809 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
1810
aac6b32f
ILT
1811 /* Skip this section later on (I don't think this currently
1812 matters, but someday it might). */
6e07e54f
ILT
1813 o->link_order_head = (struct bfd_link_order *) NULL;
1814
1815 mdebug_sec = o;
1816 }
6e07e54f 1817
aac6b32f 1818 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
6e07e54f 1819 {
aac6b32f
ILT
1820 const char *subname;
1821 unsigned int c;
1822 Elf32_gptab *tab;
1823 Elf32_External_gptab *ext_tab;
1824 unsigned int i;
1825
1826 /* The .gptab.sdata and .gptab.sbss sections hold
1827 information describing how the small data area would
1828 change depending upon the -G switch. These sections
1829 not used in executables files. */
1830 if (! info->relocateable)
1831 {
1832 asection **secpp;
1833
1834 for (p = o->link_order_head;
1835 p != (struct bfd_link_order *) NULL;
1836 p = p->next)
1837 {
1838 asection *input_section;
1839
1840 if (p->type != bfd_indirect_link_order)
1841 {
1842 if (p->type == bfd_fill_link_order)
1843 continue;
1844 abort ();
1845 }
1846
1847 input_section = p->u.indirect.section;
1848
1849 /* Hack: reset the SEC_HAS_CONTENTS flag so that
1850 elf_link_input_bfd ignores this section. */
1851 input_section->flags &=~ SEC_HAS_CONTENTS;
1852 }
1853
1854 /* Skip this section later on (I don't think this
1855 currently matters, but someday it might). */
1856 o->link_order_head = (struct bfd_link_order *) NULL;
1857
1858 /* Really remove the section. */
1859 for (secpp = &abfd->sections;
1860 *secpp != o;
1861 secpp = &(*secpp)->next)
1862 ;
1863 *secpp = (*secpp)->next;
1864 --abfd->section_count;
1865
1866 continue;
1867 }
1868
1869 /* There is one gptab for initialized data, and one for
1870 uninitialized data. */
1871 if (strcmp (o->name, ".gptab.sdata") == 0)
1872 gptab_data_sec = o;
1873 else if (strcmp (o->name, ".gptab.sbss") == 0)
1874 gptab_bss_sec = o;
1875 else
1876 {
1877 bfd_set_error (bfd_error_nonrepresentable_section);
1878 return false;
1879 }
1880
1881 /* The linker script always combines .gptab.data and
1882 .gptab.sdata into .gptab.sdata, and likewise for
1883 .gptab.bss and .gptab.sbss. It is possible that there is
1884 no .sdata or .sbss section in the output file, in which
1885 case we must change the name of the output section. */
1886 subname = o->name + sizeof ".gptab" - 1;
1887 if (bfd_get_section_by_name (abfd, subname) == NULL)
1888 {
1889 if (o == gptab_data_sec)
1890 o->name = ".gptab.data";
1891 else
1892 o->name = ".gptab.bss";
1893 subname = o->name + sizeof ".gptab" - 1;
1894 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
1895 }
1896
1897 /* Set up the first entry. */
1898 c = 1;
1899 tab = (Elf32_gptab *) malloc (c * sizeof (Elf32_gptab));
1900 if (tab == NULL)
1901 {
1902 bfd_set_error (bfd_error_no_memory);
1903 return false;
1904 }
1905 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
1906 tab[0].gt_header.gt_unused = 0;
1907
1908 /* Combine the input sections. */
6e07e54f
ILT
1909 for (p = o->link_order_head;
1910 p != (struct bfd_link_order *) NULL;
1911 p = p->next)
1912 {
aac6b32f
ILT
1913 asection *input_section;
1914 bfd *input_bfd;
1915 bfd_size_type size;
1916 unsigned long last;
1917 bfd_size_type gpentry;
1918
1919 if (p->type != bfd_indirect_link_order)
6e07e54f 1920 {
aac6b32f
ILT
1921 if (p->type == bfd_fill_link_order)
1922 continue;
1923 abort ();
1924 }
6e07e54f 1925
aac6b32f
ILT
1926 input_section = p->u.indirect.section;
1927 input_bfd = input_section->owner;
1928
1929 /* Combine the gptab entries for this input section one
1930 by one. We know that the input gptab entries are
1931 sorted by ascending -G value. */
1932 size = bfd_section_size (input_bfd, input_section);
1933 last = 0;
1934 for (gpentry = sizeof (Elf32_External_gptab);
1935 gpentry < size;
1936 gpentry += sizeof (Elf32_External_gptab))
1937 {
1938 Elf32_External_gptab ext_gptab;
1939 Elf32_gptab int_gptab;
1940 unsigned long val;
1941 unsigned long add;
1942 boolean exact;
1943 unsigned int look;
1944
1945 if (! (bfd_get_section_contents
1946 (input_bfd, input_section, (PTR) &ext_gptab,
1947 gpentry, sizeof (Elf32_External_gptab))))
9783e04a 1948 {
aac6b32f 1949 free (tab);
9783e04a
DM
1950 return false;
1951 }
aac6b32f
ILT
1952
1953 bfd_mips_elf32_swap_gptab_in (input_bfd, &ext_gptab,
1954 &int_gptab);
1955 val = int_gptab.gt_entry.gt_g_value;
1956 add = int_gptab.gt_entry.gt_bytes - last;
1957
1958 exact = false;
1959 for (look = 1; look < c; look++)
1960 {
1961 if (tab[look].gt_entry.gt_g_value >= val)
1962 tab[look].gt_entry.gt_bytes += add;
1963
1964 if (tab[look].gt_entry.gt_g_value == val)
1965 exact = true;
1966 }
1967
1968 if (! exact)
1969 {
1970 Elf32_gptab *new_tab;
1971 unsigned int max;
1972
1973 /* We need a new table entry. */
1974 new_tab = ((Elf32_gptab *)
1975 realloc ((PTR) tab,
1976 (c + 1) * sizeof (Elf32_gptab)));
1977 if (new_tab == NULL)
1978 {
1979 bfd_set_error (bfd_error_no_memory);
1980 free (tab);
1981 return false;
1982 }
1983 tab = new_tab;
1984 tab[c].gt_entry.gt_g_value = val;
1985 tab[c].gt_entry.gt_bytes = add;
1986
1987 /* Merge in the size for the next smallest -G
1988 value, since that will be implied by this new
1989 value. */
1990 max = 0;
1991 for (look = 1; look < c; look++)
1992 {
1993 if (tab[look].gt_entry.gt_g_value < val
1994 && (max == 0
1995 || (tab[look].gt_entry.gt_g_value
1996 > tab[max].gt_entry.gt_g_value)))
1997 max = look;
1998 }
1999 if (max != 0)
2000 tab[c].gt_entry.gt_bytes +=
2001 tab[max].gt_entry.gt_bytes;
2002
2003 ++c;
2004 }
2005
2006 last = int_gptab.gt_entry.gt_bytes;
6e07e54f 2007 }
aac6b32f
ILT
2008
2009 /* Hack: reset the SEC_HAS_CONTENTS flag so that
2010 elf_link_input_bfd ignores this section. */
2011 input_section->flags &=~ SEC_HAS_CONTENTS;
6e07e54f 2012 }
aac6b32f
ILT
2013
2014 /* The table must be sorted by -G value. */
2015 if (c > 2)
2016 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
2017
2018 /* Swap out the table. */
2019 ext_tab = ((Elf32_External_gptab *)
2020 bfd_alloc (abfd, c * sizeof (Elf32_External_gptab)));
2021 if (ext_tab == NULL)
6e07e54f 2022 {
aac6b32f
ILT
2023 bfd_set_error (bfd_error_no_memory);
2024 free (tab);
2025 return false;
2026 }
2027
2028 for (i = 0; i < c; i++)
2029 bfd_mips_elf32_swap_gptab_out (abfd, tab + i, ext_tab + i);
2030 free (tab);
2031
2032 o->_raw_size = c * sizeof (Elf32_External_gptab);
2033 o->contents = (bfd_byte *) ext_tab;
2034
2035 /* Skip this section later on (I don't think this currently
2036 matters, but someday it might). */
2037 o->link_order_head = (struct bfd_link_order *) NULL;
2038 }
2039 }
2040
2041 /* Get a value for the GP register. */
2042 if (elf_gp (abfd) == 0)
2043 {
2044 struct bfd_link_hash_entry *h;
2045
2046 h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
2047 if (h != (struct bfd_link_hash_entry *) NULL
2048 && h->type == bfd_link_hash_defined)
2049 elf_gp (abfd) = (h->u.def.value
2050 + h->u.def.section->output_section->vma
2051 + h->u.def.section->output_offset);
2052 else if (info->relocateable)
2053 {
2054 bfd_vma lo;
2055
2056 /* Make up a value. */
2057 lo = (bfd_vma) -1;
2058 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2059 {
2060 if (o->vma < lo
2061 && (strcmp (o->name, ".sbss") == 0
2062 || strcmp (o->name, ".sdata") == 0
2063 || strcmp (o->name, ".lit4") == 0
2064 || strcmp (o->name, ".lit8") == 0))
2065 lo = o->vma;
6e07e54f 2066 }
aac6b32f
ILT
2067 elf_gp (abfd) = lo + 0x8000;
2068 }
2069 else
2070 {
2071 /* If the relocate_section function needs to do a reloc
2072 involving the GP value, it should make a reloc_dangerous
2073 callback to warn that GP is not defined. */
6e07e54f
ILT
2074 }
2075 }
b3c0fc57 2076
aac6b32f
ILT
2077 /* Invoke the regular ELF backend linker to do all the work. */
2078 if (! bfd_elf32_bfd_final_link (abfd, info))
2079 return false;
2080
2081 /* Now write out the computed sections. */
2082
6e07e54f
ILT
2083 if (reginfo_sec != (asection *) NULL)
2084 {
2085 Elf32_External_RegInfo ext;
2086
2087 bfd_mips_elf32_swap_reginfo_out (abfd, &reginfo, &ext);
2088 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
2089 (file_ptr) 0, sizeof ext))
2090 return false;
2091 }
b3c0fc57 2092
6e07e54f
ILT
2093 if (mdebug_sec != (asection *) NULL)
2094 {
aac6b32f 2095 BFD_ASSERT (abfd->output_has_begun);
9783e04a
DM
2096 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
2097 swap, info,
2098 mdebug_sec->filepos))
6e07e54f 2099 return false;
9783e04a
DM
2100
2101 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
b3c0fc57
ILT
2102 }
2103
aac6b32f 2104 if (gptab_data_sec != (asection *) NULL)
6e07e54f 2105 {
aac6b32f
ILT
2106 if (! bfd_set_section_contents (abfd, gptab_data_sec,
2107 gptab_data_sec->contents,
2108 (file_ptr) 0,
2109 gptab_data_sec->_raw_size))
2110 return false;
2111 }
2112
2113 if (gptab_bss_sec != (asection *) NULL)
2114 {
2115 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
2116 gptab_bss_sec->contents,
2117 (file_ptr) 0,
2118 gptab_bss_sec->_raw_size))
2119 return false;
6e07e54f
ILT
2120 }
2121
2122 return true;
b3c0fc57 2123}
6e07e54f 2124
aac6b32f 2125/* Handle a MIPS ELF HI16 reloc. */
b3c0fc57
ILT
2126
2127static void
aac6b32f
ILT
2128mips_elf_relocate_hi16 (input_bfd, relhi, rello, contents, addend)
2129 bfd *input_bfd;
2130 Elf_Internal_Rela *relhi;
2131 Elf_Internal_Rela *rello;
2132 bfd_byte *contents;
2133 bfd_vma addend;
b3c0fc57 2134{
aac6b32f
ILT
2135 bfd_vma insn;
2136 bfd_vma addlo;
b3c0fc57 2137
aac6b32f
ILT
2138 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
2139
2140 addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
2141 addlo &= 0xffff;
2142
2143 addend += ((insn & 0xffff) << 16) + addlo;
2144
2145 if ((addlo & 0x8000) != 0)
2146 addend -= 0x10000;
2147 if ((addend & 0x8000) != 0)
2148 addend += 0x10000;
2149
2150 bfd_put_32 (input_bfd,
2151 (insn & 0xffff0000) | ((addend >> 16) & 0xffff),
2152 contents + relhi->r_offset);
2153}
2154
2155/* Relocate a MIPS ELF section. */
2156
2157static boolean
2158mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
82b1edf7 2159 contents, relocs, local_syms, local_sections)
aac6b32f
ILT
2160 bfd *output_bfd;
2161 struct bfd_link_info *info;
2162 bfd *input_bfd;
2163 asection *input_section;
2164 bfd_byte *contents;
2165 Elf_Internal_Rela *relocs;
2166 Elf_Internal_Sym *local_syms;
2167 asection **local_sections;
2168{
2169 Elf_Internal_Shdr *symtab_hdr;
2170 size_t locsymcount;
2171 size_t extsymoff;
2172 Elf_Internal_Rela *rel;
2173 Elf_Internal_Rela *relend;
2174
2175 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2176
2177 if (elf_bad_symtab (input_bfd))
b3c0fc57 2178 {
aac6b32f
ILT
2179 locsymcount = symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
2180 extsymoff = 0;
2181 }
2182 else
2183 {
2184 locsymcount = symtab_hdr->sh_info;
2185 extsymoff = symtab_hdr->sh_info;
2186 }
2187
2188 rel = relocs;
2189 relend = relocs + input_section->reloc_count;
2190 for (; rel < relend; rel++)
2191 {
2192 int r_type;
82b1edf7 2193 reloc_howto_type *howto;
aac6b32f
ILT
2194 long r_symndx;
2195 bfd_vma addend;
2196 struct elf_link_hash_entry *h;
2197 asection *sec;
2198 Elf_Internal_Sym *sym;
2199 bfd_reloc_status_type r;
2200
2201 r_type = ELF32_R_TYPE (rel->r_info);
2202 if (r_type < 0 || r_type >= (int) R_MIPS_max)
6e07e54f 2203 {
aac6b32f
ILT
2204 bfd_set_error (bfd_error_bad_value);
2205 return false;
6e07e54f 2206 }
aac6b32f 2207 howto = elf_mips_howto_table + r_type;
b3c0fc57 2208
aac6b32f
ILT
2209 r_symndx = ELF32_R_SYM (rel->r_info);
2210
2211 /* Mix in the change in GP address for a GP relative reloc. */
2212 if (r_type != R_MIPS_GPREL16
2213 && r_type != R_MIPS_LITERAL
2214 && r_type != R_MIPS_GPREL32)
2215 addend = 0;
2216 else
b3c0fc57 2217 {
aac6b32f
ILT
2218 if (elf_gp (output_bfd) == 0)
2219 {
2220 if (! ((*info->callbacks->reloc_dangerous)
2221 (info,
2222 "GP relative relocation when GP not defined",
2223 input_bfd, input_section,
2224 rel->r_offset)))
2225 return false;
2226 /* Only give the error once per link. */
2227 elf_gp (output_bfd) = 4;
2228 }
2229
2230 if (r_symndx < extsymoff
2231 || (elf_bad_symtab (input_bfd)
2232 && local_sections[r_symndx] != NULL))
2233 {
2234 /* This is a relocation against a section. The current
2235 addend in the instruction is the difference between
2236 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
2237 must change this to be the difference between the
2238 final definition (which will end up in RELOCATION)
2239 and the GP value of OUTPUT_BFD (which is in GP). */
2240 addend = elf_gp (input_bfd) - elf_gp (output_bfd);
2241 }
2242 else if (! info->relocateable)
2243 {
2244 /* We are doing a final link. The current addend in the
2245 instruction is simply the desired offset into the
2246 symbol (normally zero). We want the instruction to
2247 hold the difference between the final definition of
2248 the symbol (which will end up in RELOCATION) and the
2249 GP value of OUTPUT_BFD (which is in GP). */
2250 addend = - elf_gp (output_bfd);
2251 }
2252 else
2253 {
2254 /* We are generating relocateable output, and we aren't
2255 going to define this symbol, so we just leave the
2256 instruction alone. */
2257 addend = 0;
2258 }
b3c0fc57 2259 }
b3c0fc57 2260
aac6b32f
ILT
2261 h = NULL;
2262 sym = NULL;
2263 sec = NULL;
2264 if (info->relocateable)
2265 {
2266 /* This is a relocateable link. We don't have to change
2267 anything, unless the reloc is against a section symbol,
2268 in which case we have to adjust according to where the
2269 section symbol winds up in the output section. */
2270 if (r_symndx >= locsymcount
2271 || (elf_bad_symtab (input_bfd)
2272 && local_sections[r_symndx] == NULL))
2273 r = bfd_reloc_ok;
2274 else
2275 {
2276 sym = local_syms + r_symndx;
2277 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
2278 r = bfd_reloc_ok;
2279 else
2280 {
2281 sec = local_sections[r_symndx];
2282
2283 /* It would be logical to add sym->st_value here,
2284 but Irix 5 sometimes generates a garbage symbol
2285 value. */
2286 addend += sec->output_offset;
2287
2288 /* If this is HI16 with an associated LO16, adjust
2289 the addend accordingly. Otherwise, just
2290 relocate. */
2291 if (r_type != R_MIPS_HI16
2292 || (rel + 1) >= relend
2293 || ELF32_R_TYPE ((rel + 1)->r_info) != R_MIPS_LO16)
2294 r = _bfd_relocate_contents (howto, input_bfd,
2295 addend,
2296 contents + rel->r_offset);
2297 else
2298 {
2299 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1,
2300 contents, addend);
2301 r = bfd_reloc_ok;
2302 }
2303 }
2304 }
2305 }
2306 else
2307 {
2308 bfd_vma relocation;
2309
2310 /* This is a final link. */
2311 sym = NULL;
2312 if (r_symndx < extsymoff
2313 || (elf_bad_symtab (input_bfd)
2314 && local_sections[r_symndx] != NULL))
2315 {
2316 sym = local_syms + r_symndx;
2317 sec = local_sections[r_symndx];
2318 relocation = (sec->output_section->vma
2319 + sec->output_offset);
2320
2321 /* It would be logical to always add sym->st_value here,
2322 but Irix 5 sometimes generates a garbage symbol
2323 value. */
2324 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
2325 relocation += sym->st_value;
2326 }
2327 else
2328 {
2329 long indx;
2330
2331 indx = r_symndx - extsymoff;
2332 h = elf_sym_hashes (input_bfd)[indx];
2333 if (h->root.type == bfd_link_hash_defined)
2334 {
2335 sec = h->root.u.def.section;
2336 relocation = (h->root.u.def.value
2337 + sec->output_section->vma
2338 + sec->output_offset);
2339 }
2340 else if (h->root.type == bfd_link_hash_weak)
2341 relocation = 0;
2342 else
2343 {
2344 if (! ((*info->callbacks->undefined_symbol)
2345 (info, h->root.root.string, input_bfd,
2346 input_section, rel->r_offset)))
2347 return false;
2348 relocation = 0;
2349 }
2350 }
2351
2352 if (r_type != R_MIPS_HI16
2353 || (rel + 1) >= relend
2354 || ELF32_R_TYPE ((rel + 1)->r_info) != R_MIPS_LO16)
2355 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2356 contents, rel->r_offset,
2357 relocation, addend);
2358 else
2359 {
2360 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1,
2361 contents, relocation + addend);
2362 r = bfd_reloc_ok;
2363 }
2364 }
2365
2366 if (r != bfd_reloc_ok)
2367 {
2368 switch (r)
2369 {
2370 default:
2371 case bfd_reloc_outofrange:
2372 abort ();
2373 case bfd_reloc_overflow:
2374 {
2375 const char *name;
2376
2377 if (h != NULL)
2378 name = h->root.root.string;
2379 else
2380 {
82b1edf7
KR
2381 name = elf_string_from_elf_section (input_bfd,
2382 symtab_hdr->sh_link,
2383 sym->st_name);
aac6b32f
ILT
2384 if (name == NULL)
2385 return false;
2386 if (*name == '\0')
2387 name = bfd_section_name (input_bfd, sec);
2388 }
2389 if (! ((*info->callbacks->reloc_overflow)
2390 (info, name, howto->name, (bfd_vma) 0,
2391 input_bfd, input_section, rel->r_offset)))
2392 return false;
2393 }
2394 break;
2395 }
2396 }
b3c0fc57 2397 }
aac6b32f
ILT
2398
2399 return true;
b3c0fc57
ILT
2400}
2401\f
6e07e54f
ILT
2402/* ECOFF swapping routines. These are used when dealing with the
2403 .mdebug section, which is in the ECOFF debugging format. */
2404static const struct ecoff_debug_swap mips_elf_ecoff_debug_swap =
2405{
2406 /* Symbol table magic number. */
2407 magicSym,
2408 /* Alignment of debugging information. E.g., 4. */
2409 4,
2410 /* Sizes of external symbolic information. */
2411 sizeof (struct hdr_ext),
2412 sizeof (struct dnr_ext),
2413 sizeof (struct pdr_ext),
2414 sizeof (struct sym_ext),
2415 sizeof (struct opt_ext),
2416 sizeof (struct fdr_ext),
2417 sizeof (struct rfd_ext),
2418 sizeof (struct ext_ext),
2419 /* Functions to swap in external symbolic data. */
2420 ecoff_swap_hdr_in,
2421 ecoff_swap_dnr_in,
2422 ecoff_swap_pdr_in,
2423 ecoff_swap_sym_in,
2424 ecoff_swap_opt_in,
2425 ecoff_swap_fdr_in,
2426 ecoff_swap_rfd_in,
2427 ecoff_swap_ext_in,
75f3ef7a
ILT
2428 _bfd_ecoff_swap_tir_in,
2429 _bfd_ecoff_swap_rndx_in,
6e07e54f
ILT
2430 /* Functions to swap out external symbolic data. */
2431 ecoff_swap_hdr_out,
2432 ecoff_swap_dnr_out,
2433 ecoff_swap_pdr_out,
2434 ecoff_swap_sym_out,
2435 ecoff_swap_opt_out,
2436 ecoff_swap_fdr_out,
2437 ecoff_swap_rfd_out,
aac6b32f 2438 ecoff_swap_ext_out,
75f3ef7a
ILT
2439 _bfd_ecoff_swap_tir_out,
2440 _bfd_ecoff_swap_rndx_out,
aac6b32f
ILT
2441 /* Function to read in symbolic data. */
2442 mips_elf_read_ecoff_info
6e07e54f
ILT
2443};
2444\f
6b4b4d17
JK
2445#define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
2446#define TARGET_LITTLE_NAME "elf32-littlemips"
2447#define TARGET_BIG_SYM bfd_elf32_bigmips_vec
2448#define TARGET_BIG_NAME "elf32-bigmips"
2449#define ELF_ARCH bfd_arch_mips
6e07e54f 2450#define ELF_MACHINE_CODE EM_MIPS
b3c0fc57 2451#define ELF_MAXPAGESIZE 0x10000
497c5434 2452#define elf_backend_collect true
b3c0fc57
ILT
2453#define elf_info_to_howto 0
2454#define elf_info_to_howto_rel mips_info_to_howto_rel
6e07e54f
ILT
2455#define elf_backend_sym_is_global mips_elf_sym_is_global
2456#define elf_backend_object_p mips_elf_object_p
b3c0fc57
ILT
2457#define elf_backend_section_from_shdr mips_elf_section_from_shdr
2458#define elf_backend_fake_sections mips_elf_fake_sections
2459#define elf_backend_section_from_bfd_section \
2460 mips_elf_section_from_bfd_section
2461#define elf_backend_section_processing mips_elf_section_processing
2462#define elf_backend_symbol_processing mips_elf_symbol_processing
6e07e54f
ILT
2463#define elf_backend_final_write_processing \
2464 mips_elf_final_write_processing
2465#define elf_backend_ecoff_debug_swap &mips_elf_ecoff_debug_swap
b3c0fc57 2466
aac6b32f
ILT
2467#define bfd_elf32_bfd_link_hash_table_create \
2468 mips_elf_link_hash_table_create
6e07e54f 2469#define bfd_elf32_bfd_final_link mips_elf_final_link
aac6b32f
ILT
2470#define elf_backend_relocate_section mips_elf_relocate_section
2471#define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
6b4b4d17
JK
2472
2473#include "elf32-target.h"
This page took 0.181921 seconds and 4 git commands to generate.