]>
Commit | Line | Data |
---|---|---|
c618de01 | 1 | /* BFD support for handling relocation entries. |
65cab589 | 2 | Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc. |
c618de01 SC |
3 | Written by Cygnus Support. |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
0cda46cf SC |
21 | /* |
22 | SECTION | |
23 | Relocations | |
985fca12 | 24 | |
0cda46cf SC |
25 | BFD maintains relocations in much the same was as it maintains |
26 | symbols; they are left alone until required, then read in | |
27 | en-mass and traslated into an internal form. There is a common | |
28 | routine <<bfd_perform_relocation>> which acts upon the | |
29 | canonical form to to the actual fixup. | |
985fca12 | 30 | |
0cda46cf SC |
31 | Note that relocations are maintained on a per section basis, |
32 | whilst symbols are maintained on a per BFD basis. | |
985fca12 | 33 | |
0cda46cf SC |
34 | All a back end has to do to fit the BFD interface is to create |
35 | as many <<struct reloc_cache_entry>> as there are relocations | |
65cab589 | 36 | in a particular section, and fill in the right bits: |
985fca12 SC |
37 | |
38 | @menu | |
e98e6ec1 SC |
39 | @* typedef arelent:: |
40 | @* howto manager:: | |
985fca12 SC |
41 | @end menu |
42 | ||
43 | */ | |
985fca12 | 44 | #include "bfd.h" |
0cda46cf | 45 | #include "sysdep.h" |
985fca12 | 46 | #include "libbfd.h" |
e98e6ec1 | 47 | #include "seclet.h" |
c26d7d17 SC |
48 | /* |
49 | DOCDD | |
e98e6ec1 SC |
50 | INODE |
51 | typedef arelent, howto manager, Relocations, Relocations | |
985fca12 | 52 | |
0cda46cf SC |
53 | SUBSECTION |
54 | typedef arelent | |
985fca12 | 55 | |
e98e6ec1 | 56 | This is the structure of a relocation entry: |
985fca12 | 57 | |
e98e6ec1 SC |
58 | CODE_FRAGMENT |
59 | . | |
60 | .typedef enum bfd_reloc_status | |
61 | .{ | |
62 | . {* No errors detected *} | |
0cda46cf | 63 | . bfd_reloc_ok, |
e98e6ec1 SC |
64 | . |
65 | . {* The relocation was performed, but there was an overflow. *} | |
0cda46cf | 66 | . bfd_reloc_overflow, |
e98e6ec1 | 67 | . |
65cab589 | 68 | . {* The address to relocate was not within the section supplied. *} |
0cda46cf | 69 | . bfd_reloc_outofrange, |
e98e6ec1 SC |
70 | . |
71 | . {* Used by special functions *} | |
0cda46cf | 72 | . bfd_reloc_continue, |
e98e6ec1 SC |
73 | . |
74 | . {* Unused *} | |
0cda46cf | 75 | . bfd_reloc_notsupported, |
e98e6ec1 | 76 | . |
65cab589 | 77 | . {* Unsupported relocation size requested. *} |
0cda46cf | 78 | . bfd_reloc_other, |
e98e6ec1 | 79 | . |
65cab589 | 80 | . {* The symbol to relocate against was undefined. *} |
0cda46cf | 81 | . bfd_reloc_undefined, |
e98e6ec1 SC |
82 | . |
83 | . {* The relocation was performed, but may not be ok - presently | |
84 | . generated only when linking i960 coff files with i960 b.out | |
85 | . symbols. *} | |
0cda46cf | 86 | . bfd_reloc_dangerous |
e98e6ec1 | 87 | . } |
0cda46cf | 88 | . bfd_reloc_status_type; |
e98e6ec1 SC |
89 | . |
90 | . | |
0cda46cf SC |
91 | .typedef struct reloc_cache_entry |
92 | .{ | |
e98e6ec1 SC |
93 | . {* A pointer into the canonical table of pointers *} |
94 | . struct symbol_cache_entry **sym_ptr_ptr; | |
95 | . | |
96 | . {* offset in section *} | |
65cab589 | 97 | . bfd_size_type address; |
e98e6ec1 SC |
98 | . |
99 | . {* addend for relocation value *} | |
100 | . bfd_vma addend; | |
101 | . | |
102 | . {* Pointer to how to perform the required relocation *} | |
103 | . CONST struct reloc_howto_struct *howto; | |
104 | . | |
105 | .} arelent; | |
985fca12 | 106 | |
e98e6ec1 | 107 | */ |
985fca12 | 108 | |
e98e6ec1 SC |
109 | /* |
110 | DESCRIPTION | |
985fca12 | 111 | |
e98e6ec1 | 112 | Here is a description of each of the fields within a relent: |
985fca12 | 113 | |
e98e6ec1 | 114 | o sym_ptr_ptr |
985fca12 | 115 | |
e98e6ec1 SC |
116 | The symbol table pointer points to a pointer to the symbol |
117 | associated with the relocation request. This would naturally | |
118 | be the pointer into the table returned by the back end's | |
119 | get_symtab action. @xref{Symbols}. The symbol is referenced | |
120 | through a pointer to a pointer so that tools like the linker | |
121 | can fix up all the symbols of the same name by modifying only | |
122 | one pointer. The relocation routine looks in the symbol and | |
123 | uses the base of the section the symbol is attached to and the | |
124 | value of the symbol as the initial relocation offset. If the | |
125 | symbol pointer is zero, then the section provided is looked up. | |
985fca12 | 126 | |
e98e6ec1 | 127 | o address |
985fca12 | 128 | |
e98e6ec1 SC |
129 | The address field gives the offset in bytes from the base of |
130 | the section data which owns the relocation record to the first | |
131 | byte of relocatable information. The actual data relocated | |
132 | will be relative to this point - for example, a relocation | |
133 | type which modifies the bottom two bytes of a four byte word | |
134 | would not touch the first byte pointed to in a big endian | |
c26d7d17 SC |
135 | world. |
136 | ||
137 | o addend | |
138 | ||
139 | The addend is a value provided by the back end to be added (!) | |
140 | to the relocation offset. Its interpretation is dependent upon | |
141 | the howto. For example, on the 68k the code: | |
985fca12 | 142 | |
985fca12 | 143 | |
e98e6ec1 SC |
144 | | char foo[]; |
145 | | main() | |
146 | | { | |
147 | | return foo[0x12345678]; | |
148 | | } | |
985fca12 | 149 | |
e98e6ec1 | 150 | Could be compiled into: |
985fca12 | 151 | |
e98e6ec1 SC |
152 | | linkw fp,#-4 |
153 | | moveb @@#12345678,d0 | |
154 | | extbl d0 | |
155 | | unlk fp | |
156 | | rts | |
985fca12 | 157 | |
985fca12 | 158 | |
e98e6ec1 SC |
159 | This could create a reloc pointing to foo, but leave the |
160 | offset in the data (something like) | |
0cda46cf | 161 | |
985fca12 | 162 | |
e98e6ec1 SC |
163 | |RELOCATION RECORDS FOR [.text]: |
164 | |offset type value | |
165 | |00000006 32 _foo | |
166 | | | |
167 | |00000000 4e56 fffc ; linkw fp,#-4 | |
168 | |00000004 1039 1234 5678 ; moveb @@#12345678,d0 | |
169 | |0000000a 49c0 ; extbl d0 | |
170 | |0000000c 4e5e ; unlk fp | |
171 | |0000000e 4e75 ; rts | |
0cda46cf | 172 | |
985fca12 | 173 | |
e98e6ec1 SC |
174 | Using coff and an 88k, some instructions don't have enough |
175 | space in them to represent the full address range, and | |
176 | pointers have to be loaded in two parts. So you'd get something like: | |
0cda46cf | 177 | |
985fca12 | 178 | |
e98e6ec1 SC |
179 | | or.u r13,r0,hi16(_foo+0x12345678) |
180 | | ld.b r2,r13,lo16(_foo+0x12345678) | |
181 | | jmp r1 | |
985fca12 | 182 | |
985fca12 | 183 | |
65cab589 | 184 | This should create two relocs, both pointing to _foo, and with |
e98e6ec1 | 185 | 0x12340000 in their addend field. The data would consist of: |
0cda46cf | 186 | |
985fca12 | 187 | |
e98e6ec1 SC |
188 | |RELOCATION RECORDS FOR [.text]: |
189 | |offset type value | |
190 | |00000002 HVRT16 _foo+0x12340000 | |
191 | |00000006 LVRT16 _foo+0x12340000 | |
985fca12 | 192 | |
e98e6ec1 SC |
193 | |00000000 5da05678 ; or.u r13,r0,0x5678 |
194 | |00000004 1c4d5678 ; ld.b r2,r13,0x5678 | |
195 | |00000008 f400c001 ; jmp r1 | |
985fca12 | 196 | |
0cda46cf | 197 | |
e98e6ec1 SC |
198 | The relocation routine digs out the value from the data, adds |
199 | it to the addend to get the original offset and then adds the | |
200 | value of _foo. Note that all 32 bits have to be kept around | |
201 | somewhere, to cope with carry from bit 15 to bit 16. | |
985fca12 | 202 | |
65cab589 | 203 | One further example is the sparc and the a.out format. The |
e98e6ec1 SC |
204 | sparc has a similar problem to the 88k, in that some |
205 | instructions don't have room for an entire offset, but on the | |
206 | sparc the parts are created odd sized lumps. The designers of | |
207 | the a.out format chose not to use the data within the section | |
208 | for storing part of the offset; all the offset is kept within | |
209 | the reloc. Any thing in the data should be ignored. | |
0cda46cf | 210 | |
e98e6ec1 SC |
211 | | save %sp,-112,%sp |
212 | | sethi %hi(_foo+0x12345678),%g2 | |
213 | | ldsb [%g2+%lo(_foo+0x12345678)],%i0 | |
214 | | ret | |
215 | | restore | |
0cda46cf | 216 | |
e98e6ec1 SC |
217 | Both relocs contains a pointer to foo, and the offsets would |
218 | contain junk. | |
985fca12 | 219 | |
0cda46cf | 220 | |
e98e6ec1 SC |
221 | |RELOCATION RECORDS FOR [.text]: |
222 | |offset type value | |
223 | |00000004 HI22 _foo+0x12345678 | |
224 | |00000008 LO10 _foo+0x12345678 | |
225 | ||
226 | |00000000 9de3bf90 ; save %sp,-112,%sp | |
227 | |00000004 05000000 ; sethi %hi(_foo+0),%g2 | |
228 | |00000008 f048a000 ; ldsb [%g2+%lo(_foo+0)],%i0 | |
229 | |0000000c 81c7e008 ; ret | |
230 | |00000010 81e80000 ; restore | |
231 | ||
0cda46cf | 232 | |
e98e6ec1 SC |
233 | o howto |
234 | ||
235 | The howto field can be imagined as a | |
236 | relocation instruction. It is a pointer to a struct which | |
237 | contains information on what to do with all the other | |
238 | information in the reloc record and data section. A back end | |
239 | would normally have a relocation instruction set and turn | |
240 | relocations into pointers to the correct structure on input - | |
241 | but it would be possible to create each howto field on demand. | |
242 | ||
985fca12 SC |
243 | */ |
244 | ||
245 | ||
0cda46cf SC |
246 | /* |
247 | SUBSUBSECTION | |
e98e6ec1 | 248 | <<reloc_howto_type>> |
985fca12 | 249 | |
e98e6ec1 SC |
250 | The <<reloc_howto_type>> is a structure which contains all the |
251 | information that BFD needs to know to tie up a back end's data. | |
985fca12 | 252 | |
e98e6ec1 | 253 | CODE_FRAGMENT |
5022aea5 | 254 | .struct symbol_cache_entry; {* Forward declaration *} |
e98e6ec1 | 255 | . |
0cda46cf SC |
256 | .typedef CONST struct reloc_howto_struct |
257 | .{ | |
e98e6ec1 SC |
258 | . {* The type field has mainly a documetary use - the back end can |
259 | . to what it wants with it, though the normally the back end's | |
260 | . external idea of what a reloc number would be would be stored | |
261 | . in this field. For example, the a PC relative word relocation | |
262 | . in a coff environment would have the type 023 - because that's | |
263 | . what the outside world calls a R_PCRWORD reloc. *} | |
0cda46cf | 264 | . unsigned int type; |
e98e6ec1 SC |
265 | . |
266 | . {* The value the final relocation is shifted right by. This drops | |
267 | . unwanted data from the relocation. *} | |
0cda46cf | 268 | . unsigned int rightshift; |
e98e6ec1 SC |
269 | . |
270 | . {* The size of the item to be relocated - 0, is one byte, 1 is 2 | |
65cab589 DM |
271 | . bytes, 2 is four bytes. A negative value indicates that the |
272 | . result is to be subtracted from the data. *} | |
c26d7d17 | 273 | . int size; |
e98e6ec1 | 274 | . |
65cab589 | 275 | . {* Now obsolete? But m68k-coff still uses it... *} |
0cda46cf | 276 | . unsigned int bitsize; |
e98e6ec1 SC |
277 | . |
278 | . {* Notes that the relocation is relative to the location in the | |
279 | . data section of the addend. The relocation function will | |
280 | . subtract from the relocation value the address of the location | |
281 | . being relocated. *} | |
0cda46cf | 282 | . boolean pc_relative; |
e98e6ec1 | 283 | . |
0cda46cf | 284 | . unsigned int bitpos; |
e98e6ec1 SC |
285 | . |
286 | . {* Now obsolete *} | |
0cda46cf | 287 | . boolean absolute; |
e98e6ec1 SC |
288 | . |
289 | . {* Causes the relocation routine to return an error if overflow | |
290 | . is detected when relocating. *} | |
0cda46cf | 291 | . boolean complain_on_overflow; |
e98e6ec1 SC |
292 | . |
293 | . {* If this field is non null, then the supplied function is | |
294 | . called rather than the normal function. This allows really | |
65cab589 | 295 | . strange relocation methods to be accomodated (e.g., i960 callj |
e98e6ec1 | 296 | . instructions). *} |
fefb4b30 JG |
297 | . bfd_reloc_status_type (*special_function) |
298 | . PARAMS ((bfd *abfd, | |
5022aea5 SC |
299 | . arelent *reloc_entry, |
300 | . struct symbol_cache_entry *symbol, | |
301 | . PTR data, | |
8070f29d | 302 | . asection *input_section, |
fefb4b30 | 303 | . bfd *output_bfd)); |
e98e6ec1 SC |
304 | . |
305 | . {* The textual name of the relocation type. *} | |
0cda46cf | 306 | . char *name; |
e98e6ec1 SC |
307 | . |
308 | . {* When performing a partial link, some formats must modify the | |
309 | . relocations rather than the data - this flag signals this.*} | |
0cda46cf | 310 | . boolean partial_inplace; |
e98e6ec1 SC |
311 | . |
312 | . {* The src_mask is used to select what parts of the read in data | |
65cab589 | 313 | . are to be used in the relocation sum. E.g., if this was an 8 bit |
e98e6ec1 SC |
314 | . bit of data which we read and relocated, this would be |
315 | . 0x000000ff. When we have relocs which have an addend, such as | |
316 | . sun4 extended relocs, the value in the offset part of a | |
317 | . relocating field is garbage so we never use it. In this case | |
318 | . the mask would be 0x00000000. *} | |
65cab589 | 319 | . bfd_vma src_mask; |
e98e6ec1 SC |
320 | . |
321 | . {* The dst_mask is what parts of the instruction are replaced | |
322 | . into the instruction. In most cases src_mask == dst_mask, | |
323 | . except in the above special case, where dst_mask would be | |
324 | . 0x000000ff, and src_mask would be 0x00000000. *} | |
65cab589 | 325 | . bfd_vma dst_mask; |
e98e6ec1 SC |
326 | . |
327 | . {* When some formats create PC relative instructions, they leave | |
328 | . the value of the pc of the place being relocated in the offset | |
329 | . slot of the instruction, so that a PC relative relocation can | |
65cab589 | 330 | . be made just by adding in an ordinary offset (e.g., sun3 a.out). |
e98e6ec1 | 331 | . Some formats leave the displacement part of an instruction |
65cab589 | 332 | . empty (e.g., m88k bcs), this flag signals the fact.*} |
0cda46cf | 333 | . boolean pcrel_offset; |
e98e6ec1 | 334 | . |
0cda46cf | 335 | .} reloc_howto_type; |
985fca12 | 336 | |
0cda46cf | 337 | */ |
985fca12 | 338 | |
0cda46cf SC |
339 | /* |
340 | FUNCTION | |
e98e6ec1 SC |
341 | the HOWTO macro |
342 | ||
0cda46cf SC |
343 | DESCRIPTION |
344 | The HOWTO define is horrible and will go away. | |
345 | ||
346 | ||
347 | .#define HOWTO(C, R,S,B, P, BI, ABS, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \ | |
348 | . {(unsigned)C,R,S,B, P, BI, ABS,O,SF,NAME,INPLACE,MASKSRC,MASKDST,PC} | |
349 | ||
350 | DESCRIPTION | |
351 | And will be replaced with the totally magic way. But for the | |
352 | moment, we are compatible, so do it this way.. | |
353 | ||
354 | ||
355 | .#define NEWHOWTO( FUNCTION, NAME,SIZE,REL,IN) HOWTO(0,0,SIZE,0,REL,0,false,false,FUNCTION, NAME,false,0,0,IN) | |
356 | . | |
357 | DESCRIPTION | |
358 | Helper routine to turn a symbol into a relocation value. | |
359 | ||
e98e6ec1 SC |
360 | .#define HOWTO_PREPARE(relocation, symbol) \ |
361 | . { \ | |
362 | . if (symbol != (asymbol *)NULL) { \ | |
65cab589 | 363 | . if (bfd_is_com_section (symbol->section)) { \ |
e98e6ec1 SC |
364 | . relocation = 0; \ |
365 | . } \ | |
366 | . else { \ | |
367 | . relocation = symbol->value; \ | |
368 | . } \ | |
369 | . } \ | |
370 | .} | |
985fca12 SC |
371 | |
372 | */ | |
373 | ||
0cda46cf SC |
374 | /* |
375 | TYPEDEF | |
376 | reloc_chain | |
985fca12 | 377 | |
0cda46cf | 378 | DESCRIPTION |
985fca12 | 379 | |
0cda46cf | 380 | How relocs are tied together |
985fca12 | 381 | |
0cda46cf SC |
382 | .typedef unsigned char bfd_byte; |
383 | . | |
384 | .typedef struct relent_chain { | |
385 | . arelent relent; | |
386 | . struct relent_chain *next; | |
387 | .} arelent_chain; | |
985fca12 SC |
388 | |
389 | */ | |
390 | ||
391 | ||
392 | ||
0cda46cf SC |
393 | /* |
394 | FUNCTION | |
395 | bfd_perform_relocation | |
396 | ||
e98e6ec1 SC |
397 | SYNOPSIS |
398 | bfd_reloc_status_type | |
399 | bfd_perform_relocation | |
400 | (bfd * abfd, | |
401 | arelent *reloc_entry, | |
402 | PTR data, | |
403 | asection *input_section, | |
404 | bfd *output_bfd); | |
405 | ||
0cda46cf SC |
406 | DESCRIPTION |
407 | If an output_bfd is supplied to this function the generated | |
408 | image will be relocatable, the relocations are copied to the | |
409 | output file after they have been changed to reflect the new | |
410 | state of the world. There are two ways of reflecting the | |
411 | results of partial linkage in an output file; by modifying the | |
412 | output data in place, and by modifying the relocation record. | |
65cab589 | 413 | Some native formats (e.g., basic a.out and basic coff) have no |
0cda46cf SC |
414 | way of specifying an addend in the relocation type, so the |
415 | addend has to go in the output data. This is no big deal | |
416 | since in these formats the output data slot will always be big | |
417 | enough for the addend. Complex reloc types with addends were | |
418 | invented to solve just this problem. | |
419 | ||
985fca12 SC |
420 | */ |
421 | ||
422 | ||
0cda46cf | 423 | bfd_reloc_status_type |
985fca12 SC |
424 | DEFUN(bfd_perform_relocation,(abfd, |
425 | reloc_entry, | |
426 | data, | |
427 | input_section, | |
428 | output_bfd), | |
429 | bfd *abfd AND | |
430 | arelent *reloc_entry AND | |
431 | PTR data AND | |
432 | asection *input_section AND | |
433 | bfd *output_bfd) | |
434 | { | |
435 | bfd_vma relocation; | |
0cda46cf | 436 | bfd_reloc_status_type flag = bfd_reloc_ok; |
65cab589 | 437 | bfd_size_type addr = reloc_entry->address ; |
985fca12 SC |
438 | bfd_vma output_base = 0; |
439 | reloc_howto_type *howto = reloc_entry->howto; | |
e98e6ec1 SC |
440 | asection *reloc_target_output_section ; |
441 | ||
985fca12 SC |
442 | asymbol *symbol; |
443 | ||
e98e6ec1 | 444 | symbol = *( reloc_entry->sym_ptr_ptr); |
5022aea5 SC |
445 | if ((symbol->section == &bfd_abs_section) |
446 | && output_bfd != (bfd *)NULL) | |
58acdbd7 KR |
447 | { |
448 | reloc_entry->address += input_section->output_offset; | |
449 | return bfd_reloc_ok; | |
450 | } | |
451 | ||
452 | if ((symbol->section == &bfd_und_section) && output_bfd == (bfd *)NULL) | |
5022aea5 | 453 | flag = bfd_reloc_undefined; |
985fca12 | 454 | |
58acdbd7 KR |
455 | /* If there is a function supplied to handle this relocation type, |
456 | call it. It'll return `bfd_reloc_continue' if further processing | |
457 | can be done. */ | |
458 | if (howto->special_function) | |
459 | { | |
460 | bfd_reloc_status_type cont; | |
461 | cont = howto->special_function (abfd, reloc_entry, symbol, data, | |
462 | input_section, output_bfd); | |
463 | if (cont != bfd_reloc_continue) | |
464 | return cont; | |
465 | } | |
985fca12 | 466 | |
58acdbd7 KR |
467 | /* Is the address of the relocation really within the section? */ |
468 | if (reloc_entry->address > input_section->_cooked_size) | |
469 | return bfd_reloc_outofrange; | |
985fca12 | 470 | |
58acdbd7 KR |
471 | /* Work out which section the relocation is targetted at and the |
472 | initial relocation command value. */ | |
473 | ||
474 | /* Get symbol value. (Common symbols are special.) */ | |
475 | if (bfd_is_com_section (symbol->section)) | |
5022aea5 | 476 | relocation = 0; |
58acdbd7 | 477 | else |
5022aea5 | 478 | relocation = symbol->value; |
985fca12 | 479 | |
985fca12 | 480 | |
e98e6ec1 | 481 | reloc_target_output_section = symbol->section->output_section; |
985fca12 | 482 | |
58acdbd7 KR |
483 | /* Convert input-section-relative symbol value to absolute. */ |
484 | if (output_bfd && howto->partial_inplace==false) | |
5022aea5 | 485 | output_base = 0; |
58acdbd7 | 486 | else |
5022aea5 | 487 | output_base = reloc_target_output_section->vma; |
985fca12 | 488 | |
65cab589 | 489 | relocation += output_base + symbol->section->output_offset; |
985fca12 | 490 | |
58acdbd7 | 491 | /* Add in supplied addend. */ |
65cab589 | 492 | relocation += reloc_entry->addend; |
985fca12 | 493 | |
985fca12 | 494 | if (howto->pc_relative == true) |
58acdbd7 KR |
495 | { |
496 | /* Anything which started out as pc relative should end up that | |
497 | way too. | |
985fca12 | 498 | |
58acdbd7 KR |
499 | There are two ways we can see a pcrel instruction. Sometimes |
500 | the pcrel displacement has been partially calculated, it | |
501 | includes the distance from the start of the section to the | |
502 | instruction in it (e.g., sun3), and sometimes the field is | |
503 | totally blank - e.g., m88kbcs. */ | |
985fca12 | 504 | |
58acdbd7 KR |
505 | relocation -= |
506 | input_section->output_section->vma + input_section->output_offset; | |
507 | ||
508 | if (howto->pcrel_offset == true) | |
509 | relocation -= reloc_entry->address; | |
5022aea5 | 510 | } |
e98e6ec1 | 511 | |
c26d7d17 | 512 | if (output_bfd!= (bfd *)NULL) |
5022aea5 | 513 | { |
58acdbd7 KR |
514 | if ( howto->partial_inplace == false) |
515 | { | |
516 | /* This is a partial relocation, and we want to apply the relocation | |
517 | to the reloc entry rather than the raw data. Modify the reloc | |
518 | inplace to reflect what we now know. */ | |
519 | reloc_entry->addend = relocation; | |
520 | reloc_entry->address += input_section->output_offset; | |
521 | return flag; | |
522 | } | |
c26d7d17 | 523 | else |
58acdbd7 KR |
524 | { |
525 | /* This is a partial relocation, but inplace, so modify the | |
526 | reloc record a bit. | |
527 | ||
528 | If we've relocated with a symbol with a section, change | |
529 | into a ref to the section belonging to the symbol. */ | |
530 | ||
531 | reloc_entry->address += input_section->output_offset; | |
532 | ||
533 | /* WTF?? */ | |
534 | if (abfd->xvec->flavour == bfd_target_coff_flavour) | |
535 | { | |
536 | relocation -= reloc_entry->addend; | |
537 | reloc_entry->addend = 0; | |
538 | } | |
539 | else | |
540 | { | |
541 | reloc_entry->addend = relocation; | |
542 | } | |
543 | } | |
985fca12 | 544 | } |
e98e6ec1 | 545 | else |
58acdbd7 KR |
546 | { |
547 | reloc_entry->addend = 0; | |
548 | } | |
985fca12 | 549 | |
58acdbd7 KR |
550 | |
551 | if (howto->complain_on_overflow && howto->pc_relative) | |
65cab589 DM |
552 | { |
553 | /* We can detect overflow safely here */ | |
554 | ||
defcfb55 KR |
555 | bfd_signed_vma reloc_max = (1 << (howto->bitsize - 1))-1; |
556 | bfd_signed_vma reloc_min = ~(reloc_max); | |
65cab589 DM |
557 | |
558 | if ((bfd_signed_vma) relocation > reloc_max | |
559 | || (bfd_signed_vma) relocation < reloc_min) | |
560 | { | |
561 | flag = bfd_reloc_overflow; | |
562 | } | |
563 | } | |
564 | ||
985fca12 SC |
565 | /* |
566 | Either we are relocating all the way, or we don't want to apply | |
567 | the relocation to the reloc entry (probably because there isn't | |
568 | any room in the output format to describe addends to relocs) | |
569 | */ | |
570 | relocation >>= howto->rightshift; | |
571 | ||
572 | /* Shift everything up to where it's going to be used */ | |
573 | ||
574 | relocation <<= howto->bitpos; | |
575 | ||
576 | /* Wait for the day when all have the mask in them */ | |
577 | ||
578 | /* What we do: | |
579 | i instruction to be left alone | |
580 | o offset within instruction | |
581 | r relocation offset to apply | |
582 | S src mask | |
583 | D dst mask | |
584 | N ~dst mask | |
585 | A part 1 | |
586 | B part 2 | |
587 | R result | |
588 | ||
589 | Do this: | |
590 | i i i i i o o o o o from bfd_get<size> | |
591 | and S S S S S to get the size offset we want | |
592 | + r r r r r r r r r r to get the final value to place | |
593 | and D D D D D to chop to right size | |
594 | ----------------------- | |
595 | A A A A A | |
596 | And this: | |
597 | ... i i i i i o o o o o from bfd_get<size> | |
598 | and N N N N N get instruction | |
599 | ----------------------- | |
600 | ... B B B B B | |
601 | ||
602 | And then: | |
603 | B B B B B | |
604 | or A A A A A | |
605 | ----------------------- | |
606 | R R R R R R R R R R put into bfd_put<size> | |
607 | */ | |
608 | ||
609 | #define DOIT(x) \ | |
610 | x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask)) | |
611 | ||
e98e6ec1 | 612 | switch (howto->size) |
65cab589 DM |
613 | { |
614 | case 0: | |
615 | { | |
616 | char x = bfd_get_8(abfd, (char *)data + addr); | |
617 | DOIT(x); | |
618 | bfd_put_8(abfd,x, (unsigned char *) data + addr); | |
619 | } | |
620 | break; | |
621 | ||
622 | case 1: | |
623 | if (relocation) | |
624 | { | |
625 | short x = bfd_get_16(abfd, (bfd_byte *)data + addr); | |
626 | DOIT(x); | |
627 | bfd_put_16(abfd, x, (unsigned char *)data + addr); | |
628 | } | |
629 | break; | |
630 | case 2: | |
631 | if (relocation) | |
632 | { | |
633 | long x = bfd_get_32 (abfd, (bfd_byte *) data + addr); | |
634 | DOIT (x); | |
635 | bfd_put_32 (abfd, x, (bfd_byte *)data + addr); | |
636 | } | |
637 | break; | |
638 | case -2: | |
639 | { | |
640 | long x = bfd_get_32(abfd, (bfd_byte *) data + addr); | |
641 | relocation = -relocation; | |
642 | DOIT(x); | |
643 | bfd_put_32(abfd,x, (bfd_byte *)data + addr); | |
644 | } | |
645 | break; | |
646 | ||
647 | case 3: | |
648 | ||
649 | /* Do nothing */ | |
650 | break; | |
651 | default: | |
652 | return bfd_reloc_other; | |
653 | } | |
985fca12 SC |
654 | |
655 | return flag; | |
656 | } | |
c618de01 SC |
657 | |
658 | ||
2cf44d7b | 659 | |
0cda46cf | 660 | /* |
c26d7d17 | 661 | DOCDD |
e98e6ec1 SC |
662 | INODE |
663 | howto manager, , typedef arelent, Relocations | |
664 | ||
0cda46cf SC |
665 | SECTION |
666 | The howto manager | |
2cf44d7b | 667 | |
0cda46cf SC |
668 | When an application wants to create a relocation, but doesn't |
669 | know what the target machine might call it, it can find out by | |
670 | using this bit of code. | |
2cf44d7b | 671 | |
0cda46cf | 672 | */ |
2cf44d7b | 673 | |
0cda46cf SC |
674 | /* |
675 | TYPEDEF | |
676 | bfd_reloc_code_type | |
2cf44d7b | 677 | |
0cda46cf SC |
678 | DESCRIPTION |
679 | The insides of a reloc code | |
680 | ||
e98e6ec1 SC |
681 | CODE_FRAGMENT |
682 | . | |
683 | .typedef enum bfd_reloc_code_real | |
c26d7d17 | 684 | . |
e98e6ec1 | 685 | .{ |
defcfb55 KR |
686 | . {* 64 bits wide, simple reloc *} |
687 | . BFD_RELOC_64, | |
688 | . {* 64 bits, PC-relative *} | |
689 | . BFD_RELOC_64_PCREL, | |
690 | . | |
691 | . {* 32 bits wide, simple reloc *} | |
692 | . BFD_RELOC_32, | |
693 | . {* 32 bits, PC-relative *} | |
694 | . BFD_RELOC_32_PCREL, | |
695 | . | |
e98e6ec1 SC |
696 | . {* 16 bits wide, simple reloc *} |
697 | . BFD_RELOC_16, | |
defcfb55 KR |
698 | . {* 16 bits, PC-relative *} |
699 | . BFD_RELOC_16_PCREL, | |
e98e6ec1 SC |
700 | . |
701 | . {* 8 bits wide, simple *} | |
0cda46cf | 702 | . BFD_RELOC_8, |
e98e6ec1 | 703 | . {* 8 bits wide, pc relative *} |
0cda46cf | 704 | . BFD_RELOC_8_PCREL, |
defcfb55 KR |
705 | . {* 8 bits wide, but used to form an address like 0xffnn *} |
706 | . BFD_RELOC_8_FFnn, | |
e98e6ec1 SC |
707 | . |
708 | . {* The type of reloc used to build a contructor table - at the | |
709 | . moment probably a 32 bit wide abs address, but the cpu can | |
710 | . choose. *} | |
711 | . | |
8070f29d KR |
712 | . BFD_RELOC_CTOR, |
713 | . | |
8070f29d KR |
714 | . {* High 22 bits of 32-bit value; simple reloc. *} |
715 | . BFD_RELOC_HI22, | |
716 | . {* Low 10 bits. *} | |
717 | . BFD_RELOC_LO10, | |
718 | . | |
719 | . {* Reloc types used for i960/b.out. *} | |
720 | . BFD_RELOC_24_PCREL, | |
721 | . BFD_RELOC_I960_CALLJ, | |
722 | . | |
8070f29d KR |
723 | . {* 32-bit pc-relative, shifted right 2 bits (i.e., 30-bit |
724 | . word displacement, e.g. for SPARC) *} | |
725 | . BFD_RELOC_32_PCREL_S2, | |
726 | . | |
727 | . {* now for the sparc/elf codes *} | |
728 | . BFD_RELOC_NONE, {* actually used *} | |
729 | . BFD_RELOC_SPARC_WDISP22, | |
730 | . BFD_RELOC_SPARC22, | |
731 | . BFD_RELOC_SPARC13, | |
8070f29d KR |
732 | . BFD_RELOC_SPARC_GOT10, |
733 | . BFD_RELOC_SPARC_GOT13, | |
734 | . BFD_RELOC_SPARC_GOT22, | |
735 | . BFD_RELOC_SPARC_PC10, | |
736 | . BFD_RELOC_SPARC_PC22, | |
737 | . BFD_RELOC_SPARC_WPLT30, | |
738 | . BFD_RELOC_SPARC_COPY, | |
739 | . BFD_RELOC_SPARC_GLOB_DAT, | |
740 | . BFD_RELOC_SPARC_JMP_SLOT, | |
741 | . BFD_RELOC_SPARC_RELATIVE, | |
742 | . BFD_RELOC_SPARC_UA32, | |
743 | . | |
744 | . {* this one is a.out specific? *} | |
58acdbd7 | 745 | . BFD_RELOC_SPARC_BASE13, |
8070f29d KR |
746 | . BFD_RELOC_SPARC_BASE22, |
747 | . | |
defcfb55 | 748 | . {* start-sanitize-v9 *} |
defcfb55 KR |
749 | . BFD_RELOC_SPARC_10, |
750 | . BFD_RELOC_SPARC_11, | |
751 | .#define BFD_RELOC_SPARC_64 BFD_RELOC_64 | |
752 | . BFD_RELOC_SPARC_OLO10, | |
753 | . BFD_RELOC_SPARC_HH22, | |
754 | . BFD_RELOC_SPARC_HM10, | |
755 | . BFD_RELOC_SPARC_LM22, | |
756 | . BFD_RELOC_SPARC_PC_HH22, | |
757 | . BFD_RELOC_SPARC_PC_HM10, | |
758 | . BFD_RELOC_SPARC_PC_LM22, | |
759 | . BFD_RELOC_SPARC_WDISP16, | |
58acdbd7 | 760 | . BFD_RELOC_SPARC_WDISP19, |
defcfb55 KR |
761 | . BFD_RELOC_SPARC_GLOB_JMP, |
762 | . BFD_RELOC_SPARC_LO7, | |
763 | . {* end-sanitize-v9 *} | |
58acdbd7 | 764 | . |
65cab589 DM |
765 | . {* Bits 27..2 of the relocation address shifted right 2 bits; |
766 | . simple reloc otherwise. *} | |
767 | . BFD_RELOC_MIPS_JMP, | |
768 | . | |
769 | . {* signed 16-bit pc-relative, shifted right 2 bits (e.g. for MIPS) *} | |
770 | . BFD_RELOC_16_PCREL_S2, | |
771 | . | |
772 | . {* High 16 bits of 32-bit value; simple reloc. *} | |
773 | . BFD_RELOC_HI16, | |
774 | . {* High 16 bits of 32-bit value but the low 16 bits will be sign | |
775 | . extended and added to form the final result. If the low 16 | |
776 | . bits form a negative number, we need to add one to the high value | |
777 | . to compensate for the borrow when the low bits are added. *} | |
778 | . BFD_RELOC_HI16_S, | |
779 | . {* Low 16 bits. *} | |
780 | . BFD_RELOC_LO16, | |
781 | . | |
782 | . {* 16 bit relocation relative to the global pointer. *} | |
783 | . BFD_RELOC_MIPS_GPREL, | |
784 | . | |
785 | . {* These are, so far, specific to HPPA processors. I'm not sure that | |
786 | . some don't duplicate other reloc types, such as BFD_RELOC_32 and | |
787 | . _32_PCREL. Also, many more were in the list I got that don't | |
788 | . fit in well in the model BFD uses, so I've omitted them for now. | |
789 | . If we do make this reloc type get used for code that really does | |
790 | . implement the funky reloc types, they'll have to be added to this | |
791 | . list. *} | |
792 | . BFD_RELOC_HPPA_32, | |
793 | . BFD_RELOC_HPPA_11, | |
794 | . BFD_RELOC_HPPA_14, | |
795 | . BFD_RELOC_HPPA_17, | |
796 | . BFD_RELOC_HPPA_L21, | |
797 | . BFD_RELOC_HPPA_R11, | |
798 | . BFD_RELOC_HPPA_R14, | |
799 | . BFD_RELOC_HPPA_R17, | |
800 | . BFD_RELOC_HPPA_LS21, | |
801 | . BFD_RELOC_HPPA_RS11, | |
802 | . BFD_RELOC_HPPA_RS14, | |
803 | . BFD_RELOC_HPPA_RS17, | |
804 | . BFD_RELOC_HPPA_LD21, | |
805 | . BFD_RELOC_HPPA_RD11, | |
806 | . BFD_RELOC_HPPA_RD14, | |
807 | . BFD_RELOC_HPPA_RD17, | |
808 | . BFD_RELOC_HPPA_LR21, | |
809 | . BFD_RELOC_HPPA_RR14, | |
810 | . BFD_RELOC_HPPA_RR17, | |
811 | . BFD_RELOC_HPPA_GOTOFF_11, | |
812 | . BFD_RELOC_HPPA_GOTOFF_14, | |
813 | . BFD_RELOC_HPPA_GOTOFF_L21, | |
814 | . BFD_RELOC_HPPA_GOTOFF_R11, | |
815 | . BFD_RELOC_HPPA_GOTOFF_R14, | |
816 | . BFD_RELOC_HPPA_GOTOFF_LS21, | |
817 | . BFD_RELOC_HPPA_GOTOFF_RS11, | |
818 | . BFD_RELOC_HPPA_GOTOFF_RS14, | |
819 | . BFD_RELOC_HPPA_GOTOFF_LD21, | |
820 | . BFD_RELOC_HPPA_GOTOFF_RD11, | |
821 | . BFD_RELOC_HPPA_GOTOFF_RD14, | |
822 | . BFD_RELOC_HPPA_GOTOFF_LR21, | |
823 | . BFD_RELOC_HPPA_GOTOFF_RR14, | |
824 | . BFD_RELOC_HPPA_DLT_32, | |
825 | . BFD_RELOC_HPPA_DLT_11, | |
826 | . BFD_RELOC_HPPA_DLT_14, | |
827 | . BFD_RELOC_HPPA_DLT_L21, | |
828 | . BFD_RELOC_HPPA_DLT_R11, | |
829 | . BFD_RELOC_HPPA_DLT_R14, | |
830 | . BFD_RELOC_HPPA_ABS_CALL_11, | |
831 | . BFD_RELOC_HPPA_ABS_CALL_14, | |
832 | . BFD_RELOC_HPPA_ABS_CALL_17, | |
833 | . BFD_RELOC_HPPA_ABS_CALL_L21, | |
834 | . BFD_RELOC_HPPA_ABS_CALL_R11, | |
835 | . BFD_RELOC_HPPA_ABS_CALL_R14, | |
836 | . BFD_RELOC_HPPA_ABS_CALL_R17, | |
837 | . BFD_RELOC_HPPA_ABS_CALL_LS21, | |
838 | . BFD_RELOC_HPPA_ABS_CALL_RS11, | |
839 | . BFD_RELOC_HPPA_ABS_CALL_RS14, | |
840 | . BFD_RELOC_HPPA_ABS_CALL_RS17, | |
841 | . BFD_RELOC_HPPA_ABS_CALL_LD21, | |
842 | . BFD_RELOC_HPPA_ABS_CALL_RD11, | |
843 | . BFD_RELOC_HPPA_ABS_CALL_RD14, | |
844 | . BFD_RELOC_HPPA_ABS_CALL_RD17, | |
845 | . BFD_RELOC_HPPA_ABS_CALL_LR21, | |
846 | . BFD_RELOC_HPPA_ABS_CALL_RR14, | |
847 | . BFD_RELOC_HPPA_ABS_CALL_RR17, | |
848 | . BFD_RELOC_HPPA_PCREL_CALL_11, | |
849 | . BFD_RELOC_HPPA_PCREL_CALL_12, | |
850 | . BFD_RELOC_HPPA_PCREL_CALL_14, | |
851 | . BFD_RELOC_HPPA_PCREL_CALL_17, | |
852 | . BFD_RELOC_HPPA_PCREL_CALL_L21, | |
853 | . BFD_RELOC_HPPA_PCREL_CALL_R11, | |
854 | . BFD_RELOC_HPPA_PCREL_CALL_R14, | |
855 | . BFD_RELOC_HPPA_PCREL_CALL_R17, | |
856 | . BFD_RELOC_HPPA_PCREL_CALL_LS21, | |
857 | . BFD_RELOC_HPPA_PCREL_CALL_RS11, | |
858 | . BFD_RELOC_HPPA_PCREL_CALL_RS14, | |
859 | . BFD_RELOC_HPPA_PCREL_CALL_RS17, | |
860 | . BFD_RELOC_HPPA_PCREL_CALL_LD21, | |
861 | . BFD_RELOC_HPPA_PCREL_CALL_RD11, | |
862 | . BFD_RELOC_HPPA_PCREL_CALL_RD14, | |
863 | . BFD_RELOC_HPPA_PCREL_CALL_RD17, | |
864 | . BFD_RELOC_HPPA_PCREL_CALL_LR21, | |
865 | . BFD_RELOC_HPPA_PCREL_CALL_RR14, | |
866 | . BFD_RELOC_HPPA_PCREL_CALL_RR17, | |
867 | . BFD_RELOC_HPPA_PLABEL_32, | |
868 | . BFD_RELOC_HPPA_PLABEL_11, | |
869 | . BFD_RELOC_HPPA_PLABEL_14, | |
870 | . BFD_RELOC_HPPA_PLABEL_L21, | |
871 | . BFD_RELOC_HPPA_PLABEL_R11, | |
872 | . BFD_RELOC_HPPA_PLABEL_R14, | |
873 | . BFD_RELOC_HPPA_UNWIND_ENTRY, | |
874 | . BFD_RELOC_HPPA_UNWIND_ENTRIES, | |
875 | . | |
8070f29d KR |
876 | . {* this must be the highest numeric value *} |
877 | . BFD_RELOC_UNUSED | |
0cda46cf | 878 | . } bfd_reloc_code_real_type; |
2cf44d7b SC |
879 | */ |
880 | ||
881 | ||
882 | ||
0cda46cf SC |
883 | /* |
884 | SECTION | |
885 | bfd_reloc_type_lookup | |
2cf44d7b | 886 | |
e98e6ec1 SC |
887 | SYNOPSIS |
888 | CONST struct reloc_howto_struct * | |
3860075f | 889 | bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code); |
e98e6ec1 | 890 | |
0cda46cf SC |
891 | DESCRIPTION |
892 | This routine returns a pointer to a howto struct which when | |
893 | invoked, will perform the supplied relocation on data from the | |
894 | architecture noted. | |
2cf44d7b | 895 | |
2cf44d7b SC |
896 | */ |
897 | ||
898 | ||
899 | CONST struct reloc_howto_struct * | |
3860075f | 900 | DEFUN(bfd_reloc_type_lookup,(abfd, code), |
8070f29d | 901 | bfd *abfd AND |
3860075f | 902 | bfd_reloc_code_real_type code) |
2cf44d7b | 903 | { |
8070f29d | 904 | return BFD_SEND (abfd, reloc_type_lookup, (abfd, code)); |
2cf44d7b SC |
905 | } |
906 | ||
0cda46cf SC |
907 | static reloc_howto_type bfd_howto_32 = |
908 | HOWTO(0, 00,2,32,false,0,false,true,0,"VRT32", false,0xffffffff,0xffffffff,true); | |
2cf44d7b SC |
909 | |
910 | ||
0cda46cf | 911 | /* |
e98e6ec1 | 912 | INTERNAL_FUNCTION |
0cda46cf SC |
913 | bfd_default_reloc_type_lookup |
914 | ||
0cda46cf SC |
915 | SYNOPSIS |
916 | CONST struct reloc_howto_struct *bfd_default_reloc_type_lookup | |
65cab589 | 917 | (bfd *abfd AND |
3860075f | 918 | bfd_reloc_code_real_type code); |
0cda46cf | 919 | |
e98e6ec1 | 920 | DESCRIPTION |
65cab589 | 921 | Provides a default relocation lookup routine for any architecture. |
e98e6ec1 SC |
922 | |
923 | ||
0cda46cf | 924 | */ |
65cab589 | 925 | |
0cda46cf | 926 | CONST struct reloc_howto_struct * |
65cab589 DM |
927 | DEFUN(bfd_default_reloc_type_lookup, (abfd, code), |
928 | bfd *abfd AND | |
929 | bfd_reloc_code_real_type code) | |
0cda46cf | 930 | { |
65cab589 | 931 | switch (code) |
0cda46cf | 932 | { |
65cab589 DM |
933 | case BFD_RELOC_CTOR: |
934 | /* The type of reloc used in a ctor, which will be as wide as the | |
935 | address - so either a 64, 32, or 16 bitter.. */ | |
936 | switch (bfd_get_arch_info (abfd)->bits_per_address) { | |
937 | case 64: | |
938 | BFD_FAIL(); | |
939 | case 32: | |
940 | return &bfd_howto_32; | |
941 | case 16: | |
942 | BFD_FAIL(); | |
943 | default: | |
0cda46cf | 944 | BFD_FAIL(); |
65cab589 DM |
945 | } |
946 | default: | |
947 | BFD_FAIL(); | |
0cda46cf | 948 | } |
65cab589 | 949 | return (CONST struct reloc_howto_struct *)NULL; |
0cda46cf | 950 | } |
e98e6ec1 SC |
951 | |
952 | ||
d58b7049 SC |
953 | /* |
954 | INTERNAL_FUNCTION | |
955 | bfd_generic_relax_section | |
956 | ||
957 | SYNOPSIS | |
958 | boolean bfd_generic_relax_section | |
959 | (bfd *abfd, | |
960 | asection *section, | |
5022aea5 | 961 | asymbol **symbols); |
d58b7049 SC |
962 | |
963 | DESCRIPTION | |
964 | Provides default handling for relaxing for back ends which | |
8070f29d | 965 | don't do relaxing -- i.e., does nothing. |
d58b7049 SC |
966 | */ |
967 | ||
968 | boolean | |
5022aea5 | 969 | DEFUN(bfd_generic_relax_section,(abfd, section, symbols), |
d58b7049 SC |
970 | bfd *abfd AND |
971 | asection *section AND | |
5022aea5 | 972 | asymbol **symbols) |
d58b7049 SC |
973 | { |
974 | ||
975 | return false; | |
976 | ||
977 | } | |
e98e6ec1 | 978 | |
d58b7049 | 979 | |
e98e6ec1 SC |
980 | /* |
981 | INTERNAL_FUNCTION | |
982 | bfd_generic_get_relocated_section_contents | |
983 | ||
984 | SYNOPSIS | |
985 | bfd_byte * | |
65cab589 DM |
986 | bfd_generic_get_relocated_section_contents (bfd *abfd, |
987 | struct bfd_seclet *seclet, | |
988 | bfd_byte *data, | |
989 | boolean relocateable); | |
e98e6ec1 SC |
990 | |
991 | DESCRIPTION | |
992 | Provides default handling of relocation effort for back ends | |
993 | which can't be bothered to do it efficiently. | |
994 | ||
995 | */ | |
996 | ||
997 | bfd_byte * | |
65cab589 DM |
998 | DEFUN(bfd_generic_get_relocated_section_contents,(abfd, |
999 | seclet, | |
1000 | data, | |
1001 | relocateable), | |
e98e6ec1 | 1002 | bfd *abfd AND |
65cab589 DM |
1003 | struct bfd_seclet *seclet AND |
1004 | bfd_byte *data AND | |
1005 | boolean relocateable) | |
e98e6ec1 SC |
1006 | { |
1007 | extern bfd_error_vector_type bfd_error_vector; | |
e98e6ec1 SC |
1008 | |
1009 | /* Get enough memory to hold the stuff */ | |
1010 | bfd *input_bfd = seclet->u.indirect.section->owner; | |
1011 | asection *input_section = seclet->u.indirect.section; | |
1012 | ||
8070f29d | 1013 | |
e98e6ec1 | 1014 | |
defcfb55 | 1015 | size_t reloc_size = bfd_get_reloc_upper_bound(input_bfd, input_section); |
8070f29d | 1016 | arelent **reloc_vector = (arelent **) alloca(reloc_size); |
e98e6ec1 SC |
1017 | |
1018 | /* read in the section */ | |
1019 | bfd_get_section_contents(input_bfd, | |
1020 | input_section, | |
1021 | data, | |
1022 | 0, | |
1023 | input_section->_raw_size); | |
1024 | ||
1025 | /* We're not relaxing the section, so just copy the size info */ | |
1026 | input_section->_cooked_size = input_section->_raw_size; | |
1027 | input_section->reloc_done = true; | |
1028 | ||
1029 | ||
1030 | if (bfd_canonicalize_reloc(input_bfd, | |
1031 | input_section, | |
1032 | reloc_vector, | |
1033 | seclet->u.indirect.symbols) ) | |
1034 | { | |
1035 | arelent **parent; | |
1036 | for (parent = reloc_vector; * parent != (arelent *)NULL; | |
1037 | parent++) | |
1038 | { | |
1039 | bfd_reloc_status_type r= | |
1040 | bfd_perform_relocation(input_bfd, | |
1041 | *parent, | |
1042 | data, | |
65cab589 DM |
1043 | input_section, |
1044 | relocateable ? abfd : (bfd *) NULL); | |
e98e6ec1 | 1045 | |
65cab589 DM |
1046 | if (relocateable) |
1047 | { | |
1048 | asection *os = input_section->output_section; | |
1049 | ||
1050 | /* A partial link, so keep the relocs */ | |
1051 | os->orelocation[os->reloc_count] = *parent; | |
1052 | os->reloc_count++; | |
1053 | } | |
e98e6ec1 SC |
1054 | |
1055 | if (r != bfd_reloc_ok) | |
1056 | { | |
e98e6ec1 SC |
1057 | switch (r) |
1058 | { | |
1059 | case bfd_reloc_undefined: | |
1060 | bfd_error_vector.undefined_symbol(*parent, seclet); | |
1061 | break; | |
1062 | case bfd_reloc_dangerous: | |
1063 | bfd_error_vector.reloc_dangerous(*parent, seclet); | |
1064 | break; | |
1065 | case bfd_reloc_outofrange: | |
1066 | case bfd_reloc_overflow: | |
1067 | bfd_error_vector.reloc_value_truncated(*parent, seclet); | |
1068 | break; | |
1069 | default: | |
1070 | abort(); | |
1071 | break; | |
1072 | } | |
1073 | ||
1074 | } | |
1075 | } | |
1076 | } | |
1077 | ||
8070f29d | 1078 | |
e98e6ec1 SC |
1079 | return data; |
1080 | ||
1081 | ||
1082 | } |