* elfcode.h (elf_swap_ehdr_out): Adjust value written for e_shnum
[deliverable/binutils-gdb.git] / bfd / reloc.c
CommitLineData
252b5132 1/* BFD support for handling relocation entries.
7898deda
NC
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001
252b5132
RH
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
6
7This file is part of BFD, the Binary File Descriptor library.
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
23/*
24SECTION
25 Relocations
26
27 BFD maintains relocations in much the same way it maintains
28 symbols: they are left alone until required, then read in
3f9b03b5 29 en-masse and translated into an internal form. A common
252b5132
RH
30 routine <<bfd_perform_relocation>> acts upon the
31 canonical form to do the fixup.
32
33 Relocations are maintained on a per section basis,
34 while symbols are maintained on a per BFD basis.
35
36 All that a back end has to do to fit the BFD interface is to create
37 a <<struct reloc_cache_entry>> for each relocation
38 in a particular section, and fill in the right bits of the structures.
39
40@menu
41@* typedef arelent::
42@* howto manager::
43@end menu
44
45*/
46
47/* DO compile in the reloc_code name table from libbfd.h. */
48#define _BFD_MAKE_TABLE_bfd_reloc_code_real
49
50#include "bfd.h"
51#include "sysdep.h"
52#include "bfdlink.h"
53#include "libbfd.h"
54/*
55DOCDD
56INODE
57 typedef arelent, howto manager, Relocations, Relocations
58
59SUBSECTION
60 typedef arelent
61
62 This is the structure of a relocation entry:
63
64CODE_FRAGMENT
65.
66.typedef enum bfd_reloc_status
67.{
dc810e39 68. {* No errors detected *}
252b5132
RH
69. bfd_reloc_ok,
70.
dc810e39 71. {* The relocation was performed, but there was an overflow. *}
252b5132
RH
72. bfd_reloc_overflow,
73.
dc810e39 74. {* The address to relocate was not within the section supplied. *}
252b5132
RH
75. bfd_reloc_outofrange,
76.
dc810e39 77. {* Used by special functions *}
252b5132
RH
78. bfd_reloc_continue,
79.
dc810e39 80. {* Unsupported relocation size requested. *}
252b5132
RH
81. bfd_reloc_notsupported,
82.
dc810e39 83. {* Unused *}
252b5132
RH
84. bfd_reloc_other,
85.
dc810e39 86. {* The symbol to relocate against was undefined. *}
252b5132
RH
87. bfd_reloc_undefined,
88.
dc810e39
AM
89. {* The relocation was performed, but may not be ok - presently
90. generated only when linking i960 coff files with i960 b.out
91. symbols. If this type is returned, the error_message argument
92. to bfd_perform_relocation will be set. *}
252b5132
RH
93. bfd_reloc_dangerous
94. }
95. bfd_reloc_status_type;
96.
97.
98.typedef struct reloc_cache_entry
99.{
dc810e39 100. {* A pointer into the canonical table of pointers *}
252b5132
RH
101. struct symbol_cache_entry **sym_ptr_ptr;
102.
dc810e39 103. {* offset in section *}
252b5132
RH
104. bfd_size_type address;
105.
dc810e39 106. {* addend for relocation value *}
252b5132
RH
107. bfd_vma addend;
108.
dc810e39 109. {* Pointer to how to perform the required relocation *}
252b5132
RH
110. reloc_howto_type *howto;
111.
112.} arelent;
113
114*/
115
116/*
117DESCRIPTION
118
119 Here is a description of each of the fields within an <<arelent>>:
120
121 o <<sym_ptr_ptr>>
122
123 The symbol table pointer points to a pointer to the symbol
124 associated with the relocation request. It is
125 the pointer into the table returned by the back end's
126 <<get_symtab>> action. @xref{Symbols}. The symbol is referenced
127 through a pointer to a pointer so that tools like the linker
128 can fix up all the symbols of the same name by modifying only
129 one pointer. The relocation routine looks in the symbol and
130 uses the base of the section the symbol is attached to and the
131 value of the symbol as the initial relocation offset. If the
132 symbol pointer is zero, then the section provided is looked up.
133
134 o <<address>>
135
136 The <<address>> field gives the offset in bytes from the base of
137 the section data which owns the relocation record to the first
138 byte of relocatable information. The actual data relocated
139 will be relative to this point; for example, a relocation
140 type which modifies the bottom two bytes of a four byte word
141 would not touch the first byte pointed to in a big endian
142 world.
143
144 o <<addend>>
145
146 The <<addend>> is a value provided by the back end to be added (!)
147 to the relocation offset. Its interpretation is dependent upon
148 the howto. For example, on the 68k the code:
149
252b5132
RH
150| char foo[];
151| main()
152| {
153| return foo[0x12345678];
154| }
155
156 Could be compiled into:
157
158| linkw fp,#-4
159| moveb @@#12345678,d0
160| extbl d0
161| unlk fp
162| rts
163
252b5132
RH
164 This could create a reloc pointing to <<foo>>, but leave the
165 offset in the data, something like:
166
252b5132
RH
167|RELOCATION RECORDS FOR [.text]:
168|offset type value
169|00000006 32 _foo
170|
171|00000000 4e56 fffc ; linkw fp,#-4
172|00000004 1039 1234 5678 ; moveb @@#12345678,d0
173|0000000a 49c0 ; extbl d0
174|0000000c 4e5e ; unlk fp
175|0000000e 4e75 ; rts
176
252b5132
RH
177 Using coff and an 88k, some instructions don't have enough
178 space in them to represent the full address range, and
179 pointers have to be loaded in two parts. So you'd get something like:
180
252b5132
RH
181| or.u r13,r0,hi16(_foo+0x12345678)
182| ld.b r2,r13,lo16(_foo+0x12345678)
183| jmp r1
184
252b5132
RH
185 This should create two relocs, both pointing to <<_foo>>, and with
186 0x12340000 in their addend field. The data would consist of:
187
252b5132
RH
188|RELOCATION RECORDS FOR [.text]:
189|offset type value
190|00000002 HVRT16 _foo+0x12340000
191|00000006 LVRT16 _foo+0x12340000
192|
193|00000000 5da05678 ; or.u r13,r0,0x5678
194|00000004 1c4d5678 ; ld.b r2,r13,0x5678
195|00000008 f400c001 ; jmp r1
196
252b5132
RH
197 The relocation routine digs out the value from the data, adds
198 it to the addend to get the original offset, and then adds the
199 value of <<_foo>>. Note that all 32 bits have to be kept around
200 somewhere, to cope with carry from bit 15 to bit 16.
201
202 One further example is the sparc and the a.out format. The
203 sparc has a similar problem to the 88k, in that some
204 instructions don't have room for an entire offset, but on the
205 sparc the parts are created in odd sized lumps. The designers of
206 the a.out format chose to not use the data within the section
207 for storing part of the offset; all the offset is kept within
208 the reloc. Anything in the data should be ignored.
209
210| save %sp,-112,%sp
211| sethi %hi(_foo+0x12345678),%g2
212| ldsb [%g2+%lo(_foo+0x12345678)],%i0
213| ret
214| restore
215
216 Both relocs contain a pointer to <<foo>>, and the offsets
217 contain junk.
218
252b5132
RH
219|RELOCATION RECORDS FOR [.text]:
220|offset type value
221|00000004 HI22 _foo+0x12345678
222|00000008 LO10 _foo+0x12345678
223|
224|00000000 9de3bf90 ; save %sp,-112,%sp
225|00000004 05000000 ; sethi %hi(_foo+0),%g2
226|00000008 f048a000 ; ldsb [%g2+%lo(_foo+0)],%i0
227|0000000c 81c7e008 ; ret
228|00000010 81e80000 ; restore
229
252b5132
RH
230 o <<howto>>
231
232 The <<howto>> field can be imagined as a
233 relocation instruction. It is a pointer to a structure which
234 contains information on what to do with all of the other
235 information in the reloc record and data section. A back end
236 would normally have a relocation instruction set and turn
237 relocations into pointers to the correct structure on input -
238 but it would be possible to create each howto field on demand.
239
240*/
241
242/*
243SUBSUBSECTION
244 <<enum complain_overflow>>
245
246 Indicates what sort of overflow checking should be done when
247 performing a relocation.
248
249CODE_FRAGMENT
250.
251.enum complain_overflow
252.{
dc810e39 253. {* Do not complain on overflow. *}
252b5132
RH
254. complain_overflow_dont,
255.
dc810e39
AM
256. {* Complain if the bitfield overflows, whether it is considered
257. as signed or unsigned. *}
252b5132
RH
258. complain_overflow_bitfield,
259.
dc810e39
AM
260. {* Complain if the value overflows when considered as signed
261. number. *}
252b5132
RH
262. complain_overflow_signed,
263.
dc810e39
AM
264. {* Complain if the value overflows when considered as an
265. unsigned number. *}
252b5132
RH
266. complain_overflow_unsigned
267.};
268
269*/
270
271/*
272SUBSUBSECTION
273 <<reloc_howto_type>>
274
275 The <<reloc_howto_type>> is a structure which contains all the
276 information that libbfd needs to know to tie up a back end's data.
277
278CODE_FRAGMENT
279.struct symbol_cache_entry; {* Forward declaration *}
280.
281.struct reloc_howto_struct
282.{
dc810e39
AM
283. {* The type field has mainly a documentary use - the back end can
284. do what it wants with it, though normally the back end's
285. external idea of what a reloc number is stored
286. in this field. For example, a PC relative word relocation
287. in a coff environment has the type 023 - because that's
288. what the outside world calls a R_PCRWORD reloc. *}
252b5132
RH
289. unsigned int type;
290.
dc810e39
AM
291. {* The value the final relocation is shifted right by. This drops
292. unwanted data from the relocation. *}
252b5132
RH
293. unsigned int rightshift;
294.
dc810e39
AM
295. {* The size of the item to be relocated. This is *not* a
296. power-of-two measure. To get the number of bytes operated
297. on by a type of relocation, use bfd_get_reloc_size. *}
252b5132
RH
298. int size;
299.
dc810e39
AM
300. {* The number of bits in the item to be relocated. This is used
301. when doing overflow checking. *}
252b5132
RH
302. unsigned int bitsize;
303.
dc810e39
AM
304. {* Notes that the relocation is relative to the location in the
305. data section of the addend. The relocation function will
306. subtract from the relocation value the address of the location
307. being relocated. *}
252b5132
RH
308. boolean pc_relative;
309.
dc810e39
AM
310. {* The bit position of the reloc value in the destination.
311. The relocated value is left shifted by this amount. *}
252b5132
RH
312. unsigned int bitpos;
313.
dc810e39
AM
314. {* What type of overflow error should be checked for when
315. relocating. *}
252b5132
RH
316. enum complain_overflow complain_on_overflow;
317.
dc810e39
AM
318. {* If this field is non null, then the supplied function is
319. called rather than the normal function. This allows really
320. strange relocation methods to be accomodated (e.g., i960 callj
321. instructions). *}
252b5132 322. bfd_reloc_status_type (*special_function)
dc810e39
AM
323. PARAMS ((bfd *, arelent *, struct symbol_cache_entry *, PTR, asection *,
324. bfd *, char **));
252b5132 325.
dc810e39 326. {* The textual name of the relocation type. *}
252b5132
RH
327. char *name;
328.
dc810e39
AM
329. {* Some formats record a relocation addend in the section contents
330. rather than with the relocation. For ELF formats this is the
331. distinction between USE_REL and USE_RELA (though the code checks
332. for USE_REL == 1/0). The value of this field is TRUE if the
333. addend is recorded with the section contents; when performing a
334. partial link (ld -r) the section contents (the data) will be
335. modified. The value of this field is FALSE if addends are
336. recorded with the relocation (in arelent.addend); when performing
337. a partial link the relocation will be modified.
338. All relocations for all ELF USE_RELA targets should set this field
339. to FALSE (values of TRUE should be looked on with suspicion).
340. However, the converse is not true: not all relocations of all ELF
341. USE_REL targets set this field to TRUE. Why this is so is peculiar
342. to each particular target. For relocs that aren't used in partial
343. links (e.g. GOT stuff) it doesn't matter what this is set to. *}
252b5132
RH
344. boolean partial_inplace;
345.
dc810e39
AM
346. {* The src_mask selects which parts of the read in data
347. are to be used in the relocation sum. E.g., if this was an 8 bit
348. byte of data which we read and relocated, this would be
349. 0x000000ff. When we have relocs which have an addend, such as
350. sun4 extended relocs, the value in the offset part of a
351. relocating field is garbage so we never use it. In this case
352. the mask would be 0x00000000. *}
252b5132
RH
353. bfd_vma src_mask;
354.
dc810e39
AM
355. {* The dst_mask selects which parts of the instruction are replaced
356. into the instruction. In most cases src_mask == dst_mask,
357. except in the above special case, where dst_mask would be
358. 0x000000ff, and src_mask would be 0x00000000. *}
252b5132
RH
359. bfd_vma dst_mask;
360.
dc810e39
AM
361. {* When some formats create PC relative instructions, they leave
362. the value of the pc of the place being relocated in the offset
363. slot of the instruction, so that a PC relative relocation can
364. be made just by adding in an ordinary offset (e.g., sun3 a.out).
365. Some formats leave the displacement part of an instruction
366. empty (e.g., m88k bcs); this flag signals the fact. *}
252b5132 367. boolean pcrel_offset;
252b5132
RH
368.};
369
370*/
371
372/*
373FUNCTION
374 The HOWTO Macro
375
376DESCRIPTION
377 The HOWTO define is horrible and will go away.
378
dc810e39
AM
379.#define HOWTO(C, R, S, B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
380. { (unsigned) C, R, S, B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC }
252b5132
RH
381
382DESCRIPTION
383 And will be replaced with the totally magic way. But for the
384 moment, we are compatible, so do it this way.
385
dc810e39
AM
386.#define NEWHOWTO(FUNCTION, NAME, SIZE, REL, IN) \
387. HOWTO (0, 0, SIZE, 0, REL, 0, complain_overflow_dont, FUNCTION, \
388. NAME, false, 0, 0, IN)
252b5132 389.
5f771d47
ILT
390
391DESCRIPTION
392 This is used to fill in an empty howto entry in an array.
393
394.#define EMPTY_HOWTO(C) \
dc810e39
AM
395. HOWTO ((C), 0, 0, 0, false, 0, complain_overflow_dont, NULL, \
396. NULL, false, 0, 0, false)
5f771d47
ILT
397.
398
252b5132
RH
399DESCRIPTION
400 Helper routine to turn a symbol into a relocation value.
401
dc810e39
AM
402.#define HOWTO_PREPARE(relocation, symbol) \
403. { \
404. if (symbol != (asymbol *) NULL) \
405. { \
406. if (bfd_is_com_section (symbol->section)) \
407. { \
408. relocation = 0; \
409. } \
410. else \
411. { \
412. relocation = symbol->value; \
413. } \
414. } \
415. }
252b5132
RH
416
417*/
418
419/*
420FUNCTION
421 bfd_get_reloc_size
422
423SYNOPSIS
424 unsigned int bfd_get_reloc_size (reloc_howto_type *);
425
426DESCRIPTION
427 For a reloc_howto_type that operates on a fixed number of bytes,
428 this returns the number of bytes operated on.
429 */
430
431unsigned int
432bfd_get_reloc_size (howto)
433 reloc_howto_type *howto;
434{
435 switch (howto->size)
436 {
437 case 0: return 1;
438 case 1: return 2;
439 case 2: return 4;
440 case 3: return 0;
441 case 4: return 8;
442 case 8: return 16;
443 case -2: return 4;
444 default: abort ();
445 }
446}
447
448/*
449TYPEDEF
450 arelent_chain
451
452DESCRIPTION
453
454 How relocs are tied together in an <<asection>>:
455
dc810e39
AM
456.typedef struct relent_chain
457.{
252b5132 458. arelent relent;
dc810e39 459. struct relent_chain *next;
252b5132
RH
460.} arelent_chain;
461
462*/
463
464/* N_ONES produces N one bits, without overflowing machine arithmetic. */
465#define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
466
467/*
468FUNCTION
469 bfd_check_overflow
470
471SYNOPSIS
472 bfd_reloc_status_type
473 bfd_check_overflow
474 (enum complain_overflow how,
475 unsigned int bitsize,
476 unsigned int rightshift,
477 unsigned int addrsize,
478 bfd_vma relocation);
479
480DESCRIPTION
481 Perform overflow checking on @var{relocation} which has
482 @var{bitsize} significant bits and will be shifted right by
483 @var{rightshift} bits, on a machine with addresses containing
484 @var{addrsize} significant bits. The result is either of
485 @code{bfd_reloc_ok} or @code{bfd_reloc_overflow}.
486
487*/
488
489bfd_reloc_status_type
490bfd_check_overflow (how, bitsize, rightshift, addrsize, relocation)
491 enum complain_overflow how;
492 unsigned int bitsize;
493 unsigned int rightshift;
494 unsigned int addrsize;
495 bfd_vma relocation;
496{
497 bfd_vma fieldmask, addrmask, signmask, ss, a;
498 bfd_reloc_status_type flag = bfd_reloc_ok;
499
500 a = relocation;
501
502 /* Note: BITSIZE should always be <= ADDRSIZE, but in case it's not,
503 we'll be permissive: extra bits in the field mask will
504 automatically extend the address mask for purposes of the
505 overflow check. */
506 fieldmask = N_ONES (bitsize);
507 addrmask = N_ONES (addrsize) | fieldmask;
508
509 switch (how)
510 {
511 case complain_overflow_dont:
512 break;
513
514 case complain_overflow_signed:
515 /* If any sign bits are set, all sign bits must be set. That
516 is, A must be a valid negative address after shifting. */
517 a = (a & addrmask) >> rightshift;
518 signmask = ~ (fieldmask >> 1);
519 ss = a & signmask;
520 if (ss != 0 && ss != ((addrmask >> rightshift) & signmask))
521 flag = bfd_reloc_overflow;
522 break;
523
524 case complain_overflow_unsigned:
525 /* We have an overflow if the address does not fit in the field. */
526 a = (a & addrmask) >> rightshift;
527 if ((a & ~ fieldmask) != 0)
528 flag = bfd_reloc_overflow;
529 break;
530
531 case complain_overflow_bitfield:
532 /* Bitfields are sometimes signed, sometimes unsigned. We
d5afc56e
AM
533 explicitly allow an address wrap too, which means a bitfield
534 of n bits is allowed to store -2**n to 2**n-1. Thus overflow
535 if the value has some, but not all, bits set outside the
536 field. */
252b5132 537 a >>= rightshift;
d5afc56e
AM
538 ss = a & ~ fieldmask;
539 if (ss != 0 && ss != (((bfd_vma) -1 >> rightshift) & ~ fieldmask))
540 flag = bfd_reloc_overflow;
252b5132
RH
541 break;
542
543 default:
544 abort ();
545 }
546
547 return flag;
548}
549
550/*
551FUNCTION
552 bfd_perform_relocation
553
554SYNOPSIS
555 bfd_reloc_status_type
556 bfd_perform_relocation
557 (bfd *abfd,
558 arelent *reloc_entry,
559 PTR data,
560 asection *input_section,
561 bfd *output_bfd,
562 char **error_message);
563
564DESCRIPTION
565 If @var{output_bfd} is supplied to this function, the
566 generated image will be relocatable; the relocations are
567 copied to the output file after they have been changed to
568 reflect the new state of the world. There are two ways of
569 reflecting the results of partial linkage in an output file:
570 by modifying the output data in place, and by modifying the
571 relocation record. Some native formats (e.g., basic a.out and
572 basic coff) have no way of specifying an addend in the
573 relocation type, so the addend has to go in the output data.
574 This is no big deal since in these formats the output data
575 slot will always be big enough for the addend. Complex reloc
576 types with addends were invented to solve just this problem.
577 The @var{error_message} argument is set to an error message if
578 this return @code{bfd_reloc_dangerous}.
579
580*/
581
252b5132
RH
582bfd_reloc_status_type
583bfd_perform_relocation (abfd, reloc_entry, data, input_section, output_bfd,
584 error_message)
585 bfd *abfd;
586 arelent *reloc_entry;
587 PTR data;
588 asection *input_section;
589 bfd *output_bfd;
590 char **error_message;
591{
592 bfd_vma relocation;
593 bfd_reloc_status_type flag = bfd_reloc_ok;
9a968f43 594 bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
252b5132
RH
595 bfd_vma output_base = 0;
596 reloc_howto_type *howto = reloc_entry->howto;
597 asection *reloc_target_output_section;
598 asymbol *symbol;
599
600 symbol = *(reloc_entry->sym_ptr_ptr);
601 if (bfd_is_abs_section (symbol->section)
602 && output_bfd != (bfd *) NULL)
603 {
604 reloc_entry->address += input_section->output_offset;
605 return bfd_reloc_ok;
606 }
607
608 /* If we are not producing relocateable output, return an error if
609 the symbol is not defined. An undefined weak symbol is
610 considered to have a value of zero (SVR4 ABI, p. 4-27). */
611 if (bfd_is_und_section (symbol->section)
612 && (symbol->flags & BSF_WEAK) == 0
613 && output_bfd == (bfd *) NULL)
614 flag = bfd_reloc_undefined;
615
616 /* If there is a function supplied to handle this relocation type,
617 call it. It'll return `bfd_reloc_continue' if further processing
618 can be done. */
619 if (howto->special_function)
620 {
621 bfd_reloc_status_type cont;
622 cont = howto->special_function (abfd, reloc_entry, symbol, data,
623 input_section, output_bfd,
624 error_message);
625 if (cont != bfd_reloc_continue)
626 return cont;
627 }
628
629 /* Is the address of the relocation really within the section? */
e207c4fa
AM
630 if (reloc_entry->address > (input_section->_cooked_size
631 / bfd_octets_per_byte (abfd)))
252b5132
RH
632 return bfd_reloc_outofrange;
633
634 /* Work out which section the relocation is targetted at and the
635 initial relocation command value. */
636
637 /* Get symbol value. (Common symbols are special.) */
638 if (bfd_is_com_section (symbol->section))
639 relocation = 0;
640 else
641 relocation = symbol->value;
642
252b5132
RH
643 reloc_target_output_section = symbol->section->output_section;
644
645 /* Convert input-section-relative symbol value to absolute. */
646 if (output_bfd && howto->partial_inplace == false)
647 output_base = 0;
648 else
649 output_base = reloc_target_output_section->vma;
650
651 relocation += output_base + symbol->section->output_offset;
652
653 /* Add in supplied addend. */
654 relocation += reloc_entry->addend;
655
656 /* Here the variable relocation holds the final address of the
657 symbol we are relocating against, plus any addend. */
658
659 if (howto->pc_relative == true)
660 {
661 /* This is a PC relative relocation. We want to set RELOCATION
662 to the distance between the address of the symbol and the
663 location. RELOCATION is already the address of the symbol.
664
665 We start by subtracting the address of the section containing
666 the location.
667
668 If pcrel_offset is set, we must further subtract the position
669 of the location within the section. Some targets arrange for
670 the addend to be the negative of the position of the location
671 within the section; for example, i386-aout does this. For
672 i386-aout, pcrel_offset is false. Some other targets do not
673 include the position of the location; for example, m88kbcs,
674 or ELF. For those targets, pcrel_offset is true.
675
676 If we are producing relocateable output, then we must ensure
677 that this reloc will be correctly computed when the final
678 relocation is done. If pcrel_offset is false we want to wind
679 up with the negative of the location within the section,
680 which means we must adjust the existing addend by the change
681 in the location within the section. If pcrel_offset is true
682 we do not want to adjust the existing addend at all.
683
684 FIXME: This seems logical to me, but for the case of
685 producing relocateable output it is not what the code
686 actually does. I don't want to change it, because it seems
687 far too likely that something will break. */
688
689 relocation -=
690 input_section->output_section->vma + input_section->output_offset;
691
692 if (howto->pcrel_offset == true)
693 relocation -= reloc_entry->address;
694 }
695
696 if (output_bfd != (bfd *) NULL)
697 {
698 if (howto->partial_inplace == false)
699 {
700 /* This is a partial relocation, and we want to apply the relocation
701 to the reloc entry rather than the raw data. Modify the reloc
702 inplace to reflect what we now know. */
703 reloc_entry->addend = relocation;
704 reloc_entry->address += input_section->output_offset;
705 return flag;
706 }
707 else
708 {
709 /* This is a partial relocation, but inplace, so modify the
710 reloc record a bit.
711
712 If we've relocated with a symbol with a section, change
713 into a ref to the section belonging to the symbol. */
714
715 reloc_entry->address += input_section->output_offset;
716
717 /* WTF?? */
718 if (abfd->xvec->flavour == bfd_target_coff_flavour
252b5132
RH
719 && strcmp (abfd->xvec->name, "coff-Intel-little") != 0
720 && strcmp (abfd->xvec->name, "coff-Intel-big") != 0)
721 {
722#if 1
723 /* For m68k-coff, the addend was being subtracted twice during
724 relocation with -r. Removing the line below this comment
725 fixes that problem; see PR 2953.
726
727However, Ian wrote the following, regarding removing the line below,
728which explains why it is still enabled: --djm
729
730If you put a patch like that into BFD you need to check all the COFF
731linkers. I am fairly certain that patch will break coff-i386 (e.g.,
732SCO); see coff_i386_reloc in coff-i386.c where I worked around the
733problem in a different way. There may very well be a reason that the
734code works as it does.
735
736Hmmm. The first obvious point is that bfd_perform_relocation should
737not have any tests that depend upon the flavour. It's seem like
738entirely the wrong place for such a thing. The second obvious point
739is that the current code ignores the reloc addend when producing
740relocateable output for COFF. That's peculiar. In fact, I really
741have no idea what the point of the line you want to remove is.
742
743A typical COFF reloc subtracts the old value of the symbol and adds in
744the new value to the location in the object file (if it's a pc
745relative reloc it adds the difference between the symbol value and the
746location). When relocating we need to preserve that property.
747
748BFD handles this by setting the addend to the negative of the old
749value of the symbol. Unfortunately it handles common symbols in a
750non-standard way (it doesn't subtract the old value) but that's a
751different story (we can't change it without losing backward
752compatibility with old object files) (coff-i386 does subtract the old
753value, to be compatible with existing coff-i386 targets, like SCO).
754
755So everything works fine when not producing relocateable output. When
756we are producing relocateable output, logically we should do exactly
757what we do when not producing relocateable output. Therefore, your
758patch is correct. In fact, it should probably always just set
759reloc_entry->addend to 0 for all cases, since it is, in fact, going to
760add the value into the object file. This won't hurt the COFF code,
761which doesn't use the addend; I'm not sure what it will do to other
762formats (the thing to check for would be whether any formats both use
763the addend and set partial_inplace).
764
765When I wanted to make coff-i386 produce relocateable output, I ran
766into the problem that you are running into: I wanted to remove that
767line. Rather than risk it, I made the coff-i386 relocs use a special
768function; it's coff_i386_reloc in coff-i386.c. The function
769specifically adds the addend field into the object file, knowing that
770bfd_perform_relocation is not going to. If you remove that line, then
771coff-i386.c will wind up adding the addend field in twice. It's
772trivial to fix; it just needs to be done.
773
774The problem with removing the line is just that it may break some
775working code. With BFD it's hard to be sure of anything. The right
776way to deal with this is simply to build and test at least all the
777supported COFF targets. It should be straightforward if time and disk
778space consuming. For each target:
779 1) build the linker
780 2) generate some executable, and link it using -r (I would
781 probably use paranoia.o and link against newlib/libc.a, which
782 for all the supported targets would be available in
783 /usr/cygnus/progressive/H-host/target/lib/libc.a).
784 3) make the change to reloc.c
785 4) rebuild the linker
786 5) repeat step 2
787 6) if the resulting object files are the same, you have at least
788 made it no worse
789 7) if they are different you have to figure out which version is
790 right
791*/
792 relocation -= reloc_entry->addend;
793#endif
794 reloc_entry->addend = 0;
795 }
796 else
797 {
798 reloc_entry->addend = relocation;
799 }
800 }
801 }
802 else
803 {
804 reloc_entry->addend = 0;
805 }
806
807 /* FIXME: This overflow checking is incomplete, because the value
808 might have overflowed before we get here. For a correct check we
809 need to compute the value in a size larger than bitsize, but we
810 can't reasonably do that for a reloc the same size as a host
811 machine word.
812 FIXME: We should also do overflow checking on the result after
813 adding in the value contained in the object file. */
814 if (howto->complain_on_overflow != complain_overflow_dont
815 && flag == bfd_reloc_ok)
816 flag = bfd_check_overflow (howto->complain_on_overflow,
817 howto->bitsize,
818 howto->rightshift,
819 bfd_arch_bits_per_address (abfd),
820 relocation);
821
822 /*
823 Either we are relocating all the way, or we don't want to apply
824 the relocation to the reloc entry (probably because there isn't
825 any room in the output format to describe addends to relocs)
826 */
827
828 /* The cast to bfd_vma avoids a bug in the Alpha OSF/1 C compiler
829 (OSF version 1.3, compiler version 3.11). It miscompiles the
830 following program:
831
832 struct str
833 {
834 unsigned int i0;
835 } s = { 0 };
836
837 int
838 main ()
839 {
840 unsigned long x;
841
842 x = 0x100000000;
843 x <<= (unsigned long) s.i0;
844 if (x == 0)
845 printf ("failed\n");
846 else
847 printf ("succeeded (%lx)\n", x);
848 }
849 */
850
851 relocation >>= (bfd_vma) howto->rightshift;
852
853 /* Shift everything up to where it's going to be used */
854
855 relocation <<= (bfd_vma) howto->bitpos;
856
857 /* Wait for the day when all have the mask in them */
858
859 /* What we do:
860 i instruction to be left alone
861 o offset within instruction
862 r relocation offset to apply
863 S src mask
864 D dst mask
865 N ~dst mask
866 A part 1
867 B part 2
868 R result
869
870 Do this:
88b6bae0
AM
871 (( i i i i i o o o o o from bfd_get<size>
872 and S S S S S) to get the size offset we want
873 + r r r r r r r r r r) to get the final value to place
252b5132
RH
874 and D D D D D to chop to right size
875 -----------------------
88b6bae0 876 = A A A A A
252b5132 877 And this:
88b6bae0
AM
878 ( i i i i i o o o o o from bfd_get<size>
879 and N N N N N ) get instruction
252b5132 880 -----------------------
88b6bae0 881 = B B B B B
252b5132
RH
882
883 And then:
88b6bae0
AM
884 ( B B B B B
885 or A A A A A)
252b5132 886 -----------------------
88b6bae0 887 = R R R R R R R R R R put into bfd_put<size>
252b5132
RH
888 */
889
890#define DOIT(x) \
891 x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask))
892
893 switch (howto->size)
894 {
895 case 0:
896 {
9a968f43 897 char x = bfd_get_8 (abfd, (char *) data + octets);
252b5132 898 DOIT (x);
9a968f43 899 bfd_put_8 (abfd, x, (unsigned char *) data + octets);
252b5132
RH
900 }
901 break;
902
903 case 1:
904 {
9a968f43 905 short x = bfd_get_16 (abfd, (bfd_byte *) data + octets);
252b5132 906 DOIT (x);
dc810e39 907 bfd_put_16 (abfd, (bfd_vma) x, (unsigned char *) data + octets);
252b5132
RH
908 }
909 break;
910 case 2:
911 {
9a968f43 912 long x = bfd_get_32 (abfd, (bfd_byte *) data + octets);
252b5132 913 DOIT (x);
dc810e39 914 bfd_put_32 (abfd, (bfd_vma) x, (bfd_byte *) data + octets);
252b5132
RH
915 }
916 break;
917 case -2:
918 {
9a968f43 919 long x = bfd_get_32 (abfd, (bfd_byte *) data + octets);
252b5132
RH
920 relocation = -relocation;
921 DOIT (x);
dc810e39 922 bfd_put_32 (abfd, (bfd_vma) x, (bfd_byte *) data + octets);
252b5132
RH
923 }
924 break;
925
926 case -1:
927 {
9a968f43 928 long x = bfd_get_16 (abfd, (bfd_byte *) data + octets);
252b5132
RH
929 relocation = -relocation;
930 DOIT (x);
dc810e39 931 bfd_put_16 (abfd, (bfd_vma) x, (bfd_byte *) data + octets);
252b5132
RH
932 }
933 break;
934
935 case 3:
936 /* Do nothing */
937 break;
938
939 case 4:
940#ifdef BFD64
941 {
9a968f43 942 bfd_vma x = bfd_get_64 (abfd, (bfd_byte *) data + octets);
252b5132 943 DOIT (x);
9a968f43 944 bfd_put_64 (abfd, x, (bfd_byte *) data + octets);
252b5132
RH
945 }
946#else
947 abort ();
948#endif
949 break;
950 default:
951 return bfd_reloc_other;
952 }
953
954 return flag;
955}
956
957/*
958FUNCTION
959 bfd_install_relocation
960
961SYNOPSIS
962 bfd_reloc_status_type
963 bfd_install_relocation
964 (bfd *abfd,
965 arelent *reloc_entry,
966 PTR data, bfd_vma data_start,
967 asection *input_section,
968 char **error_message);
969
970DESCRIPTION
971 This looks remarkably like <<bfd_perform_relocation>>, except it
972 does not expect that the section contents have been filled in.
973 I.e., it's suitable for use when creating, rather than applying
974 a relocation.
975
976 For now, this function should be considered reserved for the
977 assembler.
978
979*/
980
252b5132
RH
981bfd_reloc_status_type
982bfd_install_relocation (abfd, reloc_entry, data_start, data_start_offset,
983 input_section, error_message)
984 bfd *abfd;
985 arelent *reloc_entry;
986 PTR data_start;
987 bfd_vma data_start_offset;
988 asection *input_section;
989 char **error_message;
990{
991 bfd_vma relocation;
992 bfd_reloc_status_type flag = bfd_reloc_ok;
9a968f43 993 bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
252b5132
RH
994 bfd_vma output_base = 0;
995 reloc_howto_type *howto = reloc_entry->howto;
996 asection *reloc_target_output_section;
997 asymbol *symbol;
998 bfd_byte *data;
999
1000 symbol = *(reloc_entry->sym_ptr_ptr);
1001 if (bfd_is_abs_section (symbol->section))
1002 {
1003 reloc_entry->address += input_section->output_offset;
1004 return bfd_reloc_ok;
1005 }
1006
1007 /* If there is a function supplied to handle this relocation type,
1008 call it. It'll return `bfd_reloc_continue' if further processing
1009 can be done. */
1010 if (howto->special_function)
1011 {
1012 bfd_reloc_status_type cont;
88b6bae0 1013
252b5132
RH
1014 /* XXX - The special_function calls haven't been fixed up to deal
1015 with creating new relocations and section contents. */
1016 cont = howto->special_function (abfd, reloc_entry, symbol,
1017 /* XXX - Non-portable! */
1018 ((bfd_byte *) data_start
1019 - data_start_offset),
1020 input_section, abfd, error_message);
1021 if (cont != bfd_reloc_continue)
1022 return cont;
1023 }
1024
1025 /* Is the address of the relocation really within the section? */
e207c4fa
AM
1026 if (reloc_entry->address > (input_section->_cooked_size
1027 / bfd_octets_per_byte (abfd)))
252b5132
RH
1028 return bfd_reloc_outofrange;
1029
1030 /* Work out which section the relocation is targetted at and the
1031 initial relocation command value. */
1032
1033 /* Get symbol value. (Common symbols are special.) */
1034 if (bfd_is_com_section (symbol->section))
1035 relocation = 0;
1036 else
1037 relocation = symbol->value;
1038
1039 reloc_target_output_section = symbol->section->output_section;
1040
1041 /* Convert input-section-relative symbol value to absolute. */
1042 if (howto->partial_inplace == false)
1043 output_base = 0;
1044 else
1045 output_base = reloc_target_output_section->vma;
1046
1047 relocation += output_base + symbol->section->output_offset;
1048
1049 /* Add in supplied addend. */
1050 relocation += reloc_entry->addend;
1051
1052 /* Here the variable relocation holds the final address of the
1053 symbol we are relocating against, plus any addend. */
1054
1055 if (howto->pc_relative == true)
1056 {
1057 /* This is a PC relative relocation. We want to set RELOCATION
1058 to the distance between the address of the symbol and the
1059 location. RELOCATION is already the address of the symbol.
1060
1061 We start by subtracting the address of the section containing
1062 the location.
1063
1064 If pcrel_offset is set, we must further subtract the position
1065 of the location within the section. Some targets arrange for
1066 the addend to be the negative of the position of the location
1067 within the section; for example, i386-aout does this. For
1068 i386-aout, pcrel_offset is false. Some other targets do not
1069 include the position of the location; for example, m88kbcs,
1070 or ELF. For those targets, pcrel_offset is true.
1071
1072 If we are producing relocateable output, then we must ensure
1073 that this reloc will be correctly computed when the final
1074 relocation is done. If pcrel_offset is false we want to wind
1075 up with the negative of the location within the section,
1076 which means we must adjust the existing addend by the change
1077 in the location within the section. If pcrel_offset is true
1078 we do not want to adjust the existing addend at all.
1079
1080 FIXME: This seems logical to me, but for the case of
1081 producing relocateable output it is not what the code
1082 actually does. I don't want to change it, because it seems
1083 far too likely that something will break. */
1084
1085 relocation -=
1086 input_section->output_section->vma + input_section->output_offset;
1087
1088 if (howto->pcrel_offset == true && howto->partial_inplace == true)
1089 relocation -= reloc_entry->address;
1090 }
1091
1092 if (howto->partial_inplace == false)
1093 {
1094 /* This is a partial relocation, and we want to apply the relocation
1095 to the reloc entry rather than the raw data. Modify the reloc
1096 inplace to reflect what we now know. */
1097 reloc_entry->addend = relocation;
1098 reloc_entry->address += input_section->output_offset;
1099 return flag;
1100 }
1101 else
1102 {
1103 /* This is a partial relocation, but inplace, so modify the
1104 reloc record a bit.
1105
1106 If we've relocated with a symbol with a section, change
1107 into a ref to the section belonging to the symbol. */
1108
1109 reloc_entry->address += input_section->output_offset;
1110
1111 /* WTF?? */
1112 if (abfd->xvec->flavour == bfd_target_coff_flavour
252b5132
RH
1113 && strcmp (abfd->xvec->name, "coff-Intel-little") != 0
1114 && strcmp (abfd->xvec->name, "coff-Intel-big") != 0)
1115 {
1116#if 1
1117/* For m68k-coff, the addend was being subtracted twice during
1118 relocation with -r. Removing the line below this comment
1119 fixes that problem; see PR 2953.
1120
1121However, Ian wrote the following, regarding removing the line below,
1122which explains why it is still enabled: --djm
1123
1124If you put a patch like that into BFD you need to check all the COFF
1125linkers. I am fairly certain that patch will break coff-i386 (e.g.,
1126SCO); see coff_i386_reloc in coff-i386.c where I worked around the
1127problem in a different way. There may very well be a reason that the
1128code works as it does.
1129
1130Hmmm. The first obvious point is that bfd_install_relocation should
1131not have any tests that depend upon the flavour. It's seem like
1132entirely the wrong place for such a thing. The second obvious point
1133is that the current code ignores the reloc addend when producing
1134relocateable output for COFF. That's peculiar. In fact, I really
1135have no idea what the point of the line you want to remove is.
1136
1137A typical COFF reloc subtracts the old value of the symbol and adds in
1138the new value to the location in the object file (if it's a pc
1139relative reloc it adds the difference between the symbol value and the
1140location). When relocating we need to preserve that property.
1141
1142BFD handles this by setting the addend to the negative of the old
1143value of the symbol. Unfortunately it handles common symbols in a
1144non-standard way (it doesn't subtract the old value) but that's a
1145different story (we can't change it without losing backward
1146compatibility with old object files) (coff-i386 does subtract the old
1147value, to be compatible with existing coff-i386 targets, like SCO).
1148
1149So everything works fine when not producing relocateable output. When
1150we are producing relocateable output, logically we should do exactly
1151what we do when not producing relocateable output. Therefore, your
1152patch is correct. In fact, it should probably always just set
1153reloc_entry->addend to 0 for all cases, since it is, in fact, going to
1154add the value into the object file. This won't hurt the COFF code,
1155which doesn't use the addend; I'm not sure what it will do to other
1156formats (the thing to check for would be whether any formats both use
1157the addend and set partial_inplace).
1158
1159When I wanted to make coff-i386 produce relocateable output, I ran
1160into the problem that you are running into: I wanted to remove that
1161line. Rather than risk it, I made the coff-i386 relocs use a special
1162function; it's coff_i386_reloc in coff-i386.c. The function
1163specifically adds the addend field into the object file, knowing that
1164bfd_install_relocation is not going to. If you remove that line, then
1165coff-i386.c will wind up adding the addend field in twice. It's
1166trivial to fix; it just needs to be done.
1167
1168The problem with removing the line is just that it may break some
1169working code. With BFD it's hard to be sure of anything. The right
1170way to deal with this is simply to build and test at least all the
1171supported COFF targets. It should be straightforward if time and disk
1172space consuming. For each target:
1173 1) build the linker
1174 2) generate some executable, and link it using -r (I would
1175 probably use paranoia.o and link against newlib/libc.a, which
1176 for all the supported targets would be available in
1177 /usr/cygnus/progressive/H-host/target/lib/libc.a).
1178 3) make the change to reloc.c
1179 4) rebuild the linker
1180 5) repeat step 2
1181 6) if the resulting object files are the same, you have at least
1182 made it no worse
1183 7) if they are different you have to figure out which version is
1184 right
1185*/
1186 relocation -= reloc_entry->addend;
1187#endif
1188 reloc_entry->addend = 0;
1189 }
1190 else
1191 {
1192 reloc_entry->addend = relocation;
1193 }
1194 }
1195
1196 /* FIXME: This overflow checking is incomplete, because the value
1197 might have overflowed before we get here. For a correct check we
1198 need to compute the value in a size larger than bitsize, but we
1199 can't reasonably do that for a reloc the same size as a host
1200 machine word.
1201 FIXME: We should also do overflow checking on the result after
1202 adding in the value contained in the object file. */
1203 if (howto->complain_on_overflow != complain_overflow_dont)
1204 flag = bfd_check_overflow (howto->complain_on_overflow,
1205 howto->bitsize,
1206 howto->rightshift,
1207 bfd_arch_bits_per_address (abfd),
1208 relocation);
1209
1210 /*
1211 Either we are relocating all the way, or we don't want to apply
1212 the relocation to the reloc entry (probably because there isn't
1213 any room in the output format to describe addends to relocs)
1214 */
1215
1216 /* The cast to bfd_vma avoids a bug in the Alpha OSF/1 C compiler
1217 (OSF version 1.3, compiler version 3.11). It miscompiles the
1218 following program:
1219
1220 struct str
1221 {
1222 unsigned int i0;
1223 } s = { 0 };
1224
1225 int
1226 main ()
1227 {
1228 unsigned long x;
1229
1230 x = 0x100000000;
1231 x <<= (unsigned long) s.i0;
1232 if (x == 0)
1233 printf ("failed\n");
1234 else
1235 printf ("succeeded (%lx)\n", x);
1236 }
1237 */
1238
1239 relocation >>= (bfd_vma) howto->rightshift;
1240
1241 /* Shift everything up to where it's going to be used */
1242
1243 relocation <<= (bfd_vma) howto->bitpos;
1244
1245 /* Wait for the day when all have the mask in them */
1246
1247 /* What we do:
1248 i instruction to be left alone
1249 o offset within instruction
1250 r relocation offset to apply
1251 S src mask
1252 D dst mask
1253 N ~dst mask
1254 A part 1
1255 B part 2
1256 R result
1257
1258 Do this:
88b6bae0
AM
1259 (( i i i i i o o o o o from bfd_get<size>
1260 and S S S S S) to get the size offset we want
1261 + r r r r r r r r r r) to get the final value to place
252b5132
RH
1262 and D D D D D to chop to right size
1263 -----------------------
88b6bae0 1264 = A A A A A
252b5132 1265 And this:
88b6bae0
AM
1266 ( i i i i i o o o o o from bfd_get<size>
1267 and N N N N N ) get instruction
252b5132 1268 -----------------------
88b6bae0 1269 = B B B B B
252b5132
RH
1270
1271 And then:
88b6bae0
AM
1272 ( B B B B B
1273 or A A A A A)
252b5132 1274 -----------------------
88b6bae0 1275 = R R R R R R R R R R put into bfd_put<size>
252b5132
RH
1276 */
1277
1278#define DOIT(x) \
1279 x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask))
1280
9a968f43 1281 data = (bfd_byte *) data_start + (octets - data_start_offset);
252b5132
RH
1282
1283 switch (howto->size)
1284 {
1285 case 0:
1286 {
1287 char x = bfd_get_8 (abfd, (char *) data);
1288 DOIT (x);
1289 bfd_put_8 (abfd, x, (unsigned char *) data);
1290 }
1291 break;
1292
1293 case 1:
1294 {
1295 short x = bfd_get_16 (abfd, (bfd_byte *) data);
1296 DOIT (x);
dc810e39 1297 bfd_put_16 (abfd, (bfd_vma) x, (unsigned char *) data);
252b5132
RH
1298 }
1299 break;
1300 case 2:
1301 {
1302 long x = bfd_get_32 (abfd, (bfd_byte *) data);
1303 DOIT (x);
dc810e39 1304 bfd_put_32 (abfd, (bfd_vma) x, (bfd_byte *) data);
252b5132
RH
1305 }
1306 break;
1307 case -2:
1308 {
1309 long x = bfd_get_32 (abfd, (bfd_byte *) data);
1310 relocation = -relocation;
1311 DOIT (x);
dc810e39 1312 bfd_put_32 (abfd, (bfd_vma) x, (bfd_byte *) data);
252b5132
RH
1313 }
1314 break;
1315
1316 case 3:
1317 /* Do nothing */
1318 break;
1319
1320 case 4:
1321 {
1322 bfd_vma x = bfd_get_64 (abfd, (bfd_byte *) data);
1323 DOIT (x);
1324 bfd_put_64 (abfd, x, (bfd_byte *) data);
1325 }
1326 break;
1327 default:
1328 return bfd_reloc_other;
1329 }
1330
1331 return flag;
1332}
1333
1334/* This relocation routine is used by some of the backend linkers.
1335 They do not construct asymbol or arelent structures, so there is no
1336 reason for them to use bfd_perform_relocation. Also,
1337 bfd_perform_relocation is so hacked up it is easier to write a new
1338 function than to try to deal with it.
1339
1340 This routine does a final relocation. Whether it is useful for a
1341 relocateable link depends upon how the object format defines
1342 relocations.
1343
1344 FIXME: This routine ignores any special_function in the HOWTO,
1345 since the existing special_function values have been written for
1346 bfd_perform_relocation.
1347
1348 HOWTO is the reloc howto information.
1349 INPUT_BFD is the BFD which the reloc applies to.
1350 INPUT_SECTION is the section which the reloc applies to.
1351 CONTENTS is the contents of the section.
1352 ADDRESS is the address of the reloc within INPUT_SECTION.
1353 VALUE is the value of the symbol the reloc refers to.
1354 ADDEND is the addend of the reloc. */
1355
1356bfd_reloc_status_type
1357_bfd_final_link_relocate (howto, input_bfd, input_section, contents, address,
1358 value, addend)
1359 reloc_howto_type *howto;
1360 bfd *input_bfd;
1361 asection *input_section;
1362 bfd_byte *contents;
1363 bfd_vma address;
1364 bfd_vma value;
1365 bfd_vma addend;
1366{
1367 bfd_vma relocation;
1368
1369 /* Sanity check the address. */
1370 if (address > input_section->_raw_size)
1371 return bfd_reloc_outofrange;
1372
1373 /* This function assumes that we are dealing with a basic relocation
1374 against a symbol. We want to compute the value of the symbol to
1375 relocate to. This is just VALUE, the value of the symbol, plus
1376 ADDEND, any addend associated with the reloc. */
1377 relocation = value + addend;
1378
1379 /* If the relocation is PC relative, we want to set RELOCATION to
1380 the distance between the symbol (currently in RELOCATION) and the
1381 location we are relocating. Some targets (e.g., i386-aout)
1382 arrange for the contents of the section to be the negative of the
1383 offset of the location within the section; for such targets
1384 pcrel_offset is false. Other targets (e.g., m88kbcs or ELF)
1385 simply leave the contents of the section as zero; for such
1386 targets pcrel_offset is true. If pcrel_offset is false we do not
1387 need to subtract out the offset of the location within the
1388 section (which is just ADDRESS). */
1389 if (howto->pc_relative)
1390 {
1391 relocation -= (input_section->output_section->vma
1392 + input_section->output_offset);
1393 if (howto->pcrel_offset)
1394 relocation -= address;
1395 }
1396
1397 return _bfd_relocate_contents (howto, input_bfd, relocation,
1398 contents + address);
1399}
1400
1401/* Relocate a given location using a given value and howto. */
1402
1403bfd_reloc_status_type
1404_bfd_relocate_contents (howto, input_bfd, relocation, location)
1405 reloc_howto_type *howto;
1406 bfd *input_bfd;
1407 bfd_vma relocation;
1408 bfd_byte *location;
1409{
1410 int size;
7442e600 1411 bfd_vma x = 0;
d5afc56e 1412 bfd_reloc_status_type flag;
252b5132
RH
1413 unsigned int rightshift = howto->rightshift;
1414 unsigned int bitpos = howto->bitpos;
1415
1416 /* If the size is negative, negate RELOCATION. This isn't very
1417 general. */
1418 if (howto->size < 0)
1419 relocation = -relocation;
1420
1421 /* Get the value we are going to relocate. */
1422 size = bfd_get_reloc_size (howto);
1423 switch (size)
1424 {
1425 default:
1426 case 0:
1427 abort ();
1428 case 1:
1429 x = bfd_get_8 (input_bfd, location);
1430 break;
1431 case 2:
1432 x = bfd_get_16 (input_bfd, location);
1433 break;
1434 case 4:
1435 x = bfd_get_32 (input_bfd, location);
1436 break;
1437 case 8:
1438#ifdef BFD64
1439 x = bfd_get_64 (input_bfd, location);
1440#else
1441 abort ();
1442#endif
1443 break;
1444 }
1445
1446 /* Check for overflow. FIXME: We may drop bits during the addition
1447 which we don't check for. We must either check at every single
1448 operation, which would be tedious, or we must do the computations
1449 in a type larger than bfd_vma, which would be inefficient. */
d5afc56e 1450 flag = bfd_reloc_ok;
252b5132
RH
1451 if (howto->complain_on_overflow != complain_overflow_dont)
1452 {
1453 bfd_vma addrmask, fieldmask, signmask, ss;
1454 bfd_vma a, b, sum;
1455
1456 /* Get the values to be added together. For signed and unsigned
1457 relocations, we assume that all values should be truncated to
1458 the size of an address. For bitfields, all the bits matter.
1459 See also bfd_check_overflow. */
1460 fieldmask = N_ONES (howto->bitsize);
1461 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
1462 a = relocation;
1463 b = x & howto->src_mask;
1464
1465 switch (howto->complain_on_overflow)
1466 {
1467 case complain_overflow_signed:
1468 a = (a & addrmask) >> rightshift;
1469
1470 /* If any sign bits are set, all sign bits must be set.
1471 That is, A must be a valid negative address after
1472 shifting. */
1473 signmask = ~ (fieldmask >> 1);
1474 ss = a & signmask;
1475 if (ss != 0 && ss != ((addrmask >> rightshift) & signmask))
d5afc56e 1476 flag = bfd_reloc_overflow;
252b5132
RH
1477
1478 /* We only need this next bit of code if the sign bit of B
1479 is below the sign bit of A. This would only happen if
1480 SRC_MASK had fewer bits than BITSIZE. Note that if
1481 SRC_MASK has more bits than BITSIZE, we can get into
1482 trouble; we would need to verify that B is in range, as
1483 we do for A above. */
1484 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
8a4ac871
AM
1485
1486 /* Set all the bits above the sign bit. */
1487 b = (b ^ signmask) - signmask;
252b5132
RH
1488
1489 b = (b & addrmask) >> bitpos;
1490
1491 /* Now we can do the addition. */
1492 sum = a + b;
1493
1494 /* See if the result has the correct sign. Bits above the
1495 sign bit are junk now; ignore them. If the sum is
1496 positive, make sure we did not have all negative inputs;
1497 if the sum is negative, make sure we did not have all
1498 positive inputs. The test below looks only at the sign
1499 bits, and it really just
1500 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
1501 */
1502 signmask = (fieldmask >> 1) + 1;
1503 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
d5afc56e 1504 flag = bfd_reloc_overflow;
252b5132
RH
1505
1506 break;
1507
1508 case complain_overflow_unsigned:
1509 /* Checking for an unsigned overflow is relatively easy:
1510 trim the addresses and add, and trim the result as well.
1511 Overflow is normally indicated when the result does not
1512 fit in the field. However, we also need to consider the
1513 case when, e.g., fieldmask is 0x7fffffff or smaller, an
1514 input is 0x80000000, and bfd_vma is only 32 bits; then we
1515 will get sum == 0, but there is an overflow, since the
1516 inputs did not fit in the field. Instead of doing a
1517 separate test, we can check for this by or-ing in the
1518 operands when testing for the sum overflowing its final
1519 field. */
1520 a = (a & addrmask) >> rightshift;
1521 b = (b & addrmask) >> bitpos;
1522 sum = (a + b) & addrmask;
1523 if ((a | b | sum) & ~ fieldmask)
d5afc56e 1524 flag = bfd_reloc_overflow;
252b5132
RH
1525
1526 break;
1527
1528 case complain_overflow_bitfield:
d5afc56e 1529 /* Much like the signed check, but for a field one bit
8a4ac871 1530 wider, and no trimming inputs with addrmask. We allow a
d5afc56e
AM
1531 bitfield to represent numbers in the range -2**n to
1532 2**n-1, where n is the number of bits in the field.
1533 Note that when bfd_vma is 32 bits, a 32-bit reloc can't
1534 overflow, which is exactly what we want. */
252b5132 1535 a >>= rightshift;
252b5132 1536
d5afc56e
AM
1537 signmask = ~ fieldmask;
1538 ss = a & signmask;
1539 if (ss != 0 && ss != (((bfd_vma) -1 >> rightshift) & signmask))
1540 flag = bfd_reloc_overflow;
252b5132 1541
d5afc56e 1542 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
8a4ac871 1543 b = (b ^ signmask) - signmask;
252b5132 1544
d5afc56e 1545 b >>= bitpos;
44257b8b 1546
252b5132 1547 sum = a + b;
d5afc56e 1548
8a4ac871
AM
1549 /* We mask with addrmask here to explicitly allow an address
1550 wrap-around. The Linux kernel relies on it, and it is
1551 the only way to write assembler code which can run when
1552 loaded at a location 0x80000000 away from the location at
1553 which it is linked. */
d5afc56e 1554 signmask = fieldmask + 1;
8a4ac871 1555 if (((~ (a ^ b)) & (a ^ sum)) & signmask & addrmask)
d5afc56e 1556 flag = bfd_reloc_overflow;
252b5132
RH
1557
1558 break;
1559
1560 default:
1561 abort ();
1562 }
1563 }
1564
1565 /* Put RELOCATION in the right bits. */
1566 relocation >>= (bfd_vma) rightshift;
1567 relocation <<= (bfd_vma) bitpos;
1568
1569 /* Add RELOCATION to the right bits of X. */
1570 x = ((x & ~howto->dst_mask)
1571 | (((x & howto->src_mask) + relocation) & howto->dst_mask));
1572
1573 /* Put the relocated value back in the object file. */
1574 switch (size)
1575 {
1576 default:
1577 case 0:
1578 abort ();
1579 case 1:
1580 bfd_put_8 (input_bfd, x, location);
1581 break;
1582 case 2:
1583 bfd_put_16 (input_bfd, x, location);
1584 break;
1585 case 4:
1586 bfd_put_32 (input_bfd, x, location);
1587 break;
1588 case 8:
1589#ifdef BFD64
1590 bfd_put_64 (input_bfd, x, location);
1591#else
1592 abort ();
1593#endif
1594 break;
1595 }
1596
d5afc56e 1597 return flag;
252b5132
RH
1598}
1599
1600/*
1601DOCDD
1602INODE
1603 howto manager, , typedef arelent, Relocations
1604
1605SECTION
1606 The howto manager
1607
1608 When an application wants to create a relocation, but doesn't
1609 know what the target machine might call it, it can find out by
1610 using this bit of code.
1611
1612*/
1613
1614/*
1615TYPEDEF
1616 bfd_reloc_code_type
1617
1618DESCRIPTION
1619 The insides of a reloc code. The idea is that, eventually, there
1620 will be one enumerator for every type of relocation we ever do.
1621 Pass one of these values to <<bfd_reloc_type_lookup>>, and it'll
1622 return a howto pointer.
1623
1624 This does mean that the application must determine the correct
1625 enumerator value; you can't get a howto pointer from a random set
1626 of attributes.
1627
1628SENUM
1629 bfd_reloc_code_real
1630
1631ENUM
1632 BFD_RELOC_64
1633ENUMX
1634 BFD_RELOC_32
1635ENUMX
1636 BFD_RELOC_26
1637ENUMX
1638 BFD_RELOC_24
1639ENUMX
1640 BFD_RELOC_16
1641ENUMX
1642 BFD_RELOC_14
1643ENUMX
1644 BFD_RELOC_8
1645ENUMDOC
1646 Basic absolute relocations of N bits.
1647
1648ENUM
1649 BFD_RELOC_64_PCREL
1650ENUMX
1651 BFD_RELOC_32_PCREL
1652ENUMX
1653 BFD_RELOC_24_PCREL
1654ENUMX
1655 BFD_RELOC_16_PCREL
1656ENUMX
1657 BFD_RELOC_12_PCREL
1658ENUMX
1659 BFD_RELOC_8_PCREL
1660ENUMDOC
1661 PC-relative relocations. Sometimes these are relative to the address
1662of the relocation itself; sometimes they are relative to the start of
1663the section containing the relocation. It depends on the specific target.
1664
1665The 24-bit relocation is used in some Intel 960 configurations.
1666
1667ENUM
1668 BFD_RELOC_32_GOT_PCREL
1669ENUMX
1670 BFD_RELOC_16_GOT_PCREL
1671ENUMX
1672 BFD_RELOC_8_GOT_PCREL
1673ENUMX
1674 BFD_RELOC_32_GOTOFF
1675ENUMX
1676 BFD_RELOC_16_GOTOFF
1677ENUMX
1678 BFD_RELOC_LO16_GOTOFF
1679ENUMX
1680 BFD_RELOC_HI16_GOTOFF
1681ENUMX
1682 BFD_RELOC_HI16_S_GOTOFF
1683ENUMX
1684 BFD_RELOC_8_GOTOFF
5bd4f169
AM
1685ENUMX
1686 BFD_RELOC_64_PLT_PCREL
252b5132
RH
1687ENUMX
1688 BFD_RELOC_32_PLT_PCREL
1689ENUMX
1690 BFD_RELOC_24_PLT_PCREL
1691ENUMX
1692 BFD_RELOC_16_PLT_PCREL
1693ENUMX
1694 BFD_RELOC_8_PLT_PCREL
5bd4f169
AM
1695ENUMX
1696 BFD_RELOC_64_PLTOFF
252b5132
RH
1697ENUMX
1698 BFD_RELOC_32_PLTOFF
1699ENUMX
1700 BFD_RELOC_16_PLTOFF
1701ENUMX
1702 BFD_RELOC_LO16_PLTOFF
1703ENUMX
1704 BFD_RELOC_HI16_PLTOFF
1705ENUMX
1706 BFD_RELOC_HI16_S_PLTOFF
1707ENUMX
1708 BFD_RELOC_8_PLTOFF
1709ENUMDOC
1710 For ELF.
1711
1712ENUM
1713 BFD_RELOC_68K_GLOB_DAT
1714ENUMX
1715 BFD_RELOC_68K_JMP_SLOT
1716ENUMX
1717 BFD_RELOC_68K_RELATIVE
1718ENUMDOC
1719 Relocations used by 68K ELF.
1720
1721ENUM
1722 BFD_RELOC_32_BASEREL
1723ENUMX
1724 BFD_RELOC_16_BASEREL
1725ENUMX
1726 BFD_RELOC_LO16_BASEREL
1727ENUMX
1728 BFD_RELOC_HI16_BASEREL
1729ENUMX
1730 BFD_RELOC_HI16_S_BASEREL
1731ENUMX
1732 BFD_RELOC_8_BASEREL
1733ENUMX
1734 BFD_RELOC_RVA
1735ENUMDOC
1736 Linkage-table relative.
1737
1738ENUM
1739 BFD_RELOC_8_FFnn
1740ENUMDOC
1741 Absolute 8-bit relocation, but used to form an address like 0xFFnn.
1742
1743ENUM
1744 BFD_RELOC_32_PCREL_S2
1745ENUMX
1746 BFD_RELOC_16_PCREL_S2
1747ENUMX
1748 BFD_RELOC_23_PCREL_S2
1749ENUMDOC
1750 These PC-relative relocations are stored as word displacements --
1751i.e., byte displacements shifted right two bits. The 30-bit word
1752displacement (<<32_PCREL_S2>> -- 32 bits, shifted 2) is used on the
1753SPARC. (SPARC tools generally refer to this as <<WDISP30>>.) The
1754signed 16-bit displacement is used on the MIPS, and the 23-bit
1755displacement is used on the Alpha.
1756
1757ENUM
1758 BFD_RELOC_HI22
1759ENUMX
1760 BFD_RELOC_LO10
1761ENUMDOC
1762 High 22 bits and low 10 bits of 32-bit value, placed into lower bits of
1763the target word. These are used on the SPARC.
1764
1765ENUM
1766 BFD_RELOC_GPREL16
1767ENUMX
1768 BFD_RELOC_GPREL32
1769ENUMDOC
1770 For systems that allocate a Global Pointer register, these are
1771displacements off that register. These relocation types are
1772handled specially, because the value the register will have is
1773decided relatively late.
1774
252b5132
RH
1775ENUM
1776 BFD_RELOC_I960_CALLJ
1777ENUMDOC
1778 Reloc types used for i960/b.out.
1779
1780ENUM
1781 BFD_RELOC_NONE
1782ENUMX
1783 BFD_RELOC_SPARC_WDISP22
1784ENUMX
1785 BFD_RELOC_SPARC22
1786ENUMX
1787 BFD_RELOC_SPARC13
1788ENUMX
1789 BFD_RELOC_SPARC_GOT10
1790ENUMX
1791 BFD_RELOC_SPARC_GOT13
1792ENUMX
1793 BFD_RELOC_SPARC_GOT22
1794ENUMX
1795 BFD_RELOC_SPARC_PC10
1796ENUMX
1797 BFD_RELOC_SPARC_PC22
1798ENUMX
1799 BFD_RELOC_SPARC_WPLT30
1800ENUMX
1801 BFD_RELOC_SPARC_COPY
1802ENUMX
1803 BFD_RELOC_SPARC_GLOB_DAT
1804ENUMX
1805 BFD_RELOC_SPARC_JMP_SLOT
1806ENUMX
1807 BFD_RELOC_SPARC_RELATIVE
0f2712ed
NC
1808ENUMX
1809 BFD_RELOC_SPARC_UA16
252b5132
RH
1810ENUMX
1811 BFD_RELOC_SPARC_UA32
0f2712ed
NC
1812ENUMX
1813 BFD_RELOC_SPARC_UA64
252b5132
RH
1814ENUMDOC
1815 SPARC ELF relocations. There is probably some overlap with other
1816 relocation types already defined.
1817
1818ENUM
1819 BFD_RELOC_SPARC_BASE13
1820ENUMX
1821 BFD_RELOC_SPARC_BASE22
1822ENUMDOC
1823 I think these are specific to SPARC a.out (e.g., Sun 4).
1824
1825ENUMEQ
1826 BFD_RELOC_SPARC_64
1827 BFD_RELOC_64
1828ENUMX
1829 BFD_RELOC_SPARC_10
1830ENUMX
1831 BFD_RELOC_SPARC_11
1832ENUMX
1833 BFD_RELOC_SPARC_OLO10
1834ENUMX
1835 BFD_RELOC_SPARC_HH22
1836ENUMX
1837 BFD_RELOC_SPARC_HM10
1838ENUMX
1839 BFD_RELOC_SPARC_LM22
1840ENUMX
1841 BFD_RELOC_SPARC_PC_HH22
1842ENUMX
1843 BFD_RELOC_SPARC_PC_HM10
1844ENUMX
1845 BFD_RELOC_SPARC_PC_LM22
1846ENUMX
1847 BFD_RELOC_SPARC_WDISP16
1848ENUMX
1849 BFD_RELOC_SPARC_WDISP19
1850ENUMX
1851 BFD_RELOC_SPARC_7
1852ENUMX
1853 BFD_RELOC_SPARC_6
1854ENUMX
1855 BFD_RELOC_SPARC_5
1856ENUMEQX
1857 BFD_RELOC_SPARC_DISP64
1858 BFD_RELOC_64_PCREL
1859ENUMX
1860 BFD_RELOC_SPARC_PLT64
1861ENUMX
1862 BFD_RELOC_SPARC_HIX22
1863ENUMX
1864 BFD_RELOC_SPARC_LOX10
1865ENUMX
1866 BFD_RELOC_SPARC_H44
1867ENUMX
1868 BFD_RELOC_SPARC_M44
1869ENUMX
1870 BFD_RELOC_SPARC_L44
1871ENUMX
1872 BFD_RELOC_SPARC_REGISTER
1873ENUMDOC
1874 SPARC64 relocations
1875
1876ENUM
1877 BFD_RELOC_SPARC_REV32
1878ENUMDOC
1879 SPARC little endian relocation
1880
1881ENUM
1882 BFD_RELOC_ALPHA_GPDISP_HI16
1883ENUMDOC
1884 Alpha ECOFF and ELF relocations. Some of these treat the symbol or
1885 "addend" in some special way.
1886 For GPDISP_HI16 ("gpdisp") relocations, the symbol is ignored when
1887 writing; when reading, it will be the absolute section symbol. The
1888 addend is the displacement in bytes of the "lda" instruction from
1889 the "ldah" instruction (which is at the address of this reloc).
1890ENUM
1891 BFD_RELOC_ALPHA_GPDISP_LO16
1892ENUMDOC
1893 For GPDISP_LO16 ("ignore") relocations, the symbol is handled as
1894 with GPDISP_HI16 relocs. The addend is ignored when writing the
1895 relocations out, and is filled in with the file's GP value on
1896 reading, for convenience.
1897
1898ENUM
1899 BFD_RELOC_ALPHA_GPDISP
1900ENUMDOC
1901 The ELF GPDISP relocation is exactly the same as the GPDISP_HI16
1902 relocation except that there is no accompanying GPDISP_LO16
1903 relocation.
1904
1905ENUM
1906 BFD_RELOC_ALPHA_LITERAL
1907ENUMX
1908 BFD_RELOC_ALPHA_ELF_LITERAL
1909ENUMX
1910 BFD_RELOC_ALPHA_LITUSE
1911ENUMDOC
1912 The Alpha LITERAL/LITUSE relocs are produced by a symbol reference;
1913 the assembler turns it into a LDQ instruction to load the address of
1914 the symbol, and then fills in a register in the real instruction.
1915
1916 The LITERAL reloc, at the LDQ instruction, refers to the .lita
1917 section symbol. The addend is ignored when writing, but is filled
1918 in with the file's GP value on reading, for convenience, as with the
1919 GPDISP_LO16 reloc.
1920
1921 The ELF_LITERAL reloc is somewhere between 16_GOTOFF and GPDISP_LO16.
1922 It should refer to the symbol to be referenced, as with 16_GOTOFF,
1923 but it generates output not based on the position within the .got
1924 section, but relative to the GP value chosen for the file during the
1925 final link stage.
1926
1927 The LITUSE reloc, on the instruction using the loaded address, gives
1928 information to the linker that it might be able to use to optimize
1929 away some literal section references. The symbol is ignored (read
1930 as the absolute section symbol), and the "addend" indicates the type
1931 of instruction using the register:
1932 1 - "memory" fmt insn
1933 2 - byte-manipulation (byte offset reg)
1934 3 - jsr (target of branch)
1935
252b5132
RH
1936ENUM
1937 BFD_RELOC_ALPHA_HINT
1938ENUMDOC
1939 The HINT relocation indicates a value that should be filled into the
1940 "hint" field of a jmp/jsr/ret instruction, for possible branch-
1941 prediction logic which may be provided on some processors.
1942
1943ENUM
1944 BFD_RELOC_ALPHA_LINKAGE
1945ENUMDOC
1946 The LINKAGE relocation outputs a linkage pair in the object file,
1947 which is filled by the linker.
1948
1949ENUM
1950 BFD_RELOC_ALPHA_CODEADDR
1951ENUMDOC
1952 The CODEADDR relocation outputs a STO_CA in the object file,
1953 which is filled by the linker.
1954
dfe57ca0
RH
1955ENUM
1956 BFD_RELOC_ALPHA_GPREL_HI16
1957ENUMX
1958 BFD_RELOC_ALPHA_GPREL_LO16
1959ENUMDOC
dc810e39
AM
1960 The GPREL_HI/LO relocations together form a 32-bit offset from the
1961 GP register.
dfe57ca0 1962
252b5132
RH
1963ENUM
1964 BFD_RELOC_MIPS_JMP
1965ENUMDOC
1966 Bits 27..2 of the relocation address shifted right 2 bits;
1967 simple reloc otherwise.
1968
1969ENUM
1970 BFD_RELOC_MIPS16_JMP
1971ENUMDOC
1972 The MIPS16 jump instruction.
1973
1974ENUM
1975 BFD_RELOC_MIPS16_GPREL
1976ENUMDOC
1977 MIPS16 GP relative reloc.
1978
1979ENUM
1980 BFD_RELOC_HI16
1981ENUMDOC
1982 High 16 bits of 32-bit value; simple reloc.
1983ENUM
1984 BFD_RELOC_HI16_S
1985ENUMDOC
1986 High 16 bits of 32-bit value but the low 16 bits will be sign
1987 extended and added to form the final result. If the low 16
1988 bits form a negative number, we need to add one to the high value
1989 to compensate for the borrow when the low bits are added.
1990ENUM
1991 BFD_RELOC_LO16
1992ENUMDOC
1993 Low 16 bits.
1994ENUM
1995 BFD_RELOC_PCREL_HI16_S
1996ENUMDOC
1997 Like BFD_RELOC_HI16_S, but PC relative.
1998ENUM
1999 BFD_RELOC_PCREL_LO16
2000ENUMDOC
2001 Like BFD_RELOC_LO16, but PC relative.
2002
252b5132
RH
2003ENUM
2004 BFD_RELOC_MIPS_LITERAL
2005ENUMDOC
2006 Relocation against a MIPS literal section.
2007
2008ENUM
2009 BFD_RELOC_MIPS_GOT16
2010ENUMX
2011 BFD_RELOC_MIPS_CALL16
252b5132
RH
2012ENUMX
2013 BFD_RELOC_MIPS_GOT_HI16
2014ENUMX
2015 BFD_RELOC_MIPS_GOT_LO16
2016ENUMX
2017 BFD_RELOC_MIPS_CALL_HI16
2018ENUMX
2019 BFD_RELOC_MIPS_CALL_LO16
3f830999
MM
2020ENUMX
2021 BFD_RELOC_MIPS_SUB
2022ENUMX
2023 BFD_RELOC_MIPS_GOT_PAGE
2024ENUMX
2025 BFD_RELOC_MIPS_GOT_OFST
2026ENUMX
2027 BFD_RELOC_MIPS_GOT_DISP
c2feb664
NC
2028ENUMX
2029 BFD_RELOC_MIPS_SHIFT5
2030ENUMX
2031 BFD_RELOC_MIPS_SHIFT6
2032ENUMX
2033 BFD_RELOC_MIPS_INSERT_A
2034ENUMX
2035 BFD_RELOC_MIPS_INSERT_B
2036ENUMX
2037 BFD_RELOC_MIPS_DELETE
2038ENUMX
2039 BFD_RELOC_MIPS_HIGHEST
2040ENUMX
2041 BFD_RELOC_MIPS_HIGHER
2042ENUMX
2043 BFD_RELOC_MIPS_SCN_DISP
2044ENUMX
2045 BFD_RELOC_MIPS_REL16
2046ENUMX
2047 BFD_RELOC_MIPS_RELGOT
2048ENUMX
2049 BFD_RELOC_MIPS_JALR
252b5132
RH
2050COMMENT
2051ENUMDOC
2052 MIPS ELF relocations.
2053
2054COMMENT
2055
2056ENUM
2057 BFD_RELOC_386_GOT32
2058ENUMX
2059 BFD_RELOC_386_PLT32
2060ENUMX
2061 BFD_RELOC_386_COPY
2062ENUMX
2063 BFD_RELOC_386_GLOB_DAT
2064ENUMX
2065 BFD_RELOC_386_JUMP_SLOT
2066ENUMX
2067 BFD_RELOC_386_RELATIVE
2068ENUMX
2069 BFD_RELOC_386_GOTOFF
2070ENUMX
2071 BFD_RELOC_386_GOTPC
2072ENUMDOC
2073 i386/elf relocations
2074
8d88c4ca
NC
2075ENUM
2076 BFD_RELOC_X86_64_GOT32
2077ENUMX
2078 BFD_RELOC_X86_64_PLT32
2079ENUMX
2080 BFD_RELOC_X86_64_COPY
2081ENUMX
2082 BFD_RELOC_X86_64_GLOB_DAT
2083ENUMX
2084 BFD_RELOC_X86_64_JUMP_SLOT
2085ENUMX
2086 BFD_RELOC_X86_64_RELATIVE
2087ENUMX
2088 BFD_RELOC_X86_64_GOTPCREL
2089ENUMX
2090 BFD_RELOC_X86_64_32S
2091ENUMDOC
2092 x86-64/elf relocations
2093
252b5132
RH
2094ENUM
2095 BFD_RELOC_NS32K_IMM_8
2096ENUMX
2097 BFD_RELOC_NS32K_IMM_16
2098ENUMX
2099 BFD_RELOC_NS32K_IMM_32
2100ENUMX
2101 BFD_RELOC_NS32K_IMM_8_PCREL
2102ENUMX
2103 BFD_RELOC_NS32K_IMM_16_PCREL
2104ENUMX
2105 BFD_RELOC_NS32K_IMM_32_PCREL
2106ENUMX
2107 BFD_RELOC_NS32K_DISP_8
2108ENUMX
2109 BFD_RELOC_NS32K_DISP_16
2110ENUMX
2111 BFD_RELOC_NS32K_DISP_32
2112ENUMX
2113 BFD_RELOC_NS32K_DISP_8_PCREL
2114ENUMX
2115 BFD_RELOC_NS32K_DISP_16_PCREL
2116ENUMX
2117 BFD_RELOC_NS32K_DISP_32_PCREL
2118ENUMDOC
2119 ns32k relocations
2120
e135f41b
NC
2121ENUM
2122 BFD_RELOC_PDP11_DISP_8_PCREL
2123ENUMX
2124 BFD_RELOC_PDP11_DISP_6_PCREL
2125ENUMDOC
2126 PDP11 relocations
2127
0bcb993b
ILT
2128ENUM
2129 BFD_RELOC_PJ_CODE_HI16
2130ENUMX
2131 BFD_RELOC_PJ_CODE_LO16
2132ENUMX
2133 BFD_RELOC_PJ_CODE_DIR16
2134ENUMX
2135 BFD_RELOC_PJ_CODE_DIR32
2136ENUMX
2137 BFD_RELOC_PJ_CODE_REL16
2138ENUMX
2139 BFD_RELOC_PJ_CODE_REL32
2140ENUMDOC
2141 Picojava relocs. Not all of these appear in object files.
88b6bae0 2142
252b5132
RH
2143ENUM
2144 BFD_RELOC_PPC_B26
2145ENUMX
2146 BFD_RELOC_PPC_BA26
2147ENUMX
2148 BFD_RELOC_PPC_TOC16
2149ENUMX
2150 BFD_RELOC_PPC_B16
2151ENUMX
2152 BFD_RELOC_PPC_B16_BRTAKEN
2153ENUMX
2154 BFD_RELOC_PPC_B16_BRNTAKEN
2155ENUMX
2156 BFD_RELOC_PPC_BA16
2157ENUMX
2158 BFD_RELOC_PPC_BA16_BRTAKEN
2159ENUMX
2160 BFD_RELOC_PPC_BA16_BRNTAKEN
2161ENUMX
2162 BFD_RELOC_PPC_COPY
2163ENUMX
2164 BFD_RELOC_PPC_GLOB_DAT
2165ENUMX
2166 BFD_RELOC_PPC_JMP_SLOT
2167ENUMX
2168 BFD_RELOC_PPC_RELATIVE
2169ENUMX
2170 BFD_RELOC_PPC_LOCAL24PC
2171ENUMX
2172 BFD_RELOC_PPC_EMB_NADDR32
2173ENUMX
2174 BFD_RELOC_PPC_EMB_NADDR16
2175ENUMX
2176 BFD_RELOC_PPC_EMB_NADDR16_LO
2177ENUMX
2178 BFD_RELOC_PPC_EMB_NADDR16_HI
2179ENUMX
2180 BFD_RELOC_PPC_EMB_NADDR16_HA
2181ENUMX
2182 BFD_RELOC_PPC_EMB_SDAI16
2183ENUMX
2184 BFD_RELOC_PPC_EMB_SDA2I16
2185ENUMX
2186 BFD_RELOC_PPC_EMB_SDA2REL
2187ENUMX
2188 BFD_RELOC_PPC_EMB_SDA21
2189ENUMX
2190 BFD_RELOC_PPC_EMB_MRKREF
2191ENUMX
2192 BFD_RELOC_PPC_EMB_RELSEC16
2193ENUMX
2194 BFD_RELOC_PPC_EMB_RELST_LO
2195ENUMX
2196 BFD_RELOC_PPC_EMB_RELST_HI
2197ENUMX
2198 BFD_RELOC_PPC_EMB_RELST_HA
2199ENUMX
2200 BFD_RELOC_PPC_EMB_BIT_FLD
2201ENUMX
2202 BFD_RELOC_PPC_EMB_RELSDA
5bd4f169
AM
2203ENUMX
2204 BFD_RELOC_PPC64_HIGHER
2205ENUMX
2206 BFD_RELOC_PPC64_HIGHER_S
2207ENUMX
2208 BFD_RELOC_PPC64_HIGHEST
2209ENUMX
2210 BFD_RELOC_PPC64_HIGHEST_S
2211ENUMX
2212 BFD_RELOC_PPC64_TOC16_LO
2213ENUMX
2214 BFD_RELOC_PPC64_TOC16_HI
2215ENUMX
2216 BFD_RELOC_PPC64_TOC16_HA
2217ENUMX
2218 BFD_RELOC_PPC64_TOC
2219ENUMX
dc810e39 2220 BFD_RELOC_PPC64_PLTGOT16
5bd4f169
AM
2221ENUMX
2222 BFD_RELOC_PPC64_PLTGOT16_LO
2223ENUMX
2224 BFD_RELOC_PPC64_PLTGOT16_HI
2225ENUMX
2226 BFD_RELOC_PPC64_PLTGOT16_HA
2227ENUMX
2228 BFD_RELOC_PPC64_ADDR16_DS
2229ENUMX
2230 BFD_RELOC_PPC64_ADDR16_LO_DS
2231ENUMX
2232 BFD_RELOC_PPC64_GOT16_DS
2233ENUMX
2234 BFD_RELOC_PPC64_GOT16_LO_DS
2235ENUMX
2236 BFD_RELOC_PPC64_PLT16_LO_DS
2237ENUMX
2238 BFD_RELOC_PPC64_SECTOFF_DS
2239ENUMX
2240 BFD_RELOC_PPC64_SECTOFF_LO_DS
2241ENUMX
2242 BFD_RELOC_PPC64_TOC16_DS
2243ENUMX
2244 BFD_RELOC_PPC64_TOC16_LO_DS
2245ENUMX
2246 BFD_RELOC_PPC64_PLTGOT16_DS
2247ENUMX
2248 BFD_RELOC_PPC64_PLTGOT16_LO_DS
252b5132
RH
2249ENUMDOC
2250 Power(rs6000) and PowerPC relocations.
2251
5b93d8bb
AM
2252ENUM
2253 BFD_RELOC_I370_D12
2254ENUMDOC
2255 IBM 370/390 relocations
2256
252b5132
RH
2257ENUM
2258 BFD_RELOC_CTOR
2259ENUMDOC
2260 The type of reloc used to build a contructor table - at the moment
2261 probably a 32 bit wide absolute relocation, but the target can choose.
2262 It generally does map to one of the other relocation types.
2263
2264ENUM
2265 BFD_RELOC_ARM_PCREL_BRANCH
2266ENUMDOC
2267 ARM 26 bit pc-relative branch. The lowest two bits must be zero and are
2268 not stored in the instruction.
dfc5f959
NC
2269ENUM
2270 BFD_RELOC_ARM_PCREL_BLX
2271ENUMDOC
2272 ARM 26 bit pc-relative branch. The lowest bit must be zero and is
2273 not stored in the instruction. The 2nd lowest bit comes from a 1 bit
2274 field in the instruction.
2275ENUM
2276 BFD_RELOC_THUMB_PCREL_BLX
2277ENUMDOC
2278 Thumb 22 bit pc-relative branch. The lowest bit must be zero and is
2279 not stored in the instruction. The 2nd lowest bit comes from a 1 bit
2280 field in the instruction.
252b5132
RH
2281ENUM
2282 BFD_RELOC_ARM_IMMEDIATE
752149a0
NC
2283ENUMX
2284 BFD_RELOC_ARM_ADRL_IMMEDIATE
252b5132
RH
2285ENUMX
2286 BFD_RELOC_ARM_OFFSET_IMM
2287ENUMX
2288 BFD_RELOC_ARM_SHIFT_IMM
2289ENUMX
2290 BFD_RELOC_ARM_SWI
2291ENUMX
2292 BFD_RELOC_ARM_MULTI
2293ENUMX
2294 BFD_RELOC_ARM_CP_OFF_IMM
2295ENUMX
2296 BFD_RELOC_ARM_ADR_IMM
2297ENUMX
2298 BFD_RELOC_ARM_LDR_IMM
2299ENUMX
2300 BFD_RELOC_ARM_LITERAL
2301ENUMX
2302 BFD_RELOC_ARM_IN_POOL
2303ENUMX
2304 BFD_RELOC_ARM_OFFSET_IMM8
2305ENUMX
2306 BFD_RELOC_ARM_HWLITERAL
2307ENUMX
2308 BFD_RELOC_ARM_THUMB_ADD
2309ENUMX
2310 BFD_RELOC_ARM_THUMB_IMM
2311ENUMX
2312 BFD_RELOC_ARM_THUMB_SHIFT
2313ENUMX
2314 BFD_RELOC_ARM_THUMB_OFFSET
2315ENUMX
2316 BFD_RELOC_ARM_GOT12
2317ENUMX
2318 BFD_RELOC_ARM_GOT32
2319ENUMX
2320 BFD_RELOC_ARM_JUMP_SLOT
2321ENUMX
2322 BFD_RELOC_ARM_COPY
2323ENUMX
2324 BFD_RELOC_ARM_GLOB_DAT
2325ENUMX
2326 BFD_RELOC_ARM_PLT32
2327ENUMX
2328 BFD_RELOC_ARM_RELATIVE
2329ENUMX
2330 BFD_RELOC_ARM_GOTOFF
2331ENUMX
2332 BFD_RELOC_ARM_GOTPC
2333ENUMDOC
2334 These relocs are only used within the ARM assembler. They are not
2335 (at present) written to any object files.
2336
2337ENUM
2338 BFD_RELOC_SH_PCDISP8BY2
2339ENUMX
2340 BFD_RELOC_SH_PCDISP12BY2
2341ENUMX
2342 BFD_RELOC_SH_IMM4
2343ENUMX
2344 BFD_RELOC_SH_IMM4BY2
2345ENUMX
2346 BFD_RELOC_SH_IMM4BY4
2347ENUMX
2348 BFD_RELOC_SH_IMM8
2349ENUMX
2350 BFD_RELOC_SH_IMM8BY2
2351ENUMX
2352 BFD_RELOC_SH_IMM8BY4
2353ENUMX
2354 BFD_RELOC_SH_PCRELIMM8BY2
2355ENUMX
2356 BFD_RELOC_SH_PCRELIMM8BY4
2357ENUMX
2358 BFD_RELOC_SH_SWITCH16
2359ENUMX
2360 BFD_RELOC_SH_SWITCH32
2361ENUMX
2362 BFD_RELOC_SH_USES
2363ENUMX
2364 BFD_RELOC_SH_COUNT
2365ENUMX
2366 BFD_RELOC_SH_ALIGN
2367ENUMX
2368 BFD_RELOC_SH_CODE
2369ENUMX
2370 BFD_RELOC_SH_DATA
2371ENUMX
2372 BFD_RELOC_SH_LABEL
015551fc
JR
2373ENUMX
2374 BFD_RELOC_SH_LOOP_START
2375ENUMX
2376 BFD_RELOC_SH_LOOP_END
3d96075c
L
2377ENUMX
2378 BFD_RELOC_SH_COPY
2379ENUMX
2380 BFD_RELOC_SH_GLOB_DAT
2381ENUMX
2382 BFD_RELOC_SH_JMP_SLOT
2383ENUMX
2384 BFD_RELOC_SH_RELATIVE
2385ENUMX
2386 BFD_RELOC_SH_GOTPC
252b5132
RH
2387ENUMDOC
2388 Hitachi SH relocs. Not all of these appear in object files.
2389
2390ENUM
2391 BFD_RELOC_THUMB_PCREL_BRANCH9
2392ENUMX
2393 BFD_RELOC_THUMB_PCREL_BRANCH12
2394ENUMX
2395 BFD_RELOC_THUMB_PCREL_BRANCH23
2396ENUMDOC
2397 Thumb 23-, 12- and 9-bit pc-relative branches. The lowest bit must
2398 be zero and is not stored in the instruction.
2399
2400ENUM
2401 BFD_RELOC_ARC_B22_PCREL
2402ENUMDOC
0d2bcfaf 2403 ARC Cores relocs.
252b5132
RH
2404 ARC 22 bit pc-relative branch. The lowest two bits must be zero and are
2405 not stored in the instruction. The high 20 bits are installed in bits 26
2406 through 7 of the instruction.
2407ENUM
2408 BFD_RELOC_ARC_B26
2409ENUMDOC
2410 ARC 26 bit absolute branch. The lowest two bits must be zero and are not
2411 stored in the instruction. The high 24 bits are installed in bits 23
2412 through 0.
2413
2414ENUM
2415 BFD_RELOC_D10V_10_PCREL_R
2416ENUMDOC
2417 Mitsubishi D10V relocs.
2418 This is a 10-bit reloc with the right 2 bits
2419 assumed to be 0.
2420ENUM
2421 BFD_RELOC_D10V_10_PCREL_L
2422ENUMDOC
2423 Mitsubishi D10V relocs.
2424 This is a 10-bit reloc with the right 2 bits
2425 assumed to be 0. This is the same as the previous reloc
2426 except it is in the left container, i.e.,
2427 shifted left 15 bits.
2428ENUM
2429 BFD_RELOC_D10V_18
2430ENUMDOC
2431 This is an 18-bit reloc with the right 2 bits
2432 assumed to be 0.
2433ENUM
2434 BFD_RELOC_D10V_18_PCREL
2435ENUMDOC
2436 This is an 18-bit reloc with the right 2 bits
2437 assumed to be 0.
2438
2439ENUM
2440 BFD_RELOC_D30V_6
2441ENUMDOC
2442 Mitsubishi D30V relocs.
2443 This is a 6-bit absolute reloc.
2444ENUM
2445 BFD_RELOC_D30V_9_PCREL
2446ENUMDOC
88b6bae0
AM
2447 This is a 6-bit pc-relative reloc with
2448 the right 3 bits assumed to be 0.
252b5132
RH
2449ENUM
2450 BFD_RELOC_D30V_9_PCREL_R
2451ENUMDOC
88b6bae0 2452 This is a 6-bit pc-relative reloc with
252b5132
RH
2453 the right 3 bits assumed to be 0. Same
2454 as the previous reloc but on the right side
88b6bae0 2455 of the container.
252b5132
RH
2456ENUM
2457 BFD_RELOC_D30V_15
2458ENUMDOC
88b6bae0
AM
2459 This is a 12-bit absolute reloc with the
2460 right 3 bitsassumed to be 0.
252b5132
RH
2461ENUM
2462 BFD_RELOC_D30V_15_PCREL
2463ENUMDOC
88b6bae0
AM
2464 This is a 12-bit pc-relative reloc with
2465 the right 3 bits assumed to be 0.
252b5132
RH
2466ENUM
2467 BFD_RELOC_D30V_15_PCREL_R
2468ENUMDOC
88b6bae0 2469 This is a 12-bit pc-relative reloc with
252b5132
RH
2470 the right 3 bits assumed to be 0. Same
2471 as the previous reloc but on the right side
88b6bae0 2472 of the container.
252b5132
RH
2473ENUM
2474 BFD_RELOC_D30V_21
2475ENUMDOC
88b6bae0 2476 This is an 18-bit absolute reloc with
252b5132
RH
2477 the right 3 bits assumed to be 0.
2478ENUM
2479 BFD_RELOC_D30V_21_PCREL
2480ENUMDOC
88b6bae0 2481 This is an 18-bit pc-relative reloc with
252b5132
RH
2482 the right 3 bits assumed to be 0.
2483ENUM
2484 BFD_RELOC_D30V_21_PCREL_R
2485ENUMDOC
88b6bae0 2486 This is an 18-bit pc-relative reloc with
252b5132
RH
2487 the right 3 bits assumed to be 0. Same
2488 as the previous reloc but on the right side
2489 of the container.
2490ENUM
2491 BFD_RELOC_D30V_32
2492ENUMDOC
2493 This is a 32-bit absolute reloc.
2494ENUM
2495 BFD_RELOC_D30V_32_PCREL
2496ENUMDOC
2497 This is a 32-bit pc-relative reloc.
2498
2499ENUM
2500 BFD_RELOC_M32R_24
2501ENUMDOC
2502 Mitsubishi M32R relocs.
2503 This is a 24 bit absolute address.
2504ENUM
2505 BFD_RELOC_M32R_10_PCREL
2506ENUMDOC
2507 This is a 10-bit pc-relative reloc with the right 2 bits assumed to be 0.
2508ENUM
2509 BFD_RELOC_M32R_18_PCREL
2510ENUMDOC
2511 This is an 18-bit reloc with the right 2 bits assumed to be 0.
2512ENUM
2513 BFD_RELOC_M32R_26_PCREL
2514ENUMDOC
2515 This is a 26-bit reloc with the right 2 bits assumed to be 0.
2516ENUM
2517 BFD_RELOC_M32R_HI16_ULO
2518ENUMDOC
2519 This is a 16-bit reloc containing the high 16 bits of an address
2520 used when the lower 16 bits are treated as unsigned.
2521ENUM
2522 BFD_RELOC_M32R_HI16_SLO
2523ENUMDOC
2524 This is a 16-bit reloc containing the high 16 bits of an address
2525 used when the lower 16 bits are treated as signed.
2526ENUM
2527 BFD_RELOC_M32R_LO16
2528ENUMDOC
2529 This is a 16-bit reloc containing the lower 16 bits of an address.
2530ENUM
2531 BFD_RELOC_M32R_SDA16
2532ENUMDOC
2533 This is a 16-bit reloc containing the small data area offset for use in
2534 add3, load, and store instructions.
2535
2536ENUM
2537 BFD_RELOC_V850_9_PCREL
2538ENUMDOC
2539 This is a 9-bit reloc
2540ENUM
2541 BFD_RELOC_V850_22_PCREL
2542ENUMDOC
2543 This is a 22-bit reloc
2544
2545ENUM
2546 BFD_RELOC_V850_SDA_16_16_OFFSET
2547ENUMDOC
2548 This is a 16 bit offset from the short data area pointer.
2549ENUM
2550 BFD_RELOC_V850_SDA_15_16_OFFSET
2551ENUMDOC
2552 This is a 16 bit offset (of which only 15 bits are used) from the
2553 short data area pointer.
2554ENUM
2555 BFD_RELOC_V850_ZDA_16_16_OFFSET
2556ENUMDOC
2557 This is a 16 bit offset from the zero data area pointer.
2558ENUM
2559 BFD_RELOC_V850_ZDA_15_16_OFFSET
2560ENUMDOC
2561 This is a 16 bit offset (of which only 15 bits are used) from the
2562 zero data area pointer.
2563ENUM
2564 BFD_RELOC_V850_TDA_6_8_OFFSET
2565ENUMDOC
2566 This is an 8 bit offset (of which only 6 bits are used) from the
2567 tiny data area pointer.
2568ENUM
2569 BFD_RELOC_V850_TDA_7_8_OFFSET
2570ENUMDOC
2571 This is an 8bit offset (of which only 7 bits are used) from the tiny
2572 data area pointer.
2573ENUM
2574 BFD_RELOC_V850_TDA_7_7_OFFSET
2575ENUMDOC
2576 This is a 7 bit offset from the tiny data area pointer.
2577ENUM
2578 BFD_RELOC_V850_TDA_16_16_OFFSET
2579ENUMDOC
2580 This is a 16 bit offset from the tiny data area pointer.
2581COMMENT
2582ENUM
2583 BFD_RELOC_V850_TDA_4_5_OFFSET
2584ENUMDOC
2585 This is a 5 bit offset (of which only 4 bits are used) from the tiny
2586 data area pointer.
2587ENUM
2588 BFD_RELOC_V850_TDA_4_4_OFFSET
2589ENUMDOC
2590 This is a 4 bit offset from the tiny data area pointer.
2591ENUM
2592 BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
2593ENUMDOC
2594 This is a 16 bit offset from the short data area pointer, with the
2595 bits placed non-contigously in the instruction.
2596ENUM
2597 BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
2598ENUMDOC
2599 This is a 16 bit offset from the zero data area pointer, with the
2600 bits placed non-contigously in the instruction.
2601ENUM
2602 BFD_RELOC_V850_CALLT_6_7_OFFSET
2603ENUMDOC
2604 This is a 6 bit offset from the call table base pointer.
2605ENUM
2606 BFD_RELOC_V850_CALLT_16_16_OFFSET
2607ENUMDOC
2608 This is a 16 bit offset from the call table base pointer.
2609COMMENT
2610
2611ENUM
2612 BFD_RELOC_MN10300_32_PCREL
2613ENUMDOC
2614 This is a 32bit pcrel reloc for the mn10300, offset by two bytes in the
2615 instruction.
2616ENUM
2617 BFD_RELOC_MN10300_16_PCREL
2618ENUMDOC
2619 This is a 16bit pcrel reloc for the mn10300, offset by two bytes in the
2620 instruction.
2621
2622ENUM
2623 BFD_RELOC_TIC30_LDP
2624ENUMDOC
2625 This is a 8bit DP reloc for the tms320c30, where the most
2626 significant 8 bits of a 24 bit word are placed into the least
2627 significant 8 bits of the opcode.
2628
81635ce4
TW
2629ENUM
2630 BFD_RELOC_TIC54X_PARTLS7
2631ENUMDOC
2632 This is a 7bit reloc for the tms320c54x, where the least
2633 significant 7 bits of a 16 bit word are placed into the least
2634 significant 7 bits of the opcode.
2635
2636ENUM
2637 BFD_RELOC_TIC54X_PARTMS9
2638ENUMDOC
2639 This is a 9bit DP reloc for the tms320c54x, where the most
2640 significant 9 bits of a 16 bit word are placed into the least
2641 significant 9 bits of the opcode.
2642
2643ENUM
2644 BFD_RELOC_TIC54X_23
2645ENUMDOC
2646 This is an extended address 23-bit reloc for the tms320c54x.
2647
2648ENUM
2649 BFD_RELOC_TIC54X_16_OF_23
2650ENUMDOC
3d855632
KH
2651 This is a 16-bit reloc for the tms320c54x, where the least
2652 significant 16 bits of a 23-bit extended address are placed into
81635ce4
TW
2653 the opcode.
2654
2655ENUM
2656 BFD_RELOC_TIC54X_MS7_OF_23
2657ENUMDOC
2658 This is a reloc for the tms320c54x, where the most
3d855632 2659 significant 7 bits of a 23-bit extended address are placed into
81635ce4 2660 the opcode.
81635ce4 2661
252b5132
RH
2662ENUM
2663 BFD_RELOC_FR30_48
2664ENUMDOC
2665 This is a 48 bit reloc for the FR30 that stores 32 bits.
2666ENUM
2667 BFD_RELOC_FR30_20
2668ENUMDOC
2669 This is a 32 bit reloc for the FR30 that stores 20 bits split up into
2670 two sections.
2671ENUM
2672 BFD_RELOC_FR30_6_IN_4
2673ENUMDOC
2674 This is a 16 bit reloc for the FR30 that stores a 6 bit word offset in
2675 4 bits.
2676ENUM
2677 BFD_RELOC_FR30_8_IN_8
2678ENUMDOC
2679 This is a 16 bit reloc for the FR30 that stores an 8 bit byte offset
2680 into 8 bits.
2681ENUM
2682 BFD_RELOC_FR30_9_IN_8
2683ENUMDOC
2684 This is a 16 bit reloc for the FR30 that stores a 9 bit short offset
2685 into 8 bits.
2686ENUM
2687 BFD_RELOC_FR30_10_IN_8
2688ENUMDOC
2689 This is a 16 bit reloc for the FR30 that stores a 10 bit word offset
2690 into 8 bits.
2691ENUM
2692 BFD_RELOC_FR30_9_PCREL
2693ENUMDOC
2694 This is a 16 bit reloc for the FR30 that stores a 9 bit pc relative
2695 short offset into 8 bits.
2696ENUM
2697 BFD_RELOC_FR30_12_PCREL
2698ENUMDOC
2699 This is a 16 bit reloc for the FR30 that stores a 12 bit pc relative
2700 short offset into 11 bits.
88b6bae0 2701
252b5132
RH
2702ENUM
2703 BFD_RELOC_MCORE_PCREL_IMM8BY4
2704ENUMX
2705 BFD_RELOC_MCORE_PCREL_IMM11BY2
2706ENUMX
2707 BFD_RELOC_MCORE_PCREL_IMM4BY2
2708ENUMX
2709 BFD_RELOC_MCORE_PCREL_32
2710ENUMX
2711 BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
36797d47
NC
2712ENUMX
2713 BFD_RELOC_MCORE_RVA
252b5132
RH
2714ENUMDOC
2715 Motorola Mcore relocations.
88b6bae0 2716
3c3bdf30
NC
2717ENUM
2718 BFD_RELOC_MMIX_GETA
2719ENUMX
2720 BFD_RELOC_MMIX_GETA_1
2721ENUMX
2722 BFD_RELOC_MMIX_GETA_2
2723ENUMX
2724 BFD_RELOC_MMIX_GETA_3
2725ENUMDOC
2726 These are relocations for the GETA instruction.
2727ENUM
2728 BFD_RELOC_MMIX_CBRANCH
2729ENUMX
2730 BFD_RELOC_MMIX_CBRANCH_J
2731ENUMX
2732 BFD_RELOC_MMIX_CBRANCH_1
2733ENUMX
2734 BFD_RELOC_MMIX_CBRANCH_2
2735ENUMX
2736 BFD_RELOC_MMIX_CBRANCH_3
2737ENUMDOC
2738 These are relocations for a conditional branch instruction.
2739ENUM
2740 BFD_RELOC_MMIX_PUSHJ
2741ENUMX
2742 BFD_RELOC_MMIX_PUSHJ_1
2743ENUMX
2744 BFD_RELOC_MMIX_PUSHJ_2
2745ENUMX
2746 BFD_RELOC_MMIX_PUSHJ_3
2747ENUMDOC
2748 These are relocations for the PUSHJ instruction.
2749ENUM
2750 BFD_RELOC_MMIX_JMP
2751ENUMX
2752 BFD_RELOC_MMIX_JMP_1
2753ENUMX
2754 BFD_RELOC_MMIX_JMP_2
2755ENUMX
2756 BFD_RELOC_MMIX_JMP_3
2757ENUMDOC
2758 These are relocations for the JMP instruction.
2759ENUM
2760 BFD_RELOC_MMIX_ADDR19
2761ENUMDOC
2762 This is a relocation for a relative address as in a GETA instruction or
2763 a branch.
2764ENUM
2765 BFD_RELOC_MMIX_ADDR27
2766ENUMDOC
2767 This is a relocation for a relative address as in a JMP instruction.
2768ENUM
2769 BFD_RELOC_MMIX_REG_OR_BYTE
2770ENUMDOC
2771 This is a relocation for an instruction field that may be a general
2772 register or a value 0..255.
2773ENUM
2774 BFD_RELOC_MMIX_REG
2775ENUMDOC
2776 This is a relocation for an instruction field that may be a general
2777 register.
2778ENUM
2779 BFD_RELOC_MMIX_BASE_PLUS_OFFSET
2780ENUMDOC
2781 This is a relocation for two instruction fields holding a register and
2782 an offset, the equivalent of the relocation.
2783ENUM
2784 BFD_RELOC_MMIX_LOCAL
2785ENUMDOC
2786 This relocation is an assertion that the expression is not allocated as
2787 a global register. It does not modify contents.
2788
adde6300
AM
2789ENUM
2790 BFD_RELOC_AVR_7_PCREL
2791ENUMDOC
2792 This is a 16 bit reloc for the AVR that stores 8 bit pc relative
2793 short offset into 7 bits.
2794ENUM
2795 BFD_RELOC_AVR_13_PCREL
2796ENUMDOC
2797 This is a 16 bit reloc for the AVR that stores 13 bit pc relative
2798 short offset into 12 bits.
2799ENUM
2800 BFD_RELOC_AVR_16_PM
2801ENUMDOC
2802 This is a 16 bit reloc for the AVR that stores 17 bit value (usually
3d855632 2803 program memory address) into 16 bits.
adde6300
AM
2804ENUM
2805 BFD_RELOC_AVR_LO8_LDI
2806ENUMDOC
2807 This is a 16 bit reloc for the AVR that stores 8 bit value (usually
2808 data memory address) into 8 bit immediate value of LDI insn.
2809ENUM
2810 BFD_RELOC_AVR_HI8_LDI
2811ENUMDOC
2812 This is a 16 bit reloc for the AVR that stores 8 bit value (high 8 bit
2813 of data memory address) into 8 bit immediate value of LDI insn.
2814ENUM
2815 BFD_RELOC_AVR_HH8_LDI
2816ENUMDOC
2817 This is a 16 bit reloc for the AVR that stores 8 bit value (most high 8 bit
2818 of program memory address) into 8 bit immediate value of LDI insn.
2819ENUM
2820 BFD_RELOC_AVR_LO8_LDI_NEG
2821ENUMDOC
2822 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2823 (usually data memory address) into 8 bit immediate value of SUBI insn.
2824ENUM
2825 BFD_RELOC_AVR_HI8_LDI_NEG
2826ENUMDOC
2827 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2828 (high 8 bit of data memory address) into 8 bit immediate value of
2829 SUBI insn.
2830ENUM
2831 BFD_RELOC_AVR_HH8_LDI_NEG
2832ENUMDOC
2833 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2834 (most high 8 bit of program memory address) into 8 bit immediate value
2835 of LDI or SUBI insn.
2836ENUM
2837 BFD_RELOC_AVR_LO8_LDI_PM
2838ENUMDOC
2839 This is a 16 bit reloc for the AVR that stores 8 bit value (usually
2840 command address) into 8 bit immediate value of LDI insn.
2841ENUM
2842 BFD_RELOC_AVR_HI8_LDI_PM
2843ENUMDOC
2844 This is a 16 bit reloc for the AVR that stores 8 bit value (high 8 bit
2845 of command address) into 8 bit immediate value of LDI insn.
2846ENUM
2847 BFD_RELOC_AVR_HH8_LDI_PM
2848ENUMDOC
2849 This is a 16 bit reloc for the AVR that stores 8 bit value (most high 8 bit
2850 of command address) into 8 bit immediate value of LDI insn.
2851ENUM
2852 BFD_RELOC_AVR_LO8_LDI_PM_NEG
2853ENUMDOC
2854 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2855 (usually command address) into 8 bit immediate value of SUBI insn.
2856ENUM
2857 BFD_RELOC_AVR_HI8_LDI_PM_NEG
2858ENUMDOC
2859 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2860 (high 8 bit of 16 bit command address) into 8 bit immediate value
2861 of SUBI insn.
2862ENUM
2863 BFD_RELOC_AVR_HH8_LDI_PM_NEG
2864ENUMDOC
2865 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2866 (high 6 bit of 22 bit command address) into 8 bit immediate
2867 value of SUBI insn.
2868ENUM
2869 BFD_RELOC_AVR_CALL
2870ENUMDOC
2871 This is a 32 bit reloc for the AVR that stores 23 bit value
2872 into 22 bits.
2873
a85d7ed0
NC
2874ENUM
2875 BFD_RELOC_390_12
2876ENUMDOC
2877 Direct 12 bit.
2878ENUM
2879 BFD_RELOC_390_GOT12
2880ENUMDOC
2881 12 bit GOT offset.
2882ENUM
2883 BFD_RELOC_390_PLT32
2884ENUMDOC
2885 32 bit PC relative PLT address.
2886ENUM
2887 BFD_RELOC_390_COPY
2888ENUMDOC
2889 Copy symbol at runtime.
2890ENUM
2891 BFD_RELOC_390_GLOB_DAT
2892ENUMDOC
2893 Create GOT entry.
2894ENUM
2895 BFD_RELOC_390_JMP_SLOT
2896ENUMDOC
2897 Create PLT entry.
2898ENUM
2899 BFD_RELOC_390_RELATIVE
2900ENUMDOC
2901 Adjust by program base.
2902ENUM
2903 BFD_RELOC_390_GOTPC
2904ENUMDOC
2905 32 bit PC relative offset to GOT.
2906ENUM
2907 BFD_RELOC_390_GOT16
2908ENUMDOC
2909 16 bit GOT offset.
2910ENUM
2911 BFD_RELOC_390_PC16DBL
2912ENUMDOC
2913 PC relative 16 bit shifted by 1.
2914ENUM
2915 BFD_RELOC_390_PLT16DBL
2916ENUMDOC
2917 16 bit PC rel. PLT shifted by 1.
2918ENUM
2919 BFD_RELOC_390_PC32DBL
2920ENUMDOC
2921 PC relative 32 bit shifted by 1.
2922ENUM
2923 BFD_RELOC_390_PLT32DBL
2924ENUMDOC
2925 32 bit PC rel. PLT shifted by 1.
2926ENUM
2927 BFD_RELOC_390_GOTPCDBL
2928ENUMDOC
2929 32 bit PC rel. GOT shifted by 1.
2930ENUM
2931 BFD_RELOC_390_GOT64
2932ENUMDOC
2933 64 bit GOT offset.
2934ENUM
2935 BFD_RELOC_390_PLT64
2936ENUMDOC
2937 64 bit PC relative PLT address.
2938ENUM
2939 BFD_RELOC_390_GOTENT
2940ENUMDOC
2941 32 bit rel. offset to GOT entry.
dc810e39 2942
252b5132
RH
2943ENUM
2944 BFD_RELOC_VTABLE_INHERIT
2945ENUMX
2946 BFD_RELOC_VTABLE_ENTRY
2947ENUMDOC
88b6bae0 2948 These two relocations are used by the linker to determine which of
252b5132
RH
2949 the entries in a C++ virtual function table are actually used. When
2950 the --gc-sections option is given, the linker will zero out the entries
2951 that are not used, so that the code for those functions need not be
2952 included in the output.
2953
2954 VTABLE_INHERIT is a zero-space relocation used to describe to the
2955 linker the inheritence tree of a C++ virtual function table. The
2956 relocation's symbol should be the parent class' vtable, and the
2957 relocation should be located at the child vtable.
2958
2959 VTABLE_ENTRY is a zero-space relocation that describes the use of a
2960 virtual function table entry. The reloc's symbol should refer to the
2961 table of the class mentioned in the code. Off of that base, an offset
88b6bae0 2962 describes the entry that is being used. For Rela hosts, this offset
252b5132
RH
2963 is stored in the reloc's addend. For Rel hosts, we are forced to put
2964 this offset in the reloc's section offset.
2965
800eeca4
JW
2966ENUM
2967 BFD_RELOC_IA64_IMM14
2968ENUMX
2969 BFD_RELOC_IA64_IMM22
2970ENUMX
2971 BFD_RELOC_IA64_IMM64
2972ENUMX
2973 BFD_RELOC_IA64_DIR32MSB
2974ENUMX
2975 BFD_RELOC_IA64_DIR32LSB
2976ENUMX
2977 BFD_RELOC_IA64_DIR64MSB
2978ENUMX
2979 BFD_RELOC_IA64_DIR64LSB
2980ENUMX
2981 BFD_RELOC_IA64_GPREL22
2982ENUMX
2983 BFD_RELOC_IA64_GPREL64I
2984ENUMX
2985 BFD_RELOC_IA64_GPREL32MSB
2986ENUMX
2987 BFD_RELOC_IA64_GPREL32LSB
2988ENUMX
2989 BFD_RELOC_IA64_GPREL64MSB
2990ENUMX
2991 BFD_RELOC_IA64_GPREL64LSB
2992ENUMX
2993 BFD_RELOC_IA64_LTOFF22
2994ENUMX
2995 BFD_RELOC_IA64_LTOFF64I
2996ENUMX
2997 BFD_RELOC_IA64_PLTOFF22
2998ENUMX
2999 BFD_RELOC_IA64_PLTOFF64I
3000ENUMX
3001 BFD_RELOC_IA64_PLTOFF64MSB
3002ENUMX
3003 BFD_RELOC_IA64_PLTOFF64LSB
3004ENUMX
3005 BFD_RELOC_IA64_FPTR64I
3006ENUMX
3007 BFD_RELOC_IA64_FPTR32MSB
3008ENUMX
3009 BFD_RELOC_IA64_FPTR32LSB
3010ENUMX
3011 BFD_RELOC_IA64_FPTR64MSB
3012ENUMX
3013 BFD_RELOC_IA64_FPTR64LSB
3014ENUMX
3015 BFD_RELOC_IA64_PCREL21B
748abff6
RH
3016ENUMX
3017 BFD_RELOC_IA64_PCREL21BI
800eeca4
JW
3018ENUMX
3019 BFD_RELOC_IA64_PCREL21M
3020ENUMX
3021 BFD_RELOC_IA64_PCREL21F
748abff6
RH
3022ENUMX
3023 BFD_RELOC_IA64_PCREL22
3024ENUMX
3025 BFD_RELOC_IA64_PCREL60B
3026ENUMX
3027 BFD_RELOC_IA64_PCREL64I
800eeca4
JW
3028ENUMX
3029 BFD_RELOC_IA64_PCREL32MSB
3030ENUMX
3031 BFD_RELOC_IA64_PCREL32LSB
3032ENUMX
3033 BFD_RELOC_IA64_PCREL64MSB
3034ENUMX
3035 BFD_RELOC_IA64_PCREL64LSB
3036ENUMX
3037 BFD_RELOC_IA64_LTOFF_FPTR22
3038ENUMX
3039 BFD_RELOC_IA64_LTOFF_FPTR64I
a4bd8390
JW
3040ENUMX
3041 BFD_RELOC_IA64_LTOFF_FPTR32MSB
3042ENUMX
3043 BFD_RELOC_IA64_LTOFF_FPTR32LSB
800eeca4
JW
3044ENUMX
3045 BFD_RELOC_IA64_LTOFF_FPTR64MSB
3046ENUMX
3047 BFD_RELOC_IA64_LTOFF_FPTR64LSB
800eeca4
JW
3048ENUMX
3049 BFD_RELOC_IA64_SEGREL32MSB
3050ENUMX
3051 BFD_RELOC_IA64_SEGREL32LSB
3052ENUMX
3053 BFD_RELOC_IA64_SEGREL64MSB
3054ENUMX
3055 BFD_RELOC_IA64_SEGREL64LSB
3056ENUMX
3057 BFD_RELOC_IA64_SECREL32MSB
3058ENUMX
3059 BFD_RELOC_IA64_SECREL32LSB
3060ENUMX
3061 BFD_RELOC_IA64_SECREL64MSB
3062ENUMX
3063 BFD_RELOC_IA64_SECREL64LSB
3064ENUMX
3065 BFD_RELOC_IA64_REL32MSB
3066ENUMX
3067 BFD_RELOC_IA64_REL32LSB
3068ENUMX
3069 BFD_RELOC_IA64_REL64MSB
3070ENUMX
3071 BFD_RELOC_IA64_REL64LSB
3072ENUMX
3073 BFD_RELOC_IA64_LTV32MSB
3074ENUMX
3075 BFD_RELOC_IA64_LTV32LSB
3076ENUMX
3077 BFD_RELOC_IA64_LTV64MSB
3078ENUMX
3079 BFD_RELOC_IA64_LTV64LSB
3080ENUMX
3081 BFD_RELOC_IA64_IPLTMSB
3082ENUMX
3083 BFD_RELOC_IA64_IPLTLSB
800eeca4
JW
3084ENUMX
3085 BFD_RELOC_IA64_COPY
3086ENUMX
3087 BFD_RELOC_IA64_TPREL22
3088ENUMX
3089 BFD_RELOC_IA64_TPREL64MSB
3090ENUMX
3091 BFD_RELOC_IA64_TPREL64LSB
3092ENUMX
3093 BFD_RELOC_IA64_LTOFF_TP22
3094ENUMX
3095 BFD_RELOC_IA64_LTOFF22X
3096ENUMX
3097 BFD_RELOC_IA64_LDXMOV
3098ENUMDOC
3099 Intel IA64 Relocations.
60bcf0fa
NC
3100
3101ENUM
3102 BFD_RELOC_M68HC11_HI8
3103ENUMDOC
3104 Motorola 68HC11 reloc.
3105 This is the 8 bits high part of an absolute address.
3106ENUM
3107 BFD_RELOC_M68HC11_LO8
3108ENUMDOC
3109 Motorola 68HC11 reloc.
3110 This is the 8 bits low part of an absolute address.
3111ENUM
3112 BFD_RELOC_M68HC11_3B
3113ENUMDOC
3114 Motorola 68HC11 reloc.
3115 This is the 3 bits of a value.
3116
06c15ad7
HPN
3117ENUM
3118 BFD_RELOC_CRIS_BDISP8
3119ENUMX
3120 BFD_RELOC_CRIS_UNSIGNED_5
3121ENUMX
3122 BFD_RELOC_CRIS_SIGNED_6
3123ENUMX
3124 BFD_RELOC_CRIS_UNSIGNED_6
3125ENUMX
3126 BFD_RELOC_CRIS_UNSIGNED_4
3127ENUMDOC
3128 These relocs are only used within the CRIS assembler. They are not
3129 (at present) written to any object files.
58d29fc3
HPN
3130ENUM
3131 BFD_RELOC_CRIS_COPY
3132ENUMX
3133 BFD_RELOC_CRIS_GLOB_DAT
3134ENUMX
3135 BFD_RELOC_CRIS_JUMP_SLOT
3136ENUMX
3137 BFD_RELOC_CRIS_RELATIVE
3138ENUMDOC
3139 Relocs used in ELF shared libraries for CRIS.
3140ENUM
3141 BFD_RELOC_CRIS_32_GOT
3142ENUMDOC
3143 32-bit offset to symbol-entry within GOT.
3144ENUM
3145 BFD_RELOC_CRIS_16_GOT
3146ENUMDOC
3147 16-bit offset to symbol-entry within GOT.
3148ENUM
3149 BFD_RELOC_CRIS_32_GOTPLT
3150ENUMDOC
3151 32-bit offset to symbol-entry within GOT, with PLT handling.
3152ENUM
3153 BFD_RELOC_CRIS_16_GOTPLT
3154ENUMDOC
3155 16-bit offset to symbol-entry within GOT, with PLT handling.
3156ENUM
3157 BFD_RELOC_CRIS_32_GOTREL
3158ENUMDOC
3159 32-bit offset to symbol, relative to GOT.
3160ENUM
3161 BFD_RELOC_CRIS_32_PLT_GOTREL
3162ENUMDOC
3163 32-bit offset to symbol with PLT entry, relative to GOT.
3164ENUM
3165 BFD_RELOC_CRIS_32_PLT_PCREL
3166ENUMDOC
3167 32-bit offset to symbol with PLT entry, relative to this relocation.
06c15ad7 3168
a87fdb8d
JE
3169ENUM
3170 BFD_RELOC_860_COPY
3171ENUMX
3172 BFD_RELOC_860_GLOB_DAT
3173ENUMX
3174 BFD_RELOC_860_JUMP_SLOT
3175ENUMX
3176 BFD_RELOC_860_RELATIVE
3177ENUMX
3178 BFD_RELOC_860_PC26
3179ENUMX
3180 BFD_RELOC_860_PLT26
3181ENUMX
3182 BFD_RELOC_860_PC16
3183ENUMX
3184 BFD_RELOC_860_LOW0
3185ENUMX
3186 BFD_RELOC_860_SPLIT0
3187ENUMX
3188 BFD_RELOC_860_LOW1
3189ENUMX
3190 BFD_RELOC_860_SPLIT1
3191ENUMX
3192 BFD_RELOC_860_LOW2
3193ENUMX
3194 BFD_RELOC_860_SPLIT2
3195ENUMX
3196 BFD_RELOC_860_LOW3
3197ENUMX
3198 BFD_RELOC_860_LOGOT0
3199ENUMX
3200 BFD_RELOC_860_SPGOT0
3201ENUMX
3202 BFD_RELOC_860_LOGOT1
3203ENUMX
3204 BFD_RELOC_860_SPGOT1
3205ENUMX
3206 BFD_RELOC_860_LOGOTOFF0
3207ENUMX
3208 BFD_RELOC_860_SPGOTOFF0
3209ENUMX
3210 BFD_RELOC_860_LOGOTOFF1
3211ENUMX
3212 BFD_RELOC_860_SPGOTOFF1
3213ENUMX
3214 BFD_RELOC_860_LOGOTOFF2
3215ENUMX
3216 BFD_RELOC_860_LOGOTOFF3
3217ENUMX
3218 BFD_RELOC_860_LOPC
3219ENUMX
3220 BFD_RELOC_860_HIGHADJ
3221ENUMX
3222 BFD_RELOC_860_HAGOT
3223ENUMX
3224 BFD_RELOC_860_HAGOTOFF
3225ENUMX
3226 BFD_RELOC_860_HAPC
3227ENUMX
3228 BFD_RELOC_860_HIGH
3229ENUMX
3230 BFD_RELOC_860_HIGOT
3231ENUMX
3232 BFD_RELOC_860_HIGOTOFF
3233ENUMDOC
3234 Intel i860 Relocations.
3235
b3baf5d0
NC
3236ENUM
3237 BFD_RELOC_OPENRISC_ABS_26
3238ENUMX
3239 BFD_RELOC_OPENRISC_REL_26
3240ENUMDOC
3241 OpenRISC Relocations.
3242
e01b0e69
JR
3243ENUM
3244 BFD_RELOC_H8_DIR16A8
3245ENUMX
3246 BFD_RELOC_H8_DIR16R8
3247ENUMX
3248 BFD_RELOC_H8_DIR24A8
3249ENUMX
3250 BFD_RELOC_H8_DIR24R8
3251ENUMX
3252 BFD_RELOC_H8_DIR32A16
3253ENUMDOC
3254 H8 elf Relocations.
3255
93fbbb04
GK
3256ENUM
3257 BFD_RELOC_XSTORMY16_REL_12
3258ENUMX
3259 BFD_RELOC_XSTORMY16_24
3260ENUMX
3261 BFD_RELOC_XSTORMY16_FPTR16
3262ENUMDOC
3263 Sony Xstormy16 Relocations.
3264
252b5132
RH
3265ENDSENUM
3266 BFD_RELOC_UNUSED
3267CODE_FRAGMENT
3268.
3269.typedef enum bfd_reloc_code_real bfd_reloc_code_real_type;
3270*/
3271
252b5132
RH
3272/*
3273FUNCTION
3274 bfd_reloc_type_lookup
3275
3276SYNOPSIS
3277 reloc_howto_type *
3278 bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code);
3279
3280DESCRIPTION
3281 Return a pointer to a howto structure which, when
3282 invoked, will perform the relocation @var{code} on data from the
3283 architecture noted.
3284
3285*/
3286
252b5132
RH
3287reloc_howto_type *
3288bfd_reloc_type_lookup (abfd, code)
3289 bfd *abfd;
3290 bfd_reloc_code_real_type code;
3291{
3292 return BFD_SEND (abfd, reloc_type_lookup, (abfd, code));
3293}
3294
3295static reloc_howto_type bfd_howto_32 =
3296HOWTO (0, 00, 2, 32, false, 0, complain_overflow_bitfield, 0, "VRT32", false, 0xffffffff, 0xffffffff, true);
3297
252b5132
RH
3298/*
3299INTERNAL_FUNCTION
3300 bfd_default_reloc_type_lookup
3301
3302SYNOPSIS
3303 reloc_howto_type *bfd_default_reloc_type_lookup
3304 (bfd *abfd, bfd_reloc_code_real_type code);
3305
3306DESCRIPTION
3307 Provides a default relocation lookup routine for any architecture.
3308
252b5132
RH
3309*/
3310
3311reloc_howto_type *
3312bfd_default_reloc_type_lookup (abfd, code)
3313 bfd *abfd;
3314 bfd_reloc_code_real_type code;
3315{
3316 switch (code)
3317 {
3318 case BFD_RELOC_CTOR:
3319 /* The type of reloc used in a ctor, which will be as wide as the
3320 address - so either a 64, 32, or 16 bitter. */
3321 switch (bfd_get_arch_info (abfd)->bits_per_address)
3322 {
3323 case 64:
3324 BFD_FAIL ();
3325 case 32:
3326 return &bfd_howto_32;
3327 case 16:
3328 BFD_FAIL ();
3329 default:
3330 BFD_FAIL ();
3331 }
3332 default:
3333 BFD_FAIL ();
3334 }
3335 return (reloc_howto_type *) NULL;
3336}
3337
3338/*
3339FUNCTION
3340 bfd_get_reloc_code_name
3341
3342SYNOPSIS
3343 const char *bfd_get_reloc_code_name (bfd_reloc_code_real_type code);
3344
3345DESCRIPTION
3346 Provides a printable name for the supplied relocation code.
3347 Useful mainly for printing error messages.
3348*/
3349
3350const char *
3351bfd_get_reloc_code_name (code)
3352 bfd_reloc_code_real_type code;
3353{
3354 if (code > BFD_RELOC_UNUSED)
3355 return 0;
3356 return bfd_reloc_code_real_names[(int)code];
3357}
3358
3359/*
3360INTERNAL_FUNCTION
3361 bfd_generic_relax_section
3362
3363SYNOPSIS
3364 boolean bfd_generic_relax_section
3365 (bfd *abfd,
3366 asection *section,
3367 struct bfd_link_info *,
3368 boolean *);
3369
3370DESCRIPTION
3371 Provides default handling for relaxing for back ends which
3372 don't do relaxing -- i.e., does nothing.
3373*/
3374
3375/*ARGSUSED*/
3376boolean
3377bfd_generic_relax_section (abfd, section, link_info, again)
7442e600
ILT
3378 bfd *abfd ATTRIBUTE_UNUSED;
3379 asection *section ATTRIBUTE_UNUSED;
3380 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
252b5132
RH
3381 boolean *again;
3382{
3383 *again = false;
3384 return true;
3385}
3386
3387/*
3388INTERNAL_FUNCTION
3389 bfd_generic_gc_sections
3390
3391SYNOPSIS
3392 boolean bfd_generic_gc_sections
3393 (bfd *, struct bfd_link_info *);
3394
3395DESCRIPTION
3396 Provides default handling for relaxing for back ends which
3397 don't do section gc -- i.e., does nothing.
3398*/
3399
3400/*ARGSUSED*/
3401boolean
3402bfd_generic_gc_sections (abfd, link_info)
7442e600
ILT
3403 bfd *abfd ATTRIBUTE_UNUSED;
3404 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
252b5132
RH
3405{
3406 return true;
3407}
3408
8550eb6e
JJ
3409/*
3410INTERNAL_FUNCTION
3411 bfd_generic_merge_sections
3412
3413SYNOPSIS
3414 boolean bfd_generic_merge_sections
3415 (bfd *, struct bfd_link_info *);
3416
3417DESCRIPTION
3418 Provides default handling for SEC_MERGE section merging for back ends
3419 which don't have SEC_MERGE support -- i.e., does nothing.
3420*/
3421
3422/*ARGSUSED*/
3423boolean
3424bfd_generic_merge_sections (abfd, link_info)
3425 bfd *abfd ATTRIBUTE_UNUSED;
3426 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
3427{
3428 return true;
3429}
3430
252b5132
RH
3431/*
3432INTERNAL_FUNCTION
3433 bfd_generic_get_relocated_section_contents
3434
3435SYNOPSIS
3436 bfd_byte *
3437 bfd_generic_get_relocated_section_contents (bfd *abfd,
3438 struct bfd_link_info *link_info,
3439 struct bfd_link_order *link_order,
3440 bfd_byte *data,
3441 boolean relocateable,
3442 asymbol **symbols);
3443
3444DESCRIPTION
3445 Provides default handling of relocation effort for back ends
3446 which can't be bothered to do it efficiently.
3447
3448*/
3449
3450bfd_byte *
3451bfd_generic_get_relocated_section_contents (abfd, link_info, link_order, data,
3452 relocateable, symbols)
3453 bfd *abfd;
3454 struct bfd_link_info *link_info;
3455 struct bfd_link_order *link_order;
3456 bfd_byte *data;
3457 boolean relocateable;
3458 asymbol **symbols;
3459{
3460 /* Get enough memory to hold the stuff */
3461 bfd *input_bfd = link_order->u.indirect.section->owner;
3462 asection *input_section = link_order->u.indirect.section;
3463
3464 long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
3465 arelent **reloc_vector = NULL;
3466 long reloc_count;
3467
3468 if (reloc_size < 0)
3469 goto error_return;
3470
dc810e39 3471 reloc_vector = (arelent **) bfd_malloc ((bfd_size_type) reloc_size);
252b5132
RH
3472 if (reloc_vector == NULL && reloc_size != 0)
3473 goto error_return;
3474
3475 /* read in the section */
3476 if (!bfd_get_section_contents (input_bfd,
3477 input_section,
3478 (PTR) data,
dc810e39 3479 (bfd_vma) 0,
252b5132
RH
3480 input_section->_raw_size))
3481 goto error_return;
3482
3483 /* We're not relaxing the section, so just copy the size info */
3484 input_section->_cooked_size = input_section->_raw_size;
3485 input_section->reloc_done = true;
3486
3487 reloc_count = bfd_canonicalize_reloc (input_bfd,
3488 input_section,
3489 reloc_vector,
3490 symbols);
3491 if (reloc_count < 0)
3492 goto error_return;
3493
3494 if (reloc_count > 0)
3495 {
3496 arelent **parent;
3497 for (parent = reloc_vector; *parent != (arelent *) NULL;
3498 parent++)
3499 {
3500 char *error_message = (char *) NULL;
3501 bfd_reloc_status_type r =
3502 bfd_perform_relocation (input_bfd,
3503 *parent,
3504 (PTR) data,
3505 input_section,
3506 relocateable ? abfd : (bfd *) NULL,
3507 &error_message);
3508
3509 if (relocateable)
3510 {
3511 asection *os = input_section->output_section;
3512
3513 /* A partial link, so keep the relocs */
3514 os->orelocation[os->reloc_count] = *parent;
3515 os->reloc_count++;
3516 }
3517
3518 if (r != bfd_reloc_ok)
3519 {
3520 switch (r)
3521 {
3522 case bfd_reloc_undefined:
3523 if (!((*link_info->callbacks->undefined_symbol)
3524 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
5cc7c785
L
3525 input_bfd, input_section, (*parent)->address,
3526 true)))
252b5132
RH
3527 goto error_return;
3528 break;
3529 case bfd_reloc_dangerous:
3530 BFD_ASSERT (error_message != (char *) NULL);
3531 if (!((*link_info->callbacks->reloc_dangerous)
3532 (link_info, error_message, input_bfd, input_section,
3533 (*parent)->address)))
3534 goto error_return;
3535 break;
3536 case bfd_reloc_overflow:
3537 if (!((*link_info->callbacks->reloc_overflow)
3538 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
3539 (*parent)->howto->name, (*parent)->addend,
3540 input_bfd, input_section, (*parent)->address)))
3541 goto error_return;
3542 break;
3543 case bfd_reloc_outofrange:
3544 default:
3545 abort ();
3546 break;
3547 }
3548
3549 }
3550 }
3551 }
3552 if (reloc_vector != NULL)
3553 free (reloc_vector);
3554 return data;
3555
3556error_return:
3557 if (reloc_vector != NULL)
3558 free (reloc_vector);
3559 return NULL;
3560}
This page took 0.451274 seconds and 4 git commands to generate.