elf-hppa.h warning fix
[deliverable/binutils-gdb.git] / bfd / elf32-i860.c
CommitLineData
0e5136c6 1/* Intel i860 specific support for 32-bit ELF.
219d1afa 2 Copyright (C) 1993-2018 Free Software Foundation, Inc.
9d751335 3
0e5136c6 4 Full i860 support contributed by Jason Eckhardt <jle@cygnus.com>.
252b5132 5
cd123cb7 6 This file is part of BFD, the Binary File Descriptor library.
252b5132 7
cd123cb7
NC
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
252b5132 12
cd123cb7
NC
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
252b5132 17
cd123cb7
NC
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
252b5132 22
252b5132 23#include "sysdep.h"
3db64b00 24#include "bfd.h"
252b5132
RH
25#include "libbfd.h"
26#include "elf-bfd.h"
0e5136c6
JE
27#include "elf/i860.h"
28
32d920dd 29/* special_function for R_860_PC26 relocation. */
d539b3aa
CG
30static bfd_reloc_status_type
31i860_howto_pc26_reloc (bfd *abfd ATTRIBUTE_UNUSED,
07d6d2b8
AM
32 arelent *reloc_entry,
33 asymbol *symbol,
34 void *data ATTRIBUTE_UNUSED,
35 asection *input_section,
36 bfd *output_bfd,
37 char **error_message ATTRIBUTE_UNUSED)
d539b3aa 38{
1c0881dd
CG
39 bfd_vma insn;
40 bfd_vma relocation;
41 bfd_byte *addr;
42
d539b3aa
CG
43 if (output_bfd != NULL
44 && (symbol->flags & BSF_SECTION_SYM) == 0
45 && (! reloc_entry->howto->partial_inplace
46 || reloc_entry->addend == 0))
47 {
48 reloc_entry->address += input_section->output_offset;
49 return bfd_reloc_ok;
50 }
51
1c0881dd
CG
52 /* Used elf32-mips.c as an example. */
53 if (bfd_is_und_section (symbol->section)
54 && output_bfd == (bfd *) NULL)
55 return bfd_reloc_undefined;
56
57 if (bfd_is_com_section (symbol->section))
58 relocation = 0;
59 else
60 relocation = symbol->value;
61
62 relocation += symbol->section->output_section->vma;
63 relocation += symbol->section->output_offset;
64 relocation += reloc_entry->addend;
65
07515404 66 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
1c0881dd
CG
67 return bfd_reloc_outofrange;
68
69 /* Adjust for PC-relative relocation. */
70 relocation -= (input_section->output_section->vma
07d6d2b8
AM
71 + input_section->output_offset
72 + reloc_entry->address
73 + 4);
1c0881dd
CG
74
75 /* Check for target out of range. */
76 if ((bfd_signed_vma)relocation > (0x3ffffff << 2)
b6518b38 77 || (bfd_signed_vma)relocation < (-0x4000000 * 4))
1c0881dd
CG
78 return bfd_reloc_outofrange;
79
80 addr = (bfd_byte *) data + reloc_entry->address;
81 insn = bfd_get_32 (abfd, addr);
82
83 relocation >>= reloc_entry->howto->rightshift;
84 insn = (insn & ~reloc_entry->howto->dst_mask)
07d6d2b8 85 | (relocation & reloc_entry->howto->dst_mask);
1c0881dd
CG
86
87 bfd_put_32 (abfd, (bfd_vma) insn, addr);
88
89 return bfd_reloc_ok;
d539b3aa
CG
90}
91
92/* special_function for R_860_PC16 relocation. */
93static bfd_reloc_status_type
94i860_howto_pc16_reloc (bfd *abfd,
07d6d2b8
AM
95 arelent *reloc_entry,
96 asymbol *symbol,
97 void *data,
98 asection *input_section,
99 bfd *output_bfd,
100 char **error_message ATTRIBUTE_UNUSED)
d539b3aa
CG
101{
102 bfd_vma insn;
103 bfd_vma relocation;
104 bfd_byte *addr;
105
106 if (output_bfd != NULL
107 && (symbol->flags & BSF_SECTION_SYM) == 0
108 && (! reloc_entry->howto->partial_inplace
109 || reloc_entry->addend == 0))
110 {
111 reloc_entry->address += input_section->output_offset;
112 return bfd_reloc_ok;
113 }
114
115 /* Used elf32-mips.c as an example. */
116 if (bfd_is_und_section (symbol->section)
117 && output_bfd == (bfd *) NULL)
118 return bfd_reloc_undefined;
119
120 if (bfd_is_com_section (symbol->section))
121 relocation = 0;
122 else
123 relocation = symbol->value;
124
125 relocation += symbol->section->output_section->vma;
126 relocation += symbol->section->output_offset;
127 relocation += reloc_entry->addend;
128
07515404 129 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
d539b3aa
CG
130 return bfd_reloc_outofrange;
131
132 /* Adjust for PC-relative relocation. */
133 relocation -= (input_section->output_section->vma
07d6d2b8
AM
134 + input_section->output_offset
135 + reloc_entry->address
136 + 4);
d539b3aa
CG
137
138 /* Check for target out of range. */
139 if ((bfd_signed_vma)relocation > (0x7fff << 2)
b6518b38 140 || (bfd_signed_vma)relocation < (-0x8000 * 4))
d539b3aa
CG
141 return bfd_reloc_outofrange;
142
143 addr = (bfd_byte *) data + reloc_entry->address;
144 insn = bfd_get_32 (abfd, addr);
145
146 relocation >>= reloc_entry->howto->rightshift;
147 relocation = (((relocation & 0xf800) << 5) | (relocation & 0x7ff))
07d6d2b8 148 & reloc_entry->howto->dst_mask;
d539b3aa
CG
149 insn = (insn & ~reloc_entry->howto->dst_mask) | relocation;
150
151 bfd_put_32 (abfd, (bfd_vma) insn, addr);
152
153 return bfd_reloc_ok;
154}
155
156/* special_function for R_860_HIGHADJ relocation. */
157static bfd_reloc_status_type
158i860_howto_highadj_reloc (bfd *abfd,
07d6d2b8
AM
159 arelent *reloc_entry,
160 asymbol *symbol,
161 void *data,
162 asection *input_section,
163 bfd *output_bfd,
164 char **error_message ATTRIBUTE_UNUSED)
d539b3aa
CG
165{
166 bfd_vma insn;
167 bfd_vma relocation;
168 bfd_byte *addr;
169
170 if (output_bfd != NULL
171 && (symbol->flags & BSF_SECTION_SYM) == 0
172 && (! reloc_entry->howto->partial_inplace
173 || reloc_entry->addend == 0))
174 {
175 reloc_entry->address += input_section->output_offset;
176 return bfd_reloc_ok;
177 }
178
179 /* Used elf32-mips.c as an example. */
180 if (bfd_is_und_section (symbol->section)
181 && output_bfd == (bfd *) NULL)
182 return bfd_reloc_undefined;
183
184 if (bfd_is_com_section (symbol->section))
185 relocation = 0;
186 else
187 relocation = symbol->value;
188
189 relocation += symbol->section->output_section->vma;
190 relocation += symbol->section->output_offset;
191 relocation += reloc_entry->addend;
192 relocation += 0x8000;
193
07515404 194 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
d539b3aa
CG
195 return bfd_reloc_outofrange;
196
197 addr = (bfd_byte *) data + reloc_entry->address;
198 insn = bfd_get_32 (abfd, addr);
199
200 relocation = ((relocation >> 16) & 0xffff);
201
202 insn = (insn & 0xffff0000) | relocation;
203
204 bfd_put_32 (abfd, (bfd_vma) insn, addr);
205
206 return bfd_reloc_ok;
207}
208
209/* special_function for R_860_SPLITn relocations. */
210static bfd_reloc_status_type
211i860_howto_splitn_reloc (bfd *abfd,
07d6d2b8
AM
212 arelent *reloc_entry,
213 asymbol *symbol,
214 void *data,
215 asection *input_section,
216 bfd *output_bfd,
217 char **error_message ATTRIBUTE_UNUSED)
d539b3aa
CG
218{
219 bfd_vma insn;
220 bfd_vma relocation;
221 bfd_byte *addr;
222
223 if (output_bfd != NULL
224 && (symbol->flags & BSF_SECTION_SYM) == 0
225 && (! reloc_entry->howto->partial_inplace
226 || reloc_entry->addend == 0))
227 {
228 reloc_entry->address += input_section->output_offset;
229 return bfd_reloc_ok;
230 }
231
232 /* Used elf32-mips.c as an example. */
233 if (bfd_is_und_section (symbol->section)
234 && output_bfd == (bfd *) NULL)
235 return bfd_reloc_undefined;
236
237 if (bfd_is_com_section (symbol->section))
238 relocation = 0;
239 else
240 relocation = symbol->value;
241
242 relocation += symbol->section->output_section->vma;
243 relocation += symbol->section->output_offset;
244 relocation += reloc_entry->addend;
245
07515404 246 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
d539b3aa
CG
247 return bfd_reloc_outofrange;
248
249 addr = (bfd_byte *) data + reloc_entry->address;
250 insn = bfd_get_32 (abfd, addr);
251
252 relocation = (((relocation & 0xf800) << 5) | (relocation & 0x7ff))
07d6d2b8 253 & reloc_entry->howto->dst_mask;
d539b3aa
CG
254 insn = (insn & ~reloc_entry->howto->dst_mask) | relocation;
255
256 bfd_put_32 (abfd, (bfd_vma) insn, addr);
257
258 return bfd_reloc_ok;
259}
de24da47 260
0e5136c6
JE
261/* This howto table is preliminary. */
262static reloc_howto_type elf32_i860_howto_table [] =
263{
264 /* This relocation does nothing. */
265 HOWTO (R_860_NONE, /* type */
266 0, /* rightshift */
6346d5ca
AM
267 3, /* size (0 = byte, 1 = short, 2 = long) */
268 0, /* bitsize */
b34976b6 269 FALSE, /* pc_relative */
0e5136c6 270 0, /* bitpos */
6346d5ca 271 complain_overflow_dont, /* complain_on_overflow */
0e5136c6
JE
272 bfd_elf_generic_reloc, /* special_function */
273 "R_860_NONE", /* name */
b34976b6 274 FALSE, /* partial_inplace */
0e5136c6
JE
275 0, /* src_mask */
276 0, /* dst_mask */
b34976b6 277 FALSE), /* pcrel_offset */
0e5136c6
JE
278
279 /* A 32-bit absolute relocation. */
280 HOWTO (R_860_32, /* type */
281 0, /* rightshift */
282 2, /* size (0 = byte, 1 = short, 2 = long) */
283 32, /* bitsize */
b34976b6 284 FALSE, /* pc_relative */
0e5136c6
JE
285 0, /* bitpos */
286 complain_overflow_bitfield, /* complain_on_overflow */
287 bfd_elf_generic_reloc, /* special_function */
288 "R_860_32", /* name */
b34976b6 289 FALSE, /* partial_inplace */
0e5136c6
JE
290 0xffffffff, /* src_mask */
291 0xffffffff, /* dst_mask */
b34976b6 292 FALSE), /* pcrel_offset */
0e5136c6
JE
293
294 HOWTO (R_860_COPY, /* type */
295 0, /* rightshift */
296 2, /* size (0 = byte, 1 = short, 2 = long) */
297 32, /* bitsize */
b34976b6 298 FALSE, /* pc_relative */
0e5136c6
JE
299 0, /* bitpos */
300 complain_overflow_bitfield, /* complain_on_overflow */
301 bfd_elf_generic_reloc, /* special_function */
302 "R_860_COPY", /* name */
b34976b6 303 TRUE, /* partial_inplace */
0e5136c6
JE
304 0xffffffff, /* src_mask */
305 0xffffffff, /* dst_mask */
b34976b6 306 FALSE), /* pcrel_offset */
0e5136c6
JE
307
308 HOWTO (R_860_GLOB_DAT, /* type */
309 0, /* rightshift */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
311 32, /* bitsize */
b34976b6 312 FALSE, /* pc_relative */
0e5136c6
JE
313 0, /* bitpos */
314 complain_overflow_bitfield, /* complain_on_overflow */
315 bfd_elf_generic_reloc, /* special_function */
316 "R_860_GLOB_DAT", /* name */
b34976b6 317 TRUE, /* partial_inplace */
0e5136c6
JE
318 0xffffffff, /* src_mask */
319 0xffffffff, /* dst_mask */
b34976b6 320 FALSE), /* pcrel_offset */
0e5136c6
JE
321
322 HOWTO (R_860_JUMP_SLOT, /* type */
323 0, /* rightshift */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
325 32, /* bitsize */
b34976b6 326 FALSE, /* pc_relative */
0e5136c6
JE
327 0, /* bitpos */
328 complain_overflow_bitfield, /* complain_on_overflow */
329 bfd_elf_generic_reloc, /* special_function */
330 "R_860_JUMP_SLOT", /* name */
b34976b6 331 TRUE, /* partial_inplace */
0e5136c6
JE
332 0xffffffff, /* src_mask */
333 0xffffffff, /* dst_mask */
b34976b6 334 FALSE), /* pcrel_offset */
0e5136c6
JE
335
336 HOWTO (R_860_RELATIVE, /* type */
337 0, /* rightshift */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
339 32, /* bitsize */
b34976b6 340 FALSE, /* pc_relative */
0e5136c6
JE
341 0, /* bitpos */
342 complain_overflow_bitfield, /* complain_on_overflow */
343 bfd_elf_generic_reloc, /* special_function */
344 "R_860_RELATIVE", /* name */
b34976b6 345 TRUE, /* partial_inplace */
0e5136c6
JE
346 0xffffffff, /* src_mask */
347 0xffffffff, /* dst_mask */
b34976b6 348 FALSE), /* pcrel_offset */
0e5136c6
JE
349
350 /* A 26-bit PC-relative relocation. */
07d6d2b8 351 HOWTO (R_860_PC26, /* type */
fdeafce7 352 2, /* rightshift */
0e5136c6
JE
353 2, /* size (0 = byte, 1 = short, 2 = long) */
354 26, /* bitsize */
b34976b6 355 TRUE, /* pc_relative */
0e5136c6
JE
356 0, /* bitpos */
357 complain_overflow_bitfield, /* complain_on_overflow */
d539b3aa 358 i860_howto_pc26_reloc, /* special_function */
0e5136c6 359 "R_860_PC26", /* name */
b34976b6 360 FALSE, /* partial_inplace */
0e5136c6
JE
361 0x3ffffff, /* src_mask */
362 0x3ffffff, /* dst_mask */
07d6d2b8 363 TRUE), /* pcrel_offset */
0e5136c6 364
07d6d2b8 365 HOWTO (R_860_PLT26, /* type */
0e5136c6
JE
366 0, /* rightshift */
367 2, /* size (0 = byte, 1 = short, 2 = long) */
368 26, /* bitsize */
b34976b6 369 TRUE, /* pc_relative */
0e5136c6
JE
370 0, /* bitpos */
371 complain_overflow_bitfield, /* complain_on_overflow */
372 bfd_elf_generic_reloc, /* special_function */
373 "R_860_PLT26", /* name */
b34976b6 374 TRUE, /* partial_inplace */
0e5136c6
JE
375 0xffffffff, /* src_mask */
376 0xffffffff, /* dst_mask */
07d6d2b8 377 TRUE), /* pcrel_offset */
0e5136c6
JE
378
379 /* A 16-bit PC-relative relocation. */
07d6d2b8 380 HOWTO (R_860_PC16, /* type */
fdeafce7 381 2, /* rightshift */
0e5136c6
JE
382 2, /* size (0 = byte, 1 = short, 2 = long) */
383 16, /* bitsize */
b34976b6 384 TRUE, /* pc_relative */
0e5136c6
JE
385 0, /* bitpos */
386 complain_overflow_bitfield, /* complain_on_overflow */
d539b3aa 387 i860_howto_pc16_reloc, /* special_function */
0e5136c6 388 "R_860_PC16", /* name */
b34976b6 389 FALSE, /* partial_inplace */
305d537e
JE
390 0x1f07ff, /* src_mask */
391 0x1f07ff, /* dst_mask */
07d6d2b8 392 TRUE), /* pcrel_offset */
0e5136c6 393
07d6d2b8 394 HOWTO (R_860_LOW0, /* type */
0e5136c6
JE
395 0, /* rightshift */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
397 16, /* bitsize */
b34976b6 398 FALSE, /* pc_relative */
0e5136c6
JE
399 0, /* bitpos */
400 complain_overflow_dont, /* complain_on_overflow */
401 bfd_elf_generic_reloc, /* special_function */
402 "R_860_LOW0", /* name */
b34976b6 403 FALSE, /* partial_inplace */
0e5136c6
JE
404 0xffff, /* src_mask */
405 0xffff, /* dst_mask */
07d6d2b8 406 FALSE), /* pcrel_offset */
0e5136c6 407
07d6d2b8 408 HOWTO (R_860_SPLIT0, /* type */
0e5136c6
JE
409 0, /* rightshift */
410 2, /* size (0 = byte, 1 = short, 2 = long) */
411 16, /* bitsize */
b34976b6 412 FALSE, /* pc_relative */
0e5136c6
JE
413 0, /* bitpos */
414 complain_overflow_dont, /* complain_on_overflow */
d539b3aa 415 i860_howto_splitn_reloc, /* special_function */
0e5136c6 416 "R_860_SPLIT0", /* name */
b34976b6 417 FALSE, /* partial_inplace */
0e5136c6
JE
418 0x1f07ff, /* src_mask */
419 0x1f07ff, /* dst_mask */
07d6d2b8 420 FALSE), /* pcrel_offset */
0e5136c6 421
07d6d2b8 422 HOWTO (R_860_LOW1, /* type */
0e5136c6
JE
423 0, /* rightshift */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
425 16, /* bitsize */
b34976b6 426 FALSE, /* pc_relative */
0e5136c6
JE
427 0, /* bitpos */
428 complain_overflow_dont, /* complain_on_overflow */
429 bfd_elf_generic_reloc, /* special_function */
430 "R_860_LOW1", /* name */
b34976b6 431 FALSE, /* partial_inplace */
0e5136c6
JE
432 0xfffe, /* src_mask */
433 0xfffe, /* dst_mask */
07d6d2b8 434 FALSE), /* pcrel_offset */
0e5136c6 435
07d6d2b8 436 HOWTO (R_860_SPLIT1, /* type */
0e5136c6
JE
437 0, /* rightshift */
438 2, /* size (0 = byte, 1 = short, 2 = long) */
439 16, /* bitsize */
b34976b6 440 FALSE, /* pc_relative */
0e5136c6
JE
441 0, /* bitpos */
442 complain_overflow_dont, /* complain_on_overflow */
d539b3aa 443 i860_howto_splitn_reloc, /* special_function */
0e5136c6 444 "R_860_SPLIT1", /* name */
b34976b6 445 FALSE, /* partial_inplace */
305d537e
JE
446 0x1f07fe, /* src_mask */
447 0x1f07fe, /* dst_mask */
07d6d2b8 448 FALSE), /* pcrel_offset */
0e5136c6 449
07d6d2b8 450 HOWTO (R_860_LOW2, /* type */
0e5136c6
JE
451 0, /* rightshift */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
453 16, /* bitsize */
b34976b6 454 FALSE, /* pc_relative */
0e5136c6
JE
455 0, /* bitpos */
456 complain_overflow_dont, /* complain_on_overflow */
457 bfd_elf_generic_reloc, /* special_function */
458 "R_860_LOW2", /* name */
b34976b6 459 FALSE, /* partial_inplace */
0e5136c6
JE
460 0xfffc, /* src_mask */
461 0xfffc, /* dst_mask */
07d6d2b8 462 FALSE), /* pcrel_offset */
0e5136c6 463
07d6d2b8 464 HOWTO (R_860_SPLIT2, /* type */
0e5136c6
JE
465 0, /* rightshift */
466 2, /* size (0 = byte, 1 = short, 2 = long) */
467 16, /* bitsize */
b34976b6 468 FALSE, /* pc_relative */
0e5136c6
JE
469 0, /* bitpos */
470 complain_overflow_dont, /* complain_on_overflow */
d539b3aa 471 i860_howto_splitn_reloc, /* special_function */
0e5136c6 472 "R_860_SPLIT2", /* name */
b34976b6 473 FALSE, /* partial_inplace */
305d537e
JE
474 0x1f07fc, /* src_mask */
475 0x1f07fc, /* dst_mask */
07d6d2b8 476 FALSE), /* pcrel_offset */
0e5136c6 477
07d6d2b8 478 HOWTO (R_860_LOW3, /* type */
0e5136c6
JE
479 0, /* rightshift */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
481 16, /* bitsize */
b34976b6 482 FALSE, /* pc_relative */
0e5136c6
JE
483 0, /* bitpos */
484 complain_overflow_dont, /* complain_on_overflow */
485 bfd_elf_generic_reloc, /* special_function */
486 "R_860_LOW3", /* name */
b34976b6 487 FALSE, /* partial_inplace */
0e5136c6
JE
488 0xfff8, /* src_mask */
489 0xfff8, /* dst_mask */
07d6d2b8 490 FALSE), /* pcrel_offset */
0e5136c6 491
07d6d2b8 492 HOWTO (R_860_LOGOT0, /* type */
0e5136c6
JE
493 0, /* rightshift */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
495 16, /* bitsize */
b34976b6 496 FALSE, /* pc_relative */
0e5136c6
JE
497 0, /* bitpos */
498 complain_overflow_dont, /* complain_on_overflow */
499 bfd_elf_generic_reloc, /* special_function */
500 "R_860_LOGOT0", /* name */
b34976b6 501 FALSE, /* partial_inplace */
0e5136c6
JE
502 0, /* src_mask */
503 0xffff, /* dst_mask */
07d6d2b8 504 TRUE), /* pcrel_offset */
0e5136c6 505
07d6d2b8 506 HOWTO (R_860_SPGOT0, /* type */
0e5136c6
JE
507 0, /* rightshift */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
509 16, /* bitsize */
b34976b6 510 FALSE, /* pc_relative */
0e5136c6
JE
511 0, /* bitpos */
512 complain_overflow_dont, /* complain_on_overflow */
513 bfd_elf_generic_reloc, /* special_function */
514 "R_860_SPGOT0", /* name */
b34976b6 515 FALSE, /* partial_inplace */
0e5136c6
JE
516 0, /* src_mask */
517 0xffff, /* dst_mask */
07d6d2b8 518 TRUE), /* pcrel_offset */
0e5136c6 519
07d6d2b8 520 HOWTO (R_860_LOGOT1, /* type */
0e5136c6
JE
521 0, /* rightshift */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
523 16, /* bitsize */
b34976b6 524 FALSE, /* pc_relative */
0e5136c6
JE
525 0, /* bitpos */
526 complain_overflow_dont, /* complain_on_overflow */
527 bfd_elf_generic_reloc, /* special_function */
528 "R_860_LOGOT1", /* name */
b34976b6 529 FALSE, /* partial_inplace */
0e5136c6
JE
530 0, /* src_mask */
531 0xffff, /* dst_mask */
07d6d2b8 532 TRUE), /* pcrel_offset */
0e5136c6 533
07d6d2b8 534 HOWTO (R_860_SPGOT1, /* type */
0e5136c6
JE
535 0, /* rightshift */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
537 16, /* bitsize */
b34976b6 538 FALSE, /* pc_relative */
0e5136c6
JE
539 0, /* bitpos */
540 complain_overflow_dont, /* complain_on_overflow */
541 bfd_elf_generic_reloc, /* special_function */
542 "R_860_SPGOT1", /* name */
b34976b6 543 FALSE, /* partial_inplace */
0e5136c6
JE
544 0, /* src_mask */
545 0xffff, /* dst_mask */
07d6d2b8 546 TRUE), /* pcrel_offset */
0e5136c6 547
07d6d2b8 548 HOWTO (R_860_LOGOTOFF0, /* type */
0e5136c6
JE
549 0, /* rightshift */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
551 32, /* bitsize */
b34976b6 552 FALSE, /* pc_relative */
0e5136c6
JE
553 0, /* bitpos */
554 complain_overflow_dont, /* complain_on_overflow */
555 bfd_elf_generic_reloc, /* special_function */
556 "R_860_LOGOTOFF0", /* name */
b34976b6 557 TRUE, /* partial_inplace */
0e5136c6
JE
558 0xffffffff, /* src_mask */
559 0xffffffff, /* dst_mask */
07d6d2b8 560 FALSE), /* pcrel_offset */
0e5136c6 561
07d6d2b8 562 HOWTO (R_860_SPGOTOFF0, /* type */
0e5136c6
JE
563 0, /* rightshift */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
565 32, /* bitsize */
b34976b6 566 FALSE, /* pc_relative */
0e5136c6
JE
567 0, /* bitpos */
568 complain_overflow_dont, /* complain_on_overflow */
569 bfd_elf_generic_reloc, /* special_function */
570 "R_860_SPGOTOFF0", /* name */
b34976b6 571 TRUE, /* partial_inplace */
0e5136c6
JE
572 0xffffffff, /* src_mask */
573 0xffffffff, /* dst_mask */
07d6d2b8 574 FALSE), /* pcrel_offset */
0e5136c6 575
07d6d2b8 576 HOWTO (R_860_LOGOTOFF1, /* type */
0e5136c6
JE
577 0, /* rightshift */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
579 32, /* bitsize */
b34976b6 580 FALSE, /* pc_relative */
0e5136c6
JE
581 0, /* bitpos */
582 complain_overflow_dont, /* complain_on_overflow */
583 bfd_elf_generic_reloc, /* special_function */
584 "R_860_LOGOTOFF1", /* name */
b34976b6 585 TRUE, /* partial_inplace */
0e5136c6
JE
586 0xffffffff, /* src_mask */
587 0xffffffff, /* dst_mask */
07d6d2b8 588 FALSE), /* pcrel_offset */
0e5136c6
JE
589
590 HOWTO (R_860_SPGOTOFF1, /* type */
591 0, /* rightshift */
592 2, /* size (0 = byte, 1 = short, 2 = long) */
593 32, /* bitsize */
b34976b6 594 FALSE, /* pc_relative */
0e5136c6
JE
595 0, /* bitpos */
596 complain_overflow_dont, /* complain_on_overflow */
597 bfd_elf_generic_reloc, /* special_function */
598 "R_860_SPGOTOFF1", /* name */
b34976b6 599 TRUE, /* partial_inplace */
0e5136c6
JE
600 0xffffffff, /* src_mask */
601 0xffffffff, /* dst_mask */
07d6d2b8 602 FALSE), /* pcrel_offset */
0e5136c6 603
07d6d2b8 604 HOWTO (R_860_LOGOTOFF2, /* type */
0e5136c6
JE
605 0, /* rightshift */
606 2, /* size (0 = byte, 1 = short, 2 = long) */
607 32, /* bitsize */
b34976b6 608 FALSE, /* pc_relative */
0e5136c6
JE
609 0, /* bitpos */
610 complain_overflow_dont, /* complain_on_overflow */
611 bfd_elf_generic_reloc, /* special_function */
612 "R_860_LOGOTOFF2", /* name */
b34976b6 613 TRUE, /* partial_inplace */
0e5136c6
JE
614 0xffffffff, /* src_mask */
615 0xffffffff, /* dst_mask */
07d6d2b8 616 FALSE), /* pcrel_offset */
0e5136c6 617
07d6d2b8 618 HOWTO (R_860_LOGOTOFF3, /* type */
0e5136c6
JE
619 0, /* rightshift */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
621 32, /* bitsize */
b34976b6 622 FALSE, /* pc_relative */
0e5136c6
JE
623 0, /* bitpos */
624 complain_overflow_dont, /* complain_on_overflow */
625 bfd_elf_generic_reloc, /* special_function */
626 "R_860_LOGOTOFF3", /* name */
b34976b6 627 TRUE, /* partial_inplace */
0e5136c6
JE
628 0xffffffff, /* src_mask */
629 0xffffffff, /* dst_mask */
07d6d2b8 630 FALSE), /* pcrel_offset */
0e5136c6 631
07d6d2b8 632 HOWTO (R_860_LOPC, /* type */
0e5136c6
JE
633 0, /* rightshift */
634 2, /* size (0 = byte, 1 = short, 2 = long) */
635 16, /* bitsize */
b34976b6 636 TRUE, /* pc_relative */
0e5136c6
JE
637 0, /* bitpos */
638 complain_overflow_bitfield, /* complain_on_overflow */
639 bfd_elf_generic_reloc, /* special_function */
640 "R_860_LOPC", /* name */
b34976b6 641 FALSE, /* partial_inplace */
0e5136c6
JE
642 0xffff, /* src_mask */
643 0xffff, /* dst_mask */
07d6d2b8 644 TRUE), /* pcrel_offset */
0e5136c6 645
07d6d2b8 646 HOWTO (R_860_HIGHADJ, /* type */
0e5136c6
JE
647 0, /* rightshift */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
649 16, /* bitsize */
b34976b6 650 FALSE, /* pc_relative */
0e5136c6
JE
651 0, /* bitpos */
652 complain_overflow_dont, /* complain_on_overflow */
d539b3aa 653 i860_howto_highadj_reloc, /* special_function */
0e5136c6 654 "R_860_HIGHADJ", /* name */
b34976b6 655 FALSE, /* partial_inplace */
0e5136c6
JE
656 0xffff, /* src_mask */
657 0xffff, /* dst_mask */
07d6d2b8 658 FALSE), /* pcrel_offset */
0e5136c6 659
07d6d2b8 660 HOWTO (R_860_HAGOT, /* type */
0e5136c6
JE
661 0, /* rightshift */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
663 16, /* bitsize */
b34976b6 664 FALSE, /* pc_relative */
0e5136c6
JE
665 0, /* bitpos */
666 complain_overflow_dont, /* complain_on_overflow */
667 bfd_elf_generic_reloc, /* special_function */
668 "R_860_HAGOT", /* name */
b34976b6 669 FALSE, /* partial_inplace */
0e5136c6
JE
670 0, /* src_mask */
671 0xffff, /* dst_mask */
07d6d2b8 672 TRUE), /* pcrel_offset */
0e5136c6 673
07d6d2b8 674 HOWTO (R_860_HAGOTOFF, /* type */
0e5136c6
JE
675 0, /* rightshift */
676 2, /* size (0 = byte, 1 = short, 2 = long) */
677 32, /* bitsize */
b34976b6 678 FALSE, /* pc_relative */
0e5136c6
JE
679 0, /* bitpos */
680 complain_overflow_dont, /* complain_on_overflow */
681 bfd_elf_generic_reloc, /* special_function */
682 "R_860_HAGOTOFF", /* name */
b34976b6 683 TRUE, /* partial_inplace */
0e5136c6
JE
684 0xffffffff, /* src_mask */
685 0xffffffff, /* dst_mask */
07d6d2b8 686 FALSE), /* pcrel_offset */
0e5136c6 687
07d6d2b8 688 HOWTO (R_860_HAPC, /* type */
0e5136c6
JE
689 0, /* rightshift */
690 2, /* size (0 = byte, 1 = short, 2 = long) */
691 16, /* bitsize */
b34976b6 692 TRUE, /* pc_relative */
0e5136c6
JE
693 0, /* bitpos */
694 complain_overflow_bitfield, /* complain_on_overflow */
695 bfd_elf_generic_reloc, /* special_function */
696 "R_860_HAPC", /* name */
b34976b6 697 FALSE, /* partial_inplace */
0e5136c6
JE
698 0xffff, /* src_mask */
699 0xffff, /* dst_mask */
07d6d2b8 700 TRUE), /* pcrel_offset */
0e5136c6 701
07d6d2b8 702 HOWTO (R_860_HIGH, /* type */
fdeafce7 703 16, /* rightshift */
0e5136c6
JE
704 2, /* size (0 = byte, 1 = short, 2 = long) */
705 16, /* bitsize */
b34976b6 706 FALSE, /* pc_relative */
0e5136c6
JE
707 0, /* bitpos */
708 complain_overflow_dont, /* complain_on_overflow */
709 bfd_elf_generic_reloc, /* special_function */
710 "R_860_HIGH", /* name */
b34976b6 711 FALSE, /* partial_inplace */
0e5136c6
JE
712 0xffff, /* src_mask */
713 0xffff, /* dst_mask */
07d6d2b8 714 FALSE), /* pcrel_offset */
0e5136c6 715
07d6d2b8 716 HOWTO (R_860_HIGOT, /* type */
0e5136c6
JE
717 0, /* rightshift */
718 2, /* size (0 = byte, 1 = short, 2 = long) */
719 16, /* bitsize */
b34976b6 720 FALSE, /* pc_relative */
0e5136c6
JE
721 0, /* bitpos */
722 complain_overflow_dont, /* complain_on_overflow */
723 bfd_elf_generic_reloc, /* special_function */
724 "R_860_HIGOT", /* name */
b34976b6 725 FALSE, /* partial_inplace */
0e5136c6
JE
726 0, /* src_mask */
727 0xffff, /* dst_mask */
07d6d2b8 728 TRUE), /* pcrel_offset */
0e5136c6 729
07d6d2b8 730 HOWTO (R_860_HIGOTOFF, /* type */
0e5136c6
JE
731 0, /* rightshift */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
733 32, /* bitsize */
b34976b6 734 FALSE, /* pc_relative */
0e5136c6
JE
735 0, /* bitpos */
736 complain_overflow_dont, /* complain_on_overflow */
737 bfd_elf_generic_reloc, /* special_function */
738 "R_860_HIGOTOFF", /* name */
b34976b6 739 TRUE, /* partial_inplace */
0e5136c6
JE
740 0xffffffff, /* src_mask */
741 0xffffffff, /* dst_mask */
07d6d2b8 742 FALSE), /* pcrel_offset */
0e5136c6 743};
0e5136c6
JE
744\f
745static unsigned char elf_code_to_howto_index[R_860_max + 1];
746
747static reloc_howto_type *
5d7c8b80 748lookup_howto (bfd *abfd, unsigned int rtype)
0e5136c6
JE
749{
750 static int initialized = 0;
751 int i;
752 int howto_tbl_size = (int) (sizeof (elf32_i860_howto_table)
753 / sizeof (elf32_i860_howto_table[0]));
5d7c8b80 754 reloc_howto_type *howto = NULL;
0e5136c6
JE
755
756 if (! initialized)
757 {
758 initialized = 1;
759 memset (elf_code_to_howto_index, 0xff,
760 sizeof (elf_code_to_howto_index));
761 for (i = 0; i < howto_tbl_size; i++)
07d6d2b8 762 elf_code_to_howto_index[elf32_i860_howto_table[i].type] = i;
0e5136c6
JE
763 }
764
5d7c8b80
MR
765 if (rtype < R_860_max)
766 {
767 i = elf_code_to_howto_index[rtype];
768 if (i < howto_tbl_size)
769 howto = elf32_i860_howto_table + i;
770 }
771 if (howto == NULL)
772 {
773 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
774 abfd, rtype);
775 bfd_set_error (bfd_error_bad_value);
776 }
777 return howto;
0e5136c6
JE
778}
779
0e5136c6
JE
780/* Given a BFD reloc, return the matching HOWTO structure. */
781static reloc_howto_type *
5d7c8b80 782elf32_i860_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
0e5136c6
JE
783{
784 unsigned int rtype;
785
786 switch (code)
787 {
788 case BFD_RELOC_NONE:
789 rtype = R_860_NONE;
790 break;
791 case BFD_RELOC_32:
792 rtype = R_860_32;
793 break;
794 case BFD_RELOC_860_COPY:
795 rtype = R_860_COPY;
796 break;
797 case BFD_RELOC_860_GLOB_DAT:
6609fa74 798 rtype = R_860_GLOB_DAT;
0e5136c6
JE
799 break;
800 case BFD_RELOC_860_JUMP_SLOT:
801 rtype = R_860_JUMP_SLOT;
802 break;
803 case BFD_RELOC_860_RELATIVE:
804 rtype = R_860_RELATIVE;
805 break;
806 case BFD_RELOC_860_PC26:
807 rtype = R_860_PC26;
808 break;
809 case BFD_RELOC_860_PLT26:
810 rtype = R_860_PLT26;
811 break;
812 case BFD_RELOC_860_PC16:
813 rtype = R_860_PC16;
814 break;
815 case BFD_RELOC_860_LOW0:
816 rtype = R_860_LOW0;
817 break;
818 case BFD_RELOC_860_SPLIT0:
819 rtype = R_860_SPLIT0;
820 break;
821 case BFD_RELOC_860_LOW1:
822 rtype = R_860_LOW1;
823 break;
824 case BFD_RELOC_860_SPLIT1:
825 rtype = R_860_SPLIT1;
826 break;
827 case BFD_RELOC_860_LOW2:
828 rtype = R_860_LOW2;
829 break;
830 case BFD_RELOC_860_SPLIT2:
831 rtype = R_860_SPLIT2;
832 break;
833 case BFD_RELOC_860_LOW3:
834 rtype = R_860_LOW3;
835 break;
836 case BFD_RELOC_860_LOGOT0:
837 rtype = R_860_LOGOT0;
838 break;
839 case BFD_RELOC_860_SPGOT0:
840 rtype = R_860_SPGOT0;
841 break;
842 case BFD_RELOC_860_LOGOT1:
843 rtype = R_860_LOGOT1;
844 break;
845 case BFD_RELOC_860_SPGOT1:
846 rtype = R_860_SPGOT1;
847 break;
848 case BFD_RELOC_860_LOGOTOFF0:
849 rtype = R_860_LOGOTOFF0;
850 break;
851 case BFD_RELOC_860_SPGOTOFF0:
852 rtype = R_860_SPGOTOFF0;
853 break;
854 case BFD_RELOC_860_LOGOTOFF1:
855 rtype = R_860_LOGOTOFF1;
856 break;
857 case BFD_RELOC_860_SPGOTOFF1:
858 rtype = R_860_SPGOTOFF1;
859 break;
860 case BFD_RELOC_860_LOGOTOFF2:
861 rtype = R_860_LOGOTOFF2;
862 break;
863 case BFD_RELOC_860_LOGOTOFF3:
864 rtype = R_860_LOGOTOFF3;
865 break;
866 case BFD_RELOC_860_LOPC:
867 rtype = R_860_LOPC;
868 break;
869 case BFD_RELOC_860_HIGHADJ:
870 rtype = R_860_HIGHADJ;
871 break;
872 case BFD_RELOC_860_HAGOT:
873 rtype = R_860_HAGOT;
874 break;
875 case BFD_RELOC_860_HAGOTOFF:
876 rtype = R_860_HAGOTOFF;
877 break;
878 case BFD_RELOC_860_HAPC:
879 rtype = R_860_HAPC;
880 break;
881 case BFD_RELOC_860_HIGH:
882 rtype = R_860_HIGH;
883 break;
884 case BFD_RELOC_860_HIGOT:
885 rtype = R_860_HIGOT;
886 break;
887 case BFD_RELOC_860_HIGOTOFF:
888 rtype = R_860_HIGOTOFF;
889 break;
890 default:
f3185997 891 return NULL;
0e5136c6 892 }
5d7c8b80 893 return lookup_howto (abfd, rtype);
0e5136c6
JE
894}
895
157090f7
AM
896static reloc_howto_type *
897elf32_i860_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
898 const char *r_name)
899{
900 unsigned int i;
901
902 for (i = 0;
903 i < (sizeof (elf32_i860_howto_table)
904 / sizeof (elf32_i860_howto_table[0]));
905 i++)
906 if (elf32_i860_howto_table[i].name != NULL
907 && strcasecmp (elf32_i860_howto_table[i].name, r_name) == 0)
908 return &elf32_i860_howto_table[i];
909
910 return NULL;
911}
912
0e5136c6 913/* Given a ELF reloc, return the matching HOWTO structure. */
f3185997
NC
914
915static bfd_boolean
5d7c8b80 916elf32_i860_info_to_howto_rela (bfd *abfd,
7734b6e9
JE
917 arelent *bfd_reloc,
918 Elf_Internal_Rela *elf_reloc)
0e5136c6 919{
dc810e39 920 bfd_reloc->howto
5d7c8b80 921 = lookup_howto (abfd, (unsigned) ELF32_R_TYPE (elf_reloc->r_info));
f3185997 922 return bfd_reloc->howto != NULL;
0e5136c6 923}
fdeafce7
JE
924\f
925/* Specialized relocation handler for R_860_SPLITn. These relocations
926 involves a 16-bit field that is split into two contiguous parts. */
927static bfd_reloc_status_type
7734b6e9
JE
928elf32_i860_relocate_splitn (bfd *input_bfd,
929 Elf_Internal_Rela *rello,
930 bfd_byte *contents,
931 bfd_vma value)
fdeafce7 932{
ded0649c 933 bfd_vma insn;
fdeafce7 934 reloc_howto_type *howto;
5d7c8b80 935 howto = lookup_howto (input_bfd, (unsigned) ELF32_R_TYPE (rello->r_info));
fdeafce7
JE
936 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
937
fdeafce7 938 /* Relocate. */
ded0649c 939 value += rello->r_addend;
fdeafce7 940
ded0649c 941 /* Separate the fields and insert. */
a48c6a54 942 value = (((value & 0xf800) << 5) | (value & 0x7ff)) & howto->dst_mask;
fdeafce7
JE
943 insn = (insn & ~howto->dst_mask) | value;
944
945 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
946 return bfd_reloc_ok;
947}
948
fdeafce7
JE
949/* Specialized relocation handler for R_860_PC16. This relocation
950 involves a 16-bit, PC-relative field that is split into two contiguous
951 parts. */
952static bfd_reloc_status_type
7734b6e9
JE
953elf32_i860_relocate_pc16 (bfd *input_bfd,
954 asection *input_section,
955 Elf_Internal_Rela *rello,
956 bfd_byte *contents,
957 bfd_vma value)
fdeafce7 958{
ded0649c 959 bfd_vma insn;
d670a150 960 reloc_howto_type *howto;
5d7c8b80 961 howto = lookup_howto (input_bfd, (unsigned) ELF32_R_TYPE (rello->r_info));
d670a150
JE
962 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
963
964 /* Adjust for PC-relative relocation. */
965 value -= (input_section->output_section->vma
966 + input_section->output_offset);
967 value -= rello->r_offset;
968
d670a150 969 /* Relocate. */
ded0649c 970 value += rello->r_addend;
d670a150 971
f680ea79
JE
972 /* Adjust the value by 4, then separate the fields and insert. */
973 value = (value - 4) >> howto->rightshift;
a48c6a54 974 value = (((value & 0xf800) << 5) | (value & 0x7ff)) & howto->dst_mask;
d670a150
JE
975 insn = (insn & ~howto->dst_mask) | value;
976
977 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
978 return bfd_reloc_ok;
979
fdeafce7 980}
fdeafce7 981
c1e8b710
JE
982/* Specialized relocation handler for R_860_PC26. This relocation
983 involves a 26-bit, PC-relative field which must be adjusted by 4. */
984static bfd_reloc_status_type
7734b6e9
JE
985elf32_i860_relocate_pc26 (bfd *input_bfd,
986 asection *input_section,
987 Elf_Internal_Rela *rello,
988 bfd_byte *contents,
989 bfd_vma value)
c1e8b710
JE
990{
991 bfd_vma insn;
992 reloc_howto_type *howto;
5d7c8b80 993 howto = lookup_howto (input_bfd, (unsigned) ELF32_R_TYPE (rello->r_info));
c1e8b710
JE
994 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
995
996 /* Adjust for PC-relative relocation. */
997 value -= (input_section->output_section->vma
998 + input_section->output_offset);
999 value -= rello->r_offset;
1000
1001 /* Relocate. */
1002 value += rello->r_addend;
1003
1004 /* Adjust value by 4 and insert the field. */
6609fa74 1005 value = ((value - 4) >> howto->rightshift) & howto->dst_mask;
c1e8b710
JE
1006 insn = (insn & ~howto->dst_mask) | value;
1007
1008 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
1009 return bfd_reloc_ok;
1010
1011}
1012
fdeafce7
JE
1013/* Specialized relocation handler for R_860_HIGHADJ. */
1014static bfd_reloc_status_type
7734b6e9
JE
1015elf32_i860_relocate_highadj (bfd *input_bfd,
1016 Elf_Internal_Rela *rel,
1017 bfd_byte *contents,
1018 bfd_vma value)
fdeafce7
JE
1019{
1020 bfd_vma insn;
1021
1022 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
1023
fdeafce7 1024 value += rel->r_addend;
68ffbac6 1025 value += 0x8000;
fdeafce7 1026 value = ((value >> 16) & 0xffff);
fdeafce7
JE
1027
1028 insn = (insn & 0xffff0000) | value;
1029
1030 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
1031 return bfd_reloc_ok;
1032}
1033
fdeafce7
JE
1034/* Perform a single relocation. By default we use the standard BFD
1035 routines. However, we handle some specially. */
1036static bfd_reloc_status_type
7734b6e9
JE
1037i860_final_link_relocate (reloc_howto_type *howto,
1038 bfd *input_bfd,
1039 asection *input_section,
1040 bfd_byte *contents,
1041 Elf_Internal_Rela *rel,
1042 bfd_vma relocation)
fdeafce7
JE
1043{
1044 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1045 contents, rel->r_offset, relocation,
1046 rel->r_addend);
1047}
1048
fdeafce7 1049/* Relocate an i860 ELF section.
252b5132 1050
fdeafce7 1051 This is boiler-plate code copied from fr30.
fdeafce7
JE
1052
1053 The RELOCATE_SECTION function is called by the new ELF backend linker
1054 to handle the relocations for a section.
1055
1056 The relocs are always passed as Rela structures; if the section
1057 actually uses Rel structures, the r_addend field will always be
1058 zero.
1059
1060 This function is responsible for adjusting the section contents as
1049f94e 1061 necessary, and (if using Rela relocs and generating a relocatable
fdeafce7
JE
1062 output file) adjusting the reloc addend as necessary.
1063
1064 This function does not have to worry about setting the reloc
1065 address or the reloc symbol index.
1066
1067 LOCAL_SYMS is a pointer to the swapped in local symbols.
1068
1069 LOCAL_SECTIONS is an array giving the section in the input file
1070 corresponding to the st_shndx field of each local symbol.
1071
1072 The global hash table entry for the global symbols can be found
1073 via elf_sym_hashes (input_bfd).
1074
1049f94e 1075 When generating relocatable output, this function must handle
fdeafce7
JE
1076 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1077 going to be the section symbol corresponding to the output
1078 section, which means that the addend must be adjusted
1079 accordingly. */
b34976b6 1080static bfd_boolean
7734b6e9
JE
1081elf32_i860_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
1082 struct bfd_link_info *info,
1083 bfd *input_bfd,
1084 asection *input_section,
1085 bfd_byte *contents,
1086 Elf_Internal_Rela *relocs,
1087 Elf_Internal_Sym *local_syms,
1088 asection **local_sections)
fdeafce7 1089{
b34976b6
AM
1090 Elf_Internal_Shdr *symtab_hdr;
1091 struct elf_link_hash_entry **sym_hashes;
1092 Elf_Internal_Rela *rel;
1093 Elf_Internal_Rela *relend;
fdeafce7
JE
1094
1095 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
1096 sym_hashes = elf_sym_hashes (input_bfd);
1097 relend = relocs + input_section->reloc_count;
1098
1099 for (rel = relocs; rel < relend; rel ++)
1100 {
07d6d2b8
AM
1101 reloc_howto_type * howto;
1102 unsigned long r_symndx;
1103 Elf_Internal_Sym * sym;
1104 asection * sec;
fdeafce7 1105 struct elf_link_hash_entry * h;
07d6d2b8
AM
1106 bfd_vma relocation;
1107 bfd_reloc_status_type r;
1108 const char * name = NULL;
1109 int r_type;
6609fa74 1110
fdeafce7 1111 r_type = ELF32_R_TYPE (rel->r_info);
fdeafce7
JE
1112 r_symndx = ELF32_R_SYM (rel->r_info);
1113
5d7c8b80 1114 howto = lookup_howto (input_bfd, (unsigned) ELF32_R_TYPE (rel->r_info));
dc810e39
AM
1115 h = NULL;
1116 sym = NULL;
1117 sec = NULL;
6609fa74 1118
fdeafce7
JE
1119 if (r_symndx < symtab_hdr->sh_info)
1120 {
1121 sym = local_syms + r_symndx;
1122 sec = local_sections [r_symndx];
8517fae7 1123 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
6609fa74 1124
fdeafce7
JE
1125 name = bfd_elf_string_from_elf_section
1126 (input_bfd, symtab_hdr->sh_link, sym->st_name);
1127 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
1128 }
1129 else
1130 {
62d887d4 1131 bfd_boolean unresolved_reloc, warned, ignored;
59c2e50f 1132
b2a8e766
AM
1133 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1134 r_symndx, symtab_hdr, sym_hashes,
1135 h, sec, relocation,
62d887d4 1136 unresolved_reloc, warned, ignored);
fdeafce7 1137 }
6609fa74 1138
dbaa2011 1139 if (sec != NULL && discarded_section (sec))
e4067dbb 1140 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
545fd46b 1141 rel, 1, relend, howto, 0, contents);
ab96bf03 1142
0e1862bb 1143 if (bfd_link_relocatable (info))
ab96bf03
AM
1144 continue;
1145
fdeafce7
JE
1146 switch (r_type)
1147 {
1148 default:
1149 r = i860_final_link_relocate (howto, input_bfd, input_section,
1150 contents, rel, relocation);
1151 break;
1152
1153 case R_860_HIGHADJ:
1154 r = elf32_i860_relocate_highadj (input_bfd, rel, contents,
1155 relocation);
1156 break;
1157
fdeafce7 1158 case R_860_PC16:
d670a150
JE
1159 r = elf32_i860_relocate_pc16 (input_bfd, input_section, rel,
1160 contents, relocation);
fdeafce7 1161 break;
fdeafce7 1162
c1e8b710
JE
1163 case R_860_PC26:
1164 r = elf32_i860_relocate_pc26 (input_bfd, input_section, rel,
1165 contents, relocation);
1166 break;
1167
fdeafce7
JE
1168 case R_860_SPLIT0:
1169 case R_860_SPLIT1:
1170 case R_860_SPLIT2:
1171 r = elf32_i860_relocate_splitn (input_bfd, rel, contents,
1172 relocation);
1173 break;
1174
1175 /* We do not yet handle GOT/PLT/Dynamic relocations. */
1176 case R_860_COPY:
1177 case R_860_GLOB_DAT:
1178 case R_860_JUMP_SLOT:
1179 case R_860_RELATIVE:
1180 case R_860_PLT26:
1181 case R_860_LOGOT0:
1182 case R_860_SPGOT0:
1183 case R_860_LOGOT1:
1184 case R_860_SPGOT1:
1185 case R_860_LOGOTOFF0:
1186 case R_860_SPGOTOFF0:
1187 case R_860_LOGOTOFF1:
1188 case R_860_SPGOTOFF1:
1189 case R_860_LOGOTOFF2:
1190 case R_860_LOGOTOFF3:
1191 case R_860_LOPC:
1192 case R_860_HAGOT:
1193 case R_860_HAGOTOFF:
1194 case R_860_HAPC:
1195 case R_860_HIGOT:
1196 case R_860_HIGOTOFF:
1197 r = bfd_reloc_notsupported;
1198 break;
6609fa74 1199 }
fdeafce7
JE
1200
1201 if (r != bfd_reloc_ok)
1202 {
1203 const char * msg = (const char *) NULL;
1204
1205 switch (r)
1206 {
1207 case bfd_reloc_overflow:
1a72702b 1208 (*info->callbacks->reloc_overflow)
dfeffb9f
L
1209 (info, (h ? &h->root : NULL), name, howto->name,
1210 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
fdeafce7 1211 break;
6609fa74 1212
fdeafce7 1213 case bfd_reloc_undefined:
1a72702b 1214 (*info->callbacks->undefined_symbol)
b34976b6 1215 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
fdeafce7 1216 break;
6609fa74 1217
fdeafce7
JE
1218 case bfd_reloc_outofrange:
1219 msg = _("internal error: out of range error");
1220 break;
1221
1222 case bfd_reloc_notsupported:
1223 msg = _("internal error: unsupported relocation error");
1224 break;
1225
1226 case bfd_reloc_dangerous:
1227 msg = _("internal error: dangerous relocation");
1228 break;
1229
1230 default:
1231 msg = _("internal error: unknown error");
1232 break;
1233 }
1234
1235 if (msg)
1a72702b
AM
1236 (*info->callbacks->warning) (info, msg, name, input_bfd,
1237 input_section, rel->r_offset);
fdeafce7
JE
1238 }
1239 }
1240
b34976b6 1241 return TRUE;
fdeafce7
JE
1242}
1243
de24da47
JE
1244/* Return whether a symbol name implies a local label. SVR4/860 compilers
1245 generate labels of the form ".ep.function_name" to denote the end of a
1246 function prolog. These should be local.
1247 ??? Do any other SVR4 compilers have this convention? If so, this should
1248 be added to the generic routine. */
b34976b6 1249static bfd_boolean
7734b6e9 1250elf32_i860_is_local_label_name (bfd *abfd, const char *name)
de24da47
JE
1251{
1252 if (name[0] == '.' && name[1] == 'e' && name[2] == 'p' && name[3] == '.')
b34976b6 1253 return TRUE;
de24da47
JE
1254
1255 return _bfd_elf_is_local_label_name (abfd, name);
1256}
fdeafce7 1257\f
6d00b590 1258#define TARGET_BIG_SYM i860_elf32_vec
9d751335 1259#define TARGET_BIG_NAME "elf32-i860"
6d00b590 1260#define TARGET_LITTLE_SYM i860_elf32_le_vec
9d751335 1261#define TARGET_LITTLE_NAME "elf32-i860-little"
0e5136c6
JE
1262#define ELF_ARCH bfd_arch_i860
1263#define ELF_MACHINE_CODE EM_860
1264#define ELF_MAXPAGESIZE 4096
1265
b491616a 1266#define elf_backend_rela_normal 1
07d6d2b8 1267#define elf_info_to_howto_rel NULL
0e5136c6 1268#define elf_info_to_howto elf32_i860_info_to_howto_rela
fdeafce7 1269#define elf_backend_relocate_section elf32_i860_relocate_section
0e5136c6 1270#define bfd_elf32_bfd_reloc_type_lookup elf32_i860_reloc_type_lookup
157090f7 1271#define bfd_elf32_bfd_reloc_name_lookup elf32_i860_reloc_name_lookup
de24da47 1272#define bfd_elf32_bfd_is_local_label_name elf32_i860_is_local_label_name
252b5132
RH
1273
1274#include "elf32-target.h"
This page took 1.019476 seconds and 4 git commands to generate.