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