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