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. */
26 BFD maintains relocations in much the same way it maintains
27 symbols: they are left alone until required, then read in
28 en-mass 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.
46 /* DO compile in the reloc_code name table from libbfd.h. */
47 #define _BFD_MAKE_TABLE_bfd_reloc_code_real
56 typedef arelent, howto manager, Relocations, Relocations
61 This is the structure of a relocation entry:
65 .typedef enum bfd_reloc_status
67 . {* No errors detected *}
70 . {* The relocation was performed, but there was an overflow. *}
73 . {* The address to relocate was not within the section supplied. *}
74 . bfd_reloc_outofrange,
76 . {* Used by special functions *}
79 . {* Unsupported relocation size requested. *}
80 . bfd_reloc_notsupported,
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. *}
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 *}
108 . {* Pointer to how to perform the required relocation *}
109 . reloc_howto_type *howto;
118 Here is a description of each of the fields within an <<arelent>>:
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.
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
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:
153 | return foo[0x12345678];
156 Could be compiled into:
159 | moveb @@#12345678,d0
165 This could create a reloc pointing to <<foo>>, but leave the
166 offset in the data, something like:
169 |RELOCATION RECORDS FOR [.text]:
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
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)
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]:
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.
218 | sethi %hi(_foo+0x12345678),%g2
219 | ldsb [%g2+%lo(_foo+0x12345678)],%i0
223 Both relocs contain a pointer to <<foo>>, and the offsets
227 |RELOCATION RECORDS FOR [.text]:
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
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.
253 <<enum complain_overflow>>
255 Indicates what sort of overflow checking should be done when
256 performing a relocation.
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
271 . complain_overflow_signed,
273 . {* Complain if the value overflows when considered as an
274 . unsigned number. *}
275 . complain_overflow_unsigned
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.
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. *}
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. *}
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
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
331 . bfd_reloc_status_type (*special_function)
332 . PARAMS ((bfd *abfd,
333 . arelent *reloc_entry,
334 . struct symbol_cache_entry *symbol,
336 . asection *input_section,
338 . char **error_message));
340 . {* The textual name of the relocation type. *}
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 . bit 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. *}
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. *}
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;
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}
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)
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)
414 Helper routine to turn a symbol into a relocation value.
416 .#define HOWTO_PREPARE(relocation, symbol) \
418 . if (symbol != (asymbol *)NULL) { \
419 . if (bfd_is_com_section (symbol->section)) { \
423 . relocation = symbol->value; \
435 unsigned int bfd_get_reloc_size (reloc_howto_type *);
438 For a reloc_howto_type that operates on a fixed number of bytes,
439 this returns the number of bytes operated on.
443 bfd_get_reloc_size (howto
)
444 reloc_howto_type
*howto
;
465 How relocs are tied together in an <<asection>>:
467 .typedef struct relent_chain {
469 . struct relent_chain *next;
474 /* N_ONES produces N one bits, without overflowing machine arithmetic. */
475 #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
482 bfd_reloc_status_type
484 (enum complain_overflow how,
485 unsigned int bitsize,
486 unsigned int rightshift,
487 unsigned int addrsize,
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
;
507 bfd_vma fieldmask
, addrmask
, signmask
, ss
, a
;
508 bfd_reloc_status_type flag
= bfd_reloc_ok
;
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
516 fieldmask
= N_ONES (bitsize
);
517 addrmask
= N_ONES (addrsize
) | fieldmask
;
521 case complain_overflow_dont
:
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);
530 if (ss
!= 0 && ss
!= ((addrmask
>> rightshift
) & signmask
))
531 flag
= bfd_reloc_overflow
;
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
;
541 case complain_overflow_bitfield
:
542 /* Bitfields are sometimes signed, sometimes unsigned. We
543 overflow if the value has some, but not all, bits set outside
544 the field, or if it has any bits set outside the field but
545 the sign bit is not set. */
547 if ((a
& ~ fieldmask
) != 0)
549 signmask
= (fieldmask
>> 1) + 1;
550 ss
= (signmask
<< rightshift
) - 1;
551 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
552 flag
= bfd_reloc_overflow
;
565 bfd_perform_relocation
568 bfd_reloc_status_type
569 bfd_perform_relocation
571 arelent *reloc_entry,
573 asection *input_section,
575 char **error_message);
578 If @var{output_bfd} is supplied to this function, the
579 generated image will be relocatable; the relocations are
580 copied to the output file after they have been changed to
581 reflect the new state of the world. There are two ways of
582 reflecting the results of partial linkage in an output file:
583 by modifying the output data in place, and by modifying the
584 relocation record. Some native formats (e.g., basic a.out and
585 basic coff) have no way of specifying an addend in the
586 relocation type, so the addend has to go in the output data.
587 This is no big deal since in these formats the output data
588 slot will always be big enough for the addend. Complex reloc
589 types with addends were invented to solve just this problem.
590 The @var{error_message} argument is set to an error message if
591 this return @code{bfd_reloc_dangerous}.
596 bfd_reloc_status_type
597 bfd_perform_relocation (abfd
, reloc_entry
, data
, input_section
, output_bfd
,
600 arelent
*reloc_entry
;
602 asection
*input_section
;
604 char **error_message
;
607 bfd_reloc_status_type flag
= bfd_reloc_ok
;
608 bfd_size_type octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
609 bfd_vma output_base
= 0;
610 reloc_howto_type
*howto
= reloc_entry
->howto
;
611 asection
*reloc_target_output_section
;
614 symbol
= *(reloc_entry
->sym_ptr_ptr
);
615 if (bfd_is_abs_section (symbol
->section
)
616 && output_bfd
!= (bfd
*) NULL
)
618 reloc_entry
->address
+= input_section
->output_offset
;
622 /* If we are not producing relocateable output, return an error if
623 the symbol is not defined. An undefined weak symbol is
624 considered to have a value of zero (SVR4 ABI, p. 4-27). */
625 if (bfd_is_und_section (symbol
->section
)
626 && (symbol
->flags
& BSF_WEAK
) == 0
627 && output_bfd
== (bfd
*) NULL
)
628 flag
= bfd_reloc_undefined
;
630 /* If there is a function supplied to handle this relocation type,
631 call it. It'll return `bfd_reloc_continue' if further processing
633 if (howto
->special_function
)
635 bfd_reloc_status_type cont
;
636 cont
= howto
->special_function (abfd
, reloc_entry
, symbol
, data
,
637 input_section
, output_bfd
,
639 if (cont
!= bfd_reloc_continue
)
643 /* Is the address of the relocation really within the section? */
644 if (reloc_entry
->address
> input_section
->_cooked_size
/
645 bfd_octets_per_byte (abfd
))
646 return bfd_reloc_outofrange
;
648 /* Work out which section the relocation is targetted at and the
649 initial relocation command value. */
651 /* Get symbol value. (Common symbols are special.) */
652 if (bfd_is_com_section (symbol
->section
))
655 relocation
= symbol
->value
;
658 reloc_target_output_section
= symbol
->section
->output_section
;
660 /* Convert input-section-relative symbol value to absolute. */
661 if (output_bfd
&& howto
->partial_inplace
== false)
664 output_base
= reloc_target_output_section
->vma
;
666 relocation
+= output_base
+ symbol
->section
->output_offset
;
668 /* Add in supplied addend. */
669 relocation
+= reloc_entry
->addend
;
671 /* Here the variable relocation holds the final address of the
672 symbol we are relocating against, plus any addend. */
674 if (howto
->pc_relative
== true)
676 /* This is a PC relative relocation. We want to set RELOCATION
677 to the distance between the address of the symbol and the
678 location. RELOCATION is already the address of the symbol.
680 We start by subtracting the address of the section containing
683 If pcrel_offset is set, we must further subtract the position
684 of the location within the section. Some targets arrange for
685 the addend to be the negative of the position of the location
686 within the section; for example, i386-aout does this. For
687 i386-aout, pcrel_offset is false. Some other targets do not
688 include the position of the location; for example, m88kbcs,
689 or ELF. For those targets, pcrel_offset is true.
691 If we are producing relocateable output, then we must ensure
692 that this reloc will be correctly computed when the final
693 relocation is done. If pcrel_offset is false we want to wind
694 up with the negative of the location within the section,
695 which means we must adjust the existing addend by the change
696 in the location within the section. If pcrel_offset is true
697 we do not want to adjust the existing addend at all.
699 FIXME: This seems logical to me, but for the case of
700 producing relocateable output it is not what the code
701 actually does. I don't want to change it, because it seems
702 far too likely that something will break. */
705 input_section
->output_section
->vma
+ input_section
->output_offset
;
707 if (howto
->pcrel_offset
== true)
708 relocation
-= reloc_entry
->address
;
711 if (output_bfd
!= (bfd
*) NULL
)
713 if (howto
->partial_inplace
== false)
715 /* This is a partial relocation, and we want to apply the relocation
716 to the reloc entry rather than the raw data. Modify the reloc
717 inplace to reflect what we now know. */
718 reloc_entry
->addend
= relocation
;
719 reloc_entry
->address
+= input_section
->output_offset
;
724 /* This is a partial relocation, but inplace, so modify the
727 If we've relocated with a symbol with a section, change
728 into a ref to the section belonging to the symbol. */
730 reloc_entry
->address
+= input_section
->output_offset
;
733 if (abfd
->xvec
->flavour
== bfd_target_coff_flavour
734 && strcmp (abfd
->xvec
->name
, "aixcoff-rs6000") != 0
735 && strcmp (abfd
->xvec
->name
, "xcoff-powermac") != 0
736 && strcmp (abfd
->xvec
->name
, "coff-Intel-little") != 0
737 && strcmp (abfd
->xvec
->name
, "coff-Intel-big") != 0)
740 /* For m68k-coff, the addend was being subtracted twice during
741 relocation with -r. Removing the line below this comment
742 fixes that problem; see PR 2953.
744 However, Ian wrote the following, regarding removing the line below,
745 which explains why it is still enabled: --djm
747 If you put a patch like that into BFD you need to check all the COFF
748 linkers. I am fairly certain that patch will break coff-i386 (e.g.,
749 SCO); see coff_i386_reloc in coff-i386.c where I worked around the
750 problem in a different way. There may very well be a reason that the
751 code works as it does.
753 Hmmm. The first obvious point is that bfd_perform_relocation should
754 not have any tests that depend upon the flavour. It's seem like
755 entirely the wrong place for such a thing. The second obvious point
756 is that the current code ignores the reloc addend when producing
757 relocateable output for COFF. That's peculiar. In fact, I really
758 have no idea what the point of the line you want to remove is.
760 A typical COFF reloc subtracts the old value of the symbol and adds in
761 the new value to the location in the object file (if it's a pc
762 relative reloc it adds the difference between the symbol value and the
763 location). When relocating we need to preserve that property.
765 BFD handles this by setting the addend to the negative of the old
766 value of the symbol. Unfortunately it handles common symbols in a
767 non-standard way (it doesn't subtract the old value) but that's a
768 different story (we can't change it without losing backward
769 compatibility with old object files) (coff-i386 does subtract the old
770 value, to be compatible with existing coff-i386 targets, like SCO).
772 So everything works fine when not producing relocateable output. When
773 we are producing relocateable output, logically we should do exactly
774 what we do when not producing relocateable output. Therefore, your
775 patch is correct. In fact, it should probably always just set
776 reloc_entry->addend to 0 for all cases, since it is, in fact, going to
777 add the value into the object file. This won't hurt the COFF code,
778 which doesn't use the addend; I'm not sure what it will do to other
779 formats (the thing to check for would be whether any formats both use
780 the addend and set partial_inplace).
782 When I wanted to make coff-i386 produce relocateable output, I ran
783 into the problem that you are running into: I wanted to remove that
784 line. Rather than risk it, I made the coff-i386 relocs use a special
785 function; it's coff_i386_reloc in coff-i386.c. The function
786 specifically adds the addend field into the object file, knowing that
787 bfd_perform_relocation is not going to. If you remove that line, then
788 coff-i386.c will wind up adding the addend field in twice. It's
789 trivial to fix; it just needs to be done.
791 The problem with removing the line is just that it may break some
792 working code. With BFD it's hard to be sure of anything. The right
793 way to deal with this is simply to build and test at least all the
794 supported COFF targets. It should be straightforward if time and disk
795 space consuming. For each target:
797 2) generate some executable, and link it using -r (I would
798 probably use paranoia.o and link against newlib/libc.a, which
799 for all the supported targets would be available in
800 /usr/cygnus/progressive/H-host/target/lib/libc.a).
801 3) make the change to reloc.c
802 4) rebuild the linker
804 6) if the resulting object files are the same, you have at least
806 7) if they are different you have to figure out which version is
809 relocation
-= reloc_entry
->addend
;
811 reloc_entry
->addend
= 0;
815 reloc_entry
->addend
= relocation
;
821 reloc_entry
->addend
= 0;
824 /* FIXME: This overflow checking is incomplete, because the value
825 might have overflowed before we get here. For a correct check we
826 need to compute the value in a size larger than bitsize, but we
827 can't reasonably do that for a reloc the same size as a host
829 FIXME: We should also do overflow checking on the result after
830 adding in the value contained in the object file. */
831 if (howto
->complain_on_overflow
!= complain_overflow_dont
832 && flag
== bfd_reloc_ok
)
833 flag
= bfd_check_overflow (howto
->complain_on_overflow
,
836 bfd_arch_bits_per_address (abfd
),
840 Either we are relocating all the way, or we don't want to apply
841 the relocation to the reloc entry (probably because there isn't
842 any room in the output format to describe addends to relocs)
845 /* The cast to bfd_vma avoids a bug in the Alpha OSF/1 C compiler
846 (OSF version 1.3, compiler version 3.11). It miscompiles the
860 x <<= (unsigned long) s.i0;
864 printf ("succeeded (%lx)\n", x);
868 relocation
>>= (bfd_vma
) howto
->rightshift
;
870 /* Shift everything up to where it's going to be used */
872 relocation
<<= (bfd_vma
) howto
->bitpos
;
874 /* Wait for the day when all have the mask in them */
877 i instruction to be left alone
878 o offset within instruction
879 r relocation offset to apply
888 i i i i i o o o o o from bfd_get<size>
889 and S S S S S to get the size offset we want
890 + r r r r r r r r r r to get the final value to place
891 and D D D D D to chop to right size
892 -----------------------
895 ... i i i i i o o o o o from bfd_get<size>
896 and N N N N N get instruction
897 -----------------------
903 -----------------------
904 R R R R R R R R R R put into bfd_put<size>
908 x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask))
914 char x
= bfd_get_8 (abfd
, (char *) data
+ octets
);
916 bfd_put_8 (abfd
, x
, (unsigned char *) data
+ octets
);
922 short x
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ octets
);
924 bfd_put_16 (abfd
, x
, (unsigned char *) data
+ octets
);
929 long x
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
931 bfd_put_32 (abfd
, x
, (bfd_byte
*) data
+ octets
);
936 long x
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
937 relocation
= -relocation
;
939 bfd_put_32 (abfd
, x
, (bfd_byte
*) data
+ octets
);
945 long x
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ octets
);
946 relocation
= -relocation
;
948 bfd_put_16 (abfd
, x
, (bfd_byte
*) data
+ octets
);
959 bfd_vma x
= bfd_get_64 (abfd
, (bfd_byte
*) data
+ octets
);
961 bfd_put_64 (abfd
, x
, (bfd_byte
*) data
+ octets
);
968 return bfd_reloc_other
;
976 bfd_install_relocation
979 bfd_reloc_status_type
980 bfd_install_relocation
982 arelent *reloc_entry,
983 PTR data, bfd_vma data_start,
984 asection *input_section,
985 char **error_message);
988 This looks remarkably like <<bfd_perform_relocation>>, except it
989 does not expect that the section contents have been filled in.
990 I.e., it's suitable for use when creating, rather than applying
993 For now, this function should be considered reserved for the
999 bfd_reloc_status_type
1000 bfd_install_relocation (abfd
, reloc_entry
, data_start
, data_start_offset
,
1001 input_section
, error_message
)
1003 arelent
*reloc_entry
;
1005 bfd_vma data_start_offset
;
1006 asection
*input_section
;
1007 char **error_message
;
1010 bfd_reloc_status_type flag
= bfd_reloc_ok
;
1011 bfd_size_type octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1012 bfd_vma output_base
= 0;
1013 reloc_howto_type
*howto
= reloc_entry
->howto
;
1014 asection
*reloc_target_output_section
;
1018 symbol
= *(reloc_entry
->sym_ptr_ptr
);
1019 if (bfd_is_abs_section (symbol
->section
))
1021 reloc_entry
->address
+= input_section
->output_offset
;
1022 return bfd_reloc_ok
;
1025 /* If there is a function supplied to handle this relocation type,
1026 call it. It'll return `bfd_reloc_continue' if further processing
1028 if (howto
->special_function
)
1030 bfd_reloc_status_type cont
;
1032 /* XXX - The special_function calls haven't been fixed up to deal
1033 with creating new relocations and section contents. */
1034 cont
= howto
->special_function (abfd
, reloc_entry
, symbol
,
1035 /* XXX - Non-portable! */
1036 ((bfd_byte
*) data_start
1037 - data_start_offset
),
1038 input_section
, abfd
, error_message
);
1039 if (cont
!= bfd_reloc_continue
)
1043 /* Is the address of the relocation really within the section? */
1044 if (reloc_entry
->address
> input_section
->_cooked_size
)
1045 return bfd_reloc_outofrange
;
1047 /* Work out which section the relocation is targetted at and the
1048 initial relocation command value. */
1050 /* Get symbol value. (Common symbols are special.) */
1051 if (bfd_is_com_section (symbol
->section
))
1054 relocation
= symbol
->value
;
1056 reloc_target_output_section
= symbol
->section
->output_section
;
1058 /* Convert input-section-relative symbol value to absolute. */
1059 if (howto
->partial_inplace
== false)
1062 output_base
= reloc_target_output_section
->vma
;
1064 relocation
+= output_base
+ symbol
->section
->output_offset
;
1066 /* Add in supplied addend. */
1067 relocation
+= reloc_entry
->addend
;
1069 /* Here the variable relocation holds the final address of the
1070 symbol we are relocating against, plus any addend. */
1072 if (howto
->pc_relative
== true)
1074 /* This is a PC relative relocation. We want to set RELOCATION
1075 to the distance between the address of the symbol and the
1076 location. RELOCATION is already the address of the symbol.
1078 We start by subtracting the address of the section containing
1081 If pcrel_offset is set, we must further subtract the position
1082 of the location within the section. Some targets arrange for
1083 the addend to be the negative of the position of the location
1084 within the section; for example, i386-aout does this. For
1085 i386-aout, pcrel_offset is false. Some other targets do not
1086 include the position of the location; for example, m88kbcs,
1087 or ELF. For those targets, pcrel_offset is true.
1089 If we are producing relocateable output, then we must ensure
1090 that this reloc will be correctly computed when the final
1091 relocation is done. If pcrel_offset is false we want to wind
1092 up with the negative of the location within the section,
1093 which means we must adjust the existing addend by the change
1094 in the location within the section. If pcrel_offset is true
1095 we do not want to adjust the existing addend at all.
1097 FIXME: This seems logical to me, but for the case of
1098 producing relocateable output it is not what the code
1099 actually does. I don't want to change it, because it seems
1100 far too likely that something will break. */
1103 input_section
->output_section
->vma
+ input_section
->output_offset
;
1105 if (howto
->pcrel_offset
== true && howto
->partial_inplace
== true)
1106 relocation
-= reloc_entry
->address
;
1109 if (howto
->partial_inplace
== false)
1111 /* This is a partial relocation, and we want to apply the relocation
1112 to the reloc entry rather than the raw data. Modify the reloc
1113 inplace to reflect what we now know. */
1114 reloc_entry
->addend
= relocation
;
1115 reloc_entry
->address
+= input_section
->output_offset
;
1120 /* This is a partial relocation, but inplace, so modify the
1123 If we've relocated with a symbol with a section, change
1124 into a ref to the section belonging to the symbol. */
1126 reloc_entry
->address
+= input_section
->output_offset
;
1129 if (abfd
->xvec
->flavour
== bfd_target_coff_flavour
1130 && strcmp (abfd
->xvec
->name
, "aixcoff-rs6000") != 0
1131 && strcmp (abfd
->xvec
->name
, "xcoff-powermac") != 0
1132 && strcmp (abfd
->xvec
->name
, "coff-Intel-little") != 0
1133 && strcmp (abfd
->xvec
->name
, "coff-Intel-big") != 0)
1136 /* For m68k-coff, the addend was being subtracted twice during
1137 relocation with -r. Removing the line below this comment
1138 fixes that problem; see PR 2953.
1140 However, Ian wrote the following, regarding removing the line below,
1141 which explains why it is still enabled: --djm
1143 If you put a patch like that into BFD you need to check all the COFF
1144 linkers. I am fairly certain that patch will break coff-i386 (e.g.,
1145 SCO); see coff_i386_reloc in coff-i386.c where I worked around the
1146 problem in a different way. There may very well be a reason that the
1147 code works as it does.
1149 Hmmm. The first obvious point is that bfd_install_relocation should
1150 not have any tests that depend upon the flavour. It's seem like
1151 entirely the wrong place for such a thing. The second obvious point
1152 is that the current code ignores the reloc addend when producing
1153 relocateable output for COFF. That's peculiar. In fact, I really
1154 have no idea what the point of the line you want to remove is.
1156 A typical COFF reloc subtracts the old value of the symbol and adds in
1157 the new value to the location in the object file (if it's a pc
1158 relative reloc it adds the difference between the symbol value and the
1159 location). When relocating we need to preserve that property.
1161 BFD handles this by setting the addend to the negative of the old
1162 value of the symbol. Unfortunately it handles common symbols in a
1163 non-standard way (it doesn't subtract the old value) but that's a
1164 different story (we can't change it without losing backward
1165 compatibility with old object files) (coff-i386 does subtract the old
1166 value, to be compatible with existing coff-i386 targets, like SCO).
1168 So everything works fine when not producing relocateable output. When
1169 we are producing relocateable output, logically we should do exactly
1170 what we do when not producing relocateable output. Therefore, your
1171 patch is correct. In fact, it should probably always just set
1172 reloc_entry->addend to 0 for all cases, since it is, in fact, going to
1173 add the value into the object file. This won't hurt the COFF code,
1174 which doesn't use the addend; I'm not sure what it will do to other
1175 formats (the thing to check for would be whether any formats both use
1176 the addend and set partial_inplace).
1178 When I wanted to make coff-i386 produce relocateable output, I ran
1179 into the problem that you are running into: I wanted to remove that
1180 line. Rather than risk it, I made the coff-i386 relocs use a special
1181 function; it's coff_i386_reloc in coff-i386.c. The function
1182 specifically adds the addend field into the object file, knowing that
1183 bfd_install_relocation is not going to. If you remove that line, then
1184 coff-i386.c will wind up adding the addend field in twice. It's
1185 trivial to fix; it just needs to be done.
1187 The problem with removing the line is just that it may break some
1188 working code. With BFD it's hard to be sure of anything. The right
1189 way to deal with this is simply to build and test at least all the
1190 supported COFF targets. It should be straightforward if time and disk
1191 space consuming. For each target:
1193 2) generate some executable, and link it using -r (I would
1194 probably use paranoia.o and link against newlib/libc.a, which
1195 for all the supported targets would be available in
1196 /usr/cygnus/progressive/H-host/target/lib/libc.a).
1197 3) make the change to reloc.c
1198 4) rebuild the linker
1200 6) if the resulting object files are the same, you have at least
1202 7) if they are different you have to figure out which version is
1205 relocation
-= reloc_entry
->addend
;
1207 reloc_entry
->addend
= 0;
1211 reloc_entry
->addend
= relocation
;
1215 /* FIXME: This overflow checking is incomplete, because the value
1216 might have overflowed before we get here. For a correct check we
1217 need to compute the value in a size larger than bitsize, but we
1218 can't reasonably do that for a reloc the same size as a host
1220 FIXME: We should also do overflow checking on the result after
1221 adding in the value contained in the object file. */
1222 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
1223 flag
= bfd_check_overflow (howto
->complain_on_overflow
,
1226 bfd_arch_bits_per_address (abfd
),
1230 Either we are relocating all the way, or we don't want to apply
1231 the relocation to the reloc entry (probably because there isn't
1232 any room in the output format to describe addends to relocs)
1235 /* The cast to bfd_vma avoids a bug in the Alpha OSF/1 C compiler
1236 (OSF version 1.3, compiler version 3.11). It miscompiles the
1250 x <<= (unsigned long) s.i0;
1252 printf ("failed\n");
1254 printf ("succeeded (%lx)\n", x);
1258 relocation
>>= (bfd_vma
) howto
->rightshift
;
1260 /* Shift everything up to where it's going to be used */
1262 relocation
<<= (bfd_vma
) howto
->bitpos
;
1264 /* Wait for the day when all have the mask in them */
1267 i instruction to be left alone
1268 o offset within instruction
1269 r relocation offset to apply
1278 i i i i i o o o o o from bfd_get<size>
1279 and S S S S S to get the size offset we want
1280 + r r r r r r r r r r to get the final value to place
1281 and D D D D D to chop to right size
1282 -----------------------
1285 ... i i i i i o o o o o from bfd_get<size>
1286 and N N N N N get instruction
1287 -----------------------
1293 -----------------------
1294 R R R R R R R R R R put into bfd_put<size>
1298 x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask))
1300 data
= (bfd_byte
*) data_start
+ (octets
- data_start_offset
);
1302 switch (howto
->size
)
1306 char x
= bfd_get_8 (abfd
, (char *) data
);
1308 bfd_put_8 (abfd
, x
, (unsigned char *) data
);
1314 short x
= bfd_get_16 (abfd
, (bfd_byte
*) data
);
1316 bfd_put_16 (abfd
, x
, (unsigned char *) data
);
1321 long x
= bfd_get_32 (abfd
, (bfd_byte
*) data
);
1323 bfd_put_32 (abfd
, x
, (bfd_byte
*) data
);
1328 long x
= bfd_get_32 (abfd
, (bfd_byte
*) data
);
1329 relocation
= -relocation
;
1331 bfd_put_32 (abfd
, x
, (bfd_byte
*) data
);
1341 bfd_vma x
= bfd_get_64 (abfd
, (bfd_byte
*) data
);
1343 bfd_put_64 (abfd
, x
, (bfd_byte
*) data
);
1347 return bfd_reloc_other
;
1353 /* This relocation routine is used by some of the backend linkers.
1354 They do not construct asymbol or arelent structures, so there is no
1355 reason for them to use bfd_perform_relocation. Also,
1356 bfd_perform_relocation is so hacked up it is easier to write a new
1357 function than to try to deal with it.
1359 This routine does a final relocation. Whether it is useful for a
1360 relocateable link depends upon how the object format defines
1363 FIXME: This routine ignores any special_function in the HOWTO,
1364 since the existing special_function values have been written for
1365 bfd_perform_relocation.
1367 HOWTO is the reloc howto information.
1368 INPUT_BFD is the BFD which the reloc applies to.
1369 INPUT_SECTION is the section which the reloc applies to.
1370 CONTENTS is the contents of the section.
1371 ADDRESS is the address of the reloc within INPUT_SECTION.
1372 VALUE is the value of the symbol the reloc refers to.
1373 ADDEND is the addend of the reloc. */
1375 bfd_reloc_status_type
1376 _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
, address
,
1378 reloc_howto_type
*howto
;
1380 asection
*input_section
;
1388 /* Sanity check the address. */
1389 if (address
> input_section
->_raw_size
)
1390 return bfd_reloc_outofrange
;
1392 /* This function assumes that we are dealing with a basic relocation
1393 against a symbol. We want to compute the value of the symbol to
1394 relocate to. This is just VALUE, the value of the symbol, plus
1395 ADDEND, any addend associated with the reloc. */
1396 relocation
= value
+ addend
;
1398 /* If the relocation is PC relative, we want to set RELOCATION to
1399 the distance between the symbol (currently in RELOCATION) and the
1400 location we are relocating. Some targets (e.g., i386-aout)
1401 arrange for the contents of the section to be the negative of the
1402 offset of the location within the section; for such targets
1403 pcrel_offset is false. Other targets (e.g., m88kbcs or ELF)
1404 simply leave the contents of the section as zero; for such
1405 targets pcrel_offset is true. If pcrel_offset is false we do not
1406 need to subtract out the offset of the location within the
1407 section (which is just ADDRESS). */
1408 if (howto
->pc_relative
)
1410 relocation
-= (input_section
->output_section
->vma
1411 + input_section
->output_offset
);
1412 if (howto
->pcrel_offset
)
1413 relocation
-= address
;
1416 return _bfd_relocate_contents (howto
, input_bfd
, relocation
,
1417 contents
+ address
);
1420 /* Relocate a given location using a given value and howto. */
1422 bfd_reloc_status_type
1423 _bfd_relocate_contents (howto
, input_bfd
, relocation
, location
)
1424 reloc_howto_type
*howto
;
1432 unsigned int rightshift
= howto
->rightshift
;
1433 unsigned int bitpos
= howto
->bitpos
;
1435 /* If the size is negative, negate RELOCATION. This isn't very
1437 if (howto
->size
< 0)
1438 relocation
= -relocation
;
1440 /* Get the value we are going to relocate. */
1441 size
= bfd_get_reloc_size (howto
);
1448 x
= bfd_get_8 (input_bfd
, location
);
1451 x
= bfd_get_16 (input_bfd
, location
);
1454 x
= bfd_get_32 (input_bfd
, location
);
1458 x
= bfd_get_64 (input_bfd
, location
);
1465 /* Check for overflow. FIXME: We may drop bits during the addition
1466 which we don't check for. We must either check at every single
1467 operation, which would be tedious, or we must do the computations
1468 in a type larger than bfd_vma, which would be inefficient. */
1470 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
1472 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
1475 /* Get the values to be added together. For signed and unsigned
1476 relocations, we assume that all values should be truncated to
1477 the size of an address. For bitfields, all the bits matter.
1478 See also bfd_check_overflow. */
1479 fieldmask
= N_ONES (howto
->bitsize
);
1480 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
1482 b
= x
& howto
->src_mask
;
1484 switch (howto
->complain_on_overflow
)
1486 case complain_overflow_signed
:
1487 a
= (a
& addrmask
) >> rightshift
;
1489 /* If any sign bits are set, all sign bits must be set.
1490 That is, A must be a valid negative address after
1492 signmask
= ~ (fieldmask
>> 1);
1494 if (ss
!= 0 && ss
!= ((addrmask
>> rightshift
) & signmask
))
1497 /* We only need this next bit of code if the sign bit of B
1498 is below the sign bit of A. This would only happen if
1499 SRC_MASK had fewer bits than BITSIZE. Note that if
1500 SRC_MASK has more bits than BITSIZE, we can get into
1501 trouble; we would need to verify that B is in range, as
1502 we do for A above. */
1503 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
1504 if ((b
& signmask
) != 0)
1506 /* Set all the bits above the sign bit. */
1507 b
-= signmask
<<= 1;
1510 b
= (b
& addrmask
) >> bitpos
;
1512 /* Now we can do the addition. */
1515 /* See if the result has the correct sign. Bits above the
1516 sign bit are junk now; ignore them. If the sum is
1517 positive, make sure we did not have all negative inputs;
1518 if the sum is negative, make sure we did not have all
1519 positive inputs. The test below looks only at the sign
1520 bits, and it really just
1521 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
1523 signmask
= (fieldmask
>> 1) + 1;
1524 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
1529 case complain_overflow_unsigned
:
1530 /* Checking for an unsigned overflow is relatively easy:
1531 trim the addresses and add, and trim the result as well.
1532 Overflow is normally indicated when the result does not
1533 fit in the field. However, we also need to consider the
1534 case when, e.g., fieldmask is 0x7fffffff or smaller, an
1535 input is 0x80000000, and bfd_vma is only 32 bits; then we
1536 will get sum == 0, but there is an overflow, since the
1537 inputs did not fit in the field. Instead of doing a
1538 separate test, we can check for this by or-ing in the
1539 operands when testing for the sum overflowing its final
1541 a
= (a
& addrmask
) >> rightshift
;
1542 b
= (b
& addrmask
) >> bitpos
;
1543 sum
= (a
+ b
) & addrmask
;
1544 if ((a
| b
| sum
) & ~ fieldmask
)
1549 case complain_overflow_bitfield
:
1550 /* Much like unsigned, except no trimming with addrmask. In
1551 addition, the sum overflows if there is a carry out of
1552 the bfd_vma, i.e., the sum is less than either input
1557 /* Bitfields are sometimes used for signed numbers; for
1558 example, a 13-bit field sometimes represents values in
1559 0..8191 and sometimes represents values in -4096..4095.
1560 If the field is signed and a is -4095 (0x1001) and b is
1561 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
1562 0x1fff is 0x3000). It's not clear how to handle this
1563 everywhere, since there is not way to know how many bits
1564 are significant in the relocation, but the original code
1565 assumed that it was fully sign extended, and we will keep
1567 signmask
= (fieldmask
>> 1) + 1;
1569 if ((a
& ~ fieldmask
) != 0)
1571 /* Some bits out of the field are set. This might not
1572 be a problem: if this is a signed bitfield, it is OK
1573 iff all the high bits are set, including the sign
1574 bit. We'll try setting all but the most significant
1575 bit in the original relocation value: if this is all
1576 ones, we are OK, assuming a signed bitfield. */
1577 ss
= (signmask
<< rightshift
) - 1;
1578 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
1583 /* We just assume (b & ~ fieldmask) == 0. */
1585 /* We explicitly permit wrap around if this relocation
1586 covers the high bit of an address. The Linux kernel
1587 relies on it, and it is the only way to write assembler
1588 code which can run when loaded at a location 0x80000000
1589 away from the location at which it is linked. */
1590 if (howto
->bitsize
+ rightshift
1591 == bfd_arch_bits_per_address (input_bfd
))
1595 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
1597 /* There was a carry out, or the field overflow. Test
1598 for signed operands again. Here is the overflow test
1599 is as for complain_overflow_signed. */
1600 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
1611 /* Put RELOCATION in the right bits. */
1612 relocation
>>= (bfd_vma
) rightshift
;
1613 relocation
<<= (bfd_vma
) bitpos
;
1615 /* Add RELOCATION to the right bits of X. */
1616 x
= ((x
& ~howto
->dst_mask
)
1617 | (((x
& howto
->src_mask
) + relocation
) & howto
->dst_mask
));
1619 /* Put the relocated value back in the object file. */
1626 bfd_put_8 (input_bfd
, x
, location
);
1629 bfd_put_16 (input_bfd
, x
, location
);
1632 bfd_put_32 (input_bfd
, x
, location
);
1636 bfd_put_64 (input_bfd
, x
, location
);
1643 return overflow
? bfd_reloc_overflow
: bfd_reloc_ok
;
1649 howto manager, , typedef arelent, Relocations
1654 When an application wants to create a relocation, but doesn't
1655 know what the target machine might call it, it can find out by
1656 using this bit of code.
1665 The insides of a reloc code. The idea is that, eventually, there
1666 will be one enumerator for every type of relocation we ever do.
1667 Pass one of these values to <<bfd_reloc_type_lookup>>, and it'll
1668 return a howto pointer.
1670 This does mean that the application must determine the correct
1671 enumerator value; you can't get a howto pointer from a random set
1692 Basic absolute relocations of N bits.
1707 PC-relative relocations. Sometimes these are relative to the address
1708 of the relocation itself; sometimes they are relative to the start of
1709 the section containing the relocation. It depends on the specific target.
1711 The 24-bit relocation is used in some Intel 960 configurations.
1714 BFD_RELOC_32_GOT_PCREL
1716 BFD_RELOC_16_GOT_PCREL
1718 BFD_RELOC_8_GOT_PCREL
1724 BFD_RELOC_LO16_GOTOFF
1726 BFD_RELOC_HI16_GOTOFF
1728 BFD_RELOC_HI16_S_GOTOFF
1732 BFD_RELOC_32_PLT_PCREL
1734 BFD_RELOC_24_PLT_PCREL
1736 BFD_RELOC_16_PLT_PCREL
1738 BFD_RELOC_8_PLT_PCREL
1744 BFD_RELOC_LO16_PLTOFF
1746 BFD_RELOC_HI16_PLTOFF
1748 BFD_RELOC_HI16_S_PLTOFF
1755 BFD_RELOC_68K_GLOB_DAT
1757 BFD_RELOC_68K_JMP_SLOT
1759 BFD_RELOC_68K_RELATIVE
1761 Relocations used by 68K ELF.
1764 BFD_RELOC_32_BASEREL
1766 BFD_RELOC_16_BASEREL
1768 BFD_RELOC_LO16_BASEREL
1770 BFD_RELOC_HI16_BASEREL
1772 BFD_RELOC_HI16_S_BASEREL
1778 Linkage-table relative.
1783 Absolute 8-bit relocation, but used to form an address like 0xFFnn.
1786 BFD_RELOC_32_PCREL_S2
1788 BFD_RELOC_16_PCREL_S2
1790 BFD_RELOC_23_PCREL_S2
1792 These PC-relative relocations are stored as word displacements --
1793 i.e., byte displacements shifted right two bits. The 30-bit word
1794 displacement (<<32_PCREL_S2>> -- 32 bits, shifted 2) is used on the
1795 SPARC. (SPARC tools generally refer to this as <<WDISP30>>.) The
1796 signed 16-bit displacement is used on the MIPS, and the 23-bit
1797 displacement is used on the Alpha.
1804 High 22 bits and low 10 bits of 32-bit value, placed into lower bits of
1805 the target word. These are used on the SPARC.
1812 For systems that allocate a Global Pointer register, these are
1813 displacements off that register. These relocation types are
1814 handled specially, because the value the register will have is
1815 decided relatively late.
1819 BFD_RELOC_I960_CALLJ
1821 Reloc types used for i960/b.out.
1826 BFD_RELOC_SPARC_WDISP22
1832 BFD_RELOC_SPARC_GOT10
1834 BFD_RELOC_SPARC_GOT13
1836 BFD_RELOC_SPARC_GOT22
1838 BFD_RELOC_SPARC_PC10
1840 BFD_RELOC_SPARC_PC22
1842 BFD_RELOC_SPARC_WPLT30
1844 BFD_RELOC_SPARC_COPY
1846 BFD_RELOC_SPARC_GLOB_DAT
1848 BFD_RELOC_SPARC_JMP_SLOT
1850 BFD_RELOC_SPARC_RELATIVE
1852 BFD_RELOC_SPARC_UA32
1854 SPARC ELF relocations. There is probably some overlap with other
1855 relocation types already defined.
1858 BFD_RELOC_SPARC_BASE13
1860 BFD_RELOC_SPARC_BASE22
1862 I think these are specific to SPARC a.out (e.g., Sun 4).
1872 BFD_RELOC_SPARC_OLO10
1874 BFD_RELOC_SPARC_HH22
1876 BFD_RELOC_SPARC_HM10
1878 BFD_RELOC_SPARC_LM22
1880 BFD_RELOC_SPARC_PC_HH22
1882 BFD_RELOC_SPARC_PC_HM10
1884 BFD_RELOC_SPARC_PC_LM22
1886 BFD_RELOC_SPARC_WDISP16
1888 BFD_RELOC_SPARC_WDISP19
1896 BFD_RELOC_SPARC_DISP64
1899 BFD_RELOC_SPARC_PLT64
1901 BFD_RELOC_SPARC_HIX22
1903 BFD_RELOC_SPARC_LOX10
1911 BFD_RELOC_SPARC_REGISTER
1916 BFD_RELOC_SPARC_REV32
1918 SPARC little endian relocation
1921 BFD_RELOC_ALPHA_GPDISP_HI16
1923 Alpha ECOFF and ELF relocations. Some of these treat the symbol or
1924 "addend" in some special way.
1925 For GPDISP_HI16 ("gpdisp") relocations, the symbol is ignored when
1926 writing; when reading, it will be the absolute section symbol. The
1927 addend is the displacement in bytes of the "lda" instruction from
1928 the "ldah" instruction (which is at the address of this reloc).
1930 BFD_RELOC_ALPHA_GPDISP_LO16
1932 For GPDISP_LO16 ("ignore") relocations, the symbol is handled as
1933 with GPDISP_HI16 relocs. The addend is ignored when writing the
1934 relocations out, and is filled in with the file's GP value on
1935 reading, for convenience.
1938 BFD_RELOC_ALPHA_GPDISP
1940 The ELF GPDISP relocation is exactly the same as the GPDISP_HI16
1941 relocation except that there is no accompanying GPDISP_LO16
1945 BFD_RELOC_ALPHA_LITERAL
1947 BFD_RELOC_ALPHA_ELF_LITERAL
1949 BFD_RELOC_ALPHA_LITUSE
1951 The Alpha LITERAL/LITUSE relocs are produced by a symbol reference;
1952 the assembler turns it into a LDQ instruction to load the address of
1953 the symbol, and then fills in a register in the real instruction.
1955 The LITERAL reloc, at the LDQ instruction, refers to the .lita
1956 section symbol. The addend is ignored when writing, but is filled
1957 in with the file's GP value on reading, for convenience, as with the
1960 The ELF_LITERAL reloc is somewhere between 16_GOTOFF and GPDISP_LO16.
1961 It should refer to the symbol to be referenced, as with 16_GOTOFF,
1962 but it generates output not based on the position within the .got
1963 section, but relative to the GP value chosen for the file during the
1966 The LITUSE reloc, on the instruction using the loaded address, gives
1967 information to the linker that it might be able to use to optimize
1968 away some literal section references. The symbol is ignored (read
1969 as the absolute section symbol), and the "addend" indicates the type
1970 of instruction using the register:
1971 1 - "memory" fmt insn
1972 2 - byte-manipulation (byte offset reg)
1973 3 - jsr (target of branch)
1975 The GNU linker currently doesn't do any of this optimizing.
1978 BFD_RELOC_ALPHA_USER_LITERAL
1980 BFD_RELOC_ALPHA_USER_LITUSE_BASE
1982 BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF
1984 BFD_RELOC_ALPHA_USER_LITUSE_JSR
1986 BFD_RELOC_ALPHA_USER_GPDISP
1988 BFD_RELOC_ALPHA_USER_GPRELHIGH
1990 BFD_RELOC_ALPHA_USER_GPRELLOW
1992 The BFD_RELOC_ALPHA_USER_* relocations are used by the assembler to
1993 process the explicit !<reloc>!sequence relocations, and are mapped
1994 into the normal relocations at the end of processing.
1997 BFD_RELOC_ALPHA_HINT
1999 The HINT relocation indicates a value that should be filled into the
2000 "hint" field of a jmp/jsr/ret instruction, for possible branch-
2001 prediction logic which may be provided on some processors.
2004 BFD_RELOC_ALPHA_LINKAGE
2006 The LINKAGE relocation outputs a linkage pair in the object file,
2007 which is filled by the linker.
2010 BFD_RELOC_ALPHA_CODEADDR
2012 The CODEADDR relocation outputs a STO_CA in the object file,
2013 which is filled by the linker.
2018 Bits 27..2 of the relocation address shifted right 2 bits;
2019 simple reloc otherwise.
2022 BFD_RELOC_MIPS16_JMP
2024 The MIPS16 jump instruction.
2027 BFD_RELOC_MIPS16_GPREL
2029 MIPS16 GP relative reloc.
2034 High 16 bits of 32-bit value; simple reloc.
2038 High 16 bits of 32-bit value but the low 16 bits will be sign
2039 extended and added to form the final result. If the low 16
2040 bits form a negative number, we need to add one to the high value
2041 to compensate for the borrow when the low bits are added.
2047 BFD_RELOC_PCREL_HI16_S
2049 Like BFD_RELOC_HI16_S, but PC relative.
2051 BFD_RELOC_PCREL_LO16
2053 Like BFD_RELOC_LO16, but PC relative.
2056 BFD_RELOC_MIPS_GPREL
2059 Relocation relative to the global pointer.
2062 BFD_RELOC_MIPS_LITERAL
2064 Relocation against a MIPS literal section.
2067 BFD_RELOC_MIPS_GOT16
2069 BFD_RELOC_MIPS_CALL16
2071 BFD_RELOC_MIPS_GPREL32
2074 BFD_RELOC_MIPS_GOT_HI16
2076 BFD_RELOC_MIPS_GOT_LO16
2078 BFD_RELOC_MIPS_CALL_HI16
2080 BFD_RELOC_MIPS_CALL_LO16
2084 BFD_RELOC_MIPS_GOT_PAGE
2086 BFD_RELOC_MIPS_GOT_OFST
2088 BFD_RELOC_MIPS_GOT_DISP
2091 MIPS ELF relocations.
2102 BFD_RELOC_386_GLOB_DAT
2104 BFD_RELOC_386_JUMP_SLOT
2106 BFD_RELOC_386_RELATIVE
2108 BFD_RELOC_386_GOTOFF
2112 i386/elf relocations
2115 BFD_RELOC_NS32K_IMM_8
2117 BFD_RELOC_NS32K_IMM_16
2119 BFD_RELOC_NS32K_IMM_32
2121 BFD_RELOC_NS32K_IMM_8_PCREL
2123 BFD_RELOC_NS32K_IMM_16_PCREL
2125 BFD_RELOC_NS32K_IMM_32_PCREL
2127 BFD_RELOC_NS32K_DISP_8
2129 BFD_RELOC_NS32K_DISP_16
2131 BFD_RELOC_NS32K_DISP_32
2133 BFD_RELOC_NS32K_DISP_8_PCREL
2135 BFD_RELOC_NS32K_DISP_16_PCREL
2137 BFD_RELOC_NS32K_DISP_32_PCREL
2142 BFD_RELOC_PJ_CODE_HI16
2144 BFD_RELOC_PJ_CODE_LO16
2146 BFD_RELOC_PJ_CODE_DIR16
2148 BFD_RELOC_PJ_CODE_DIR32
2150 BFD_RELOC_PJ_CODE_REL16
2152 BFD_RELOC_PJ_CODE_REL32
2154 Picojava relocs. Not all of these appear in object files.
2165 BFD_RELOC_PPC_B16_BRTAKEN
2167 BFD_RELOC_PPC_B16_BRNTAKEN
2171 BFD_RELOC_PPC_BA16_BRTAKEN
2173 BFD_RELOC_PPC_BA16_BRNTAKEN
2177 BFD_RELOC_PPC_GLOB_DAT
2179 BFD_RELOC_PPC_JMP_SLOT
2181 BFD_RELOC_PPC_RELATIVE
2183 BFD_RELOC_PPC_LOCAL24PC
2185 BFD_RELOC_PPC_EMB_NADDR32
2187 BFD_RELOC_PPC_EMB_NADDR16
2189 BFD_RELOC_PPC_EMB_NADDR16_LO
2191 BFD_RELOC_PPC_EMB_NADDR16_HI
2193 BFD_RELOC_PPC_EMB_NADDR16_HA
2195 BFD_RELOC_PPC_EMB_SDAI16
2197 BFD_RELOC_PPC_EMB_SDA2I16
2199 BFD_RELOC_PPC_EMB_SDA2REL
2201 BFD_RELOC_PPC_EMB_SDA21
2203 BFD_RELOC_PPC_EMB_MRKREF
2205 BFD_RELOC_PPC_EMB_RELSEC16
2207 BFD_RELOC_PPC_EMB_RELST_LO
2209 BFD_RELOC_PPC_EMB_RELST_HI
2211 BFD_RELOC_PPC_EMB_RELST_HA
2213 BFD_RELOC_PPC_EMB_BIT_FLD
2215 BFD_RELOC_PPC_EMB_RELSDA
2217 Power(rs6000) and PowerPC relocations.
2222 IBM 370/390 relocations
2227 The type of reloc used to build a contructor table - at the moment
2228 probably a 32 bit wide absolute relocation, but the target can choose.
2229 It generally does map to one of the other relocation types.
2232 BFD_RELOC_ARM_PCREL_BRANCH
2234 ARM 26 bit pc-relative branch. The lowest two bits must be zero and are
2235 not stored in the instruction.
2237 BFD_RELOC_ARM_IMMEDIATE
2239 BFD_RELOC_ARM_ADRL_IMMEDIATE
2241 BFD_RELOC_ARM_OFFSET_IMM
2243 BFD_RELOC_ARM_SHIFT_IMM
2249 BFD_RELOC_ARM_CP_OFF_IMM
2251 BFD_RELOC_ARM_ADR_IMM
2253 BFD_RELOC_ARM_LDR_IMM
2255 BFD_RELOC_ARM_LITERAL
2257 BFD_RELOC_ARM_IN_POOL
2259 BFD_RELOC_ARM_OFFSET_IMM8
2261 BFD_RELOC_ARM_HWLITERAL
2263 BFD_RELOC_ARM_THUMB_ADD
2265 BFD_RELOC_ARM_THUMB_IMM
2267 BFD_RELOC_ARM_THUMB_SHIFT
2269 BFD_RELOC_ARM_THUMB_OFFSET
2275 BFD_RELOC_ARM_JUMP_SLOT
2279 BFD_RELOC_ARM_GLOB_DAT
2283 BFD_RELOC_ARM_RELATIVE
2285 BFD_RELOC_ARM_GOTOFF
2289 These relocs are only used within the ARM assembler. They are not
2290 (at present) written to any object files.
2293 BFD_RELOC_SH_PCDISP8BY2
2295 BFD_RELOC_SH_PCDISP12BY2
2299 BFD_RELOC_SH_IMM4BY2
2301 BFD_RELOC_SH_IMM4BY4
2305 BFD_RELOC_SH_IMM8BY2
2307 BFD_RELOC_SH_IMM8BY4
2309 BFD_RELOC_SH_PCRELIMM8BY2
2311 BFD_RELOC_SH_PCRELIMM8BY4
2313 BFD_RELOC_SH_SWITCH16
2315 BFD_RELOC_SH_SWITCH32
2329 Hitachi SH relocs. Not all of these appear in object files.
2332 BFD_RELOC_THUMB_PCREL_BRANCH9
2334 BFD_RELOC_THUMB_PCREL_BRANCH12
2336 BFD_RELOC_THUMB_PCREL_BRANCH23
2338 Thumb 23-, 12- and 9-bit pc-relative branches. The lowest bit must
2339 be zero and is not stored in the instruction.
2342 BFD_RELOC_ARC_B22_PCREL
2344 Argonaut RISC Core (ARC) relocs.
2345 ARC 22 bit pc-relative branch. The lowest two bits must be zero and are
2346 not stored in the instruction. The high 20 bits are installed in bits 26
2347 through 7 of the instruction.
2351 ARC 26 bit absolute branch. The lowest two bits must be zero and are not
2352 stored in the instruction. The high 24 bits are installed in bits 23
2356 BFD_RELOC_D10V_10_PCREL_R
2358 Mitsubishi D10V relocs.
2359 This is a 10-bit reloc with the right 2 bits
2362 BFD_RELOC_D10V_10_PCREL_L
2364 Mitsubishi D10V relocs.
2365 This is a 10-bit reloc with the right 2 bits
2366 assumed to be 0. This is the same as the previous reloc
2367 except it is in the left container, i.e.,
2368 shifted left 15 bits.
2372 This is an 18-bit reloc with the right 2 bits
2375 BFD_RELOC_D10V_18_PCREL
2377 This is an 18-bit reloc with the right 2 bits
2383 Mitsubishi D30V relocs.
2384 This is a 6-bit absolute reloc.
2386 BFD_RELOC_D30V_9_PCREL
2388 This is a 6-bit pc-relative reloc with
2389 the right 3 bits assumed to be 0.
2391 BFD_RELOC_D30V_9_PCREL_R
2393 This is a 6-bit pc-relative reloc with
2394 the right 3 bits assumed to be 0. Same
2395 as the previous reloc but on the right side
2400 This is a 12-bit absolute reloc with the
2401 right 3 bitsassumed to be 0.
2403 BFD_RELOC_D30V_15_PCREL
2405 This is a 12-bit pc-relative reloc with
2406 the right 3 bits assumed to be 0.
2408 BFD_RELOC_D30V_15_PCREL_R
2410 This is a 12-bit pc-relative reloc with
2411 the right 3 bits assumed to be 0. Same
2412 as the previous reloc but on the right side
2417 This is an 18-bit absolute reloc with
2418 the right 3 bits assumed to be 0.
2420 BFD_RELOC_D30V_21_PCREL
2422 This is an 18-bit pc-relative reloc with
2423 the right 3 bits assumed to be 0.
2425 BFD_RELOC_D30V_21_PCREL_R
2427 This is an 18-bit pc-relative reloc with
2428 the right 3 bits assumed to be 0. Same
2429 as the previous reloc but on the right side
2434 This is a 32-bit absolute reloc.
2436 BFD_RELOC_D30V_32_PCREL
2438 This is a 32-bit pc-relative reloc.
2443 Mitsubishi M32R relocs.
2444 This is a 24 bit absolute address.
2446 BFD_RELOC_M32R_10_PCREL
2448 This is a 10-bit pc-relative reloc with the right 2 bits assumed to be 0.
2450 BFD_RELOC_M32R_18_PCREL
2452 This is an 18-bit reloc with the right 2 bits assumed to be 0.
2454 BFD_RELOC_M32R_26_PCREL
2456 This is a 26-bit reloc with the right 2 bits assumed to be 0.
2458 BFD_RELOC_M32R_HI16_ULO
2460 This is a 16-bit reloc containing the high 16 bits of an address
2461 used when the lower 16 bits are treated as unsigned.
2463 BFD_RELOC_M32R_HI16_SLO
2465 This is a 16-bit reloc containing the high 16 bits of an address
2466 used when the lower 16 bits are treated as signed.
2470 This is a 16-bit reloc containing the lower 16 bits of an address.
2472 BFD_RELOC_M32R_SDA16
2474 This is a 16-bit reloc containing the small data area offset for use in
2475 add3, load, and store instructions.
2478 BFD_RELOC_V850_9_PCREL
2480 This is a 9-bit reloc
2482 BFD_RELOC_V850_22_PCREL
2484 This is a 22-bit reloc
2487 BFD_RELOC_V850_SDA_16_16_OFFSET
2489 This is a 16 bit offset from the short data area pointer.
2491 BFD_RELOC_V850_SDA_15_16_OFFSET
2493 This is a 16 bit offset (of which only 15 bits are used) from the
2494 short data area pointer.
2496 BFD_RELOC_V850_ZDA_16_16_OFFSET
2498 This is a 16 bit offset from the zero data area pointer.
2500 BFD_RELOC_V850_ZDA_15_16_OFFSET
2502 This is a 16 bit offset (of which only 15 bits are used) from the
2503 zero data area pointer.
2505 BFD_RELOC_V850_TDA_6_8_OFFSET
2507 This is an 8 bit offset (of which only 6 bits are used) from the
2508 tiny data area pointer.
2510 BFD_RELOC_V850_TDA_7_8_OFFSET
2512 This is an 8bit offset (of which only 7 bits are used) from the tiny
2515 BFD_RELOC_V850_TDA_7_7_OFFSET
2517 This is a 7 bit offset from the tiny data area pointer.
2519 BFD_RELOC_V850_TDA_16_16_OFFSET
2521 This is a 16 bit offset from the tiny data area pointer.
2524 BFD_RELOC_V850_TDA_4_5_OFFSET
2526 This is a 5 bit offset (of which only 4 bits are used) from the tiny
2529 BFD_RELOC_V850_TDA_4_4_OFFSET
2531 This is a 4 bit offset from the tiny data area pointer.
2533 BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
2535 This is a 16 bit offset from the short data area pointer, with the
2536 bits placed non-contigously in the instruction.
2538 BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
2540 This is a 16 bit offset from the zero data area pointer, with the
2541 bits placed non-contigously in the instruction.
2543 BFD_RELOC_V850_CALLT_6_7_OFFSET
2545 This is a 6 bit offset from the call table base pointer.
2547 BFD_RELOC_V850_CALLT_16_16_OFFSET
2549 This is a 16 bit offset from the call table base pointer.
2553 BFD_RELOC_MN10300_32_PCREL
2555 This is a 32bit pcrel reloc for the mn10300, offset by two bytes in the
2558 BFD_RELOC_MN10300_16_PCREL
2560 This is a 16bit pcrel reloc for the mn10300, offset by two bytes in the
2566 This is a 8bit DP reloc for the tms320c30, where the most
2567 significant 8 bits of a 24 bit word are placed into the least
2568 significant 8 bits of the opcode.
2573 This is a 48 bit reloc for the FR30 that stores 32 bits.
2577 This is a 32 bit reloc for the FR30 that stores 20 bits split up into
2580 BFD_RELOC_FR30_6_IN_4
2582 This is a 16 bit reloc for the FR30 that stores a 6 bit word offset in
2585 BFD_RELOC_FR30_8_IN_8
2587 This is a 16 bit reloc for the FR30 that stores an 8 bit byte offset
2590 BFD_RELOC_FR30_9_IN_8
2592 This is a 16 bit reloc for the FR30 that stores a 9 bit short offset
2595 BFD_RELOC_FR30_10_IN_8
2597 This is a 16 bit reloc for the FR30 that stores a 10 bit word offset
2600 BFD_RELOC_FR30_9_PCREL
2602 This is a 16 bit reloc for the FR30 that stores a 9 bit pc relative
2603 short offset into 8 bits.
2605 BFD_RELOC_FR30_12_PCREL
2607 This is a 16 bit reloc for the FR30 that stores a 12 bit pc relative
2608 short offset into 11 bits.
2611 BFD_RELOC_MCORE_PCREL_IMM8BY4
2613 BFD_RELOC_MCORE_PCREL_IMM11BY2
2615 BFD_RELOC_MCORE_PCREL_IMM4BY2
2617 BFD_RELOC_MCORE_PCREL_32
2619 BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2
2623 Motorola Mcore relocations.
2626 BFD_RELOC_VTABLE_INHERIT
2628 BFD_RELOC_VTABLE_ENTRY
2630 These two relocations are used by the linker to determine which of
2631 the entries in a C++ virtual function table are actually used. When
2632 the --gc-sections option is given, the linker will zero out the entries
2633 that are not used, so that the code for those functions need not be
2634 included in the output.
2636 VTABLE_INHERIT is a zero-space relocation used to describe to the
2637 linker the inheritence tree of a C++ virtual function table. The
2638 relocation's symbol should be the parent class' vtable, and the
2639 relocation should be located at the child vtable.
2641 VTABLE_ENTRY is a zero-space relocation that describes the use of a
2642 virtual function table entry. The reloc's symbol should refer to the
2643 table of the class mentioned in the code. Off of that base, an offset
2644 describes the entry that is being used. For Rela hosts, this offset
2645 is stored in the reloc's addend. For Rel hosts, we are forced to put
2646 this offset in the reloc's section offset.
2652 .typedef enum bfd_reloc_code_real bfd_reloc_code_real_type;
2658 bfd_reloc_type_lookup
2662 bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code);
2665 Return a pointer to a howto structure which, when
2666 invoked, will perform the relocation @var{code} on data from the
2673 bfd_reloc_type_lookup (abfd
, code
)
2675 bfd_reloc_code_real_type code
;
2677 return BFD_SEND (abfd
, reloc_type_lookup
, (abfd
, code
));
2680 static reloc_howto_type bfd_howto_32
=
2681 HOWTO (0, 00, 2, 32, false, 0, complain_overflow_bitfield
, 0, "VRT32", false, 0xffffffff, 0xffffffff, true);
2686 bfd_default_reloc_type_lookup
2689 reloc_howto_type *bfd_default_reloc_type_lookup
2690 (bfd *abfd, bfd_reloc_code_real_type code);
2693 Provides a default relocation lookup routine for any architecture.
2699 bfd_default_reloc_type_lookup (abfd
, code
)
2701 bfd_reloc_code_real_type code
;
2705 case BFD_RELOC_CTOR
:
2706 /* The type of reloc used in a ctor, which will be as wide as the
2707 address - so either a 64, 32, or 16 bitter. */
2708 switch (bfd_get_arch_info (abfd
)->bits_per_address
)
2713 return &bfd_howto_32
;
2722 return (reloc_howto_type
*) NULL
;
2727 bfd_get_reloc_code_name
2730 const char *bfd_get_reloc_code_name (bfd_reloc_code_real_type code);
2733 Provides a printable name for the supplied relocation code.
2734 Useful mainly for printing error messages.
2738 bfd_get_reloc_code_name (code
)
2739 bfd_reloc_code_real_type code
;
2741 if (code
> BFD_RELOC_UNUSED
)
2743 return bfd_reloc_code_real_names
[(int)code
];
2748 bfd_generic_relax_section
2751 boolean bfd_generic_relax_section
2754 struct bfd_link_info *,
2758 Provides default handling for relaxing for back ends which
2759 don't do relaxing -- i.e., does nothing.
2764 bfd_generic_relax_section (abfd
, section
, link_info
, again
)
2765 bfd
*abfd ATTRIBUTE_UNUSED
;
2766 asection
*section ATTRIBUTE_UNUSED
;
2767 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
;
2776 bfd_generic_gc_sections
2779 boolean bfd_generic_gc_sections
2780 (bfd *, struct bfd_link_info *);
2783 Provides default handling for relaxing for back ends which
2784 don't do section gc -- i.e., does nothing.
2789 bfd_generic_gc_sections (abfd
, link_info
)
2790 bfd
*abfd ATTRIBUTE_UNUSED
;
2791 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
;
2798 bfd_generic_get_relocated_section_contents
2802 bfd_generic_get_relocated_section_contents (bfd *abfd,
2803 struct bfd_link_info *link_info,
2804 struct bfd_link_order *link_order,
2806 boolean relocateable,
2810 Provides default handling of relocation effort for back ends
2811 which can't be bothered to do it efficiently.
2816 bfd_generic_get_relocated_section_contents (abfd
, link_info
, link_order
, data
,
2817 relocateable
, symbols
)
2819 struct bfd_link_info
*link_info
;
2820 struct bfd_link_order
*link_order
;
2822 boolean relocateable
;
2825 /* Get enough memory to hold the stuff */
2826 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
2827 asection
*input_section
= link_order
->u
.indirect
.section
;
2829 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
2830 arelent
**reloc_vector
= NULL
;
2836 reloc_vector
= (arelent
**) bfd_malloc ((size_t) reloc_size
);
2837 if (reloc_vector
== NULL
&& reloc_size
!= 0)
2840 /* read in the section */
2841 if (!bfd_get_section_contents (input_bfd
,
2845 input_section
->_raw_size
))
2848 /* We're not relaxing the section, so just copy the size info */
2849 input_section
->_cooked_size
= input_section
->_raw_size
;
2850 input_section
->reloc_done
= true;
2852 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
2856 if (reloc_count
< 0)
2859 if (reloc_count
> 0)
2862 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
2865 char *error_message
= (char *) NULL
;
2866 bfd_reloc_status_type r
=
2867 bfd_perform_relocation (input_bfd
,
2871 relocateable
? abfd
: (bfd
*) NULL
,
2876 asection
*os
= input_section
->output_section
;
2878 /* A partial link, so keep the relocs */
2879 os
->orelocation
[os
->reloc_count
] = *parent
;
2883 if (r
!= bfd_reloc_ok
)
2887 case bfd_reloc_undefined
:
2888 if (!((*link_info
->callbacks
->undefined_symbol
)
2889 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
2890 input_bfd
, input_section
, (*parent
)->address
,
2894 case bfd_reloc_dangerous
:
2895 BFD_ASSERT (error_message
!= (char *) NULL
);
2896 if (!((*link_info
->callbacks
->reloc_dangerous
)
2897 (link_info
, error_message
, input_bfd
, input_section
,
2898 (*parent
)->address
)))
2901 case bfd_reloc_overflow
:
2902 if (!((*link_info
->callbacks
->reloc_overflow
)
2903 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
2904 (*parent
)->howto
->name
, (*parent
)->addend
,
2905 input_bfd
, input_section
, (*parent
)->address
)))
2908 case bfd_reloc_outofrange
:
2917 if (reloc_vector
!= NULL
)
2918 free (reloc_vector
);
2922 if (reloc_vector
!= NULL
)
2923 free (reloc_vector
);