from ralphc: recognize some mips variants
[deliverable/binutils-gdb.git] / bfd / reloc.c
CommitLineData
c618de01
SC
1/* BFD support for handling relocation entries.
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
3 Written by Cygnus Support.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
0cda46cf
SC
21/*
22SECTION
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
36 in a particuar 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/*
49DOCDD
e98e6ec1
SC
50INODE
51 typedef arelent, howto manager, Relocations, Relocations
985fca12 52
0cda46cf
SC
53SUBSECTION
54 typedef arelent
985fca12 55
e98e6ec1 56 This is the structure of a relocation entry:
985fca12 57
e98e6ec1
SC
58CODE_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
SC
67.
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
SC
76.
77. {* Unsupported relocation size requested. *}
0cda46cf 78. bfd_reloc_other,
e98e6ec1
SC
79.
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 *}
97. rawdata_offset address;
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/*
110DESCRIPTION
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
e98e6ec1
SC
184 This whould create two relocs, both pointing to _foo, and with
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
e98e6ec1
SC
203 On further example is the sparc and the a.out format. The
204 sparc has a similar problem to the 88k, in that some
205 instructions don't have room for an entire offset, but on the
206 sparc the parts are created 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/*
247SUBSUBSECTION
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 253CODE_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
c26d7d17
SC
271. bytes, 3 is four bytes. A -ve value indicates that the
272. result is to be subtracted from the data*}
273. int size;
e98e6ec1
SC
274.
275. {* Now obsolete *}
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
SC
283.
284. {* Now obsolete *}
0cda46cf 285. unsigned int bitpos;
e98e6ec1
SC
286.
287. {* Now obsolete *}
0cda46cf 288. boolean absolute;
e98e6ec1
SC
289.
290. {* Causes the relocation routine to return an error if overflow
291. is detected when relocating. *}
0cda46cf 292. boolean complain_on_overflow;
e98e6ec1
SC
293.
294. {* If this field is non null, then the supplied function is
295. called rather than the normal function. This allows really
296. strange relocation methods to be accomodated (eg, i960 callj
297. instructions). *}
fefb4b30
JG
298. bfd_reloc_status_type (*special_function)
299. PARAMS ((bfd *abfd,
5022aea5
SC
300. arelent *reloc_entry,
301. struct symbol_cache_entry *symbol,
302. PTR data,
8070f29d 303. asection *input_section,
fefb4b30 304. bfd *output_bfd));
e98e6ec1
SC
305.
306. {* The textual name of the relocation type. *}
0cda46cf 307. char *name;
e98e6ec1
SC
308.
309. {* When performing a partial link, some formats must modify the
310. relocations rather than the data - this flag signals this.*}
0cda46cf 311. boolean partial_inplace;
e98e6ec1
SC
312.
313. {* The src_mask is used to select what parts of the read in data
314. are to be used in the relocation sum. Eg, if this was an 8 bit
315. bit of data which we read and relocated, this would be
316. 0x000000ff. When we have relocs which have an addend, such as
317. sun4 extended relocs, the value in the offset part of a
318. relocating field is garbage so we never use it. In this case
319. the mask would be 0x00000000. *}
0cda46cf 320. bfd_word src_mask;
e98e6ec1
SC
321.
322. {* The dst_mask is what parts of the instruction are replaced
323. into the instruction. In most cases src_mask == dst_mask,
324. except in the above special case, where dst_mask would be
325. 0x000000ff, and src_mask would be 0x00000000. *}
0cda46cf 326. bfd_word dst_mask;
e98e6ec1
SC
327.
328. {* When some formats create PC relative instructions, they leave
329. the value of the pc of the place being relocated in the offset
330. slot of the instruction, so that a PC relative relocation can
331. be made just by adding in an ordinary offset (eg sun3 a.out).
332. Some formats leave the displacement part of an instruction
333. empty (eg m88k bcs), this flag signals the fact.*}
0cda46cf 334. boolean pcrel_offset;
e98e6ec1 335.
0cda46cf 336.} reloc_howto_type;
985fca12 337
0cda46cf 338*/
985fca12 339
0cda46cf
SC
340/*
341FUNCTION
e98e6ec1
SC
342 the HOWTO macro
343
0cda46cf
SC
344DESCRIPTION
345 The HOWTO define is horrible and will go away.
346
347
348.#define HOWTO(C, R,S,B, P, BI, ABS, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
349. {(unsigned)C,R,S,B, P, BI, ABS,O,SF,NAME,INPLACE,MASKSRC,MASKDST,PC}
350
351DESCRIPTION
352 And will be replaced with the totally magic way. But for the
353 moment, we are compatible, so do it this way..
354
355
356.#define NEWHOWTO( FUNCTION, NAME,SIZE,REL,IN) HOWTO(0,0,SIZE,0,REL,0,false,false,FUNCTION, NAME,false,0,0,IN)
357.
358DESCRIPTION
359 Helper routine to turn a symbol into a relocation value.
360
e98e6ec1
SC
361.#define HOWTO_PREPARE(relocation, symbol) \
362. { \
363. if (symbol != (asymbol *)NULL) { \
364. if (symbol->section == &bfd_com_section) { \
365. relocation = 0; \
366. } \
367. else { \
368. relocation = symbol->value; \
369. } \
370. } \
371.}
985fca12
SC
372
373*/
374
0cda46cf
SC
375/*
376TYPEDEF
377 reloc_chain
985fca12 378
0cda46cf 379DESCRIPTION
985fca12 380
0cda46cf 381 How relocs are tied together
985fca12 382
0cda46cf
SC
383.typedef unsigned char bfd_byte;
384.
385.typedef struct relent_chain {
386. arelent relent;
387. struct relent_chain *next;
388.} arelent_chain;
985fca12
SC
389
390*/
391
392
393
0cda46cf
SC
394/*
395FUNCTION
396 bfd_perform_relocation
397
e98e6ec1
SC
398SYNOPSIS
399 bfd_reloc_status_type
400 bfd_perform_relocation
401 (bfd * abfd,
402 arelent *reloc_entry,
403 PTR data,
404 asection *input_section,
405 bfd *output_bfd);
406
0cda46cf
SC
407DESCRIPTION
408 If an output_bfd is supplied to this function the generated
409 image will be relocatable, the relocations are copied to the
410 output file after they have been changed to reflect the new
411 state of the world. There are two ways of reflecting the
412 results of partial linkage in an output file; by modifying the
413 output data in place, and by modifying the relocation record.
414 Some native formats (eg basic a.out and basic coff) have no
415 way of specifying an addend in the relocation type, so the
416 addend has to go in the output data. This is no big deal
417 since in these formats the output data slot will always be big
418 enough for the addend. Complex reloc types with addends were
419 invented to solve just this problem.
420
985fca12
SC
421*/
422
423
0cda46cf 424bfd_reloc_status_type
985fca12
SC
425DEFUN(bfd_perform_relocation,(abfd,
426 reloc_entry,
427 data,
428 input_section,
429 output_bfd),
430 bfd *abfd AND
431 arelent *reloc_entry AND
432 PTR data AND
433 asection *input_section AND
434 bfd *output_bfd)
435{
436 bfd_vma relocation;
0cda46cf 437 bfd_reloc_status_type flag = bfd_reloc_ok;
985fca12
SC
438 bfd_vma addr = reloc_entry->address ;
439 bfd_vma output_base = 0;
440 reloc_howto_type *howto = reloc_entry->howto;
e98e6ec1
SC
441 asection *reloc_target_output_section ;
442
985fca12
SC
443 asymbol *symbol;
444
e98e6ec1 445 symbol = *( reloc_entry->sym_ptr_ptr);
5022aea5
SC
446 if ((symbol->section == &bfd_abs_section)
447 && output_bfd != (bfd *)NULL)
448 {
449 reloc_entry->address += input_section->output_offset;
450
451 return bfd_reloc_ok;
452
453 }
454
e98e6ec1 455 if ((symbol->section == &bfd_und_section) && output_bfd == (bfd *)NULL) {
5022aea5
SC
456 flag = bfd_reloc_undefined;
457 }
985fca12 458
8070f29d 459 if (howto->special_function) {
5022aea5
SC
460 bfd_reloc_status_type cont;
461 cont = howto->special_function(abfd,
462 reloc_entry,
463 symbol,
464 data,
8070f29d
KR
465 input_section,
466 output_bfd);
5022aea5
SC
467 if (cont != bfd_reloc_continue) return cont;
468 }
985fca12
SC
469
470 /*
471 Work out which section the relocation is targetted at and the
472 initial relocation command value.
473 */
474
475
e98e6ec1 476 if (symbol->section == &bfd_com_section) {
5022aea5
SC
477 relocation = 0;
478 }
e98e6ec1 479 else {
5022aea5
SC
480 relocation = symbol->value;
481 }
985fca12 482
985fca12 483
e98e6ec1 484 reloc_target_output_section = symbol->section->output_section;
985fca12 485
e98e6ec1 486 if (output_bfd && howto->partial_inplace==false) {
5022aea5
SC
487 output_base = 0;
488 }
e98e6ec1 489 else {
5022aea5 490 output_base = reloc_target_output_section->vma;
985fca12 491
5022aea5 492 }
985fca12 493
e98e6ec1
SC
494 relocation += output_base + symbol->section->output_offset;
495
985fca12
SC
496
497 relocation += reloc_entry->addend ;
498
499
e98e6ec1
SC
500 if(reloc_entry->address > input_section->_cooked_size)
501 {
502 return bfd_reloc_outofrange;
503 }
985fca12
SC
504
505
506 if (howto->pc_relative == true)
e98e6ec1
SC
507 {
508 /*
509 Anything which started out as pc relative should end up that
510 way too.
511
512 There are two ways we can see a pcrel instruction. Sometimes
513 the pcrel displacement has been partially calculated, it
514 includes the distance from the start of the section to the
515 instruction in it (eg sun3), and sometimes the field is
516 totally blank - eg m88kbcs.
517 */
985fca12
SC
518
519
e98e6ec1
SC
520 relocation -=
521 input_section->output_section->vma + input_section->output_offset;
985fca12 522
e98e6ec1 523 if (howto->pcrel_offset == true) {
5022aea5
SC
524 relocation -= reloc_entry->address;
525 }
985fca12 526
e98e6ec1
SC
527 }
528
c26d7d17
SC
529 if (output_bfd!= (bfd *)NULL)
530 {
531 if ( howto->partial_inplace == false)
532 {
5022aea5
SC
533 /*
534 This is a partial relocation, and we want to apply the relocation
535 to the reloc entry rather than the raw data. Modify the reloc
536 inplace to reflect what we now know.
537 */
538 reloc_entry->addend = relocation ;
539 reloc_entry->address += input_section->output_offset;
540 return flag;
541 }
542 else
543 {
544 /* This is a partial relocation, but inplace, so modify the
545 reloc record a bit.
546
547 If we've relocated with a symbol with a section, change
548 into a ref to the section belonging to the symbol
549 */
e98e6ec1 550
c26d7d17
SC
551 reloc_entry->address += input_section->output_offset;
552
553 if (abfd->xvec->flavour == bfd_target_coff_flavour)
554 {
555 relocation -= reloc_entry->addend;
556 reloc_entry->addend = 0;
557 }
558 else
559 {
560 reloc_entry->addend = relocation ;
561 }
985fca12 562 }
5022aea5 563 }
e98e6ec1
SC
564 else
565 {
5022aea5
SC
566 reloc_entry->addend = 0;
567 }
e98e6ec1 568
985fca12 569
985fca12
SC
570 /*
571 Either we are relocating all the way, or we don't want to apply
572 the relocation to the reloc entry (probably because there isn't
573 any room in the output format to describe addends to relocs)
574 */
575 relocation >>= howto->rightshift;
576
577 /* Shift everything up to where it's going to be used */
578
579 relocation <<= howto->bitpos;
580
581 /* Wait for the day when all have the mask in them */
582
583 /* What we do:
584 i instruction to be left alone
585 o offset within instruction
586 r relocation offset to apply
587 S src mask
588 D dst mask
589 N ~dst mask
590 A part 1
591 B part 2
592 R result
593
594 Do this:
595 i i i i i o o o o o from bfd_get<size>
596 and S S S S S to get the size offset we want
597 + r r r r r r r r r r to get the final value to place
598 and D D D D D to chop to right size
599 -----------------------
600 A A A A A
601 And this:
602 ... i i i i i o o o o o from bfd_get<size>
603 and N N N N N get instruction
604 -----------------------
605 ... B B B B B
606
607 And then:
608 B B B B B
609 or A A A A A
610 -----------------------
611 R R R R R R R R R R put into bfd_put<size>
612 */
613
614#define DOIT(x) \
615 x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask))
616
e98e6ec1
SC
617 switch (howto->size)
618 {
5022aea5
SC
619 case 0:
620 {
621 char x = bfd_get_8(abfd, (char *)data + addr);
622 DOIT(x);
623 bfd_put_8(abfd,x, (unsigned char *) data + addr);
624 }
e98e6ec1
SC
625 break;
626
5022aea5
SC
627 case 1:
628 {
629 short x = bfd_get_16(abfd, (bfd_byte *)data + addr);
630 DOIT(x);
631 bfd_put_16(abfd, x, (unsigned char *)data + addr);
632 }
e98e6ec1 633 break;
5022aea5
SC
634 case 2:
635 {
636 long x = bfd_get_32(abfd, (bfd_byte *) data + addr);
637 DOIT(x);
638 bfd_put_32(abfd,x, (bfd_byte *)data + addr);
639 }
e98e6ec1 640 break;
c26d7d17
SC
641 case -2:
642 {
643 long x = bfd_get_32(abfd, (bfd_byte *) data + addr);
644 relocation = -relocation;
645 DOIT(x);
646 bfd_put_32(abfd,x, (bfd_byte *)data + addr);
647 }
648 break;
649
5022aea5 650 case 3:
e98e6ec1
SC
651
652 /* Do nothing */
653 break;
5022aea5 654 default:
e98e6ec1
SC
655 return bfd_reloc_other;
656 }
985fca12
SC
657
658 return flag;
659}
c618de01
SC
660
661
2cf44d7b 662
0cda46cf 663/*
c26d7d17 664DOCDD
e98e6ec1
SC
665INODE
666 howto manager, , typedef arelent, Relocations
667
0cda46cf
SC
668SECTION
669 The howto manager
2cf44d7b 670
0cda46cf
SC
671 When an application wants to create a relocation, but doesn't
672 know what the target machine might call it, it can find out by
673 using this bit of code.
2cf44d7b 674
0cda46cf 675*/
2cf44d7b 676
0cda46cf
SC
677/*
678TYPEDEF
679 bfd_reloc_code_type
2cf44d7b 680
0cda46cf
SC
681DESCRIPTION
682 The insides of a reloc code
683
e98e6ec1
SC
684CODE_FRAGMENT
685.
686.typedef enum bfd_reloc_code_real
c26d7d17 687.
e98e6ec1
SC
688.{
689. {* 16 bits wide, simple reloc *}
690. BFD_RELOC_16,
691.
692. {* 8 bits wide, but used to form an address like 0xffnn *}
0cda46cf 693. BFD_RELOC_8_FFnn,
e98e6ec1
SC
694.
695. {* 8 bits wide, simple *}
0cda46cf 696. BFD_RELOC_8,
e98e6ec1
SC
697.
698. {* 8 bits wide, pc relative *}
0cda46cf 699. BFD_RELOC_8_PCREL,
e98e6ec1
SC
700.
701. {* The type of reloc used to build a contructor table - at the
702. moment probably a 32 bit wide abs address, but the cpu can
703. choose. *}
704.
8070f29d
KR
705. BFD_RELOC_CTOR,
706.
707. {* 32 bits wide, simple reloc *}
708. BFD_RELOC_32,
709. {* 32 bits, PC-relative *}
710. BFD_RELOC_32_PCREL,
711.
712. {* High 22 bits of 32-bit value; simple reloc. *}
713. BFD_RELOC_HI22,
714. {* Low 10 bits. *}
715. BFD_RELOC_LO10,
716.
717. {* Reloc types used for i960/b.out. *}
718. BFD_RELOC_24_PCREL,
719. BFD_RELOC_I960_CALLJ,
720.
721. BFD_RELOC_16_PCREL,
722. {* 32-bit pc-relative, shifted right 2 bits (i.e., 30-bit
723. word displacement, e.g. for SPARC) *}
724. BFD_RELOC_32_PCREL_S2,
725.
726. {* now for the sparc/elf codes *}
727. BFD_RELOC_NONE, {* actually used *}
728. BFD_RELOC_SPARC_WDISP22,
729. BFD_RELOC_SPARC22,
730. BFD_RELOC_SPARC13,
731. BFD_RELOC_SPARC_BASE13,
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? *}
745. BFD_RELOC_SPARC_BASE22,
746.
747. {* this must be the highest numeric value *}
748. BFD_RELOC_UNUSED
0cda46cf 749. } bfd_reloc_code_real_type;
2cf44d7b
SC
750*/
751
752
753
0cda46cf
SC
754/*
755SECTION
756 bfd_reloc_type_lookup
2cf44d7b 757
e98e6ec1
SC
758SYNOPSIS
759 CONST struct reloc_howto_struct *
3860075f 760 bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code);
e98e6ec1 761
0cda46cf
SC
762DESCRIPTION
763 This routine returns a pointer to a howto struct which when
764 invoked, will perform the supplied relocation on data from the
765 architecture noted.
2cf44d7b 766
2cf44d7b
SC
767*/
768
769
770CONST struct reloc_howto_struct *
3860075f 771DEFUN(bfd_reloc_type_lookup,(abfd, code),
8070f29d 772 bfd *abfd AND
3860075f 773 bfd_reloc_code_real_type code)
2cf44d7b 774{
8070f29d 775 return BFD_SEND (abfd, reloc_type_lookup, (abfd, code));
2cf44d7b
SC
776}
777
0cda46cf
SC
778static reloc_howto_type bfd_howto_32 =
779 HOWTO(0, 00,2,32,false,0,false,true,0,"VRT32", false,0xffffffff,0xffffffff,true);
2cf44d7b
SC
780
781
0cda46cf 782/*
e98e6ec1 783INTERNAL_FUNCTION
0cda46cf
SC
784 bfd_default_reloc_type_lookup
785
0cda46cf
SC
786SYNOPSIS
787 CONST struct reloc_howto_struct *bfd_default_reloc_type_lookup
788 (CONST struct bfd_arch_info *,
3860075f 789 bfd_reloc_code_real_type code);
0cda46cf 790
e98e6ec1
SC
791DESCRIPTION
792 Provides a default relocation lookuperer for any architectue
793
794
0cda46cf
SC
795*/
796CONST struct reloc_howto_struct *
797DEFUN(bfd_default_reloc_type_lookup,(arch, code),
798 CONST struct bfd_arch_info *arch AND
3860075f 799 bfd_reloc_code_real_type code)
0cda46cf
SC
800{
801 switch (code)
802 {
803 case BFD_RELOC_CTOR:
804 /* The type of reloc used in a ctor, which will be as wide as the
805 address - so either a 64, 32, or 16 bitter.. */
806 switch (arch->bits_per_address) {
807 case 64:
808 BFD_FAIL();
809 case 32:
810 return &bfd_howto_32;
811 case 16:
812 BFD_FAIL();
813 default:
814 BFD_FAIL();
815 }
816 default:
817 BFD_FAIL();
818 }
c26d7d17 819return (CONST struct reloc_howto_struct *)NULL;
0cda46cf 820}
e98e6ec1
SC
821
822
d58b7049
SC
823/*
824INTERNAL_FUNCTION
825 bfd_generic_relax_section
826
827SYNOPSIS
828 boolean bfd_generic_relax_section
829 (bfd *abfd,
830 asection *section,
5022aea5 831 asymbol **symbols);
d58b7049
SC
832
833DESCRIPTION
834 Provides default handling for relaxing for back ends which
8070f29d 835 don't do relaxing -- i.e., does nothing.
d58b7049
SC
836*/
837
838boolean
5022aea5 839DEFUN(bfd_generic_relax_section,(abfd, section, symbols),
d58b7049
SC
840 bfd *abfd AND
841 asection *section AND
5022aea5 842 asymbol **symbols)
d58b7049
SC
843{
844
845 return false;
846
847}
e98e6ec1 848
d58b7049 849
e98e6ec1
SC
850/*
851INTERNAL_FUNCTION
852 bfd_generic_get_relocated_section_contents
853
854SYNOPSIS
855 bfd_byte *
856 bfd_generic_get_relocated_section_contents(bfd *abfd,
8070f29d
KR
857 struct bfd_seclet_struct *seclet,
858 bfd_byte *data)
e98e6ec1
SC
859
860DESCRIPTION
861 Provides default handling of relocation effort for back ends
862 which can't be bothered to do it efficiently.
863
864*/
865
866bfd_byte *
8070f29d 867DEFUN(bfd_generic_get_relocated_section_contents,(abfd, seclet, data),
e98e6ec1 868 bfd *abfd AND
8070f29d
KR
869 struct bfd_seclet_struct *seclet AND
870 bfd_byte *data)
e98e6ec1
SC
871{
872 extern bfd_error_vector_type bfd_error_vector;
e98e6ec1
SC
873
874 /* Get enough memory to hold the stuff */
875 bfd *input_bfd = seclet->u.indirect.section->owner;
876 asection *input_section = seclet->u.indirect.section;
877
8070f29d 878
e98e6ec1
SC
879
880 bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd,
881 input_section);
8070f29d 882 arelent **reloc_vector = (arelent **) alloca(reloc_size);
e98e6ec1
SC
883
884 /* read in the section */
885 bfd_get_section_contents(input_bfd,
886 input_section,
887 data,
888 0,
889 input_section->_raw_size);
890
891/* We're not relaxing the section, so just copy the size info */
892 input_section->_cooked_size = input_section->_raw_size;
893 input_section->reloc_done = true;
894
895
896 if (bfd_canonicalize_reloc(input_bfd,
897 input_section,
898 reloc_vector,
899 seclet->u.indirect.symbols) )
900 {
901 arelent **parent;
902 for (parent = reloc_vector; * parent != (arelent *)NULL;
903 parent++)
904 {
905 bfd_reloc_status_type r=
906 bfd_perform_relocation(input_bfd,
907 *parent,
908 data,
909 input_section, 0);
910
911
912 if (r != bfd_reloc_ok)
913 {
e98e6ec1
SC
914 switch (r)
915 {
916 case bfd_reloc_undefined:
917 bfd_error_vector.undefined_symbol(*parent, seclet);
918 break;
919 case bfd_reloc_dangerous:
920 bfd_error_vector.reloc_dangerous(*parent, seclet);
921 break;
922 case bfd_reloc_outofrange:
923 case bfd_reloc_overflow:
924 bfd_error_vector.reloc_value_truncated(*parent, seclet);
925 break;
926 default:
927 abort();
928 break;
929 }
930
931 }
932 }
933 }
934
8070f29d 935
e98e6ec1
SC
936 return data;
937
938
939}
940
This page took 0.102831 seconds and 4 git commands to generate.