]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* MIPS-specific support for 64-bit ELF |
157090f7 AM |
2 | Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, |
3 | 2007 Free Software Foundation, Inc. | |
252b5132 | 4 | Ian Lance Taylor, Cygnus Support |
103186c6 MM |
5 | Linker support added by Mark Mitchell, CodeSourcery, LLC. |
6 | <mark@codesourcery.com> | |
252b5132 RH |
7 | |
8 | This file is part of BFD, the Binary File Descriptor library. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with this program; if not, write to the Free Software | |
3e110533 | 22 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 RH |
23 | |
24 | /* This file supports the 64-bit MIPS ELF ABI. | |
25 | ||
26 | The MIPS 64-bit ELF ABI uses an unusual reloc format. This file | |
27 | overrides the usual ELF reloc handling, and handles reading and | |
36b45482 | 28 | writing the relocations here. */ |
252b5132 | 29 | |
5b6a02bc TS |
30 | /* TODO: Many things are unsupported, even if there is some code for it |
31 | . (which was mostly stolen from elf32-mips.c and slightly adapted). | |
32 | . | |
33 | . - Relocation handling for REL relocs is wrong in many cases and | |
34 | . generally untested. | |
35 | . - Relocation handling for RELA relocs related to GOT support are | |
36 | . also likely to be wrong. | |
a4382ec6 | 37 | . - Support for MIPS16 is untested. |
5b6a02bc TS |
38 | . - Combined relocs with RSS_* entries are unsupported. |
39 | . - The whole GOT handling for NewABI is missing, some parts of | |
c6e90b02 | 40 | . the OldABI version is still lying around and should be removed. |
5b6a02bc TS |
41 | */ |
42 | ||
252b5132 | 43 | #include "sysdep.h" |
3db64b00 | 44 | #include "bfd.h" |
252b5132 RH |
45 | #include "libbfd.h" |
46 | #include "aout/ar.h" | |
47 | #include "bfdlink.h" | |
48 | #include "genlink.h" | |
49 | #include "elf-bfd.h" | |
c6e90b02 | 50 | #include "elfxx-mips.h" |
252b5132 RH |
51 | #include "elf/mips.h" |
52 | ||
53 | /* Get the ECOFF swapping routines. The 64-bit ABI is not supposed to | |
54 | use ECOFF. However, we support it anyhow for an easier changeover. */ | |
55 | #include "coff/sym.h" | |
56 | #include "coff/symconst.h" | |
57 | #include "coff/internal.h" | |
58 | #include "coff/ecoff.h" | |
59 | /* The 64 bit versions of the mdebug data structures are in alpha.h. */ | |
60 | #include "coff/alpha.h" | |
23e2c83b | 61 | #define ECOFF_SIGNED_64 |
252b5132 RH |
62 | #include "ecoffswap.h" |
63 | ||
64 | static void mips_elf64_swap_reloc_in | |
11a2be4d | 65 | (bfd *, const Elf64_Mips_External_Rel *, Elf64_Mips_Internal_Rela *); |
252b5132 | 66 | static void mips_elf64_swap_reloca_in |
11a2be4d | 67 | (bfd *, const Elf64_Mips_External_Rela *, Elf64_Mips_Internal_Rela *); |
252b5132 | 68 | static void mips_elf64_swap_reloc_out |
11a2be4d | 69 | (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rel *); |
252b5132 | 70 | static void mips_elf64_swap_reloca_out |
11a2be4d | 71 | (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rela *); |
c7ac6ff8 | 72 | static void mips_elf64_be_swap_reloc_in |
11a2be4d | 73 | (bfd *, const bfd_byte *, Elf_Internal_Rela *); |
c7ac6ff8 | 74 | static void mips_elf64_be_swap_reloc_out |
11a2be4d | 75 | (bfd *, const Elf_Internal_Rela *, bfd_byte *); |
c7ac6ff8 | 76 | static void mips_elf64_be_swap_reloca_in |
11a2be4d | 77 | (bfd *, const bfd_byte *, Elf_Internal_Rela *); |
c7ac6ff8 | 78 | static void mips_elf64_be_swap_reloca_out |
11a2be4d | 79 | (bfd *, const Elf_Internal_Rela *, bfd_byte *); |
c6e90b02 | 80 | static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup |
11a2be4d | 81 | (bfd *, bfd_reloc_code_real_type); |
c6e90b02 | 82 | static reloc_howto_type *mips_elf64_rtype_to_howto |
11a2be4d | 83 | (unsigned int, bfd_boolean); |
5b6a02bc | 84 | static void mips_elf64_info_to_howto_rel |
11a2be4d | 85 | (bfd *, arelent *, Elf_Internal_Rela *); |
5b6a02bc | 86 | static void mips_elf64_info_to_howto_rela |
11a2be4d | 87 | (bfd *, arelent *, Elf_Internal_Rela *); |
b34976b6 | 88 | static long mips_elf64_get_reloc_upper_bound |
11a2be4d | 89 | (bfd *, asection *); |
fee24f1c | 90 | static long mips_elf64_canonicalize_reloc |
11a2be4d RS |
91 | (bfd *, asection *, arelent **, asymbol **); |
92 | static long mips_elf64_get_dynamic_reloc_upper_bound | |
93 | (bfd *); | |
fee24f1c | 94 | static long mips_elf64_canonicalize_dynamic_reloc |
11a2be4d | 95 | (bfd *, arelent **, asymbol **); |
b34976b6 | 96 | static bfd_boolean mips_elf64_slurp_one_reloc_table |
11a2be4d RS |
97 | (bfd *, asection *, Elf_Internal_Shdr *, bfd_size_type, arelent *, |
98 | asymbol **, bfd_boolean); | |
b34976b6 | 99 | static bfd_boolean mips_elf64_slurp_reloc_table |
11a2be4d | 100 | (bfd *, asection *, asymbol **, bfd_boolean); |
b34976b6 | 101 | static void mips_elf64_write_relocs |
11a2be4d | 102 | (bfd *, asection *, void *); |
5b6a02bc | 103 | static void mips_elf64_write_rel |
11a2be4d | 104 | (bfd *, asection *, Elf_Internal_Shdr *, int *, void *); |
5b6a02bc | 105 | static void mips_elf64_write_rela |
11a2be4d | 106 | (bfd *, asection *, Elf_Internal_Shdr *, int *, void *); |
5b6a02bc | 107 | static bfd_reloc_status_type mips_elf64_gprel16_reloc |
11a2be4d | 108 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
5b6a02bc | 109 | static bfd_reloc_status_type mips_elf64_literal_reloc |
11a2be4d | 110 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
5b6a02bc | 111 | static bfd_reloc_status_type mips_elf64_gprel32_reloc |
11a2be4d | 112 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
5b6a02bc | 113 | static bfd_reloc_status_type mips_elf64_shift6_reloc |
11a2be4d | 114 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
a4382ec6 | 115 | static bfd_reloc_status_type mips16_gprel_reloc |
11a2be4d | 116 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
b34976b6 | 117 | static bfd_boolean mips_elf64_assign_gp |
11a2be4d | 118 | (bfd *, bfd_vma *); |
5b6a02bc | 119 | static bfd_reloc_status_type mips_elf64_final_gp |
11a2be4d | 120 | (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *); |
b34976b6 | 121 | static bfd_boolean mips_elf64_object_p |
11a2be4d | 122 | (bfd *); |
b34976b6 | 123 | static irix_compat_t elf64_mips_irix_compat |
11a2be4d | 124 | (bfd *); |
d0112f73 | 125 | static bfd_boolean elf64_mips_grok_prstatus |
11a2be4d | 126 | (bfd *, Elf_Internal_Note *); |
d0112f73 | 127 | static bfd_boolean elf64_mips_grok_psinfo |
11a2be4d | 128 | (bfd *, Elf_Internal_Note *); |
c6e90b02 | 129 | |
a4382ec6 TS |
130 | extern const bfd_target bfd_elf64_bigmips_vec; |
131 | extern const bfd_target bfd_elf64_littlemips_vec; | |
252b5132 RH |
132 | |
133 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value | |
134 | from smaller values. Start with zero, widen, *then* decrement. */ | |
135 | #define MINUS_ONE (((bfd_vma)0) - 1) | |
136 | ||
103186c6 MM |
137 | /* The number of local .got entries we reserve. */ |
138 | #define MIPS_RESERVED_GOTNO (2) | |
c6e90b02 | 139 | \f |
252b5132 RH |
140 | /* The relocation table used for SHT_REL sections. */ |
141 | ||
142 | static reloc_howto_type mips_elf64_howto_table_rel[] = | |
143 | { | |
144 | /* No relocation. */ | |
145 | HOWTO (R_MIPS_NONE, /* type */ | |
146 | 0, /* rightshift */ | |
147 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
148 | 0, /* bitsize */ | |
b34976b6 | 149 | FALSE, /* pc_relative */ |
252b5132 RH |
150 | 0, /* bitpos */ |
151 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 152 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 153 | "R_MIPS_NONE", /* name */ |
b34976b6 | 154 | FALSE, /* partial_inplace */ |
252b5132 RH |
155 | 0, /* src_mask */ |
156 | 0, /* dst_mask */ | |
b34976b6 | 157 | FALSE), /* pcrel_offset */ |
252b5132 RH |
158 | |
159 | /* 16 bit relocation. */ | |
160 | HOWTO (R_MIPS_16, /* type */ | |
161 | 0, /* rightshift */ | |
5b6a02bc | 162 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 | 163 | 16, /* bitsize */ |
b34976b6 | 164 | FALSE, /* pc_relative */ |
252b5132 | 165 | 0, /* bitpos */ |
5b6a02bc | 166 | complain_overflow_signed, /* complain_on_overflow */ |
30ac9238 | 167 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 168 | "R_MIPS_16", /* name */ |
b34976b6 | 169 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
170 | 0x0000ffff, /* src_mask */ |
171 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 172 | FALSE), /* pcrel_offset */ |
252b5132 RH |
173 | |
174 | /* 32 bit relocation. */ | |
175 | HOWTO (R_MIPS_32, /* type */ | |
176 | 0, /* rightshift */ | |
177 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
178 | 32, /* bitsize */ | |
b34976b6 | 179 | FALSE, /* pc_relative */ |
252b5132 | 180 | 0, /* bitpos */ |
77bfe34f | 181 | complain_overflow_dont, /* complain_on_overflow */ |
30ac9238 | 182 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 183 | "R_MIPS_32", /* name */ |
b34976b6 | 184 | TRUE, /* partial_inplace */ |
252b5132 RH |
185 | 0xffffffff, /* src_mask */ |
186 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 187 | FALSE), /* pcrel_offset */ |
252b5132 RH |
188 | |
189 | /* 32 bit symbol relative relocation. */ | |
190 | HOWTO (R_MIPS_REL32, /* type */ | |
191 | 0, /* rightshift */ | |
192 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
193 | 32, /* bitsize */ | |
b34976b6 | 194 | FALSE, /* pc_relative */ |
252b5132 | 195 | 0, /* bitpos */ |
77bfe34f | 196 | complain_overflow_dont, /* complain_on_overflow */ |
30ac9238 | 197 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 198 | "R_MIPS_REL32", /* name */ |
b34976b6 | 199 | TRUE, /* partial_inplace */ |
252b5132 RH |
200 | 0xffffffff, /* src_mask */ |
201 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 202 | FALSE), /* pcrel_offset */ |
252b5132 | 203 | |
77bfe34f | 204 | /* 26 bit jump address. */ |
252b5132 RH |
205 | HOWTO (R_MIPS_26, /* type */ |
206 | 2, /* rightshift */ | |
207 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
208 | 26, /* bitsize */ | |
b34976b6 | 209 | FALSE, /* pc_relative */ |
252b5132 RH |
210 | 0, /* bitpos */ |
211 | complain_overflow_dont, /* complain_on_overflow */ | |
56fc028e | 212 | /* This needs complex overflow |
77bfe34f | 213 | detection, because the upper 36 |
b401d8e5 | 214 | bits must match the PC + 4. */ |
30ac9238 | 215 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 216 | "R_MIPS_26", /* name */ |
b34976b6 | 217 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
218 | 0x03ffffff, /* src_mask */ |
219 | 0x03ffffff, /* dst_mask */ | |
b34976b6 | 220 | FALSE), /* pcrel_offset */ |
252b5132 | 221 | |
a4382ec6 TS |
222 | /* R_MIPS_HI16 and R_MIPS_LO16 are unsupported for NewABI REL. |
223 | However, the native IRIX6 tools use them, so we try our best. */ | |
224 | ||
252b5132 RH |
225 | /* High 16 bits of symbol value. */ |
226 | HOWTO (R_MIPS_HI16, /* type */ | |
30ac9238 | 227 | 16, /* rightshift */ |
252b5132 RH |
228 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
229 | 16, /* bitsize */ | |
b34976b6 | 230 | FALSE, /* pc_relative */ |
252b5132 RH |
231 | 0, /* bitpos */ |
232 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 233 | _bfd_mips_elf_hi16_reloc, /* special_function */ |
252b5132 | 234 | "R_MIPS_HI16", /* name */ |
b34976b6 | 235 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
236 | 0x0000ffff, /* src_mask */ |
237 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 238 | FALSE), /* pcrel_offset */ |
252b5132 RH |
239 | |
240 | /* Low 16 bits of symbol value. */ | |
241 | HOWTO (R_MIPS_LO16, /* type */ | |
242 | 0, /* rightshift */ | |
243 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
244 | 16, /* bitsize */ | |
b34976b6 | 245 | FALSE, /* pc_relative */ |
252b5132 RH |
246 | 0, /* bitpos */ |
247 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 248 | _bfd_mips_elf_lo16_reloc, /* special_function */ |
252b5132 | 249 | "R_MIPS_LO16", /* name */ |
b34976b6 | 250 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
251 | 0x0000ffff, /* src_mask */ |
252 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 253 | FALSE), /* pcrel_offset */ |
252b5132 RH |
254 | |
255 | /* GP relative reference. */ | |
256 | HOWTO (R_MIPS_GPREL16, /* type */ | |
257 | 0, /* rightshift */ | |
258 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
259 | 16, /* bitsize */ | |
b34976b6 | 260 | FALSE, /* pc_relative */ |
252b5132 RH |
261 | 0, /* bitpos */ |
262 | complain_overflow_signed, /* complain_on_overflow */ | |
5b6a02bc | 263 | mips_elf64_gprel16_reloc, /* special_function */ |
252b5132 | 264 | "R_MIPS_GPREL16", /* name */ |
b34976b6 | 265 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
266 | 0x0000ffff, /* src_mask */ |
267 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 268 | FALSE), /* pcrel_offset */ |
252b5132 RH |
269 | |
270 | /* Reference to literal section. */ | |
271 | HOWTO (R_MIPS_LITERAL, /* type */ | |
272 | 0, /* rightshift */ | |
273 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
274 | 16, /* bitsize */ | |
b34976b6 | 275 | FALSE, /* pc_relative */ |
252b5132 RH |
276 | 0, /* bitpos */ |
277 | complain_overflow_signed, /* complain_on_overflow */ | |
5b6a02bc | 278 | mips_elf64_literal_reloc, /* special_function */ |
252b5132 | 279 | "R_MIPS_LITERAL", /* name */ |
b34976b6 | 280 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
281 | 0x0000ffff, /* src_mask */ |
282 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 283 | FALSE), /* pcrel_offset */ |
252b5132 RH |
284 | |
285 | /* Reference to global offset table. */ | |
286 | HOWTO (R_MIPS_GOT16, /* type */ | |
287 | 0, /* rightshift */ | |
288 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
289 | 16, /* bitsize */ | |
b34976b6 | 290 | FALSE, /* pc_relative */ |
252b5132 RH |
291 | 0, /* bitpos */ |
292 | complain_overflow_signed, /* complain_on_overflow */ | |
30ac9238 | 293 | _bfd_mips_elf_got16_reloc, /* special_function */ |
252b5132 | 294 | "R_MIPS_GOT16", /* name */ |
b34976b6 | 295 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
296 | 0x0000ffff, /* src_mask */ |
297 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 298 | FALSE), /* pcrel_offset */ |
252b5132 | 299 | |
bad36eac DJ |
300 | /* 16 bit PC relative reference. Note that the ABI document has a typo |
301 | and claims R_MIPS_PC16 to be not rightshifted, rendering it useless. | |
302 | We do the right thing here. */ | |
252b5132 | 303 | HOWTO (R_MIPS_PC16, /* type */ |
bad36eac | 304 | 2, /* rightshift */ |
252b5132 RH |
305 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
306 | 16, /* bitsize */ | |
b34976b6 | 307 | TRUE, /* pc_relative */ |
252b5132 RH |
308 | 0, /* bitpos */ |
309 | complain_overflow_signed, /* complain_on_overflow */ | |
30ac9238 | 310 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 311 | "R_MIPS_PC16", /* name */ |
b34976b6 | 312 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
313 | 0x0000ffff, /* src_mask */ |
314 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 315 | TRUE), /* pcrel_offset */ |
252b5132 RH |
316 | |
317 | /* 16 bit call through global offset table. */ | |
252b5132 RH |
318 | HOWTO (R_MIPS_CALL16, /* type */ |
319 | 0, /* rightshift */ | |
320 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
321 | 16, /* bitsize */ | |
b34976b6 | 322 | FALSE, /* pc_relative */ |
252b5132 RH |
323 | 0, /* bitpos */ |
324 | complain_overflow_signed, /* complain_on_overflow */ | |
30ac9238 | 325 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 326 | "R_MIPS_CALL16", /* name */ |
b34976b6 | 327 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
328 | 0x0000ffff, /* src_mask */ |
329 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 330 | FALSE), /* pcrel_offset */ |
252b5132 RH |
331 | |
332 | /* 32 bit GP relative reference. */ | |
333 | HOWTO (R_MIPS_GPREL32, /* type */ | |
334 | 0, /* rightshift */ | |
335 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
336 | 32, /* bitsize */ | |
b34976b6 | 337 | FALSE, /* pc_relative */ |
252b5132 | 338 | 0, /* bitpos */ |
5b6a02bc TS |
339 | complain_overflow_dont, /* complain_on_overflow */ |
340 | mips_elf64_gprel32_reloc, /* special_function */ | |
252b5132 | 341 | "R_MIPS_GPREL32", /* name */ |
b34976b6 | 342 | TRUE, /* partial_inplace */ |
252b5132 RH |
343 | 0xffffffff, /* src_mask */ |
344 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 345 | FALSE), /* pcrel_offset */ |
252b5132 | 346 | |
a4382ec6 TS |
347 | EMPTY_HOWTO (13), |
348 | EMPTY_HOWTO (14), | |
349 | EMPTY_HOWTO (15), | |
252b5132 RH |
350 | |
351 | /* A 5 bit shift field. */ | |
352 | HOWTO (R_MIPS_SHIFT5, /* type */ | |
353 | 0, /* rightshift */ | |
354 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
355 | 5, /* bitsize */ | |
b34976b6 | 356 | FALSE, /* pc_relative */ |
252b5132 RH |
357 | 6, /* bitpos */ |
358 | complain_overflow_bitfield, /* complain_on_overflow */ | |
30ac9238 | 359 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 360 | "R_MIPS_SHIFT5", /* name */ |
b34976b6 | 361 | TRUE, /* partial_inplace */ |
252b5132 RH |
362 | 0x000007c0, /* src_mask */ |
363 | 0x000007c0, /* dst_mask */ | |
b34976b6 | 364 | FALSE), /* pcrel_offset */ |
252b5132 RH |
365 | |
366 | /* A 6 bit shift field. */ | |
252b5132 RH |
367 | HOWTO (R_MIPS_SHIFT6, /* type */ |
368 | 0, /* rightshift */ | |
369 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
370 | 6, /* bitsize */ | |
b34976b6 | 371 | FALSE, /* pc_relative */ |
252b5132 RH |
372 | 6, /* bitpos */ |
373 | complain_overflow_bitfield, /* complain_on_overflow */ | |
5b6a02bc | 374 | mips_elf64_shift6_reloc, /* special_function */ |
252b5132 | 375 | "R_MIPS_SHIFT6", /* name */ |
b34976b6 | 376 | TRUE, /* partial_inplace */ |
252b5132 RH |
377 | 0x000007c4, /* src_mask */ |
378 | 0x000007c4, /* dst_mask */ | |
b34976b6 | 379 | FALSE), /* pcrel_offset */ |
252b5132 RH |
380 | |
381 | /* 64 bit relocation. */ | |
382 | HOWTO (R_MIPS_64, /* type */ | |
383 | 0, /* rightshift */ | |
384 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
385 | 64, /* bitsize */ | |
b34976b6 | 386 | FALSE, /* pc_relative */ |
252b5132 | 387 | 0, /* bitpos */ |
77bfe34f | 388 | complain_overflow_dont, /* complain_on_overflow */ |
30ac9238 | 389 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 390 | "R_MIPS_64", /* name */ |
b34976b6 | 391 | TRUE, /* partial_inplace */ |
252b5132 RH |
392 | MINUS_ONE, /* src_mask */ |
393 | MINUS_ONE, /* dst_mask */ | |
b34976b6 | 394 | FALSE), /* pcrel_offset */ |
252b5132 RH |
395 | |
396 | /* Displacement in the global offset table. */ | |
252b5132 RH |
397 | HOWTO (R_MIPS_GOT_DISP, /* type */ |
398 | 0, /* rightshift */ | |
399 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
400 | 16, /* bitsize */ | |
b34976b6 | 401 | FALSE, /* pc_relative */ |
252b5132 | 402 | 0, /* bitpos */ |
77bfe34f | 403 | complain_overflow_signed, /* complain_on_overflow */ |
30ac9238 | 404 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 405 | "R_MIPS_GOT_DISP", /* name */ |
b34976b6 | 406 | TRUE, /* partial_inplace */ |
252b5132 RH |
407 | 0x0000ffff, /* src_mask */ |
408 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 409 | FALSE), /* pcrel_offset */ |
252b5132 RH |
410 | |
411 | /* Displacement to page pointer in the global offset table. */ | |
252b5132 RH |
412 | HOWTO (R_MIPS_GOT_PAGE, /* type */ |
413 | 0, /* rightshift */ | |
414 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
415 | 16, /* bitsize */ | |
b34976b6 | 416 | FALSE, /* pc_relative */ |
252b5132 | 417 | 0, /* bitpos */ |
77bfe34f | 418 | complain_overflow_signed, /* complain_on_overflow */ |
30ac9238 | 419 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 420 | "R_MIPS_GOT_PAGE", /* name */ |
b34976b6 | 421 | TRUE, /* partial_inplace */ |
252b5132 RH |
422 | 0x0000ffff, /* src_mask */ |
423 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 424 | FALSE), /* pcrel_offset */ |
252b5132 RH |
425 | |
426 | /* Offset from page pointer in the global offset table. */ | |
252b5132 RH |
427 | HOWTO (R_MIPS_GOT_OFST, /* type */ |
428 | 0, /* rightshift */ | |
429 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
430 | 16, /* bitsize */ | |
b34976b6 | 431 | FALSE, /* pc_relative */ |
252b5132 | 432 | 0, /* bitpos */ |
77bfe34f | 433 | complain_overflow_signed, /* complain_on_overflow */ |
30ac9238 | 434 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 435 | "R_MIPS_GOT_OFST", /* name */ |
b34976b6 | 436 | TRUE, /* partial_inplace */ |
252b5132 RH |
437 | 0x0000ffff, /* src_mask */ |
438 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 439 | FALSE), /* pcrel_offset */ |
252b5132 RH |
440 | |
441 | /* High 16 bits of displacement in global offset table. */ | |
252b5132 RH |
442 | HOWTO (R_MIPS_GOT_HI16, /* type */ |
443 | 0, /* rightshift */ | |
444 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
445 | 16, /* bitsize */ | |
b34976b6 | 446 | FALSE, /* pc_relative */ |
252b5132 RH |
447 | 0, /* bitpos */ |
448 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 449 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 450 | "R_MIPS_GOT_HI16", /* name */ |
b34976b6 | 451 | TRUE, /* partial_inplace */ |
252b5132 RH |
452 | 0x0000ffff, /* src_mask */ |
453 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 454 | FALSE), /* pcrel_offset */ |
252b5132 RH |
455 | |
456 | /* Low 16 bits of displacement in global offset table. */ | |
252b5132 RH |
457 | HOWTO (R_MIPS_GOT_LO16, /* type */ |
458 | 0, /* rightshift */ | |
459 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
460 | 16, /* bitsize */ | |
b34976b6 | 461 | FALSE, /* pc_relative */ |
252b5132 RH |
462 | 0, /* bitpos */ |
463 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 464 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 465 | "R_MIPS_GOT_LO16", /* name */ |
b34976b6 | 466 | TRUE, /* partial_inplace */ |
252b5132 RH |
467 | 0x0000ffff, /* src_mask */ |
468 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 469 | FALSE), /* pcrel_offset */ |
252b5132 | 470 | |
4cc11e76 | 471 | /* 64 bit subtraction. */ |
252b5132 RH |
472 | HOWTO (R_MIPS_SUB, /* type */ |
473 | 0, /* rightshift */ | |
474 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
475 | 64, /* bitsize */ | |
b34976b6 | 476 | FALSE, /* pc_relative */ |
252b5132 | 477 | 0, /* bitpos */ |
77bfe34f | 478 | complain_overflow_dont, /* complain_on_overflow */ |
30ac9238 | 479 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 480 | "R_MIPS_SUB", /* name */ |
b34976b6 | 481 | TRUE, /* partial_inplace */ |
252b5132 RH |
482 | MINUS_ONE, /* src_mask */ |
483 | MINUS_ONE, /* dst_mask */ | |
b34976b6 | 484 | FALSE), /* pcrel_offset */ |
252b5132 RH |
485 | |
486 | /* Insert the addend as an instruction. */ | |
487 | /* FIXME: Not handled correctly. */ | |
488 | HOWTO (R_MIPS_INSERT_A, /* type */ | |
489 | 0, /* rightshift */ | |
77bfe34f TS |
490 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
491 | 32, /* bitsize */ | |
b34976b6 | 492 | FALSE, /* pc_relative */ |
252b5132 RH |
493 | 0, /* bitpos */ |
494 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 495 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 496 | "R_MIPS_INSERT_A", /* name */ |
b34976b6 | 497 | TRUE, /* partial_inplace */ |
77bfe34f TS |
498 | 0xffffffff, /* src_mask */ |
499 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 500 | FALSE), /* pcrel_offset */ |
252b5132 RH |
501 | |
502 | /* Insert the addend as an instruction, and change all relocations | |
503 | to refer to the old instruction at the address. */ | |
504 | /* FIXME: Not handled correctly. */ | |
505 | HOWTO (R_MIPS_INSERT_B, /* type */ | |
506 | 0, /* rightshift */ | |
77bfe34f TS |
507 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
508 | 32, /* bitsize */ | |
b34976b6 | 509 | FALSE, /* pc_relative */ |
252b5132 RH |
510 | 0, /* bitpos */ |
511 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 512 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 513 | "R_MIPS_INSERT_B", /* name */ |
b34976b6 | 514 | TRUE, /* partial_inplace */ |
77bfe34f TS |
515 | 0xffffffff, /* src_mask */ |
516 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 517 | FALSE), /* pcrel_offset */ |
252b5132 RH |
518 | |
519 | /* Delete a 32 bit instruction. */ | |
520 | /* FIXME: Not handled correctly. */ | |
521 | HOWTO (R_MIPS_DELETE, /* type */ | |
522 | 0, /* rightshift */ | |
77bfe34f TS |
523 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
524 | 32, /* bitsize */ | |
b34976b6 | 525 | FALSE, /* pc_relative */ |
252b5132 RH |
526 | 0, /* bitpos */ |
527 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 528 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 529 | "R_MIPS_DELETE", /* name */ |
b34976b6 | 530 | TRUE, /* partial_inplace */ |
77bfe34f TS |
531 | 0xffffffff, /* src_mask */ |
532 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 533 | FALSE), /* pcrel_offset */ |
252b5132 | 534 | |
a4382ec6 TS |
535 | /* The MIPS ELF64 ABI Draft wants us to support these for REL relocations. |
536 | We don't, because | |
537 | a) It means building the addend from a R_MIPS_HIGHEST/R_MIPS_HIGHER/ | |
538 | R_MIPS_HI16/R_MIPS_LO16 sequence with varying ordering, using | |
539 | fallable heuristics. | |
540 | b) No other NewABI toolchain actually emits such relocations. */ | |
541 | EMPTY_HOWTO (R_MIPS_HIGHER), | |
542 | EMPTY_HOWTO (R_MIPS_HIGHEST), | |
252b5132 RH |
543 | |
544 | /* High 16 bits of displacement in global offset table. */ | |
252b5132 RH |
545 | HOWTO (R_MIPS_CALL_HI16, /* type */ |
546 | 0, /* rightshift */ | |
547 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
548 | 16, /* bitsize */ | |
b34976b6 | 549 | FALSE, /* pc_relative */ |
252b5132 RH |
550 | 0, /* bitpos */ |
551 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 552 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 553 | "R_MIPS_CALL_HI16", /* name */ |
b34976b6 | 554 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
555 | 0x0000ffff, /* src_mask */ |
556 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 557 | FALSE), /* pcrel_offset */ |
252b5132 RH |
558 | |
559 | /* Low 16 bits of displacement in global offset table. */ | |
252b5132 RH |
560 | HOWTO (R_MIPS_CALL_LO16, /* type */ |
561 | 0, /* rightshift */ | |
562 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
563 | 16, /* bitsize */ | |
b34976b6 | 564 | FALSE, /* pc_relative */ |
252b5132 RH |
565 | 0, /* bitpos */ |
566 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 567 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 568 | "R_MIPS_CALL_LO16", /* name */ |
b34976b6 | 569 | TRUE, /* partial_inplace */ |
5b6a02bc TS |
570 | 0x0000ffff, /* src_mask */ |
571 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 572 | FALSE), /* pcrel_offset */ |
252b5132 | 573 | |
5b6a02bc | 574 | /* Section displacement, used by an associated event location section. */ |
252b5132 RH |
575 | HOWTO (R_MIPS_SCN_DISP, /* type */ |
576 | 0, /* rightshift */ | |
77bfe34f TS |
577 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
578 | 32, /* bitsize */ | |
b34976b6 | 579 | FALSE, /* pc_relative */ |
252b5132 RH |
580 | 0, /* bitpos */ |
581 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 582 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 583 | "R_MIPS_SCN_DISP", /* name */ |
b34976b6 | 584 | TRUE, /* partial_inplace */ |
77bfe34f TS |
585 | 0xffffffff, /* src_mask */ |
586 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 587 | FALSE), /* pcrel_offset */ |
252b5132 RH |
588 | |
589 | HOWTO (R_MIPS_REL16, /* type */ | |
590 | 0, /* rightshift */ | |
77bfe34f TS |
591 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
592 | 16, /* bitsize */ | |
b34976b6 | 593 | FALSE, /* pc_relative */ |
252b5132 | 594 | 0, /* bitpos */ |
77bfe34f | 595 | complain_overflow_signed, /* complain_on_overflow */ |
30ac9238 | 596 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 597 | "R_MIPS_REL16", /* name */ |
b34976b6 | 598 | TRUE, /* partial_inplace */ |
77bfe34f TS |
599 | 0xffff, /* src_mask */ |
600 | 0xffff, /* dst_mask */ | |
b34976b6 | 601 | FALSE), /* pcrel_offset */ |
252b5132 | 602 | |
77bfe34f TS |
603 | /* These two are obsolete. */ |
604 | EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE), | |
605 | EMPTY_HOWTO (R_MIPS_PJUMP), | |
252b5132 | 606 | |
5b6a02bc TS |
607 | /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section. |
608 | It must be used for multigot GOT's (and only there). */ | |
252b5132 RH |
609 | HOWTO (R_MIPS_RELGOT, /* type */ |
610 | 0, /* rightshift */ | |
77bfe34f TS |
611 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
612 | 32, /* bitsize */ | |
b34976b6 | 613 | FALSE, /* pc_relative */ |
252b5132 RH |
614 | 0, /* bitpos */ |
615 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 616 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 617 | "R_MIPS_RELGOT", /* name */ |
b34976b6 | 618 | TRUE, /* partial_inplace */ |
77bfe34f TS |
619 | 0xffffffff, /* src_mask */ |
620 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 621 | FALSE), /* pcrel_offset */ |
d2905643 | 622 | |
fe8bc63d | 623 | /* Protected jump conversion. This is an optimization hint. No |
d2905643 | 624 | relocation is required for correctness. */ |
99277196 | 625 | HOWTO (R_MIPS_JALR, /* type */ |
d2905643 | 626 | 0, /* rightshift */ |
77bfe34f | 627 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
5b6a02bc | 628 | 32, /* bitsize */ |
b34976b6 | 629 | FALSE, /* pc_relative */ |
d2905643 MM |
630 | 0, /* bitpos */ |
631 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 632 | _bfd_mips_elf_generic_reloc, /* special_function */ |
99277196 | 633 | "R_MIPS_JALR", /* name */ |
b34976b6 | 634 | FALSE, /* partial_inplace */ |
77bfe34f | 635 | 0, /* src_mask */ |
5b6a02bc | 636 | 0x00000000, /* dst_mask */ |
b34976b6 | 637 | FALSE), /* pcrel_offset */ |
0f20cc35 DJ |
638 | |
639 | /* TLS relocations. */ | |
640 | EMPTY_HOWTO (R_MIPS_TLS_DTPMOD32), | |
641 | EMPTY_HOWTO (R_MIPS_TLS_DTPREL32), | |
642 | ||
643 | HOWTO (R_MIPS_TLS_DTPMOD64, /* type */ | |
644 | 0, /* rightshift */ | |
645 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
646 | 64, /* bitsize */ | |
647 | FALSE, /* pc_relative */ | |
648 | 0, /* bitpos */ | |
649 | complain_overflow_dont, /* complain_on_overflow */ | |
650 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
651 | "R_MIPS_TLS_DTPMOD64", /* name */ | |
652 | TRUE, /* partial_inplace */ | |
653 | MINUS_ONE, /* src_mask */ | |
654 | MINUS_ONE, /* dst_mask */ | |
655 | FALSE), /* pcrel_offset */ | |
656 | ||
657 | HOWTO (R_MIPS_TLS_DTPREL64, /* type */ | |
658 | 0, /* rightshift */ | |
659 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
660 | 64, /* bitsize */ | |
661 | FALSE, /* pc_relative */ | |
662 | 0, /* bitpos */ | |
663 | complain_overflow_dont, /* complain_on_overflow */ | |
664 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
665 | "R_MIPS_TLS_DTPREL64", /* name */ | |
666 | TRUE, /* partial_inplace */ | |
667 | MINUS_ONE, /* src_mask */ | |
668 | MINUS_ONE, /* dst_mask */ | |
669 | FALSE), /* pcrel_offset */ | |
670 | ||
671 | /* TLS general dynamic variable reference. */ | |
672 | HOWTO (R_MIPS_TLS_GD, /* type */ | |
673 | 0, /* rightshift */ | |
674 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
675 | 16, /* bitsize */ | |
676 | FALSE, /* pc_relative */ | |
677 | 0, /* bitpos */ | |
678 | complain_overflow_signed, /* complain_on_overflow */ | |
679 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
680 | "R_MIPS_TLS_GD", /* name */ | |
681 | TRUE, /* partial_inplace */ | |
682 | 0x0000ffff, /* src_mask */ | |
683 | 0x0000ffff, /* dst_mask */ | |
684 | FALSE), /* pcrel_offset */ | |
685 | ||
686 | /* TLS local dynamic variable reference. */ | |
687 | HOWTO (R_MIPS_TLS_LDM, /* type */ | |
688 | 0, /* rightshift */ | |
689 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
690 | 16, /* bitsize */ | |
691 | FALSE, /* pc_relative */ | |
692 | 0, /* bitpos */ | |
693 | complain_overflow_signed, /* complain_on_overflow */ | |
694 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
695 | "R_MIPS_TLS_LDM", /* name */ | |
696 | TRUE, /* partial_inplace */ | |
697 | 0x0000ffff, /* src_mask */ | |
698 | 0x0000ffff, /* dst_mask */ | |
699 | FALSE), /* pcrel_offset */ | |
700 | ||
701 | /* TLS local dynamic offset. */ | |
702 | HOWTO (R_MIPS_TLS_DTPREL_HI16, /* type */ | |
703 | 0, /* rightshift */ | |
704 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
705 | 16, /* bitsize */ | |
706 | FALSE, /* pc_relative */ | |
707 | 0, /* bitpos */ | |
708 | complain_overflow_signed, /* complain_on_overflow */ | |
709 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
710 | "R_MIPS_TLS_DTPREL_HI16", /* name */ | |
711 | TRUE, /* partial_inplace */ | |
712 | 0x0000ffff, /* src_mask */ | |
713 | 0x0000ffff, /* dst_mask */ | |
714 | FALSE), /* pcrel_offset */ | |
715 | ||
716 | /* TLS local dynamic offset. */ | |
717 | HOWTO (R_MIPS_TLS_DTPREL_LO16, /* type */ | |
718 | 0, /* rightshift */ | |
719 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
720 | 16, /* bitsize */ | |
721 | FALSE, /* pc_relative */ | |
722 | 0, /* bitpos */ | |
723 | complain_overflow_signed, /* complain_on_overflow */ | |
724 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
725 | "R_MIPS_TLS_DTPREL_LO16", /* name */ | |
726 | TRUE, /* partial_inplace */ | |
727 | 0x0000ffff, /* src_mask */ | |
728 | 0x0000ffff, /* dst_mask */ | |
729 | FALSE), /* pcrel_offset */ | |
730 | ||
731 | /* TLS thread pointer offset. */ | |
732 | HOWTO (R_MIPS_TLS_GOTTPREL, /* type */ | |
733 | 0, /* rightshift */ | |
734 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
735 | 16, /* bitsize */ | |
736 | FALSE, /* pc_relative */ | |
737 | 0, /* bitpos */ | |
738 | complain_overflow_signed, /* complain_on_overflow */ | |
739 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
740 | "R_MIPS_TLS_GOTTPREL", /* name */ | |
741 | TRUE, /* partial_inplace */ | |
742 | 0x0000ffff, /* src_mask */ | |
743 | 0x0000ffff, /* dst_mask */ | |
744 | FALSE), /* pcrel_offset */ | |
745 | ||
746 | /* TLS IE dynamic relocations. */ | |
747 | EMPTY_HOWTO (R_MIPS_TLS_TPREL32), | |
748 | ||
749 | HOWTO (R_MIPS_TLS_TPREL64, /* type */ | |
750 | 0, /* rightshift */ | |
751 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
752 | 64, /* bitsize */ | |
753 | FALSE, /* pc_relative */ | |
754 | 0, /* bitpos */ | |
755 | complain_overflow_dont, /* complain_on_overflow */ | |
756 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
757 | "R_MIPS_TLS_TPREL64", /* name */ | |
758 | TRUE, /* partial_inplace */ | |
759 | MINUS_ONE, /* src_mask */ | |
760 | MINUS_ONE, /* dst_mask */ | |
761 | FALSE), /* pcrel_offset */ | |
762 | ||
763 | /* TLS thread pointer offset. */ | |
764 | HOWTO (R_MIPS_TLS_TPREL_HI16, /* type */ | |
765 | 0, /* rightshift */ | |
766 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
767 | 16, /* bitsize */ | |
768 | FALSE, /* pc_relative */ | |
769 | 0, /* bitpos */ | |
770 | complain_overflow_signed, /* complain_on_overflow */ | |
771 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
772 | "R_MIPS_TLS_TPREL_HI16", /* name */ | |
773 | TRUE, /* partial_inplace */ | |
774 | 0x0000ffff, /* src_mask */ | |
775 | 0x0000ffff, /* dst_mask */ | |
776 | FALSE), /* pcrel_offset */ | |
777 | ||
778 | /* TLS thread pointer offset. */ | |
779 | HOWTO (R_MIPS_TLS_TPREL_LO16, /* type */ | |
780 | 0, /* rightshift */ | |
781 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
782 | 16, /* bitsize */ | |
783 | FALSE, /* pc_relative */ | |
784 | 0, /* bitpos */ | |
785 | complain_overflow_signed, /* complain_on_overflow */ | |
786 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
787 | "R_MIPS_TLS_TPREL_LO16", /* name */ | |
788 | TRUE, /* partial_inplace */ | |
789 | 0x0000ffff, /* src_mask */ | |
790 | 0x0000ffff, /* dst_mask */ | |
791 | FALSE), /* pcrel_offset */ | |
165b93e7 RS |
792 | |
793 | /* 32 bit relocation with no addend. */ | |
794 | HOWTO (R_MIPS_GLOB_DAT, /* type */ | |
795 | 0, /* rightshift */ | |
796 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
797 | 32, /* bitsize */ | |
798 | FALSE, /* pc_relative */ | |
799 | 0, /* bitpos */ | |
800 | complain_overflow_dont, /* complain_on_overflow */ | |
801 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
802 | "R_MIPS_GLOB_DAT", /* name */ | |
803 | FALSE, /* partial_inplace */ | |
804 | 0x0, /* src_mask */ | |
805 | 0xffffffff, /* dst_mask */ | |
806 | FALSE), /* pcrel_offset */ | |
252b5132 RH |
807 | }; |
808 | ||
809 | /* The relocation table used for SHT_RELA sections. */ | |
810 | ||
811 | static reloc_howto_type mips_elf64_howto_table_rela[] = | |
812 | { | |
813 | /* No relocation. */ | |
814 | HOWTO (R_MIPS_NONE, /* type */ | |
815 | 0, /* rightshift */ | |
816 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
817 | 0, /* bitsize */ | |
b34976b6 | 818 | FALSE, /* pc_relative */ |
252b5132 RH |
819 | 0, /* bitpos */ |
820 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 821 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 822 | "R_MIPS_NONE", /* name */ |
b34976b6 | 823 | FALSE, /* partial_inplace */ |
252b5132 RH |
824 | 0, /* src_mask */ |
825 | 0, /* dst_mask */ | |
b34976b6 | 826 | FALSE), /* pcrel_offset */ |
252b5132 RH |
827 | |
828 | /* 16 bit relocation. */ | |
829 | HOWTO (R_MIPS_16, /* type */ | |
830 | 0, /* rightshift */ | |
5b6a02bc | 831 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 | 832 | 16, /* bitsize */ |
b34976b6 | 833 | FALSE, /* pc_relative */ |
252b5132 | 834 | 0, /* bitpos */ |
5b6a02bc | 835 | complain_overflow_signed, /* complain_on_overflow */ |
30ac9238 | 836 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 837 | "R_MIPS_16", /* name */ |
b34976b6 | 838 | FALSE, /* partial_inplace */ |
252b5132 | 839 | 0, /* src_mask */ |
5b6a02bc | 840 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 841 | FALSE), /* pcrel_offset */ |
252b5132 RH |
842 | |
843 | /* 32 bit relocation. */ | |
844 | HOWTO (R_MIPS_32, /* type */ | |
845 | 0, /* rightshift */ | |
846 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
847 | 32, /* bitsize */ | |
b34976b6 | 848 | FALSE, /* pc_relative */ |
252b5132 | 849 | 0, /* bitpos */ |
77bfe34f | 850 | complain_overflow_dont, /* complain_on_overflow */ |
30ac9238 | 851 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 852 | "R_MIPS_32", /* name */ |
b34976b6 | 853 | FALSE, /* partial_inplace */ |
252b5132 RH |
854 | 0, /* src_mask */ |
855 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 856 | FALSE), /* pcrel_offset */ |
252b5132 RH |
857 | |
858 | /* 32 bit symbol relative relocation. */ | |
859 | HOWTO (R_MIPS_REL32, /* type */ | |
860 | 0, /* rightshift */ | |
861 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
862 | 32, /* bitsize */ | |
b34976b6 | 863 | FALSE, /* pc_relative */ |
252b5132 | 864 | 0, /* bitpos */ |
77bfe34f | 865 | complain_overflow_dont, /* complain_on_overflow */ |
30ac9238 | 866 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 867 | "R_MIPS_REL32", /* name */ |
b34976b6 | 868 | FALSE, /* partial_inplace */ |
252b5132 RH |
869 | 0, /* src_mask */ |
870 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 871 | FALSE), /* pcrel_offset */ |
252b5132 | 872 | |
77bfe34f | 873 | /* 26 bit jump address. */ |
252b5132 RH |
874 | HOWTO (R_MIPS_26, /* type */ |
875 | 2, /* rightshift */ | |
876 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
877 | 26, /* bitsize */ | |
b34976b6 | 878 | FALSE, /* pc_relative */ |
252b5132 RH |
879 | 0, /* bitpos */ |
880 | complain_overflow_dont, /* complain_on_overflow */ | |
56fc028e | 881 | /* This needs complex overflow |
77bfe34f | 882 | detection, because the upper 36 |
b401d8e5 | 883 | bits must match the PC + 4. */ |
30ac9238 | 884 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 885 | "R_MIPS_26", /* name */ |
b34976b6 | 886 | FALSE, /* partial_inplace */ |
252b5132 | 887 | 0, /* src_mask */ |
5b6a02bc | 888 | 0x03ffffff, /* dst_mask */ |
b34976b6 | 889 | FALSE), /* pcrel_offset */ |
252b5132 RH |
890 | |
891 | /* High 16 bits of symbol value. */ | |
892 | HOWTO (R_MIPS_HI16, /* type */ | |
893 | 0, /* rightshift */ | |
894 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
895 | 16, /* bitsize */ | |
b34976b6 | 896 | FALSE, /* pc_relative */ |
252b5132 RH |
897 | 0, /* bitpos */ |
898 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 899 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 900 | "R_MIPS_HI16", /* name */ |
b34976b6 | 901 | FALSE, /* partial_inplace */ |
252b5132 | 902 | 0, /* src_mask */ |
5b6a02bc | 903 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 904 | FALSE), /* pcrel_offset */ |
252b5132 RH |
905 | |
906 | /* Low 16 bits of symbol value. */ | |
907 | HOWTO (R_MIPS_LO16, /* type */ | |
908 | 0, /* rightshift */ | |
909 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
910 | 16, /* bitsize */ | |
b34976b6 | 911 | FALSE, /* pc_relative */ |
252b5132 RH |
912 | 0, /* bitpos */ |
913 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 914 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 915 | "R_MIPS_LO16", /* name */ |
b34976b6 | 916 | FALSE, /* partial_inplace */ |
252b5132 | 917 | 0, /* src_mask */ |
5b6a02bc | 918 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 919 | FALSE), /* pcrel_offset */ |
252b5132 RH |
920 | |
921 | /* GP relative reference. */ | |
922 | HOWTO (R_MIPS_GPREL16, /* type */ | |
923 | 0, /* rightshift */ | |
924 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
925 | 16, /* bitsize */ | |
b34976b6 | 926 | FALSE, /* pc_relative */ |
252b5132 RH |
927 | 0, /* bitpos */ |
928 | complain_overflow_signed, /* complain_on_overflow */ | |
a4382ec6 | 929 | mips_elf64_gprel16_reloc, /* special_function */ |
252b5132 | 930 | "R_MIPS_GPREL16", /* name */ |
b34976b6 | 931 | FALSE, /* partial_inplace */ |
252b5132 | 932 | 0, /* src_mask */ |
5b6a02bc | 933 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 934 | FALSE), /* pcrel_offset */ |
252b5132 RH |
935 | |
936 | /* Reference to literal section. */ | |
937 | HOWTO (R_MIPS_LITERAL, /* type */ | |
938 | 0, /* rightshift */ | |
939 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
940 | 16, /* bitsize */ | |
b34976b6 | 941 | FALSE, /* pc_relative */ |
252b5132 RH |
942 | 0, /* bitpos */ |
943 | complain_overflow_signed, /* complain_on_overflow */ | |
5b6a02bc | 944 | mips_elf64_literal_reloc, /* special_function */ |
252b5132 | 945 | "R_MIPS_LITERAL", /* name */ |
b34976b6 | 946 | FALSE, /* partial_inplace */ |
252b5132 | 947 | 0, /* src_mask */ |
5b6a02bc | 948 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 949 | FALSE), /* pcrel_offset */ |
252b5132 RH |
950 | |
951 | /* Reference to global offset table. */ | |
252b5132 RH |
952 | HOWTO (R_MIPS_GOT16, /* type */ |
953 | 0, /* rightshift */ | |
954 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
955 | 16, /* bitsize */ | |
b34976b6 | 956 | FALSE, /* pc_relative */ |
252b5132 RH |
957 | 0, /* bitpos */ |
958 | complain_overflow_signed, /* complain_on_overflow */ | |
30ac9238 | 959 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 960 | "R_MIPS_GOT16", /* name */ |
b34976b6 | 961 | FALSE, /* partial_inplace */ |
252b5132 | 962 | 0, /* src_mask */ |
5b6a02bc | 963 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 964 | FALSE), /* pcrel_offset */ |
252b5132 | 965 | |
bad36eac DJ |
966 | /* 16 bit PC relative reference. Note that the ABI document has a typo |
967 | and claims R_MIPS_PC16 to be not rightshifted, rendering it useless. | |
968 | We do the right thing here. */ | |
252b5132 | 969 | HOWTO (R_MIPS_PC16, /* type */ |
bad36eac | 970 | 2, /* rightshift */ |
252b5132 RH |
971 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
972 | 16, /* bitsize */ | |
b34976b6 | 973 | TRUE, /* pc_relative */ |
252b5132 RH |
974 | 0, /* bitpos */ |
975 | complain_overflow_signed, /* complain_on_overflow */ | |
30ac9238 | 976 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 977 | "R_MIPS_PC16", /* name */ |
b34976b6 | 978 | FALSE, /* partial_inplace */ |
252b5132 | 979 | 0, /* src_mask */ |
5b6a02bc | 980 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 981 | TRUE), /* pcrel_offset */ |
252b5132 RH |
982 | |
983 | /* 16 bit call through global offset table. */ | |
252b5132 RH |
984 | HOWTO (R_MIPS_CALL16, /* type */ |
985 | 0, /* rightshift */ | |
986 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
987 | 16, /* bitsize */ | |
b34976b6 | 988 | FALSE, /* pc_relative */ |
252b5132 RH |
989 | 0, /* bitpos */ |
990 | complain_overflow_signed, /* complain_on_overflow */ | |
30ac9238 | 991 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 992 | "R_MIPS_CALL16", /* name */ |
b34976b6 | 993 | FALSE, /* partial_inplace */ |
252b5132 | 994 | 0, /* src_mask */ |
5b6a02bc | 995 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 996 | FALSE), /* pcrel_offset */ |
252b5132 RH |
997 | |
998 | /* 32 bit GP relative reference. */ | |
999 | HOWTO (R_MIPS_GPREL32, /* type */ | |
1000 | 0, /* rightshift */ | |
1001 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1002 | 32, /* bitsize */ | |
b34976b6 | 1003 | FALSE, /* pc_relative */ |
252b5132 | 1004 | 0, /* bitpos */ |
5b6a02bc TS |
1005 | complain_overflow_dont, /* complain_on_overflow */ |
1006 | mips_elf64_gprel32_reloc, /* special_function */ | |
252b5132 | 1007 | "R_MIPS_GPREL32", /* name */ |
b34976b6 | 1008 | FALSE, /* partial_inplace */ |
252b5132 RH |
1009 | 0, /* src_mask */ |
1010 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 1011 | FALSE), /* pcrel_offset */ |
252b5132 | 1012 | |
a4382ec6 TS |
1013 | EMPTY_HOWTO (13), |
1014 | EMPTY_HOWTO (14), | |
1015 | EMPTY_HOWTO (15), | |
252b5132 RH |
1016 | |
1017 | /* A 5 bit shift field. */ | |
1018 | HOWTO (R_MIPS_SHIFT5, /* type */ | |
1019 | 0, /* rightshift */ | |
1020 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1021 | 5, /* bitsize */ | |
b34976b6 | 1022 | FALSE, /* pc_relative */ |
252b5132 RH |
1023 | 6, /* bitpos */ |
1024 | complain_overflow_bitfield, /* complain_on_overflow */ | |
30ac9238 | 1025 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1026 | "R_MIPS_SHIFT5", /* name */ |
b34976b6 | 1027 | FALSE, /* partial_inplace */ |
252b5132 RH |
1028 | 0, /* src_mask */ |
1029 | 0x000007c0, /* dst_mask */ | |
b34976b6 | 1030 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1031 | |
1032 | /* A 6 bit shift field. */ | |
252b5132 RH |
1033 | HOWTO (R_MIPS_SHIFT6, /* type */ |
1034 | 0, /* rightshift */ | |
1035 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1036 | 6, /* bitsize */ | |
b34976b6 | 1037 | FALSE, /* pc_relative */ |
252b5132 RH |
1038 | 6, /* bitpos */ |
1039 | complain_overflow_bitfield, /* complain_on_overflow */ | |
5b6a02bc | 1040 | mips_elf64_shift6_reloc, /* special_function */ |
252b5132 | 1041 | "R_MIPS_SHIFT6", /* name */ |
b34976b6 | 1042 | FALSE, /* partial_inplace */ |
252b5132 RH |
1043 | 0, /* src_mask */ |
1044 | 0x000007c4, /* dst_mask */ | |
b34976b6 | 1045 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1046 | |
1047 | /* 64 bit relocation. */ | |
1048 | HOWTO (R_MIPS_64, /* type */ | |
1049 | 0, /* rightshift */ | |
1050 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1051 | 64, /* bitsize */ | |
b34976b6 | 1052 | FALSE, /* pc_relative */ |
252b5132 | 1053 | 0, /* bitpos */ |
77bfe34f | 1054 | complain_overflow_dont, /* complain_on_overflow */ |
30ac9238 | 1055 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1056 | "R_MIPS_64", /* name */ |
b34976b6 | 1057 | FALSE, /* partial_inplace */ |
252b5132 RH |
1058 | 0, /* src_mask */ |
1059 | MINUS_ONE, /* dst_mask */ | |
b34976b6 | 1060 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1061 | |
1062 | /* Displacement in the global offset table. */ | |
252b5132 RH |
1063 | HOWTO (R_MIPS_GOT_DISP, /* type */ |
1064 | 0, /* rightshift */ | |
1065 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1066 | 16, /* bitsize */ | |
b34976b6 | 1067 | FALSE, /* pc_relative */ |
252b5132 | 1068 | 0, /* bitpos */ |
77bfe34f | 1069 | complain_overflow_signed, /* complain_on_overflow */ |
30ac9238 | 1070 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1071 | "R_MIPS_GOT_DISP", /* name */ |
b34976b6 | 1072 | FALSE, /* partial_inplace */ |
252b5132 RH |
1073 | 0, /* src_mask */ |
1074 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 1075 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1076 | |
1077 | /* Displacement to page pointer in the global offset table. */ | |
252b5132 RH |
1078 | HOWTO (R_MIPS_GOT_PAGE, /* type */ |
1079 | 0, /* rightshift */ | |
1080 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1081 | 16, /* bitsize */ | |
b34976b6 | 1082 | FALSE, /* pc_relative */ |
252b5132 | 1083 | 0, /* bitpos */ |
77bfe34f | 1084 | complain_overflow_signed, /* complain_on_overflow */ |
30ac9238 | 1085 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1086 | "R_MIPS_GOT_PAGE", /* name */ |
b34976b6 | 1087 | FALSE, /* partial_inplace */ |
252b5132 RH |
1088 | 0, /* src_mask */ |
1089 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 1090 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1091 | |
1092 | /* Offset from page pointer in the global offset table. */ | |
252b5132 RH |
1093 | HOWTO (R_MIPS_GOT_OFST, /* type */ |
1094 | 0, /* rightshift */ | |
1095 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1096 | 16, /* bitsize */ | |
b34976b6 | 1097 | FALSE, /* pc_relative */ |
252b5132 | 1098 | 0, /* bitpos */ |
77bfe34f | 1099 | complain_overflow_signed, /* complain_on_overflow */ |
30ac9238 | 1100 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1101 | "R_MIPS_GOT_OFST", /* name */ |
b34976b6 | 1102 | FALSE, /* partial_inplace */ |
252b5132 RH |
1103 | 0, /* src_mask */ |
1104 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 1105 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1106 | |
1107 | /* High 16 bits of displacement in global offset table. */ | |
252b5132 RH |
1108 | HOWTO (R_MIPS_GOT_HI16, /* type */ |
1109 | 0, /* rightshift */ | |
1110 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1111 | 16, /* bitsize */ | |
b34976b6 | 1112 | FALSE, /* pc_relative */ |
252b5132 RH |
1113 | 0, /* bitpos */ |
1114 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1115 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1116 | "R_MIPS_GOT_HI16", /* name */ |
b34976b6 | 1117 | FALSE, /* partial_inplace */ |
252b5132 RH |
1118 | 0, /* src_mask */ |
1119 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 1120 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1121 | |
1122 | /* Low 16 bits of displacement in global offset table. */ | |
252b5132 RH |
1123 | HOWTO (R_MIPS_GOT_LO16, /* type */ |
1124 | 0, /* rightshift */ | |
1125 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1126 | 16, /* bitsize */ | |
b34976b6 | 1127 | FALSE, /* pc_relative */ |
252b5132 RH |
1128 | 0, /* bitpos */ |
1129 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1130 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1131 | "R_MIPS_GOT_LO16", /* name */ |
b34976b6 | 1132 | FALSE, /* partial_inplace */ |
252b5132 RH |
1133 | 0, /* src_mask */ |
1134 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 1135 | FALSE), /* pcrel_offset */ |
252b5132 | 1136 | |
4cc11e76 | 1137 | /* 64 bit subtraction. */ |
252b5132 RH |
1138 | HOWTO (R_MIPS_SUB, /* type */ |
1139 | 0, /* rightshift */ | |
1140 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1141 | 64, /* bitsize */ | |
b34976b6 | 1142 | FALSE, /* pc_relative */ |
252b5132 | 1143 | 0, /* bitpos */ |
77bfe34f | 1144 | complain_overflow_dont, /* complain_on_overflow */ |
30ac9238 | 1145 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1146 | "R_MIPS_SUB", /* name */ |
b34976b6 | 1147 | FALSE, /* partial_inplace */ |
252b5132 RH |
1148 | 0, /* src_mask */ |
1149 | MINUS_ONE, /* dst_mask */ | |
b34976b6 | 1150 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1151 | |
1152 | /* Insert the addend as an instruction. */ | |
1153 | /* FIXME: Not handled correctly. */ | |
1154 | HOWTO (R_MIPS_INSERT_A, /* type */ | |
1155 | 0, /* rightshift */ | |
77bfe34f TS |
1156 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
1157 | 32, /* bitsize */ | |
b34976b6 | 1158 | FALSE, /* pc_relative */ |
252b5132 RH |
1159 | 0, /* bitpos */ |
1160 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1161 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1162 | "R_MIPS_INSERT_A", /* name */ |
b34976b6 | 1163 | FALSE, /* partial_inplace */ |
252b5132 | 1164 | 0, /* src_mask */ |
77bfe34f | 1165 | 0xffffffff, /* dst_mask */ |
b34976b6 | 1166 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1167 | |
1168 | /* Insert the addend as an instruction, and change all relocations | |
1169 | to refer to the old instruction at the address. */ | |
1170 | /* FIXME: Not handled correctly. */ | |
1171 | HOWTO (R_MIPS_INSERT_B, /* type */ | |
1172 | 0, /* rightshift */ | |
77bfe34f TS |
1173 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
1174 | 32, /* bitsize */ | |
b34976b6 | 1175 | FALSE, /* pc_relative */ |
252b5132 RH |
1176 | 0, /* bitpos */ |
1177 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1178 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1179 | "R_MIPS_INSERT_B", /* name */ |
b34976b6 | 1180 | FALSE, /* partial_inplace */ |
252b5132 | 1181 | 0, /* src_mask */ |
77bfe34f | 1182 | 0xffffffff, /* dst_mask */ |
b34976b6 | 1183 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1184 | |
1185 | /* Delete a 32 bit instruction. */ | |
1186 | /* FIXME: Not handled correctly. */ | |
1187 | HOWTO (R_MIPS_DELETE, /* type */ | |
1188 | 0, /* rightshift */ | |
77bfe34f TS |
1189 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
1190 | 32, /* bitsize */ | |
b34976b6 | 1191 | FALSE, /* pc_relative */ |
252b5132 RH |
1192 | 0, /* bitpos */ |
1193 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1194 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1195 | "R_MIPS_DELETE", /* name */ |
b34976b6 | 1196 | FALSE, /* partial_inplace */ |
252b5132 | 1197 | 0, /* src_mask */ |
77bfe34f | 1198 | 0xffffffff, /* dst_mask */ |
b34976b6 | 1199 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1200 | |
1201 | /* Get the higher value of a 64 bit addend. */ | |
252b5132 RH |
1202 | HOWTO (R_MIPS_HIGHER, /* type */ |
1203 | 0, /* rightshift */ | |
1204 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1205 | 16, /* bitsize */ | |
b34976b6 | 1206 | FALSE, /* pc_relative */ |
252b5132 RH |
1207 | 0, /* bitpos */ |
1208 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1209 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1210 | "R_MIPS_HIGHER", /* name */ |
b34976b6 | 1211 | FALSE, /* partial_inplace */ |
252b5132 | 1212 | 0, /* src_mask */ |
5b6a02bc | 1213 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 1214 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1215 | |
1216 | /* Get the highest value of a 64 bit addend. */ | |
252b5132 RH |
1217 | HOWTO (R_MIPS_HIGHEST, /* type */ |
1218 | 0, /* rightshift */ | |
1219 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1220 | 16, /* bitsize */ | |
b34976b6 | 1221 | FALSE, /* pc_relative */ |
252b5132 RH |
1222 | 0, /* bitpos */ |
1223 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1224 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1225 | "R_MIPS_HIGHEST", /* name */ |
b34976b6 | 1226 | FALSE, /* partial_inplace */ |
252b5132 | 1227 | 0, /* src_mask */ |
5b6a02bc | 1228 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 1229 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1230 | |
1231 | /* High 16 bits of displacement in global offset table. */ | |
252b5132 RH |
1232 | HOWTO (R_MIPS_CALL_HI16, /* type */ |
1233 | 0, /* rightshift */ | |
1234 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1235 | 16, /* bitsize */ | |
b34976b6 | 1236 | FALSE, /* pc_relative */ |
252b5132 RH |
1237 | 0, /* bitpos */ |
1238 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1239 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1240 | "R_MIPS_CALL_HI16", /* name */ |
b34976b6 | 1241 | FALSE, /* partial_inplace */ |
252b5132 | 1242 | 0, /* src_mask */ |
5b6a02bc | 1243 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 1244 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1245 | |
1246 | /* Low 16 bits of displacement in global offset table. */ | |
252b5132 RH |
1247 | HOWTO (R_MIPS_CALL_LO16, /* type */ |
1248 | 0, /* rightshift */ | |
1249 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1250 | 16, /* bitsize */ | |
b34976b6 | 1251 | FALSE, /* pc_relative */ |
252b5132 RH |
1252 | 0, /* bitpos */ |
1253 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1254 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1255 | "R_MIPS_CALL_LO16", /* name */ |
b34976b6 | 1256 | FALSE, /* partial_inplace */ |
252b5132 | 1257 | 0, /* src_mask */ |
5b6a02bc | 1258 | 0x0000ffff, /* dst_mask */ |
b34976b6 | 1259 | FALSE), /* pcrel_offset */ |
252b5132 | 1260 | |
5b6a02bc | 1261 | /* Section displacement, used by an associated event location section. */ |
252b5132 RH |
1262 | HOWTO (R_MIPS_SCN_DISP, /* type */ |
1263 | 0, /* rightshift */ | |
77bfe34f TS |
1264 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
1265 | 32, /* bitsize */ | |
b34976b6 | 1266 | FALSE, /* pc_relative */ |
252b5132 RH |
1267 | 0, /* bitpos */ |
1268 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1269 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1270 | "R_MIPS_SCN_DISP", /* name */ |
b34976b6 | 1271 | FALSE, /* partial_inplace */ |
252b5132 | 1272 | 0, /* src_mask */ |
77bfe34f | 1273 | 0xffffffff, /* dst_mask */ |
b34976b6 | 1274 | FALSE), /* pcrel_offset */ |
252b5132 RH |
1275 | |
1276 | HOWTO (R_MIPS_REL16, /* type */ | |
1277 | 0, /* rightshift */ | |
77bfe34f TS |
1278 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1279 | 16, /* bitsize */ | |
b34976b6 | 1280 | FALSE, /* pc_relative */ |
252b5132 | 1281 | 0, /* bitpos */ |
77bfe34f | 1282 | complain_overflow_signed, /* complain_on_overflow */ |
30ac9238 | 1283 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1284 | "R_MIPS_REL16", /* name */ |
b34976b6 | 1285 | FALSE, /* partial_inplace */ |
252b5132 | 1286 | 0, /* src_mask */ |
77bfe34f | 1287 | 0xffff, /* dst_mask */ |
b34976b6 | 1288 | FALSE), /* pcrel_offset */ |
252b5132 | 1289 | |
77bfe34f TS |
1290 | /* These two are obsolete. */ |
1291 | EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE), | |
1292 | EMPTY_HOWTO (R_MIPS_PJUMP), | |
252b5132 | 1293 | |
5b6a02bc TS |
1294 | /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section. |
1295 | It must be used for multigot GOT's (and only there). */ | |
252b5132 RH |
1296 | HOWTO (R_MIPS_RELGOT, /* type */ |
1297 | 0, /* rightshift */ | |
77bfe34f TS |
1298 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
1299 | 32, /* bitsize */ | |
b34976b6 | 1300 | FALSE, /* pc_relative */ |
252b5132 RH |
1301 | 0, /* bitpos */ |
1302 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1303 | _bfd_mips_elf_generic_reloc, /* special_function */ |
252b5132 | 1304 | "R_MIPS_RELGOT", /* name */ |
b34976b6 | 1305 | FALSE, /* partial_inplace */ |
252b5132 | 1306 | 0, /* src_mask */ |
77bfe34f | 1307 | 0xffffffff, /* dst_mask */ |
b34976b6 | 1308 | FALSE), /* pcrel_offset */ |
d2905643 | 1309 | |
fe8bc63d | 1310 | /* Protected jump conversion. This is an optimization hint. No |
d2905643 | 1311 | relocation is required for correctness. */ |
99277196 | 1312 | HOWTO (R_MIPS_JALR, /* type */ |
d2905643 | 1313 | 0, /* rightshift */ |
77bfe34f | 1314 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
5b6a02bc | 1315 | 32, /* bitsize */ |
b34976b6 | 1316 | FALSE, /* pc_relative */ |
d2905643 MM |
1317 | 0, /* bitpos */ |
1318 | complain_overflow_dont, /* complain_on_overflow */ | |
30ac9238 | 1319 | _bfd_mips_elf_generic_reloc, /* special_function */ |
99277196 | 1320 | "R_MIPS_JALR", /* name */ |
b34976b6 | 1321 | FALSE, /* partial_inplace */ |
77bfe34f | 1322 | 0, /* src_mask */ |
5b6a02bc | 1323 | 0x00000000, /* dst_mask */ |
b34976b6 | 1324 | FALSE), /* pcrel_offset */ |
0f20cc35 DJ |
1325 | |
1326 | /* TLS relocations. */ | |
1327 | EMPTY_HOWTO (R_MIPS_TLS_DTPMOD32), | |
1328 | EMPTY_HOWTO (R_MIPS_TLS_DTPREL32), | |
1329 | EMPTY_HOWTO (R_MIPS_TLS_DTPMOD64), | |
741d6ea8 JM |
1330 | |
1331 | HOWTO (R_MIPS_TLS_DTPREL64, /* type */ | |
1332 | 0, /* rightshift */ | |
1333 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1334 | 64, /* bitsize */ | |
1335 | FALSE, /* pc_relative */ | |
1336 | 0, /* bitpos */ | |
1337 | complain_overflow_dont, /* complain_on_overflow */ | |
1338 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
1339 | "R_MIPS_TLS_DTPREL64", /* name */ | |
1340 | TRUE, /* partial_inplace */ | |
1341 | MINUS_ONE, /* src_mask */ | |
1342 | MINUS_ONE, /* dst_mask */ | |
1343 | FALSE), /* pcrel_offset */ | |
0f20cc35 DJ |
1344 | |
1345 | /* TLS general dynamic variable reference. */ | |
1346 | HOWTO (R_MIPS_TLS_GD, /* type */ | |
1347 | 0, /* rightshift */ | |
1348 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1349 | 16, /* bitsize */ | |
1350 | FALSE, /* pc_relative */ | |
1351 | 0, /* bitpos */ | |
1352 | complain_overflow_signed, /* complain_on_overflow */ | |
1353 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
1354 | "R_MIPS_TLS_GD", /* name */ | |
1355 | TRUE, /* partial_inplace */ | |
1356 | 0x0000ffff, /* src_mask */ | |
1357 | 0x0000ffff, /* dst_mask */ | |
1358 | FALSE), /* pcrel_offset */ | |
1359 | ||
1360 | /* TLS local dynamic variable reference. */ | |
1361 | HOWTO (R_MIPS_TLS_LDM, /* type */ | |
1362 | 0, /* rightshift */ | |
1363 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1364 | 16, /* bitsize */ | |
1365 | FALSE, /* pc_relative */ | |
1366 | 0, /* bitpos */ | |
1367 | complain_overflow_signed, /* complain_on_overflow */ | |
1368 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
1369 | "R_MIPS_TLS_LDM", /* name */ | |
1370 | TRUE, /* partial_inplace */ | |
1371 | 0x0000ffff, /* src_mask */ | |
1372 | 0x0000ffff, /* dst_mask */ | |
1373 | FALSE), /* pcrel_offset */ | |
1374 | ||
1375 | /* TLS local dynamic offset. */ | |
1376 | HOWTO (R_MIPS_TLS_DTPREL_HI16, /* type */ | |
1377 | 0, /* rightshift */ | |
1378 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1379 | 16, /* bitsize */ | |
1380 | FALSE, /* pc_relative */ | |
1381 | 0, /* bitpos */ | |
1382 | complain_overflow_signed, /* complain_on_overflow */ | |
1383 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
1384 | "R_MIPS_TLS_DTPREL_HI16", /* name */ | |
1385 | TRUE, /* partial_inplace */ | |
1386 | 0x0000ffff, /* src_mask */ | |
1387 | 0x0000ffff, /* dst_mask */ | |
1388 | FALSE), /* pcrel_offset */ | |
1389 | ||
1390 | /* TLS local dynamic offset. */ | |
1391 | HOWTO (R_MIPS_TLS_DTPREL_LO16, /* type */ | |
1392 | 0, /* rightshift */ | |
1393 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1394 | 16, /* bitsize */ | |
1395 | FALSE, /* pc_relative */ | |
1396 | 0, /* bitpos */ | |
1397 | complain_overflow_signed, /* complain_on_overflow */ | |
1398 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
1399 | "R_MIPS_TLS_DTPREL_LO16", /* name */ | |
1400 | TRUE, /* partial_inplace */ | |
1401 | 0x0000ffff, /* src_mask */ | |
1402 | 0x0000ffff, /* dst_mask */ | |
1403 | FALSE), /* pcrel_offset */ | |
1404 | ||
1405 | /* TLS thread pointer offset. */ | |
1406 | HOWTO (R_MIPS_TLS_GOTTPREL, /* type */ | |
1407 | 0, /* rightshift */ | |
1408 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1409 | 16, /* bitsize */ | |
1410 | FALSE, /* pc_relative */ | |
1411 | 0, /* bitpos */ | |
1412 | complain_overflow_signed, /* complain_on_overflow */ | |
1413 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
1414 | "R_MIPS_TLS_GOTTPREL", /* name */ | |
1415 | TRUE, /* partial_inplace */ | |
1416 | 0x0000ffff, /* src_mask */ | |
1417 | 0x0000ffff, /* dst_mask */ | |
1418 | FALSE), /* pcrel_offset */ | |
1419 | ||
1420 | EMPTY_HOWTO (R_MIPS_TLS_TPREL32), | |
1421 | EMPTY_HOWTO (R_MIPS_TLS_TPREL64), | |
1422 | ||
1423 | /* TLS thread pointer offset. */ | |
1424 | HOWTO (R_MIPS_TLS_TPREL_HI16, /* type */ | |
1425 | 0, /* rightshift */ | |
1426 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1427 | 16, /* bitsize */ | |
1428 | FALSE, /* pc_relative */ | |
1429 | 0, /* bitpos */ | |
1430 | complain_overflow_signed, /* complain_on_overflow */ | |
1431 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
1432 | "R_MIPS_TLS_TPREL_HI16", /* name */ | |
1433 | TRUE, /* partial_inplace */ | |
1434 | 0x0000ffff, /* src_mask */ | |
1435 | 0x0000ffff, /* dst_mask */ | |
1436 | FALSE), /* pcrel_offset */ | |
1437 | ||
1438 | /* TLS thread pointer offset. */ | |
1439 | HOWTO (R_MIPS_TLS_TPREL_LO16, /* type */ | |
1440 | 0, /* rightshift */ | |
1441 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1442 | 16, /* bitsize */ | |
1443 | FALSE, /* pc_relative */ | |
1444 | 0, /* bitpos */ | |
1445 | complain_overflow_signed, /* complain_on_overflow */ | |
1446 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
1447 | "R_MIPS_TLS_TPREL_LO16", /* name */ | |
1448 | TRUE, /* partial_inplace */ | |
1449 | 0x0000ffff, /* src_mask */ | |
1450 | 0x0000ffff, /* dst_mask */ | |
1451 | FALSE), /* pcrel_offset */ | |
165b93e7 RS |
1452 | |
1453 | /* 32 bit relocation with no addend. */ | |
1454 | HOWTO (R_MIPS_GLOB_DAT, /* type */ | |
1455 | 0, /* rightshift */ | |
1456 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1457 | 32, /* bitsize */ | |
1458 | FALSE, /* pc_relative */ | |
1459 | 0, /* bitpos */ | |
1460 | complain_overflow_dont, /* complain_on_overflow */ | |
1461 | _bfd_mips_elf_generic_reloc, /* special_function */ | |
1462 | "R_MIPS_GLOB_DAT", /* name */ | |
1463 | FALSE, /* partial_inplace */ | |
1464 | 0x0, /* src_mask */ | |
1465 | 0xffffffff, /* dst_mask */ | |
1466 | FALSE), /* pcrel_offset */ | |
252b5132 | 1467 | }; |
a4382ec6 | 1468 | |
d6f16593 MR |
1469 | static reloc_howto_type mips16_elf64_howto_table_rel[] = |
1470 | { | |
1471 | /* The reloc used for the mips16 jump instruction. */ | |
a4382ec6 TS |
1472 | HOWTO (R_MIPS16_26, /* type */ |
1473 | 2, /* rightshift */ | |
1474 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1475 | 26, /* bitsize */ | |
b34976b6 | 1476 | FALSE, /* pc_relative */ |
a4382ec6 TS |
1477 | 0, /* bitpos */ |
1478 | complain_overflow_dont, /* complain_on_overflow */ | |
1479 | /* This needs complex overflow | |
1480 | detection, because the upper four | |
1481 | bits must match the PC. */ | |
35d3d567 | 1482 | _bfd_mips_elf_generic_reloc, /* special_function */ |
a4382ec6 | 1483 | "R_MIPS16_26", /* name */ |
b34976b6 | 1484 | TRUE, /* partial_inplace */ |
a4382ec6 TS |
1485 | 0x3ffffff, /* src_mask */ |
1486 | 0x3ffffff, /* dst_mask */ | |
d6f16593 | 1487 | FALSE), /* pcrel_offset */ |
a4382ec6 | 1488 | |
d6f16593 | 1489 | /* The reloc used for the mips16 gprel instruction. */ |
a4382ec6 TS |
1490 | HOWTO (R_MIPS16_GPREL, /* type */ |
1491 | 0, /* rightshift */ | |
1492 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1493 | 16, /* bitsize */ | |
b34976b6 | 1494 | FALSE, /* pc_relative */ |
a4382ec6 TS |
1495 | 0, /* bitpos */ |
1496 | complain_overflow_signed, /* complain_on_overflow */ | |
1497 | mips16_gprel_reloc, /* special_function */ | |
1498 | "R_MIPS16_GPREL", /* name */ | |
b34976b6 | 1499 | TRUE, /* partial_inplace */ |
d6f16593 MR |
1500 | 0x0000ffff, /* src_mask */ |
1501 | 0x0000ffff, /* dst_mask */ | |
1502 | FALSE), /* pcrel_offset */ | |
1503 | ||
1504 | /* A placeholder for MIPS16 reference to global offset table. */ | |
1505 | EMPTY_HOWTO (R_MIPS16_GOT16), | |
1506 | ||
1507 | /* A placeholder for MIPS16 16 bit call through global offset table. */ | |
1508 | EMPTY_HOWTO (R_MIPS16_CALL16), | |
1509 | ||
1510 | /* MIPS16 high 16 bits of symbol value. */ | |
1511 | HOWTO (R_MIPS16_HI16, /* type */ | |
1512 | 16, /* rightshift */ | |
1513 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1514 | 16, /* bitsize */ | |
1515 | FALSE, /* pc_relative */ | |
1516 | 0, /* bitpos */ | |
1517 | complain_overflow_dont, /* complain_on_overflow */ | |
1518 | _bfd_mips_elf_hi16_reloc, /* special_function */ | |
1519 | "R_MIPS16_HI16", /* name */ | |
1520 | TRUE, /* partial_inplace */ | |
1521 | 0x0000ffff, /* src_mask */ | |
1522 | 0x0000ffff, /* dst_mask */ | |
1523 | FALSE), /* pcrel_offset */ | |
1524 | ||
1525 | /* MIPS16 low 16 bits of symbol value. */ | |
1526 | HOWTO (R_MIPS16_LO16, /* type */ | |
1527 | 0, /* rightshift */ | |
1528 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1529 | 16, /* bitsize */ | |
1530 | FALSE, /* pc_relative */ | |
1531 | 0, /* bitpos */ | |
1532 | complain_overflow_dont, /* complain_on_overflow */ | |
1533 | _bfd_mips_elf_lo16_reloc, /* special_function */ | |
1534 | "R_MIPS16_LO16", /* name */ | |
1535 | TRUE, /* partial_inplace */ | |
1536 | 0x0000ffff, /* src_mask */ | |
1537 | 0x0000ffff, /* dst_mask */ | |
1538 | FALSE), /* pcrel_offset */ | |
1539 | }; | |
1540 | ||
1541 | static reloc_howto_type mips16_elf64_howto_table_rela[] = | |
1542 | { | |
1543 | /* The reloc used for the mips16 jump instruction. */ | |
1544 | HOWTO (R_MIPS16_26, /* type */ | |
1545 | 2, /* rightshift */ | |
1546 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1547 | 26, /* bitsize */ | |
1548 | FALSE, /* pc_relative */ | |
1549 | 0, /* bitpos */ | |
1550 | complain_overflow_dont, /* complain_on_overflow */ | |
1551 | /* This needs complex overflow | |
1552 | detection, because the upper four | |
1553 | bits must match the PC. */ | |
35d3d567 | 1554 | _bfd_mips_elf_generic_reloc, /* special_function */ |
d6f16593 MR |
1555 | "R_MIPS16_26", /* name */ |
1556 | FALSE, /* partial_inplace */ | |
1557 | 0x3ffffff, /* src_mask */ | |
1558 | 0x3ffffff, /* dst_mask */ | |
1559 | FALSE), /* pcrel_offset */ | |
1560 | ||
1561 | /* The reloc used for the mips16 gprel instruction. */ | |
1562 | HOWTO (R_MIPS16_GPREL, /* type */ | |
1563 | 0, /* rightshift */ | |
1564 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1565 | 16, /* bitsize */ | |
1566 | FALSE, /* pc_relative */ | |
1567 | 0, /* bitpos */ | |
1568 | complain_overflow_signed, /* complain_on_overflow */ | |
1569 | mips16_gprel_reloc, /* special_function */ | |
1570 | "R_MIPS16_GPREL", /* name */ | |
1571 | FALSE, /* partial_inplace */ | |
1572 | 0x0000ffff, /* src_mask */ | |
1573 | 0x0000ffff, /* dst_mask */ | |
1574 | FALSE), /* pcrel_offset */ | |
1575 | ||
1576 | /* A placeholder for MIPS16 reference to global offset table. */ | |
1577 | EMPTY_HOWTO (R_MIPS16_GOT16), | |
1578 | ||
1579 | /* A placeholder for MIPS16 16 bit call through global offset table. */ | |
1580 | EMPTY_HOWTO (R_MIPS16_CALL16), | |
1581 | ||
1582 | /* MIPS16 high 16 bits of symbol value. */ | |
1583 | HOWTO (R_MIPS16_HI16, /* type */ | |
1584 | 16, /* rightshift */ | |
1585 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1586 | 16, /* bitsize */ | |
1587 | FALSE, /* pc_relative */ | |
1588 | 0, /* bitpos */ | |
1589 | complain_overflow_dont, /* complain_on_overflow */ | |
1590 | _bfd_mips_elf_hi16_reloc, /* special_function */ | |
1591 | "R_MIPS16_HI16", /* name */ | |
1592 | FALSE, /* partial_inplace */ | |
1593 | 0x0000ffff, /* src_mask */ | |
1594 | 0x0000ffff, /* dst_mask */ | |
1595 | FALSE), /* pcrel_offset */ | |
1596 | ||
1597 | /* MIPS16 low 16 bits of symbol value. */ | |
1598 | HOWTO (R_MIPS16_LO16, /* type */ | |
1599 | 0, /* rightshift */ | |
1600 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1601 | 16, /* bitsize */ | |
1602 | FALSE, /* pc_relative */ | |
1603 | 0, /* bitpos */ | |
1604 | complain_overflow_dont, /* complain_on_overflow */ | |
1605 | _bfd_mips_elf_lo16_reloc, /* special_function */ | |
1606 | "R_MIPS16_LO16", /* name */ | |
1607 | FALSE, /* partial_inplace */ | |
1608 | 0x0000ffff, /* src_mask */ | |
1609 | 0x0000ffff, /* dst_mask */ | |
1610 | FALSE), /* pcrel_offset */ | |
1611 | }; | |
a4382ec6 TS |
1612 | |
1613 | /* GNU extension to record C++ vtable hierarchy */ | |
1614 | static reloc_howto_type elf_mips_gnu_vtinherit_howto = | |
1615 | HOWTO (R_MIPS_GNU_VTINHERIT, /* type */ | |
1616 | 0, /* rightshift */ | |
1617 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1618 | 0, /* bitsize */ | |
b34976b6 | 1619 | FALSE, /* pc_relative */ |
a4382ec6 TS |
1620 | 0, /* bitpos */ |
1621 | complain_overflow_dont, /* complain_on_overflow */ | |
1622 | NULL, /* special_function */ | |
1623 | "R_MIPS_GNU_VTINHERIT", /* name */ | |
b34976b6 | 1624 | FALSE, /* partial_inplace */ |
a4382ec6 TS |
1625 | 0, /* src_mask */ |
1626 | 0, /* dst_mask */ | |
b34976b6 | 1627 | FALSE); /* pcrel_offset */ |
a4382ec6 TS |
1628 | |
1629 | /* GNU extension to record C++ vtable member usage */ | |
1630 | static reloc_howto_type elf_mips_gnu_vtentry_howto = | |
1631 | HOWTO (R_MIPS_GNU_VTENTRY, /* type */ | |
1632 | 0, /* rightshift */ | |
1633 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1634 | 0, /* bitsize */ | |
b34976b6 | 1635 | FALSE, /* pc_relative */ |
a4382ec6 TS |
1636 | 0, /* bitpos */ |
1637 | complain_overflow_dont, /* complain_on_overflow */ | |
1638 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
1639 | "R_MIPS_GNU_VTENTRY", /* name */ | |
b34976b6 | 1640 | FALSE, /* partial_inplace */ |
a4382ec6 TS |
1641 | 0, /* src_mask */ |
1642 | 0, /* dst_mask */ | |
b34976b6 | 1643 | FALSE); /* pcrel_offset */ |
c6e90b02 | 1644 | \f |
d0c728db TS |
1645 | /* 16 bit offset for pc-relative branches. */ |
1646 | static reloc_howto_type elf_mips_gnu_rel16_s2 = | |
1647 | HOWTO (R_MIPS_GNU_REL16_S2, /* type */ | |
1648 | 2, /* rightshift */ | |
1649 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1650 | 16, /* bitsize */ | |
1651 | TRUE, /* pc_relative */ | |
1652 | 0, /* bitpos */ | |
1653 | complain_overflow_signed, /* complain_on_overflow */ | |
30ac9238 | 1654 | _bfd_mips_elf_generic_reloc, /* special_function */ |
d0c728db TS |
1655 | "R_MIPS_GNU_REL16_S2", /* name */ |
1656 | TRUE, /* partial_inplace */ | |
1657 | 0x0000ffff, /* src_mask */ | |
1658 | 0x0000ffff, /* dst_mask */ | |
1659 | TRUE); /* pcrel_offset */ | |
1660 | ||
1661 | /* 16 bit offset for pc-relative branches. */ | |
1662 | static reloc_howto_type elf_mips_gnu_rela16_s2 = | |
1663 | HOWTO (R_MIPS_GNU_REL16_S2, /* type */ | |
1664 | 2, /* rightshift */ | |
1665 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1666 | 16, /* bitsize */ | |
1667 | TRUE, /* pc_relative */ | |
1668 | 0, /* bitpos */ | |
1669 | complain_overflow_signed, /* complain_on_overflow */ | |
30ac9238 | 1670 | _bfd_mips_elf_generic_reloc, /* special_function */ |
d0c728db TS |
1671 | "R_MIPS_GNU_REL16_S2", /* name */ |
1672 | FALSE, /* partial_inplace */ | |
1673 | 0, /* src_mask */ | |
1674 | 0x0000ffff, /* dst_mask */ | |
1675 | TRUE); /* pcrel_offset */ | |
1676 | \f | |
252b5132 RH |
1677 | /* Swap in a MIPS 64-bit Rel reloc. */ |
1678 | ||
1679 | static void | |
11a2be4d RS |
1680 | mips_elf64_swap_reloc_in (bfd *abfd, const Elf64_Mips_External_Rel *src, |
1681 | Elf64_Mips_Internal_Rela *dst) | |
252b5132 | 1682 | { |
dc810e39 AM |
1683 | dst->r_offset = H_GET_64 (abfd, src->r_offset); |
1684 | dst->r_sym = H_GET_32 (abfd, src->r_sym); | |
1685 | dst->r_ssym = H_GET_8 (abfd, src->r_ssym); | |
1686 | dst->r_type3 = H_GET_8 (abfd, src->r_type3); | |
1687 | dst->r_type2 = H_GET_8 (abfd, src->r_type2); | |
1688 | dst->r_type = H_GET_8 (abfd, src->r_type); | |
947216bf | 1689 | dst->r_addend = 0; |
252b5132 RH |
1690 | } |
1691 | ||
1692 | /* Swap in a MIPS 64-bit Rela reloc. */ | |
1693 | ||
1694 | static void | |
11a2be4d RS |
1695 | mips_elf64_swap_reloca_in (bfd *abfd, const Elf64_Mips_External_Rela *src, |
1696 | Elf64_Mips_Internal_Rela *dst) | |
252b5132 | 1697 | { |
dc810e39 AM |
1698 | dst->r_offset = H_GET_64 (abfd, src->r_offset); |
1699 | dst->r_sym = H_GET_32 (abfd, src->r_sym); | |
1700 | dst->r_ssym = H_GET_8 (abfd, src->r_ssym); | |
1701 | dst->r_type3 = H_GET_8 (abfd, src->r_type3); | |
1702 | dst->r_type2 = H_GET_8 (abfd, src->r_type2); | |
1703 | dst->r_type = H_GET_8 (abfd, src->r_type); | |
1704 | dst->r_addend = H_GET_S64 (abfd, src->r_addend); | |
252b5132 RH |
1705 | } |
1706 | ||
252b5132 RH |
1707 | /* Swap out a MIPS 64-bit Rel reloc. */ |
1708 | ||
1709 | static void | |
11a2be4d RS |
1710 | mips_elf64_swap_reloc_out (bfd *abfd, const Elf64_Mips_Internal_Rela *src, |
1711 | Elf64_Mips_External_Rel *dst) | |
252b5132 | 1712 | { |
dc810e39 AM |
1713 | H_PUT_64 (abfd, src->r_offset, dst->r_offset); |
1714 | H_PUT_32 (abfd, src->r_sym, dst->r_sym); | |
1715 | H_PUT_8 (abfd, src->r_ssym, dst->r_ssym); | |
1716 | H_PUT_8 (abfd, src->r_type3, dst->r_type3); | |
1717 | H_PUT_8 (abfd, src->r_type2, dst->r_type2); | |
1718 | H_PUT_8 (abfd, src->r_type, dst->r_type); | |
252b5132 RH |
1719 | } |
1720 | ||
252b5132 RH |
1721 | /* Swap out a MIPS 64-bit Rela reloc. */ |
1722 | ||
1723 | static void | |
11a2be4d RS |
1724 | mips_elf64_swap_reloca_out (bfd *abfd, const Elf64_Mips_Internal_Rela *src, |
1725 | Elf64_Mips_External_Rela *dst) | |
252b5132 | 1726 | { |
dc810e39 AM |
1727 | H_PUT_64 (abfd, src->r_offset, dst->r_offset); |
1728 | H_PUT_32 (abfd, src->r_sym, dst->r_sym); | |
1729 | H_PUT_8 (abfd, src->r_ssym, dst->r_ssym); | |
1730 | H_PUT_8 (abfd, src->r_type3, dst->r_type3); | |
1731 | H_PUT_8 (abfd, src->r_type2, dst->r_type2); | |
1732 | H_PUT_8 (abfd, src->r_type, dst->r_type); | |
5b6a02bc | 1733 | H_PUT_S64 (abfd, src->r_addend, dst->r_addend); |
252b5132 RH |
1734 | } |
1735 | ||
c7ac6ff8 MM |
1736 | /* Swap in a MIPS 64-bit Rel reloc. */ |
1737 | ||
1738 | static void | |
11a2be4d RS |
1739 | mips_elf64_be_swap_reloc_in (bfd *abfd, const bfd_byte *src, |
1740 | Elf_Internal_Rela *dst) | |
c7ac6ff8 | 1741 | { |
947216bf | 1742 | Elf64_Mips_Internal_Rela mirel; |
c7ac6ff8 | 1743 | |
fe8bc63d | 1744 | mips_elf64_swap_reloc_in (abfd, |
c7ac6ff8 MM |
1745 | (const Elf64_Mips_External_Rel *) src, |
1746 | &mirel); | |
1747 | ||
1748 | dst[0].r_offset = mirel.r_offset; | |
5b6a02bc | 1749 | dst[0].r_info = ELF64_R_INFO (mirel.r_sym, mirel.r_type); |
947216bf | 1750 | dst[0].r_addend = 0; |
c7ac6ff8 | 1751 | dst[1].r_offset = mirel.r_offset; |
5b6a02bc | 1752 | dst[1].r_info = ELF64_R_INFO (mirel.r_ssym, mirel.r_type2); |
947216bf | 1753 | dst[1].r_addend = 0; |
c7ac6ff8 | 1754 | dst[2].r_offset = mirel.r_offset; |
5b6a02bc | 1755 | dst[2].r_info = ELF64_R_INFO (STN_UNDEF, mirel.r_type3); |
947216bf | 1756 | dst[2].r_addend = 0; |
c7ac6ff8 MM |
1757 | } |
1758 | ||
1759 | /* Swap in a MIPS 64-bit Rela reloc. */ | |
1760 | ||
1761 | static void | |
11a2be4d RS |
1762 | mips_elf64_be_swap_reloca_in (bfd *abfd, const bfd_byte *src, |
1763 | Elf_Internal_Rela *dst) | |
c7ac6ff8 MM |
1764 | { |
1765 | Elf64_Mips_Internal_Rela mirela; | |
1766 | ||
fe8bc63d | 1767 | mips_elf64_swap_reloca_in (abfd, |
c7ac6ff8 MM |
1768 | (const Elf64_Mips_External_Rela *) src, |
1769 | &mirela); | |
1770 | ||
1771 | dst[0].r_offset = mirela.r_offset; | |
5b6a02bc | 1772 | dst[0].r_info = ELF64_R_INFO (mirela.r_sym, mirela.r_type); |
c7ac6ff8 MM |
1773 | dst[0].r_addend = mirela.r_addend; |
1774 | dst[1].r_offset = mirela.r_offset; | |
5b6a02bc | 1775 | dst[1].r_info = ELF64_R_INFO (mirela.r_ssym, mirela.r_type2); |
c7ac6ff8 MM |
1776 | dst[1].r_addend = 0; |
1777 | dst[2].r_offset = mirela.r_offset; | |
5b6a02bc | 1778 | dst[2].r_info = ELF64_R_INFO (STN_UNDEF, mirela.r_type3); |
c7ac6ff8 MM |
1779 | dst[2].r_addend = 0; |
1780 | } | |
1781 | ||
1782 | /* Swap out a MIPS 64-bit Rel reloc. */ | |
1783 | ||
1784 | static void | |
11a2be4d RS |
1785 | mips_elf64_be_swap_reloc_out (bfd *abfd, const Elf_Internal_Rela *src, |
1786 | bfd_byte *dst) | |
c7ac6ff8 | 1787 | { |
947216bf | 1788 | Elf64_Mips_Internal_Rela mirel; |
c7ac6ff8 | 1789 | |
5b6a02bc TS |
1790 | mirel.r_offset = src[0].r_offset; |
1791 | BFD_ASSERT(src[0].r_offset == src[1].r_offset); | |
5b6a02bc TS |
1792 | |
1793 | mirel.r_type = ELF64_MIPS_R_TYPE (src[0].r_info); | |
1794 | mirel.r_sym = ELF64_R_SYM (src[0].r_info); | |
a902ee94 | 1795 | mirel.r_type2 = ELF64_MIPS_R_TYPE (src[1].r_info); |
5b6a02bc | 1796 | mirel.r_ssym = ELF64_MIPS_R_SSYM (src[1].r_info); |
a902ee94 | 1797 | mirel.r_type3 = ELF64_MIPS_R_TYPE (src[2].r_info); |
c7ac6ff8 | 1798 | |
fe8bc63d | 1799 | mips_elf64_swap_reloc_out (abfd, &mirel, |
c7ac6ff8 MM |
1800 | (Elf64_Mips_External_Rel *) dst); |
1801 | } | |
1802 | ||
1803 | /* Swap out a MIPS 64-bit Rela reloc. */ | |
1804 | ||
1805 | static void | |
11a2be4d RS |
1806 | mips_elf64_be_swap_reloca_out (bfd *abfd, const Elf_Internal_Rela *src, |
1807 | bfd_byte *dst) | |
c7ac6ff8 MM |
1808 | { |
1809 | Elf64_Mips_Internal_Rela mirela; | |
1810 | ||
5b6a02bc TS |
1811 | mirela.r_offset = src[0].r_offset; |
1812 | BFD_ASSERT(src[0].r_offset == src[1].r_offset); | |
1813 | BFD_ASSERT(src[0].r_offset == src[2].r_offset); | |
1814 | ||
1815 | mirela.r_type = ELF64_MIPS_R_TYPE (src[0].r_info); | |
1816 | mirela.r_sym = ELF64_R_SYM (src[0].r_info); | |
1817 | mirela.r_addend = src[0].r_addend; | |
1818 | BFD_ASSERT(src[1].r_addend == 0); | |
1819 | BFD_ASSERT(src[2].r_addend == 0); | |
1820 | ||
47293a4c | 1821 | mirela.r_type2 = ELF64_MIPS_R_TYPE (src[1].r_info); |
5b6a02bc | 1822 | mirela.r_ssym = ELF64_MIPS_R_SSYM (src[1].r_info); |
47293a4c | 1823 | mirela.r_type3 = ELF64_MIPS_R_TYPE (src[2].r_info); |
c7ac6ff8 | 1824 | |
fe8bc63d | 1825 | mips_elf64_swap_reloca_out (abfd, &mirela, |
c7ac6ff8 MM |
1826 | (Elf64_Mips_External_Rela *) dst); |
1827 | } | |
c6e90b02 | 1828 | \f |
b34976b6 | 1829 | /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a |
5b6a02bc | 1830 | dangerous relocation. */ |
252b5132 | 1831 | |
b34976b6 | 1832 | static bfd_boolean |
11a2be4d | 1833 | mips_elf64_assign_gp (bfd *output_bfd, bfd_vma *pgp) |
252b5132 | 1834 | { |
252b5132 | 1835 | unsigned int count; |
5b6a02bc | 1836 | asymbol **sym; |
252b5132 | 1837 | unsigned int i; |
252b5132 | 1838 | |
5b6a02bc TS |
1839 | /* If we've already figured out what GP will be, just return it. */ |
1840 | *pgp = _bfd_get_gp_value (output_bfd); | |
1841 | if (*pgp) | |
b34976b6 | 1842 | return TRUE; |
252b5132 | 1843 | |
5b6a02bc TS |
1844 | count = bfd_get_symcount (output_bfd); |
1845 | sym = bfd_get_outsymbols (output_bfd); | |
252b5132 | 1846 | |
5b6a02bc TS |
1847 | /* The linker script will have created a symbol named `_gp' with the |
1848 | appropriate value. */ | |
11a2be4d | 1849 | if (sym == NULL) |
5b6a02bc TS |
1850 | i = count; |
1851 | else | |
1852 | { | |
1853 | for (i = 0; i < count; i++, sym++) | |
1854 | { | |
3f9c735e | 1855 | register const char *name; |
252b5132 | 1856 | |
5b6a02bc TS |
1857 | name = bfd_asymbol_name (*sym); |
1858 | if (*name == '_' && strcmp (name, "_gp") == 0) | |
1859 | { | |
1860 | *pgp = bfd_asymbol_value (*sym); | |
1861 | _bfd_set_gp_value (output_bfd, *pgp); | |
1862 | break; | |
1863 | } | |
1864 | } | |
1865 | } | |
252b5132 | 1866 | |
5b6a02bc TS |
1867 | if (i >= count) |
1868 | { | |
1869 | /* Only get the error once. */ | |
1870 | *pgp = 4; | |
1871 | _bfd_set_gp_value (output_bfd, *pgp); | |
b34976b6 | 1872 | return FALSE; |
5b6a02bc | 1873 | } |
252b5132 | 1874 | |
b34976b6 | 1875 | return TRUE; |
5b6a02bc | 1876 | } |
252b5132 | 1877 | |
5b6a02bc TS |
1878 | /* We have to figure out the gp value, so that we can adjust the |
1879 | symbol value correctly. We look up the symbol _gp in the output | |
1880 | BFD. If we can't find it, we're stuck. We cache it in the ELF | |
1881 | target data. We don't need to adjust the symbol value for an | |
1049f94e | 1882 | external symbol if we are producing relocatable output. */ |
5b6a02bc TS |
1883 | |
1884 | static bfd_reloc_status_type | |
11a2be4d RS |
1885 | mips_elf64_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable, |
1886 | char **error_message, bfd_vma *pgp) | |
5b6a02bc TS |
1887 | { |
1888 | if (bfd_is_und_section (symbol->section) | |
1049f94e | 1889 | && ! relocatable) |
252b5132 | 1890 | { |
5b6a02bc TS |
1891 | *pgp = 0; |
1892 | return bfd_reloc_undefined; | |
1893 | } | |
252b5132 | 1894 | |
5b6a02bc TS |
1895 | *pgp = _bfd_get_gp_value (output_bfd); |
1896 | if (*pgp == 0 | |
1049f94e | 1897 | && (! relocatable |
5b6a02bc TS |
1898 | || (symbol->flags & BSF_SECTION_SYM) != 0)) |
1899 | { | |
1049f94e | 1900 | if (relocatable) |
252b5132 | 1901 | { |
5b6a02bc | 1902 | /* Make up a value. */ |
a902ee94 | 1903 | *pgp = symbol->section->output_section->vma /*+ 0x4000*/; |
5b6a02bc TS |
1904 | _bfd_set_gp_value (output_bfd, *pgp); |
1905 | } | |
1906 | else if (!mips_elf64_assign_gp (output_bfd, pgp)) | |
1907 | { | |
1908 | *error_message = | |
1909 | (char *) _("GP relative relocation when _gp not defined"); | |
1910 | return bfd_reloc_dangerous; | |
252b5132 | 1911 | } |
5b6a02bc | 1912 | } |
252b5132 | 1913 | |
5b6a02bc TS |
1914 | return bfd_reloc_ok; |
1915 | } | |
252b5132 | 1916 | |
5b6a02bc TS |
1917 | /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must |
1918 | become the offset from the gp register. */ | |
252b5132 | 1919 | |
a4382ec6 | 1920 | static bfd_reloc_status_type |
11a2be4d RS |
1921 | mips_elf64_gprel16_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
1922 | void *data, asection *input_section, bfd *output_bfd, | |
1923 | char **error_message) | |
5b6a02bc | 1924 | { |
1049f94e | 1925 | bfd_boolean relocatable; |
5b6a02bc TS |
1926 | bfd_reloc_status_type ret; |
1927 | bfd_vma gp; | |
1928 | ||
a7ebbfdf TS |
1929 | /* If we're relocating, and this is an external symbol, we don't want |
1930 | to change anything. */ | |
11a2be4d | 1931 | if (output_bfd != NULL |
5b6a02bc | 1932 | && (symbol->flags & BSF_SECTION_SYM) == 0 |
a7ebbfdf | 1933 | && (symbol->flags & BSF_LOCAL) != 0) |
5b6a02bc TS |
1934 | { |
1935 | reloc_entry->address += input_section->output_offset; | |
1936 | return bfd_reloc_ok; | |
1937 | } | |
1938 | ||
11a2be4d | 1939 | if (output_bfd != NULL) |
1049f94e | 1940 | relocatable = TRUE; |
5b6a02bc TS |
1941 | else |
1942 | { | |
1049f94e | 1943 | relocatable = FALSE; |
5b6a02bc TS |
1944 | output_bfd = symbol->section->output_section->owner; |
1945 | } | |
1946 | ||
1049f94e | 1947 | ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message, |
5b6a02bc TS |
1948 | &gp); |
1949 | if (ret != bfd_reloc_ok) | |
1950 | return ret; | |
1951 | ||
c6e90b02 | 1952 | return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry, |
1049f94e | 1953 | input_section, relocatable, |
c6e90b02 | 1954 | data, gp); |
5b6a02bc TS |
1955 | } |
1956 | ||
a4382ec6 | 1957 | /* Do a R_MIPS_LITERAL relocation. */ |
5b6a02bc | 1958 | |
a4382ec6 | 1959 | static bfd_reloc_status_type |
11a2be4d RS |
1960 | mips_elf64_literal_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
1961 | void *data, asection *input_section, bfd *output_bfd, | |
1962 | char **error_message) | |
5b6a02bc | 1963 | { |
1049f94e | 1964 | bfd_boolean relocatable; |
a4382ec6 | 1965 | bfd_reloc_status_type ret; |
5b6a02bc TS |
1966 | bfd_vma gp; |
1967 | ||
254f0426 | 1968 | /* R_MIPS_LITERAL relocations are defined for local symbols only. */ |
11a2be4d | 1969 | if (output_bfd != NULL |
5b6a02bc | 1970 | && (symbol->flags & BSF_SECTION_SYM) == 0 |
a7ebbfdf | 1971 | && (symbol->flags & BSF_LOCAL) != 0) |
5b6a02bc | 1972 | { |
254f0426 MR |
1973 | *error_message = (char *) |
1974 | _("literal relocation occurs for an external symbol"); | |
1975 | return bfd_reloc_outofrange; | |
5b6a02bc TS |
1976 | } |
1977 | ||
a4382ec6 | 1978 | /* FIXME: The entries in the .lit8 and .lit4 sections should be merged. */ |
11a2be4d | 1979 | if (output_bfd != NULL) |
1049f94e | 1980 | relocatable = TRUE; |
5b6a02bc TS |
1981 | else |
1982 | { | |
1049f94e | 1983 | relocatable = FALSE; |
5b6a02bc TS |
1984 | output_bfd = symbol->section->output_section->owner; |
1985 | } | |
1986 | ||
1049f94e | 1987 | ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message, |
a4382ec6 TS |
1988 | &gp); |
1989 | if (ret != bfd_reloc_ok) | |
1990 | return ret; | |
5b6a02bc | 1991 | |
a4382ec6 | 1992 | return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry, |
1049f94e | 1993 | input_section, relocatable, |
a4382ec6 | 1994 | data, gp); |
5b6a02bc TS |
1995 | } |
1996 | ||
a4382ec6 TS |
1997 | /* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must |
1998 | become the offset from the gp register. */ | |
5b6a02bc | 1999 | |
a4382ec6 | 2000 | static bfd_reloc_status_type |
11a2be4d RS |
2001 | mips_elf64_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2002 | void *data, asection *input_section, bfd *output_bfd, | |
2003 | char **error_message) | |
5b6a02bc | 2004 | { |
1049f94e | 2005 | bfd_boolean relocatable; |
5b6a02bc TS |
2006 | bfd_reloc_status_type ret; |
2007 | bfd_vma gp; | |
2008 | bfd_vma relocation; | |
a7ebbfdf | 2009 | bfd_vma val; |
5b6a02bc | 2010 | |
765f2ef6 | 2011 | /* R_MIPS_GPREL32 relocations are defined for local symbols only. */ |
11a2be4d | 2012 | if (output_bfd != NULL |
5b6a02bc | 2013 | && (symbol->flags & BSF_SECTION_SYM) == 0 |
a7ebbfdf | 2014 | && (symbol->flags & BSF_LOCAL) != 0) |
5b6a02bc TS |
2015 | { |
2016 | *error_message = (char *) | |
2017 | _("32bits gp relative relocation occurs for an external symbol"); | |
2018 | return bfd_reloc_outofrange; | |
2019 | } | |
2020 | ||
11a2be4d | 2021 | if (output_bfd != NULL) |
1049f94e | 2022 | relocatable = TRUE; |
5b6a02bc TS |
2023 | else |
2024 | { | |
1049f94e | 2025 | relocatable = FALSE; |
5b6a02bc | 2026 | output_bfd = symbol->section->output_section->owner; |
5b6a02bc TS |
2027 | } |
2028 | ||
99277196 MR |
2029 | ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, |
2030 | error_message, &gp); | |
2031 | if (ret != bfd_reloc_ok) | |
2032 | return ret; | |
a7ebbfdf | 2033 | |
5b6a02bc TS |
2034 | if (bfd_is_com_section (symbol->section)) |
2035 | relocation = 0; | |
2036 | else | |
2037 | relocation = symbol->value; | |
2038 | ||
2039 | relocation += symbol->section->output_section->vma; | |
2040 | relocation += symbol->section->output_offset; | |
2041 | ||
07515404 | 2042 | if (reloc_entry->address > bfd_get_section_limit (abfd, input_section)) |
5b6a02bc TS |
2043 | return bfd_reloc_outofrange; |
2044 | ||
5b6a02bc | 2045 | /* Set val to the offset into the section or symbol. */ |
a7ebbfdf TS |
2046 | val = reloc_entry->addend; |
2047 | ||
2048 | if (reloc_entry->howto->partial_inplace) | |
2049 | val += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address); | |
5b6a02bc TS |
2050 | |
2051 | /* Adjust val for the final section location and GP value. If we | |
1049f94e | 2052 | are producing relocatable output, we don't want to do this for |
5b6a02bc | 2053 | an external symbol. */ |
1049f94e | 2054 | if (! relocatable |
5b6a02bc TS |
2055 | || (symbol->flags & BSF_SECTION_SYM) != 0) |
2056 | val += relocation - gp; | |
2057 | ||
a7ebbfdf TS |
2058 | if (reloc_entry->howto->partial_inplace) |
2059 | bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address); | |
2060 | else | |
2061 | reloc_entry->addend = val; | |
5b6a02bc | 2062 | |
1049f94e | 2063 | if (relocatable) |
5b6a02bc TS |
2064 | reloc_entry->address += input_section->output_offset; |
2065 | ||
2066 | return bfd_reloc_ok; | |
2067 | } | |
2068 | ||
2069 | /* Do a R_MIPS_SHIFT6 relocation. The MSB of the shift is stored at bit 2, | |
a4382ec6 | 2070 | the rest is at bits 6-10. The bitpos already got right by the howto. */ |
5b6a02bc | 2071 | |
a4382ec6 | 2072 | static bfd_reloc_status_type |
30ac9238 RS |
2073 | mips_elf64_shift6_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2074 | void *data, asection *input_section, bfd *output_bfd, | |
2075 | char **error_message) | |
5b6a02bc | 2076 | { |
a7ebbfdf TS |
2077 | if (reloc_entry->howto->partial_inplace) |
2078 | { | |
2079 | reloc_entry->addend = ((reloc_entry->addend & 0x00007c0) | |
2080 | | (reloc_entry->addend & 0x00000800) >> 9); | |
2081 | } | |
5b6a02bc | 2082 | |
30ac9238 RS |
2083 | return _bfd_mips_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
2084 | input_section, output_bfd, | |
2085 | error_message); | |
5b6a02bc TS |
2086 | } |
2087 | ||
a4382ec6 TS |
2088 | /* Handle a mips16 GP relative reloc. */ |
2089 | ||
2090 | static bfd_reloc_status_type | |
11a2be4d RS |
2091 | mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
2092 | void *data, asection *input_section, bfd *output_bfd, | |
2093 | char **error_message) | |
a4382ec6 | 2094 | { |
1049f94e | 2095 | bfd_boolean relocatable; |
a4382ec6 | 2096 | bfd_reloc_status_type ret; |
d6f16593 | 2097 | bfd_byte *location; |
a4382ec6 | 2098 | bfd_vma gp; |
a4382ec6 | 2099 | |
7f05722e MR |
2100 | /* If we're relocating, and this is an external symbol, we don't want |
2101 | to change anything. */ | |
a4382ec6 TS |
2102 | if (output_bfd != NULL |
2103 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
a7ebbfdf | 2104 | && (symbol->flags & BSF_LOCAL) != 0) |
a4382ec6 TS |
2105 | { |
2106 | reloc_entry->address += input_section->output_offset; | |
2107 | return bfd_reloc_ok; | |
2108 | } | |
2109 | ||
2110 | if (output_bfd != NULL) | |
1049f94e | 2111 | relocatable = TRUE; |
a4382ec6 TS |
2112 | else |
2113 | { | |
1049f94e | 2114 | relocatable = FALSE; |
a4382ec6 TS |
2115 | output_bfd = symbol->section->output_section->owner; |
2116 | } | |
2117 | ||
1049f94e | 2118 | ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message, |
a4382ec6 TS |
2119 | &gp); |
2120 | if (ret != bfd_reloc_ok) | |
2121 | return ret; | |
2122 | ||
d6f16593 MR |
2123 | location = (bfd_byte *) data + reloc_entry->address; |
2124 | _bfd_mips16_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE, | |
2125 | location); | |
2126 | ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry, | |
2127 | input_section, relocatable, | |
2128 | data, gp); | |
2129 | _bfd_mips16_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable, | |
2130 | location); | |
a7ebbfdf | 2131 | |
d6f16593 | 2132 | return ret; |
a4382ec6 TS |
2133 | } |
2134 | \f | |
2135 | /* A mapping from BFD reloc types to MIPS ELF reloc types. */ | |
2136 | ||
2137 | struct elf_reloc_map { | |
2138 | bfd_reloc_code_real_type bfd_val; | |
2139 | enum elf_mips_reloc_type elf_val; | |
2140 | }; | |
2141 | ||
2142 | static const struct elf_reloc_map mips_reloc_map[] = | |
2143 | { | |
2144 | { BFD_RELOC_NONE, R_MIPS_NONE }, | |
2145 | { BFD_RELOC_16, R_MIPS_16 }, | |
2146 | { BFD_RELOC_32, R_MIPS_32 }, | |
2147 | /* There is no BFD reloc for R_MIPS_REL32. */ | |
2148 | { BFD_RELOC_64, R_MIPS_64 }, | |
2149 | { BFD_RELOC_CTOR, R_MIPS_64 }, | |
bad36eac | 2150 | { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 }, |
a4382ec6 TS |
2151 | { BFD_RELOC_HI16_S, R_MIPS_HI16 }, |
2152 | { BFD_RELOC_LO16, R_MIPS_LO16 }, | |
2153 | { BFD_RELOC_GPREL16, R_MIPS_GPREL16 }, | |
2154 | { BFD_RELOC_GPREL32, R_MIPS_GPREL32 }, | |
2155 | { BFD_RELOC_MIPS_JMP, R_MIPS_26 }, | |
2156 | { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL }, | |
2157 | { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 }, | |
2158 | { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 }, | |
2159 | { BFD_RELOC_MIPS_SHIFT5, R_MIPS_SHIFT5 }, | |
2160 | { BFD_RELOC_MIPS_SHIFT6, R_MIPS_SHIFT6 }, | |
2161 | { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP }, | |
2162 | { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE }, | |
2163 | { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST }, | |
2164 | { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 }, | |
2165 | { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 }, | |
2166 | { BFD_RELOC_MIPS_SUB, R_MIPS_SUB }, | |
2167 | { BFD_RELOC_MIPS_INSERT_A, R_MIPS_INSERT_A }, | |
2168 | { BFD_RELOC_MIPS_INSERT_B, R_MIPS_INSERT_B }, | |
2169 | { BFD_RELOC_MIPS_DELETE, R_MIPS_DELETE }, | |
2170 | { BFD_RELOC_MIPS_HIGHEST, R_MIPS_HIGHEST }, | |
2171 | { BFD_RELOC_MIPS_HIGHER, R_MIPS_HIGHER }, | |
2172 | { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 }, | |
2173 | { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 }, | |
2174 | { BFD_RELOC_MIPS_SCN_DISP, R_MIPS_SCN_DISP }, | |
2175 | { BFD_RELOC_MIPS_REL16, R_MIPS_REL16 }, | |
2176 | /* Use of R_MIPS_ADD_IMMEDIATE and R_MIPS_PJUMP is deprecated. */ | |
2177 | { BFD_RELOC_MIPS_RELGOT, R_MIPS_RELGOT }, | |
0f20cc35 DJ |
2178 | { BFD_RELOC_MIPS_JALR, R_MIPS_JALR }, |
2179 | { BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 }, | |
2180 | { BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 }, | |
2181 | { BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 }, | |
2182 | { BFD_RELOC_MIPS_TLS_DTPREL64, R_MIPS_TLS_DTPREL64 }, | |
2183 | { BFD_RELOC_MIPS_TLS_GD, R_MIPS_TLS_GD }, | |
2184 | { BFD_RELOC_MIPS_TLS_LDM, R_MIPS_TLS_LDM }, | |
2185 | { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_MIPS_TLS_DTPREL_HI16 }, | |
2186 | { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_DTPREL_LO16 }, | |
2187 | { BFD_RELOC_MIPS_TLS_GOTTPREL, R_MIPS_TLS_GOTTPREL }, | |
2188 | { BFD_RELOC_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL32 }, | |
2189 | { BFD_RELOC_MIPS_TLS_TPREL64, R_MIPS_TLS_TPREL64 }, | |
2190 | { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_MIPS_TLS_TPREL_HI16 }, | |
2191 | { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_MIPS_TLS_TPREL_LO16 } | |
a4382ec6 TS |
2192 | }; |
2193 | ||
d6f16593 MR |
2194 | static const struct elf_reloc_map mips16_reloc_map[] = |
2195 | { | |
2196 | { BFD_RELOC_MIPS16_JMP, R_MIPS16_26 - R_MIPS16_min }, | |
2197 | { BFD_RELOC_MIPS16_GPREL, R_MIPS16_GPREL - R_MIPS16_min }, | |
2198 | { BFD_RELOC_MIPS16_HI16_S, R_MIPS16_HI16 - R_MIPS16_min }, | |
2199 | { BFD_RELOC_MIPS16_LO16, R_MIPS16_LO16 - R_MIPS16_min }, | |
2200 | }; | |
2201 | ||
5b6a02bc TS |
2202 | /* Given a BFD reloc type, return a howto structure. */ |
2203 | ||
2204 | static reloc_howto_type * | |
11a2be4d RS |
2205 | bfd_elf64_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
2206 | bfd_reloc_code_real_type code) | |
5b6a02bc | 2207 | { |
a4382ec6 | 2208 | unsigned int i; |
5b6a02bc TS |
2209 | /* FIXME: We default to RELA here instead of choosing the right |
2210 | relocation variant. */ | |
2211 | reloc_howto_type *howto_table = mips_elf64_howto_table_rela; | |
d6f16593 | 2212 | reloc_howto_type *howto16_table = mips16_elf64_howto_table_rela; |
5b6a02bc | 2213 | |
a4382ec6 TS |
2214 | for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); |
2215 | i++) | |
2216 | { | |
2217 | if (mips_reloc_map[i].bfd_val == code) | |
2218 | return &howto_table[(int) mips_reloc_map[i].elf_val]; | |
2219 | } | |
2220 | ||
d6f16593 MR |
2221 | for (i = 0; i < sizeof (mips16_reloc_map) / sizeof (struct elf_reloc_map); |
2222 | i++) | |
2223 | { | |
2224 | if (mips16_reloc_map[i].bfd_val == code) | |
2225 | return &howto16_table[(int) mips16_reloc_map[i].elf_val]; | |
2226 | } | |
2227 | ||
5b6a02bc TS |
2228 | switch (code) |
2229 | { | |
5b6a02bc TS |
2230 | case BFD_RELOC_VTABLE_INHERIT: |
2231 | return &elf_mips_gnu_vtinherit_howto; | |
2232 | case BFD_RELOC_VTABLE_ENTRY: | |
2233 | return &elf_mips_gnu_vtentry_howto; | |
5b6a02bc TS |
2234 | default: |
2235 | bfd_set_error (bfd_error_bad_value); | |
2236 | return NULL; | |
2237 | } | |
2238 | } | |
2239 | ||
157090f7 AM |
2240 | static reloc_howto_type * |
2241 | bfd_elf64_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
2242 | const char *r_name) | |
2243 | { | |
2244 | unsigned int i; | |
2245 | ||
2246 | for (i = 0; | |
2247 | i < (sizeof (mips_elf64_howto_table_rela) | |
2248 | / sizeof (mips_elf64_howto_table_rela[0])); i++) | |
2249 | if (mips_elf64_howto_table_rela[i].name != NULL | |
2250 | && strcasecmp (mips_elf64_howto_table_rela[i].name, r_name) == 0) | |
2251 | return &mips_elf64_howto_table_rela[i]; | |
2252 | ||
2253 | for (i = 0; | |
2254 | i < (sizeof (mips16_elf64_howto_table_rela) | |
2255 | / sizeof (mips16_elf64_howto_table_rela[0])); | |
2256 | i++) | |
2257 | if (mips16_elf64_howto_table_rela[i].name != NULL | |
2258 | && strcasecmp (mips16_elf64_howto_table_rela[i].name, r_name) == 0) | |
2259 | return &mips16_elf64_howto_table_rela[i]; | |
2260 | ||
2261 | if (strcasecmp (elf_mips_gnu_vtinherit_howto.name, r_name) == 0) | |
2262 | return &elf_mips_gnu_vtinherit_howto; | |
2263 | if (strcasecmp (elf_mips_gnu_vtentry_howto.name, r_name) == 0) | |
2264 | return &elf_mips_gnu_vtentry_howto; | |
2265 | if (strcasecmp (elf_mips_gnu_rel16_s2.name, r_name) == 0) | |
2266 | return &elf_mips_gnu_rel16_s2; | |
2267 | if (strcasecmp (elf_mips_gnu_rela16_s2.name, r_name) == 0) | |
2268 | return &elf_mips_gnu_rela16_s2; | |
2269 | ||
2270 | return NULL; | |
2271 | } | |
2272 | ||
947216bf | 2273 | /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */ |
c6e90b02 TS |
2274 | |
2275 | static reloc_howto_type * | |
11a2be4d | 2276 | mips_elf64_rtype_to_howto (unsigned int r_type, bfd_boolean rela_p) |
c6e90b02 TS |
2277 | { |
2278 | switch (r_type) | |
2279 | { | |
c6e90b02 TS |
2280 | case R_MIPS_GNU_VTINHERIT: |
2281 | return &elf_mips_gnu_vtinherit_howto; | |
c6e90b02 TS |
2282 | case R_MIPS_GNU_VTENTRY: |
2283 | return &elf_mips_gnu_vtentry_howto; | |
d0c728db TS |
2284 | case R_MIPS_GNU_REL16_S2: |
2285 | if (rela_p) | |
2286 | return &elf_mips_gnu_rela16_s2; | |
2287 | else | |
2288 | return &elf_mips_gnu_rel16_s2; | |
c6e90b02 | 2289 | default: |
d6f16593 MR |
2290 | if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max) |
2291 | { | |
2292 | if (rela_p) | |
2293 | return &mips16_elf64_howto_table_rela[r_type - R_MIPS16_min]; | |
2294 | else | |
2295 | return &mips16_elf64_howto_table_rel[r_type - R_MIPS16_min]; | |
2296 | } | |
c6e90b02 TS |
2297 | BFD_ASSERT (r_type < (unsigned int) R_MIPS_max); |
2298 | if (rela_p) | |
2299 | return &mips_elf64_howto_table_rela[r_type]; | |
2300 | else | |
2301 | return &mips_elf64_howto_table_rel[r_type]; | |
2302 | break; | |
2303 | } | |
2304 | } | |
2305 | ||
5b6a02bc TS |
2306 | /* Prevent relocation handling by bfd for MIPS ELF64. */ |
2307 | ||
2308 | static void | |
11a2be4d RS |
2309 | mips_elf64_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, |
2310 | arelent *cache_ptr ATTRIBUTE_UNUSED, | |
2311 | Elf_Internal_Rela *dst ATTRIBUTE_UNUSED) | |
5b6a02bc TS |
2312 | { |
2313 | BFD_ASSERT (0); | |
2314 | } | |
2315 | ||
2316 | static void | |
11a2be4d RS |
2317 | mips_elf64_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, |
2318 | arelent *cache_ptr ATTRIBUTE_UNUSED, | |
2319 | Elf_Internal_Rela *dst ATTRIBUTE_UNUSED) | |
5b6a02bc TS |
2320 | { |
2321 | BFD_ASSERT (0); | |
2322 | } | |
2323 | ||
2324 | /* Since each entry in an SHT_REL or SHT_RELA section can represent up | |
2325 | to three relocs, we must tell the user to allocate more space. */ | |
2326 | ||
2327 | static long | |
11a2be4d | 2328 | mips_elf64_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) |
5b6a02bc TS |
2329 | { |
2330 | return (sec->reloc_count * 3 + 1) * sizeof (arelent *); | |
2331 | } | |
2332 | ||
fee24f1c | 2333 | static long |
11a2be4d | 2334 | mips_elf64_get_dynamic_reloc_upper_bound (bfd *abfd) |
fee24f1c AO |
2335 | { |
2336 | return _bfd_elf_get_dynamic_reloc_upper_bound (abfd) * 3; | |
2337 | } | |
2338 | ||
2339 | /* We must also copy more relocations than the corresponding functions | |
2340 | in elf.c would, so the two following functions are slightly | |
2341 | modified from elf.c, that multiply the external relocation count by | |
2342 | 3 to obtain the internal relocation count. */ | |
2343 | ||
2344 | static long | |
11a2be4d RS |
2345 | mips_elf64_canonicalize_reloc (bfd *abfd, sec_ptr section, |
2346 | arelent **relptr, asymbol **symbols) | |
fee24f1c AO |
2347 | { |
2348 | arelent *tblptr; | |
2349 | unsigned int i; | |
9c5bfbb7 | 2350 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); |
fee24f1c AO |
2351 | |
2352 | if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE)) | |
2353 | return -1; | |
2354 | ||
2355 | tblptr = section->relocation; | |
2356 | for (i = 0; i < section->reloc_count * 3; i++) | |
2357 | *relptr++ = tblptr++; | |
2358 | ||
2359 | *relptr = NULL; | |
2360 | ||
2361 | return section->reloc_count * 3; | |
2362 | } | |
2363 | ||
2364 | static long | |
11a2be4d RS |
2365 | mips_elf64_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage, |
2366 | asymbol **syms) | |
fee24f1c | 2367 | { |
11a2be4d | 2368 | bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean); |
fee24f1c AO |
2369 | asection *s; |
2370 | long ret; | |
2371 | ||
2372 | if (elf_dynsymtab (abfd) == 0) | |
2373 | { | |
2374 | bfd_set_error (bfd_error_invalid_operation); | |
2375 | return -1; | |
2376 | } | |
2377 | ||
2378 | slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table; | |
2379 | ret = 0; | |
2380 | for (s = abfd->sections; s != NULL; s = s->next) | |
2381 | { | |
2382 | if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd) | |
2383 | && (elf_section_data (s)->this_hdr.sh_type == SHT_REL | |
2384 | || elf_section_data (s)->this_hdr.sh_type == SHT_RELA)) | |
2385 | { | |
2386 | arelent *p; | |
2387 | long count, i; | |
2388 | ||
2389 | if (! (*slurp_relocs) (abfd, s, syms, TRUE)) | |
2390 | return -1; | |
eea6121a | 2391 | count = s->size / elf_section_data (s)->this_hdr.sh_entsize * 3; |
fee24f1c AO |
2392 | p = s->relocation; |
2393 | for (i = 0; i < count; i++) | |
2394 | *storage++ = p++; | |
2395 | ret += count; | |
2396 | } | |
2397 | } | |
2398 | ||
2399 | *storage = NULL; | |
2400 | ||
2401 | return ret; | |
2402 | } | |
2403 | ||
2404 | /* Read the relocations from one reloc section. This is mostly copied | |
2405 | from elfcode.h, except for the changes to expand one external | |
2406 | relocation to 3 internal ones. We must unfortunately set | |
2407 | reloc_count to the number of external relocations, because a lot of | |
2408 | generic code seems to depend on this. */ | |
5b6a02bc | 2409 | |
b34976b6 | 2410 | static bfd_boolean |
11a2be4d RS |
2411 | mips_elf64_slurp_one_reloc_table (bfd *abfd, asection *asect, |
2412 | Elf_Internal_Shdr *rel_hdr, | |
2413 | bfd_size_type reloc_count, | |
2414 | arelent *relents, asymbol **symbols, | |
2415 | bfd_boolean dynamic) | |
5b6a02bc | 2416 | { |
11a2be4d | 2417 | void *allocated; |
5b6a02bc | 2418 | bfd_byte *native_relocs; |
5b6a02bc | 2419 | arelent *relent; |
5b6a02bc TS |
2420 | bfd_vma i; |
2421 | int entsize; | |
32159579 | 2422 | bfd_boolean rela_p; |
5b6a02bc | 2423 | |
11a2be4d | 2424 | allocated = bfd_malloc (rel_hdr->sh_size); |
5b6a02bc | 2425 | if (allocated == NULL) |
b34976b6 | 2426 | return FALSE; |
5b6a02bc TS |
2427 | |
2428 | if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0 | |
fee24f1c AO |
2429 | || (bfd_bread (allocated, rel_hdr->sh_size, abfd) |
2430 | != rel_hdr->sh_size)) | |
5b6a02bc TS |
2431 | goto error_return; |
2432 | ||
11a2be4d | 2433 | native_relocs = allocated; |
5b6a02bc | 2434 | |
5b6a02bc TS |
2435 | entsize = rel_hdr->sh_entsize; |
2436 | BFD_ASSERT (entsize == sizeof (Elf64_Mips_External_Rel) | |
2437 | || entsize == sizeof (Elf64_Mips_External_Rela)); | |
2438 | ||
5b6a02bc | 2439 | if (entsize == sizeof (Elf64_Mips_External_Rel)) |
32159579 | 2440 | rela_p = FALSE; |
5b6a02bc | 2441 | else |
32159579 | 2442 | rela_p = TRUE; |
5b6a02bc | 2443 | |
fee24f1c AO |
2444 | for (i = 0, relent = relents; |
2445 | i < reloc_count; | |
2446 | i++, native_relocs += entsize) | |
5b6a02bc TS |
2447 | { |
2448 | Elf64_Mips_Internal_Rela rela; | |
b34976b6 | 2449 | bfd_boolean used_sym, used_ssym; |
5b6a02bc TS |
2450 | int ir; |
2451 | ||
2452 | if (entsize == sizeof (Elf64_Mips_External_Rela)) | |
2453 | mips_elf64_swap_reloca_in (abfd, | |
2454 | (Elf64_Mips_External_Rela *) native_relocs, | |
2455 | &rela); | |
2456 | else | |
947216bf AM |
2457 | mips_elf64_swap_reloc_in (abfd, |
2458 | (Elf64_Mips_External_Rel *) native_relocs, | |
2459 | &rela); | |
5b6a02bc | 2460 | |
49179469 | 2461 | /* Each entry represents exactly three actual relocations. */ |
5b6a02bc | 2462 | |
b34976b6 AM |
2463 | used_sym = FALSE; |
2464 | used_ssym = FALSE; | |
5b6a02bc TS |
2465 | for (ir = 0; ir < 3; ir++) |
2466 | { | |
2467 | enum elf_mips_reloc_type type; | |
2468 | ||
2469 | switch (ir) | |
252b5132 RH |
2470 | { |
2471 | default: | |
2472 | abort (); | |
2473 | case 0: | |
2474 | type = (enum elf_mips_reloc_type) rela.r_type; | |
2475 | break; | |
2476 | case 1: | |
2477 | type = (enum elf_mips_reloc_type) rela.r_type2; | |
2478 | break; | |
2479 | case 2: | |
2480 | type = (enum elf_mips_reloc_type) rela.r_type3; | |
2481 | break; | |
2482 | } | |
2483 | ||
252b5132 RH |
2484 | /* Some types require symbols, whereas some do not. */ |
2485 | switch (type) | |
2486 | { | |
2487 | case R_MIPS_NONE: | |
2488 | case R_MIPS_LITERAL: | |
2489 | case R_MIPS_INSERT_A: | |
2490 | case R_MIPS_INSERT_B: | |
2491 | case R_MIPS_DELETE: | |
2492 | relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | |
2493 | break; | |
2494 | ||
2495 | default: | |
2496 | if (! used_sym) | |
2497 | { | |
2498 | if (rela.r_sym == 0) | |
2499 | relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | |
2500 | else | |
2501 | { | |
2502 | asymbol **ps, *s; | |
2503 | ||
2504 | ps = symbols + rela.r_sym - 1; | |
2505 | s = *ps; | |
2506 | if ((s->flags & BSF_SECTION_SYM) == 0) | |
2507 | relent->sym_ptr_ptr = ps; | |
2508 | else | |
2509 | relent->sym_ptr_ptr = s->section->symbol_ptr_ptr; | |
2510 | } | |
2511 | ||
b34976b6 | 2512 | used_sym = TRUE; |
252b5132 RH |
2513 | } |
2514 | else if (! used_ssym) | |
2515 | { | |
2516 | switch (rela.r_ssym) | |
2517 | { | |
2518 | case RSS_UNDEF: | |
2519 | relent->sym_ptr_ptr = | |
2520 | bfd_abs_section_ptr->symbol_ptr_ptr; | |
2521 | break; | |
2522 | ||
2523 | case RSS_GP: | |
2524 | case RSS_GP0: | |
2525 | case RSS_LOC: | |
2526 | /* FIXME: I think these need to be handled using | |
99277196 | 2527 | special howto structures. */ |
252b5132 RH |
2528 | BFD_ASSERT (0); |
2529 | break; | |
2530 | ||
2531 | default: | |
2532 | BFD_ASSERT (0); | |
2533 | break; | |
2534 | } | |
2535 | ||
b34976b6 | 2536 | used_ssym = TRUE; |
252b5132 RH |
2537 | } |
2538 | else | |
2539 | relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | |
2540 | ||
2541 | break; | |
2542 | } | |
2543 | ||
2544 | /* The address of an ELF reloc is section relative for an | |
2545 | object file, and absolute for an executable file or | |
2546 | shared library. The address of a BFD reloc is always | |
2547 | section relative. */ | |
fee24f1c | 2548 | if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 || dynamic) |
252b5132 RH |
2549 | relent->address = rela.r_offset; |
2550 | else | |
2551 | relent->address = rela.r_offset - asect->vma; | |
2552 | ||
2553 | relent->addend = rela.r_addend; | |
2554 | ||
32159579 | 2555 | relent->howto = mips_elf64_rtype_to_howto (type, rela_p); |
252b5132 RH |
2556 | |
2557 | ++relent; | |
2558 | } | |
2559 | } | |
2560 | ||
49179469 | 2561 | asect->reloc_count += (relent - relents) / 3; |
252b5132 RH |
2562 | |
2563 | if (allocated != NULL) | |
2564 | free (allocated); | |
2565 | ||
b34976b6 | 2566 | return TRUE; |
252b5132 RH |
2567 | |
2568 | error_return: | |
2569 | if (allocated != NULL) | |
2570 | free (allocated); | |
b34976b6 | 2571 | return FALSE; |
252b5132 RH |
2572 | } |
2573 | ||
2574 | /* Read the relocations. On Irix 6, there can be two reloc sections | |
fee24f1c AO |
2575 | associated with a single data section. This is copied from |
2576 | elfcode.h as well, with changes as small as accounting for 3 | |
2577 | internal relocs per external reloc and resetting reloc_count to | |
2578 | zero before processing the relocs of a section. */ | |
252b5132 | 2579 | |
b34976b6 | 2580 | static bfd_boolean |
11a2be4d RS |
2581 | mips_elf64_slurp_reloc_table (bfd *abfd, asection *asect, |
2582 | asymbol **symbols, bfd_boolean dynamic) | |
252b5132 RH |
2583 | { |
2584 | struct bfd_elf_section_data * const d = elf_section_data (asect); | |
fee24f1c AO |
2585 | Elf_Internal_Shdr *rel_hdr; |
2586 | Elf_Internal_Shdr *rel_hdr2; | |
2587 | bfd_size_type reloc_count; | |
2588 | bfd_size_type reloc_count2; | |
2589 | arelent *relents; | |
2590 | bfd_size_type amt; | |
2591 | ||
2592 | if (asect->relocation != NULL) | |
2593 | return TRUE; | |
252b5132 | 2594 | |
fee24f1c | 2595 | if (! dynamic) |
252b5132 | 2596 | { |
fee24f1c AO |
2597 | if ((asect->flags & SEC_RELOC) == 0 |
2598 | || asect->reloc_count == 0) | |
2599 | return TRUE; | |
252b5132 | 2600 | |
fee24f1c AO |
2601 | rel_hdr = &d->rel_hdr; |
2602 | reloc_count = NUM_SHDR_ENTRIES (rel_hdr); | |
2603 | rel_hdr2 = d->rel_hdr2; | |
2604 | reloc_count2 = (rel_hdr2 ? NUM_SHDR_ENTRIES (rel_hdr2) : 0); | |
2605 | ||
2606 | BFD_ASSERT (asect->reloc_count == reloc_count + reloc_count2); | |
2607 | BFD_ASSERT (asect->rel_filepos == rel_hdr->sh_offset | |
2608 | || (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset)); | |
2609 | ||
2610 | } | |
2611 | else | |
2612 | { | |
2613 | /* Note that ASECT->RELOC_COUNT tends not to be accurate in this | |
2614 | case because relocations against this section may use the | |
2615 | dynamic symbol table, and in that case bfd_section_from_shdr | |
2616 | in elf.c does not update the RELOC_COUNT. */ | |
eea6121a | 2617 | if (asect->size == 0) |
fee24f1c AO |
2618 | return TRUE; |
2619 | ||
2620 | rel_hdr = &d->this_hdr; | |
2621 | reloc_count = NUM_SHDR_ENTRIES (rel_hdr); | |
2622 | rel_hdr2 = NULL; | |
2623 | reloc_count2 = 0; | |
2624 | } | |
252b5132 RH |
2625 | |
2626 | /* Allocate space for 3 arelent structures for each Rel structure. */ | |
fee24f1c | 2627 | amt = (reloc_count + reloc_count2) * 3 * sizeof (arelent); |
11a2be4d | 2628 | relents = bfd_alloc (abfd, amt); |
fee24f1c | 2629 | if (relents == NULL) |
b34976b6 | 2630 | return FALSE; |
252b5132 RH |
2631 | |
2632 | /* The slurp_one_reloc_table routine increments reloc_count. */ | |
2633 | asect->reloc_count = 0; | |
2634 | ||
fee24f1c AO |
2635 | if (! mips_elf64_slurp_one_reloc_table (abfd, asect, |
2636 | rel_hdr, reloc_count, | |
2637 | relents, | |
2638 | symbols, dynamic)) | |
b34976b6 | 2639 | return FALSE; |
252b5132 RH |
2640 | if (d->rel_hdr2 != NULL) |
2641 | { | |
fee24f1c AO |
2642 | if (! mips_elf64_slurp_one_reloc_table (abfd, asect, |
2643 | rel_hdr2, reloc_count2, | |
2644 | relents + reloc_count * 3, | |
2645 | symbols, dynamic)) | |
b34976b6 | 2646 | return FALSE; |
252b5132 RH |
2647 | } |
2648 | ||
fee24f1c | 2649 | asect->relocation = relents; |
b34976b6 | 2650 | return TRUE; |
252b5132 RH |
2651 | } |
2652 | ||
2653 | /* Write out the relocations. */ | |
2654 | ||
2655 | static void | |
11a2be4d | 2656 | mips_elf64_write_relocs (bfd *abfd, asection *sec, void *data) |
252b5132 | 2657 | { |
11a2be4d | 2658 | bfd_boolean *failedp = data; |
5b6a02bc TS |
2659 | int count; |
2660 | Elf_Internal_Shdr *rel_hdr; | |
252b5132 | 2661 | unsigned int idx; |
252b5132 RH |
2662 | |
2663 | /* If we have already failed, don't do anything. */ | |
2664 | if (*failedp) | |
2665 | return; | |
2666 | ||
2667 | if ((sec->flags & SEC_RELOC) == 0) | |
2668 | return; | |
2669 | ||
2670 | /* The linker backend writes the relocs out itself, and sets the | |
2671 | reloc_count field to zero to inhibit writing them here. Also, | |
2672 | sometimes the SEC_RELOC flag gets set even when there aren't any | |
2673 | relocs. */ | |
2674 | if (sec->reloc_count == 0) | |
2675 | return; | |
2676 | ||
2677 | /* We can combine up to three relocs that refer to the same address | |
2678 | if the latter relocs have no associated symbol. */ | |
2679 | count = 0; | |
2680 | for (idx = 0; idx < sec->reloc_count; idx++) | |
2681 | { | |
2682 | bfd_vma addr; | |
2683 | unsigned int i; | |
2684 | ||
2685 | ++count; | |
2686 | ||
2687 | addr = sec->orelocation[idx]->address; | |
2688 | for (i = 0; i < 2; i++) | |
2689 | { | |
2690 | arelent *r; | |
2691 | ||
2692 | if (idx + 1 >= sec->reloc_count) | |
2693 | break; | |
2694 | r = sec->orelocation[idx + 1]; | |
2695 | if (r->address != addr | |
2696 | || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section) | |
2697 | || (*r->sym_ptr_ptr)->value != 0) | |
2698 | break; | |
2699 | ||
2700 | /* We can merge the reloc at IDX + 1 with the reloc at IDX. */ | |
2701 | ||
2702 | ++idx; | |
2703 | } | |
2704 | } | |
2705 | ||
5b6a02bc | 2706 | rel_hdr = &elf_section_data (sec)->rel_hdr; |
252b5132 | 2707 | |
5b6a02bc TS |
2708 | /* Do the actual relocation. */ |
2709 | ||
2710 | if (rel_hdr->sh_entsize == sizeof(Elf64_Mips_External_Rel)) | |
2711 | mips_elf64_write_rel (abfd, sec, rel_hdr, &count, data); | |
2712 | else if (rel_hdr->sh_entsize == sizeof(Elf64_Mips_External_Rela)) | |
2713 | mips_elf64_write_rela (abfd, sec, rel_hdr, &count, data); | |
2714 | else | |
2715 | BFD_ASSERT (0); | |
2716 | } | |
2717 | ||
2718 | static void | |
11a2be4d RS |
2719 | mips_elf64_write_rel (bfd *abfd, asection *sec, |
2720 | Elf_Internal_Shdr *rel_hdr, | |
2721 | int *count, void *data) | |
5b6a02bc | 2722 | { |
11a2be4d | 2723 | bfd_boolean *failedp = data; |
5b6a02bc TS |
2724 | Elf64_Mips_External_Rel *ext_rel; |
2725 | unsigned int idx; | |
2726 | asymbol *last_sym = 0; | |
2727 | int last_sym_idx = 0; | |
2728 | ||
11a2be4d RS |
2729 | rel_hdr->sh_size = rel_hdr->sh_entsize * *count; |
2730 | rel_hdr->contents = bfd_alloc (abfd, rel_hdr->sh_size); | |
5b6a02bc | 2731 | if (rel_hdr->contents == NULL) |
252b5132 | 2732 | { |
b34976b6 | 2733 | *failedp = TRUE; |
252b5132 RH |
2734 | return; |
2735 | } | |
2736 | ||
5b6a02bc TS |
2737 | ext_rel = (Elf64_Mips_External_Rel *) rel_hdr->contents; |
2738 | for (idx = 0; idx < sec->reloc_count; idx++, ext_rel++) | |
252b5132 RH |
2739 | { |
2740 | arelent *ptr; | |
947216bf | 2741 | Elf64_Mips_Internal_Rela int_rel; |
252b5132 RH |
2742 | asymbol *sym; |
2743 | int n; | |
2744 | unsigned int i; | |
2745 | ||
2746 | ptr = sec->orelocation[idx]; | |
2747 | ||
2748 | /* The address of an ELF reloc is section relative for an object | |
2749 | file, and absolute for an executable file or shared library. | |
2750 | The address of a BFD reloc is always section relative. */ | |
2751 | if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0) | |
5b6a02bc | 2752 | int_rel.r_offset = ptr->address; |
252b5132 | 2753 | else |
5b6a02bc | 2754 | int_rel.r_offset = ptr->address + sec->vma; |
252b5132 RH |
2755 | |
2756 | sym = *ptr->sym_ptr_ptr; | |
2757 | if (sym == last_sym) | |
2758 | n = last_sym_idx; | |
99022dfb RS |
2759 | else if (bfd_is_abs_section (sym->section) && sym->value == 0) |
2760 | n = STN_UNDEF; | |
252b5132 RH |
2761 | else |
2762 | { | |
2763 | last_sym = sym; | |
2764 | n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym); | |
2765 | if (n < 0) | |
2766 | { | |
b34976b6 | 2767 | *failedp = TRUE; |
252b5132 RH |
2768 | return; |
2769 | } | |
2770 | last_sym_idx = n; | |
2771 | } | |
2772 | ||
5b6a02bc TS |
2773 | int_rel.r_sym = n; |
2774 | int_rel.r_ssym = RSS_UNDEF; | |
252b5132 RH |
2775 | |
2776 | if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec | |
2777 | && ! _bfd_elf_validate_reloc (abfd, ptr)) | |
2778 | { | |
b34976b6 | 2779 | *failedp = TRUE; |
252b5132 RH |
2780 | return; |
2781 | } | |
2782 | ||
5b6a02bc TS |
2783 | int_rel.r_type = ptr->howto->type; |
2784 | int_rel.r_type2 = (int) R_MIPS_NONE; | |
2785 | int_rel.r_type3 = (int) R_MIPS_NONE; | |
252b5132 RH |
2786 | |
2787 | for (i = 0; i < 2; i++) | |
2788 | { | |
2789 | arelent *r; | |
2790 | ||
2791 | if (idx + 1 >= sec->reloc_count) | |
2792 | break; | |
2793 | r = sec->orelocation[idx + 1]; | |
2794 | if (r->address != ptr->address | |
2795 | || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section) | |
2796 | || (*r->sym_ptr_ptr)->value != 0) | |
2797 | break; | |
2798 | ||
2799 | /* We can merge the reloc at IDX + 1 with the reloc at IDX. */ | |
2800 | ||
2801 | if (i == 0) | |
5b6a02bc | 2802 | int_rel.r_type2 = r->howto->type; |
252b5132 | 2803 | else |
5b6a02bc | 2804 | int_rel.r_type3 = r->howto->type; |
252b5132 RH |
2805 | |
2806 | ++idx; | |
2807 | } | |
2808 | ||
5b6a02bc | 2809 | mips_elf64_swap_reloc_out (abfd, &int_rel, ext_rel); |
252b5132 RH |
2810 | } |
2811 | ||
5b6a02bc TS |
2812 | BFD_ASSERT (ext_rel - (Elf64_Mips_External_Rel *) rel_hdr->contents |
2813 | == *count); | |
252b5132 | 2814 | } |
5b6a02bc TS |
2815 | |
2816 | static void | |
11a2be4d RS |
2817 | mips_elf64_write_rela (bfd *abfd, asection *sec, |
2818 | Elf_Internal_Shdr *rela_hdr, | |
2819 | int *count, void *data) | |
5b6a02bc | 2820 | { |
11a2be4d | 2821 | bfd_boolean *failedp = data; |
5b6a02bc TS |
2822 | Elf64_Mips_External_Rela *ext_rela; |
2823 | unsigned int idx; | |
2824 | asymbol *last_sym = 0; | |
2825 | int last_sym_idx = 0; | |
2826 | ||
11a2be4d RS |
2827 | rela_hdr->sh_size = rela_hdr->sh_entsize * *count; |
2828 | rela_hdr->contents = bfd_alloc (abfd, rela_hdr->sh_size); | |
5b6a02bc TS |
2829 | if (rela_hdr->contents == NULL) |
2830 | { | |
b34976b6 | 2831 | *failedp = TRUE; |
5b6a02bc TS |
2832 | return; |
2833 | } | |
2834 | ||
2835 | ext_rela = (Elf64_Mips_External_Rela *) rela_hdr->contents; | |
2836 | for (idx = 0; idx < sec->reloc_count; idx++, ext_rela++) | |
2837 | { | |
2838 | arelent *ptr; | |
2839 | Elf64_Mips_Internal_Rela int_rela; | |
2840 | asymbol *sym; | |
2841 | int n; | |
2842 | unsigned int i; | |
2843 | ||
2844 | ptr = sec->orelocation[idx]; | |
2845 | ||
2846 | /* The address of an ELF reloc is section relative for an object | |
2847 | file, and absolute for an executable file or shared library. | |
2848 | The address of a BFD reloc is always section relative. */ | |
2849 | if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0) | |
2850 | int_rela.r_offset = ptr->address; | |
2851 | else | |
2852 | int_rela.r_offset = ptr->address + sec->vma; | |
2853 | ||
2854 | sym = *ptr->sym_ptr_ptr; | |
2855 | if (sym == last_sym) | |
2856 | n = last_sym_idx; | |
99022dfb RS |
2857 | else if (bfd_is_abs_section (sym->section) && sym->value == 0) |
2858 | n = STN_UNDEF; | |
5b6a02bc TS |
2859 | else |
2860 | { | |
2861 | last_sym = sym; | |
2862 | n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym); | |
2863 | if (n < 0) | |
2864 | { | |
b34976b6 | 2865 | *failedp = TRUE; |
5b6a02bc TS |
2866 | return; |
2867 | } | |
2868 | last_sym_idx = n; | |
2869 | } | |
2870 | ||
2871 | int_rela.r_sym = n; | |
2872 | int_rela.r_addend = ptr->addend; | |
2873 | int_rela.r_ssym = RSS_UNDEF; | |
2874 | ||
2875 | if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec | |
2876 | && ! _bfd_elf_validate_reloc (abfd, ptr)) | |
2877 | { | |
b34976b6 | 2878 | *failedp = TRUE; |
5b6a02bc TS |
2879 | return; |
2880 | } | |
2881 | ||
2882 | int_rela.r_type = ptr->howto->type; | |
2883 | int_rela.r_type2 = (int) R_MIPS_NONE; | |
2884 | int_rela.r_type3 = (int) R_MIPS_NONE; | |
2885 | ||
2886 | for (i = 0; i < 2; i++) | |
2887 | { | |
2888 | arelent *r; | |
2889 | ||
2890 | if (idx + 1 >= sec->reloc_count) | |
2891 | break; | |
2892 | r = sec->orelocation[idx + 1]; | |
2893 | if (r->address != ptr->address | |
2894 | || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section) | |
2895 | || (*r->sym_ptr_ptr)->value != 0) | |
2896 | break; | |
2897 | ||
2898 | /* We can merge the reloc at IDX + 1 with the reloc at IDX. */ | |
2899 | ||
2900 | if (i == 0) | |
2901 | int_rela.r_type2 = r->howto->type; | |
2902 | else | |
2903 | int_rela.r_type3 = r->howto->type; | |
2904 | ||
2905 | ++idx; | |
2906 | } | |
2907 | ||
2908 | mips_elf64_swap_reloca_out (abfd, &int_rela, ext_rela); | |
2909 | } | |
2910 | ||
2911 | BFD_ASSERT (ext_rela - (Elf64_Mips_External_Rela *) rela_hdr->contents | |
2912 | == *count); | |
2913 | } | |
2914 | \f | |
c6e90b02 | 2915 | /* Set the right machine number for a MIPS ELF file. */ |
5b6a02bc | 2916 | |
b34976b6 | 2917 | static bfd_boolean |
11a2be4d | 2918 | mips_elf64_object_p (bfd *abfd) |
5b6a02bc | 2919 | { |
c6e90b02 | 2920 | unsigned long mach; |
5b6a02bc | 2921 | |
c6e90b02 TS |
2922 | /* Irix 6 is broken. Object file symbol tables are not always |
2923 | sorted correctly such that local symbols precede global symbols, | |
2924 | and the sh_info field in the symbol table is not always right. */ | |
a4382ec6 | 2925 | if (elf64_mips_irix_compat (abfd) != ict_none) |
b34976b6 | 2926 | elf_bad_symtab (abfd) = TRUE; |
5b6a02bc | 2927 | |
c6e90b02 TS |
2928 | mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags); |
2929 | bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach); | |
b34976b6 | 2930 | return TRUE; |
5b6a02bc TS |
2931 | } |
2932 | ||
c6e90b02 TS |
2933 | /* Depending on the target vector we generate some version of Irix |
2934 | executables or "normal" MIPS ELF ABI executables. */ | |
2935 | static irix_compat_t | |
11a2be4d | 2936 | elf64_mips_irix_compat (bfd *abfd) |
5b6a02bc | 2937 | { |
a4382ec6 TS |
2938 | if ((abfd->xvec == &bfd_elf64_bigmips_vec) |
2939 | || (abfd->xvec == &bfd_elf64_littlemips_vec)) | |
c6e90b02 | 2940 | return ict_irix6; |
a4382ec6 TS |
2941 | else |
2942 | return ict_none; | |
5b6a02bc TS |
2943 | } |
2944 | \f | |
d0112f73 KB |
2945 | /* Support for core dump NOTE sections. */ |
2946 | static bfd_boolean | |
11a2be4d | 2947 | elf64_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
d0112f73 KB |
2948 | { |
2949 | int offset; | |
eea6121a | 2950 | unsigned int size; |
d0112f73 KB |
2951 | |
2952 | switch (note->descsz) | |
2953 | { | |
2954 | default: | |
2955 | return FALSE; | |
2956 | ||
2957 | case 480: /* Linux/MIPS - N64 kernel */ | |
2958 | /* pr_cursig */ | |
2959 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
2960 | ||
2961 | /* pr_pid */ | |
2962 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32); | |
2963 | ||
2964 | /* pr_reg */ | |
2965 | offset = 112; | |
eea6121a | 2966 | size = 360; |
d0112f73 KB |
2967 | |
2968 | break; | |
2969 | } | |
2970 | ||
2971 | /* Make a ".reg/999" section. */ | |
2972 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
eea6121a | 2973 | size, note->descpos + offset); |
d0112f73 KB |
2974 | } |
2975 | ||
2976 | static bfd_boolean | |
11a2be4d | 2977 | elf64_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
d0112f73 KB |
2978 | { |
2979 | switch (note->descsz) | |
2980 | { | |
2981 | default: | |
2982 | return FALSE; | |
2983 | ||
2984 | case 136: /* Linux/MIPS - N64 kernel elf_prpsinfo */ | |
2985 | elf_tdata (abfd)->core_program | |
2986 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); | |
2987 | elf_tdata (abfd)->core_command | |
2988 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); | |
2989 | } | |
2990 | ||
2991 | /* Note that for some reason, a spurious space is tacked | |
2992 | onto the end of the args in some (at least one anyway) | |
2993 | implementations, so strip it off if it exists. */ | |
2994 | ||
2995 | { | |
2996 | char *command = elf_tdata (abfd)->core_command; | |
2997 | int n = strlen (command); | |
2998 | ||
2999 | if (0 < n && command[n - 1] == ' ') | |
3000 | command[n - 1] = '\0'; | |
3001 | } | |
3002 | ||
3003 | return TRUE; | |
3004 | } | |
3005 | \f | |
c6e90b02 TS |
3006 | /* ECOFF swapping routines. These are used when dealing with the |
3007 | .mdebug section, which is in the ECOFF debugging format. */ | |
3008 | static const struct ecoff_debug_swap mips_elf64_ecoff_debug_swap = | |
5b6a02bc | 3009 | { |
c6e90b02 TS |
3010 | /* Symbol table magic number. */ |
3011 | magicSym2, | |
3012 | /* Alignment of debugging information. E.g., 4. */ | |
3013 | 8, | |
3014 | /* Sizes of external symbolic information. */ | |
3015 | sizeof (struct hdr_ext), | |
3016 | sizeof (struct dnr_ext), | |
3017 | sizeof (struct pdr_ext), | |
3018 | sizeof (struct sym_ext), | |
3019 | sizeof (struct opt_ext), | |
3020 | sizeof (struct fdr_ext), | |
3021 | sizeof (struct rfd_ext), | |
3022 | sizeof (struct ext_ext), | |
3023 | /* Functions to swap in external symbolic data. */ | |
3024 | ecoff_swap_hdr_in, | |
3025 | ecoff_swap_dnr_in, | |
3026 | ecoff_swap_pdr_in, | |
3027 | ecoff_swap_sym_in, | |
3028 | ecoff_swap_opt_in, | |
3029 | ecoff_swap_fdr_in, | |
3030 | ecoff_swap_rfd_in, | |
3031 | ecoff_swap_ext_in, | |
3032 | _bfd_ecoff_swap_tir_in, | |
3033 | _bfd_ecoff_swap_rndx_in, | |
3034 | /* Functions to swap out external symbolic data. */ | |
3035 | ecoff_swap_hdr_out, | |
3036 | ecoff_swap_dnr_out, | |
3037 | ecoff_swap_pdr_out, | |
3038 | ecoff_swap_sym_out, | |
3039 | ecoff_swap_opt_out, | |
3040 | ecoff_swap_fdr_out, | |
3041 | ecoff_swap_rfd_out, | |
3042 | ecoff_swap_ext_out, | |
3043 | _bfd_ecoff_swap_tir_out, | |
3044 | _bfd_ecoff_swap_rndx_out, | |
3045 | /* Function to read in symbolic data. */ | |
3046 | _bfd_mips_elf_read_ecoff_info | |
3047 | }; | |
3048 | \f | |
3049 | /* Relocations in the 64 bit MIPS ELF ABI are more complex than in | |
3050 | standard ELF. This structure is used to redirect the relocation | |
3051 | handling routines. */ | |
5b6a02bc | 3052 | |
c6e90b02 | 3053 | const struct elf_size_info mips_elf64_size_info = |
5b6a02bc | 3054 | { |
c6e90b02 TS |
3055 | sizeof (Elf64_External_Ehdr), |
3056 | sizeof (Elf64_External_Phdr), | |
3057 | sizeof (Elf64_External_Shdr), | |
3058 | sizeof (Elf64_Mips_External_Rel), | |
3059 | sizeof (Elf64_Mips_External_Rela), | |
3060 | sizeof (Elf64_External_Sym), | |
3061 | sizeof (Elf64_External_Dyn), | |
3062 | sizeof (Elf_External_Note), | |
99277196 MR |
3063 | 4, /* hash-table entry size */ |
3064 | 3, /* internal relocations per external relocations */ | |
c6e90b02 | 3065 | 64, /* arch_size */ |
45d6a902 | 3066 | 3, /* log_file_align */ |
c6e90b02 TS |
3067 | ELFCLASS64, |
3068 | EV_CURRENT, | |
3069 | bfd_elf64_write_out_phdrs, | |
3070 | bfd_elf64_write_shdrs_and_ehdr, | |
3071 | mips_elf64_write_relocs, | |
73ff0d56 | 3072 | bfd_elf64_swap_symbol_in, |
c6e90b02 TS |
3073 | bfd_elf64_swap_symbol_out, |
3074 | mips_elf64_slurp_reloc_table, | |
3075 | bfd_elf64_slurp_symbol_table, | |
3076 | bfd_elf64_swap_dyn_in, | |
3077 | bfd_elf64_swap_dyn_out, | |
3078 | mips_elf64_be_swap_reloc_in, | |
3079 | mips_elf64_be_swap_reloc_out, | |
3080 | mips_elf64_be_swap_reloca_in, | |
3081 | mips_elf64_be_swap_reloca_out | |
5b6a02bc TS |
3082 | }; |
3083 | ||
c6e90b02 TS |
3084 | #define ELF_ARCH bfd_arch_mips |
3085 | #define ELF_MACHINE_CODE EM_MIPS | |
103186c6 | 3086 | |
b34976b6 AM |
3087 | #define elf_backend_collect TRUE |
3088 | #define elf_backend_type_change_ok TRUE | |
3089 | #define elf_backend_can_gc_sections TRUE | |
5b6a02bc TS |
3090 | #define elf_info_to_howto mips_elf64_info_to_howto_rela |
3091 | #define elf_info_to_howto_rel mips_elf64_info_to_howto_rel | |
c6e90b02 | 3092 | #define elf_backend_object_p mips_elf64_object_p |
5b6a02bc TS |
3093 | #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing |
3094 | #define elf_backend_section_processing _bfd_mips_elf_section_processing | |
103186c6 | 3095 | #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr |
252b5132 RH |
3096 | #define elf_backend_fake_sections _bfd_mips_elf_fake_sections |
3097 | #define elf_backend_section_from_bfd_section \ | |
c6e90b02 | 3098 | _bfd_mips_elf_section_from_bfd_section |
103186c6 | 3099 | #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook |
5b6a02bc | 3100 | #define elf_backend_link_output_symbol_hook \ |
c6e90b02 | 3101 | _bfd_mips_elf_link_output_symbol_hook |
103186c6 | 3102 | #define elf_backend_create_dynamic_sections \ |
c6e90b02 TS |
3103 | _bfd_mips_elf_create_dynamic_sections |
3104 | #define elf_backend_check_relocs _bfd_mips_elf_check_relocs | |
8992f0d7 TS |
3105 | #define elf_backend_merge_symbol_attribute \ |
3106 | _bfd_mips_elf_merge_symbol_attribute | |
103186c6 | 3107 | #define elf_backend_adjust_dynamic_symbol \ |
c6e90b02 | 3108 | _bfd_mips_elf_adjust_dynamic_symbol |
103186c6 | 3109 | #define elf_backend_always_size_sections \ |
c6e90b02 | 3110 | _bfd_mips_elf_always_size_sections |
103186c6 | 3111 | #define elf_backend_size_dynamic_sections \ |
c6e90b02 | 3112 | _bfd_mips_elf_size_dynamic_sections |
74541ad4 | 3113 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
c6e90b02 | 3114 | #define elf_backend_relocate_section _bfd_mips_elf_relocate_section |
103186c6 | 3115 | #define elf_backend_finish_dynamic_symbol \ |
c6e90b02 | 3116 | _bfd_mips_elf_finish_dynamic_symbol |
103186c6 | 3117 | #define elf_backend_finish_dynamic_sections \ |
c6e90b02 | 3118 | _bfd_mips_elf_finish_dynamic_sections |
5b6a02bc | 3119 | #define elf_backend_final_write_processing \ |
c6e90b02 | 3120 | _bfd_mips_elf_final_write_processing |
5b6a02bc | 3121 | #define elf_backend_additional_program_headers \ |
c6e90b02 | 3122 | _bfd_mips_elf_additional_program_headers |
5b6a02bc | 3123 | #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map |
c6e90b02 TS |
3124 | #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook |
3125 | #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook | |
427b80f4 RS |
3126 | #define elf_backend_copy_indirect_symbol \ |
3127 | _bfd_mips_elf_copy_indirect_symbol | |
c6e90b02 | 3128 | #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol |
53bfd6b4 MR |
3129 | #define elf_backend_ignore_discarded_relocs \ |
3130 | _bfd_mips_elf_ignore_discarded_relocs | |
c6e90b02 TS |
3131 | #define elf_backend_mips_irix_compat elf64_mips_irix_compat |
3132 | #define elf_backend_mips_rtype_to_howto mips_elf64_rtype_to_howto | |
5b6a02bc TS |
3133 | #define elf_backend_ecoff_debug_swap &mips_elf64_ecoff_debug_swap |
3134 | #define elf_backend_size_info mips_elf64_size_info | |
d0112f73 KB |
3135 | |
3136 | #define elf_backend_grok_prstatus elf64_mips_grok_prstatus | |
3137 | #define elf_backend_grok_psinfo elf64_mips_grok_psinfo | |
5b6a02bc TS |
3138 | |
3139 | #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO) | |
1e2be829 TS |
3140 | |
3141 | /* MIPS ELF64 can use a mixture of REL and RELA, but some Relocations | |
c6e90b02 | 3142 | work better/work only in RELA, so we default to this. */ |
1e2be829 TS |
3143 | #define elf_backend_may_use_rel_p 1 |
3144 | #define elf_backend_may_use_rela_p 1 | |
3145 | #define elf_backend_default_use_rela_p 1 | |
103186c6 | 3146 | |
d01414a5 TS |
3147 | #define elf_backend_write_section _bfd_mips_elf_write_section |
3148 | ||
fe8bc63d | 3149 | /* We don't set bfd_elf64_bfd_is_local_label_name because the 32-bit |
103186c6 MM |
3150 | MIPS-specific function only applies to IRIX5, which had no 64-bit |
3151 | ABI. */ | |
252b5132 | 3152 | #define bfd_elf64_find_nearest_line _bfd_mips_elf_find_nearest_line |
4ab527b0 | 3153 | #define bfd_elf64_find_inliner_info _bfd_mips_elf_find_inliner_info |
f0abc2a1 | 3154 | #define bfd_elf64_new_section_hook _bfd_mips_elf_new_section_hook |
252b5132 | 3155 | #define bfd_elf64_set_section_contents _bfd_mips_elf_set_section_contents |
c6e90b02 TS |
3156 | #define bfd_elf64_bfd_get_relocated_section_contents \ |
3157 | _bfd_elf_mips_get_relocated_section_contents | |
103186c6 | 3158 | #define bfd_elf64_bfd_link_hash_table_create \ |
c6e90b02 TS |
3159 | _bfd_mips_elf_link_hash_table_create |
3160 | #define bfd_elf64_bfd_final_link _bfd_mips_elf_final_link | |
252b5132 | 3161 | #define bfd_elf64_bfd_merge_private_bfd_data \ |
c6e90b02 | 3162 | _bfd_mips_elf_merge_private_bfd_data |
252b5132 | 3163 | #define bfd_elf64_bfd_set_private_flags _bfd_mips_elf_set_private_flags |
103186c6 | 3164 | #define bfd_elf64_bfd_print_private_bfd_data \ |
c6e90b02 | 3165 | _bfd_mips_elf_print_private_bfd_data |
252b5132 | 3166 | |
103186c6 | 3167 | #define bfd_elf64_get_reloc_upper_bound mips_elf64_get_reloc_upper_bound |
fee24f1c AO |
3168 | #define bfd_elf64_canonicalize_reloc mips_elf64_canonicalize_reloc |
3169 | #define bfd_elf64_get_dynamic_reloc_upper_bound mips_elf64_get_dynamic_reloc_upper_bound | |
3170 | #define bfd_elf64_canonicalize_dynamic_reloc mips_elf64_canonicalize_dynamic_reloc | |
d0647110 | 3171 | #define bfd_elf64_bfd_relax_section _bfd_mips_relax_section |
c6e90b02 TS |
3172 | |
3173 | /* MIPS ELF64 archive functions. */ | |
252b5132 | 3174 | #define bfd_elf64_archive_functions |
b34976b6 | 3175 | extern bfd_boolean bfd_elf64_archive_slurp_armap |
11a2be4d | 3176 | (bfd *); |
b34976b6 | 3177 | extern bfd_boolean bfd_elf64_archive_write_armap |
11a2be4d | 3178 | (bfd *, unsigned int, struct orl *, unsigned int, int); |
252b5132 | 3179 | #define bfd_elf64_archive_slurp_extended_name_table \ |
c6e90b02 | 3180 | _bfd_archive_coff_slurp_extended_name_table |
252b5132 | 3181 | #define bfd_elf64_archive_construct_extended_name_table \ |
c6e90b02 | 3182 | _bfd_archive_coff_construct_extended_name_table |
252b5132 | 3183 | #define bfd_elf64_archive_truncate_arname \ |
c6e90b02 | 3184 | _bfd_archive_coff_truncate_arname |
252b5132 RH |
3185 | #define bfd_elf64_archive_read_ar_hdr _bfd_archive_coff_read_ar_hdr |
3186 | #define bfd_elf64_archive_openr_next_archived_file \ | |
c6e90b02 | 3187 | _bfd_archive_coff_openr_next_archived_file |
252b5132 | 3188 | #define bfd_elf64_archive_get_elt_at_index \ |
c6e90b02 | 3189 | _bfd_archive_coff_get_elt_at_index |
252b5132 | 3190 | #define bfd_elf64_archive_generic_stat_arch_elt \ |
c6e90b02 | 3191 | _bfd_archive_coff_generic_stat_arch_elt |
252b5132 | 3192 | #define bfd_elf64_archive_update_armap_timestamp \ |
c6e90b02 | 3193 | _bfd_archive_coff_update_armap_timestamp |
252b5132 | 3194 | |
5b6a02bc TS |
3195 | /* The SGI style (n)64 NewABI. */ |
3196 | #define TARGET_LITTLE_SYM bfd_elf64_littlemips_vec | |
3197 | #define TARGET_LITTLE_NAME "elf64-littlemips" | |
3198 | #define TARGET_BIG_SYM bfd_elf64_bigmips_vec | |
3199 | #define TARGET_BIG_NAME "elf64-bigmips" | |
fdbafa10 | 3200 | |
7fd91fe0 TS |
3201 | #define ELF_MAXPAGESIZE 0x10000 |
3202 | #define ELF_COMMONPAGESIZE 0x1000 | |
fdbafa10 | 3203 | |
4301eeb1 | 3204 | #include "elf64-target.h" |
fdbafa10 | 3205 | |
5b6a02bc | 3206 | /* The SYSV-style 'traditional' (n)64 NewABI. */ |
fdbafa10 L |
3207 | #undef TARGET_LITTLE_SYM |
3208 | #undef TARGET_LITTLE_NAME | |
3209 | #undef TARGET_BIG_SYM | |
3210 | #undef TARGET_BIG_NAME | |
3211 | ||
4301eeb1 | 3212 | #undef ELF_MAXPAGESIZE |
7fd91fe0 | 3213 | #undef ELF_COMMONPAGESIZE |
4301eeb1 | 3214 | |
99277196 MR |
3215 | #define TARGET_LITTLE_SYM bfd_elf64_tradlittlemips_vec |
3216 | #define TARGET_LITTLE_NAME "elf64-tradlittlemips" | |
3217 | #define TARGET_BIG_SYM bfd_elf64_tradbigmips_vec | |
3218 | #define TARGET_BIG_NAME "elf64-tradbigmips" | |
fdbafa10 | 3219 | |
4301eeb1 | 3220 | #define ELF_MAXPAGESIZE 0x10000 |
7fd91fe0 | 3221 | #define ELF_COMMONPAGESIZE 0x1000 |
4301eeb1 MR |
3222 | #define elf64_bed elf64_tradbed |
3223 | ||
5b6a02bc | 3224 | /* Include the target file again for this target. */ |
fdbafa10 | 3225 | #include "elf64-target.h" |