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