include/elf/ChangeLog
[deliverable/binutils-gdb.git] / bfd / elf32-mips.c
1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
6 <ian@cygnus.com>.
7 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
8 <mark@codesourcery.com>
9 Traditional MIPS targets support added by Koundinya.K, Dansk Data
10 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
11
12 This file is part of BFD, the Binary File Descriptor library.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27
28 /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
29 different MIPS ELF from other targets. This matters when linking.
30 This file supports both, switching at runtime. */
31
32 #include "bfd.h"
33 #include "sysdep.h"
34 #include "libbfd.h"
35 #include "bfdlink.h"
36 #include "genlink.h"
37 #include "elf-bfd.h"
38 #include "elfxx-mips.h"
39 #include "elf/mips.h"
40
41 /* Get the ECOFF swapping routines. */
42 #include "coff/sym.h"
43 #include "coff/symconst.h"
44 #include "coff/internal.h"
45 #include "coff/ecoff.h"
46 #include "coff/mips.h"
47 #define ECOFF_SIGNED_32
48 #include "ecoffswap.h"
49
50 static bfd_reloc_status_type mips_elf_hi16_reloc
51 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
52 static bfd_reloc_status_type mips_elf_lo16_reloc
53 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
54 static bfd_reloc_status_type mips_elf_got16_reloc
55 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
56 static bfd_reloc_status_type mips_elf_gprel32_reloc
57 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
58 static bfd_reloc_status_type mips32_64bit_reloc
59 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
60 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
61 PARAMS ((bfd *, bfd_reloc_code_real_type));
62 static reloc_howto_type *mips_elf32_rtype_to_howto
63 PARAMS ((unsigned int, boolean));
64 static void mips_info_to_howto_rel
65 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
66 static void mips_info_to_howto_rela
67 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
68 static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
69 static boolean mips_elf32_object_p PARAMS ((bfd *));
70 static boolean mips_elf_is_local_label_name
71 PARAMS ((bfd *, const char *));
72 static bfd_reloc_status_type mips16_jump_reloc
73 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
74 static bfd_reloc_status_type mips16_gprel_reloc
75 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
76 static bfd_reloc_status_type mips_elf_final_gp
77 PARAMS ((bfd *, asymbol *, boolean, char **, bfd_vma *));
78 static boolean mips_elf_assign_gp PARAMS ((bfd *, bfd_vma *));
79 static boolean elf32_mips_grok_prstatus
80 PARAMS ((bfd *, Elf_Internal_Note *));
81 static boolean elf32_mips_grok_psinfo
82 PARAMS ((bfd *, Elf_Internal_Note *));
83 static irix_compat_t elf32_mips_irix_compat
84 PARAMS ((bfd *));
85
86 extern const bfd_target bfd_elf32_bigmips_vec;
87 extern const bfd_target bfd_elf32_littlemips_vec;
88
89 /* Nonzero if ABFD is using the N32 ABI. */
90 #define ABI_N32_P(abfd) \
91 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
92
93 /* Whether we are trying to be compatible with IRIX at all. */
94 #define SGI_COMPAT(abfd) \
95 (elf32_mips_irix_compat (abfd) != ict_none)
96
97 /* The number of local .got entries we reserve. */
98 #define MIPS_RESERVED_GOTNO (2)
99
100 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
101 from smaller values. Start with zero, widen, *then* decrement. */
102 #define MINUS_ONE (((bfd_vma)0) - 1)
103
104 /* The relocation table used for SHT_REL sections. */
105
106 static reloc_howto_type elf_mips_howto_table_rel[] =
107 {
108 /* No relocation. */
109 HOWTO (R_MIPS_NONE, /* type */
110 0, /* rightshift */
111 0, /* size (0 = byte, 1 = short, 2 = long) */
112 0, /* bitsize */
113 false, /* pc_relative */
114 0, /* bitpos */
115 complain_overflow_dont, /* complain_on_overflow */
116 bfd_elf_generic_reloc, /* special_function */
117 "R_MIPS_NONE", /* name */
118 false, /* partial_inplace */
119 0, /* src_mask */
120 0, /* dst_mask */
121 false), /* pcrel_offset */
122
123 /* 16 bit relocation. */
124 HOWTO (R_MIPS_16, /* type */
125 0, /* rightshift */
126 2, /* size (0 = byte, 1 = short, 2 = long) */
127 16, /* bitsize */
128 false, /* pc_relative */
129 0, /* bitpos */
130 complain_overflow_signed, /* complain_on_overflow */
131 bfd_elf_generic_reloc, /* special_function */
132 "R_MIPS_16", /* name */
133 true, /* partial_inplace */
134 0x0000ffff, /* src_mask */
135 0x0000ffff, /* dst_mask */
136 false), /* pcrel_offset */
137
138 /* 32 bit relocation. */
139 HOWTO (R_MIPS_32, /* type */
140 0, /* rightshift */
141 2, /* size (0 = byte, 1 = short, 2 = long) */
142 32, /* bitsize */
143 false, /* pc_relative */
144 0, /* bitpos */
145 complain_overflow_dont, /* complain_on_overflow */
146 bfd_elf_generic_reloc, /* special_function */
147 "R_MIPS_32", /* name */
148 true, /* partial_inplace */
149 0xffffffff, /* src_mask */
150 0xffffffff, /* dst_mask */
151 false), /* pcrel_offset */
152
153 /* 32 bit symbol relative relocation. */
154 HOWTO (R_MIPS_REL32, /* type */
155 0, /* rightshift */
156 2, /* size (0 = byte, 1 = short, 2 = long) */
157 32, /* bitsize */
158 false, /* pc_relative */
159 0, /* bitpos */
160 complain_overflow_dont, /* complain_on_overflow */
161 bfd_elf_generic_reloc, /* special_function */
162 "R_MIPS_REL32", /* name */
163 true, /* partial_inplace */
164 0xffffffff, /* src_mask */
165 0xffffffff, /* dst_mask */
166 false), /* pcrel_offset */
167
168 /* 26 bit jump address. */
169 HOWTO (R_MIPS_26, /* type */
170 2, /* rightshift */
171 2, /* size (0 = byte, 1 = short, 2 = long) */
172 26, /* bitsize */
173 false, /* pc_relative */
174 0, /* bitpos */
175 complain_overflow_dont, /* complain_on_overflow */
176 /* This needs complex overflow
177 detection, because the upper four
178 bits must match the PC + 4. */
179 bfd_elf_generic_reloc, /* special_function */
180 "R_MIPS_26", /* name */
181 true, /* partial_inplace */
182 0x03ffffff, /* src_mask */
183 0x03ffffff, /* dst_mask */
184 false), /* pcrel_offset */
185
186 /* High 16 bits of symbol value. */
187 HOWTO (R_MIPS_HI16, /* type */
188 0, /* rightshift */
189 2, /* size (0 = byte, 1 = short, 2 = long) */
190 16, /* bitsize */
191 false, /* pc_relative */
192 0, /* bitpos */
193 complain_overflow_dont, /* complain_on_overflow */
194 mips_elf_hi16_reloc, /* special_function */
195 "R_MIPS_HI16", /* name */
196 true, /* partial_inplace */
197 0x0000ffff, /* src_mask */
198 0x0000ffff, /* dst_mask */
199 false), /* pcrel_offset */
200
201 /* Low 16 bits of symbol value. */
202 HOWTO (R_MIPS_LO16, /* type */
203 0, /* rightshift */
204 2, /* size (0 = byte, 1 = short, 2 = long) */
205 16, /* bitsize */
206 false, /* pc_relative */
207 0, /* bitpos */
208 complain_overflow_dont, /* complain_on_overflow */
209 mips_elf_lo16_reloc, /* special_function */
210 "R_MIPS_LO16", /* name */
211 true, /* partial_inplace */
212 0x0000ffff, /* src_mask */
213 0x0000ffff, /* dst_mask */
214 false), /* pcrel_offset */
215
216 /* GP relative reference. */
217 HOWTO (R_MIPS_GPREL16, /* type */
218 0, /* rightshift */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
220 16, /* bitsize */
221 false, /* pc_relative */
222 0, /* bitpos */
223 complain_overflow_signed, /* complain_on_overflow */
224 _bfd_mips_elf32_gprel16_reloc, /* special_function */
225 "R_MIPS_GPREL16", /* name */
226 true, /* partial_inplace */
227 0x0000ffff, /* src_mask */
228 0x0000ffff, /* dst_mask */
229 false), /* pcrel_offset */
230
231 /* Reference to literal section. */
232 HOWTO (R_MIPS_LITERAL, /* type */
233 0, /* rightshift */
234 2, /* size (0 = byte, 1 = short, 2 = long) */
235 16, /* bitsize */
236 false, /* pc_relative */
237 0, /* bitpos */
238 complain_overflow_signed, /* complain_on_overflow */
239 _bfd_mips_elf32_gprel16_reloc, /* special_function */
240 "R_MIPS_LITERAL", /* name */
241 true, /* partial_inplace */
242 0x0000ffff, /* src_mask */
243 0x0000ffff, /* dst_mask */
244 false), /* pcrel_offset */
245
246 /* Reference to global offset table. */
247 HOWTO (R_MIPS_GOT16, /* type */
248 0, /* rightshift */
249 2, /* size (0 = byte, 1 = short, 2 = long) */
250 16, /* bitsize */
251 false, /* pc_relative */
252 0, /* bitpos */
253 complain_overflow_signed, /* complain_on_overflow */
254 mips_elf_got16_reloc, /* special_function */
255 "R_MIPS_GOT16", /* name */
256 true, /* partial_inplace */
257 0x0000ffff, /* src_mask */
258 0x0000ffff, /* dst_mask */
259 false), /* pcrel_offset */
260
261 /* 16 bit PC relative reference. */
262 HOWTO (R_MIPS_PC16, /* type */
263 0, /* rightshift */
264 2, /* size (0 = byte, 1 = short, 2 = long) */
265 16, /* bitsize */
266 true, /* pc_relative */
267 0, /* bitpos */
268 complain_overflow_signed, /* complain_on_overflow */
269 bfd_elf_generic_reloc, /* special_function */
270 "R_MIPS_PC16", /* name */
271 true, /* partial_inplace */
272 0x0000ffff, /* src_mask */
273 0x0000ffff, /* dst_mask */
274 true), /* pcrel_offset */
275
276 /* 16 bit call through global offset table. */
277 HOWTO (R_MIPS_CALL16, /* type */
278 0, /* rightshift */
279 2, /* size (0 = byte, 1 = short, 2 = long) */
280 16, /* bitsize */
281 false, /* pc_relative */
282 0, /* bitpos */
283 complain_overflow_signed, /* complain_on_overflow */
284 bfd_elf_generic_reloc, /* special_function */
285 "R_MIPS_CALL16", /* name */
286 true, /* partial_inplace */
287 0x0000ffff, /* src_mask */
288 0x0000ffff, /* dst_mask */
289 false), /* pcrel_offset */
290
291 /* 32 bit GP relative reference. */
292 HOWTO (R_MIPS_GPREL32, /* type */
293 0, /* rightshift */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
295 32, /* bitsize */
296 false, /* pc_relative */
297 0, /* bitpos */
298 complain_overflow_dont, /* complain_on_overflow */
299 mips_elf_gprel32_reloc, /* special_function */
300 "R_MIPS_GPREL32", /* name */
301 true, /* partial_inplace */
302 0xffffffff, /* src_mask */
303 0xffffffff, /* dst_mask */
304 false), /* pcrel_offset */
305
306 /* The remaining relocs are defined on Irix 5, although they are
307 not defined by the ABI. */
308 EMPTY_HOWTO (13),
309 EMPTY_HOWTO (14),
310 EMPTY_HOWTO (15),
311
312 /* A 5 bit shift field. */
313 HOWTO (R_MIPS_SHIFT5, /* type */
314 0, /* rightshift */
315 2, /* size (0 = byte, 1 = short, 2 = long) */
316 5, /* bitsize */
317 false, /* pc_relative */
318 6, /* bitpos */
319 complain_overflow_bitfield, /* complain_on_overflow */
320 bfd_elf_generic_reloc, /* special_function */
321 "R_MIPS_SHIFT5", /* name */
322 true, /* partial_inplace */
323 0x000007c0, /* src_mask */
324 0x000007c0, /* dst_mask */
325 false), /* pcrel_offset */
326
327 /* A 6 bit shift field. */
328 /* FIXME: This is not handled correctly; a special function is
329 needed to put the most significant bit in the right place. */
330 HOWTO (R_MIPS_SHIFT6, /* type */
331 0, /* rightshift */
332 2, /* size (0 = byte, 1 = short, 2 = long) */
333 6, /* bitsize */
334 false, /* pc_relative */
335 6, /* bitpos */
336 complain_overflow_bitfield, /* complain_on_overflow */
337 bfd_elf_generic_reloc, /* special_function */
338 "R_MIPS_SHIFT6", /* name */
339 true, /* partial_inplace */
340 0x000007c4, /* src_mask */
341 0x000007c4, /* dst_mask */
342 false), /* pcrel_offset */
343
344 /* A 64 bit relocation. */
345 HOWTO (R_MIPS_64, /* type */
346 0, /* rightshift */
347 4, /* size (0 = byte, 1 = short, 2 = long) */
348 64, /* bitsize */
349 false, /* pc_relative */
350 0, /* bitpos */
351 complain_overflow_dont, /* complain_on_overflow */
352 mips32_64bit_reloc, /* special_function */
353 "R_MIPS_64", /* name */
354 true, /* partial_inplace */
355 MINUS_ONE, /* src_mask */
356 MINUS_ONE, /* dst_mask */
357 false), /* pcrel_offset */
358
359 /* Displacement in the global offset table. */
360 HOWTO (R_MIPS_GOT_DISP, /* type */
361 0, /* rightshift */
362 2, /* size (0 = byte, 1 = short, 2 = long) */
363 16, /* bitsize */
364 false, /* pc_relative */
365 0, /* bitpos */
366 complain_overflow_signed, /* complain_on_overflow */
367 bfd_elf_generic_reloc, /* special_function */
368 "R_MIPS_GOT_DISP", /* name */
369 true, /* partial_inplace */
370 0x0000ffff, /* src_mask */
371 0x0000ffff, /* dst_mask */
372 false), /* pcrel_offset */
373
374 /* Displacement to page pointer in the global offset table. */
375 HOWTO (R_MIPS_GOT_PAGE, /* type */
376 0, /* rightshift */
377 2, /* size (0 = byte, 1 = short, 2 = long) */
378 16, /* bitsize */
379 false, /* pc_relative */
380 0, /* bitpos */
381 complain_overflow_signed, /* complain_on_overflow */
382 bfd_elf_generic_reloc, /* special_function */
383 "R_MIPS_GOT_PAGE", /* name */
384 true, /* partial_inplace */
385 0x0000ffff, /* src_mask */
386 0x0000ffff, /* dst_mask */
387 false), /* pcrel_offset */
388
389 /* Offset from page pointer in the global offset table. */
390 HOWTO (R_MIPS_GOT_OFST, /* type */
391 0, /* rightshift */
392 2, /* size (0 = byte, 1 = short, 2 = long) */
393 16, /* bitsize */
394 false, /* pc_relative */
395 0, /* bitpos */
396 complain_overflow_signed, /* complain_on_overflow */
397 bfd_elf_generic_reloc, /* special_function */
398 "R_MIPS_GOT_OFST", /* name */
399 true, /* partial_inplace */
400 0x0000ffff, /* src_mask */
401 0x0000ffff, /* dst_mask */
402 false), /* pcrel_offset */
403
404 /* High 16 bits of displacement in global offset table. */
405 HOWTO (R_MIPS_GOT_HI16, /* type */
406 0, /* rightshift */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
408 16, /* bitsize */
409 false, /* pc_relative */
410 0, /* bitpos */
411 complain_overflow_dont, /* complain_on_overflow */
412 bfd_elf_generic_reloc, /* special_function */
413 "R_MIPS_GOT_HI16", /* name */
414 true, /* partial_inplace */
415 0x0000ffff, /* src_mask */
416 0x0000ffff, /* dst_mask */
417 false), /* pcrel_offset */
418
419 /* Low 16 bits of displacement in global offset table. */
420 HOWTO (R_MIPS_GOT_LO16, /* type */
421 0, /* rightshift */
422 2, /* size (0 = byte, 1 = short, 2 = long) */
423 16, /* bitsize */
424 false, /* pc_relative */
425 0, /* bitpos */
426 complain_overflow_dont, /* complain_on_overflow */
427 bfd_elf_generic_reloc, /* special_function */
428 "R_MIPS_GOT_LO16", /* name */
429 true, /* partial_inplace */
430 0x0000ffff, /* src_mask */
431 0x0000ffff, /* dst_mask */
432 false), /* pcrel_offset */
433
434 /* 64 bit subtraction. Used in the N32 ABI. */
435 HOWTO (R_MIPS_SUB, /* type */
436 0, /* rightshift */
437 4, /* size (0 = byte, 1 = short, 2 = long) */
438 64, /* bitsize */
439 false, /* pc_relative */
440 0, /* bitpos */
441 complain_overflow_dont, /* complain_on_overflow */
442 bfd_elf_generic_reloc, /* special_function */
443 "R_MIPS_SUB", /* name */
444 true, /* partial_inplace */
445 MINUS_ONE, /* src_mask */
446 MINUS_ONE, /* dst_mask */
447 false), /* pcrel_offset */
448
449 /* Used to cause the linker to insert and delete instructions? */
450 EMPTY_HOWTO (R_MIPS_INSERT_A),
451 EMPTY_HOWTO (R_MIPS_INSERT_B),
452 EMPTY_HOWTO (R_MIPS_DELETE),
453
454 /* Get the higher value of a 64 bit addend. */
455 HOWTO (R_MIPS_HIGHER, /* type */
456 0, /* rightshift */
457 2, /* size (0 = byte, 1 = short, 2 = long) */
458 16, /* bitsize */
459 false, /* pc_relative */
460 0, /* bitpos */
461 complain_overflow_dont, /* complain_on_overflow */
462 bfd_elf_generic_reloc, /* special_function */
463 "R_MIPS_HIGHER", /* name */
464 true, /* partial_inplace */
465 0x0000ffff, /* src_mask */
466 0x0000ffff, /* dst_mask */
467 false), /* pcrel_offset */
468
469 /* Get the highest value of a 64 bit addend. */
470 HOWTO (R_MIPS_HIGHEST, /* type */
471 0, /* rightshift */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
473 16, /* bitsize */
474 false, /* pc_relative */
475 0, /* bitpos */
476 complain_overflow_dont, /* complain_on_overflow */
477 bfd_elf_generic_reloc, /* special_function */
478 "R_MIPS_HIGHEST", /* name */
479 true, /* partial_inplace */
480 0x0000ffff, /* src_mask */
481 0x0000ffff, /* dst_mask */
482 false), /* pcrel_offset */
483
484 /* High 16 bits of displacement in global offset table. */
485 HOWTO (R_MIPS_CALL_HI16, /* type */
486 0, /* rightshift */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
488 16, /* bitsize */
489 false, /* pc_relative */
490 0, /* bitpos */
491 complain_overflow_dont, /* complain_on_overflow */
492 bfd_elf_generic_reloc, /* special_function */
493 "R_MIPS_CALL_HI16", /* name */
494 true, /* partial_inplace */
495 0x0000ffff, /* src_mask */
496 0x0000ffff, /* dst_mask */
497 false), /* pcrel_offset */
498
499 /* Low 16 bits of displacement in global offset table. */
500 HOWTO (R_MIPS_CALL_LO16, /* type */
501 0, /* rightshift */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
503 16, /* bitsize */
504 false, /* pc_relative */
505 0, /* bitpos */
506 complain_overflow_dont, /* complain_on_overflow */
507 bfd_elf_generic_reloc, /* special_function */
508 "R_MIPS_CALL_LO16", /* name */
509 true, /* partial_inplace */
510 0x0000ffff, /* src_mask */
511 0x0000ffff, /* dst_mask */
512 false), /* pcrel_offset */
513
514 /* Section displacement. */
515 HOWTO (R_MIPS_SCN_DISP, /* type */
516 0, /* rightshift */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
518 32, /* bitsize */
519 false, /* pc_relative */
520 0, /* bitpos */
521 complain_overflow_dont, /* complain_on_overflow */
522 bfd_elf_generic_reloc, /* special_function */
523 "R_MIPS_SCN_DISP", /* name */
524 true, /* partial_inplace */
525 0xffffffff, /* src_mask */
526 0xffffffff, /* dst_mask */
527 false), /* pcrel_offset */
528
529 EMPTY_HOWTO (R_MIPS_REL16),
530 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
531 EMPTY_HOWTO (R_MIPS_PJUMP),
532 EMPTY_HOWTO (R_MIPS_RELGOT),
533
534 /* Protected jump conversion. This is an optimization hint. No
535 relocation is required for correctness. */
536 HOWTO (R_MIPS_JALR, /* type */
537 0, /* rightshift */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
539 32, /* bitsize */
540 false, /* pc_relative */
541 0, /* bitpos */
542 complain_overflow_dont, /* complain_on_overflow */
543 bfd_elf_generic_reloc, /* special_function */
544 "R_MIPS_JALR", /* name */
545 false, /* partial_inplace */
546 0x00000000, /* src_mask */
547 0x00000000, /* dst_mask */
548 false), /* pcrel_offset */
549 };
550
551 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
552 is a hack to make the linker think that we need 64 bit values. */
553 static reloc_howto_type elf_mips_ctor64_howto =
554 HOWTO (R_MIPS_64, /* type */
555 0, /* rightshift */
556 4, /* size (0 = byte, 1 = short, 2 = long) */
557 32, /* bitsize */
558 false, /* pc_relative */
559 0, /* bitpos */
560 complain_overflow_signed, /* complain_on_overflow */
561 mips32_64bit_reloc, /* special_function */
562 "R_MIPS_64", /* name */
563 true, /* partial_inplace */
564 0xffffffff, /* src_mask */
565 0xffffffff, /* dst_mask */
566 false); /* pcrel_offset */
567
568 /* The reloc used for the mips16 jump instruction. */
569 static reloc_howto_type elf_mips16_jump_howto =
570 HOWTO (R_MIPS16_26, /* type */
571 2, /* rightshift */
572 2, /* size (0 = byte, 1 = short, 2 = long) */
573 26, /* bitsize */
574 false, /* pc_relative */
575 0, /* bitpos */
576 complain_overflow_dont, /* complain_on_overflow */
577 /* This needs complex overflow
578 detection, because the upper four
579 bits must match the PC. */
580 mips16_jump_reloc, /* special_function */
581 "R_MIPS16_26", /* name */
582 true, /* partial_inplace */
583 0x3ffffff, /* src_mask */
584 0x3ffffff, /* dst_mask */
585 false); /* pcrel_offset */
586
587 /* The reloc used for the mips16 gprel instruction. */
588 static reloc_howto_type elf_mips16_gprel_howto =
589 HOWTO (R_MIPS16_GPREL, /* type */
590 0, /* rightshift */
591 2, /* size (0 = byte, 1 = short, 2 = long) */
592 16, /* bitsize */
593 false, /* pc_relative */
594 0, /* bitpos */
595 complain_overflow_signed, /* complain_on_overflow */
596 mips16_gprel_reloc, /* special_function */
597 "R_MIPS16_GPREL", /* name */
598 true, /* partial_inplace */
599 0x07ff001f, /* src_mask */
600 0x07ff001f, /* dst_mask */
601 false); /* pcrel_offset */
602
603 /* GNU extensions for embedded-pic. */
604 /* High 16 bits of symbol value, pc-relative. */
605 static reloc_howto_type elf_mips_gnu_rel_hi16 =
606 HOWTO (R_MIPS_GNU_REL_HI16, /* type */
607 0, /* rightshift */
608 2, /* size (0 = byte, 1 = short, 2 = long) */
609 16, /* bitsize */
610 true, /* pc_relative */
611 0, /* bitpos */
612 complain_overflow_dont, /* complain_on_overflow */
613 mips_elf_hi16_reloc, /* special_function */
614 "R_MIPS_GNU_REL_HI16", /* name */
615 true, /* partial_inplace */
616 0xffff, /* src_mask */
617 0xffff, /* dst_mask */
618 true); /* pcrel_offset */
619
620 /* Low 16 bits of symbol value, pc-relative. */
621 static reloc_howto_type elf_mips_gnu_rel_lo16 =
622 HOWTO (R_MIPS_GNU_REL_LO16, /* type */
623 0, /* rightshift */
624 2, /* size (0 = byte, 1 = short, 2 = long) */
625 16, /* bitsize */
626 true, /* pc_relative */
627 0, /* bitpos */
628 complain_overflow_dont, /* complain_on_overflow */
629 mips_elf_lo16_reloc, /* special_function */
630 "R_MIPS_GNU_REL_LO16", /* name */
631 true, /* partial_inplace */
632 0xffff, /* src_mask */
633 0xffff, /* dst_mask */
634 true); /* pcrel_offset */
635
636 /* 16 bit offset for pc-relative branches. */
637 static reloc_howto_type elf_mips_gnu_rel16_s2 =
638 HOWTO (R_MIPS_GNU_REL16_S2, /* type */
639 2, /* rightshift */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
641 16, /* bitsize */
642 true, /* pc_relative */
643 0, /* bitpos */
644 complain_overflow_signed, /* complain_on_overflow */
645 bfd_elf_generic_reloc, /* special_function */
646 "R_MIPS_GNU_REL16_S2", /* name */
647 true, /* partial_inplace */
648 0xffff, /* src_mask */
649 0xffff, /* dst_mask */
650 true); /* pcrel_offset */
651
652 /* 64 bit pc-relative. */
653 static reloc_howto_type elf_mips_gnu_pcrel64 =
654 HOWTO (R_MIPS_PC64, /* type */
655 0, /* rightshift */
656 4, /* size (0 = byte, 1 = short, 2 = long) */
657 64, /* bitsize */
658 true, /* pc_relative */
659 0, /* bitpos */
660 complain_overflow_signed, /* complain_on_overflow */
661 bfd_elf_generic_reloc, /* special_function */
662 "R_MIPS_PC64", /* name */
663 true, /* partial_inplace */
664 MINUS_ONE, /* src_mask */
665 MINUS_ONE, /* dst_mask */
666 true); /* pcrel_offset */
667
668 /* 32 bit pc-relative. */
669 static reloc_howto_type elf_mips_gnu_pcrel32 =
670 HOWTO (R_MIPS_PC32, /* type */
671 0, /* rightshift */
672 2, /* size (0 = byte, 1 = short, 2 = long) */
673 32, /* bitsize */
674 true, /* pc_relative */
675 0, /* bitpos */
676 complain_overflow_signed, /* complain_on_overflow */
677 bfd_elf_generic_reloc, /* special_function */
678 "R_MIPS_PC32", /* name */
679 true, /* partial_inplace */
680 0xffffffff, /* src_mask */
681 0xffffffff, /* dst_mask */
682 true); /* pcrel_offset */
683
684 /* GNU extension to record C++ vtable hierarchy */
685 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
686 HOWTO (R_MIPS_GNU_VTINHERIT, /* type */
687 0, /* rightshift */
688 2, /* size (0 = byte, 1 = short, 2 = long) */
689 0, /* bitsize */
690 false, /* pc_relative */
691 0, /* bitpos */
692 complain_overflow_dont, /* complain_on_overflow */
693 NULL, /* special_function */
694 "R_MIPS_GNU_VTINHERIT", /* name */
695 false, /* partial_inplace */
696 0, /* src_mask */
697 0, /* dst_mask */
698 false); /* pcrel_offset */
699
700 /* GNU extension to record C++ vtable member usage */
701 static reloc_howto_type elf_mips_gnu_vtentry_howto =
702 HOWTO (R_MIPS_GNU_VTENTRY, /* type */
703 0, /* rightshift */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
705 0, /* bitsize */
706 false, /* pc_relative */
707 0, /* bitpos */
708 complain_overflow_dont, /* complain_on_overflow */
709 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
710 "R_MIPS_GNU_VTENTRY", /* name */
711 false, /* partial_inplace */
712 0, /* src_mask */
713 0, /* dst_mask */
714 false); /* pcrel_offset */
715
716 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
717 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
718 the HI16. Here we just save the information we need; we do the
719 actual relocation when we see the LO16.
720
721 MIPS ELF requires that the LO16 immediately follow the HI16. As a
722 GNU extension, for non-pc-relative relocations, we permit an
723 arbitrary number of HI16 relocs to be associated with a single LO16
724 reloc. This extension permits gcc to output the HI and LO relocs
725 itself.
726
727 This cannot be done for PC-relative relocations because both the HI16
728 and LO16 parts of the relocations must be done relative to the LO16
729 part, and there can be carry to or borrow from the HI16 part. */
730
731 struct mips_hi16
732 {
733 struct mips_hi16 *next;
734 bfd_byte *addr;
735 bfd_vma addend;
736 };
737
738 /* FIXME: This should not be a static variable. */
739
740 static struct mips_hi16 *mips_hi16_list;
741
742 static bfd_reloc_status_type
743 mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data, input_section,
744 output_bfd, error_message)
745 bfd *abfd ATTRIBUTE_UNUSED;
746 arelent *reloc_entry;
747 asymbol *symbol;
748 PTR data;
749 asection *input_section;
750 bfd *output_bfd;
751 char **error_message;
752 {
753 bfd_reloc_status_type ret;
754 bfd_vma relocation;
755 struct mips_hi16 *n;
756
757 /* If we're relocating, and this is an external symbol, we don't want
758 to change anything. */
759 if (output_bfd != (bfd *) NULL
760 && (symbol->flags & BSF_SECTION_SYM) == 0
761 && reloc_entry->addend == 0)
762 {
763 reloc_entry->address += input_section->output_offset;
764 return bfd_reloc_ok;
765 }
766
767 ret = bfd_reloc_ok;
768
769 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
770 {
771 boolean relocateable;
772 bfd_vma gp;
773
774 if (ret == bfd_reloc_undefined)
775 abort ();
776
777 if (output_bfd != NULL)
778 relocateable = true;
779 else
780 {
781 relocateable = false;
782 output_bfd = symbol->section->output_section->owner;
783 }
784
785 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
786 error_message, &gp);
787 if (ret != bfd_reloc_ok)
788 return ret;
789
790 relocation = gp - reloc_entry->address;
791 }
792 else
793 {
794 if (bfd_is_und_section (symbol->section)
795 && output_bfd == (bfd *) NULL)
796 ret = bfd_reloc_undefined;
797
798 if (bfd_is_com_section (symbol->section))
799 relocation = 0;
800 else
801 relocation = symbol->value;
802 }
803
804 relocation += symbol->section->output_section->vma;
805 relocation += symbol->section->output_offset;
806 relocation += reloc_entry->addend;
807
808 if (reloc_entry->address > input_section->_cooked_size)
809 return bfd_reloc_outofrange;
810
811 /* Save the information, and let LO16 do the actual relocation. */
812 n = (struct mips_hi16 *) bfd_malloc ((bfd_size_type) sizeof *n);
813 if (n == NULL)
814 return bfd_reloc_outofrange;
815 n->addr = (bfd_byte *) data + reloc_entry->address;
816 n->addend = relocation;
817 n->next = mips_hi16_list;
818 mips_hi16_list = n;
819
820 if (output_bfd != (bfd *) NULL)
821 reloc_entry->address += input_section->output_offset;
822
823 return ret;
824 }
825
826 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
827 inplace relocation; this function exists in order to do the
828 R_MIPS_HI16 relocation described above. */
829
830 static bfd_reloc_status_type
831 mips_elf_lo16_reloc (abfd, reloc_entry, symbol, data, input_section,
832 output_bfd, error_message)
833 bfd *abfd;
834 arelent *reloc_entry;
835 asymbol *symbol;
836 PTR data;
837 asection *input_section;
838 bfd *output_bfd;
839 char **error_message;
840 {
841 arelent gp_disp_relent;
842
843 if (mips_hi16_list != NULL)
844 {
845 struct mips_hi16 *l;
846
847 l = mips_hi16_list;
848 while (l != NULL)
849 {
850 unsigned long insn;
851 unsigned long val;
852 unsigned long vallo;
853 struct mips_hi16 *next;
854
855 /* Do the HI16 relocation. Note that we actually don't need
856 to know anything about the LO16 itself, except where to
857 find the low 16 bits of the addend needed by the LO16. */
858 insn = bfd_get_32 (abfd, l->addr);
859 vallo = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
860
861 /* The low order 16 bits are always treated as a signed
862 value. */
863 vallo = ((vallo & 0xffff) ^ 0x8000) - 0x8000;
864 val = ((insn & 0xffff) << 16) + vallo;
865 val += l->addend;
866
867 /* If PC-relative, we need to subtract out the address of the LO
868 half of the HI/LO. (The actual relocation is relative
869 to that instruction.) */
870 if (reloc_entry->howto->pc_relative)
871 val -= reloc_entry->address;
872
873 /* At this point, "val" has the value of the combined HI/LO
874 pair. If the low order 16 bits (which will be used for
875 the LO16 insn) are negative, then we will need an
876 adjustment for the high order 16 bits. */
877 val += 0x8000;
878 val = (val >> 16) & 0xffff;
879
880 insn &= ~ (bfd_vma) 0xffff;
881 insn |= val;
882 bfd_put_32 (abfd, (bfd_vma) insn, l->addr);
883
884 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
885 {
886 gp_disp_relent = *reloc_entry;
887 reloc_entry = &gp_disp_relent;
888 reloc_entry->addend = l->addend;
889 }
890
891 next = l->next;
892 free (l);
893 l = next;
894 }
895
896 mips_hi16_list = NULL;
897 }
898 else if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
899 {
900 bfd_reloc_status_type ret;
901 bfd_vma gp, relocation;
902
903 /* FIXME: Does this case ever occur? */
904
905 ret = mips_elf_final_gp (output_bfd, symbol, true, error_message, &gp);
906 if (ret != bfd_reloc_ok)
907 return ret;
908
909 relocation = gp - reloc_entry->address;
910 relocation += symbol->section->output_section->vma;
911 relocation += symbol->section->output_offset;
912 relocation += reloc_entry->addend;
913
914 if (reloc_entry->address > input_section->_cooked_size)
915 return bfd_reloc_outofrange;
916
917 gp_disp_relent = *reloc_entry;
918 reloc_entry = &gp_disp_relent;
919 reloc_entry->addend = relocation - 4;
920 }
921
922 /* Now do the LO16 reloc in the usual way. */
923 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
924 input_section, output_bfd, error_message);
925 }
926
927 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
928 table used for PIC code. If the symbol is an external symbol, the
929 instruction is modified to contain the offset of the appropriate
930 entry in the global offset table. If the symbol is a section
931 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
932 addends are combined to form the real addend against the section
933 symbol; the GOT16 is modified to contain the offset of an entry in
934 the global offset table, and the LO16 is modified to offset it
935 appropriately. Thus an offset larger than 16 bits requires a
936 modified value in the global offset table.
937
938 This implementation suffices for the assembler, but the linker does
939 not yet know how to create global offset tables. */
940
941 static bfd_reloc_status_type
942 mips_elf_got16_reloc (abfd, reloc_entry, symbol, data, input_section,
943 output_bfd, error_message)
944 bfd *abfd;
945 arelent *reloc_entry;
946 asymbol *symbol;
947 PTR data;
948 asection *input_section;
949 bfd *output_bfd;
950 char **error_message;
951 {
952 /* If we're relocating, and this is an external symbol, we don't want
953 to change anything. */
954 if (output_bfd != (bfd *) NULL
955 && (symbol->flags & BSF_SECTION_SYM) == 0
956 && reloc_entry->addend == 0)
957 {
958 reloc_entry->address += input_section->output_offset;
959 return bfd_reloc_ok;
960 }
961
962 /* If we're relocating, and this is a local symbol, we can handle it
963 just like HI16. */
964 if (output_bfd != (bfd *) NULL
965 && (symbol->flags & BSF_SECTION_SYM) != 0)
966 return mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
967 input_section, output_bfd, error_message);
968
969 abort ();
970 }
971
972 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
973 dangerous relocation. */
974
975 static boolean
976 mips_elf_assign_gp (output_bfd, pgp)
977 bfd *output_bfd;
978 bfd_vma *pgp;
979 {
980 unsigned int count;
981 asymbol **sym;
982 unsigned int i;
983
984 /* If we've already figured out what GP will be, just return it. */
985 *pgp = _bfd_get_gp_value (output_bfd);
986 if (*pgp)
987 return true;
988
989 count = bfd_get_symcount (output_bfd);
990 sym = bfd_get_outsymbols (output_bfd);
991
992 /* The linker script will have created a symbol named `_gp' with the
993 appropriate value. */
994 if (sym == (asymbol **) NULL)
995 i = count;
996 else
997 {
998 for (i = 0; i < count; i++, sym++)
999 {
1000 register const char *name;
1001
1002 name = bfd_asymbol_name (*sym);
1003 if (*name == '_' && strcmp (name, "_gp") == 0)
1004 {
1005 *pgp = bfd_asymbol_value (*sym);
1006 _bfd_set_gp_value (output_bfd, *pgp);
1007 break;
1008 }
1009 }
1010 }
1011
1012 if (i >= count)
1013 {
1014 /* Only get the error once. */
1015 *pgp = 4;
1016 _bfd_set_gp_value (output_bfd, *pgp);
1017 return false;
1018 }
1019
1020 return true;
1021 }
1022
1023 /* We have to figure out the gp value, so that we can adjust the
1024 symbol value correctly. We look up the symbol _gp in the output
1025 BFD. If we can't find it, we're stuck. We cache it in the ELF
1026 target data. We don't need to adjust the symbol value for an
1027 external symbol if we are producing relocateable output. */
1028
1029 static bfd_reloc_status_type
1030 mips_elf_final_gp (output_bfd, symbol, relocateable, error_message, pgp)
1031 bfd *output_bfd;
1032 asymbol *symbol;
1033 boolean relocateable;
1034 char **error_message;
1035 bfd_vma *pgp;
1036 {
1037 if (bfd_is_und_section (symbol->section)
1038 && ! relocateable)
1039 {
1040 *pgp = 0;
1041 return bfd_reloc_undefined;
1042 }
1043
1044 *pgp = _bfd_get_gp_value (output_bfd);
1045 if (*pgp == 0
1046 && (! relocateable
1047 || (symbol->flags & BSF_SECTION_SYM) != 0))
1048 {
1049 if (relocateable)
1050 {
1051 /* Make up a value. */
1052 *pgp = symbol->section->output_section->vma + 0x4000;
1053 _bfd_set_gp_value (output_bfd, *pgp);
1054 }
1055 else if (!mips_elf_assign_gp (output_bfd, pgp))
1056 {
1057 *error_message =
1058 (char *) _("GP relative relocation when _gp not defined");
1059 return bfd_reloc_dangerous;
1060 }
1061 }
1062
1063 return bfd_reloc_ok;
1064 }
1065
1066 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1067 become the offset from the gp register. This function also handles
1068 R_MIPS_LITERAL relocations, although those can be handled more
1069 cleverly because the entries in the .lit8 and .lit4 sections can be
1070 merged. */
1071
1072 bfd_reloc_status_type
1073 _bfd_mips_elf32_gprel16_reloc (abfd, reloc_entry, symbol, data, input_section,
1074 output_bfd, error_message)
1075 bfd *abfd;
1076 arelent *reloc_entry;
1077 asymbol *symbol;
1078 PTR data;
1079 asection *input_section;
1080 bfd *output_bfd;
1081 char **error_message;
1082 {
1083 boolean relocateable;
1084 bfd_reloc_status_type ret;
1085 bfd_vma gp;
1086
1087 /* If we're relocating, and this is an external symbol with no
1088 addend, we don't want to change anything. We will only have an
1089 addend if this is a newly created reloc, not read from an ELF
1090 file. */
1091 if (output_bfd != (bfd *) NULL
1092 && (symbol->flags & BSF_SECTION_SYM) == 0
1093 && reloc_entry->addend == 0)
1094 {
1095 reloc_entry->address += input_section->output_offset;
1096 return bfd_reloc_ok;
1097 }
1098
1099 if (output_bfd != (bfd *) NULL)
1100 relocateable = true;
1101 else
1102 {
1103 relocateable = false;
1104 output_bfd = symbol->section->output_section->owner;
1105 }
1106
1107 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1108 &gp);
1109 if (ret != bfd_reloc_ok)
1110 return ret;
1111
1112 return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1113 input_section, relocateable,
1114 data, gp);
1115 }
1116
1117 /* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must
1118 become the offset from the gp register. */
1119
1120 static bfd_reloc_status_type gprel32_with_gp PARAMS ((bfd *, asymbol *,
1121 arelent *, asection *,
1122 boolean, PTR, bfd_vma));
1123
1124 static bfd_reloc_status_type
1125 mips_elf_gprel32_reloc (abfd, reloc_entry, symbol, data, input_section,
1126 output_bfd, error_message)
1127 bfd *abfd;
1128 arelent *reloc_entry;
1129 asymbol *symbol;
1130 PTR data;
1131 asection *input_section;
1132 bfd *output_bfd;
1133 char **error_message;
1134 {
1135 boolean relocateable;
1136 bfd_reloc_status_type ret;
1137 bfd_vma gp;
1138
1139 /* If we're relocating, and this is an external symbol with no
1140 addend, we don't want to change anything. We will only have an
1141 addend if this is a newly created reloc, not read from an ELF
1142 file. */
1143 if (output_bfd != (bfd *) NULL
1144 && (symbol->flags & BSF_SECTION_SYM) == 0
1145 && reloc_entry->addend == 0)
1146 {
1147 *error_message = (char *)
1148 _("32bits gp relative relocation occurs for an external symbol");
1149 return bfd_reloc_outofrange;
1150 }
1151
1152 if (output_bfd != (bfd *) NULL)
1153 {
1154 relocateable = true;
1155 gp = _bfd_get_gp_value (output_bfd);
1156 }
1157 else
1158 {
1159 relocateable = false;
1160 output_bfd = symbol->section->output_section->owner;
1161
1162 ret = mips_elf_final_gp (output_bfd, symbol, relocateable,
1163 error_message, &gp);
1164 if (ret != bfd_reloc_ok)
1165 return ret;
1166 }
1167
1168 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1169 relocateable, data, gp);
1170 }
1171
1172 static bfd_reloc_status_type
1173 gprel32_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data,
1174 gp)
1175 bfd *abfd;
1176 asymbol *symbol;
1177 arelent *reloc_entry;
1178 asection *input_section;
1179 boolean relocateable;
1180 PTR data;
1181 bfd_vma gp;
1182 {
1183 bfd_vma relocation;
1184 unsigned long val;
1185
1186 if (bfd_is_com_section (symbol->section))
1187 relocation = 0;
1188 else
1189 relocation = symbol->value;
1190
1191 relocation += symbol->section->output_section->vma;
1192 relocation += symbol->section->output_offset;
1193
1194 if (reloc_entry->address > input_section->_cooked_size)
1195 return bfd_reloc_outofrange;
1196
1197 if (reloc_entry->howto->src_mask == 0)
1198 {
1199 /* This case arises with the 64-bit MIPS ELF ABI. */
1200 val = 0;
1201 }
1202 else
1203 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1204
1205 /* Set val to the offset into the section or symbol. */
1206 val += reloc_entry->addend;
1207
1208 /* Adjust val for the final section location and GP value. If we
1209 are producing relocateable output, we don't want to do this for
1210 an external symbol. */
1211 if (! relocateable
1212 || (symbol->flags & BSF_SECTION_SYM) != 0)
1213 val += relocation - gp;
1214
1215 bfd_put_32 (abfd, (bfd_vma) val, (bfd_byte *) data + reloc_entry->address);
1216
1217 if (relocateable)
1218 reloc_entry->address += input_section->output_offset;
1219
1220 return bfd_reloc_ok;
1221 }
1222
1223 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1224 generated when addresses are 64 bits. The upper 32 bits are a simple
1225 sign extension. */
1226
1227 static bfd_reloc_status_type
1228 mips32_64bit_reloc (abfd, reloc_entry, symbol, data, input_section,
1229 output_bfd, error_message)
1230 bfd *abfd;
1231 arelent *reloc_entry;
1232 asymbol *symbol;
1233 PTR data;
1234 asection *input_section;
1235 bfd *output_bfd;
1236 char **error_message;
1237 {
1238 bfd_reloc_status_type r;
1239 arelent reloc32;
1240 unsigned long val;
1241 bfd_size_type addr;
1242
1243 r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1244 input_section, output_bfd, error_message);
1245 if (r != bfd_reloc_continue)
1246 return r;
1247
1248 /* Do a normal 32 bit relocation on the lower 32 bits. */
1249 reloc32 = *reloc_entry;
1250 if (bfd_big_endian (abfd))
1251 reloc32.address += 4;
1252 reloc32.howto = &elf_mips_howto_table_rel[R_MIPS_32];
1253 r = bfd_perform_relocation (abfd, &reloc32, data, input_section,
1254 output_bfd, error_message);
1255
1256 /* Sign extend into the upper 32 bits. */
1257 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc32.address);
1258 if ((val & 0x80000000) != 0)
1259 val = 0xffffffff;
1260 else
1261 val = 0;
1262 addr = reloc_entry->address;
1263 if (bfd_little_endian (abfd))
1264 addr += 4;
1265 bfd_put_32 (abfd, (bfd_vma) val, (bfd_byte *) data + addr);
1266
1267 return r;
1268 }
1269
1270 /* Handle a mips16 jump. */
1271
1272 static bfd_reloc_status_type
1273 mips16_jump_reloc (abfd, reloc_entry, symbol, data, input_section,
1274 output_bfd, error_message)
1275 bfd *abfd ATTRIBUTE_UNUSED;
1276 arelent *reloc_entry;
1277 asymbol *symbol;
1278 PTR data ATTRIBUTE_UNUSED;
1279 asection *input_section;
1280 bfd *output_bfd;
1281 char **error_message ATTRIBUTE_UNUSED;
1282 {
1283 if (output_bfd != (bfd *) NULL
1284 && (symbol->flags & BSF_SECTION_SYM) == 0
1285 && reloc_entry->addend == 0)
1286 {
1287 reloc_entry->address += input_section->output_offset;
1288 return bfd_reloc_ok;
1289 }
1290
1291 /* FIXME. */
1292 {
1293 static boolean warned;
1294
1295 if (! warned)
1296 (*_bfd_error_handler)
1297 (_("Linking mips16 objects into %s format is not supported"),
1298 bfd_get_target (input_section->output_section->owner));
1299 warned = true;
1300 }
1301
1302 return bfd_reloc_undefined;
1303 }
1304
1305 /* Handle a mips16 GP relative reloc. */
1306
1307 static bfd_reloc_status_type
1308 mips16_gprel_reloc (abfd, reloc_entry, symbol, data, input_section,
1309 output_bfd, error_message)
1310 bfd *abfd;
1311 arelent *reloc_entry;
1312 asymbol *symbol;
1313 PTR data;
1314 asection *input_section;
1315 bfd *output_bfd;
1316 char **error_message;
1317 {
1318 boolean relocateable;
1319 bfd_reloc_status_type ret;
1320 bfd_vma gp;
1321 unsigned short extend, insn;
1322 unsigned long final;
1323
1324 /* If we're relocating, and this is an external symbol with no
1325 addend, we don't want to change anything. We will only have an
1326 addend if this is a newly created reloc, not read from an ELF
1327 file. */
1328 if (output_bfd != NULL
1329 && (symbol->flags & BSF_SECTION_SYM) == 0
1330 && reloc_entry->addend == 0)
1331 {
1332 reloc_entry->address += input_section->output_offset;
1333 return bfd_reloc_ok;
1334 }
1335
1336 if (output_bfd != NULL)
1337 relocateable = true;
1338 else
1339 {
1340 relocateable = false;
1341 output_bfd = symbol->section->output_section->owner;
1342 }
1343
1344 ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message,
1345 &gp);
1346 if (ret != bfd_reloc_ok)
1347 return ret;
1348
1349 if (reloc_entry->address > input_section->_cooked_size)
1350 return bfd_reloc_outofrange;
1351
1352 /* Pick up the mips16 extend instruction and the real instruction. */
1353 extend = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);
1354 insn = bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address + 2);
1355
1356 /* Stuff the current addend back as a 32 bit value, do the usual
1357 relocation, and then clean up. */
1358 bfd_put_32 (abfd,
1359 (bfd_vma) (((extend & 0x1f) << 11)
1360 | (extend & 0x7e0)
1361 | (insn & 0x1f)),
1362 (bfd_byte *) data + reloc_entry->address);
1363
1364 ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1365 input_section, relocateable, data, gp);
1366
1367 final = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1368 bfd_put_16 (abfd,
1369 (bfd_vma) ((extend & 0xf800)
1370 | ((final >> 11) & 0x1f)
1371 | (final & 0x7e0)),
1372 (bfd_byte *) data + reloc_entry->address);
1373 bfd_put_16 (abfd,
1374 (bfd_vma) ((insn & 0xffe0)
1375 | (final & 0x1f)),
1376 (bfd_byte *) data + reloc_entry->address + 2);
1377
1378 return ret;
1379 }
1380
1381 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1382
1383 struct elf_reloc_map {
1384 bfd_reloc_code_real_type bfd_val;
1385 enum elf_mips_reloc_type elf_val;
1386 };
1387
1388 static const struct elf_reloc_map mips_reloc_map[] =
1389 {
1390 { BFD_RELOC_NONE, R_MIPS_NONE },
1391 { BFD_RELOC_16, R_MIPS_16 },
1392 { BFD_RELOC_32, R_MIPS_32 },
1393 /* There is no BFD reloc for R_MIPS_REL32. */
1394 { BFD_RELOC_64, R_MIPS_64 },
1395 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1396 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1397 { BFD_RELOC_LO16, R_MIPS_LO16 },
1398 { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
1399 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1400 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1401 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
1402 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1403 { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
1404 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1405 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1406 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1407 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
1408 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
1409 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
1410 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
1411 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP }
1412 };
1413
1414 /* Given a BFD reloc type, return a howto structure. */
1415
1416 static reloc_howto_type *
1417 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
1418 bfd *abfd;
1419 bfd_reloc_code_real_type code;
1420 {
1421 unsigned int i;
1422 reloc_howto_type *howto_table = elf_mips_howto_table_rel;
1423
1424 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
1425 i++)
1426 {
1427 if (mips_reloc_map[i].bfd_val == code)
1428 return &howto_table[(int) mips_reloc_map[i].elf_val];
1429 }
1430
1431 switch (code)
1432 {
1433 default:
1434 bfd_set_error (bfd_error_bad_value);
1435 return NULL;
1436
1437 case BFD_RELOC_CTOR:
1438 /* We need to handle BFD_RELOC_CTOR specially.
1439 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1440 size of addresses on this architecture. */
1441 if (bfd_arch_bits_per_address (abfd) == 32)
1442 return &howto_table[(int) R_MIPS_32];
1443 else
1444 return &elf_mips_ctor64_howto;
1445
1446 case BFD_RELOC_MIPS16_JMP:
1447 return &elf_mips16_jump_howto;
1448 case BFD_RELOC_MIPS16_GPREL:
1449 return &elf_mips16_gprel_howto;
1450 case BFD_RELOC_VTABLE_INHERIT:
1451 return &elf_mips_gnu_vtinherit_howto;
1452 case BFD_RELOC_VTABLE_ENTRY:
1453 return &elf_mips_gnu_vtentry_howto;
1454 case BFD_RELOC_PCREL_HI16_S:
1455 return &elf_mips_gnu_rel_hi16;
1456 case BFD_RELOC_PCREL_LO16:
1457 return &elf_mips_gnu_rel_lo16;
1458 case BFD_RELOC_16_PCREL_S2:
1459 return &elf_mips_gnu_rel16_s2;
1460 case BFD_RELOC_64_PCREL:
1461 return &elf_mips_gnu_pcrel64;
1462 case BFD_RELOC_32_PCREL:
1463 return &elf_mips_gnu_pcrel32;
1464 }
1465 }
1466
1467 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
1468
1469 static reloc_howto_type *
1470 mips_elf32_rtype_to_howto (r_type, rela_p)
1471 unsigned int r_type;
1472 boolean rela_p ATTRIBUTE_UNUSED;
1473 {
1474 switch (r_type)
1475 {
1476 case R_MIPS16_26:
1477 return &elf_mips16_jump_howto;
1478 case R_MIPS16_GPREL:
1479 return &elf_mips16_gprel_howto;
1480 case R_MIPS_GNU_VTINHERIT:
1481 return &elf_mips_gnu_vtinherit_howto;
1482 case R_MIPS_GNU_VTENTRY:
1483 return &elf_mips_gnu_vtentry_howto;
1484 case R_MIPS_GNU_REL_HI16:
1485 return &elf_mips_gnu_rel_hi16;
1486 case R_MIPS_GNU_REL_LO16:
1487 return &elf_mips_gnu_rel_lo16;
1488 case R_MIPS_GNU_REL16_S2:
1489 return &elf_mips_gnu_rel16_s2;
1490 case R_MIPS_PC64:
1491 return &elf_mips_gnu_pcrel64;
1492 case R_MIPS_PC32:
1493 return &elf_mips_gnu_pcrel32;
1494 default:
1495 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
1496 return &elf_mips_howto_table_rel[r_type];
1497 }
1498 }
1499
1500 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
1501
1502 static void
1503 mips_info_to_howto_rel (abfd, cache_ptr, dst)
1504 bfd *abfd;
1505 arelent *cache_ptr;
1506 Elf_Internal_Rela *dst;
1507 {
1508 unsigned int r_type;
1509
1510 r_type = ELF32_R_TYPE (dst->r_info);
1511 cache_ptr->howto = mips_elf32_rtype_to_howto (r_type, false);
1512
1513 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1514 value for the object file. We get the addend now, rather than
1515 when we do the relocation, because the symbol manipulations done
1516 by the linker may cause us to lose track of the input BFD. */
1517 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
1518 && (r_type == (unsigned int) R_MIPS_GPREL16
1519 || r_type == (unsigned int) R_MIPS_LITERAL))
1520 cache_ptr->addend = elf_gp (abfd);
1521 }
1522
1523 /* Given a MIPS Elf_Internal_Rela, fill in an arelent structure. */
1524
1525 static void
1526 mips_info_to_howto_rela (abfd, cache_ptr, dst)
1527 bfd *abfd;
1528 arelent *cache_ptr;
1529 Elf_Internal_Rela *dst;
1530 {
1531 mips_info_to_howto_rel (abfd, cache_ptr, dst);
1532
1533 /* If we ever need to do any extra processing with dst->r_addend
1534 (the field omitted in an Elf_Internal_Rel) we can do it here. */
1535 }
1536 \f
1537 /* Determine whether a symbol is global for the purposes of splitting
1538 the symbol table into global symbols and local symbols. At least
1539 on Irix 5, this split must be between section symbols and all other
1540 symbols. On most ELF targets the split is between static symbols
1541 and externally visible symbols. */
1542
1543 static boolean
1544 mips_elf_sym_is_global (abfd, sym)
1545 bfd *abfd ATTRIBUTE_UNUSED;
1546 asymbol *sym;
1547 {
1548 if (SGI_COMPAT (abfd))
1549 return (sym->flags & BSF_SECTION_SYM) == 0;
1550 else
1551 return ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
1552 || bfd_is_und_section (bfd_get_section (sym))
1553 || bfd_is_com_section (bfd_get_section (sym)));
1554 }
1555 \f
1556 /* Set the right machine number for a MIPS ELF file. */
1557
1558 static boolean
1559 mips_elf32_object_p (abfd)
1560 bfd *abfd;
1561 {
1562 unsigned long mach;
1563
1564 /* Irix 5 and 6 are broken. Object file symbol tables are not always
1565 sorted correctly such that local symbols precede global symbols,
1566 and the sh_info field in the symbol table is not always right. */
1567 if (SGI_COMPAT (abfd))
1568 elf_bad_symtab (abfd) = true;
1569
1570 if (ABI_N32_P (abfd))
1571 return false;
1572
1573 mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
1574 bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
1575
1576 return true;
1577 }
1578 \f
1579 /* MIPS ELF local labels start with '$', not 'L'. */
1580
1581 static boolean
1582 mips_elf_is_local_label_name (abfd, name)
1583 bfd *abfd;
1584 const char *name;
1585 {
1586 if (name[0] == '$')
1587 return true;
1588
1589 /* On Irix 6, the labels go back to starting with '.', so we accept
1590 the generic ELF local label syntax as well. */
1591 return _bfd_elf_is_local_label_name (abfd, name);
1592 }
1593 \f
1594 /* Support for core dump NOTE sections. */
1595 static boolean
1596 elf32_mips_grok_prstatus (abfd, note)
1597 bfd *abfd;
1598 Elf_Internal_Note *note;
1599 {
1600 int offset;
1601 unsigned int raw_size;
1602
1603 switch (note->descsz)
1604 {
1605 default:
1606 return false;
1607
1608 case 256: /* Linux/MIPS */
1609 /* pr_cursig */
1610 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1611
1612 /* pr_pid */
1613 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1614
1615 /* pr_reg */
1616 offset = 72;
1617 raw_size = 180;
1618
1619 break;
1620 }
1621
1622 /* Make a ".reg/999" section. */
1623 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1624 raw_size, note->descpos + offset);
1625 }
1626
1627 static boolean
1628 elf32_mips_grok_psinfo (abfd, note)
1629 bfd *abfd;
1630 Elf_Internal_Note *note;
1631 {
1632 switch (note->descsz)
1633 {
1634 default:
1635 return false;
1636
1637 case 128: /* Linux/MIPS elf_prpsinfo */
1638 elf_tdata (abfd)->core_program
1639 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
1640 elf_tdata (abfd)->core_command
1641 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
1642 }
1643
1644 /* Note that for some reason, a spurious space is tacked
1645 onto the end of the args in some (at least one anyway)
1646 implementations, so strip it off if it exists. */
1647
1648 {
1649 char *command = elf_tdata (abfd)->core_command;
1650 int n = strlen (command);
1651
1652 if (0 < n && command[n - 1] == ' ')
1653 command[n - 1] = '\0';
1654 }
1655
1656 return true;
1657 }
1658 \f
1659 /* Depending on the target vector we generate some version of Irix
1660 executables or "normal" MIPS ELF ABI executables. */
1661 static irix_compat_t
1662 elf32_mips_irix_compat (abfd)
1663 bfd *abfd;
1664 {
1665 if ((abfd->xvec == &bfd_elf32_bigmips_vec)
1666 || (abfd->xvec == &bfd_elf32_littlemips_vec))
1667 return ict_irix5;
1668 else
1669 return ict_none;
1670 }
1671 \f
1672 /* Given a data section and an in-memory embedded reloc section, store
1673 relocation information into the embedded reloc section which can be
1674 used at runtime to relocate the data section. This is called by the
1675 linker when the --embedded-relocs switch is used. This is called
1676 after the add_symbols entry point has been called for all the
1677 objects, and before the final_link entry point is called. */
1678
1679 boolean
1680 bfd_mips_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
1681 bfd *abfd;
1682 struct bfd_link_info *info;
1683 asection *datasec;
1684 asection *relsec;
1685 char **errmsg;
1686 {
1687 Elf_Internal_Shdr *symtab_hdr;
1688 Elf_Internal_Sym *isymbuf = NULL;
1689 Elf_Internal_Rela *internal_relocs = NULL;
1690 Elf_Internal_Rela *irel, *irelend;
1691 bfd_byte *p;
1692
1693 BFD_ASSERT (! info->relocateable);
1694
1695 *errmsg = NULL;
1696
1697 if (datasec->reloc_count == 0)
1698 return true;
1699
1700 /* Read this BFD's symbols if we haven't done so already, or get the cached
1701 copy if it exists. */
1702 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1703 if (symtab_hdr->sh_info != 0)
1704 {
1705 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1706 if (isymbuf == NULL)
1707 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
1708 symtab_hdr->sh_info, 0,
1709 NULL, NULL, NULL);
1710 if (isymbuf == NULL)
1711 goto error_return;
1712 }
1713
1714 /* Get a copy of the native relocations. */
1715 internal_relocs = (_bfd_elf32_link_read_relocs
1716 (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
1717 info->keep_memory));
1718 if (internal_relocs == NULL)
1719 goto error_return;
1720
1721 relsec->contents = (bfd_byte *) bfd_alloc (abfd, datasec->reloc_count * 12);
1722 if (relsec->contents == NULL)
1723 goto error_return;
1724
1725 p = relsec->contents;
1726
1727 irelend = internal_relocs + datasec->reloc_count;
1728
1729 for (irel = internal_relocs; irel < irelend; irel++, p += 12)
1730 {
1731 asection *targetsec;
1732
1733 /* We are going to write a four byte longword into the runtime
1734 reloc section. The longword will be the address in the data
1735 section which must be relocated. It is followed by the name
1736 of the target section NUL-padded or truncated to 8
1737 characters. */
1738
1739 /* We can only relocate absolute longword relocs at run time. */
1740 if ((ELF32_R_TYPE (irel->r_info) != (int) R_MIPS_32) &&
1741 (ELF32_R_TYPE (irel->r_info) != (int) R_MIPS_64))
1742 {
1743 *errmsg = _("unsupported reloc type");
1744 bfd_set_error (bfd_error_bad_value);
1745 goto error_return;
1746 }
1747 /* Get the target section referred to by the reloc. */
1748 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
1749 {
1750 Elf_Internal_Sym *isym;
1751
1752 /* A local symbol. */
1753 isym = isymbuf + ELF32_R_SYM (irel->r_info);
1754 targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
1755 }
1756 else
1757 {
1758 unsigned long indx;
1759 struct elf_link_hash_entry *h;
1760
1761 /* An external symbol. */
1762 indx = ELF32_R_SYM (irel->r_info);
1763 h = elf_sym_hashes (abfd)[indx];
1764 targetsec = NULL;
1765 /*
1766 For some reason, in certain programs, the symbol will
1767 not be in the hash table. It seems to happen when you
1768 declare a static table of pointers to const external structures.
1769 In this case, the relocs are relative to data, not
1770 text, so just treating it like an undefined link
1771 should be sufficient. */
1772 BFD_ASSERT(h != NULL);
1773 if (h->root.type == bfd_link_hash_defined
1774 || h->root.type == bfd_link_hash_defweak)
1775 targetsec = h->root.u.def.section;
1776 }
1777
1778
1779 /*
1780 Set the low bit of the relocation offset if it's a MIPS64 reloc.
1781 Relocations will always be on (at least) 32-bit boundaries. */
1782
1783 bfd_put_32 (abfd, ((irel->r_offset + datasec->output_offset) +
1784 ((ELF32_R_TYPE (irel->r_info) == (int) R_MIPS_64) ? 1 : 0)),
1785 p);
1786 memset (p + 4, 0, 8);
1787 if (targetsec != NULL)
1788 strncpy (p + 4, targetsec->output_section->name, 8);
1789 }
1790
1791 if (internal_relocs != NULL
1792 && elf_section_data (datasec)->relocs != internal_relocs)
1793 free (internal_relocs);
1794 if (isymbuf != NULL
1795 && symtab_hdr->contents != (unsigned char *) isymbuf)
1796 free (isymbuf);
1797 return true;
1798
1799 error_return:
1800 if (internal_relocs != NULL
1801 && elf_section_data (datasec)->relocs != internal_relocs)
1802 free (internal_relocs);
1803 if (isymbuf != NULL
1804 && symtab_hdr->contents != (unsigned char *) isymbuf)
1805 free (isymbuf);
1806 return false;
1807 }
1808 \f
1809 /* ECOFF swapping routines. These are used when dealing with the
1810 .mdebug section, which is in the ECOFF debugging format. */
1811 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
1812 /* Symbol table magic number. */
1813 magicSym,
1814 /* Alignment of debugging information. E.g., 4. */
1815 4,
1816 /* Sizes of external symbolic information. */
1817 sizeof (struct hdr_ext),
1818 sizeof (struct dnr_ext),
1819 sizeof (struct pdr_ext),
1820 sizeof (struct sym_ext),
1821 sizeof (struct opt_ext),
1822 sizeof (struct fdr_ext),
1823 sizeof (struct rfd_ext),
1824 sizeof (struct ext_ext),
1825 /* Functions to swap in external symbolic data. */
1826 ecoff_swap_hdr_in,
1827 ecoff_swap_dnr_in,
1828 ecoff_swap_pdr_in,
1829 ecoff_swap_sym_in,
1830 ecoff_swap_opt_in,
1831 ecoff_swap_fdr_in,
1832 ecoff_swap_rfd_in,
1833 ecoff_swap_ext_in,
1834 _bfd_ecoff_swap_tir_in,
1835 _bfd_ecoff_swap_rndx_in,
1836 /* Functions to swap out external symbolic data. */
1837 ecoff_swap_hdr_out,
1838 ecoff_swap_dnr_out,
1839 ecoff_swap_pdr_out,
1840 ecoff_swap_sym_out,
1841 ecoff_swap_opt_out,
1842 ecoff_swap_fdr_out,
1843 ecoff_swap_rfd_out,
1844 ecoff_swap_ext_out,
1845 _bfd_ecoff_swap_tir_out,
1846 _bfd_ecoff_swap_rndx_out,
1847 /* Function to read in symbolic data. */
1848 _bfd_mips_elf_read_ecoff_info
1849 };
1850 \f
1851 #define ELF_ARCH bfd_arch_mips
1852 #define ELF_MACHINE_CODE EM_MIPS
1853
1854 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
1855 a value of 0x1000, and we are compatible. */
1856 #define ELF_MAXPAGESIZE 0x1000
1857
1858 #define elf_backend_collect true
1859 #define elf_backend_type_change_ok true
1860 #define elf_backend_can_gc_sections true
1861 #define elf_info_to_howto mips_info_to_howto_rela
1862 #define elf_info_to_howto_rel mips_info_to_howto_rel
1863 #define elf_backend_sym_is_global mips_elf_sym_is_global
1864 #define elf_backend_object_p mips_elf32_object_p
1865 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
1866 #define elf_backend_section_processing _bfd_mips_elf_section_processing
1867 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
1868 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
1869 #define elf_backend_section_from_bfd_section \
1870 _bfd_mips_elf_section_from_bfd_section
1871 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
1872 #define elf_backend_link_output_symbol_hook \
1873 _bfd_mips_elf_link_output_symbol_hook
1874 #define elf_backend_create_dynamic_sections \
1875 _bfd_mips_elf_create_dynamic_sections
1876 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
1877 #define elf_backend_adjust_dynamic_symbol \
1878 _bfd_mips_elf_adjust_dynamic_symbol
1879 #define elf_backend_always_size_sections \
1880 _bfd_mips_elf_always_size_sections
1881 #define elf_backend_size_dynamic_sections \
1882 _bfd_mips_elf_size_dynamic_sections
1883 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
1884 #define elf_backend_finish_dynamic_symbol \
1885 _bfd_mips_elf_finish_dynamic_symbol
1886 #define elf_backend_finish_dynamic_sections \
1887 _bfd_mips_elf_finish_dynamic_sections
1888 #define elf_backend_final_write_processing \
1889 _bfd_mips_elf_final_write_processing
1890 #define elf_backend_additional_program_headers \
1891 _bfd_mips_elf_additional_program_headers
1892 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
1893 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
1894 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
1895 #define elf_backend_copy_indirect_symbol \
1896 _bfd_mips_elf_copy_indirect_symbol
1897 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
1898 #define elf_backend_grok_prstatus elf32_mips_grok_prstatus
1899 #define elf_backend_grok_psinfo elf32_mips_grok_psinfo
1900 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
1901
1902 #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
1903 #define elf_backend_plt_header_size 0
1904 #define elf_backend_may_use_rel_p 1
1905 #define elf_backend_may_use_rela_p 0
1906 #define elf_backend_default_use_rela_p 0
1907 #define elf_backend_sign_extend_vma true
1908
1909 #define elf_backend_discard_info _bfd_mips_elf_discard_info
1910 #define elf_backend_ignore_discarded_relocs \
1911 _bfd_mips_elf_ignore_discarded_relocs
1912 #define elf_backend_mips_irix_compat elf32_mips_irix_compat
1913 #define elf_backend_mips_rtype_to_howto mips_elf32_rtype_to_howto
1914 #define bfd_elf32_bfd_is_local_label_name \
1915 mips_elf_is_local_label_name
1916 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
1917 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
1918 #define bfd_elf32_bfd_get_relocated_section_contents \
1919 _bfd_elf_mips_get_relocated_section_contents
1920 #define bfd_elf32_bfd_link_hash_table_create \
1921 _bfd_mips_elf_link_hash_table_create
1922 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
1923 #define bfd_elf32_bfd_merge_private_bfd_data \
1924 _bfd_mips_elf_merge_private_bfd_data
1925 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
1926 #define bfd_elf32_bfd_print_private_bfd_data \
1927 _bfd_mips_elf_print_private_bfd_data
1928
1929 /* Support for SGI-ish mips targets. */
1930 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
1931 #define TARGET_LITTLE_NAME "elf32-littlemips"
1932 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
1933 #define TARGET_BIG_NAME "elf32-bigmips"
1934
1935 #include "elf32-target.h"
1936
1937 /* Support for traditional mips targets. */
1938 #define INCLUDED_TARGET_FILE /* More a type of flag. */
1939
1940 #undef TARGET_LITTLE_SYM
1941 #undef TARGET_LITTLE_NAME
1942 #undef TARGET_BIG_SYM
1943 #undef TARGET_BIG_NAME
1944
1945 #define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
1946 #define TARGET_LITTLE_NAME "elf32-tradlittlemips"
1947 #define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
1948 #define TARGET_BIG_NAME "elf32-tradbigmips"
1949
1950 /* Include the target file again for this target. */
1951 #include "elf32-target.h"
This page took 0.068219 seconds and 5 git commands to generate.