]>
Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | /* BFD support for handling relocation entries. |
2 | Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999 | |
3 | Free Software Foundation, Inc. | |
4 | Written by Cygnus Support. | |
5 | ||
6 | This file is part of BFD, the Binary File Descriptor library. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | /* | |
23 | SECTION | |
24 | Relocations | |
25 | ||
26 | BFD maintains relocations in much the same way it maintains | |
27 | symbols: they are left alone until required, then read in | |
28 | en-mass and translated into an internal form. A common | |
29 | routine <<bfd_perform_relocation>> acts upon the | |
30 | canonical form to do the fixup. | |
31 | ||
32 | Relocations are maintained on a per section basis, | |
33 | while symbols are maintained on a per BFD basis. | |
34 | ||
35 | All that a back end has to do to fit the BFD interface is to create | |
36 | a <<struct reloc_cache_entry>> for each relocation | |
37 | in a particular section, and fill in the right bits of the structures. | |
38 | ||
39 | @menu | |
40 | @* typedef arelent:: | |
41 | @* howto manager:: | |
42 | @end menu | |
43 | ||
44 | */ | |
45 | ||
46 | /* DO compile in the reloc_code name table from libbfd.h. */ | |
47 | #define _BFD_MAKE_TABLE_bfd_reloc_code_real | |
48 | ||
49 | #include "bfd.h" | |
50 | #include "sysdep.h" | |
51 | #include "bfdlink.h" | |
52 | #include "libbfd.h" | |
53 | /* | |
54 | DOCDD | |
55 | INODE | |
56 | typedef arelent, howto manager, Relocations, Relocations | |
57 | ||
58 | SUBSECTION | |
59 | typedef arelent | |
60 | ||
61 | This is the structure of a relocation entry: | |
62 | ||
63 | CODE_FRAGMENT | |
64 | . | |
65 | .typedef enum bfd_reloc_status | |
66 | .{ | |
67 | . {* No errors detected *} | |
68 | . bfd_reloc_ok, | |
69 | . | |
70 | . {* The relocation was performed, but there was an overflow. *} | |
71 | . bfd_reloc_overflow, | |
72 | . | |
73 | . {* The address to relocate was not within the section supplied. *} | |
74 | . bfd_reloc_outofrange, | |
75 | . | |
76 | . {* Used by special functions *} | |
77 | . bfd_reloc_continue, | |
78 | . | |
79 | . {* Unsupported relocation size requested. *} | |
80 | . bfd_reloc_notsupported, | |
81 | . | |
82 | . {* Unused *} | |
83 | . bfd_reloc_other, | |
84 | . | |
85 | . {* The symbol to relocate against was undefined. *} | |
86 | . bfd_reloc_undefined, | |
87 | . | |
88 | . {* The relocation was performed, but may not be ok - presently | |
89 | . generated only when linking i960 coff files with i960 b.out | |
90 | . symbols. If this type is returned, the error_message argument | |
91 | . to bfd_perform_relocation will be set. *} | |
92 | . bfd_reloc_dangerous | |
93 | . } | |
94 | . bfd_reloc_status_type; | |
95 | . | |
96 | . | |
97 | .typedef struct reloc_cache_entry | |
98 | .{ | |
99 | . {* A pointer into the canonical table of pointers *} | |
100 | . struct symbol_cache_entry **sym_ptr_ptr; | |
101 | . | |
102 | . {* offset in section *} | |
103 | . bfd_size_type address; | |
104 | . | |
105 | . {* addend for relocation value *} | |
106 | . bfd_vma addend; | |
107 | . | |
108 | . {* Pointer to how to perform the required relocation *} | |
109 | . reloc_howto_type *howto; | |
110 | . | |
111 | .} arelent; | |
112 | ||
113 | */ | |
114 | ||
115 | /* | |
116 | DESCRIPTION | |
117 | ||
118 | Here is a description of each of the fields within an <<arelent>>: | |
119 | ||
120 | o <<sym_ptr_ptr>> | |
121 | ||
122 | The symbol table pointer points to a pointer to the symbol | |
123 | associated with the relocation request. It is | |
124 | the pointer into the table returned by the back end's | |
125 | <<get_symtab>> action. @xref{Symbols}. The symbol is referenced | |
126 | through a pointer to a pointer so that tools like the linker | |
127 | can fix up all the symbols of the same name by modifying only | |
128 | one pointer. The relocation routine looks in the symbol and | |
129 | uses the base of the section the symbol is attached to and the | |
130 | value of the symbol as the initial relocation offset. If the | |
131 | symbol pointer is zero, then the section provided is looked up. | |
132 | ||
133 | o <<address>> | |
134 | ||
135 | The <<address>> field gives the offset in bytes from the base of | |
136 | the section data which owns the relocation record to the first | |
137 | byte of relocatable information. The actual data relocated | |
138 | will be relative to this point; for example, a relocation | |
139 | type which modifies the bottom two bytes of a four byte word | |
140 | would not touch the first byte pointed to in a big endian | |
141 | world. | |
142 | ||
143 | o <<addend>> | |
144 | ||
145 | The <<addend>> is a value provided by the back end to be added (!) | |
146 | to the relocation offset. Its interpretation is dependent upon | |
147 | the howto. For example, on the 68k the code: | |
148 | ||
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 | ||
165 | This could create a reloc pointing to <<foo>>, but leave the | |
166 | offset in the data, something like: | |
167 | ||
168 | ||
169 | |RELOCATION RECORDS FOR [.text]: | |
170 | |offset type value | |
171 | |00000006 32 _foo | |
172 | | | |
173 | |00000000 4e56 fffc ; linkw fp,#-4 | |
174 | |00000004 1039 1234 5678 ; moveb @@#12345678,d0 | |
175 | |0000000a 49c0 ; extbl d0 | |
176 | |0000000c 4e5e ; unlk fp | |
177 | |0000000e 4e75 ; rts | |
178 | ||
179 | ||
180 | Using coff and an 88k, some instructions don't have enough | |
181 | space in them to represent the full address range, and | |
182 | pointers have to be loaded in two parts. So you'd get something like: | |
183 | ||
184 | ||
185 | | or.u r13,r0,hi16(_foo+0x12345678) | |
186 | | ld.b r2,r13,lo16(_foo+0x12345678) | |
187 | | jmp r1 | |
188 | ||
189 | ||
190 | This should create two relocs, both pointing to <<_foo>>, and with | |
191 | 0x12340000 in their addend field. The data would consist of: | |
192 | ||
193 | ||
194 | |RELOCATION RECORDS FOR [.text]: | |
195 | |offset type value | |
196 | |00000002 HVRT16 _foo+0x12340000 | |
197 | |00000006 LVRT16 _foo+0x12340000 | |
198 | | | |
199 | |00000000 5da05678 ; or.u r13,r0,0x5678 | |
200 | |00000004 1c4d5678 ; ld.b r2,r13,0x5678 | |
201 | |00000008 f400c001 ; jmp r1 | |
202 | ||
203 | ||
204 | The relocation routine digs out the value from the data, adds | |
205 | it to the addend to get the original offset, and then adds the | |
206 | value of <<_foo>>. Note that all 32 bits have to be kept around | |
207 | somewhere, to cope with carry from bit 15 to bit 16. | |
208 | ||
209 | One further example is the sparc and the a.out format. The | |
210 | sparc has a similar problem to the 88k, in that some | |
211 | instructions don't have room for an entire offset, but on the | |
212 | sparc the parts are created in odd sized lumps. The designers of | |
213 | the a.out format chose to not use the data within the section | |
214 | for storing part of the offset; all the offset is kept within | |
215 | the reloc. Anything in the data should be ignored. | |
216 | ||
217 | | save %sp,-112,%sp | |
218 | | sethi %hi(_foo+0x12345678),%g2 | |
219 | | ldsb [%g2+%lo(_foo+0x12345678)],%i0 | |
220 | | ret | |
221 | | restore | |
222 | ||
223 | Both relocs contain a pointer to <<foo>>, and the offsets | |
224 | contain junk. | |
225 | ||
226 | ||
227 | |RELOCATION RECORDS FOR [.text]: | |
228 | |offset type value | |
229 | |00000004 HI22 _foo+0x12345678 | |
230 | |00000008 LO10 _foo+0x12345678 | |
231 | | | |
232 | |00000000 9de3bf90 ; save %sp,-112,%sp | |
233 | |00000004 05000000 ; sethi %hi(_foo+0),%g2 | |
234 | |00000008 f048a000 ; ldsb [%g2+%lo(_foo+0)],%i0 | |
235 | |0000000c 81c7e008 ; ret | |
236 | |00000010 81e80000 ; restore | |
237 | ||
238 | ||
239 | o <<howto>> | |
240 | ||
241 | The <<howto>> field can be imagined as a | |
242 | relocation instruction. It is a pointer to a structure which | |
243 | contains information on what to do with all of the other | |
244 | information in the reloc record and data section. A back end | |
245 | would normally have a relocation instruction set and turn | |
246 | relocations into pointers to the correct structure on input - | |
247 | but it would be possible to create each howto field on demand. | |
248 | ||
249 | */ | |
250 | ||
251 | /* | |
252 | SUBSUBSECTION | |
253 | <<enum complain_overflow>> | |
254 | ||
255 | Indicates what sort of overflow checking should be done when | |
256 | performing a relocation. | |
257 | ||
258 | CODE_FRAGMENT | |
259 | . | |
260 | .enum complain_overflow | |
261 | .{ | |
262 | . {* Do not complain on overflow. *} | |
263 | . complain_overflow_dont, | |
264 | . | |
265 | . {* Complain if the bitfield overflows, whether it is considered | |
266 | . as signed or unsigned. *} | |
267 | . complain_overflow_bitfield, | |
268 | . | |
269 | . {* Complain if the value overflows when considered as signed | |
270 | . number. *} | |
271 | . complain_overflow_signed, | |
272 | . | |
273 | . {* Complain if the value overflows when considered as an | |
274 | . unsigned number. *} | |
275 | . complain_overflow_unsigned | |
276 | .}; | |
277 | ||
278 | */ | |
279 | ||
280 | /* | |
281 | SUBSUBSECTION | |
282 | <<reloc_howto_type>> | |
283 | ||
284 | The <<reloc_howto_type>> is a structure which contains all the | |
285 | information that libbfd needs to know to tie up a back end's data. | |
286 | ||
287 | CODE_FRAGMENT | |
288 | .struct symbol_cache_entry; {* Forward declaration *} | |
289 | . | |
290 | .struct reloc_howto_struct | |
291 | .{ | |
292 | . {* The type field has mainly a documentary use - the back end can | |
293 | . do what it wants with it, though normally the back end's | |
294 | . external idea of what a reloc number is stored | |
295 | . in this field. For example, a PC relative word relocation | |
296 | . in a coff environment has the type 023 - because that's | |
297 | . what the outside world calls a R_PCRWORD reloc. *} | |
298 | . unsigned int type; | |
299 | . | |
300 | . {* The value the final relocation is shifted right by. This drops | |
301 | . unwanted data from the relocation. *} | |
302 | . unsigned int rightshift; | |
303 | . | |
304 | . {* The size of the item to be relocated. This is *not* a | |
305 | . power-of-two measure. To get the number of bytes operated | |
306 | . on by a type of relocation, use bfd_get_reloc_size. *} | |
307 | . int size; | |
308 | . | |
309 | . {* The number of bits in the item to be relocated. This is used | |
310 | . when doing overflow checking. *} | |
311 | . unsigned int bitsize; | |
312 | . | |
313 | . {* Notes that the relocation is relative to the location in the | |
314 | . data section of the addend. The relocation function will | |
315 | . subtract from the relocation value the address of the location | |
316 | . being relocated. *} | |
317 | . boolean pc_relative; | |
318 | . | |
319 | . {* The bit position of the reloc value in the destination. | |
320 | . The relocated value is left shifted by this amount. *} | |
321 | . unsigned int bitpos; | |
322 | . | |
323 | . {* What type of overflow error should be checked for when | |
324 | . relocating. *} | |
325 | . enum complain_overflow complain_on_overflow; | |
326 | . | |
327 | . {* If this field is non null, then the supplied function is | |
328 | . called rather than the normal function. This allows really | |
329 | . strange relocation methods to be accomodated (e.g., i960 callj | |
330 | . instructions). *} | |
331 | . bfd_reloc_status_type (*special_function) | |
332 | . PARAMS ((bfd *abfd, | |
333 | . arelent *reloc_entry, | |
334 | . struct symbol_cache_entry *symbol, | |
335 | . PTR data, | |
336 | . asection *input_section, | |
337 | . bfd *output_bfd, | |
338 | . char **error_message)); | |
339 | . | |
340 | . {* The textual name of the relocation type. *} | |
341 | . char *name; | |
342 | . | |
343 | . {* When performing a partial link, some formats must modify the | |
344 | . relocations rather than the data - this flag signals this.*} | |
345 | . boolean partial_inplace; | |
346 | . | |
347 | . {* The src_mask selects which parts of the read in data | |
348 | . are to be used in the relocation sum. E.g., if this was an 8 bit | |
349 | . bit of data which we read and relocated, this would be | |
350 | . 0x000000ff. When we have relocs which have an addend, such as | |
351 | . sun4 extended relocs, the value in the offset part of a | |
352 | . relocating field is garbage so we never use it. In this case | |
353 | . the mask would be 0x00000000. *} | |
354 | . bfd_vma src_mask; | |
355 | . | |
356 | . {* The dst_mask selects which parts of the instruction are replaced | |
357 | . into the instruction. In most cases src_mask == dst_mask, | |
358 | . except in the above special case, where dst_mask would be | |
359 | . 0x000000ff, and src_mask would be 0x00000000. *} | |
360 | . bfd_vma dst_mask; | |
361 | . | |
362 | . {* When some formats create PC relative instructions, they leave | |
363 | . the value of the pc of the place being relocated in the offset | |
364 | . slot of the instruction, so that a PC relative relocation can | |
365 | . be made just by adding in an ordinary offset (e.g., sun3 a.out). | |
366 | . Some formats leave the displacement part of an instruction | |
367 | . empty (e.g., m88k bcs); this flag signals the fact.*} | |
368 | . boolean pcrel_offset; | |
369 | . | |
370 | .}; | |
371 | ||
372 | */ | |
373 | ||
374 | /* | |
375 | FUNCTION | |
376 | The HOWTO Macro | |
377 | ||
378 | DESCRIPTION | |
379 | The HOWTO define is horrible and will go away. | |
380 | ||
381 | ||
382 | .#define HOWTO(C, R,S,B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \ | |
383 | . {(unsigned)C,R,S,B, P, BI, O,SF,NAME,INPLACE,MASKSRC,MASKDST,PC} | |
384 | ||
385 | DESCRIPTION | |
386 | And will be replaced with the totally magic way. But for the | |
387 | moment, we are compatible, so do it this way. | |
388 | ||
389 | ||
390 | .#define NEWHOWTO( FUNCTION, NAME,SIZE,REL,IN) HOWTO(0,0,SIZE,0,REL,0,complain_overflow_dont,FUNCTION, NAME,false,0,0,IN) | |
391 | . | |
5f771d47 ILT |
392 | |
393 | DESCRIPTION | |
394 | This is used to fill in an empty howto entry in an array. | |
395 | ||
396 | .#define EMPTY_HOWTO(C) \ | |
397 | . HOWTO((C),0,0,0,false,0,complain_overflow_dont,NULL,NULL,false,0,0,false) | |
398 | . | |
399 | ||
252b5132 RH |
400 | DESCRIPTION |
401 | Helper routine to turn a symbol into a relocation value. | |
402 | ||
403 | .#define HOWTO_PREPARE(relocation, symbol) \ | |
404 | . { \ | |
405 | . if (symbol != (asymbol *)NULL) { \ | |
406 | . if (bfd_is_com_section (symbol->section)) { \ | |
407 | . relocation = 0; \ | |
408 | . } \ | |
409 | . else { \ | |
410 | . relocation = symbol->value; \ | |
411 | . } \ | |
412 | . } \ | |
413 | .} | |
414 | ||
415 | */ | |
416 | ||
417 | /* | |
418 | FUNCTION | |
419 | bfd_get_reloc_size | |
420 | ||
421 | SYNOPSIS | |
422 | unsigned int bfd_get_reloc_size (reloc_howto_type *); | |
423 | ||
424 | DESCRIPTION | |
425 | For a reloc_howto_type that operates on a fixed number of bytes, | |
426 | this returns the number of bytes operated on. | |
427 | */ | |
428 | ||
429 | unsigned int | |
430 | bfd_get_reloc_size (howto) | |
431 | reloc_howto_type *howto; | |
432 | { | |
433 | switch (howto->size) | |
434 | { | |
435 | case 0: return 1; | |
436 | case 1: return 2; | |
437 | case 2: return 4; | |
438 | case 3: return 0; | |
439 | case 4: return 8; | |
440 | case 8: return 16; | |
441 | case -2: return 4; | |
442 | default: abort (); | |
443 | } | |
444 | } | |
445 | ||
446 | /* | |
447 | TYPEDEF | |
448 | arelent_chain | |
449 | ||
450 | DESCRIPTION | |
451 | ||
452 | How relocs are tied together in an <<asection>>: | |
453 | ||
454 | .typedef struct relent_chain { | |
455 | . arelent relent; | |
456 | . struct relent_chain *next; | |
457 | .} arelent_chain; | |
458 | ||
459 | */ | |
460 | ||
461 | /* N_ONES produces N one bits, without overflowing machine arithmetic. */ | |
462 | #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1) | |
463 | ||
464 | /* | |
465 | FUNCTION | |
466 | bfd_check_overflow | |
467 | ||
468 | SYNOPSIS | |
469 | bfd_reloc_status_type | |
470 | bfd_check_overflow | |
471 | (enum complain_overflow how, | |
472 | unsigned int bitsize, | |
473 | unsigned int rightshift, | |
474 | unsigned int addrsize, | |
475 | bfd_vma relocation); | |
476 | ||
477 | DESCRIPTION | |
478 | Perform overflow checking on @var{relocation} which has | |
479 | @var{bitsize} significant bits and will be shifted right by | |
480 | @var{rightshift} bits, on a machine with addresses containing | |
481 | @var{addrsize} significant bits. The result is either of | |
482 | @code{bfd_reloc_ok} or @code{bfd_reloc_overflow}. | |
483 | ||
484 | */ | |
485 | ||
486 | bfd_reloc_status_type | |
487 | bfd_check_overflow (how, bitsize, rightshift, addrsize, relocation) | |
488 | enum complain_overflow how; | |
489 | unsigned int bitsize; | |
490 | unsigned int rightshift; | |
491 | unsigned int addrsize; | |
492 | bfd_vma relocation; | |
493 | { | |
494 | bfd_vma fieldmask, addrmask, signmask, ss, a; | |
495 | bfd_reloc_status_type flag = bfd_reloc_ok; | |
496 | ||
497 | a = relocation; | |
498 | ||
499 | /* Note: BITSIZE should always be <= ADDRSIZE, but in case it's not, | |
500 | we'll be permissive: extra bits in the field mask will | |
501 | automatically extend the address mask for purposes of the | |
502 | overflow check. */ | |
503 | fieldmask = N_ONES (bitsize); | |
504 | addrmask = N_ONES (addrsize) | fieldmask; | |
505 | ||
506 | switch (how) | |
507 | { | |
508 | case complain_overflow_dont: | |
509 | break; | |
510 | ||
511 | case complain_overflow_signed: | |
512 | /* If any sign bits are set, all sign bits must be set. That | |
513 | is, A must be a valid negative address after shifting. */ | |
514 | a = (a & addrmask) >> rightshift; | |
515 | signmask = ~ (fieldmask >> 1); | |
516 | ss = a & signmask; | |
517 | if (ss != 0 && ss != ((addrmask >> rightshift) & signmask)) | |
518 | flag = bfd_reloc_overflow; | |
519 | break; | |
520 | ||
521 | case complain_overflow_unsigned: | |
522 | /* We have an overflow if the address does not fit in the field. */ | |
523 | a = (a & addrmask) >> rightshift; | |
524 | if ((a & ~ fieldmask) != 0) | |
525 | flag = bfd_reloc_overflow; | |
526 | break; | |
527 | ||
528 | case complain_overflow_bitfield: | |
529 | /* Bitfields are sometimes signed, sometimes unsigned. We | |
530 | overflow if the value has some, but not all, bits set outside | |
531 | the field, or if it has any bits set outside the field but | |
532 | the sign bit is not set. */ | |
533 | a >>= rightshift; | |
534 | if ((a & ~ fieldmask) != 0) | |
535 | { | |
536 | signmask = (fieldmask >> 1) + 1; | |
537 | ss = (signmask << rightshift) - 1; | |
538 | if ((ss | relocation) != ~ (bfd_vma) 0) | |
539 | flag = bfd_reloc_overflow; | |
540 | } | |
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 | ||
583 | bfd_reloc_status_type | |
584 | bfd_perform_relocation (abfd, reloc_entry, data, input_section, output_bfd, | |
585 | error_message) | |
586 | bfd *abfd; | |
587 | arelent *reloc_entry; | |
588 | PTR data; | |
589 | asection *input_section; | |
590 | bfd *output_bfd; | |
591 | char **error_message; | |
592 | { | |
593 | bfd_vma relocation; | |
594 | bfd_reloc_status_type flag = bfd_reloc_ok; | |
595 | bfd_size_type addr = reloc_entry->address; | |
596 | bfd_vma output_base = 0; | |
597 | reloc_howto_type *howto = reloc_entry->howto; | |
598 | asection *reloc_target_output_section; | |
599 | asymbol *symbol; | |
600 | ||
601 | symbol = *(reloc_entry->sym_ptr_ptr); | |
602 | if (bfd_is_abs_section (symbol->section) | |
603 | && output_bfd != (bfd *) NULL) | |
604 | { | |
605 | reloc_entry->address += input_section->output_offset; | |
606 | return bfd_reloc_ok; | |
607 | } | |
608 | ||
609 | /* If we are not producing relocateable output, return an error if | |
610 | the symbol is not defined. An undefined weak symbol is | |
611 | considered to have a value of zero (SVR4 ABI, p. 4-27). */ | |
612 | if (bfd_is_und_section (symbol->section) | |
613 | && (symbol->flags & BSF_WEAK) == 0 | |
614 | && output_bfd == (bfd *) NULL) | |
615 | flag = bfd_reloc_undefined; | |
616 | ||
617 | /* If there is a function supplied to handle this relocation type, | |
618 | call it. It'll return `bfd_reloc_continue' if further processing | |
619 | can be done. */ | |
620 | if (howto->special_function) | |
621 | { | |
622 | bfd_reloc_status_type cont; | |
623 | cont = howto->special_function (abfd, reloc_entry, symbol, data, | |
624 | input_section, output_bfd, | |
625 | error_message); | |
626 | if (cont != bfd_reloc_continue) | |
627 | return cont; | |
628 | } | |
629 | ||
630 | /* Is the address of the relocation really within the section? */ | |
631 | if (reloc_entry->address > input_section->_cooked_size) | |
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 | ||
644 | reloc_target_output_section = symbol->section->output_section; | |
645 | ||
646 | /* Convert input-section-relative symbol value to absolute. */ | |
647 | if (output_bfd && howto->partial_inplace == false) | |
648 | output_base = 0; | |
649 | else | |
650 | output_base = reloc_target_output_section->vma; | |
651 | ||
652 | relocation += output_base + symbol->section->output_offset; | |
653 | ||
654 | /* Add in supplied addend. */ | |
655 | relocation += reloc_entry->addend; | |
656 | ||
657 | /* Here the variable relocation holds the final address of the | |
658 | symbol we are relocating against, plus any addend. */ | |
659 | ||
660 | if (howto->pc_relative == true) | |
661 | { | |
662 | /* This is a PC relative relocation. We want to set RELOCATION | |
663 | to the distance between the address of the symbol and the | |
664 | location. RELOCATION is already the address of the symbol. | |
665 | ||
666 | We start by subtracting the address of the section containing | |
667 | the location. | |
668 | ||
669 | If pcrel_offset is set, we must further subtract the position | |
670 | of the location within the section. Some targets arrange for | |
671 | the addend to be the negative of the position of the location | |
672 | within the section; for example, i386-aout does this. For | |
673 | i386-aout, pcrel_offset is false. Some other targets do not | |
674 | include the position of the location; for example, m88kbcs, | |
675 | or ELF. For those targets, pcrel_offset is true. | |
676 | ||
677 | If we are producing relocateable output, then we must ensure | |
678 | that this reloc will be correctly computed when the final | |
679 | relocation is done. If pcrel_offset is false we want to wind | |
680 | up with the negative of the location within the section, | |
681 | which means we must adjust the existing addend by the change | |
682 | in the location within the section. If pcrel_offset is true | |
683 | we do not want to adjust the existing addend at all. | |
684 | ||
685 | FIXME: This seems logical to me, but for the case of | |
686 | producing relocateable output it is not what the code | |
687 | actually does. I don't want to change it, because it seems | |
688 | far too likely that something will break. */ | |
689 | ||
690 | relocation -= | |
691 | input_section->output_section->vma + input_section->output_offset; | |
692 | ||
693 | if (howto->pcrel_offset == true) | |
694 | relocation -= reloc_entry->address; | |
695 | } | |
696 | ||
697 | if (output_bfd != (bfd *) NULL) | |
698 | { | |
699 | if (howto->partial_inplace == false) | |
700 | { | |
701 | /* This is a partial relocation, and we want to apply the relocation | |
702 | to the reloc entry rather than the raw data. Modify the reloc | |
703 | inplace to reflect what we now know. */ | |
704 | reloc_entry->addend = relocation; | |
705 | reloc_entry->address += input_section->output_offset; | |
706 | return flag; | |
707 | } | |
708 | else | |
709 | { | |
710 | /* This is a partial relocation, but inplace, so modify the | |
711 | reloc record a bit. | |
712 | ||
713 | If we've relocated with a symbol with a section, change | |
714 | into a ref to the section belonging to the symbol. */ | |
715 | ||
716 | reloc_entry->address += input_section->output_offset; | |
717 | ||
718 | /* WTF?? */ | |
719 | if (abfd->xvec->flavour == bfd_target_coff_flavour | |
720 | && strcmp (abfd->xvec->name, "aixcoff-rs6000") != 0 | |
721 | && strcmp (abfd->xvec->name, "xcoff-powermac") != 0 | |
722 | && strcmp (abfd->xvec->name, "coff-Intel-little") != 0 | |
723 | && strcmp (abfd->xvec->name, "coff-Intel-big") != 0) | |
724 | { | |
725 | #if 1 | |
726 | /* For m68k-coff, the addend was being subtracted twice during | |
727 | relocation with -r. Removing the line below this comment | |
728 | fixes that problem; see PR 2953. | |
729 | ||
730 | However, Ian wrote the following, regarding removing the line below, | |
731 | which explains why it is still enabled: --djm | |
732 | ||
733 | If you put a patch like that into BFD you need to check all the COFF | |
734 | linkers. I am fairly certain that patch will break coff-i386 (e.g., | |
735 | SCO); see coff_i386_reloc in coff-i386.c where I worked around the | |
736 | problem in a different way. There may very well be a reason that the | |
737 | code works as it does. | |
738 | ||
739 | Hmmm. The first obvious point is that bfd_perform_relocation should | |
740 | not have any tests that depend upon the flavour. It's seem like | |
741 | entirely the wrong place for such a thing. The second obvious point | |
742 | is that the current code ignores the reloc addend when producing | |
743 | relocateable output for COFF. That's peculiar. In fact, I really | |
744 | have no idea what the point of the line you want to remove is. | |
745 | ||
746 | A typical COFF reloc subtracts the old value of the symbol and adds in | |
747 | the new value to the location in the object file (if it's a pc | |
748 | relative reloc it adds the difference between the symbol value and the | |
749 | location). When relocating we need to preserve that property. | |
750 | ||
751 | BFD handles this by setting the addend to the negative of the old | |
752 | value of the symbol. Unfortunately it handles common symbols in a | |
753 | non-standard way (it doesn't subtract the old value) but that's a | |
754 | different story (we can't change it without losing backward | |
755 | compatibility with old object files) (coff-i386 does subtract the old | |
756 | value, to be compatible with existing coff-i386 targets, like SCO). | |
757 | ||
758 | So everything works fine when not producing relocateable output. When | |
759 | we are producing relocateable output, logically we should do exactly | |
760 | what we do when not producing relocateable output. Therefore, your | |
761 | patch is correct. In fact, it should probably always just set | |
762 | reloc_entry->addend to 0 for all cases, since it is, in fact, going to | |
763 | add the value into the object file. This won't hurt the COFF code, | |
764 | which doesn't use the addend; I'm not sure what it will do to other | |
765 | formats (the thing to check for would be whether any formats both use | |
766 | the addend and set partial_inplace). | |
767 | ||
768 | When I wanted to make coff-i386 produce relocateable output, I ran | |
769 | into the problem that you are running into: I wanted to remove that | |
770 | line. Rather than risk it, I made the coff-i386 relocs use a special | |
771 | function; it's coff_i386_reloc in coff-i386.c. The function | |
772 | specifically adds the addend field into the object file, knowing that | |
773 | bfd_perform_relocation is not going to. If you remove that line, then | |
774 | coff-i386.c will wind up adding the addend field in twice. It's | |
775 | trivial to fix; it just needs to be done. | |
776 | ||
777 | The problem with removing the line is just that it may break some | |
778 | working code. With BFD it's hard to be sure of anything. The right | |
779 | way to deal with this is simply to build and test at least all the | |
780 | supported COFF targets. It should be straightforward if time and disk | |
781 | space consuming. For each target: | |
782 | 1) build the linker | |
783 | 2) generate some executable, and link it using -r (I would | |
784 | probably use paranoia.o and link against newlib/libc.a, which | |
785 | for all the supported targets would be available in | |
786 | /usr/cygnus/progressive/H-host/target/lib/libc.a). | |
787 | 3) make the change to reloc.c | |
788 | 4) rebuild the linker | |
789 | 5) repeat step 2 | |
790 | 6) if the resulting object files are the same, you have at least | |
791 | made it no worse | |
792 | 7) if they are different you have to figure out which version is | |
793 | right | |
794 | */ | |
795 | relocation -= reloc_entry->addend; | |
796 | #endif | |
797 | reloc_entry->addend = 0; | |
798 | } | |
799 | else | |
800 | { | |
801 | reloc_entry->addend = relocation; | |
802 | } | |
803 | } | |
804 | } | |
805 | else | |
806 | { | |
807 | reloc_entry->addend = 0; | |
808 | } | |
809 | ||
810 | /* FIXME: This overflow checking is incomplete, because the value | |
811 | might have overflowed before we get here. For a correct check we | |
812 | need to compute the value in a size larger than bitsize, but we | |
813 | can't reasonably do that for a reloc the same size as a host | |
814 | machine word. | |
815 | FIXME: We should also do overflow checking on the result after | |
816 | adding in the value contained in the object file. */ | |
817 | if (howto->complain_on_overflow != complain_overflow_dont | |
818 | && flag == bfd_reloc_ok) | |
819 | flag = bfd_check_overflow (howto->complain_on_overflow, | |
820 | howto->bitsize, | |
821 | howto->rightshift, | |
822 | bfd_arch_bits_per_address (abfd), | |
823 | relocation); | |
824 | ||
825 | /* | |
826 | Either we are relocating all the way, or we don't want to apply | |
827 | the relocation to the reloc entry (probably because there isn't | |
828 | any room in the output format to describe addends to relocs) | |
829 | */ | |
830 | ||
831 | /* The cast to bfd_vma avoids a bug in the Alpha OSF/1 C compiler | |
832 | (OSF version 1.3, compiler version 3.11). It miscompiles the | |
833 | following program: | |
834 | ||
835 | struct str | |
836 | { | |
837 | unsigned int i0; | |
838 | } s = { 0 }; | |
839 | ||
840 | int | |
841 | main () | |
842 | { | |
843 | unsigned long x; | |
844 | ||
845 | x = 0x100000000; | |
846 | x <<= (unsigned long) s.i0; | |
847 | if (x == 0) | |
848 | printf ("failed\n"); | |
849 | else | |
850 | printf ("succeeded (%lx)\n", x); | |
851 | } | |
852 | */ | |
853 | ||
854 | relocation >>= (bfd_vma) howto->rightshift; | |
855 | ||
856 | /* Shift everything up to where it's going to be used */ | |
857 | ||
858 | relocation <<= (bfd_vma) howto->bitpos; | |
859 | ||
860 | /* Wait for the day when all have the mask in them */ | |
861 | ||
862 | /* What we do: | |
863 | i instruction to be left alone | |
864 | o offset within instruction | |
865 | r relocation offset to apply | |
866 | S src mask | |
867 | D dst mask | |
868 | N ~dst mask | |
869 | A part 1 | |
870 | B part 2 | |
871 | R result | |
872 | ||
873 | Do this: | |
874 | i i i i i o o o o o from bfd_get<size> | |
875 | and S S S S S to get the size offset we want | |
876 | + r r r r r r r r r r to get the final value to place | |
877 | and D D D D D to chop to right size | |
878 | ----------------------- | |
879 | A A A A A | |
880 | And this: | |
881 | ... i i i i i o o o o o from bfd_get<size> | |
882 | and N N N N N get instruction | |
883 | ----------------------- | |
884 | ... B B B B B | |
885 | ||
886 | And then: | |
887 | B B B B B | |
888 | or A A A A A | |
889 | ----------------------- | |
890 | R R R R R R R R R R put into bfd_put<size> | |
891 | */ | |
892 | ||
893 | #define DOIT(x) \ | |
894 | x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask)) | |
895 | ||
896 | switch (howto->size) | |
897 | { | |
898 | case 0: | |
899 | { | |
900 | char x = bfd_get_8 (abfd, (char *) data + addr); | |
901 | DOIT (x); | |
902 | bfd_put_8 (abfd, x, (unsigned char *) data + addr); | |
903 | } | |
904 | break; | |
905 | ||
906 | case 1: | |
907 | { | |
908 | short x = bfd_get_16 (abfd, (bfd_byte *) data + addr); | |
909 | DOIT (x); | |
910 | bfd_put_16 (abfd, x, (unsigned char *) data + addr); | |
911 | } | |
912 | break; | |
913 | case 2: | |
914 | { | |
915 | long x = bfd_get_32 (abfd, (bfd_byte *) data + addr); | |
916 | DOIT (x); | |
917 | bfd_put_32 (abfd, x, (bfd_byte *) data + addr); | |
918 | } | |
919 | break; | |
920 | case -2: | |
921 | { | |
922 | long x = bfd_get_32 (abfd, (bfd_byte *) data + addr); | |
923 | relocation = -relocation; | |
924 | DOIT (x); | |
925 | bfd_put_32 (abfd, x, (bfd_byte *) data + addr); | |
926 | } | |
927 | break; | |
928 | ||
929 | case -1: | |
930 | { | |
931 | long x = bfd_get_16 (abfd, (bfd_byte *) data + addr); | |
932 | relocation = -relocation; | |
933 | DOIT (x); | |
934 | bfd_put_16 (abfd, x, (bfd_byte *) data + addr); | |
935 | } | |
936 | break; | |
937 | ||
938 | case 3: | |
939 | /* Do nothing */ | |
940 | break; | |
941 | ||
942 | case 4: | |
943 | #ifdef BFD64 | |
944 | { | |
945 | bfd_vma x = bfd_get_64 (abfd, (bfd_byte *) data + addr); | |
946 | DOIT (x); | |
947 | bfd_put_64 (abfd, x, (bfd_byte *) data + addr); | |
948 | } | |
949 | #else | |
950 | abort (); | |
951 | #endif | |
952 | break; | |
953 | default: | |
954 | return bfd_reloc_other; | |
955 | } | |
956 | ||
957 | return flag; | |
958 | } | |
959 | ||
960 | /* | |
961 | FUNCTION | |
962 | bfd_install_relocation | |
963 | ||
964 | SYNOPSIS | |
965 | bfd_reloc_status_type | |
966 | bfd_install_relocation | |
967 | (bfd *abfd, | |
968 | arelent *reloc_entry, | |
969 | PTR data, bfd_vma data_start, | |
970 | asection *input_section, | |
971 | char **error_message); | |
972 | ||
973 | DESCRIPTION | |
974 | This looks remarkably like <<bfd_perform_relocation>>, except it | |
975 | does not expect that the section contents have been filled in. | |
976 | I.e., it's suitable for use when creating, rather than applying | |
977 | a relocation. | |
978 | ||
979 | For now, this function should be considered reserved for the | |
980 | assembler. | |
981 | ||
982 | */ | |
983 | ||
984 | ||
985 | bfd_reloc_status_type | |
986 | bfd_install_relocation (abfd, reloc_entry, data_start, data_start_offset, | |
987 | input_section, error_message) | |
988 | bfd *abfd; | |
989 | arelent *reloc_entry; | |
990 | PTR data_start; | |
991 | bfd_vma data_start_offset; | |
992 | asection *input_section; | |
993 | char **error_message; | |
994 | { | |
995 | bfd_vma relocation; | |
996 | bfd_reloc_status_type flag = bfd_reloc_ok; | |
997 | bfd_size_type addr = reloc_entry->address; | |
998 | bfd_vma output_base = 0; | |
999 | reloc_howto_type *howto = reloc_entry->howto; | |
1000 | asection *reloc_target_output_section; | |
1001 | asymbol *symbol; | |
1002 | bfd_byte *data; | |
1003 | ||
1004 | symbol = *(reloc_entry->sym_ptr_ptr); | |
1005 | if (bfd_is_abs_section (symbol->section)) | |
1006 | { | |
1007 | reloc_entry->address += input_section->output_offset; | |
1008 | return bfd_reloc_ok; | |
1009 | } | |
1010 | ||
1011 | /* If there is a function supplied to handle this relocation type, | |
1012 | call it. It'll return `bfd_reloc_continue' if further processing | |
1013 | can be done. */ | |
1014 | if (howto->special_function) | |
1015 | { | |
1016 | bfd_reloc_status_type cont; | |
1017 | ||
1018 | /* XXX - The special_function calls haven't been fixed up to deal | |
1019 | with creating new relocations and section contents. */ | |
1020 | cont = howto->special_function (abfd, reloc_entry, symbol, | |
1021 | /* XXX - Non-portable! */ | |
1022 | ((bfd_byte *) data_start | |
1023 | - data_start_offset), | |
1024 | input_section, abfd, error_message); | |
1025 | if (cont != bfd_reloc_continue) | |
1026 | return cont; | |
1027 | } | |
1028 | ||
1029 | /* Is the address of the relocation really within the section? */ | |
1030 | if (reloc_entry->address > input_section->_cooked_size) | |
1031 | return bfd_reloc_outofrange; | |
1032 | ||
1033 | /* Work out which section the relocation is targetted at and the | |
1034 | initial relocation command value. */ | |
1035 | ||
1036 | /* Get symbol value. (Common symbols are special.) */ | |
1037 | if (bfd_is_com_section (symbol->section)) | |
1038 | relocation = 0; | |
1039 | else | |
1040 | relocation = symbol->value; | |
1041 | ||
1042 | reloc_target_output_section = symbol->section->output_section; | |
1043 | ||
1044 | /* Convert input-section-relative symbol value to absolute. */ | |
1045 | if (howto->partial_inplace == false) | |
1046 | output_base = 0; | |
1047 | else | |
1048 | output_base = reloc_target_output_section->vma; | |
1049 | ||
1050 | relocation += output_base + symbol->section->output_offset; | |
1051 | ||
1052 | /* Add in supplied addend. */ | |
1053 | relocation += reloc_entry->addend; | |
1054 | ||
1055 | /* Here the variable relocation holds the final address of the | |
1056 | symbol we are relocating against, plus any addend. */ | |
1057 | ||
1058 | if (howto->pc_relative == true) | |
1059 | { | |
1060 | /* This is a PC relative relocation. We want to set RELOCATION | |
1061 | to the distance between the address of the symbol and the | |
1062 | location. RELOCATION is already the address of the symbol. | |
1063 | ||
1064 | We start by subtracting the address of the section containing | |
1065 | the location. | |
1066 | ||
1067 | If pcrel_offset is set, we must further subtract the position | |
1068 | of the location within the section. Some targets arrange for | |
1069 | the addend to be the negative of the position of the location | |
1070 | within the section; for example, i386-aout does this. For | |
1071 | i386-aout, pcrel_offset is false. Some other targets do not | |
1072 | include the position of the location; for example, m88kbcs, | |
1073 | or ELF. For those targets, pcrel_offset is true. | |
1074 | ||
1075 | If we are producing relocateable output, then we must ensure | |
1076 | that this reloc will be correctly computed when the final | |
1077 | relocation is done. If pcrel_offset is false we want to wind | |
1078 | up with the negative of the location within the section, | |
1079 | which means we must adjust the existing addend by the change | |
1080 | in the location within the section. If pcrel_offset is true | |
1081 | we do not want to adjust the existing addend at all. | |
1082 | ||
1083 | FIXME: This seems logical to me, but for the case of | |
1084 | producing relocateable output it is not what the code | |
1085 | actually does. I don't want to change it, because it seems | |
1086 | far too likely that something will break. */ | |
1087 | ||
1088 | relocation -= | |
1089 | input_section->output_section->vma + input_section->output_offset; | |
1090 | ||
1091 | if (howto->pcrel_offset == true && howto->partial_inplace == true) | |
1092 | relocation -= reloc_entry->address; | |
1093 | } | |
1094 | ||
1095 | if (howto->partial_inplace == false) | |
1096 | { | |
1097 | /* This is a partial relocation, and we want to apply the relocation | |
1098 | to the reloc entry rather than the raw data. Modify the reloc | |
1099 | inplace to reflect what we now know. */ | |
1100 | reloc_entry->addend = relocation; | |
1101 | reloc_entry->address += input_section->output_offset; | |
1102 | return flag; | |
1103 | } | |
1104 | else | |
1105 | { | |
1106 | /* This is a partial relocation, but inplace, so modify the | |
1107 | reloc record a bit. | |
1108 | ||
1109 | If we've relocated with a symbol with a section, change | |
1110 | into a ref to the section belonging to the symbol. */ | |
1111 | ||
1112 | reloc_entry->address += input_section->output_offset; | |
1113 | ||
1114 | /* WTF?? */ | |
1115 | if (abfd->xvec->flavour == bfd_target_coff_flavour | |
1116 | && strcmp (abfd->xvec->name, "aixcoff-rs6000") != 0 | |
1117 | && strcmp (abfd->xvec->name, "xcoff-powermac") != 0 | |
1118 | && strcmp (abfd->xvec->name, "coff-Intel-little") != 0 | |
1119 | && strcmp (abfd->xvec->name, "coff-Intel-big") != 0) | |
1120 | { | |
1121 | #if 1 | |
1122 | /* For m68k-coff, the addend was being subtracted twice during | |
1123 | relocation with -r. Removing the line below this comment | |
1124 | fixes that problem; see PR 2953. | |
1125 | ||
1126 | However, Ian wrote the following, regarding removing the line below, | |
1127 | which explains why it is still enabled: --djm | |
1128 | ||
1129 | If you put a patch like that into BFD you need to check all the COFF | |
1130 | linkers. I am fairly certain that patch will break coff-i386 (e.g., | |
1131 | SCO); see coff_i386_reloc in coff-i386.c where I worked around the | |
1132 | problem in a different way. There may very well be a reason that the | |
1133 | code works as it does. | |
1134 | ||
1135 | Hmmm. The first obvious point is that bfd_install_relocation should | |
1136 | not have any tests that depend upon the flavour. It's seem like | |
1137 | entirely the wrong place for such a thing. The second obvious point | |
1138 | is that the current code ignores the reloc addend when producing | |
1139 | relocateable output for COFF. That's peculiar. In fact, I really | |
1140 | have no idea what the point of the line you want to remove is. | |
1141 | ||
1142 | A typical COFF reloc subtracts the old value of the symbol and adds in | |
1143 | the new value to the location in the object file (if it's a pc | |
1144 | relative reloc it adds the difference between the symbol value and the | |
1145 | location). When relocating we need to preserve that property. | |
1146 | ||
1147 | BFD handles this by setting the addend to the negative of the old | |
1148 | value of the symbol. Unfortunately it handles common symbols in a | |
1149 | non-standard way (it doesn't subtract the old value) but that's a | |
1150 | different story (we can't change it without losing backward | |
1151 | compatibility with old object files) (coff-i386 does subtract the old | |
1152 | value, to be compatible with existing coff-i386 targets, like SCO). | |
1153 | ||
1154 | So everything works fine when not producing relocateable output. When | |
1155 | we are producing relocateable output, logically we should do exactly | |
1156 | what we do when not producing relocateable output. Therefore, your | |
1157 | patch is correct. In fact, it should probably always just set | |
1158 | reloc_entry->addend to 0 for all cases, since it is, in fact, going to | |
1159 | add the value into the object file. This won't hurt the COFF code, | |
1160 | which doesn't use the addend; I'm not sure what it will do to other | |
1161 | formats (the thing to check for would be whether any formats both use | |
1162 | the addend and set partial_inplace). | |
1163 | ||
1164 | When I wanted to make coff-i386 produce relocateable output, I ran | |
1165 | into the problem that you are running into: I wanted to remove that | |
1166 | line. Rather than risk it, I made the coff-i386 relocs use a special | |
1167 | function; it's coff_i386_reloc in coff-i386.c. The function | |
1168 | specifically adds the addend field into the object file, knowing that | |
1169 | bfd_install_relocation is not going to. If you remove that line, then | |
1170 | coff-i386.c will wind up adding the addend field in twice. It's | |
1171 | trivial to fix; it just needs to be done. | |
1172 | ||
1173 | The problem with removing the line is just that it may break some | |
1174 | working code. With BFD it's hard to be sure of anything. The right | |
1175 | way to deal with this is simply to build and test at least all the | |
1176 | supported COFF targets. It should be straightforward if time and disk | |
1177 | space consuming. For each target: | |
1178 | 1) build the linker | |
1179 | 2) generate some executable, and link it using -r (I would | |
1180 | probably use paranoia.o and link against newlib/libc.a, which | |
1181 | for all the supported targets would be available in | |
1182 | /usr/cygnus/progressive/H-host/target/lib/libc.a). | |
1183 | 3) make the change to reloc.c | |
1184 | 4) rebuild the linker | |
1185 | 5) repeat step 2 | |
1186 | 6) if the resulting object files are the same, you have at least | |
1187 | made it no worse | |
1188 | 7) if they are different you have to figure out which version is | |
1189 | right | |
1190 | */ | |
1191 | relocation -= reloc_entry->addend; | |
1192 | #endif | |
1193 | reloc_entry->addend = 0; | |
1194 | } | |
1195 | else | |
1196 | { | |
1197 | reloc_entry->addend = relocation; | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | /* FIXME: This overflow checking is incomplete, because the value | |
1202 | might have overflowed before we get here. For a correct check we | |
1203 | need to compute the value in a size larger than bitsize, but we | |
1204 | can't reasonably do that for a reloc the same size as a host | |
1205 | machine word. | |
1206 | FIXME: We should also do overflow checking on the result after | |
1207 | adding in the value contained in the object file. */ | |
1208 | if (howto->complain_on_overflow != complain_overflow_dont) | |
1209 | flag = bfd_check_overflow (howto->complain_on_overflow, | |
1210 | howto->bitsize, | |
1211 | howto->rightshift, | |
1212 | bfd_arch_bits_per_address (abfd), | |
1213 | relocation); | |
1214 | ||
1215 | /* | |
1216 | Either we are relocating all the way, or we don't want to apply | |
1217 | the relocation to the reloc entry (probably because there isn't | |
1218 | any room in the output format to describe addends to relocs) | |
1219 | */ | |
1220 | ||
1221 | /* The cast to bfd_vma avoids a bug in the Alpha OSF/1 C compiler | |
1222 | (OSF version 1.3, compiler version 3.11). It miscompiles the | |
1223 | following program: | |
1224 | ||
1225 | struct str | |
1226 | { | |
1227 | unsigned int i0; | |
1228 | } s = { 0 }; | |
1229 | ||
1230 | int | |
1231 | main () | |
1232 | { | |
1233 | unsigned long x; | |
1234 | ||
1235 | x = 0x100000000; | |
1236 | x <<= (unsigned long) s.i0; | |
1237 | if (x == 0) | |
1238 | printf ("failed\n"); | |
1239 | else | |
1240 | printf ("succeeded (%lx)\n", x); | |
1241 | } | |
1242 | */ | |
1243 | ||
1244 | relocation >>= (bfd_vma) howto->rightshift; | |
1245 | ||
1246 | /* Shift everything up to where it's going to be used */ | |
1247 | ||
1248 | relocation <<= (bfd_vma) howto->bitpos; | |
1249 | ||
1250 | /* Wait for the day when all have the mask in them */ | |
1251 | ||
1252 | /* What we do: | |
1253 | i instruction to be left alone | |
1254 | o offset within instruction | |
1255 | r relocation offset to apply | |
1256 | S src mask | |
1257 | D dst mask | |
1258 | N ~dst mask | |
1259 | A part 1 | |
1260 | B part 2 | |
1261 | R result | |
1262 | ||
1263 | Do this: | |
1264 | i i i i i o o o o o from bfd_get<size> | |
1265 | and S S S S S to get the size offset we want | |
1266 | + r r r r r r r r r r to get the final value to place | |
1267 | and D D D D D to chop to right size | |
1268 | ----------------------- | |
1269 | A A A A A | |
1270 | And this: | |
1271 | ... i i i i i o o o o o from bfd_get<size> | |
1272 | and N N N N N get instruction | |
1273 | ----------------------- | |
1274 | ... B B B B B | |
1275 | ||
1276 | And then: | |
1277 | B B B B B | |
1278 | or A A A A A | |
1279 | ----------------------- | |
1280 | R R R R R R R R R R put into bfd_put<size> | |
1281 | */ | |
1282 | ||
1283 | #define DOIT(x) \ | |
1284 | x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask)) | |
1285 | ||
1286 | data = (bfd_byte *) data_start + (addr - data_start_offset); | |
1287 | ||
1288 | switch (howto->size) | |
1289 | { | |
1290 | case 0: | |
1291 | { | |
1292 | char x = bfd_get_8 (abfd, (char *) data); | |
1293 | DOIT (x); | |
1294 | bfd_put_8 (abfd, x, (unsigned char *) data); | |
1295 | } | |
1296 | break; | |
1297 | ||
1298 | case 1: | |
1299 | { | |
1300 | short x = bfd_get_16 (abfd, (bfd_byte *) data); | |
1301 | DOIT (x); | |
1302 | bfd_put_16 (abfd, x, (unsigned char *) data); | |
1303 | } | |
1304 | break; | |
1305 | case 2: | |
1306 | { | |
1307 | long x = bfd_get_32 (abfd, (bfd_byte *) data); | |
1308 | DOIT (x); | |
1309 | bfd_put_32 (abfd, x, (bfd_byte *) data); | |
1310 | } | |
1311 | break; | |
1312 | case -2: | |
1313 | { | |
1314 | long x = bfd_get_32 (abfd, (bfd_byte *) data); | |
1315 | relocation = -relocation; | |
1316 | DOIT (x); | |
1317 | bfd_put_32 (abfd, x, (bfd_byte *) data); | |
1318 | } | |
1319 | break; | |
1320 | ||
1321 | case 3: | |
1322 | /* Do nothing */ | |
1323 | break; | |
1324 | ||
1325 | case 4: | |
1326 | { | |
1327 | bfd_vma x = bfd_get_64 (abfd, (bfd_byte *) data); | |
1328 | DOIT (x); | |
1329 | bfd_put_64 (abfd, x, (bfd_byte *) data); | |
1330 | } | |
1331 | break; | |
1332 | default: | |
1333 | return bfd_reloc_other; | |
1334 | } | |
1335 | ||
1336 | return flag; | |
1337 | } | |
1338 | ||
1339 | /* This relocation routine is used by some of the backend linkers. | |
1340 | They do not construct asymbol or arelent structures, so there is no | |
1341 | reason for them to use bfd_perform_relocation. Also, | |
1342 | bfd_perform_relocation is so hacked up it is easier to write a new | |
1343 | function than to try to deal with it. | |
1344 | ||
1345 | This routine does a final relocation. Whether it is useful for a | |
1346 | relocateable link depends upon how the object format defines | |
1347 | relocations. | |
1348 | ||
1349 | FIXME: This routine ignores any special_function in the HOWTO, | |
1350 | since the existing special_function values have been written for | |
1351 | bfd_perform_relocation. | |
1352 | ||
1353 | HOWTO is the reloc howto information. | |
1354 | INPUT_BFD is the BFD which the reloc applies to. | |
1355 | INPUT_SECTION is the section which the reloc applies to. | |
1356 | CONTENTS is the contents of the section. | |
1357 | ADDRESS is the address of the reloc within INPUT_SECTION. | |
1358 | VALUE is the value of the symbol the reloc refers to. | |
1359 | ADDEND is the addend of the reloc. */ | |
1360 | ||
1361 | bfd_reloc_status_type | |
1362 | _bfd_final_link_relocate (howto, input_bfd, input_section, contents, address, | |
1363 | value, addend) | |
1364 | reloc_howto_type *howto; | |
1365 | bfd *input_bfd; | |
1366 | asection *input_section; | |
1367 | bfd_byte *contents; | |
1368 | bfd_vma address; | |
1369 | bfd_vma value; | |
1370 | bfd_vma addend; | |
1371 | { | |
1372 | bfd_vma relocation; | |
1373 | ||
1374 | /* Sanity check the address. */ | |
1375 | if (address > input_section->_raw_size) | |
1376 | return bfd_reloc_outofrange; | |
1377 | ||
1378 | /* This function assumes that we are dealing with a basic relocation | |
1379 | against a symbol. We want to compute the value of the symbol to | |
1380 | relocate to. This is just VALUE, the value of the symbol, plus | |
1381 | ADDEND, any addend associated with the reloc. */ | |
1382 | relocation = value + addend; | |
1383 | ||
1384 | /* If the relocation is PC relative, we want to set RELOCATION to | |
1385 | the distance between the symbol (currently in RELOCATION) and the | |
1386 | location we are relocating. Some targets (e.g., i386-aout) | |
1387 | arrange for the contents of the section to be the negative of the | |
1388 | offset of the location within the section; for such targets | |
1389 | pcrel_offset is false. Other targets (e.g., m88kbcs or ELF) | |
1390 | simply leave the contents of the section as zero; for such | |
1391 | targets pcrel_offset is true. If pcrel_offset is false we do not | |
1392 | need to subtract out the offset of the location within the | |
1393 | section (which is just ADDRESS). */ | |
1394 | if (howto->pc_relative) | |
1395 | { | |
1396 | relocation -= (input_section->output_section->vma | |
1397 | + input_section->output_offset); | |
1398 | if (howto->pcrel_offset) | |
1399 | relocation -= address; | |
1400 | } | |
1401 | ||
1402 | return _bfd_relocate_contents (howto, input_bfd, relocation, | |
1403 | contents + address); | |
1404 | } | |
1405 | ||
1406 | /* Relocate a given location using a given value and howto. */ | |
1407 | ||
1408 | bfd_reloc_status_type | |
1409 | _bfd_relocate_contents (howto, input_bfd, relocation, location) | |
1410 | reloc_howto_type *howto; | |
1411 | bfd *input_bfd; | |
1412 | bfd_vma relocation; | |
1413 | bfd_byte *location; | |
1414 | { | |
1415 | int size; | |
7442e600 | 1416 | bfd_vma x = 0; |
252b5132 RH |
1417 | boolean overflow; |
1418 | unsigned int rightshift = howto->rightshift; | |
1419 | unsigned int bitpos = howto->bitpos; | |
1420 | ||
1421 | /* If the size is negative, negate RELOCATION. This isn't very | |
1422 | general. */ | |
1423 | if (howto->size < 0) | |
1424 | relocation = -relocation; | |
1425 | ||
1426 | /* Get the value we are going to relocate. */ | |
1427 | size = bfd_get_reloc_size (howto); | |
1428 | switch (size) | |
1429 | { | |
1430 | default: | |
1431 | case 0: | |
1432 | abort (); | |
1433 | case 1: | |
1434 | x = bfd_get_8 (input_bfd, location); | |
1435 | break; | |
1436 | case 2: | |
1437 | x = bfd_get_16 (input_bfd, location); | |
1438 | break; | |
1439 | case 4: | |
1440 | x = bfd_get_32 (input_bfd, location); | |
1441 | break; | |
1442 | case 8: | |
1443 | #ifdef BFD64 | |
1444 | x = bfd_get_64 (input_bfd, location); | |
1445 | #else | |
1446 | abort (); | |
1447 | #endif | |
1448 | break; | |
1449 | } | |
1450 | ||
1451 | /* Check for overflow. FIXME: We may drop bits during the addition | |
1452 | which we don't check for. We must either check at every single | |
1453 | operation, which would be tedious, or we must do the computations | |
1454 | in a type larger than bfd_vma, which would be inefficient. */ | |
1455 | overflow = false; | |
1456 | if (howto->complain_on_overflow != complain_overflow_dont) | |
1457 | { | |
1458 | bfd_vma addrmask, fieldmask, signmask, ss; | |
1459 | bfd_vma a, b, sum; | |
1460 | ||
1461 | /* Get the values to be added together. For signed and unsigned | |
1462 | relocations, we assume that all values should be truncated to | |
1463 | the size of an address. For bitfields, all the bits matter. | |
1464 | See also bfd_check_overflow. */ | |
1465 | fieldmask = N_ONES (howto->bitsize); | |
1466 | addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask; | |
1467 | a = relocation; | |
1468 | b = x & howto->src_mask; | |
1469 | ||
1470 | switch (howto->complain_on_overflow) | |
1471 | { | |
1472 | case complain_overflow_signed: | |
1473 | a = (a & addrmask) >> rightshift; | |
1474 | ||
1475 | /* If any sign bits are set, all sign bits must be set. | |
1476 | That is, A must be a valid negative address after | |
1477 | shifting. */ | |
1478 | signmask = ~ (fieldmask >> 1); | |
1479 | ss = a & signmask; | |
1480 | if (ss != 0 && ss != ((addrmask >> rightshift) & signmask)) | |
1481 | overflow = true; | |
1482 | ||
1483 | /* We only need this next bit of code if the sign bit of B | |
1484 | is below the sign bit of A. This would only happen if | |
1485 | SRC_MASK had fewer bits than BITSIZE. Note that if | |
1486 | SRC_MASK has more bits than BITSIZE, we can get into | |
1487 | trouble; we would need to verify that B is in range, as | |
1488 | we do for A above. */ | |
1489 | signmask = ((~ howto->src_mask) >> 1) & howto->src_mask; | |
1490 | if ((b & signmask) != 0) | |
1491 | { | |
1492 | /* Set all the bits above the sign bit. */ | |
1493 | b -= signmask <<= 1; | |
1494 | } | |
1495 | ||
1496 | b = (b & addrmask) >> bitpos; | |
1497 | ||
1498 | /* Now we can do the addition. */ | |
1499 | sum = a + b; | |
1500 | ||
1501 | /* See if the result has the correct sign. Bits above the | |
1502 | sign bit are junk now; ignore them. If the sum is | |
1503 | positive, make sure we did not have all negative inputs; | |
1504 | if the sum is negative, make sure we did not have all | |
1505 | positive inputs. The test below looks only at the sign | |
1506 | bits, and it really just | |
1507 | SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM) | |
1508 | */ | |
1509 | signmask = (fieldmask >> 1) + 1; | |
1510 | if (((~ (a ^ b)) & (a ^ sum)) & signmask) | |
1511 | overflow = true; | |
1512 | ||
1513 | break; | |
1514 | ||
1515 | case complain_overflow_unsigned: | |
1516 | /* Checking for an unsigned overflow is relatively easy: | |
1517 | trim the addresses and add, and trim the result as well. | |
1518 | Overflow is normally indicated when the result does not | |
1519 | fit in the field. However, we also need to consider the | |
1520 | case when, e.g., fieldmask is 0x7fffffff or smaller, an | |
1521 | input is 0x80000000, and bfd_vma is only 32 bits; then we | |
1522 | will get sum == 0, but there is an overflow, since the | |
1523 | inputs did not fit in the field. Instead of doing a | |
1524 | separate test, we can check for this by or-ing in the | |
1525 | operands when testing for the sum overflowing its final | |
1526 | field. */ | |
1527 | a = (a & addrmask) >> rightshift; | |
1528 | b = (b & addrmask) >> bitpos; | |
1529 | sum = (a + b) & addrmask; | |
1530 | if ((a | b | sum) & ~ fieldmask) | |
1531 | overflow = true; | |
1532 | ||
1533 | break; | |
1534 | ||
1535 | case complain_overflow_bitfield: | |
1536 | /* Much like unsigned, except no trimming with addrmask. In | |
1537 | addition, the sum overflows if there is a carry out of | |
1538 | the bfd_vma, i.e., the sum is less than either input | |
1539 | operand. */ | |
1540 | a >>= rightshift; | |
1541 | b >>= bitpos; | |
1542 | ||
1543 | /* Bitfields are sometimes used for signed numbers; for | |
1544 | example, a 13-bit field sometimes represents values in | |
1545 | 0..8191 and sometimes represents values in -4096..4095. | |
1546 | If the field is signed and a is -4095 (0x1001) and b is | |
1547 | -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 + | |
1548 | 0x1fff is 0x3000). It's not clear how to handle this | |
1549 | everywhere, since there is not way to know how many bits | |
1550 | are significant in the relocation, but the original code | |
1551 | assumed that it was fully sign extended, and we will keep | |
1552 | that assumption. */ | |
1553 | signmask = (fieldmask >> 1) + 1; | |
1554 | ||
1555 | if ((a & ~ fieldmask) != 0) | |
1556 | { | |
1557 | /* Some bits out of the field are set. This might not | |
1558 | be a problem: if this is a signed bitfield, it is OK | |
1559 | iff all the high bits are set, including the sign | |
1560 | bit. We'll try setting all but the most significant | |
1561 | bit in the original relocation value: if this is all | |
1562 | ones, we are OK, assuming a signed bitfield. */ | |
1563 | ss = (signmask << rightshift) - 1; | |
1564 | if ((ss | relocation) != ~ (bfd_vma) 0) | |
1565 | overflow = true; | |
1566 | a &= fieldmask; | |
1567 | } | |
1568 | ||
1569 | /* We just assume (b & ~ fieldmask) == 0. */ | |
1570 | ||
44257b8b ILT |
1571 | /* We explicitly permit wrap around if this relocation |
1572 | covers the high bit of an address. The Linux kernel | |
1573 | relies on it, and it is the only way to write assembler | |
1574 | code which can run when loaded at a location 0x80000000 | |
1575 | away from the location at which it is linked. */ | |
1576 | if (howto->bitsize + rightshift | |
1577 | == bfd_arch_bits_per_address (input_bfd)) | |
1578 | break; | |
1579 | ||
252b5132 RH |
1580 | sum = a + b; |
1581 | if (sum < a || (sum & ~ fieldmask) != 0) | |
1582 | { | |
1583 | /* There was a carry out, or the field overflow. Test | |
1584 | for signed operands again. Here is the overflow test | |
1585 | is as for complain_overflow_signed. */ | |
1586 | if (((~ (a ^ b)) & (a ^ sum)) & signmask) | |
1587 | overflow = true; | |
1588 | } | |
1589 | ||
1590 | break; | |
1591 | ||
1592 | default: | |
1593 | abort (); | |
1594 | } | |
1595 | } | |
1596 | ||
1597 | /* Put RELOCATION in the right bits. */ | |
1598 | relocation >>= (bfd_vma) rightshift; | |
1599 | relocation <<= (bfd_vma) bitpos; | |
1600 | ||
1601 | /* Add RELOCATION to the right bits of X. */ | |
1602 | x = ((x & ~howto->dst_mask) | |
1603 | | (((x & howto->src_mask) + relocation) & howto->dst_mask)); | |
1604 | ||
1605 | /* Put the relocated value back in the object file. */ | |
1606 | switch (size) | |
1607 | { | |
1608 | default: | |
1609 | case 0: | |
1610 | abort (); | |
1611 | case 1: | |
1612 | bfd_put_8 (input_bfd, x, location); | |
1613 | break; | |
1614 | case 2: | |
1615 | bfd_put_16 (input_bfd, x, location); | |
1616 | break; | |
1617 | case 4: | |
1618 | bfd_put_32 (input_bfd, x, location); | |
1619 | break; | |
1620 | case 8: | |
1621 | #ifdef BFD64 | |
1622 | bfd_put_64 (input_bfd, x, location); | |
1623 | #else | |
1624 | abort (); | |
1625 | #endif | |
1626 | break; | |
1627 | } | |
1628 | ||
1629 | return overflow ? bfd_reloc_overflow : bfd_reloc_ok; | |
1630 | } | |
1631 | ||
1632 | /* | |
1633 | DOCDD | |
1634 | INODE | |
1635 | howto manager, , typedef arelent, Relocations | |
1636 | ||
1637 | SECTION | |
1638 | The howto manager | |
1639 | ||
1640 | When an application wants to create a relocation, but doesn't | |
1641 | know what the target machine might call it, it can find out by | |
1642 | using this bit of code. | |
1643 | ||
1644 | */ | |
1645 | ||
1646 | /* | |
1647 | TYPEDEF | |
1648 | bfd_reloc_code_type | |
1649 | ||
1650 | DESCRIPTION | |
1651 | The insides of a reloc code. The idea is that, eventually, there | |
1652 | will be one enumerator for every type of relocation we ever do. | |
1653 | Pass one of these values to <<bfd_reloc_type_lookup>>, and it'll | |
1654 | return a howto pointer. | |
1655 | ||
1656 | This does mean that the application must determine the correct | |
1657 | enumerator value; you can't get a howto pointer from a random set | |
1658 | of attributes. | |
1659 | ||
1660 | SENUM | |
1661 | bfd_reloc_code_real | |
1662 | ||
1663 | ENUM | |
1664 | BFD_RELOC_64 | |
1665 | ENUMX | |
1666 | BFD_RELOC_32 | |
1667 | ENUMX | |
1668 | BFD_RELOC_26 | |
1669 | ENUMX | |
1670 | BFD_RELOC_24 | |
1671 | ENUMX | |
1672 | BFD_RELOC_16 | |
1673 | ENUMX | |
1674 | BFD_RELOC_14 | |
1675 | ENUMX | |
1676 | BFD_RELOC_8 | |
1677 | ENUMDOC | |
1678 | Basic absolute relocations of N bits. | |
1679 | ||
1680 | ENUM | |
1681 | BFD_RELOC_64_PCREL | |
1682 | ENUMX | |
1683 | BFD_RELOC_32_PCREL | |
1684 | ENUMX | |
1685 | BFD_RELOC_24_PCREL | |
1686 | ENUMX | |
1687 | BFD_RELOC_16_PCREL | |
1688 | ENUMX | |
1689 | BFD_RELOC_12_PCREL | |
1690 | ENUMX | |
1691 | BFD_RELOC_8_PCREL | |
1692 | ENUMDOC | |
1693 | PC-relative relocations. Sometimes these are relative to the address | |
1694 | of the relocation itself; sometimes they are relative to the start of | |
1695 | the section containing the relocation. It depends on the specific target. | |
1696 | ||
1697 | The 24-bit relocation is used in some Intel 960 configurations. | |
1698 | ||
1699 | ENUM | |
1700 | BFD_RELOC_32_GOT_PCREL | |
1701 | ENUMX | |
1702 | BFD_RELOC_16_GOT_PCREL | |
1703 | ENUMX | |
1704 | BFD_RELOC_8_GOT_PCREL | |
1705 | ENUMX | |
1706 | BFD_RELOC_32_GOTOFF | |
1707 | ENUMX | |
1708 | BFD_RELOC_16_GOTOFF | |
1709 | ENUMX | |
1710 | BFD_RELOC_LO16_GOTOFF | |
1711 | ENUMX | |
1712 | BFD_RELOC_HI16_GOTOFF | |
1713 | ENUMX | |
1714 | BFD_RELOC_HI16_S_GOTOFF | |
1715 | ENUMX | |
1716 | BFD_RELOC_8_GOTOFF | |
1717 | ENUMX | |
1718 | BFD_RELOC_32_PLT_PCREL | |
1719 | ENUMX | |
1720 | BFD_RELOC_24_PLT_PCREL | |
1721 | ENUMX | |
1722 | BFD_RELOC_16_PLT_PCREL | |
1723 | ENUMX | |
1724 | BFD_RELOC_8_PLT_PCREL | |
1725 | ENUMX | |
1726 | BFD_RELOC_32_PLTOFF | |
1727 | ENUMX | |
1728 | BFD_RELOC_16_PLTOFF | |
1729 | ENUMX | |
1730 | BFD_RELOC_LO16_PLTOFF | |
1731 | ENUMX | |
1732 | BFD_RELOC_HI16_PLTOFF | |
1733 | ENUMX | |
1734 | BFD_RELOC_HI16_S_PLTOFF | |
1735 | ENUMX | |
1736 | BFD_RELOC_8_PLTOFF | |
1737 | ENUMDOC | |
1738 | For ELF. | |
1739 | ||
1740 | ENUM | |
1741 | BFD_RELOC_68K_GLOB_DAT | |
1742 | ENUMX | |
1743 | BFD_RELOC_68K_JMP_SLOT | |
1744 | ENUMX | |
1745 | BFD_RELOC_68K_RELATIVE | |
1746 | ENUMDOC | |
1747 | Relocations used by 68K ELF. | |
1748 | ||
1749 | ENUM | |
1750 | BFD_RELOC_32_BASEREL | |
1751 | ENUMX | |
1752 | BFD_RELOC_16_BASEREL | |
1753 | ENUMX | |
1754 | BFD_RELOC_LO16_BASEREL | |
1755 | ENUMX | |
1756 | BFD_RELOC_HI16_BASEREL | |
1757 | ENUMX | |
1758 | BFD_RELOC_HI16_S_BASEREL | |
1759 | ENUMX | |
1760 | BFD_RELOC_8_BASEREL | |
1761 | ENUMX | |
1762 | BFD_RELOC_RVA | |
1763 | ENUMDOC | |
1764 | Linkage-table relative. | |
1765 | ||
1766 | ENUM | |
1767 | BFD_RELOC_8_FFnn | |
1768 | ENUMDOC | |
1769 | Absolute 8-bit relocation, but used to form an address like 0xFFnn. | |
1770 | ||
1771 | ENUM | |
1772 | BFD_RELOC_32_PCREL_S2 | |
1773 | ENUMX | |
1774 | BFD_RELOC_16_PCREL_S2 | |
1775 | ENUMX | |
1776 | BFD_RELOC_23_PCREL_S2 | |
1777 | ENUMDOC | |
1778 | These PC-relative relocations are stored as word displacements -- | |
1779 | i.e., byte displacements shifted right two bits. The 30-bit word | |
1780 | displacement (<<32_PCREL_S2>> -- 32 bits, shifted 2) is used on the | |
1781 | SPARC. (SPARC tools generally refer to this as <<WDISP30>>.) The | |
1782 | signed 16-bit displacement is used on the MIPS, and the 23-bit | |
1783 | displacement is used on the Alpha. | |
1784 | ||
1785 | ENUM | |
1786 | BFD_RELOC_HI22 | |
1787 | ENUMX | |
1788 | BFD_RELOC_LO10 | |
1789 | ENUMDOC | |
1790 | High 22 bits and low 10 bits of 32-bit value, placed into lower bits of | |
1791 | the target word. These are used on the SPARC. | |
1792 | ||
1793 | ENUM | |
1794 | BFD_RELOC_GPREL16 | |
1795 | ENUMX | |
1796 | BFD_RELOC_GPREL32 | |
1797 | ENUMDOC | |
1798 | For systems that allocate a Global Pointer register, these are | |
1799 | displacements off that register. These relocation types are | |
1800 | handled specially, because the value the register will have is | |
1801 | decided relatively late. | |
1802 | ||
1803 | ||
1804 | ENUM | |
1805 | BFD_RELOC_I960_CALLJ | |
1806 | ENUMDOC | |
1807 | Reloc types used for i960/b.out. | |
1808 | ||
1809 | ENUM | |
1810 | BFD_RELOC_NONE | |
1811 | ENUMX | |
1812 | BFD_RELOC_SPARC_WDISP22 | |
1813 | ENUMX | |
1814 | BFD_RELOC_SPARC22 | |
1815 | ENUMX | |
1816 | BFD_RELOC_SPARC13 | |
1817 | ENUMX | |
1818 | BFD_RELOC_SPARC_GOT10 | |
1819 | ENUMX | |
1820 | BFD_RELOC_SPARC_GOT13 | |
1821 | ENUMX | |
1822 | BFD_RELOC_SPARC_GOT22 | |
1823 | ENUMX | |
1824 | BFD_RELOC_SPARC_PC10 | |
1825 | ENUMX | |
1826 | BFD_RELOC_SPARC_PC22 | |
1827 | ENUMX | |
1828 | BFD_RELOC_SPARC_WPLT30 | |
1829 | ENUMX | |
1830 | BFD_RELOC_SPARC_COPY | |
1831 | ENUMX | |
1832 | BFD_RELOC_SPARC_GLOB_DAT | |
1833 | ENUMX | |
1834 | BFD_RELOC_SPARC_JMP_SLOT | |
1835 | ENUMX | |
1836 | BFD_RELOC_SPARC_RELATIVE | |
1837 | ENUMX | |
1838 | BFD_RELOC_SPARC_UA32 | |
1839 | ENUMDOC | |
1840 | SPARC ELF relocations. There is probably some overlap with other | |
1841 | relocation types already defined. | |
1842 | ||
1843 | ENUM | |
1844 | BFD_RELOC_SPARC_BASE13 | |
1845 | ENUMX | |
1846 | BFD_RELOC_SPARC_BASE22 | |
1847 | ENUMDOC | |
1848 | I think these are specific to SPARC a.out (e.g., Sun 4). | |
1849 | ||
1850 | ENUMEQ | |
1851 | BFD_RELOC_SPARC_64 | |
1852 | BFD_RELOC_64 | |
1853 | ENUMX | |
1854 | BFD_RELOC_SPARC_10 | |
1855 | ENUMX | |
1856 | BFD_RELOC_SPARC_11 | |
1857 | ENUMX | |
1858 | BFD_RELOC_SPARC_OLO10 | |
1859 | ENUMX | |
1860 | BFD_RELOC_SPARC_HH22 | |
1861 | ENUMX | |
1862 | BFD_RELOC_SPARC_HM10 | |
1863 | ENUMX | |
1864 | BFD_RELOC_SPARC_LM22 | |
1865 | ENUMX | |
1866 | BFD_RELOC_SPARC_PC_HH22 | |
1867 | ENUMX | |
1868 | BFD_RELOC_SPARC_PC_HM10 | |
1869 | ENUMX | |
1870 | BFD_RELOC_SPARC_PC_LM22 | |
1871 | ENUMX | |
1872 | BFD_RELOC_SPARC_WDISP16 | |
1873 | ENUMX | |
1874 | BFD_RELOC_SPARC_WDISP19 | |
1875 | ENUMX | |
1876 | BFD_RELOC_SPARC_7 | |
1877 | ENUMX | |
1878 | BFD_RELOC_SPARC_6 | |
1879 | ENUMX | |
1880 | BFD_RELOC_SPARC_5 | |
1881 | ENUMEQX | |
1882 | BFD_RELOC_SPARC_DISP64 | |
1883 | BFD_RELOC_64_PCREL | |
1884 | ENUMX | |
1885 | BFD_RELOC_SPARC_PLT64 | |
1886 | ENUMX | |
1887 | BFD_RELOC_SPARC_HIX22 | |
1888 | ENUMX | |
1889 | BFD_RELOC_SPARC_LOX10 | |
1890 | ENUMX | |
1891 | BFD_RELOC_SPARC_H44 | |
1892 | ENUMX | |
1893 | BFD_RELOC_SPARC_M44 | |
1894 | ENUMX | |
1895 | BFD_RELOC_SPARC_L44 | |
1896 | ENUMX | |
1897 | BFD_RELOC_SPARC_REGISTER | |
1898 | ENUMDOC | |
1899 | SPARC64 relocations | |
1900 | ||
1901 | ENUM | |
1902 | BFD_RELOC_SPARC_REV32 | |
1903 | ENUMDOC | |
1904 | SPARC little endian relocation | |
1905 | ||
1906 | ENUM | |
1907 | BFD_RELOC_ALPHA_GPDISP_HI16 | |
1908 | ENUMDOC | |
1909 | Alpha ECOFF and ELF relocations. Some of these treat the symbol or | |
1910 | "addend" in some special way. | |
1911 | For GPDISP_HI16 ("gpdisp") relocations, the symbol is ignored when | |
1912 | writing; when reading, it will be the absolute section symbol. The | |
1913 | addend is the displacement in bytes of the "lda" instruction from | |
1914 | the "ldah" instruction (which is at the address of this reloc). | |
1915 | ENUM | |
1916 | BFD_RELOC_ALPHA_GPDISP_LO16 | |
1917 | ENUMDOC | |
1918 | For GPDISP_LO16 ("ignore") relocations, the symbol is handled as | |
1919 | with GPDISP_HI16 relocs. The addend is ignored when writing the | |
1920 | relocations out, and is filled in with the file's GP value on | |
1921 | reading, for convenience. | |
1922 | ||
1923 | ENUM | |
1924 | BFD_RELOC_ALPHA_GPDISP | |
1925 | ENUMDOC | |
1926 | The ELF GPDISP relocation is exactly the same as the GPDISP_HI16 | |
1927 | relocation except that there is no accompanying GPDISP_LO16 | |
1928 | relocation. | |
1929 | ||
1930 | ENUM | |
1931 | BFD_RELOC_ALPHA_LITERAL | |
1932 | ENUMX | |
1933 | BFD_RELOC_ALPHA_ELF_LITERAL | |
1934 | ENUMX | |
1935 | BFD_RELOC_ALPHA_LITUSE | |
1936 | ENUMDOC | |
1937 | The Alpha LITERAL/LITUSE relocs are produced by a symbol reference; | |
1938 | the assembler turns it into a LDQ instruction to load the address of | |
1939 | the symbol, and then fills in a register in the real instruction. | |
1940 | ||
1941 | The LITERAL reloc, at the LDQ instruction, refers to the .lita | |
1942 | section symbol. The addend is ignored when writing, but is filled | |
1943 | in with the file's GP value on reading, for convenience, as with the | |
1944 | GPDISP_LO16 reloc. | |
1945 | ||
1946 | The ELF_LITERAL reloc is somewhere between 16_GOTOFF and GPDISP_LO16. | |
1947 | It should refer to the symbol to be referenced, as with 16_GOTOFF, | |
1948 | but it generates output not based on the position within the .got | |
1949 | section, but relative to the GP value chosen for the file during the | |
1950 | final link stage. | |
1951 | ||
1952 | The LITUSE reloc, on the instruction using the loaded address, gives | |
1953 | information to the linker that it might be able to use to optimize | |
1954 | away some literal section references. The symbol is ignored (read | |
1955 | as the absolute section symbol), and the "addend" indicates the type | |
1956 | of instruction using the register: | |
1957 | 1 - "memory" fmt insn | |
1958 | 2 - byte-manipulation (byte offset reg) | |
1959 | 3 - jsr (target of branch) | |
1960 | ||
1961 | The GNU linker currently doesn't do any of this optimizing. | |
1962 | ||
fe174262 MM |
1963 | ENUM |
1964 | BFD_RELOC_ALPHA_USER_LITERAL | |
1965 | ENUMX | |
1966 | BFD_RELOC_ALPHA_USER_LITUSE_BASE | |
1967 | ENUMX | |
1968 | BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF | |
1969 | ENUMX | |
1970 | BFD_RELOC_ALPHA_USER_LITUSE_JSR | |
1971 | ENUMX | |
1972 | BFD_RELOC_ALPHA_USER_GPDISP | |
1973 | ENUMX | |
1974 | BFD_RELOC_ALPHA_USER_GPRELHIGH | |
1975 | ENUMX | |
1976 | BFD_RELOC_ALPHA_USER_GPRELLOW | |
1977 | ENUMDOC | |
1978 | The BFD_RELOC_ALPHA_USER_* relocations are used by the assembler to | |
1979 | process the explicit !<reloc>!sequence relocations, and are mapped | |
1980 | into the normal relocations at the end of processing. | |
1981 | ||
252b5132 RH |
1982 | ENUM |
1983 | BFD_RELOC_ALPHA_HINT | |
1984 | ENUMDOC | |
1985 | The HINT relocation indicates a value that should be filled into the | |
1986 | "hint" field of a jmp/jsr/ret instruction, for possible branch- | |
1987 | prediction logic which may be provided on some processors. | |
1988 | ||
1989 | ENUM | |
1990 | BFD_RELOC_ALPHA_LINKAGE | |
1991 | ENUMDOC | |
1992 | The LINKAGE relocation outputs a linkage pair in the object file, | |
1993 | which is filled by the linker. | |
1994 | ||
1995 | ENUM | |
1996 | BFD_RELOC_ALPHA_CODEADDR | |
1997 | ENUMDOC | |
1998 | The CODEADDR relocation outputs a STO_CA in the object file, | |
1999 | which is filled by the linker. | |
2000 | ||
2001 | ENUM | |
2002 | BFD_RELOC_MIPS_JMP | |
2003 | ENUMDOC | |
2004 | Bits 27..2 of the relocation address shifted right 2 bits; | |
2005 | simple reloc otherwise. | |
2006 | ||
2007 | ENUM | |
2008 | BFD_RELOC_MIPS16_JMP | |
2009 | ENUMDOC | |
2010 | The MIPS16 jump instruction. | |
2011 | ||
2012 | ENUM | |
2013 | BFD_RELOC_MIPS16_GPREL | |
2014 | ENUMDOC | |
2015 | MIPS16 GP relative reloc. | |
2016 | ||
2017 | ENUM | |
2018 | BFD_RELOC_HI16 | |
2019 | ENUMDOC | |
2020 | High 16 bits of 32-bit value; simple reloc. | |
2021 | ENUM | |
2022 | BFD_RELOC_HI16_S | |
2023 | ENUMDOC | |
2024 | High 16 bits of 32-bit value but the low 16 bits will be sign | |
2025 | extended and added to form the final result. If the low 16 | |
2026 | bits form a negative number, we need to add one to the high value | |
2027 | to compensate for the borrow when the low bits are added. | |
2028 | ENUM | |
2029 | BFD_RELOC_LO16 | |
2030 | ENUMDOC | |
2031 | Low 16 bits. | |
2032 | ENUM | |
2033 | BFD_RELOC_PCREL_HI16_S | |
2034 | ENUMDOC | |
2035 | Like BFD_RELOC_HI16_S, but PC relative. | |
2036 | ENUM | |
2037 | BFD_RELOC_PCREL_LO16 | |
2038 | ENUMDOC | |
2039 | Like BFD_RELOC_LO16, but PC relative. | |
2040 | ||
2041 | ENUMEQ | |
2042 | BFD_RELOC_MIPS_GPREL | |
2043 | BFD_RELOC_GPREL16 | |
2044 | ENUMDOC | |
2045 | Relocation relative to the global pointer. | |
2046 | ||
2047 | ENUM | |
2048 | BFD_RELOC_MIPS_LITERAL | |
2049 | ENUMDOC | |
2050 | Relocation against a MIPS literal section. | |
2051 | ||
2052 | ENUM | |
2053 | BFD_RELOC_MIPS_GOT16 | |
2054 | ENUMX | |
2055 | BFD_RELOC_MIPS_CALL16 | |
2056 | ENUMEQX | |
2057 | BFD_RELOC_MIPS_GPREL32 | |
2058 | BFD_RELOC_GPREL32 | |
2059 | ENUMX | |
2060 | BFD_RELOC_MIPS_GOT_HI16 | |
2061 | ENUMX | |
2062 | BFD_RELOC_MIPS_GOT_LO16 | |
2063 | ENUMX | |
2064 | BFD_RELOC_MIPS_CALL_HI16 | |
2065 | ENUMX | |
2066 | BFD_RELOC_MIPS_CALL_LO16 | |
3f830999 MM |
2067 | ENUMX |
2068 | BFD_RELOC_MIPS_SUB | |
2069 | ENUMX | |
2070 | BFD_RELOC_MIPS_GOT_PAGE | |
2071 | ENUMX | |
2072 | BFD_RELOC_MIPS_GOT_OFST | |
2073 | ENUMX | |
2074 | BFD_RELOC_MIPS_GOT_DISP | |
252b5132 RH |
2075 | COMMENT |
2076 | ENUMDOC | |
2077 | MIPS ELF relocations. | |
2078 | ||
2079 | COMMENT | |
2080 | ||
2081 | ENUM | |
2082 | BFD_RELOC_386_GOT32 | |
2083 | ENUMX | |
2084 | BFD_RELOC_386_PLT32 | |
2085 | ENUMX | |
2086 | BFD_RELOC_386_COPY | |
2087 | ENUMX | |
2088 | BFD_RELOC_386_GLOB_DAT | |
2089 | ENUMX | |
2090 | BFD_RELOC_386_JUMP_SLOT | |
2091 | ENUMX | |
2092 | BFD_RELOC_386_RELATIVE | |
2093 | ENUMX | |
2094 | BFD_RELOC_386_GOTOFF | |
2095 | ENUMX | |
2096 | BFD_RELOC_386_GOTPC | |
2097 | ENUMDOC | |
2098 | i386/elf relocations | |
2099 | ||
2100 | ENUM | |
2101 | BFD_RELOC_NS32K_IMM_8 | |
2102 | ENUMX | |
2103 | BFD_RELOC_NS32K_IMM_16 | |
2104 | ENUMX | |
2105 | BFD_RELOC_NS32K_IMM_32 | |
2106 | ENUMX | |
2107 | BFD_RELOC_NS32K_IMM_8_PCREL | |
2108 | ENUMX | |
2109 | BFD_RELOC_NS32K_IMM_16_PCREL | |
2110 | ENUMX | |
2111 | BFD_RELOC_NS32K_IMM_32_PCREL | |
2112 | ENUMX | |
2113 | BFD_RELOC_NS32K_DISP_8 | |
2114 | ENUMX | |
2115 | BFD_RELOC_NS32K_DISP_16 | |
2116 | ENUMX | |
2117 | BFD_RELOC_NS32K_DISP_32 | |
2118 | ENUMX | |
2119 | BFD_RELOC_NS32K_DISP_8_PCREL | |
2120 | ENUMX | |
2121 | BFD_RELOC_NS32K_DISP_16_PCREL | |
2122 | ENUMX | |
2123 | BFD_RELOC_NS32K_DISP_32_PCREL | |
2124 | ENUMDOC | |
2125 | ns32k relocations | |
2126 | ||
0bcb993b ILT |
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 | ||
252b5132 RH |
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 | ENUMDOC | |
2203 | Power(rs6000) and PowerPC relocations. | |
2204 | ||
2205 | ENUM | |
2206 | BFD_RELOC_CTOR | |
2207 | ENUMDOC | |
2208 | The type of reloc used to build a contructor table - at the moment | |
2209 | probably a 32 bit wide absolute relocation, but the target can choose. | |
2210 | It generally does map to one of the other relocation types. | |
2211 | ||
2212 | ENUM | |
2213 | BFD_RELOC_ARM_PCREL_BRANCH | |
2214 | ENUMDOC | |
2215 | ARM 26 bit pc-relative branch. The lowest two bits must be zero and are | |
2216 | not stored in the instruction. | |
2217 | ENUM | |
2218 | BFD_RELOC_ARM_IMMEDIATE | |
752149a0 NC |
2219 | ENUMX |
2220 | BFD_RELOC_ARM_ADRL_IMMEDIATE | |
252b5132 RH |
2221 | ENUMX |
2222 | BFD_RELOC_ARM_OFFSET_IMM | |
2223 | ENUMX | |
2224 | BFD_RELOC_ARM_SHIFT_IMM | |
2225 | ENUMX | |
2226 | BFD_RELOC_ARM_SWI | |
2227 | ENUMX | |
2228 | BFD_RELOC_ARM_MULTI | |
2229 | ENUMX | |
2230 | BFD_RELOC_ARM_CP_OFF_IMM | |
2231 | ENUMX | |
2232 | BFD_RELOC_ARM_ADR_IMM | |
2233 | ENUMX | |
2234 | BFD_RELOC_ARM_LDR_IMM | |
2235 | ENUMX | |
2236 | BFD_RELOC_ARM_LITERAL | |
2237 | ENUMX | |
2238 | BFD_RELOC_ARM_IN_POOL | |
2239 | ENUMX | |
2240 | BFD_RELOC_ARM_OFFSET_IMM8 | |
2241 | ENUMX | |
2242 | BFD_RELOC_ARM_HWLITERAL | |
2243 | ENUMX | |
2244 | BFD_RELOC_ARM_THUMB_ADD | |
2245 | ENUMX | |
2246 | BFD_RELOC_ARM_THUMB_IMM | |
2247 | ENUMX | |
2248 | BFD_RELOC_ARM_THUMB_SHIFT | |
2249 | ENUMX | |
2250 | BFD_RELOC_ARM_THUMB_OFFSET | |
2251 | ENUMX | |
2252 | BFD_RELOC_ARM_GOT12 | |
2253 | ENUMX | |
2254 | BFD_RELOC_ARM_GOT32 | |
2255 | ENUMX | |
2256 | BFD_RELOC_ARM_JUMP_SLOT | |
2257 | ENUMX | |
2258 | BFD_RELOC_ARM_COPY | |
2259 | ENUMX | |
2260 | BFD_RELOC_ARM_GLOB_DAT | |
2261 | ENUMX | |
2262 | BFD_RELOC_ARM_PLT32 | |
2263 | ENUMX | |
2264 | BFD_RELOC_ARM_RELATIVE | |
2265 | ENUMX | |
2266 | BFD_RELOC_ARM_GOTOFF | |
2267 | ENUMX | |
2268 | BFD_RELOC_ARM_GOTPC | |
2269 | ENUMDOC | |
2270 | These relocs are only used within the ARM assembler. They are not | |
2271 | (at present) written to any object files. | |
2272 | ||
2273 | ENUM | |
2274 | BFD_RELOC_SH_PCDISP8BY2 | |
2275 | ENUMX | |
2276 | BFD_RELOC_SH_PCDISP12BY2 | |
2277 | ENUMX | |
2278 | BFD_RELOC_SH_IMM4 | |
2279 | ENUMX | |
2280 | BFD_RELOC_SH_IMM4BY2 | |
2281 | ENUMX | |
2282 | BFD_RELOC_SH_IMM4BY4 | |
2283 | ENUMX | |
2284 | BFD_RELOC_SH_IMM8 | |
2285 | ENUMX | |
2286 | BFD_RELOC_SH_IMM8BY2 | |
2287 | ENUMX | |
2288 | BFD_RELOC_SH_IMM8BY4 | |
2289 | ENUMX | |
2290 | BFD_RELOC_SH_PCRELIMM8BY2 | |
2291 | ENUMX | |
2292 | BFD_RELOC_SH_PCRELIMM8BY4 | |
2293 | ENUMX | |
2294 | BFD_RELOC_SH_SWITCH16 | |
2295 | ENUMX | |
2296 | BFD_RELOC_SH_SWITCH32 | |
2297 | ENUMX | |
2298 | BFD_RELOC_SH_USES | |
2299 | ENUMX | |
2300 | BFD_RELOC_SH_COUNT | |
2301 | ENUMX | |
2302 | BFD_RELOC_SH_ALIGN | |
2303 | ENUMX | |
2304 | BFD_RELOC_SH_CODE | |
2305 | ENUMX | |
2306 | BFD_RELOC_SH_DATA | |
2307 | ENUMX | |
2308 | BFD_RELOC_SH_LABEL | |
2309 | ENUMDOC | |
2310 | Hitachi SH relocs. Not all of these appear in object files. | |
2311 | ||
2312 | ENUM | |
2313 | BFD_RELOC_THUMB_PCREL_BRANCH9 | |
2314 | ENUMX | |
2315 | BFD_RELOC_THUMB_PCREL_BRANCH12 | |
2316 | ENUMX | |
2317 | BFD_RELOC_THUMB_PCREL_BRANCH23 | |
2318 | ENUMDOC | |
2319 | Thumb 23-, 12- and 9-bit pc-relative branches. The lowest bit must | |
2320 | be zero and is not stored in the instruction. | |
2321 | ||
2322 | ENUM | |
2323 | BFD_RELOC_ARC_B22_PCREL | |
2324 | ENUMDOC | |
2325 | Argonaut RISC Core (ARC) relocs. | |
2326 | ARC 22 bit pc-relative branch. The lowest two bits must be zero and are | |
2327 | not stored in the instruction. The high 20 bits are installed in bits 26 | |
2328 | through 7 of the instruction. | |
2329 | ENUM | |
2330 | BFD_RELOC_ARC_B26 | |
2331 | ENUMDOC | |
2332 | ARC 26 bit absolute branch. The lowest two bits must be zero and are not | |
2333 | stored in the instruction. The high 24 bits are installed in bits 23 | |
2334 | through 0. | |
2335 | ||
2336 | ENUM | |
2337 | BFD_RELOC_D10V_10_PCREL_R | |
2338 | ENUMDOC | |
2339 | Mitsubishi D10V relocs. | |
2340 | This is a 10-bit reloc with the right 2 bits | |
2341 | assumed to be 0. | |
2342 | ENUM | |
2343 | BFD_RELOC_D10V_10_PCREL_L | |
2344 | ENUMDOC | |
2345 | Mitsubishi D10V relocs. | |
2346 | This is a 10-bit reloc with the right 2 bits | |
2347 | assumed to be 0. This is the same as the previous reloc | |
2348 | except it is in the left container, i.e., | |
2349 | shifted left 15 bits. | |
2350 | ENUM | |
2351 | BFD_RELOC_D10V_18 | |
2352 | ENUMDOC | |
2353 | This is an 18-bit reloc with the right 2 bits | |
2354 | assumed to be 0. | |
2355 | ENUM | |
2356 | BFD_RELOC_D10V_18_PCREL | |
2357 | ENUMDOC | |
2358 | This is an 18-bit reloc with the right 2 bits | |
2359 | assumed to be 0. | |
2360 | ||
2361 | ENUM | |
2362 | BFD_RELOC_D30V_6 | |
2363 | ENUMDOC | |
2364 | Mitsubishi D30V relocs. | |
2365 | This is a 6-bit absolute reloc. | |
2366 | ENUM | |
2367 | BFD_RELOC_D30V_9_PCREL | |
2368 | ENUMDOC | |
2369 | This is a 6-bit pc-relative reloc with | |
2370 | the right 3 bits assumed to be 0. | |
2371 | ENUM | |
2372 | BFD_RELOC_D30V_9_PCREL_R | |
2373 | ENUMDOC | |
2374 | This is a 6-bit pc-relative reloc with | |
2375 | the right 3 bits assumed to be 0. Same | |
2376 | as the previous reloc but on the right side | |
2377 | of the container. | |
2378 | ENUM | |
2379 | BFD_RELOC_D30V_15 | |
2380 | ENUMDOC | |
2381 | This is a 12-bit absolute reloc with the | |
2382 | right 3 bitsassumed to be 0. | |
2383 | ENUM | |
2384 | BFD_RELOC_D30V_15_PCREL | |
2385 | ENUMDOC | |
2386 | This is a 12-bit pc-relative reloc with | |
2387 | the right 3 bits assumed to be 0. | |
2388 | ENUM | |
2389 | BFD_RELOC_D30V_15_PCREL_R | |
2390 | ENUMDOC | |
2391 | This is a 12-bit pc-relative reloc with | |
2392 | the right 3 bits assumed to be 0. Same | |
2393 | as the previous reloc but on the right side | |
2394 | of the container. | |
2395 | ENUM | |
2396 | BFD_RELOC_D30V_21 | |
2397 | ENUMDOC | |
2398 | This is an 18-bit absolute reloc with | |
2399 | the right 3 bits assumed to be 0. | |
2400 | ENUM | |
2401 | BFD_RELOC_D30V_21_PCREL | |
2402 | ENUMDOC | |
2403 | This is an 18-bit pc-relative reloc with | |
2404 | the right 3 bits assumed to be 0. | |
2405 | ENUM | |
2406 | BFD_RELOC_D30V_21_PCREL_R | |
2407 | ENUMDOC | |
2408 | This is an 18-bit pc-relative reloc with | |
2409 | the right 3 bits assumed to be 0. Same | |
2410 | as the previous reloc but on the right side | |
2411 | of the container. | |
2412 | ENUM | |
2413 | BFD_RELOC_D30V_32 | |
2414 | ENUMDOC | |
2415 | This is a 32-bit absolute reloc. | |
2416 | ENUM | |
2417 | BFD_RELOC_D30V_32_PCREL | |
2418 | ENUMDOC | |
2419 | This is a 32-bit pc-relative reloc. | |
2420 | ||
2421 | ENUM | |
2422 | BFD_RELOC_M32R_24 | |
2423 | ENUMDOC | |
2424 | Mitsubishi M32R relocs. | |
2425 | This is a 24 bit absolute address. | |
2426 | ENUM | |
2427 | BFD_RELOC_M32R_10_PCREL | |
2428 | ENUMDOC | |
2429 | This is a 10-bit pc-relative reloc with the right 2 bits assumed to be 0. | |
2430 | ENUM | |
2431 | BFD_RELOC_M32R_18_PCREL | |
2432 | ENUMDOC | |
2433 | This is an 18-bit reloc with the right 2 bits assumed to be 0. | |
2434 | ENUM | |
2435 | BFD_RELOC_M32R_26_PCREL | |
2436 | ENUMDOC | |
2437 | This is a 26-bit reloc with the right 2 bits assumed to be 0. | |
2438 | ENUM | |
2439 | BFD_RELOC_M32R_HI16_ULO | |
2440 | ENUMDOC | |
2441 | This is a 16-bit reloc containing the high 16 bits of an address | |
2442 | used when the lower 16 bits are treated as unsigned. | |
2443 | ENUM | |
2444 | BFD_RELOC_M32R_HI16_SLO | |
2445 | ENUMDOC | |
2446 | This is a 16-bit reloc containing the high 16 bits of an address | |
2447 | used when the lower 16 bits are treated as signed. | |
2448 | ENUM | |
2449 | BFD_RELOC_M32R_LO16 | |
2450 | ENUMDOC | |
2451 | This is a 16-bit reloc containing the lower 16 bits of an address. | |
2452 | ENUM | |
2453 | BFD_RELOC_M32R_SDA16 | |
2454 | ENUMDOC | |
2455 | This is a 16-bit reloc containing the small data area offset for use in | |
2456 | add3, load, and store instructions. | |
2457 | ||
2458 | ENUM | |
2459 | BFD_RELOC_V850_9_PCREL | |
2460 | ENUMDOC | |
2461 | This is a 9-bit reloc | |
2462 | ENUM | |
2463 | BFD_RELOC_V850_22_PCREL | |
2464 | ENUMDOC | |
2465 | This is a 22-bit reloc | |
2466 | ||
2467 | ENUM | |
2468 | BFD_RELOC_V850_SDA_16_16_OFFSET | |
2469 | ENUMDOC | |
2470 | This is a 16 bit offset from the short data area pointer. | |
2471 | ENUM | |
2472 | BFD_RELOC_V850_SDA_15_16_OFFSET | |
2473 | ENUMDOC | |
2474 | This is a 16 bit offset (of which only 15 bits are used) from the | |
2475 | short data area pointer. | |
2476 | ENUM | |
2477 | BFD_RELOC_V850_ZDA_16_16_OFFSET | |
2478 | ENUMDOC | |
2479 | This is a 16 bit offset from the zero data area pointer. | |
2480 | ENUM | |
2481 | BFD_RELOC_V850_ZDA_15_16_OFFSET | |
2482 | ENUMDOC | |
2483 | This is a 16 bit offset (of which only 15 bits are used) from the | |
2484 | zero data area pointer. | |
2485 | ENUM | |
2486 | BFD_RELOC_V850_TDA_6_8_OFFSET | |
2487 | ENUMDOC | |
2488 | This is an 8 bit offset (of which only 6 bits are used) from the | |
2489 | tiny data area pointer. | |
2490 | ENUM | |
2491 | BFD_RELOC_V850_TDA_7_8_OFFSET | |
2492 | ENUMDOC | |
2493 | This is an 8bit offset (of which only 7 bits are used) from the tiny | |
2494 | data area pointer. | |
2495 | ENUM | |
2496 | BFD_RELOC_V850_TDA_7_7_OFFSET | |
2497 | ENUMDOC | |
2498 | This is a 7 bit offset from the tiny data area pointer. | |
2499 | ENUM | |
2500 | BFD_RELOC_V850_TDA_16_16_OFFSET | |
2501 | ENUMDOC | |
2502 | This is a 16 bit offset from the tiny data area pointer. | |
2503 | COMMENT | |
2504 | ENUM | |
2505 | BFD_RELOC_V850_TDA_4_5_OFFSET | |
2506 | ENUMDOC | |
2507 | This is a 5 bit offset (of which only 4 bits are used) from the tiny | |
2508 | data area pointer. | |
2509 | ENUM | |
2510 | BFD_RELOC_V850_TDA_4_4_OFFSET | |
2511 | ENUMDOC | |
2512 | This is a 4 bit offset from the tiny data area pointer. | |
2513 | ENUM | |
2514 | BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET | |
2515 | ENUMDOC | |
2516 | This is a 16 bit offset from the short data area pointer, with the | |
2517 | bits placed non-contigously in the instruction. | |
2518 | ENUM | |
2519 | BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET | |
2520 | ENUMDOC | |
2521 | This is a 16 bit offset from the zero data area pointer, with the | |
2522 | bits placed non-contigously in the instruction. | |
2523 | ENUM | |
2524 | BFD_RELOC_V850_CALLT_6_7_OFFSET | |
2525 | ENUMDOC | |
2526 | This is a 6 bit offset from the call table base pointer. | |
2527 | ENUM | |
2528 | BFD_RELOC_V850_CALLT_16_16_OFFSET | |
2529 | ENUMDOC | |
2530 | This is a 16 bit offset from the call table base pointer. | |
2531 | COMMENT | |
2532 | ||
2533 | ENUM | |
2534 | BFD_RELOC_MN10300_32_PCREL | |
2535 | ENUMDOC | |
2536 | This is a 32bit pcrel reloc for the mn10300, offset by two bytes in the | |
2537 | instruction. | |
2538 | ENUM | |
2539 | BFD_RELOC_MN10300_16_PCREL | |
2540 | ENUMDOC | |
2541 | This is a 16bit pcrel reloc for the mn10300, offset by two bytes in the | |
2542 | instruction. | |
2543 | ||
2544 | ENUM | |
2545 | BFD_RELOC_TIC30_LDP | |
2546 | ENUMDOC | |
2547 | This is a 8bit DP reloc for the tms320c30, where the most | |
2548 | significant 8 bits of a 24 bit word are placed into the least | |
2549 | significant 8 bits of the opcode. | |
2550 | ||
2551 | ENUM | |
2552 | BFD_RELOC_FR30_48 | |
2553 | ENUMDOC | |
2554 | This is a 48 bit reloc for the FR30 that stores 32 bits. | |
2555 | ENUM | |
2556 | BFD_RELOC_FR30_20 | |
2557 | ENUMDOC | |
2558 | This is a 32 bit reloc for the FR30 that stores 20 bits split up into | |
2559 | two sections. | |
2560 | ENUM | |
2561 | BFD_RELOC_FR30_6_IN_4 | |
2562 | ENUMDOC | |
2563 | This is a 16 bit reloc for the FR30 that stores a 6 bit word offset in | |
2564 | 4 bits. | |
2565 | ENUM | |
2566 | BFD_RELOC_FR30_8_IN_8 | |
2567 | ENUMDOC | |
2568 | This is a 16 bit reloc for the FR30 that stores an 8 bit byte offset | |
2569 | into 8 bits. | |
2570 | ENUM | |
2571 | BFD_RELOC_FR30_9_IN_8 | |
2572 | ENUMDOC | |
2573 | This is a 16 bit reloc for the FR30 that stores a 9 bit short offset | |
2574 | into 8 bits. | |
2575 | ENUM | |
2576 | BFD_RELOC_FR30_10_IN_8 | |
2577 | ENUMDOC | |
2578 | This is a 16 bit reloc for the FR30 that stores a 10 bit word offset | |
2579 | into 8 bits. | |
2580 | ENUM | |
2581 | BFD_RELOC_FR30_9_PCREL | |
2582 | ENUMDOC | |
2583 | This is a 16 bit reloc for the FR30 that stores a 9 bit pc relative | |
2584 | short offset into 8 bits. | |
2585 | ENUM | |
2586 | BFD_RELOC_FR30_12_PCREL | |
2587 | ENUMDOC | |
2588 | This is a 16 bit reloc for the FR30 that stores a 12 bit pc relative | |
2589 | short offset into 11 bits. | |
2590 | ||
2591 | ENUM | |
2592 | BFD_RELOC_MCORE_PCREL_IMM8BY4 | |
2593 | ENUMX | |
2594 | BFD_RELOC_MCORE_PCREL_IMM11BY2 | |
2595 | ENUMX | |
2596 | BFD_RELOC_MCORE_PCREL_IMM4BY2 | |
2597 | ENUMX | |
2598 | BFD_RELOC_MCORE_PCREL_32 | |
2599 | ENUMX | |
2600 | BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2 | |
36797d47 NC |
2601 | ENUMX |
2602 | BFD_RELOC_MCORE_RVA | |
252b5132 RH |
2603 | ENUMDOC |
2604 | Motorola Mcore relocations. | |
2605 | ||
2606 | ENUM | |
2607 | BFD_RELOC_VTABLE_INHERIT | |
2608 | ENUMX | |
2609 | BFD_RELOC_VTABLE_ENTRY | |
2610 | ENUMDOC | |
2611 | These two relocations are used by the linker to determine which of | |
2612 | the entries in a C++ virtual function table are actually used. When | |
2613 | the --gc-sections option is given, the linker will zero out the entries | |
2614 | that are not used, so that the code for those functions need not be | |
2615 | included in the output. | |
2616 | ||
2617 | VTABLE_INHERIT is a zero-space relocation used to describe to the | |
2618 | linker the inheritence tree of a C++ virtual function table. The | |
2619 | relocation's symbol should be the parent class' vtable, and the | |
2620 | relocation should be located at the child vtable. | |
2621 | ||
2622 | VTABLE_ENTRY is a zero-space relocation that describes the use of a | |
2623 | virtual function table entry. The reloc's symbol should refer to the | |
2624 | table of the class mentioned in the code. Off of that base, an offset | |
2625 | describes the entry that is being used. For Rela hosts, this offset | |
2626 | is stored in the reloc's addend. For Rel hosts, we are forced to put | |
2627 | this offset in the reloc's section offset. | |
2628 | ||
2629 | ENDSENUM | |
2630 | BFD_RELOC_UNUSED | |
2631 | CODE_FRAGMENT | |
2632 | . | |
2633 | .typedef enum bfd_reloc_code_real bfd_reloc_code_real_type; | |
2634 | */ | |
2635 | ||
2636 | ||
2637 | /* | |
2638 | FUNCTION | |
2639 | bfd_reloc_type_lookup | |
2640 | ||
2641 | SYNOPSIS | |
2642 | reloc_howto_type * | |
2643 | bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code); | |
2644 | ||
2645 | DESCRIPTION | |
2646 | Return a pointer to a howto structure which, when | |
2647 | invoked, will perform the relocation @var{code} on data from the | |
2648 | architecture noted. | |
2649 | ||
2650 | */ | |
2651 | ||
2652 | ||
2653 | reloc_howto_type * | |
2654 | bfd_reloc_type_lookup (abfd, code) | |
2655 | bfd *abfd; | |
2656 | bfd_reloc_code_real_type code; | |
2657 | { | |
2658 | return BFD_SEND (abfd, reloc_type_lookup, (abfd, code)); | |
2659 | } | |
2660 | ||
2661 | static reloc_howto_type bfd_howto_32 = | |
2662 | HOWTO (0, 00, 2, 32, false, 0, complain_overflow_bitfield, 0, "VRT32", false, 0xffffffff, 0xffffffff, true); | |
2663 | ||
2664 | ||
2665 | /* | |
2666 | INTERNAL_FUNCTION | |
2667 | bfd_default_reloc_type_lookup | |
2668 | ||
2669 | SYNOPSIS | |
2670 | reloc_howto_type *bfd_default_reloc_type_lookup | |
2671 | (bfd *abfd, bfd_reloc_code_real_type code); | |
2672 | ||
2673 | DESCRIPTION | |
2674 | Provides a default relocation lookup routine for any architecture. | |
2675 | ||
2676 | ||
2677 | */ | |
2678 | ||
2679 | reloc_howto_type * | |
2680 | bfd_default_reloc_type_lookup (abfd, code) | |
2681 | bfd *abfd; | |
2682 | bfd_reloc_code_real_type code; | |
2683 | { | |
2684 | switch (code) | |
2685 | { | |
2686 | case BFD_RELOC_CTOR: | |
2687 | /* The type of reloc used in a ctor, which will be as wide as the | |
2688 | address - so either a 64, 32, or 16 bitter. */ | |
2689 | switch (bfd_get_arch_info (abfd)->bits_per_address) | |
2690 | { | |
2691 | case 64: | |
2692 | BFD_FAIL (); | |
2693 | case 32: | |
2694 | return &bfd_howto_32; | |
2695 | case 16: | |
2696 | BFD_FAIL (); | |
2697 | default: | |
2698 | BFD_FAIL (); | |
2699 | } | |
2700 | default: | |
2701 | BFD_FAIL (); | |
2702 | } | |
2703 | return (reloc_howto_type *) NULL; | |
2704 | } | |
2705 | ||
2706 | /* | |
2707 | FUNCTION | |
2708 | bfd_get_reloc_code_name | |
2709 | ||
2710 | SYNOPSIS | |
2711 | const char *bfd_get_reloc_code_name (bfd_reloc_code_real_type code); | |
2712 | ||
2713 | DESCRIPTION | |
2714 | Provides a printable name for the supplied relocation code. | |
2715 | Useful mainly for printing error messages. | |
2716 | */ | |
2717 | ||
2718 | const char * | |
2719 | bfd_get_reloc_code_name (code) | |
2720 | bfd_reloc_code_real_type code; | |
2721 | { | |
2722 | if (code > BFD_RELOC_UNUSED) | |
2723 | return 0; | |
2724 | return bfd_reloc_code_real_names[(int)code]; | |
2725 | } | |
2726 | ||
2727 | /* | |
2728 | INTERNAL_FUNCTION | |
2729 | bfd_generic_relax_section | |
2730 | ||
2731 | SYNOPSIS | |
2732 | boolean bfd_generic_relax_section | |
2733 | (bfd *abfd, | |
2734 | asection *section, | |
2735 | struct bfd_link_info *, | |
2736 | boolean *); | |
2737 | ||
2738 | DESCRIPTION | |
2739 | Provides default handling for relaxing for back ends which | |
2740 | don't do relaxing -- i.e., does nothing. | |
2741 | */ | |
2742 | ||
2743 | /*ARGSUSED*/ | |
2744 | boolean | |
2745 | bfd_generic_relax_section (abfd, section, link_info, again) | |
7442e600 ILT |
2746 | bfd *abfd ATTRIBUTE_UNUSED; |
2747 | asection *section ATTRIBUTE_UNUSED; | |
2748 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED; | |
252b5132 RH |
2749 | boolean *again; |
2750 | { | |
2751 | *again = false; | |
2752 | return true; | |
2753 | } | |
2754 | ||
2755 | /* | |
2756 | INTERNAL_FUNCTION | |
2757 | bfd_generic_gc_sections | |
2758 | ||
2759 | SYNOPSIS | |
2760 | boolean bfd_generic_gc_sections | |
2761 | (bfd *, struct bfd_link_info *); | |
2762 | ||
2763 | DESCRIPTION | |
2764 | Provides default handling for relaxing for back ends which | |
2765 | don't do section gc -- i.e., does nothing. | |
2766 | */ | |
2767 | ||
2768 | /*ARGSUSED*/ | |
2769 | boolean | |
2770 | bfd_generic_gc_sections (abfd, link_info) | |
7442e600 ILT |
2771 | bfd *abfd ATTRIBUTE_UNUSED; |
2772 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED; | |
252b5132 RH |
2773 | { |
2774 | return true; | |
2775 | } | |
2776 | ||
2777 | /* | |
2778 | INTERNAL_FUNCTION | |
2779 | bfd_generic_get_relocated_section_contents | |
2780 | ||
2781 | SYNOPSIS | |
2782 | bfd_byte * | |
2783 | bfd_generic_get_relocated_section_contents (bfd *abfd, | |
2784 | struct bfd_link_info *link_info, | |
2785 | struct bfd_link_order *link_order, | |
2786 | bfd_byte *data, | |
2787 | boolean relocateable, | |
2788 | asymbol **symbols); | |
2789 | ||
2790 | DESCRIPTION | |
2791 | Provides default handling of relocation effort for back ends | |
2792 | which can't be bothered to do it efficiently. | |
2793 | ||
2794 | */ | |
2795 | ||
2796 | bfd_byte * | |
2797 | bfd_generic_get_relocated_section_contents (abfd, link_info, link_order, data, | |
2798 | relocateable, symbols) | |
2799 | bfd *abfd; | |
2800 | struct bfd_link_info *link_info; | |
2801 | struct bfd_link_order *link_order; | |
2802 | bfd_byte *data; | |
2803 | boolean relocateable; | |
2804 | asymbol **symbols; | |
2805 | { | |
2806 | /* Get enough memory to hold the stuff */ | |
2807 | bfd *input_bfd = link_order->u.indirect.section->owner; | |
2808 | asection *input_section = link_order->u.indirect.section; | |
2809 | ||
2810 | long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section); | |
2811 | arelent **reloc_vector = NULL; | |
2812 | long reloc_count; | |
2813 | ||
2814 | if (reloc_size < 0) | |
2815 | goto error_return; | |
2816 | ||
2817 | reloc_vector = (arelent **) bfd_malloc ((size_t) reloc_size); | |
2818 | if (reloc_vector == NULL && reloc_size != 0) | |
2819 | goto error_return; | |
2820 | ||
2821 | /* read in the section */ | |
2822 | if (!bfd_get_section_contents (input_bfd, | |
2823 | input_section, | |
2824 | (PTR) data, | |
2825 | 0, | |
2826 | input_section->_raw_size)) | |
2827 | goto error_return; | |
2828 | ||
2829 | /* We're not relaxing the section, so just copy the size info */ | |
2830 | input_section->_cooked_size = input_section->_raw_size; | |
2831 | input_section->reloc_done = true; | |
2832 | ||
2833 | reloc_count = bfd_canonicalize_reloc (input_bfd, | |
2834 | input_section, | |
2835 | reloc_vector, | |
2836 | symbols); | |
2837 | if (reloc_count < 0) | |
2838 | goto error_return; | |
2839 | ||
2840 | if (reloc_count > 0) | |
2841 | { | |
2842 | arelent **parent; | |
2843 | for (parent = reloc_vector; *parent != (arelent *) NULL; | |
2844 | parent++) | |
2845 | { | |
2846 | char *error_message = (char *) NULL; | |
2847 | bfd_reloc_status_type r = | |
2848 | bfd_perform_relocation (input_bfd, | |
2849 | *parent, | |
2850 | (PTR) data, | |
2851 | input_section, | |
2852 | relocateable ? abfd : (bfd *) NULL, | |
2853 | &error_message); | |
2854 | ||
2855 | if (relocateable) | |
2856 | { | |
2857 | asection *os = input_section->output_section; | |
2858 | ||
2859 | /* A partial link, so keep the relocs */ | |
2860 | os->orelocation[os->reloc_count] = *parent; | |
2861 | os->reloc_count++; | |
2862 | } | |
2863 | ||
2864 | if (r != bfd_reloc_ok) | |
2865 | { | |
2866 | switch (r) | |
2867 | { | |
2868 | case bfd_reloc_undefined: | |
2869 | if (!((*link_info->callbacks->undefined_symbol) | |
2870 | (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr), | |
2871 | input_bfd, input_section, (*parent)->address))) | |
2872 | goto error_return; | |
2873 | break; | |
2874 | case bfd_reloc_dangerous: | |
2875 | BFD_ASSERT (error_message != (char *) NULL); | |
2876 | if (!((*link_info->callbacks->reloc_dangerous) | |
2877 | (link_info, error_message, input_bfd, input_section, | |
2878 | (*parent)->address))) | |
2879 | goto error_return; | |
2880 | break; | |
2881 | case bfd_reloc_overflow: | |
2882 | if (!((*link_info->callbacks->reloc_overflow) | |
2883 | (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr), | |
2884 | (*parent)->howto->name, (*parent)->addend, | |
2885 | input_bfd, input_section, (*parent)->address))) | |
2886 | goto error_return; | |
2887 | break; | |
2888 | case bfd_reloc_outofrange: | |
2889 | default: | |
2890 | abort (); | |
2891 | break; | |
2892 | } | |
2893 | ||
2894 | } | |
2895 | } | |
2896 | } | |
2897 | if (reloc_vector != NULL) | |
2898 | free (reloc_vector); | |
2899 | return data; | |
2900 | ||
2901 | error_return: | |
2902 | if (reloc_vector != NULL) | |
2903 | free (reloc_vector); | |
2904 | return NULL; | |
2905 | } |