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