Add field ``name'' to floatformat.
[binutils.git] / bfd / reloc.c
blob7b86e37be30e8b53b8e6b49fa190f3b8163980b4
1 /* BFD support for handling relocation entries.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
4 Written by Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 SECTION
24 Relocations
26 BFD maintains relocations in much the same way it maintains
27 symbols: they are left alone until required, then read in
28 en-masse and translated into an internal form. A common
29 routine <<bfd_perform_relocation>> acts upon the
30 canonical form to do the fixup.
32 Relocations are maintained on a per section basis,
33 while symbols are maintained on a per BFD basis.
35 All that a back end has to do to fit the BFD interface is to create
36 a <<struct reloc_cache_entry>> for each relocation
37 in a particular section, and fill in the right bits of the structures.
39 @menu
40 @* typedef arelent::
41 @* howto manager::
42 @end menu
46 /* DO compile in the reloc_code name table from libbfd.h. */
47 #define _BFD_MAKE_TABLE_bfd_reloc_code_real
49 #include "bfd.h"
50 #include "sysdep.h"
51 #include "bfdlink.h"
52 #include "libbfd.h"
54 DOCDD
55 INODE
56 typedef arelent, howto manager, Relocations, Relocations
58 SUBSECTION
59 typedef arelent
61 This is the structure of a relocation entry:
63 CODE_FRAGMENT
65 .typedef enum bfd_reloc_status
67 . {* No errors detected *}
68 . bfd_reloc_ok,
70 . {* The relocation was performed, but there was an overflow. *}
71 . bfd_reloc_overflow,
73 . {* The address to relocate was not within the section supplied. *}
74 . bfd_reloc_outofrange,
76 . {* Used by special functions *}
77 . bfd_reloc_continue,
79 . {* Unsupported relocation size requested. *}
80 . bfd_reloc_notsupported,
82 . {* Unused *}
83 . bfd_reloc_other,
85 . {* The symbol to relocate against was undefined. *}
86 . bfd_reloc_undefined,
88 . {* The relocation was performed, but may not be ok - presently
89 . generated only when linking i960 coff files with i960 b.out
90 . symbols. If this type is returned, the error_message argument
91 . to bfd_perform_relocation will be set. *}
92 . bfd_reloc_dangerous
93 . }
94 . bfd_reloc_status_type;
97 .typedef struct reloc_cache_entry
99 . {* A pointer into the canonical table of pointers *}
100 . struct symbol_cache_entry **sym_ptr_ptr;
102 . {* offset in section *}
103 . bfd_size_type address;
105 . {* addend for relocation value *}
106 . bfd_vma addend;
108 . {* Pointer to how to perform the required relocation *}
109 . reloc_howto_type *howto;
111 .} arelent;
116 DESCRIPTION
118 Here is a description of each of the fields within an <<arelent>>:
120 o <<sym_ptr_ptr>>
122 The symbol table pointer points to a pointer to the symbol
123 associated with the relocation request. It is
124 the pointer into the table returned by the back end's
125 <<get_symtab>> action. @xref{Symbols}. The symbol is referenced
126 through a pointer to a pointer so that tools like the linker
127 can fix up all the symbols of the same name by modifying only
128 one pointer. The relocation routine looks in the symbol and
129 uses the base of the section the symbol is attached to and the
130 value of the symbol as the initial relocation offset. If the
131 symbol pointer is zero, then the section provided is looked up.
133 o <<address>>
135 The <<address>> field gives the offset in bytes from the base of
136 the section data which owns the relocation record to the first
137 byte of relocatable information. The actual data relocated
138 will be relative to this point; for example, a relocation
139 type which modifies the bottom two bytes of a four byte word
140 would not touch the first byte pointed to in a big endian
141 world.
143 o <<addend>>
145 The <<addend>> is a value provided by the back end to be added (!)
146 to the relocation offset. Its interpretation is dependent upon
147 the howto. For example, on the 68k the code:
150 | char foo[];
151 | main()
153 | return foo[0x12345678];
156 Could be compiled into:
158 | linkw fp,#-4
159 | moveb @@#12345678,d0
160 | extbl d0
161 | unlk fp
162 | rts
165 This could create a reloc pointing to <<foo>>, but leave the
166 offset in the data, something like:
169 |RELOCATION RECORDS FOR [.text]:
170 |offset type value
171 |00000006 32 _foo
173 |00000000 4e56 fffc ; linkw fp,#-4
174 |00000004 1039 1234 5678 ; moveb @@#12345678,d0
175 |0000000a 49c0 ; extbl d0
176 |0000000c 4e5e ; unlk fp
177 |0000000e 4e75 ; rts
180 Using coff and an 88k, some instructions don't have enough
181 space in them to represent the full address range, and
182 pointers have to be loaded in two parts. So you'd get something like:
185 | or.u r13,r0,hi16(_foo+0x12345678)
186 | ld.b r2,r13,lo16(_foo+0x12345678)
187 | jmp r1
190 This should create two relocs, both pointing to <<_foo>>, and with
191 0x12340000 in their addend field. The data would consist of:
194 |RELOCATION RECORDS FOR [.text]:
195 |offset type value
196 |00000002 HVRT16 _foo+0x12340000
197 |00000006 LVRT16 _foo+0x12340000
199 |00000000 5da05678 ; or.u r13,r0,0x5678
200 |00000004 1c4d5678 ; ld.b r2,r13,0x5678
201 |00000008 f400c001 ; jmp r1
204 The relocation routine digs out the value from the data, adds
205 it to the addend to get the original offset, and then adds the
206 value of <<_foo>>. Note that all 32 bits have to be kept around
207 somewhere, to cope with carry from bit 15 to bit 16.
209 One further example is the sparc and the a.out format. The
210 sparc has a similar problem to the 88k, in that some
211 instructions don't have room for an entire offset, but on the
212 sparc the parts are created in odd sized lumps. The designers of
213 the a.out format chose to not use the data within the section
214 for storing part of the offset; all the offset is kept within
215 the reloc. Anything in the data should be ignored.
217 | save %sp,-112,%sp
218 | sethi %hi(_foo+0x12345678),%g2
219 | ldsb [%g2+%lo(_foo+0x12345678)],%i0
220 | ret
221 | restore
223 Both relocs contain a pointer to <<foo>>, and the offsets
224 contain junk.
227 |RELOCATION RECORDS FOR [.text]:
228 |offset type value
229 |00000004 HI22 _foo+0x12345678
230 |00000008 LO10 _foo+0x12345678
232 |00000000 9de3bf90 ; save %sp,-112,%sp
233 |00000004 05000000 ; sethi %hi(_foo+0),%g2
234 |00000008 f048a000 ; ldsb [%g2+%lo(_foo+0)],%i0
235 |0000000c 81c7e008 ; ret
236 |00000010 81e80000 ; restore
239 o <<howto>>
241 The <<howto>> field can be imagined as a
242 relocation instruction. It is a pointer to a structure which
243 contains information on what to do with all of the other
244 information in the reloc record and data section. A back end
245 would normally have a relocation instruction set and turn
246 relocations into pointers to the correct structure on input -
247 but it would be possible to create each howto field on demand.
252 SUBSUBSECTION
253 <<enum complain_overflow>>
255 Indicates what sort of overflow checking should be done when
256 performing a relocation.
258 CODE_FRAGMENT
260 .enum complain_overflow
262 . {* Do not complain on overflow. *}
263 . complain_overflow_dont,
265 . {* Complain if the bitfield overflows, whether it is considered
266 . as signed or unsigned. *}
267 . complain_overflow_bitfield,
269 . {* Complain if the value overflows when considered as signed
270 . number. *}
271 . complain_overflow_signed,
273 . {* Complain if the value overflows when considered as an
274 . unsigned number. *}
275 . complain_overflow_unsigned
281 SUBSUBSECTION
282 <<reloc_howto_type>>
284 The <<reloc_howto_type>> is a structure which contains all the
285 information that libbfd needs to know to tie up a back end's data.
287 CODE_FRAGMENT
288 .struct symbol_cache_entry; {* Forward declaration *}
290 .struct reloc_howto_struct
292 . {* The type field has mainly a documentary use - the back end can
293 . do what it wants with it, though normally the back end's
294 . external idea of what a reloc number is stored
295 . in this field. For example, a PC relative word relocation
296 . in a coff environment has the type 023 - because that's
297 . what the outside world calls a R_PCRWORD reloc. *}
298 . unsigned int type;
300 . {* The value the final relocation is shifted right by. This drops
301 . unwanted data from the relocation. *}
302 . unsigned int rightshift;
304 . {* The size of the item to be relocated. This is *not* a
305 . power-of-two measure. To get the number of bytes operated
306 . on by a type of relocation, use bfd_get_reloc_size. *}
307 . int size;
309 . {* The number of bits in the item to be relocated. This is used
310 . when doing overflow checking. *}
311 . unsigned int bitsize;
313 . {* Notes that the relocation is relative to the location in the
314 . data section of the addend. The relocation function will
315 . subtract from the relocation value the address of the location
316 . being relocated. *}
317 . boolean pc_relative;
319 . {* The bit position of the reloc value in the destination.
320 . The relocated value is left shifted by this amount. *}
321 . unsigned int bitpos;
323 . {* What type of overflow error should be checked for when
324 . relocating. *}
325 . enum complain_overflow complain_on_overflow;
327 . {* If this field is non null, then the supplied function is
328 . called rather than the normal function. This allows really
329 . strange relocation methods to be accomodated (e.g., i960 callj
330 . instructions). *}
331 . bfd_reloc_status_type (*special_function)
332 . PARAMS ((bfd *abfd,
333 . arelent *reloc_entry,
334 . struct symbol_cache_entry *symbol,
335 . PTR data,
336 . asection *input_section,
337 . bfd *output_bfd,
338 . char **error_message));
340 . {* The textual name of the relocation type. *}
341 . char *name;
343 . {* Some formats record a relocation addend in the section contents
344 . rather than with the relocation. For ELF formats this is the
345 . distinction between USE_REL and USE_RELA (though the code checks
346 . for USE_REL == 1/0). The value of this field is TRUE if the
347 . addend is recorded with the section contents; when performing a
348 . partial link (ld -r) the section contents (the data) will be
349 . modified. The value of this field is FALSE if addends are
350 . recorded with the relocation (in arelent.addend); when performing
351 . a partial link the relocation will be modified.
352 . All relocations for all ELF USE_RELA targets should set this field
353 . to FALSE (values of TRUE should be looked on with suspicion).
354 . However, the converse is not true: not all relocations of all ELF
355 . USE_REL targets set this field to TRUE. Why this is so is peculiar
356 . to each particular target. For relocs that aren't used in partial
357 . links (e.g. GOT stuff) it doesn't matter what this is set to. *}
358 . boolean partial_inplace;
360 . {* The src_mask selects which parts of the read in data
361 . are to be used in the relocation sum. E.g., if this was an 8 bit
362 . byte of data which we read and relocated, this would be
363 . 0x000000ff. When we have relocs which have an addend, such as
364 . sun4 extended relocs, the value in the offset part of a
365 . relocating field is garbage so we never use it. In this case
366 . the mask would be 0x00000000. *}
367 . bfd_vma src_mask;
369 . {* The dst_mask selects which parts of the instruction are replaced
370 . into the instruction. In most cases src_mask == dst_mask,
371 . except in the above special case, where dst_mask would be
372 . 0x000000ff, and src_mask would be 0x00000000. *}
373 . bfd_vma dst_mask;
375 . {* When some formats create PC relative instructions, they leave
376 . the value of the pc of the place being relocated in the offset
377 . slot of the instruction, so that a PC relative relocation can
378 . be made just by adding in an ordinary offset (e.g., sun3 a.out).
379 . Some formats leave the displacement part of an instruction
380 . empty (e.g., m88k bcs); this flag signals the fact.*}
381 . boolean pcrel_offset;
388 FUNCTION
389 The HOWTO Macro
391 DESCRIPTION
392 The HOWTO define is horrible and will go away.
395 .#define HOWTO(C, R,S,B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
396 . {(unsigned)C,R,S,B, P, BI, O,SF,NAME,INPLACE,MASKSRC,MASKDST,PC}
398 DESCRIPTION
399 And will be replaced with the totally magic way. But for the
400 moment, we are compatible, so do it this way.
403 .#define NEWHOWTO( FUNCTION, NAME,SIZE,REL,IN) HOWTO(0,0,SIZE,0,REL,0,complain_overflow_dont,FUNCTION, NAME,false,0,0,IN)
406 DESCRIPTION
407 This is used to fill in an empty howto entry in an array.
409 .#define EMPTY_HOWTO(C) \
410 . HOWTO((C),0,0,0,false,0,complain_overflow_dont,NULL,NULL,false,0,0,false)
413 DESCRIPTION
414 Helper routine to turn a symbol into a relocation value.
416 .#define HOWTO_PREPARE(relocation, symbol) \
417 . { \
418 . if (symbol != (asymbol *)NULL) { \
419 . if (bfd_is_com_section (symbol->section)) { \
420 . relocation = 0; \
421 . } \
422 . else { \
423 . relocation = symbol->value; \
424 . } \
425 . } \
431 FUNCTION
432 bfd_get_reloc_size
434 SYNOPSIS
435 unsigned int bfd_get_reloc_size (reloc_howto_type *);
437 DESCRIPTION
438 For a reloc_howto_type that operates on a fixed number of bytes,
439 this returns the number of bytes operated on.
442 unsigned int
443 bfd_get_reloc_size (howto)
444 reloc_howto_type *howto;
446 switch (howto->size)
448 case 0: return 1;
449 case 1: return 2;
450 case 2: return 4;
451 case 3: return 0;
452 case 4: return 8;
453 case 8: return 16;
454 case -2: return 4;
455 default: abort ();
460 TYPEDEF
461 arelent_chain
463 DESCRIPTION
465 How relocs are tied together in an <<asection>>:
467 .typedef struct relent_chain {
468 . arelent relent;
469 . struct relent_chain *next;
470 .} arelent_chain;
474 /* N_ONES produces N one bits, without overflowing machine arithmetic. */
475 #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
478 FUNCTION
479 bfd_check_overflow
481 SYNOPSIS
482 bfd_reloc_status_type
483 bfd_check_overflow
484 (enum complain_overflow how,
485 unsigned int bitsize,
486 unsigned int rightshift,
487 unsigned int addrsize,
488 bfd_vma relocation);
490 DESCRIPTION
491 Perform overflow checking on @var{relocation} which has
492 @var{bitsize} significant bits and will be shifted right by
493 @var{rightshift} bits, on a machine with addresses containing
494 @var{addrsize} significant bits. The result is either of
495 @code{bfd_reloc_ok} or @code{bfd_reloc_overflow}.
499 bfd_reloc_status_type
500 bfd_check_overflow (how, bitsize, rightshift, addrsize, relocation)
501 enum complain_overflow how;
502 unsigned int bitsize;
503 unsigned int rightshift;
504 unsigned int addrsize;
505 bfd_vma relocation;
507 bfd_vma fieldmask, addrmask, signmask, ss, a;
508 bfd_reloc_status_type flag = bfd_reloc_ok;
510 a = relocation;
512 /* Note: BITSIZE should always be <= ADDRSIZE, but in case it's not,
513 we'll be permissive: extra bits in the field mask will
514 automatically extend the address mask for purposes of the
515 overflow check. */
516 fieldmask = N_ONES (bitsize);
517 addrmask = N_ONES (addrsize) | fieldmask;
519 switch (how)
521 case complain_overflow_dont:
522 break;
524 case complain_overflow_signed:
525 /* If any sign bits are set, all sign bits must be set. That
526 is, A must be a valid negative address after shifting. */
527 a = (a & addrmask) >> rightshift;
528 signmask = ~ (fieldmask >> 1);
529 ss = a & signmask;
530 if (ss != 0 && ss != ((addrmask >> rightshift) & signmask))
531 flag = bfd_reloc_overflow;
532 break;
534 case complain_overflow_unsigned:
535 /* We have an overflow if the address does not fit in the field. */
536 a = (a & addrmask) >> rightshift;
537 if ((a & ~ fieldmask) != 0)
538 flag = bfd_reloc_overflow;
539 break;
541 case complain_overflow_bitfield:
542 /* Bitfields are sometimes signed, sometimes unsigned. We
543 explicitly allow an address wrap too, which means a bitfield
544 of n bits is allowed to store -2**n to 2**n-1. Thus overflow
545 if the value has some, but not all, bits set outside the
546 field. */
547 a >>= rightshift;
548 ss = a & ~ fieldmask;
549 if (ss != 0 && ss != (((bfd_vma) -1 >> rightshift) & ~ fieldmask))
550 flag = bfd_reloc_overflow;
551 break;
553 default:
554 abort ();
557 return flag;
561 FUNCTION
562 bfd_perform_relocation
564 SYNOPSIS
565 bfd_reloc_status_type
566 bfd_perform_relocation
567 (bfd *abfd,
568 arelent *reloc_entry,
569 PTR data,
570 asection *input_section,
571 bfd *output_bfd,
572 char **error_message);
574 DESCRIPTION
575 If @var{output_bfd} is supplied to this function, the
576 generated image will be relocatable; the relocations are
577 copied to the output file after they have been changed to
578 reflect the new state of the world. There are two ways of
579 reflecting the results of partial linkage in an output file:
580 by modifying the output data in place, and by modifying the
581 relocation record. Some native formats (e.g., basic a.out and
582 basic coff) have no way of specifying an addend in the
583 relocation type, so the addend has to go in the output data.
584 This is no big deal since in these formats the output data
585 slot will always be big enough for the addend. Complex reloc
586 types with addends were invented to solve just this problem.
587 The @var{error_message} argument is set to an error message if
588 this return @code{bfd_reloc_dangerous}.
593 bfd_reloc_status_type
594 bfd_perform_relocation (abfd, reloc_entry, data, input_section, output_bfd,
595 error_message)
596 bfd *abfd;
597 arelent *reloc_entry;
598 PTR data;
599 asection *input_section;
600 bfd *output_bfd;
601 char **error_message;
603 bfd_vma relocation;
604 bfd_reloc_status_type flag = bfd_reloc_ok;
605 bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
606 bfd_vma output_base = 0;
607 reloc_howto_type *howto = reloc_entry->howto;
608 asection *reloc_target_output_section;
609 asymbol *symbol;
611 symbol = *(reloc_entry->sym_ptr_ptr);
612 if (bfd_is_abs_section (symbol->section)
613 && output_bfd != (bfd *) NULL)
615 reloc_entry->address += input_section->output_offset;
616 return bfd_reloc_ok;
619 /* If we are not producing relocateable output, return an error if
620 the symbol is not defined. An undefined weak symbol is
621 considered to have a value of zero (SVR4 ABI, p. 4-27). */
622 if (bfd_is_und_section (symbol->section)
623 && (symbol->flags & BSF_WEAK) == 0
624 && output_bfd == (bfd *) NULL)
625 flag = bfd_reloc_undefined;
627 /* If there is a function supplied to handle this relocation type,
628 call it. It'll return `bfd_reloc_continue' if further processing
629 can be done. */
630 if (howto->special_function)
632 bfd_reloc_status_type cont;
633 cont = howto->special_function (abfd, reloc_entry, symbol, data,
634 input_section, output_bfd,
635 error_message);
636 if (cont != bfd_reloc_continue)
637 return cont;
640 /* Is the address of the relocation really within the section? */
641 if (reloc_entry->address > input_section->_cooked_size /
642 bfd_octets_per_byte (abfd))
643 return bfd_reloc_outofrange;
645 /* Work out which section the relocation is targetted at and the
646 initial relocation command value. */
648 /* Get symbol value. (Common symbols are special.) */
649 if (bfd_is_com_section (symbol->section))
650 relocation = 0;
651 else
652 relocation = symbol->value;
655 reloc_target_output_section = symbol->section->output_section;
657 /* Convert input-section-relative symbol value to absolute. */
658 if (output_bfd && howto->partial_inplace == false)
659 output_base = 0;
660 else
661 output_base = reloc_target_output_section->vma;
663 relocation += output_base + symbol->section->output_offset;
665 /* Add in supplied addend. */
666 relocation += reloc_entry->addend;
668 /* Here the variable relocation holds the final address of the
669 symbol we are relocating against, plus any addend. */
671 if (howto->pc_relative == true)
673 /* This is a PC relative relocation. We want to set RELOCATION
674 to the distance between the address of the symbol and the
675 location. RELOCATION is already the address of the symbol.
677 We start by subtracting the address of the section containing
678 the location.
680 If pcrel_offset is set, we must further subtract the position
681 of the location within the section. Some targets arrange for
682 the addend to be the negative of the position of the location
683 within the section; for example, i386-aout does this. For
684 i386-aout, pcrel_offset is false. Some other targets do not
685 include the position of the location; for example, m88kbcs,
686 or ELF. For those targets, pcrel_offset is true.
688 If we are producing relocateable output, then we must ensure
689 that this reloc will be correctly computed when the final
690 relocation is done. If pcrel_offset is false we want to wind
691 up with the negative of the location within the section,
692 which means we must adjust the existing addend by the change
693 in the location within the section. If pcrel_offset is true
694 we do not want to adjust the existing addend at all.
696 FIXME: This seems logical to me, but for the case of
697 producing relocateable output it is not what the code
698 actually does. I don't want to change it, because it seems
699 far too likely that something will break. */
701 relocation -=
702 input_section->output_section->vma + input_section->output_offset;
704 if (howto->pcrel_offset == true)
705 relocation -= reloc_entry->address;
708 if (output_bfd != (bfd *) NULL)
710 if (howto->partial_inplace == false)
712 /* This is a partial relocation, and we want to apply the relocation
713 to the reloc entry rather than the raw data. Modify the reloc
714 inplace to reflect what we now know. */
715 reloc_entry->addend = relocation;
716 reloc_entry->address += input_section->output_offset;
717 return flag;
719 else
721 /* This is a partial relocation, but inplace, so modify the
722 reloc record a bit.
724 If we've relocated with a symbol with a section, change
725 into a ref to the section belonging to the symbol. */
727 reloc_entry->address += input_section->output_offset;
729 /* WTF?? */
730 if (abfd->xvec->flavour == bfd_target_coff_flavour
731 && strcmp (abfd->xvec->name, "aixcoff-rs6000") != 0
732 && strcmp (abfd->xvec->name, "aixcoff64-rs6000") != 0
733 && strcmp (abfd->xvec->name, "xcoff-powermac") != 0
734 && strcmp (abfd->xvec->name, "coff-Intel-little") != 0
735 && strcmp (abfd->xvec->name, "coff-Intel-big") != 0)
737 #if 1
738 /* For m68k-coff, the addend was being subtracted twice during
739 relocation with -r. Removing the line below this comment
740 fixes that problem; see PR 2953.
742 However, Ian wrote the following, regarding removing the line below,
743 which explains why it is still enabled: --djm
745 If you put a patch like that into BFD you need to check all the COFF
746 linkers. I am fairly certain that patch will break coff-i386 (e.g.,
747 SCO); see coff_i386_reloc in coff-i386.c where I worked around the
748 problem in a different way. There may very well be a reason that the
749 code works as it does.
751 Hmmm. The first obvious point is that bfd_perform_relocation should
752 not have any tests that depend upon the flavour. It's seem like
753 entirely the wrong place for such a thing. The second obvious point
754 is that the current code ignores the reloc addend when producing
755 relocateable output for COFF. That's peculiar. In fact, I really
756 have no idea what the point of the line you want to remove is.
758 A typical COFF reloc subtracts the old value of the symbol and adds in
759 the new value to the location in the object file (if it's a pc
760 relative reloc it adds the difference between the symbol value and the
761 location). When relocating we need to preserve that property.
763 BFD handles this by setting the addend to the negative of the old
764 value of the symbol. Unfortunately it handles common symbols in a
765 non-standard way (it doesn't subtract the old value) but that's a
766 different story (we can't change it without losing backward
767 compatibility with old object files) (coff-i386 does subtract the old
768 value, to be compatible with existing coff-i386 targets, like SCO).
770 So everything works fine when not producing relocateable output. When
771 we are producing relocateable output, logically we should do exactly
772 what we do when not producing relocateable output. Therefore, your
773 patch is correct. In fact, it should probably always just set
774 reloc_entry->addend to 0 for all cases, since it is, in fact, going to
775 add the value into the object file. This won't hurt the COFF code,
776 which doesn't use the addend; I'm not sure what it will do to other
777 formats (the thing to check for would be whether any formats both use
778 the addend and set partial_inplace).
780 When I wanted to make coff-i386 produce relocateable output, I ran
781 into the problem that you are running into: I wanted to remove that
782 line. Rather than risk it, I made the coff-i386 relocs use a special
783 function; it's coff_i386_reloc in coff-i386.c. The function
784 specifically adds the addend field into the object file, knowing that
785 bfd_perform_relocation is not going to. If you remove that line, then
786 coff-i386.c will wind up adding the addend field in twice. It's
787 trivial to fix; it just needs to be done.
789 The problem with removing the line is just that it may break some
790 working code. With BFD it's hard to be sure of anything. The right
791 way to deal with this is simply to build and test at least all the
792 supported COFF targets. It should be straightforward if time and disk
793 space consuming. For each target:
794 1) build the linker
795 2) generate some executable, and link it using -r (I would
796 probably use paranoia.o and link against newlib/libc.a, which
797 for all the supported targets would be available in
798 /usr/cygnus/progressive/H-host/target/lib/libc.a).
799 3) make the change to reloc.c
800 4) rebuild the linker
801 5) repeat step 2
802 6) if the resulting object files are the same, you have at least
803 made it no worse
804 7) if they are different you have to figure out which version is
805 right
807 relocation -= reloc_entry->addend;
808 #endif
809 reloc_entry->addend = 0;
811 else
813 reloc_entry->addend = relocation;
817 else
819 reloc_entry->addend = 0;
822 /* FIXME: This overflow checking is incomplete, because the value
823 might have overflowed before we get here. For a correct check we
824 need to compute the value in a size larger than bitsize, but we
825 can't reasonably do that for a reloc the same size as a host
826 machine word.
827 FIXME: We should also do overflow checking on the result after
828 adding in the value contained in the object file. */
829 if (howto->complain_on_overflow != complain_overflow_dont
830 && flag == bfd_reloc_ok)
831 flag = bfd_check_overflow (howto->complain_on_overflow,
832 howto->bitsize,
833 howto->rightshift,
834 bfd_arch_bits_per_address (abfd),
835 relocation);
838 Either we are relocating all the way, or we don't want to apply
839 the relocation to the reloc entry (probably because there isn't
840 any room in the output format to describe addends to relocs)
843 /* The cast to bfd_vma avoids a bug in the Alpha OSF/1 C compiler
844 (OSF version 1.3, compiler version 3.11). It miscompiles the
845 following program:
847 struct str
849 unsigned int i0;
850 } s = { 0 };
853 main ()
855 unsigned long x;
857 x = 0x100000000;
858 x <<= (unsigned long) s.i0;
859 if (x == 0)
860 printf ("failed\n");
861 else
862 printf ("succeeded (%lx)\n", x);
866 relocation >>= (bfd_vma) howto->rightshift;
868 /* Shift everything up to where it's going to be used */
870 relocation <<= (bfd_vma) howto->bitpos;
872 /* Wait for the day when all have the mask in them */
874 /* What we do:
875 i instruction to be left alone
876 o offset within instruction
877 r relocation offset to apply
878 S src mask
879 D dst mask
880 N ~dst mask
881 A part 1
882 B part 2
883 R result
885 Do this:
886 (( i i i i i o o o o o from bfd_get<size>
887 and S S S S S) to get the size offset we want
888 + r r r r r r r r r r) to get the final value to place
889 and D D D D D to chop to right size
890 -----------------------
891 = A A A A A
892 And this:
893 ( i i i i i o o o o o from bfd_get<size>
894 and N N N N N ) get instruction
895 -----------------------
896 = B B B B B
898 And then:
899 ( B B B B B
900 or A A A A A)
901 -----------------------
902 = R R R R R R R R R R put into bfd_put<size>
905 #define DOIT(x) \
906 x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask))
908 switch (howto->size)
910 case 0:
912 char x = bfd_get_8 (abfd, (char *) data + octets);
913 DOIT (x);
914 bfd_put_8 (abfd, x, (unsigned char *) data + octets);
916 break;
918 case 1:
920 short x = bfd_get_16 (abfd, (bfd_byte *) data + octets);
921 DOIT (x);
922 bfd_put_16 (abfd, x, (unsigned char *) data + octets);
924 break;
925 case 2:
927 long x = bfd_get_32 (abfd, (bfd_byte *) data + octets);
928 DOIT (x);
929 bfd_put_32 (abfd, x, (bfd_byte *) data + octets);
931 break;
932 case -2:
934 long x = bfd_get_32 (abfd, (bfd_byte *) data + octets);
935 relocation = -relocation;
936 DOIT (x);
937 bfd_put_32 (abfd, x, (bfd_byte *) data + octets);
939 break;
941 case -1:
943 long x = bfd_get_16 (abfd, (bfd_byte *) data + octets);
944 relocation = -relocation;
945 DOIT (x);
946 bfd_put_16 (abfd, x, (bfd_byte *) data + octets);
948 break;
950 case 3:
951 /* Do nothing */
952 break;
954 case 4:
955 #ifdef BFD64
957 bfd_vma x = bfd_get_64 (abfd, (bfd_byte *) data + octets);
958 DOIT (x);
959 bfd_put_64 (abfd, x, (bfd_byte *) data + octets);
961 #else
962 abort ();
963 #endif
964 break;
965 default:
966 return bfd_reloc_other;
969 return flag;
973 FUNCTION
974 bfd_install_relocation
976 SYNOPSIS
977 bfd_reloc_status_type
978 bfd_install_relocation
979 (bfd *abfd,
980 arelent *reloc_entry,
981 PTR data, bfd_vma data_start,
982 asection *input_section,
983 char **error_message);
985 DESCRIPTION
986 This looks remarkably like <<bfd_perform_relocation>>, except it
987 does not expect that the section contents have been filled in.
988 I.e., it's suitable for use when creating, rather than applying
989 a relocation.
991 For now, this function should be considered reserved for the
992 assembler.
997 bfd_reloc_status_type
998 bfd_install_relocation (abfd, reloc_entry, data_start, data_start_offset,
999 input_section, error_message)
1000 bfd *abfd;
1001 arelent *reloc_entry;
1002 PTR data_start;
1003 bfd_vma data_start_offset;
1004 asection *input_section;
1005 char **error_message;
1007 bfd_vma relocation;
1008 bfd_reloc_status_type flag = bfd_reloc_ok;
1009 bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1010 bfd_vma output_base = 0;
1011 reloc_howto_type *howto = reloc_entry->howto;
1012 asection *reloc_target_output_section;
1013 asymbol *symbol;
1014 bfd_byte *data;
1016 symbol = *(reloc_entry->sym_ptr_ptr);
1017 if (bfd_is_abs_section (symbol->section))
1019 reloc_entry->address += input_section->output_offset;
1020 return bfd_reloc_ok;
1023 /* If there is a function supplied to handle this relocation type,
1024 call it. It'll return `bfd_reloc_continue' if further processing
1025 can be done. */
1026 if (howto->special_function)
1028 bfd_reloc_status_type cont;
1030 /* XXX - The special_function calls haven't been fixed up to deal
1031 with creating new relocations and section contents. */
1032 cont = howto->special_function (abfd, reloc_entry, symbol,
1033 /* XXX - Non-portable! */
1034 ((bfd_byte *) data_start
1035 - data_start_offset),
1036 input_section, abfd, error_message);
1037 if (cont != bfd_reloc_continue)
1038 return cont;
1041 /* Is the address of the relocation really within the section? */
1042 if (reloc_entry->address > input_section->_cooked_size)
1043 return bfd_reloc_outofrange;
1045 /* Work out which section the relocation is targetted at and the
1046 initial relocation command value. */
1048 /* Get symbol value. (Common symbols are special.) */
1049 if (bfd_is_com_section (symbol->section))
1050 relocation = 0;
1051 else
1052 relocation = symbol->value;
1054 reloc_target_output_section = symbol->section->output_section;
1056 /* Convert input-section-relative symbol value to absolute. */
1057 if (howto->partial_inplace == false)
1058 output_base = 0;
1059 else
1060 output_base = reloc_target_output_section->vma;
1062 relocation += output_base + symbol->section->output_offset;
1064 /* Add in supplied addend. */
1065 relocation += reloc_entry->addend;
1067 /* Here the variable relocation holds the final address of the
1068 symbol we are relocating against, plus any addend. */
1070 if (howto->pc_relative == true)
1072 /* This is a PC relative relocation. We want to set RELOCATION
1073 to the distance between the address of the symbol and the
1074 location. RELOCATION is already the address of the symbol.
1076 We start by subtracting the address of the section containing
1077 the location.
1079 If pcrel_offset is set, we must further subtract the position
1080 of the location within the section. Some targets arrange for
1081 the addend to be the negative of the position of the location
1082 within the section; for example, i386-aout does this. For
1083 i386-aout, pcrel_offset is false. Some other targets do not
1084 include the position of the location; for example, m88kbcs,
1085 or ELF. For those targets, pcrel_offset is true.
1087 If we are producing relocateable output, then we must ensure
1088 that this reloc will be correctly computed when the final
1089 relocation is done. If pcrel_offset is false we want to wind
1090 up with the negative of the location within the section,
1091 which means we must adjust the existing addend by the change
1092 in the location within the section. If pcrel_offset is true
1093 we do not want to adjust the existing addend at all.
1095 FIXME: This seems logical to me, but for the case of
1096 producing relocateable output it is not what the code
1097 actually does. I don't want to change it, because it seems
1098 far too likely that something will break. */
1100 relocation -=
1101 input_section->output_section->vma + input_section->output_offset;
1103 if (howto->pcrel_offset == true && howto->partial_inplace == true)
1104 relocation -= reloc_entry->address;
1107 if (howto->partial_inplace == false)
1109 /* This is a partial relocation, and we want to apply the relocation
1110 to the reloc entry rather than the raw data. Modify the reloc
1111 inplace to reflect what we now know. */
1112 reloc_entry->addend = relocation;
1113 reloc_entry->address += input_section->output_offset;
1114 return flag;
1116 else
1118 /* This is a partial relocation, but inplace, so modify the
1119 reloc record a bit.
1121 If we've relocated with a symbol with a section, change
1122 into a ref to the section belonging to the symbol. */
1124 reloc_entry->address += input_section->output_offset;
1126 /* WTF?? */
1127 if (abfd->xvec->flavour == bfd_target_coff_flavour
1128 && strcmp (abfd->xvec->name, "aixcoff-rs6000") != 0
1129 && strcmp (abfd->xvec->name, "aixcoff64-rs6000") != 0
1130 && strcmp (abfd->xvec->name, "xcoff-powermac") != 0
1131 && strcmp (abfd->xvec->name, "coff-Intel-little") != 0
1132 && strcmp (abfd->xvec->name, "coff-Intel-big") != 0)
1134 #if 1
1135 /* For m68k-coff, the addend was being subtracted twice during
1136 relocation with -r. Removing the line below this comment
1137 fixes that problem; see PR 2953.
1139 However, Ian wrote the following, regarding removing the line below,
1140 which explains why it is still enabled: --djm
1142 If you put a patch like that into BFD you need to check all the COFF
1143 linkers. I am fairly certain that patch will break coff-i386 (e.g.,
1144 SCO); see coff_i386_reloc in coff-i386.c where I worked around the
1145 problem in a different way. There may very well be a reason that the
1146 code works as it does.
1148 Hmmm. The first obvious point is that bfd_install_relocation should
1149 not have any tests that depend upon the flavour. It's seem like
1150 entirely the wrong place for such a thing. The second obvious point
1151 is that the current code ignores the reloc addend when producing
1152 relocateable output for COFF. That's peculiar. In fact, I really
1153 have no idea what the point of the line you want to remove is.
1155 A typical COFF reloc subtracts the old value of the symbol and adds in
1156 the new value to the location in the object file (if it's a pc
1157 relative reloc it adds the difference between the symbol value and the
1158 location). When relocating we need to preserve that property.
1160 BFD handles this by setting the addend to the negative of the old
1161 value of the symbol. Unfortunately it handles common symbols in a
1162 non-standard way (it doesn't subtract the old value) but that's a
1163 different story (we can't change it without losing backward
1164 compatibility with old object files) (coff-i386 does subtract the old
1165 value, to be compatible with existing coff-i386 targets, like SCO).
1167 So everything works fine when not producing relocateable output. When
1168 we are producing relocateable output, logically we should do exactly
1169 what we do when not producing relocateable output. Therefore, your
1170 patch is correct. In fact, it should probably always just set
1171 reloc_entry->addend to 0 for all cases, since it is, in fact, going to
1172 add the value into the object file. This won't hurt the COFF code,
1173 which doesn't use the addend; I'm not sure what it will do to other
1174 formats (the thing to check for would be whether any formats both use
1175 the addend and set partial_inplace).
1177 When I wanted to make coff-i386 produce relocateable output, I ran
1178 into the problem that you are running into: I wanted to remove that
1179 line. Rather than risk it, I made the coff-i386 relocs use a special
1180 function; it's coff_i386_reloc in coff-i386.c. The function
1181 specifically adds the addend field into the object file, knowing that
1182 bfd_install_relocation is not going to. If you remove that line, then
1183 coff-i386.c will wind up adding the addend field in twice. It's
1184 trivial to fix; it just needs to be done.
1186 The problem with removing the line is just that it may break some
1187 working code. With BFD it's hard to be sure of anything. The right
1188 way to deal with this is simply to build and test at least all the
1189 supported COFF targets. It should be straightforward if time and disk
1190 space consuming. For each target:
1191 1) build the linker
1192 2) generate some executable, and link it using -r (I would
1193 probably use paranoia.o and link against newlib/libc.a, which
1194 for all the supported targets would be available in
1195 /usr/cygnus/progressive/H-host/target/lib/libc.a).
1196 3) make the change to reloc.c
1197 4) rebuild the linker
1198 5) repeat step 2
1199 6) if the resulting object files are the same, you have at least
1200 made it no worse
1201 7) if they are different you have to figure out which version is
1202 right
1204 relocation -= reloc_entry->addend;
1205 #endif
1206 reloc_entry->addend = 0;
1208 else
1210 reloc_entry->addend = relocation;
1214 /* FIXME: This overflow checking is incomplete, because the value
1215 might have overflowed before we get here. For a correct check we
1216 need to compute the value in a size larger than bitsize, but we
1217 can't reasonably do that for a reloc the same size as a host
1218 machine word.
1219 FIXME: We should also do overflow checking on the result after
1220 adding in the value contained in the object file. */
1221 if (howto->complain_on_overflow != complain_overflow_dont)
1222 flag = bfd_check_overflow (howto->complain_on_overflow,
1223 howto->bitsize,
1224 howto->rightshift,
1225 bfd_arch_bits_per_address (abfd),
1226 relocation);
1229 Either we are relocating all the way, or we don't want to apply
1230 the relocation to the reloc entry (probably because there isn't
1231 any room in the output format to describe addends to relocs)
1234 /* The cast to bfd_vma avoids a bug in the Alpha OSF/1 C compiler
1235 (OSF version 1.3, compiler version 3.11). It miscompiles the
1236 following program:
1238 struct str
1240 unsigned int i0;
1241 } s = { 0 };
1244 main ()
1246 unsigned long x;
1248 x = 0x100000000;
1249 x <<= (unsigned long) s.i0;
1250 if (x == 0)
1251 printf ("failed\n");
1252 else
1253 printf ("succeeded (%lx)\n", x);
1257 relocation >>= (bfd_vma) howto->rightshift;
1259 /* Shift everything up to where it's going to be used */
1261 relocation <<= (bfd_vma) howto->bitpos;
1263 /* Wait for the day when all have the mask in them */
1265 /* What we do:
1266 i instruction to be left alone
1267 o offset within instruction
1268 r relocation offset to apply
1269 S src mask
1270 D dst mask
1271 N ~dst mask
1272 A part 1
1273 B part 2
1274 R result
1276 Do this:
1277 (( i i i i i o o o o o from bfd_get<size>
1278 and S S S S S) to get the size offset we want
1279 + r r r r r r r r r r) to get the final value to place
1280 and D D D D D to chop to right size
1281 -----------------------
1282 = A A A A A
1283 And this:
1284 ( i i i i i o o o o o from bfd_get<size>
1285 and N N N N N ) get instruction
1286 -----------------------
1287 = B B B B B
1289 And then:
1290 ( B B B B B
1291 or A A A A A)
1292 -----------------------
1293 = R R R R R R R R R R put into bfd_put<size>
1296 #define DOIT(x) \
1297 x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask))
1299 data = (bfd_byte *) data_start + (octets - data_start_offset);
1301 switch (howto->size)
1303 case 0:
1305 char x = bfd_get_8 (abfd, (char *) data);
1306 DOIT (x);
1307 bfd_put_8 (abfd, x, (unsigned char *) data);
1309 break;
1311 case 1:
1313 short x = bfd_get_16 (abfd, (bfd_byte *) data);
1314 DOIT (x);
1315 bfd_put_16 (abfd, x, (unsigned char *) data);
1317 break;
1318 case 2:
1320 long x = bfd_get_32 (abfd, (bfd_byte *) data);
1321 DOIT (x);
1322 bfd_put_32 (abfd, x, (bfd_byte *) data);
1324 break;
1325 case -2:
1327 long x = bfd_get_32 (abfd, (bfd_byte *) data);
1328 relocation = -relocation;
1329 DOIT (x);
1330 bfd_put_32 (abfd, x, (bfd_byte *) data);
1332 break;
1334 case 3:
1335 /* Do nothing */
1336 break;
1338 case 4:
1340 bfd_vma x = bfd_get_64 (abfd, (bfd_byte *) data);
1341 DOIT (x);
1342 bfd_put_64 (abfd, x, (bfd_byte *) data);
1344 break;
1345 default:
1346 return bfd_reloc_other;
1349 return flag;
1352 /* This relocation routine is used by some of the backend linkers.
1353 They do not construct asymbol or arelent structures, so there is no
1354 reason for them to use bfd_perform_relocation. Also,
1355 bfd_perform_relocation is so hacked up it is easier to write a new
1356 function than to try to deal with it.
1358 This routine does a final relocation. Whether it is useful for a
1359 relocateable link depends upon how the object format defines
1360 relocations.
1362 FIXME: This routine ignores any special_function in the HOWTO,
1363 since the existing special_function values have been written for
1364 bfd_perform_relocation.
1366 HOWTO is the reloc howto information.
1367 INPUT_BFD is the BFD which the reloc applies to.
1368 INPUT_SECTION is the section which the reloc applies to.
1369 CONTENTS is the contents of the section.
1370 ADDRESS is the address of the reloc within INPUT_SECTION.
1371 VALUE is the value of the symbol the reloc refers to.
1372 ADDEND is the addend of the reloc. */
1374 bfd_reloc_status_type
1375 _bfd_final_link_relocate (howto, input_bfd, input_section, contents, address,
1376 value, addend)
1377 reloc_howto_type *howto;
1378 bfd *input_bfd;
1379 asection *input_section;
1380 bfd_byte *contents;
1381 bfd_vma address;
1382 bfd_vma value;
1383 bfd_vma addend;
1385 bfd_vma relocation;
1387 /* Sanity check the address. */
1388 if (address > input_section->_raw_size)
1389 return bfd_reloc_outofrange;
1391 /* This function assumes that we are dealing with a basic relocation
1392 against a symbol. We want to compute the value of the symbol to
1393 relocate to. This is just VALUE, the value of the symbol, plus
1394 ADDEND, any addend associated with the reloc. */
1395 relocation = value + addend;
1397 /* If the relocation is PC relative, we want to set RELOCATION to
1398 the distance between the symbol (currently in RELOCATION) and the
1399 location we are relocating. Some targets (e.g., i386-aout)
1400 arrange for the contents of the section to be the negative of the
1401 offset of the location within the section; for such targets
1402 pcrel_offset is false. Other targets (e.g., m88kbcs or ELF)
1403 simply leave the contents of the section as zero; for such
1404 targets pcrel_offset is true. If pcrel_offset is false we do not
1405 need to subtract out the offset of the location within the
1406 section (which is just ADDRESS). */
1407 if (howto->pc_relative)
1409 relocation -= (input_section->output_section->vma
1410 + input_section->output_offset);
1411 if (howto->pcrel_offset)
1412 relocation -= address;
1415 return _bfd_relocate_contents (howto, input_bfd, relocation,
1416 contents + address);
1419 /* Relocate a given location using a given value and howto. */
1421 bfd_reloc_status_type
1422 _bfd_relocate_contents (howto, input_bfd, relocation, location)
1423 reloc_howto_type *howto;
1424 bfd *input_bfd;
1425 bfd_vma relocation;
1426 bfd_byte *location;
1428 int size;
1429 bfd_vma x = 0;
1430 bfd_reloc_status_type flag;
1431 unsigned int rightshift = howto->rightshift;
1432 unsigned int bitpos = howto->bitpos;
1434 /* If the size is negative, negate RELOCATION. This isn't very
1435 general. */
1436 if (howto->size < 0)
1437 relocation = -relocation;
1439 /* Get the value we are going to relocate. */
1440 size = bfd_get_reloc_size (howto);
1441 switch (size)
1443 default:
1444 case 0:
1445 abort ();
1446 case 1:
1447 x = bfd_get_8 (input_bfd, location);
1448 break;
1449 case 2:
1450 x = bfd_get_16 (input_bfd, location);
1451 break;
1452 case 4:
1453 x = bfd_get_32 (input_bfd, location);
1454 break;
1455 case 8:
1456 #ifdef BFD64
1457 x = bfd_get_64 (input_bfd, location);
1458 #else
1459 abort ();
1460 #endif
1461 break;
1464 /* Check for overflow. FIXME: We may drop bits during the addition
1465 which we don't check for. We must either check at every single
1466 operation, which would be tedious, or we must do the computations
1467 in a type larger than bfd_vma, which would be inefficient. */
1468 flag = bfd_reloc_ok;
1469 if (howto->complain_on_overflow != complain_overflow_dont)
1471 bfd_vma addrmask, fieldmask, signmask, ss;
1472 bfd_vma a, b, sum;
1474 /* Get the values to be added together. For signed and unsigned
1475 relocations, we assume that all values should be truncated to
1476 the size of an address. For bitfields, all the bits matter.
1477 See also bfd_check_overflow. */
1478 fieldmask = N_ONES (howto->bitsize);
1479 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
1480 a = relocation;
1481 b = x & howto->src_mask;
1483 switch (howto->complain_on_overflow)
1485 case complain_overflow_signed:
1486 a = (a & addrmask) >> rightshift;
1488 /* If any sign bits are set, all sign bits must be set.
1489 That is, A must be a valid negative address after
1490 shifting. */
1491 signmask = ~ (fieldmask >> 1);
1492 ss = a & signmask;
1493 if (ss != 0 && ss != ((addrmask >> rightshift) & signmask))
1494 flag = bfd_reloc_overflow;
1496 /* We only need this next bit of code if the sign bit of B
1497 is below the sign bit of A. This would only happen if
1498 SRC_MASK had fewer bits than BITSIZE. Note that if
1499 SRC_MASK has more bits than BITSIZE, we can get into
1500 trouble; we would need to verify that B is in range, as
1501 we do for A above. */
1502 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
1504 /* Set all the bits above the sign bit. */
1505 b = (b ^ signmask) - signmask;
1507 b = (b & addrmask) >> bitpos;
1509 /* Now we can do the addition. */
1510 sum = a + b;
1512 /* See if the result has the correct sign. Bits above the
1513 sign bit are junk now; ignore them. If the sum is
1514 positive, make sure we did not have all negative inputs;
1515 if the sum is negative, make sure we did not have all
1516 positive inputs. The test below looks only at the sign
1517 bits, and it really just
1518 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
1520 signmask = (fieldmask >> 1) + 1;
1521 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
1522 flag = bfd_reloc_overflow;
1524 break;
1526 case complain_overflow_unsigned:
1527 /* Checking for an unsigned overflow is relatively easy:
1528 trim the addresses and add, and trim the result as well.
1529 Overflow is normally indicated when the result does not
1530 fit in the field. However, we also need to consider the
1531 case when, e.g., fieldmask is 0x7fffffff or smaller, an
1532 input is 0x80000000, and bfd_vma is only 32 bits; then we
1533 will get sum == 0, but there is an overflow, since the
1534 inputs did not fit in the field. Instead of doing a
1535 separate test, we can check for this by or-ing in the
1536 operands when testing for the sum overflowing its final
1537 field. */
1538 a = (a & addrmask) >> rightshift;
1539 b = (b & addrmask) >> bitpos;
1540 sum = (a + b) & addrmask;
1541 if ((a | b | sum) & ~ fieldmask)
1542 flag = bfd_reloc_overflow;
1544 break;
1546 case complain_overflow_bitfield:
1547 /* Much like the signed check, but for a field one bit
1548 wider, and no trimming inputs with addrmask. We allow a
1549 bitfield to represent numbers in the range -2**n to
1550 2**n-1, where n is the number of bits in the field.
1551 Note that when bfd_vma is 32 bits, a 32-bit reloc can't
1552 overflow, which is exactly what we want. */
1553 a >>= rightshift;
1555 signmask = ~ fieldmask;
1556 ss = a & signmask;
1557 if (ss != 0 && ss != (((bfd_vma) -1 >> rightshift) & signmask))
1558 flag = bfd_reloc_overflow;
1560 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
1561 b = (b ^ signmask) - signmask;
1563 b >>= bitpos;
1565 sum = a + b;
1567 /* We mask with addrmask here to explicitly allow an address
1568 wrap-around. The Linux kernel relies on it, and it is
1569 the only way to write assembler code which can run when
1570 loaded at a location 0x80000000 away from the location at
1571 which it is linked. */
1572 signmask = fieldmask + 1;
1573 if (((~ (a ^ b)) & (a ^ sum)) & signmask & addrmask)
1574 flag = bfd_reloc_overflow;
1576 break;
1578 default:
1579 abort ();
1583 /* Put RELOCATION in the right bits. */
1584 relocation >>= (bfd_vma) rightshift;
1585 relocation <<= (bfd_vma) bitpos;
1587 /* Add RELOCATION to the right bits of X. */
1588 x = ((x & ~howto->dst_mask)
1589 | (((x & howto->src_mask) + relocation) & howto->dst_mask));
1591 /* Put the relocated value back in the object file. */
1592 switch (size)
1594 default:
1595 case 0:
1596 abort ();
1597 case 1:
1598 bfd_put_8 (input_bfd, x, location);
1599 break;
1600 case 2:
1601 bfd_put_16 (input_bfd, x, location);
1602 break;
1603 case 4:
1604 bfd_put_32 (input_bfd, x, location);
1605 break;
1606 case 8:
1607 #ifdef BFD64
1608 bfd_put_64 (input_bfd, x, location);
1609 #else
1610 abort ();
1611 #endif
1612 break;
1615 return flag;
1619 DOCDD
1620 INODE
1621 howto manager, , typedef arelent, Relocations
1623 SECTION
1624 The howto manager
1626 When an application wants to create a relocation, but doesn't
1627 know what the target machine might call it, it can find out by
1628 using this bit of code.
1633 TYPEDEF
1634 bfd_reloc_code_type
1636 DESCRIPTION
1637 The insides of a reloc code. The idea is that, eventually, there
1638 will be one enumerator for every type of relocation we ever do.
1639 Pass one of these values to <<bfd_reloc_type_lookup>>, and it'll
1640 return a howto pointer.
1642 This does mean that the application must determine the correct
1643 enumerator value; you can't get a howto pointer from a random set
1644 of attributes.
1646 SENUM
1647 bfd_reloc_code_real
1649 ENUM
1650 BFD_RELOC_64
1651 ENUMX
1652 BFD_RELOC_32
1653 ENUMX
1654 BFD_RELOC_26
1655 ENUMX
1656 BFD_RELOC_24
1657 ENUMX
1658 BFD_RELOC_16
1659 ENUMX
1660 BFD_RELOC_14
1661 ENUMX
1662 BFD_RELOC_8
1663 ENUMDOC
1664 Basic absolute relocations of N bits.
1666 ENUM
1667 BFD_RELOC_64_PCREL
1668 ENUMX
1669 BFD_RELOC_32_PCREL
1670 ENUMX
1671 BFD_RELOC_24_PCREL
1672 ENUMX
1673 BFD_RELOC_16_PCREL
1674 ENUMX
1675 BFD_RELOC_12_PCREL
1676 ENUMX
1677 BFD_RELOC_8_PCREL
1678 ENUMDOC
1679 PC-relative relocations. Sometimes these are relative to the address
1680 of the relocation itself; sometimes they are relative to the start of
1681 the section containing the relocation. It depends on the specific target.
1683 The 24-bit relocation is used in some Intel 960 configurations.
1685 ENUM
1686 BFD_RELOC_32_GOT_PCREL
1687 ENUMX
1688 BFD_RELOC_16_GOT_PCREL
1689 ENUMX
1690 BFD_RELOC_8_GOT_PCREL
1691 ENUMX
1692 BFD_RELOC_32_GOTOFF
1693 ENUMX
1694 BFD_RELOC_16_GOTOFF
1695 ENUMX
1696 BFD_RELOC_LO16_GOTOFF
1697 ENUMX
1698 BFD_RELOC_HI16_GOTOFF
1699 ENUMX
1700 BFD_RELOC_HI16_S_GOTOFF
1701 ENUMX
1702 BFD_RELOC_8_GOTOFF
1703 ENUMX
1704 BFD_RELOC_32_PLT_PCREL
1705 ENUMX
1706 BFD_RELOC_24_PLT_PCREL
1707 ENUMX
1708 BFD_RELOC_16_PLT_PCREL
1709 ENUMX
1710 BFD_RELOC_8_PLT_PCREL
1711 ENUMX
1712 BFD_RELOC_32_PLTOFF
1713 ENUMX
1714 BFD_RELOC_16_PLTOFF
1715 ENUMX
1716 BFD_RELOC_LO16_PLTOFF
1717 ENUMX
1718 BFD_RELOC_HI16_PLTOFF
1719 ENUMX
1720 BFD_RELOC_HI16_S_PLTOFF
1721 ENUMX
1722 BFD_RELOC_8_PLTOFF
1723 ENUMDOC
1724 For ELF.
1726 ENUM
1727 BFD_RELOC_68K_GLOB_DAT
1728 ENUMX
1729 BFD_RELOC_68K_JMP_SLOT
1730 ENUMX
1731 BFD_RELOC_68K_RELATIVE
1732 ENUMDOC
1733 Relocations used by 68K ELF.
1735 ENUM
1736 BFD_RELOC_32_BASEREL
1737 ENUMX
1738 BFD_RELOC_16_BASEREL
1739 ENUMX
1740 BFD_RELOC_LO16_BASEREL
1741 ENUMX
1742 BFD_RELOC_HI16_BASEREL
1743 ENUMX
1744 BFD_RELOC_HI16_S_BASEREL
1745 ENUMX
1746 BFD_RELOC_8_BASEREL
1747 ENUMX
1748 BFD_RELOC_RVA
1749 ENUMDOC
1750 Linkage-table relative.
1752 ENUM
1753 BFD_RELOC_8_FFnn
1754 ENUMDOC
1755 Absolute 8-bit relocation, but used to form an address like 0xFFnn.
1757 ENUM
1758 BFD_RELOC_32_PCREL_S2
1759 ENUMX
1760 BFD_RELOC_16_PCREL_S2
1761 ENUMX
1762 BFD_RELOC_23_PCREL_S2
1763 ENUMDOC
1764 These PC-relative relocations are stored as word displacements --
1765 i.e., byte displacements shifted right two bits. The 30-bit word
1766 displacement (<<32_PCREL_S2>> -- 32 bits, shifted 2) is used on the
1767 SPARC. (SPARC tools generally refer to this as <<WDISP30>>.) The
1768 signed 16-bit displacement is used on the MIPS, and the 23-bit
1769 displacement is used on the Alpha.
1771 ENUM
1772 BFD_RELOC_HI22
1773 ENUMX
1774 BFD_RELOC_LO10
1775 ENUMDOC
1776 High 22 bits and low 10 bits of 32-bit value, placed into lower bits of
1777 the target word. These are used on the SPARC.
1779 ENUM
1780 BFD_RELOC_GPREL16
1781 ENUMX
1782 BFD_RELOC_GPREL32
1783 ENUMDOC
1784 For systems that allocate a Global Pointer register, these are
1785 displacements off that register. These relocation types are
1786 handled specially, because the value the register will have is
1787 decided relatively late.
1790 ENUM
1791 BFD_RELOC_I960_CALLJ
1792 ENUMDOC
1793 Reloc types used for i960/b.out.
1795 ENUM
1796 BFD_RELOC_NONE
1797 ENUMX
1798 BFD_RELOC_SPARC_WDISP22
1799 ENUMX
1800 BFD_RELOC_SPARC22
1801 ENUMX
1802 BFD_RELOC_SPARC13
1803 ENUMX
1804 BFD_RELOC_SPARC_GOT10
1805 ENUMX
1806 BFD_RELOC_SPARC_GOT13
1807 ENUMX
1808 BFD_RELOC_SPARC_GOT22
1809 ENUMX
1810 BFD_RELOC_SPARC_PC10
1811 ENUMX
1812 BFD_RELOC_SPARC_PC22
1813 ENUMX
1814 BFD_RELOC_SPARC_WPLT30
1815 ENUMX
1816 BFD_RELOC_SPARC_COPY
1817 ENUMX
1818 BFD_RELOC_SPARC_GLOB_DAT
1819 ENUMX
1820 BFD_RELOC_SPARC_JMP_SLOT
1821 ENUMX
1822 BFD_RELOC_SPARC_RELATIVE
1823 ENUMX
1824 BFD_RELOC_SPARC_UA32
1825 ENUMDOC
1826 SPARC ELF relocations. There is probably some overlap with other
1827 relocation types already defined.
1829 ENUM
1830 BFD_RELOC_SPARC_BASE13
1831 ENUMX
1832 BFD_RELOC_SPARC_BASE22
1833 ENUMDOC
1834 I think these are specific to SPARC a.out (e.g., Sun 4).
1836 ENUMEQ
1837 BFD_RELOC_SPARC_64
1838 BFD_RELOC_64
1839 ENUMX
1840 BFD_RELOC_SPARC_10
1841 ENUMX
1842 BFD_RELOC_SPARC_11
1843 ENUMX
1844 BFD_RELOC_SPARC_OLO10
1845 ENUMX
1846 BFD_RELOC_SPARC_HH22
1847 ENUMX
1848 BFD_RELOC_SPARC_HM10
1849 ENUMX
1850 BFD_RELOC_SPARC_LM22
1851 ENUMX
1852 BFD_RELOC_SPARC_PC_HH22
1853 ENUMX
1854 BFD_RELOC_SPARC_PC_HM10
1855 ENUMX
1856 BFD_RELOC_SPARC_PC_LM22
1857 ENUMX
1858 BFD_RELOC_SPARC_WDISP16
1859 ENUMX
1860 BFD_RELOC_SPARC_WDISP19
1861 ENUMX
1862 BFD_RELOC_SPARC_7
1863 ENUMX
1864 BFD_RELOC_SPARC_6
1865 ENUMX
1866 BFD_RELOC_SPARC_5
1867 ENUMEQX
1868 BFD_RELOC_SPARC_DISP64
1869 BFD_RELOC_64_PCREL
1870 ENUMX
1871 BFD_RELOC_SPARC_PLT64
1872 ENUMX
1873 BFD_RELOC_SPARC_HIX22
1874 ENUMX
1875 BFD_RELOC_SPARC_LOX10
1876 ENUMX
1877 BFD_RELOC_SPARC_H44
1878 ENUMX
1879 BFD_RELOC_SPARC_M44
1880 ENUMX
1881 BFD_RELOC_SPARC_L44
1882 ENUMX
1883 BFD_RELOC_SPARC_REGISTER
1884 ENUMDOC
1885 SPARC64 relocations
1887 ENUM
1888 BFD_RELOC_SPARC_REV32
1889 ENUMDOC
1890 SPARC little endian relocation
1892 ENUM
1893 BFD_RELOC_ALPHA_GPDISP_HI16
1894 ENUMDOC
1895 Alpha ECOFF and ELF relocations. Some of these treat the symbol or
1896 "addend" in some special way.
1897 For GPDISP_HI16 ("gpdisp") relocations, the symbol is ignored when
1898 writing; when reading, it will be the absolute section symbol. The
1899 addend is the displacement in bytes of the "lda" instruction from
1900 the "ldah" instruction (which is at the address of this reloc).
1901 ENUM
1902 BFD_RELOC_ALPHA_GPDISP_LO16
1903 ENUMDOC
1904 For GPDISP_LO16 ("ignore") relocations, the symbol is handled as
1905 with GPDISP_HI16 relocs. The addend is ignored when writing the
1906 relocations out, and is filled in with the file's GP value on
1907 reading, for convenience.
1909 ENUM
1910 BFD_RELOC_ALPHA_GPDISP
1911 ENUMDOC
1912 The ELF GPDISP relocation is exactly the same as the GPDISP_HI16
1913 relocation except that there is no accompanying GPDISP_LO16
1914 relocation.
1916 ENUM
1917 BFD_RELOC_ALPHA_LITERAL
1918 ENUMX
1919 BFD_RELOC_ALPHA_ELF_LITERAL
1920 ENUMX
1921 BFD_RELOC_ALPHA_LITUSE
1922 ENUMDOC
1923 The Alpha LITERAL/LITUSE relocs are produced by a symbol reference;
1924 the assembler turns it into a LDQ instruction to load the address of
1925 the symbol, and then fills in a register in the real instruction.
1927 The LITERAL reloc, at the LDQ instruction, refers to the .lita
1928 section symbol. The addend is ignored when writing, but is filled
1929 in with the file's GP value on reading, for convenience, as with the
1930 GPDISP_LO16 reloc.
1932 The ELF_LITERAL reloc is somewhere between 16_GOTOFF and GPDISP_LO16.
1933 It should refer to the symbol to be referenced, as with 16_GOTOFF,
1934 but it generates output not based on the position within the .got
1935 section, but relative to the GP value chosen for the file during the
1936 final link stage.
1938 The LITUSE reloc, on the instruction using the loaded address, gives
1939 information to the linker that it might be able to use to optimize
1940 away some literal section references. The symbol is ignored (read
1941 as the absolute section symbol), and the "addend" indicates the type
1942 of instruction using the register:
1943 1 - "memory" fmt insn
1944 2 - byte-manipulation (byte offset reg)
1945 3 - jsr (target of branch)
1947 The GNU linker currently doesn't do any of this optimizing.
1949 ENUM
1950 BFD_RELOC_ALPHA_USER_LITERAL
1951 ENUMX
1952 BFD_RELOC_ALPHA_USER_LITUSE_BASE
1953 ENUMX
1954 BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF
1955 ENUMX
1956 BFD_RELOC_ALPHA_USER_LITUSE_JSR
1957 ENUMX
1958 BFD_RELOC_ALPHA_USER_GPDISP
1959 ENUMX
1960 BFD_RELOC_ALPHA_USER_GPRELHIGH
1961 ENUMX
1962 BFD_RELOC_ALPHA_USER_GPRELLOW
1963 ENUMDOC
1964 The BFD_RELOC_ALPHA_USER_* relocations are used by the assembler to
1965 process the explicit !<reloc>!sequence relocations, and are mapped
1966 into the normal relocations at the end of processing.
1968 ENUM
1969 BFD_RELOC_ALPHA_HINT
1970 ENUMDOC
1971 The HINT relocation indicates a value that should be filled into the
1972 "hint" field of a jmp/jsr/ret instruction, for possible branch-
1973 prediction logic which may be provided on some processors.
1975 ENUM
1976 BFD_RELOC_ALPHA_LINKAGE
1977 ENUMDOC
1978 The LINKAGE relocation outputs a linkage pair in the object file,
1979 which is filled by the linker.
1981 ENUM
1982 BFD_RELOC_ALPHA_CODEADDR
1983 ENUMDOC
1984 The CODEADDR relocation outputs a STO_CA in the object file,
1985 which is filled by the linker.
1987 ENUM
1988 BFD_RELOC_MIPS_JMP
1989 ENUMDOC
1990 Bits 27..2 of the relocation address shifted right 2 bits;
1991 simple reloc otherwise.
1993 ENUM
1994 BFD_RELOC_MIPS16_JMP
1995 ENUMDOC
1996 The MIPS16 jump instruction.
1998 ENUM
1999 BFD_RELOC_MIPS16_GPREL
2000 ENUMDOC
2001 MIPS16 GP relative reloc.
2003 ENUM
2004 BFD_RELOC_HI16
2005 ENUMDOC
2006 High 16 bits of 32-bit value; simple reloc.
2007 ENUM
2008 BFD_RELOC_HI16_S
2009 ENUMDOC
2010 High 16 bits of 32-bit value but the low 16 bits will be sign
2011 extended and added to form the final result. If the low 16
2012 bits form a negative number, we need to add one to the high value
2013 to compensate for the borrow when the low bits are added.
2014 ENUM
2015 BFD_RELOC_LO16
2016 ENUMDOC
2017 Low 16 bits.
2018 ENUM
2019 BFD_RELOC_PCREL_HI16_S
2020 ENUMDOC
2021 Like BFD_RELOC_HI16_S, but PC relative.
2022 ENUM
2023 BFD_RELOC_PCREL_LO16
2024 ENUMDOC
2025 Like BFD_RELOC_LO16, but PC relative.
2027 ENUMEQ
2028 BFD_RELOC_MIPS_GPREL
2029 BFD_RELOC_GPREL16
2030 ENUMDOC
2031 Relocation relative to the global pointer.
2033 ENUM
2034 BFD_RELOC_MIPS_LITERAL
2035 ENUMDOC
2036 Relocation against a MIPS literal section.
2038 ENUM
2039 BFD_RELOC_MIPS_GOT16
2040 ENUMX
2041 BFD_RELOC_MIPS_CALL16
2042 ENUMEQX
2043 BFD_RELOC_MIPS_GPREL32
2044 BFD_RELOC_GPREL32
2045 ENUMX
2046 BFD_RELOC_MIPS_GOT_HI16
2047 ENUMX
2048 BFD_RELOC_MIPS_GOT_LO16
2049 ENUMX
2050 BFD_RELOC_MIPS_CALL_HI16
2051 ENUMX
2052 BFD_RELOC_MIPS_CALL_LO16
2053 ENUMX
2054 BFD_RELOC_MIPS_SUB
2055 ENUMX
2056 BFD_RELOC_MIPS_GOT_PAGE
2057 ENUMX
2058 BFD_RELOC_MIPS_GOT_OFST
2059 ENUMX
2060 BFD_RELOC_MIPS_GOT_DISP
2061 COMMENT
2062 ENUMDOC
2063 MIPS ELF relocations.
2065 COMMENT
2067 ENUM
2068 BFD_RELOC_386_GOT32
2069 ENUMX
2070 BFD_RELOC_386_PLT32
2071 ENUMX
2072 BFD_RELOC_386_COPY
2073 ENUMX
2074 BFD_RELOC_386_GLOB_DAT
2075 ENUMX
2076 BFD_RELOC_386_JUMP_SLOT
2077 ENUMX
2078 BFD_RELOC_386_RELATIVE
2079 ENUMX
2080 BFD_RELOC_386_GOTOFF
2081 ENUMX
2082 BFD_RELOC_386_GOTPC
2083 ENUMDOC
2084 i386/elf relocations
2086 ENUM
2087 BFD_RELOC_NS32K_IMM_8
2088 ENUMX
2089 BFD_RELOC_NS32K_IMM_16
2090 ENUMX
2091 BFD_RELOC_NS32K_IMM_32
2092 ENUMX
2093 BFD_RELOC_NS32K_IMM_8_PCREL
2094 ENUMX
2095 BFD_RELOC_NS32K_IMM_16_PCREL
2096 ENUMX
2097 BFD_RELOC_NS32K_IMM_32_PCREL
2098 ENUMX
2099 BFD_RELOC_NS32K_DISP_8
2100 ENUMX
2101 BFD_RELOC_NS32K_DISP_16
2102 ENUMX
2103 BFD_RELOC_NS32K_DISP_32
2104 ENUMX
2105 BFD_RELOC_NS32K_DISP_8_PCREL
2106 ENUMX
2107 BFD_RELOC_NS32K_DISP_16_PCREL
2108 ENUMX
2109 BFD_RELOC_NS32K_DISP_32_PCREL
2110 ENUMDOC
2111 ns32k relocations
2113 ENUM
2114 BFD_RELOC_PJ_CODE_HI16
2115 ENUMX
2116 BFD_RELOC_PJ_CODE_LO16
2117 ENUMX
2118 BFD_RELOC_PJ_CODE_DIR16
2119 ENUMX
2120 BFD_RELOC_PJ_CODE_DIR32
2121 ENUMX
2122 BFD_RELOC_PJ_CODE_REL16
2123 ENUMX
2124 BFD_RELOC_PJ_CODE_REL32
2125 ENUMDOC
2126 Picojava relocs. Not all of these appear in object files.
2128 ENUM
2129 BFD_RELOC_PPC_B26
2130 ENUMX
2131 BFD_RELOC_PPC_BA26
2132 ENUMX
2133 BFD_RELOC_PPC_TOC16
2134 ENUMX
2135 BFD_RELOC_PPC_B16
2136 ENUMX
2137 BFD_RELOC_PPC_B16_BRTAKEN
2138 ENUMX
2139 BFD_RELOC_PPC_B16_BRNTAKEN
2140 ENUMX
2141 BFD_RELOC_PPC_BA16
2142 ENUMX
2143 BFD_RELOC_PPC_BA16_BRTAKEN
2144 ENUMX
2145 BFD_RELOC_PPC_BA16_BRNTAKEN
2146 ENUMX
2147 BFD_RELOC_PPC_COPY
2148 ENUMX
2149 BFD_RELOC_PPC_GLOB_DAT
2150 ENUMX
2151 BFD_RELOC_PPC_JMP_SLOT
2152 ENUMX
2153 BFD_RELOC_PPC_RELATIVE
2154 ENUMX
2155 BFD_RELOC_PPC_LOCAL24PC
2156 ENUMX
2157 BFD_RELOC_PPC_EMB_NADDR32
2158 ENUMX
2159 BFD_RELOC_PPC_EMB_NADDR16
2160 ENUMX
2161 BFD_RELOC_PPC_EMB_NADDR16_LO
2162 ENUMX
2163 BFD_RELOC_PPC_EMB_NADDR16_HI
2164 ENUMX
2165 BFD_RELOC_PPC_EMB_NADDR16_HA
2166 ENUMX
2167 BFD_RELOC_PPC_EMB_SDAI16
2168 ENUMX
2169 BFD_RELOC_PPC_EMB_SDA2I16
2170 ENUMX
2171 BFD_RELOC_PPC_EMB_SDA2REL
2172 ENUMX
2173 BFD_RELOC_PPC_EMB_SDA21
2174 ENUMX
2175 BFD_RELOC_PPC_EMB_MRKREF
2176 ENUMX
2177 BFD_RELOC_PPC_EMB_RELSEC16
2178 ENUMX
2179 BFD_RELOC_PPC_EMB_RELST_LO
2180 ENUMX
2181 BFD_RELOC_PPC_EMB_RELST_HI
2182 ENUMX
2183 BFD_RELOC_PPC_EMB_RELST_HA
2184 ENUMX
2185 BFD_RELOC_PPC_EMB_BIT_FLD
2186 ENUMX
2187 BFD_RELOC_PPC_EMB_RELSDA
2188 ENUMDOC
2189 Power(rs6000) and PowerPC relocations.
2191 ENUM
2192 BFD_RELOC_I370_D12
2193 ENUMDOC
2194 IBM 370/390 relocations
2196 ENUM
2197 BFD_RELOC_CTOR
2198 ENUMDOC
2199 The type of reloc used to build a contructor table - at the moment
2200 probably a 32 bit wide absolute relocation, but the target can choose.
2201 It generally does map to one of the other relocation types.
2203 ENUM
2204 BFD_RELOC_ARM_PCREL_BRANCH
2205 ENUMDOC
2206 ARM 26 bit pc-relative branch. The lowest two bits must be zero and are
2207 not stored in the instruction.
2208 ENUM
2209 BFD_RELOC_ARM_PCREL_BLX
2210 ENUMDOC
2211 ARM 26 bit pc-relative branch. The lowest bit must be zero and is
2212 not stored in the instruction. The 2nd lowest bit comes from a 1 bit
2213 field in the instruction.
2214 ENUM
2215 BFD_RELOC_THUMB_PCREL_BLX
2216 ENUMDOC
2217 Thumb 22 bit pc-relative branch. The lowest bit must be zero and is
2218 not stored in the instruction. The 2nd lowest bit comes from a 1 bit
2219 field in the instruction.
2220 ENUM
2221 BFD_RELOC_ARM_IMMEDIATE
2222 ENUMX
2223 BFD_RELOC_ARM_ADRL_IMMEDIATE
2224 ENUMX
2225 BFD_RELOC_ARM_OFFSET_IMM
2226 ENUMX
2227 BFD_RELOC_ARM_SHIFT_IMM
2228 ENUMX
2229 BFD_RELOC_ARM_SWI
2230 ENUMX
2231 BFD_RELOC_ARM_MULTI
2232 ENUMX
2233 BFD_RELOC_ARM_CP_OFF_IMM
2234 ENUMX
2235 BFD_RELOC_ARM_ADR_IMM
2236 ENUMX
2237 BFD_RELOC_ARM_LDR_IMM
2238 ENUMX
2239 BFD_RELOC_ARM_LITERAL
2240 ENUMX
2241 BFD_RELOC_ARM_IN_POOL
2242 ENUMX
2243 BFD_RELOC_ARM_OFFSET_IMM8
2244 ENUMX
2245 BFD_RELOC_ARM_HWLITERAL
2246 ENUMX
2247 BFD_RELOC_ARM_THUMB_ADD
2248 ENUMX
2249 BFD_RELOC_ARM_THUMB_IMM
2250 ENUMX
2251 BFD_RELOC_ARM_THUMB_SHIFT
2252 ENUMX
2253 BFD_RELOC_ARM_THUMB_OFFSET
2254 ENUMX
2255 BFD_RELOC_ARM_GOT12
2256 ENUMX
2257 BFD_RELOC_ARM_GOT32
2258 ENUMX
2259 BFD_RELOC_ARM_JUMP_SLOT
2260 ENUMX
2261 BFD_RELOC_ARM_COPY
2262 ENUMX
2263 BFD_RELOC_ARM_GLOB_DAT
2264 ENUMX
2265 BFD_RELOC_ARM_PLT32
2266 ENUMX
2267 BFD_RELOC_ARM_RELATIVE
2268 ENUMX
2269 BFD_RELOC_ARM_GOTOFF
2270 ENUMX
2271 BFD_RELOC_ARM_GOTPC
2272 ENUMDOC
2273 These relocs are only used within the ARM assembler. They are not
2274 (at present) written to any object files.
2276 ENUM
2277 BFD_RELOC_SH_PCDISP8BY2
2278 ENUMX
2279 BFD_RELOC_SH_PCDISP12BY2
2280 ENUMX
2281 BFD_RELOC_SH_IMM4
2282 ENUMX
2283 BFD_RELOC_SH_IMM4BY2
2284 ENUMX
2285 BFD_RELOC_SH_IMM4BY4
2286 ENUMX
2287 BFD_RELOC_SH_IMM8
2288 ENUMX
2289 BFD_RELOC_SH_IMM8BY2
2290 ENUMX
2291 BFD_RELOC_SH_IMM8BY4
2292 ENUMX
2293 BFD_RELOC_SH_PCRELIMM8BY2
2294 ENUMX
2295 BFD_RELOC_SH_PCRELIMM8BY4
2296 ENUMX
2297 BFD_RELOC_SH_SWITCH16
2298 ENUMX
2299 BFD_RELOC_SH_SWITCH32
2300 ENUMX
2301 BFD_RELOC_SH_USES
2302 ENUMX
2303 BFD_RELOC_SH_COUNT
2304 ENUMX
2305 BFD_RELOC_SH_ALIGN
2306 ENUMX
2307 BFD_RELOC_SH_CODE
2308 ENUMX
2309 BFD_RELOC_SH_DATA
2310 ENUMX
2311 BFD_RELOC_SH_LABEL
2312 ENUMX
2313 BFD_RELOC_SH_LOOP_START
2314 ENUMX
2315 BFD_RELOC_SH_LOOP_END
2316 ENUMDOC
2317 Hitachi SH relocs. Not all of these appear in object files.
2319 ENUM
2320 BFD_RELOC_THUMB_PCREL_BRANCH9
2321 ENUMX
2322 BFD_RELOC_THUMB_PCREL_BRANCH12
2323 ENUMX
2324 BFD_RELOC_THUMB_PCREL_BRANCH23
2325 ENUMDOC
2326 Thumb 23-, 12- and 9-bit pc-relative branches. The lowest bit must
2327 be zero and is not stored in the instruction.
2329 ENUM
2330 BFD_RELOC_ARC_B22_PCREL
2331 ENUMDOC
2332 Argonaut RISC Core (ARC) relocs.
2333 ARC 22 bit pc-relative branch. The lowest two bits must be zero and are
2334 not stored in the instruction. The high 20 bits are installed in bits 26
2335 through 7 of the instruction.
2336 ENUM
2337 BFD_RELOC_ARC_B26
2338 ENUMDOC
2339 ARC 26 bit absolute branch. The lowest two bits must be zero and are not
2340 stored in the instruction. The high 24 bits are installed in bits 23
2341 through 0.
2343 ENUM
2344 BFD_RELOC_D10V_10_PCREL_R
2345 ENUMDOC
2346 Mitsubishi D10V relocs.
2347 This is a 10-bit reloc with the right 2 bits
2348 assumed to be 0.
2349 ENUM
2350 BFD_RELOC_D10V_10_PCREL_L
2351 ENUMDOC
2352 Mitsubishi D10V relocs.
2353 This is a 10-bit reloc with the right 2 bits
2354 assumed to be 0. This is the same as the previous reloc
2355 except it is in the left container, i.e.,
2356 shifted left 15 bits.
2357 ENUM
2358 BFD_RELOC_D10V_18
2359 ENUMDOC
2360 This is an 18-bit reloc with the right 2 bits
2361 assumed to be 0.
2362 ENUM
2363 BFD_RELOC_D10V_18_PCREL
2364 ENUMDOC
2365 This is an 18-bit reloc with the right 2 bits
2366 assumed to be 0.
2368 ENUM
2369 BFD_RELOC_D30V_6
2370 ENUMDOC
2371 Mitsubishi D30V relocs.
2372 This is a 6-bit absolute reloc.
2373 ENUM
2374 BFD_RELOC_D30V_9_PCREL
2375 ENUMDOC
2376 This is a 6-bit pc-relative reloc with
2377 the right 3 bits assumed to be 0.
2378 ENUM
2379 BFD_RELOC_D30V_9_PCREL_R
2380 ENUMDOC
2381 This is a 6-bit pc-relative reloc with
2382 the right 3 bits assumed to be 0. Same
2383 as the previous reloc but on the right side
2384 of the container.
2385 ENUM
2386 BFD_RELOC_D30V_15
2387 ENUMDOC
2388 This is a 12-bit absolute reloc with the
2389 right 3 bitsassumed to be 0.
2390 ENUM
2391 BFD_RELOC_D30V_15_PCREL
2392 ENUMDOC
2393 This is a 12-bit pc-relative reloc with
2394 the right 3 bits assumed to be 0.
2395 ENUM
2396 BFD_RELOC_D30V_15_PCREL_R
2397 ENUMDOC
2398 This is a 12-bit pc-relative reloc with
2399 the right 3 bits assumed to be 0. Same
2400 as the previous reloc but on the right side
2401 of the container.
2402 ENUM
2403 BFD_RELOC_D30V_21
2404 ENUMDOC
2405 This is an 18-bit absolute reloc with
2406 the right 3 bits assumed to be 0.
2407 ENUM
2408 BFD_RELOC_D30V_21_PCREL
2409 ENUMDOC
2410 This is an 18-bit pc-relative reloc with
2411 the right 3 bits assumed to be 0.
2412 ENUM
2413 BFD_RELOC_D30V_21_PCREL_R
2414 ENUMDOC
2415 This is an 18-bit pc-relative reloc with
2416 the right 3 bits assumed to be 0. Same
2417 as the previous reloc but on the right side
2418 of the container.
2419 ENUM
2420 BFD_RELOC_D30V_32
2421 ENUMDOC
2422 This is a 32-bit absolute reloc.
2423 ENUM
2424 BFD_RELOC_D30V_32_PCREL
2425 ENUMDOC
2426 This is a 32-bit pc-relative reloc.
2428 ENUM
2429 BFD_RELOC_M32R_24
2430 ENUMDOC
2431 Mitsubishi M32R relocs.
2432 This is a 24 bit absolute address.
2433 ENUM
2434 BFD_RELOC_M32R_10_PCREL
2435 ENUMDOC
2436 This is a 10-bit pc-relative reloc with the right 2 bits assumed to be 0.
2437 ENUM
2438 BFD_RELOC_M32R_18_PCREL
2439 ENUMDOC
2440 This is an 18-bit reloc with the right 2 bits assumed to be 0.
2441 ENUM
2442 BFD_RELOC_M32R_26_PCREL
2443 ENUMDOC
2444 This is a 26-bit reloc with the right 2 bits assumed to be 0.
2445 ENUM
2446 BFD_RELOC_M32R_HI16_ULO
2447 ENUMDOC
2448 This is a 16-bit reloc containing the high 16 bits of an address
2449 used when the lower 16 bits are treated as unsigned.
2450 ENUM
2451 BFD_RELOC_M32R_HI16_SLO
2452 ENUMDOC
2453 This is a 16-bit reloc containing the high 16 bits of an address
2454 used when the lower 16 bits are treated as signed.
2455 ENUM
2456 BFD_RELOC_M32R_LO16
2457 ENUMDOC
2458 This is a 16-bit reloc containing the lower 16 bits of an address.
2459 ENUM
2460 BFD_RELOC_M32R_SDA16
2461 ENUMDOC
2462 This is a 16-bit reloc containing the small data area offset for use in
2463 add3, load, and store instructions.
2465 ENUM
2466 BFD_RELOC_V850_9_PCREL
2467 ENUMDOC
2468 This is a 9-bit reloc
2469 ENUM
2470 BFD_RELOC_V850_22_PCREL
2471 ENUMDOC
2472 This is a 22-bit reloc
2474 ENUM
2475 BFD_RELOC_V850_SDA_16_16_OFFSET
2476 ENUMDOC
2477 This is a 16 bit offset from the short data area pointer.
2478 ENUM
2479 BFD_RELOC_V850_SDA_15_16_OFFSET
2480 ENUMDOC
2481 This is a 16 bit offset (of which only 15 bits are used) from the
2482 short data area pointer.
2483 ENUM
2484 BFD_RELOC_V850_ZDA_16_16_OFFSET
2485 ENUMDOC
2486 This is a 16 bit offset from the zero data area pointer.
2487 ENUM
2488 BFD_RELOC_V850_ZDA_15_16_OFFSET
2489 ENUMDOC
2490 This is a 16 bit offset (of which only 15 bits are used) from the
2491 zero data area pointer.
2492 ENUM
2493 BFD_RELOC_V850_TDA_6_8_OFFSET
2494 ENUMDOC
2495 This is an 8 bit offset (of which only 6 bits are used) from the
2496 tiny data area pointer.
2497 ENUM
2498 BFD_RELOC_V850_TDA_7_8_OFFSET
2499 ENUMDOC
2500 This is an 8bit offset (of which only 7 bits are used) from the tiny
2501 data area pointer.
2502 ENUM
2503 BFD_RELOC_V850_TDA_7_7_OFFSET
2504 ENUMDOC
2505 This is a 7 bit offset from the tiny data area pointer.
2506 ENUM
2507 BFD_RELOC_V850_TDA_16_16_OFFSET
2508 ENUMDOC
2509 This is a 16 bit offset from the tiny data area pointer.
2510 COMMENT
2511 ENUM
2512 BFD_RELOC_V850_TDA_4_5_OFFSET
2513 ENUMDOC
2514 This is a 5 bit offset (of which only 4 bits are used) from the tiny
2515 data area pointer.
2516 ENUM
2517 BFD_RELOC_V850_TDA_4_4_OFFSET
2518 ENUMDOC
2519 This is a 4 bit offset from the tiny data area pointer.
2520 ENUM
2521 BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
2522 ENUMDOC
2523 This is a 16 bit offset from the short data area pointer, with the
2524 bits placed non-contigously in the instruction.
2525 ENUM
2526 BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
2527 ENUMDOC
2528 This is a 16 bit offset from the zero data area pointer, with the
2529 bits placed non-contigously in the instruction.
2530 ENUM
2531 BFD_RELOC_V850_CALLT_6_7_OFFSET
2532 ENUMDOC
2533 This is a 6 bit offset from the call table base pointer.
2534 ENUM
2535 BFD_RELOC_V850_CALLT_16_16_OFFSET
2536 ENUMDOC
2537 This is a 16 bit offset from the call table base pointer.
2538 COMMENT
2540 ENUM
2541 BFD_RELOC_MN10300_32_PCREL
2542 ENUMDOC
2543 This is a 32bit pcrel reloc for the mn10300, offset by two bytes in the
2544 instruction.
2545 ENUM
2546 BFD_RELOC_MN10300_16_PCREL
2547 ENUMDOC
2548 This is a 16bit pcrel reloc for the mn10300, offset by two bytes in the
2549 instruction.
2551 ENUM
2552 BFD_RELOC_TIC30_LDP
2553 ENUMDOC
2554 This is a 8bit DP reloc for the tms320c30, where the most
2555 significant 8 bits of a 24 bit word are placed into the least
2556 significant 8 bits of the opcode.
2558 ENUM
2559 BFD_RELOC_TIC54X_PARTLS7
2560 ENUMDOC
2561 This is a 7bit reloc for the tms320c54x, where the least
2562 significant 7 bits of a 16 bit word are placed into the least
2563 significant 7 bits of the opcode.
2565 ENUM
2566 BFD_RELOC_TIC54X_PARTMS9
2567 ENUMDOC
2568 This is a 9bit DP reloc for the tms320c54x, where the most
2569 significant 9 bits of a 16 bit word are placed into the least
2570 significant 9 bits of the opcode.
2572 ENUM
2573 BFD_RELOC_TIC54X_23
2574 ENUMDOC
2575 This is an extended address 23-bit reloc for the tms320c54x.
2577 ENUM
2578 BFD_RELOC_TIC54X_16_OF_23
2579 ENUMDOC
2580 This is a 16-bit reloc for the tms320c54x, where the least
2581 significant 16 bits of a 23-bit extended address are placed into
2582 the opcode.
2584 ENUM
2585 BFD_RELOC_TIC54X_MS7_OF_23
2586 ENUMDOC
2587 This is a reloc for the tms320c54x, where the most
2588 significant 7 bits of a 23-bit extended address are placed into
2589 the opcode.
2591 ENUM
2592 BFD_RELOC_FR30_48
2593 ENUMDOC
2594 This is a 48 bit reloc for the FR30 that stores 32 bits.
2595 ENUM
2596 BFD_RELOC_FR30_20
2597 ENUMDOC
2598 This is a 32 bit reloc for the FR30 that stores 20 bits split up into
2599 two sections.
2600 ENUM
2601 BFD_RELOC_FR30_6_IN_4
2602 ENUMDOC
2603 This is a 16 bit reloc for the FR30 that stores a 6 bit word offset in
2604 4 bits.
2605 ENUM
2606 BFD_RELOC_FR30_8_IN_8
2607 ENUMDOC
2608 This is a 16 bit reloc for the FR30 that stores an 8 bit byte offset
2609 into 8 bits.
2610 ENUM
2611 BFD_RELOC_FR30_9_IN_8
2612 ENUMDOC
2613 This is a 16 bit reloc for the FR30 that stores a 9 bit short offset
2614 into 8 bits.
2615 ENUM
2616 BFD_RELOC_FR30_10_IN_8
2617 ENUMDOC
2618 This is a 16 bit reloc for the FR30 that stores a 10 bit word offset
2619 into 8 bits.
2620 ENUM
2621 BFD_RELOC_FR30_9_PCREL
2622 ENUMDOC
2623 This is a 16 bit reloc for the FR30 that stores a 9 bit pc relative
2624 short offset into 8 bits.
2625 ENUM
2626 BFD_RELOC_FR30_12_PCREL
2627 ENUMDOC
2628 This is a 16 bit reloc for the FR30 that stores a 12 bit pc relative
2629 short offset into 11 bits.
2631 ENUM
2632 BFD_RELOC_MCORE_PCREL_IMM8BY4
2633 ENUMX
2634 BFD_RELOC_MCORE_PCREL_IMM11BY2
2635 ENUMX
2636 BFD_RELOC_MCORE_PCREL_IMM4BY2
2637 ENUMX
2638 BFD_RELOC_MCORE_PCREL_32
2639 ENUMX
2640 BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
2641 ENUMX
2642 BFD_RELOC_MCORE_RVA
2643 ENUMDOC
2644 Motorola Mcore relocations.
2646 ENUM
2647 BFD_RELOC_AVR_7_PCREL
2648 ENUMDOC
2649 This is a 16 bit reloc for the AVR that stores 8 bit pc relative
2650 short offset into 7 bits.
2651 ENUM
2652 BFD_RELOC_AVR_13_PCREL
2653 ENUMDOC
2654 This is a 16 bit reloc for the AVR that stores 13 bit pc relative
2655 short offset into 12 bits.
2656 ENUM
2657 BFD_RELOC_AVR_16_PM
2658 ENUMDOC
2659 This is a 16 bit reloc for the AVR that stores 17 bit value (usually
2660 program memory address) into 16 bits.
2661 ENUM
2662 BFD_RELOC_AVR_LO8_LDI
2663 ENUMDOC
2664 This is a 16 bit reloc for the AVR that stores 8 bit value (usually
2665 data memory address) into 8 bit immediate value of LDI insn.
2666 ENUM
2667 BFD_RELOC_AVR_HI8_LDI
2668 ENUMDOC
2669 This is a 16 bit reloc for the AVR that stores 8 bit value (high 8 bit
2670 of data memory address) into 8 bit immediate value of LDI insn.
2671 ENUM
2672 BFD_RELOC_AVR_HH8_LDI
2673 ENUMDOC
2674 This is a 16 bit reloc for the AVR that stores 8 bit value (most high 8 bit
2675 of program memory address) into 8 bit immediate value of LDI insn.
2676 ENUM
2677 BFD_RELOC_AVR_LO8_LDI_NEG
2678 ENUMDOC
2679 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2680 (usually data memory address) into 8 bit immediate value of SUBI insn.
2681 ENUM
2682 BFD_RELOC_AVR_HI8_LDI_NEG
2683 ENUMDOC
2684 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2685 (high 8 bit of data memory address) into 8 bit immediate value of
2686 SUBI insn.
2687 ENUM
2688 BFD_RELOC_AVR_HH8_LDI_NEG
2689 ENUMDOC
2690 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2691 (most high 8 bit of program memory address) into 8 bit immediate value
2692 of LDI or SUBI insn.
2693 ENUM
2694 BFD_RELOC_AVR_LO8_LDI_PM
2695 ENUMDOC
2696 This is a 16 bit reloc for the AVR that stores 8 bit value (usually
2697 command address) into 8 bit immediate value of LDI insn.
2698 ENUM
2699 BFD_RELOC_AVR_HI8_LDI_PM
2700 ENUMDOC
2701 This is a 16 bit reloc for the AVR that stores 8 bit value (high 8 bit
2702 of command address) into 8 bit immediate value of LDI insn.
2703 ENUM
2704 BFD_RELOC_AVR_HH8_LDI_PM
2705 ENUMDOC
2706 This is a 16 bit reloc for the AVR that stores 8 bit value (most high 8 bit
2707 of command address) into 8 bit immediate value of LDI insn.
2708 ENUM
2709 BFD_RELOC_AVR_LO8_LDI_PM_NEG
2710 ENUMDOC
2711 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2712 (usually command address) into 8 bit immediate value of SUBI insn.
2713 ENUM
2714 BFD_RELOC_AVR_HI8_LDI_PM_NEG
2715 ENUMDOC
2716 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2717 (high 8 bit of 16 bit command address) into 8 bit immediate value
2718 of SUBI insn.
2719 ENUM
2720 BFD_RELOC_AVR_HH8_LDI_PM_NEG
2721 ENUMDOC
2722 This is a 16 bit reloc for the AVR that stores negated 8 bit value
2723 (high 6 bit of 22 bit command address) into 8 bit immediate
2724 value of SUBI insn.
2725 ENUM
2726 BFD_RELOC_AVR_CALL
2727 ENUMDOC
2728 This is a 32 bit reloc for the AVR that stores 23 bit value
2729 into 22 bits.
2731 ENUM
2732 BFD_RELOC_VTABLE_INHERIT
2733 ENUMX
2734 BFD_RELOC_VTABLE_ENTRY
2735 ENUMDOC
2736 These two relocations are used by the linker to determine which of
2737 the entries in a C++ virtual function table are actually used. When
2738 the --gc-sections option is given, the linker will zero out the entries
2739 that are not used, so that the code for those functions need not be
2740 included in the output.
2742 VTABLE_INHERIT is a zero-space relocation used to describe to the
2743 linker the inheritence tree of a C++ virtual function table. The
2744 relocation's symbol should be the parent class' vtable, and the
2745 relocation should be located at the child vtable.
2747 VTABLE_ENTRY is a zero-space relocation that describes the use of a
2748 virtual function table entry. The reloc's symbol should refer to the
2749 table of the class mentioned in the code. Off of that base, an offset
2750 describes the entry that is being used. For Rela hosts, this offset
2751 is stored in the reloc's addend. For Rel hosts, we are forced to put
2752 this offset in the reloc's section offset.
2754 ENUM
2755 BFD_RELOC_IA64_IMM14
2756 ENUMX
2757 BFD_RELOC_IA64_IMM22
2758 ENUMX
2759 BFD_RELOC_IA64_IMM64
2760 ENUMX
2761 BFD_RELOC_IA64_DIR32MSB
2762 ENUMX
2763 BFD_RELOC_IA64_DIR32LSB
2764 ENUMX
2765 BFD_RELOC_IA64_DIR64MSB
2766 ENUMX
2767 BFD_RELOC_IA64_DIR64LSB
2768 ENUMX
2769 BFD_RELOC_IA64_GPREL22
2770 ENUMX
2771 BFD_RELOC_IA64_GPREL64I
2772 ENUMX
2773 BFD_RELOC_IA64_GPREL32MSB
2774 ENUMX
2775 BFD_RELOC_IA64_GPREL32LSB
2776 ENUMX
2777 BFD_RELOC_IA64_GPREL64MSB
2778 ENUMX
2779 BFD_RELOC_IA64_GPREL64LSB
2780 ENUMX
2781 BFD_RELOC_IA64_LTOFF22
2782 ENUMX
2783 BFD_RELOC_IA64_LTOFF64I
2784 ENUMX
2785 BFD_RELOC_IA64_PLTOFF22
2786 ENUMX
2787 BFD_RELOC_IA64_PLTOFF64I
2788 ENUMX
2789 BFD_RELOC_IA64_PLTOFF64MSB
2790 ENUMX
2791 BFD_RELOC_IA64_PLTOFF64LSB
2792 ENUMX
2793 BFD_RELOC_IA64_FPTR64I
2794 ENUMX
2795 BFD_RELOC_IA64_FPTR32MSB
2796 ENUMX
2797 BFD_RELOC_IA64_FPTR32LSB
2798 ENUMX
2799 BFD_RELOC_IA64_FPTR64MSB
2800 ENUMX
2801 BFD_RELOC_IA64_FPTR64LSB
2802 ENUMX
2803 BFD_RELOC_IA64_PCREL21B
2804 ENUMX
2805 BFD_RELOC_IA64_PCREL21BI
2806 ENUMX
2807 BFD_RELOC_IA64_PCREL21M
2808 ENUMX
2809 BFD_RELOC_IA64_PCREL21F
2810 ENUMX
2811 BFD_RELOC_IA64_PCREL22
2812 ENUMX
2813 BFD_RELOC_IA64_PCREL60B
2814 ENUMX
2815 BFD_RELOC_IA64_PCREL64I
2816 ENUMX
2817 BFD_RELOC_IA64_PCREL32MSB
2818 ENUMX
2819 BFD_RELOC_IA64_PCREL32LSB
2820 ENUMX
2821 BFD_RELOC_IA64_PCREL64MSB
2822 ENUMX
2823 BFD_RELOC_IA64_PCREL64LSB
2824 ENUMX
2825 BFD_RELOC_IA64_LTOFF_FPTR22
2826 ENUMX
2827 BFD_RELOC_IA64_LTOFF_FPTR64I
2828 ENUMX
2829 BFD_RELOC_IA64_LTOFF_FPTR64MSB
2830 ENUMX
2831 BFD_RELOC_IA64_LTOFF_FPTR64LSB
2832 ENUMX
2833 BFD_RELOC_IA64_SEGBASE
2834 ENUMX
2835 BFD_RELOC_IA64_SEGREL32MSB
2836 ENUMX
2837 BFD_RELOC_IA64_SEGREL32LSB
2838 ENUMX
2839 BFD_RELOC_IA64_SEGREL64MSB
2840 ENUMX
2841 BFD_RELOC_IA64_SEGREL64LSB
2842 ENUMX
2843 BFD_RELOC_IA64_SECREL32MSB
2844 ENUMX
2845 BFD_RELOC_IA64_SECREL32LSB
2846 ENUMX
2847 BFD_RELOC_IA64_SECREL64MSB
2848 ENUMX
2849 BFD_RELOC_IA64_SECREL64LSB
2850 ENUMX
2851 BFD_RELOC_IA64_REL32MSB
2852 ENUMX
2853 BFD_RELOC_IA64_REL32LSB
2854 ENUMX
2855 BFD_RELOC_IA64_REL64MSB
2856 ENUMX
2857 BFD_RELOC_IA64_REL64LSB
2858 ENUMX
2859 BFD_RELOC_IA64_LTV32MSB
2860 ENUMX
2861 BFD_RELOC_IA64_LTV32LSB
2862 ENUMX
2863 BFD_RELOC_IA64_LTV64MSB
2864 ENUMX
2865 BFD_RELOC_IA64_LTV64LSB
2866 ENUMX
2867 BFD_RELOC_IA64_IPLTMSB
2868 ENUMX
2869 BFD_RELOC_IA64_IPLTLSB
2870 ENUMX
2871 BFD_RELOC_IA64_EPLTMSB
2872 ENUMX
2873 BFD_RELOC_IA64_EPLTLSB
2874 ENUMX
2875 BFD_RELOC_IA64_COPY
2876 ENUMX
2877 BFD_RELOC_IA64_TPREL22
2878 ENUMX
2879 BFD_RELOC_IA64_TPREL64MSB
2880 ENUMX
2881 BFD_RELOC_IA64_TPREL64LSB
2882 ENUMX
2883 BFD_RELOC_IA64_LTOFF_TP22
2884 ENUMX
2885 BFD_RELOC_IA64_LTOFF22X
2886 ENUMX
2887 BFD_RELOC_IA64_LDXMOV
2888 ENUMDOC
2889 Intel IA64 Relocations.
2890 ENDSENUM
2891 BFD_RELOC_UNUSED
2892 CODE_FRAGMENT
2894 .typedef enum bfd_reloc_code_real bfd_reloc_code_real_type;
2899 FUNCTION
2900 bfd_reloc_type_lookup
2902 SYNOPSIS
2903 reloc_howto_type *
2904 bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code);
2906 DESCRIPTION
2907 Return a pointer to a howto structure which, when
2908 invoked, will perform the relocation @var{code} on data from the
2909 architecture noted.
2914 reloc_howto_type *
2915 bfd_reloc_type_lookup (abfd, code)
2916 bfd *abfd;
2917 bfd_reloc_code_real_type code;
2919 return BFD_SEND (abfd, reloc_type_lookup, (abfd, code));
2922 static reloc_howto_type bfd_howto_32 =
2923 HOWTO (0, 00, 2, 32, false, 0, complain_overflow_bitfield, 0, "VRT32", false, 0xffffffff, 0xffffffff, true);
2927 INTERNAL_FUNCTION
2928 bfd_default_reloc_type_lookup
2930 SYNOPSIS
2931 reloc_howto_type *bfd_default_reloc_type_lookup
2932 (bfd *abfd, bfd_reloc_code_real_type code);
2934 DESCRIPTION
2935 Provides a default relocation lookup routine for any architecture.
2940 reloc_howto_type *
2941 bfd_default_reloc_type_lookup (abfd, code)
2942 bfd *abfd;
2943 bfd_reloc_code_real_type code;
2945 switch (code)
2947 case BFD_RELOC_CTOR:
2948 /* The type of reloc used in a ctor, which will be as wide as the
2949 address - so either a 64, 32, or 16 bitter. */
2950 switch (bfd_get_arch_info (abfd)->bits_per_address)
2952 case 64:
2953 BFD_FAIL ();
2954 case 32:
2955 return &bfd_howto_32;
2956 case 16:
2957 BFD_FAIL ();
2958 default:
2959 BFD_FAIL ();
2961 default:
2962 BFD_FAIL ();
2964 return (reloc_howto_type *) NULL;
2968 FUNCTION
2969 bfd_get_reloc_code_name
2971 SYNOPSIS
2972 const char *bfd_get_reloc_code_name (bfd_reloc_code_real_type code);
2974 DESCRIPTION
2975 Provides a printable name for the supplied relocation code.
2976 Useful mainly for printing error messages.
2979 const char *
2980 bfd_get_reloc_code_name (code)
2981 bfd_reloc_code_real_type code;
2983 if (code > BFD_RELOC_UNUSED)
2984 return 0;
2985 return bfd_reloc_code_real_names[(int)code];
2989 INTERNAL_FUNCTION
2990 bfd_generic_relax_section
2992 SYNOPSIS
2993 boolean bfd_generic_relax_section
2994 (bfd *abfd,
2995 asection *section,
2996 struct bfd_link_info *,
2997 boolean *);
2999 DESCRIPTION
3000 Provides default handling for relaxing for back ends which
3001 don't do relaxing -- i.e., does nothing.
3004 /*ARGSUSED*/
3005 boolean
3006 bfd_generic_relax_section (abfd, section, link_info, again)
3007 bfd *abfd ATTRIBUTE_UNUSED;
3008 asection *section ATTRIBUTE_UNUSED;
3009 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
3010 boolean *again;
3012 *again = false;
3013 return true;
3017 INTERNAL_FUNCTION
3018 bfd_generic_gc_sections
3020 SYNOPSIS
3021 boolean bfd_generic_gc_sections
3022 (bfd *, struct bfd_link_info *);
3024 DESCRIPTION
3025 Provides default handling for relaxing for back ends which
3026 don't do section gc -- i.e., does nothing.
3029 /*ARGSUSED*/
3030 boolean
3031 bfd_generic_gc_sections (abfd, link_info)
3032 bfd *abfd ATTRIBUTE_UNUSED;
3033 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
3035 return true;
3039 INTERNAL_FUNCTION
3040 bfd_generic_get_relocated_section_contents
3042 SYNOPSIS
3043 bfd_byte *
3044 bfd_generic_get_relocated_section_contents (bfd *abfd,
3045 struct bfd_link_info *link_info,
3046 struct bfd_link_order *link_order,
3047 bfd_byte *data,
3048 boolean relocateable,
3049 asymbol **symbols);
3051 DESCRIPTION
3052 Provides default handling of relocation effort for back ends
3053 which can't be bothered to do it efficiently.
3057 bfd_byte *
3058 bfd_generic_get_relocated_section_contents (abfd, link_info, link_order, data,
3059 relocateable, symbols)
3060 bfd *abfd;
3061 struct bfd_link_info *link_info;
3062 struct bfd_link_order *link_order;
3063 bfd_byte *data;
3064 boolean relocateable;
3065 asymbol **symbols;
3067 /* Get enough memory to hold the stuff */
3068 bfd *input_bfd = link_order->u.indirect.section->owner;
3069 asection *input_section = link_order->u.indirect.section;
3071 long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
3072 arelent **reloc_vector = NULL;
3073 long reloc_count;
3075 if (reloc_size < 0)
3076 goto error_return;
3078 reloc_vector = (arelent **) bfd_malloc ((size_t) reloc_size);
3079 if (reloc_vector == NULL && reloc_size != 0)
3080 goto error_return;
3082 /* read in the section */
3083 if (!bfd_get_section_contents (input_bfd,
3084 input_section,
3085 (PTR) data,
3087 input_section->_raw_size))
3088 goto error_return;
3090 /* We're not relaxing the section, so just copy the size info */
3091 input_section->_cooked_size = input_section->_raw_size;
3092 input_section->reloc_done = true;
3094 reloc_count = bfd_canonicalize_reloc (input_bfd,
3095 input_section,
3096 reloc_vector,
3097 symbols);
3098 if (reloc_count < 0)
3099 goto error_return;
3101 if (reloc_count > 0)
3103 arelent **parent;
3104 for (parent = reloc_vector; *parent != (arelent *) NULL;
3105 parent++)
3107 char *error_message = (char *) NULL;
3108 bfd_reloc_status_type r =
3109 bfd_perform_relocation (input_bfd,
3110 *parent,
3111 (PTR) data,
3112 input_section,
3113 relocateable ? abfd : (bfd *) NULL,
3114 &error_message);
3116 if (relocateable)
3118 asection *os = input_section->output_section;
3120 /* A partial link, so keep the relocs */
3121 os->orelocation[os->reloc_count] = *parent;
3122 os->reloc_count++;
3125 if (r != bfd_reloc_ok)
3127 switch (r)
3129 case bfd_reloc_undefined:
3130 if (!((*link_info->callbacks->undefined_symbol)
3131 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
3132 input_bfd, input_section, (*parent)->address,
3133 true)))
3134 goto error_return;
3135 break;
3136 case bfd_reloc_dangerous:
3137 BFD_ASSERT (error_message != (char *) NULL);
3138 if (!((*link_info->callbacks->reloc_dangerous)
3139 (link_info, error_message, input_bfd, input_section,
3140 (*parent)->address)))
3141 goto error_return;
3142 break;
3143 case bfd_reloc_overflow:
3144 if (!((*link_info->callbacks->reloc_overflow)
3145 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
3146 (*parent)->howto->name, (*parent)->addend,
3147 input_bfd, input_section, (*parent)->address)))
3148 goto error_return;
3149 break;
3150 case bfd_reloc_outofrange:
3151 default:
3152 abort ();
3153 break;
3159 if (reloc_vector != NULL)
3160 free (reloc_vector);
3161 return data;
3163 error_return:
3164 if (reloc_vector != NULL)
3165 free (reloc_vector);
3166 return NULL;