1 /* BFD back-end for PowerPC Microsoft Portable Executable files.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
4 Original version pieced together by Kim Knuttila (krk@cygnus.com)
6 There is nothing new under the sun. This file draws a lot on other
7 coff files, in particular, those for the rs/6000, alpha, mips, and
8 intel backends, and the PE work for the arm.
10 This file is part of BFD, the Binary File Descriptor library.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 - relocs generated by gas
29 - ld will link files, but they do not run.
30 - dlltool will not produce correct output in some .reloc cases, and will
31 not produce the right glue code for dll function calls.
40 #include "coff/powerpc.h"
41 #include "coff/internal.h"
49 #define BADMAG(x) PPCBADMAG(x)
53 /* The toc is a set of bfd_vma fields. We use the fact that valid */
54 /* addresses are even (i.e. the bit representing "1" is off) to allow */
55 /* us to encode a little extra information in the field */
56 /* - Unallocated addresses are intialized to 1. */
57 /* - Allocated addresses are even numbers. */
58 /* The first time we actually write a reference to the toc in the bfd, */
59 /* we want to record that fact in a fixup file (if it is asked for), so */
60 /* we keep track of whether or not an address has been written by marking */
61 /* the low order bit with a "1" upon writing */
63 #define SET_UNALLOCATED(x) ((x) = 1)
64 #define IS_UNALLOCATED(x) ((x) == 1)
66 #define IS_WRITTEN(x) ((x) & 1)
67 #define MARK_AS_WRITTEN(x) ((x) |= 1)
68 #define MAKE_ADDR_AGAIN(x) ((x) &= ~1)
71 /* Turn on this check if you suspect something amiss in the hash tables */
74 /* Need a 7 char string for an eye catcher */
77 #define HASH_CHECK_DCL char eye_catcher[8];
78 #define HASH_CHECK_INIT(ret) strcpy(ret->eye_catcher, EYE)
79 #define HASH_CHECK(addr) \
80 if (strcmp(addr->eye_catcher, EYE) != 0) \
83 "File %s, line %d, Hash check failure, bad eye %8s\n", \
84 __FILE__, __LINE__, addr->eye_catcher); \
91 #define HASH_CHECK_DCL
92 #define HASH_CHECK_INIT(ret)
93 #define HASH_CHECK(addr)
97 /* In order not to add an int to every hash table item for every coff
98 linker, we define our own hash table, derived from the coff one */
100 /* PE linker hash table entries. */
102 struct ppc_coff_link_hash_entry
104 struct coff_link_hash_entry root
; /* First entry, as required */
106 /* As we wonder around the relocs, we'll keep the assigned toc_offset
108 bfd_vma toc_offset
; /* Our addition, as required */
110 unsigned long int glue_insn
;
116 /* PE linker hash table. */
118 struct ppc_coff_link_hash_table
120 struct coff_link_hash_table root
; /* First entry, as required */
123 static struct bfd_hash_entry
*ppc_coff_link_hash_newfunc
124 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*,
127 /* Routine to create an entry in the link hash table. */
129 static struct bfd_hash_entry
*
130 ppc_coff_link_hash_newfunc (entry
, table
, string
)
131 struct bfd_hash_entry
*entry
;
132 struct bfd_hash_table
*table
;
135 struct ppc_coff_link_hash_entry
*ret
=
136 (struct ppc_coff_link_hash_entry
*) entry
;
138 /* Allocate the structure if it has not already been allocated by a
140 if (ret
== (struct ppc_coff_link_hash_entry
*) NULL
)
141 ret
= (struct ppc_coff_link_hash_entry
*)
142 bfd_hash_allocate (table
,
143 sizeof (struct ppc_coff_link_hash_entry
));
145 if (ret
== (struct ppc_coff_link_hash_entry
*) NULL
)
148 /* Call the allocation method of the superclass. */
149 ret
= ((struct ppc_coff_link_hash_entry
*)
150 _bfd_coff_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
155 /* Initialize the local fields. */
156 SET_UNALLOCATED(ret
->toc_offset
);
157 ret
->symbol_is_glue
= 0;
160 HASH_CHECK_INIT(ret
);
163 return (struct bfd_hash_entry
*) ret
;
166 /* Initialize a PE linker hash table. */
169 ppc_coff_link_hash_table_init (table
, abfd
, newfunc
)
170 struct ppc_coff_link_hash_table
*table
;
172 struct bfd_hash_entry
*(*newfunc
) PARAMS ((struct bfd_hash_entry
*,
173 struct bfd_hash_table
*,
176 return _bfd_coff_link_hash_table_init (&table
->root
, abfd
, newfunc
);
179 /* Create a PE linker hash table. */
181 static struct bfd_link_hash_table
*
182 ppc_coff_link_hash_table_create (abfd
)
185 struct ppc_coff_link_hash_table
*ret
;
187 ret
= ((struct ppc_coff_link_hash_table
*)
188 bfd_alloc (abfd
, sizeof (struct ppc_coff_link_hash_table
)));
191 if (! ppc_coff_link_hash_table_init (ret
, abfd
,
192 ppc_coff_link_hash_newfunc
))
194 bfd_release (abfd
, ret
);
195 return (struct bfd_link_hash_table
*) NULL
;
197 return &ret
->root
.root
;
200 /* Now, tailor coffcode.h to use our hash stuff */
202 #define coff_bfd_link_hash_table_create ppc_coff_link_hash_table_create
205 /* The nt loader points the toc register to &toc + 32768, in order to */
206 /* use the complete range of a 16-bit displacement. We have to adjust */
207 /* for this when we fix up loads displaced off the toc reg. */
208 #define TOC_LOAD_ADJUSTMENT (-32768)
209 #define TOC_SECTION_NAME ".private.toc"
211 /* The main body of code is in coffcode.h. */
213 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
215 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
216 from smaller values. Start with zero, widen, *then* decrement. */
217 #define MINUS_ONE (((bfd_vma)0) - 1)
219 /* these should definitely go in a header file somewhere... */
222 #define IMAGE_REL_PPC_ABSOLUTE 0x0000
225 #define IMAGE_REL_PPC_ADDR64 0x0001
228 #define IMAGE_REL_PPC_ADDR32 0x0002
230 /* 26-bit address, shifted left 2 (branch absolute) */
231 #define IMAGE_REL_PPC_ADDR24 0x0003
234 #define IMAGE_REL_PPC_ADDR16 0x0004
236 /* 16-bit address, shifted left 2 (load doubleword) */
237 #define IMAGE_REL_PPC_ADDR14 0x0005
239 /* 26-bit PC-relative offset, shifted left 2 (branch relative) */
240 #define IMAGE_REL_PPC_REL24 0x0006
242 /* 16-bit PC-relative offset, shifted left 2 (br cond relative) */
243 #define IMAGE_REL_PPC_REL14 0x0007
245 /* 16-bit offset from TOC base */
246 #define IMAGE_REL_PPC_TOCREL16 0x0008
248 /* 16-bit offset from TOC base, shifted left 2 (load doubleword) */
249 #define IMAGE_REL_PPC_TOCREL14 0x0009
251 /* 32-bit addr w/o image base */
252 #define IMAGE_REL_PPC_ADDR32NB 0x000A
254 /* va of containing section (as in an image sectionhdr) */
255 #define IMAGE_REL_PPC_SECREL 0x000B
257 /* sectionheader number */
258 #define IMAGE_REL_PPC_SECTION 0x000C
260 /* substitute TOC restore instruction iff symbol is glue code */
261 #define IMAGE_REL_PPC_IFGLUE 0x000D
263 /* symbol is glue code; virtual address is TOC restore instruction */
264 #define IMAGE_REL_PPC_IMGLUE 0x000E
266 /* va of containing section (limited to 16 bits) */
267 #define IMAGE_REL_PPC_SECREL16 0x000F
269 /* stuff to handle immediate data when the number of bits in the */
270 /* data is greater than the number of bits in the immediate field */
271 /* We need to do (usually) 32 bit arithmetic on 16 bit chunks */
272 #define IMAGE_REL_PPC_REFHI 0x0010
273 #define IMAGE_REL_PPC_REFLO 0x0011
274 #define IMAGE_REL_PPC_PAIR 0x0012
276 /* This is essentially the same as tocrel16, with TOCDEFN assumed */
277 #define IMAGE_REL_PPC_TOCREL16_DEFN 0x0013
279 /* Flag bits in IMAGE_RELOCATION.TYPE */
281 /* subtract reloc value rather than adding it */
282 #define IMAGE_REL_PPC_NEG 0x0100
284 /* fix branch prediction bit to predict branch taken */
285 #define IMAGE_REL_PPC_BRTAKEN 0x0200
287 /* fix branch prediction bit to predict branch not taken */
288 #define IMAGE_REL_PPC_BRNTAKEN 0x0400
290 /* toc slot defined in file (or, data in toc) */
291 #define IMAGE_REL_PPC_TOCDEFN 0x0800
293 /* masks to isolate above values in IMAGE_RELOCATION.Type */
294 #define IMAGE_REL_PPC_TYPEMASK 0x00FF
295 #define IMAGE_REL_PPC_FLAGMASK 0x0F00
297 #define EXTRACT_TYPE(x) ((x) & IMAGE_REL_PPC_TYPEMASK)
298 #define EXTRACT_FLAGS(x) ((x) & IMAGE_REL_PPC_FLAGMASK)
299 #define EXTRACT_JUNK(x) \
300 ((x) & ~(IMAGE_REL_PPC_TYPEMASK | IMAGE_REL_PPC_FLAGMASK))
303 /* static helper functions to make relocation work */
304 /* (Work In Progress) */
306 static bfd_reloc_status_type ppc_refhi_reloc
PARAMS ((bfd
*abfd
,
314 static bfd_reloc_status_type ppc_reflo_reloc
PARAMS ((bfd
*abfd
,
322 static bfd_reloc_status_type ppc_pair_reloc
PARAMS ((bfd
*abfd
,
331 static bfd_reloc_status_type ppc_toc16_reloc
PARAMS ((bfd
*abfd
,
340 static bfd_reloc_status_type ppc_addr32nb_reloc
PARAMS ((bfd
*abfd
,
348 static bfd_reloc_status_type ppc_section_reloc
PARAMS ((bfd
*abfd
,
356 static bfd_reloc_status_type ppc_secrel_reloc
PARAMS ((bfd
*abfd
,
364 static bfd_reloc_status_type ppc_imglue_reloc
PARAMS ((bfd
*abfd
,
374 static boolean in_reloc_p
PARAMS((bfd
*abfd
, reloc_howto_type
*howto
));
377 /* FIXME: It'll take a while to get through all of these. I only need a few to
378 get us started, so those I'll make sure work. Those marked FIXME are either
379 completely unverified or have a specific unknown marked in the comment */
381 /*---------------------------------------------------------------------------*/
383 /* Relocation entries for Windows/NT on PowerPC. */
385 /* From the document "" we find the following listed as used relocs: */
387 /* ABSOLUTE : The noop */
388 /* ADDR[64|32|16] : fields that hold addresses in data fields or the */
389 /* 16 bit displacement field on a load/store. */
390 /* ADDR[24|14] : fields that hold addresses in branch and cond */
391 /* branches. These represent [26|16] bit addresses. */
392 /* The low order 2 bits are preserved. */
393 /* REL[24|14] : branches relative to the Instruction Address */
394 /* register. These represent [26|16] bit addresses, */
395 /* as before. The instruction field will be zero, and */
396 /* the address of the SYM will be inserted at link time. */
397 /* TOCREL16 : 16 bit displacement field referring to a slot in */
399 /* TOCREL14 : 16 bit displacement field, similar to REL14 or ADDR14. */
400 /* ADDR32NB : 32 bit address relative to the virtual origin. */
401 /* (On the alpha, this is always a linker generated thunk)*/
402 /* (i.e. 32bit addr relative to the image base) */
403 /* SECREL : The value is relative to the start of the section */
404 /* containing the symbol. */
405 /* SECTION : access to the header containing the item. Supports the */
406 /* codeview debugger. */
408 /* In particular, note that the document does not indicate that the */
409 /* relocations listed in the header file are used. */
413 /*---------------------------------------------------------------------------*/
415 static reloc_howto_type ppc_coff_howto_table
[] =
417 /* IMAGE_REL_PPC_ABSOLUTE 0x0000 NOP */
419 HOWTO (IMAGE_REL_PPC_ABSOLUTE
, /* type */
421 0, /* size (0 = byte, 1 = short, 2 = long) */
423 false, /* pc_relative */
425 complain_overflow_dont
, /* dont complain_on_overflow */
426 0, /* special_function */
427 "ABSOLUTE", /* name */
428 false, /* partial_inplace */
431 false), /* pcrel_offset */
433 /* IMAGE_REL_PPC_ADDR64 0x0001 64-bit address */
435 HOWTO(IMAGE_REL_PPC_ADDR64
, /* type */
437 3, /* size (0 = byte, 1 = short, 2 = long) */
439 false, /* pc_relative */
441 complain_overflow_bitfield
, /* complain_on_overflow */
442 0, /* special_function */
444 true, /* partial_inplace */
445 MINUS_ONE
, /* src_mask */
446 MINUS_ONE
, /* dst_mask */
447 false), /* pcrel_offset */
449 /* IMAGE_REL_PPC_ADDR32 0x0002 32-bit address */
451 HOWTO (IMAGE_REL_PPC_ADDR32
, /* type */
453 2, /* size (0 = byte, 1 = short, 2 = long) */
455 false, /* pc_relative */
457 complain_overflow_bitfield
, /* complain_on_overflow */
458 0, /* special_function */
460 true, /* partial_inplace */
461 0xffffffff, /* src_mask */
462 0xffffffff, /* dst_mask */
463 false), /* pcrel_offset */
465 /* IMAGE_REL_PPC_ADDR24 0x0003 26-bit address, shifted left 2 (branch absolute) */
466 /* the LI field is in bit 6 through bit 29 is 24 bits, + 2 for the shift */
467 /* Of course, That's the IBM approved bit numbering, which is not what */
468 /* anyone else uses.... The li field is in bit 2 thru 25 */
470 HOWTO (IMAGE_REL_PPC_ADDR24
, /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 false, /* pc_relative */
476 complain_overflow_bitfield
, /* complain_on_overflow */
477 0, /* special_function */
479 true, /* partial_inplace */
480 0x07fffffc, /* src_mask */
481 0x07fffffc, /* dst_mask */
482 false), /* pcrel_offset */
484 /* IMAGE_REL_PPC_ADDR16 0x0004 16-bit address */
486 HOWTO (IMAGE_REL_PPC_ADDR16
, /* type */
488 1, /* size (0 = byte, 1 = short, 2 = long) */
490 false, /* pc_relative */
492 complain_overflow_signed
, /* complain_on_overflow */
493 0, /* special_function */
495 true, /* partial_inplace */
496 0xffff, /* src_mask */
497 0xffff, /* dst_mask */
498 false), /* pcrel_offset */
500 /* IMAGE_REL_PPC_ADDR14 0x0005 */
501 /* 16-bit address, shifted left 2 (load doubleword) */
502 /* FIXME: the mask is likely wrong, and the bit position may be as well */
504 HOWTO (IMAGE_REL_PPC_ADDR14
, /* type */
506 1, /* size (0 = byte, 1 = short, 2 = long) */
508 false, /* pc_relative */
510 complain_overflow_signed
, /* complain_on_overflow */
511 0, /* special_function */
513 true, /* partial_inplace */
514 0xffff, /* src_mask */
515 0xffff, /* dst_mask */
516 false), /* pcrel_offset */
518 /* IMAGE_REL_PPC_REL24 0x0006 */
519 /* 26-bit PC-relative offset, shifted left 2 (branch relative) */
521 HOWTO (IMAGE_REL_PPC_REL24
, /* type */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
525 true, /* pc_relative */
527 complain_overflow_signed
, /* complain_on_overflow */
528 0, /* special_function */
530 true, /* partial_inplace */
531 0x3fffffc, /* src_mask */
532 0x3fffffc, /* dst_mask */
533 false), /* pcrel_offset */
535 /* IMAGE_REL_PPC_REL14 0x0007 */
536 /* 16-bit PC-relative offset, shifted left 2 (br cond relative) */
537 /* FIXME: the mask is likely wrong, and the bit position may be as well */
538 /* FIXME: how does it know how far to shift? */
540 HOWTO (IMAGE_REL_PPC_ADDR14
, /* type */
542 1, /* size (0 = byte, 1 = short, 2 = long) */
544 false, /* pc_relative */
546 complain_overflow_signed
, /* complain_on_overflow */
547 0, /* special_function */
549 true, /* partial_inplace */
550 0xffff, /* src_mask */
551 0xffff, /* dst_mask */
552 true), /* pcrel_offset */
554 /* IMAGE_REL_PPC_TOCREL16 0x0008 */
555 /* 16-bit offset from TOC base */
557 HOWTO (IMAGE_REL_PPC_TOCREL16
,/* type */
559 1, /* size (0 = byte, 1 = short, 2 = long) */
561 false, /* pc_relative */
563 complain_overflow_dont
, /* complain_on_overflow */
564 ppc_toc16_reloc
, /* special_function */
565 "TOCREL16", /* name */
566 false, /* partial_inplace */
567 0xffff, /* src_mask */
568 0xffff, /* dst_mask */
569 false), /* pcrel_offset */
571 /* IMAGE_REL_PPC_TOCREL14 0x0009 */
572 /* 16-bit offset from TOC base, shifted left 2 (load doubleword) */
574 HOWTO (IMAGE_REL_PPC_TOCREL14
,/* type */
576 1, /* size (0 = byte, 1 = short, 2 = long) */
578 false, /* pc_relative */
580 complain_overflow_signed
, /* complain_on_overflow */
581 0, /* special_function */
582 "TOCREL14", /* name */
583 false, /* partial_inplace */
584 0xffff, /* src_mask */
585 0xffff, /* dst_mask */
586 false), /* pcrel_offset */
588 /* IMAGE_REL_PPC_ADDR32NB 0x000A */
589 /* 32-bit addr w/ image base */
591 HOWTO (IMAGE_REL_PPC_ADDR32NB
,/* type */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
595 false, /* pc_relative */
597 complain_overflow_signed
, /* complain_on_overflow */
598 0, /* special_function */
599 "ADDR32NB", /* name */
600 true, /* partial_inplace */
601 0xffffffff, /* src_mask */
602 0xffffffff, /* dst_mask */
603 false), /* pcrel_offset */
605 /* IMAGE_REL_PPC_SECREL 0x000B */
606 /* va of containing section (as in an image sectionhdr) */
608 HOWTO (IMAGE_REL_PPC_SECREL
,/* type */
610 2, /* size (0 = byte, 1 = short, 2 = long) */
612 false, /* pc_relative */
614 complain_overflow_signed
, /* complain_on_overflow */
615 ppc_secrel_reloc
, /* special_function */
617 true, /* partial_inplace */
618 0xffffffff, /* src_mask */
619 0xffffffff, /* dst_mask */
620 true), /* pcrel_offset */
622 /* IMAGE_REL_PPC_SECTION 0x000C */
623 /* sectionheader number */
625 HOWTO (IMAGE_REL_PPC_SECTION
,/* type */
627 2, /* size (0 = byte, 1 = short, 2 = long) */
629 false, /* pc_relative */
631 complain_overflow_signed
, /* complain_on_overflow */
632 ppc_section_reloc
, /* special_function */
633 "SECTION", /* name */
634 true, /* partial_inplace */
635 0xffffffff, /* src_mask */
636 0xffffffff, /* dst_mask */
637 true), /* pcrel_offset */
639 /* IMAGE_REL_PPC_IFGLUE 0x000D */
640 /* substitute TOC restore instruction iff symbol is glue code */
642 HOWTO (IMAGE_REL_PPC_IFGLUE
,/* type */
644 2, /* size (0 = byte, 1 = short, 2 = long) */
646 false, /* pc_relative */
648 complain_overflow_signed
, /* complain_on_overflow */
649 0, /* special_function */
651 true, /* partial_inplace */
652 0xffffffff, /* src_mask */
653 0xffffffff, /* dst_mask */
654 false), /* pcrel_offset */
656 /* IMAGE_REL_PPC_IMGLUE 0x000E */
657 /* symbol is glue code; virtual address is TOC restore instruction */
659 HOWTO (IMAGE_REL_PPC_IMGLUE
,/* type */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
663 false, /* pc_relative */
665 complain_overflow_dont
, /* complain_on_overflow */
666 ppc_imglue_reloc
, /* special_function */
668 false, /* partial_inplace */
669 0xffffffff, /* src_mask */
670 0xffffffff, /* dst_mask */
671 false), /* pcrel_offset */
673 /* IMAGE_REL_PPC_SECREL16 0x000F */
674 /* va of containing section (limited to 16 bits) */
676 HOWTO (IMAGE_REL_PPC_SECREL16
,/* type */
678 1, /* size (0 = byte, 1 = short, 2 = long) */
680 false, /* pc_relative */
682 complain_overflow_signed
, /* complain_on_overflow */
683 0, /* special_function */
684 "SECREL16", /* name */
685 true, /* partial_inplace */
686 0xffff, /* src_mask */
687 0xffff, /* dst_mask */
688 true), /* pcrel_offset */
690 /* IMAGE_REL_PPC_REFHI 0x0010 */
692 HOWTO (IMAGE_REL_PPC_REFHI
, /* type */
694 1, /* size (0 = byte, 1 = short, 2 = long) */
696 false, /* pc_relative */
698 complain_overflow_signed
, /* complain_on_overflow */
699 ppc_refhi_reloc
, /* special_function */
701 true, /* partial_inplace */
702 0xffffffff, /* src_mask */
703 0xffffffff, /* dst_mask */
704 false), /* pcrel_offset */
706 /* IMAGE_REL_PPC_REFLO 0x0011 */
708 HOWTO (IMAGE_REL_PPC_REFLO
, /* type */
710 1, /* size (0 = byte, 1 = short, 2 = long) */
712 false, /* pc_relative */
714 complain_overflow_signed
, /* complain_on_overflow */
715 ppc_refhi_reloc
, /* special_function */
717 true, /* partial_inplace */
718 0xffffffff, /* src_mask */
719 0xffffffff, /* dst_mask */
720 false), /* pcrel_offset */
722 /* IMAGE_REL_PPC_PAIR 0x0012 */
724 HOWTO (IMAGE_REL_PPC_PAIR
, /* type */
726 1, /* size (0 = byte, 1 = short, 2 = long) */
728 false, /* pc_relative */
730 complain_overflow_signed
, /* complain_on_overflow */
731 ppc_pair_reloc
, /* special_function */
733 true, /* partial_inplace */
734 0xffffffff, /* src_mask */
735 0xffffffff, /* dst_mask */
736 false), /* pcrel_offset */
738 /* IMAGE_REL_PPC_TOCREL16_DEFN 0x0013 */
739 /* 16-bit offset from TOC base, without causing a definition */
741 HOWTO ( (IMAGE_REL_PPC_TOCREL16
| IMAGE_REL_PPC_TOCDEFN
), /* type */
743 1, /* size (0 = byte, 1 = short, 2 = long) */
745 false, /* pc_relative */
747 complain_overflow_dont
, /* complain_on_overflow */
748 0, /* special_function */
749 "TOCREL16, TOCDEFN", /* name */
750 false, /* partial_inplace */
751 0xffff, /* src_mask */
752 0xffff, /* dst_mask */
753 false), /* pcrel_offset */
760 /* Some really cheezy macros that can be turned on to test stderr :-) */
769 fprintf(stderr,"Unimplemented Relocation -- %s\n",x); \
773 #define DUMP_RELOC(n,r) \
775 fprintf(stderr,"%s sym %d, addr %d, addend %d\n", \
776 n, (*(r->sym_ptr_ptr))->name, \
777 r->address, r->addend); \
780 /* Given a reloc name, n, and a pointer to an internal_reloc,
781 dump out interesting information on the contents
783 #define n_name _n._n_name
784 #define n_zeroes _n._n_n._n_zeroes
785 #define n_offset _n._n_n._n_offset
789 #define DUMP_RELOC2(n,r) \
791 fprintf(stderr,"%s sym %d, r_vaddr %d %s\n", \
792 n, r->r_symndx, r->r_vaddr,\
793 (((r->r_type) & IMAGE_REL_PPC_TOCDEFN) == 0) \
799 #define DUMP_RELOC(n,r)
800 #define DUMP_RELOC2(n,r)
805 /* toc construction and management routines */
806 extern bfd
* bfd_of_toc_owner
;
807 extern long int global_toc_size
;
809 extern long int import_table_size
;
810 extern long int first_thunk_address
;
811 extern long int thunk_size
;
829 struct list_ele
*next
;
831 enum ref_category cat
;
836 extern struct list_ele
*head
;
837 extern struct list_ele
*tail
;
840 record_toc(toc_section
, our_toc_offset
, cat
, name
)
841 asection
*toc_section
;
843 enum ref_category cat
;
846 /* add this entry to our toc addr-offset-name list */
848 t
= (struct list_ele
*) bfd_malloc (sizeof (struct list_ele
));
852 t
->offset
= our_toc_offset
;
855 t
->addr
= toc_section
->output_offset
+ our_toc_offset
;
869 #ifdef COFF_IMAGE_WITH_PE
871 /* record a toc offset against a symbol */
873 ppc_record_toc_entry(abfd
, info
, sec
, sym
, toc_kind
)
875 struct bfd_link_info
*info
;
878 enum toc_type toc_kind
;
880 struct ppc_coff_link_hash_entry
*h
;
887 h
= (struct ppc_coff_link_hash_entry
*) (obj_coff_sym_hashes (abfd
)[sym
]);
895 local_syms
= obj_coff_local_toc_table(abfd
);
899 /* allocate a table */
901 (int *) bfd_zalloc (abfd
,
902 obj_raw_syment_count(abfd
) * sizeof(int));
905 obj_coff_local_toc_table(abfd
) = local_syms
;
906 for (i
= 0; i
< obj_raw_syment_count(abfd
); ++i
)
908 SET_UNALLOCATED(local_syms
[i
]);
912 if (IS_UNALLOCATED(local_syms
[sym
]))
914 local_syms
[sym
] = global_toc_size
;
915 global_toc_size
+= 4;
917 /* The size must fit in a 16bit displacment */
918 if (global_toc_size
> 65535)
920 (*_bfd_error_handler
) ("TOC overflow");
921 bfd_set_error (bfd_error_file_too_big
);
928 name
= h
->root
.root
.root
.string
;
930 /* check to see if there's a toc slot allocated. If not, do it
931 here. It will be used in relocate_section */
932 if (IS_UNALLOCATED(h
->toc_offset
))
934 h
->toc_offset
= global_toc_size
;
935 global_toc_size
+= 4;
937 /* The size must fit in a 16bit displacment */
938 if (global_toc_size
>= 65535)
940 (*_bfd_error_handler
) ("TOC overflow");
941 bfd_set_error (bfd_error_file_too_big
);
950 /* record a toc offset against a symbol */
952 ppc_mark_symbol_as_glue(abfd
, sym
, rel
)
955 struct internal_reloc
*rel
;
957 struct ppc_coff_link_hash_entry
*h
;
959 h
= (struct ppc_coff_link_hash_entry
*) (obj_coff_sym_hashes (abfd
)[sym
]);
963 h
->symbol_is_glue
= 1;
964 h
->glue_insn
= bfd_get_32 (abfd
, (bfd_byte
*) &rel
->r_vaddr
);
969 #endif /* COFF_IMAGE_WITH_PE */
972 /* Return true if this relocation should
973 appear in the output .reloc section. */
975 static boolean
in_reloc_p(abfd
, howto
)
977 reloc_howto_type
*howto
;
980 (! howto
->pc_relative
)
981 && (howto
->type
!= IMAGE_REL_PPC_ADDR32NB
)
982 && (howto
->type
!= IMAGE_REL_PPC_TOCREL16
)
983 && (howto
->type
!= IMAGE_REL_PPC_IMGLUE
)
984 && (howto
->type
!= IMAGE_REL_PPC_IFGLUE
)
985 && (howto
->type
!= IMAGE_REL_PPC_SECREL
)
986 && (howto
->type
!= IMAGE_REL_PPC_SECTION
)
987 && (howto
->type
!= IMAGE_REL_PPC_SECREL16
)
988 && (howto
->type
!= IMAGE_REL_PPC_REFHI
)
989 && (howto
->type
!= IMAGE_REL_PPC_REFLO
)
990 && (howto
->type
!= IMAGE_REL_PPC_PAIR
)
991 && (howto
->type
!= IMAGE_REL_PPC_TOCREL16_DEFN
) ;
996 /* this function is in charge of performing all the ppc PE relocations */
997 /* Don't yet know if we want to do this this particular way ... (krk) */
998 /* FIXME: (it is not yet enabled) */
1000 static bfd_reloc_status_type
1001 pe_ppc_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1004 arelent
*reloc_entry
;
1007 asection
*input_section
;
1009 char **error_message
;
1011 /* the consth relocation comes in two parts, we have to remember
1012 the state between calls, in these variables */
1013 static boolean part1_consth_active
= false;
1014 static unsigned long part1_consth_value
;
1016 unsigned long sym_value
;
1017 unsigned short r_type
;
1018 unsigned long addr
= reloc_entry
->address
; /*+ input_section->vma*/
1020 r_type
= reloc_entry
->howto
->type
;
1024 /* Partial linking - do nothing */
1025 reloc_entry
->address
+= input_section
->output_offset
;
1026 return bfd_reloc_ok
;
1029 if (symbol_in
!= NULL
1030 && bfd_is_und_section (symbol_in
->section
))
1032 /* Keep the state machine happy in case we're called again */
1033 if (r_type
== IMAGE_REL_PPC_REFHI
)
1035 part1_consth_active
= true;
1036 part1_consth_value
= 0;
1038 return(bfd_reloc_undefined
);
1041 if ((part1_consth_active
) && (r_type
!= IMAGE_REL_PPC_PAIR
))
1043 part1_consth_active
= false;
1044 *error_message
= (char *) "Missing PAIR";
1045 return(bfd_reloc_dangerous
);
1049 sym_value
= get_symbol_value(symbol_in
);
1051 return(bfd_reloc_ok
);
1056 /* The reloc processing routine for the optimized COFF linker. */
1059 coff_ppc_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1060 contents
, relocs
, syms
, sections
)
1062 struct bfd_link_info
*info
;
1064 asection
*input_section
;
1066 struct internal_reloc
*relocs
;
1067 struct internal_syment
*syms
;
1068 asection
**sections
;
1070 struct internal_reloc
*rel
;
1071 struct internal_reloc
*relend
;
1074 asection
*toc_section
= 0;
1076 reloc_howto_type
*howto
= 0;
1078 /* If we are performing a relocateable link, we don't need to do a
1079 thing. The caller will take care of adjusting the reloc
1080 addresses and symbol indices. */
1081 if (info
->relocateable
)
1088 relend
= rel
+ input_section
->reloc_count
;
1089 for (; rel
< relend
; rel
++)
1092 struct ppc_coff_link_hash_entry
*h
;
1093 struct internal_syment
*sym
;
1097 bfd_reloc_status_type rstat
;
1100 unsigned short r_type
= EXTRACT_TYPE (rel
->r_type
);
1101 unsigned short r_flags
= EXTRACT_FLAGS(rel
->r_type
);
1103 symndx
= rel
->r_symndx
;
1104 loc
= contents
+ rel
->r_vaddr
- input_section
->vma
;
1106 /* FIXME: check bounds on r_type */
1107 howto
= ppc_coff_howto_table
+ r_type
;
1116 h
= (struct ppc_coff_link_hash_entry
*)
1117 (obj_coff_sym_hashes (input_bfd
)[symndx
]);
1123 sym
= syms
+ symndx
;
1126 if (r_type
== IMAGE_REL_PPC_IMGLUE
&& h
== 0)
1128 /* An IMGLUE reloc must have a name. Something is very wrong. */
1135 /* FIXME: PAIR unsupported in the following code */
1139 sec
= bfd_abs_section_ptr
;
1142 sec
= sections
[symndx
];
1143 val
= (sec
->output_section
->vma
1144 + sec
->output_offset
1153 if (h
->root
.root
.type
== bfd_link_hash_defined
1154 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1156 sec
= h
->root
.root
.u
.def
.section
;
1157 val
= (h
->root
.root
.u
.def
.value
1158 + sec
->output_section
->vma
1159 + sec
->output_offset
);
1163 if (! ((*info
->callbacks
->undefined_symbol
)
1164 (info
, h
->root
.root
.root
.string
, input_bfd
, input_section
,
1165 rel
->r_vaddr
- input_section
->vma
)))
1170 rstat
= bfd_reloc_ok
;
1172 /* Each case must do its own relocation, setting rstat appropriately */
1176 (*_bfd_error_handler
)
1177 ("%s: unsupported relocation type 0x%02x",
1178 bfd_get_filename (input_bfd
), r_type
);
1179 bfd_set_error (bfd_error_bad_value
);
1181 case IMAGE_REL_PPC_TOCREL16
:
1183 bfd_vma our_toc_offset
;
1186 DUMP_RELOC2(howto
->name
, rel
);
1188 if (toc_section
== 0)
1190 toc_section
= bfd_get_section_by_name (bfd_of_toc_owner
,
1193 if ( toc_section
== NULL
)
1195 /* There is no toc section. Something is very wrong. */
1201 * Amazing bit tricks present. As we may have seen earlier, we
1202 * use the 1 bit to tell us whether or not a toc offset has been
1203 * allocated. Now that they've all been allocated, we will use
1204 * the 1 bit to tell us if we've written this particular toc
1209 { /* it is a file local symbol */
1210 int *local_toc_table
;
1213 sym
= syms
+ symndx
;
1214 name
= sym
->_n
._n_name
;
1216 local_toc_table
= obj_coff_local_toc_table(input_bfd
);
1217 our_toc_offset
= local_toc_table
[symndx
];
1219 if (IS_WRITTEN(our_toc_offset
))
1221 /* if it has been written out, it is marked with the
1222 1 bit. Fix up our offset, but do not write it out
1225 MAKE_ADDR_AGAIN(our_toc_offset
);
1229 /* write out the toc entry */
1230 record_toc(toc_section
,
1235 bfd_put_32(output_bfd
,
1237 toc_section
->contents
+ our_toc_offset
);
1239 MARK_AS_WRITTEN(local_toc_table
[symndx
]);
1245 const char *name
= h
->root
.root
.root
.string
;
1246 our_toc_offset
= h
->toc_offset
;
1248 if ((r_flags
& IMAGE_REL_PPC_TOCDEFN
)
1249 == IMAGE_REL_PPC_TOCDEFN
)
1251 /* This is unbelievable cheese. Some knowledgable asm
1252 hacker has decided to use r2 as a base for loading
1253 a value. He/She does this by setting the tocdefn bit,
1254 and not supplying a toc definition. The behaviour is
1255 then to use the difference between the value of the
1256 symbol and the actual location of the toc as the toc
1259 In fact, what is usually happening is, because the
1260 Import Address Table is mapped immediately following
1261 the toc, some trippy library code trying for speed on
1262 dll linkage, takes advantage of that and considers
1263 the IAT to be part of the toc, thus saving a load.
1266 our_toc_offset
= val
-
1267 (toc_section
->output_section
->vma
+
1268 toc_section
->output_offset
);
1270 /* The size must still fit in a 16bit displacment */
1271 if (our_toc_offset
>= 65535)
1273 (*_bfd_error_handler
)
1274 ("%s: Relocation for %s of %x exceeds Toc size limit",
1275 bfd_get_filename (input_bfd
), name
, our_toc_offset
);
1276 bfd_set_error (bfd_error_bad_value
);
1280 record_toc(toc_section
, our_toc_offset
, pub
, strdup(name
));
1282 else if (IS_WRITTEN(our_toc_offset
))
1284 /* if it has been written out, it is marked with the
1285 1 bit. Fix up our offset, but do not write it out
1288 MAKE_ADDR_AGAIN(our_toc_offset
);
1292 record_toc(toc_section
, our_toc_offset
, pub
, strdup(name
));
1294 /* write out the toc entry */
1295 bfd_put_32(output_bfd
,
1297 toc_section
->contents
+ our_toc_offset
);
1299 MARK_AS_WRITTEN(h
->toc_offset
);
1300 /* The tricky part is that this is the address that */
1301 /* needs a .reloc entry for it */
1306 if (fixit
&& info
->base_file
)
1308 /* So if this is non pcrelative, and is referenced
1309 to a section or a common symbol, then it needs a reloc */
1311 /* relocation to a symbol in a section which
1312 isn't absolute - we output the address here
1315 bfd_vma addr
= toc_section
->output_section
->vma
1316 + toc_section
->output_offset
+ our_toc_offset
;
1318 if (coff_data(output_bfd
)->pe
)
1319 addr
-= pe_data(output_bfd
)->pe_opthdr
.ImageBase
;
1321 fwrite (&addr
, 1,4, (FILE *) info
->base_file
);
1325 /* FIXME: this test is conservative */
1326 if ( (r_flags
& IMAGE_REL_PPC_TOCDEFN
) != IMAGE_REL_PPC_TOCDEFN
&&
1327 our_toc_offset
> toc_section
->_raw_size
)
1329 (*_bfd_error_handler
)
1330 ("%s: Relocation exceeds allocated TOC (%x)",
1331 bfd_get_filename (input_bfd
),
1332 toc_section
->_raw_size
);
1333 bfd_set_error (bfd_error_bad_value
);
1337 /* Now we know the relocation for this toc reference */
1338 relocation
= our_toc_offset
+ TOC_LOAD_ADJUSTMENT
;
1339 rstat
= _bfd_relocate_contents (howto
,
1345 case IMAGE_REL_PPC_IFGLUE
:
1347 /* To solve this, we need to know whether or not the symbol */
1348 /* appearing on the call instruction is a glue function or not. */
1349 /* A glue function must announce itself via a IMGLUE reloc, and */
1350 /* the reloc contains the required toc restore instruction */
1353 const char *my_name
;
1354 DUMP_RELOC2(howto
->name
, rel
);
1358 my_name
= h
->root
.root
.root
.string
;
1359 if (h
->symbol_is_glue
== 1)
1361 x
= bfd_get_32(input_bfd
, loc
);
1362 bfd_put_32(input_bfd
, h
->glue_insn
, loc
);
1367 case IMAGE_REL_PPC_SECREL
:
1368 /* Unimplemented: codeview debugging information */
1369 /* For fast access to the header of the section
1370 containing the item. */
1372 case IMAGE_REL_PPC_SECTION
:
1373 /* Unimplemented: codeview debugging information */
1374 /* Is used to indicate that the value should be relative
1375 to the beginning of the section that contains the
1378 case IMAGE_REL_PPC_ABSOLUTE
:
1380 const char *my_name
;
1382 my_name
= (syms
+symndx
)->_n
._n_name
;
1385 my_name
= h
->root
.root
.root
.string
;
1389 "Warning: unsupported reloc %s <file %s, section %s>\n",
1391 bfd_get_filename(input_bfd
),
1392 input_section
->name
);
1394 fprintf(stderr
,"sym %ld (%s), r_vaddr %ld (%lx)\n",
1395 rel
->r_symndx
, my_name
, (long) rel
->r_vaddr
,
1396 (unsigned long) rel
->r_vaddr
);
1399 case IMAGE_REL_PPC_IMGLUE
:
1401 /* There is nothing to do now. This reloc was noted in the first
1402 pass over the relocs, and the glue instruction extracted */
1403 const char *my_name
;
1404 if (h
->symbol_is_glue
== 1)
1406 my_name
= h
->root
.root
.root
.string
;
1408 (*_bfd_error_handler
)
1409 ("%s: Out of order IMGLUE reloc for %s",
1410 bfd_get_filename (input_bfd
), my_name
);
1411 bfd_set_error (bfd_error_bad_value
);
1415 case IMAGE_REL_PPC_ADDR32NB
:
1417 struct coff_link_hash_entry
*myh
= 0;
1418 const char *name
= 0;
1419 DUMP_RELOC2(howto
->name
, rel
);
1421 if (strncmp(".idata$2",input_section
->name
,8) == 0 && first_thunk_address
== 0)
1423 /* set magic values */
1425 struct coff_link_hash_entry
*myh
= 0;
1426 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1428 false, false, true);
1429 first_thunk_address
= myh
->root
.u
.def
.value
+
1430 sec
->output_section
->vma
+
1431 sec
->output_offset
-
1432 pe_data(output_bfd
)->pe_opthdr
.ImageBase
;
1434 idata5offset
= myh
->root
.u
.def
.value
;
1435 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1437 false, false, true);
1439 thunk_size
= myh
->root
.u
.def
.value
- idata5offset
;
1440 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1442 false, false, true);
1443 import_table_size
= myh
->root
.u
.def
.value
;
1447 { /* it is a file local symbol */
1448 sym
= syms
+ symndx
;
1449 name
= sym
->_n
._n_name
;
1455 name
= h
->root
.root
.root
.string
;
1456 if (strcmp(".idata$2", name
) == 0)
1457 target
= "__idata2_magic__";
1458 else if (strcmp(".idata$4", name
) == 0)
1459 target
= "__idata4_magic__";
1460 else if (strcmp(".idata$5", name
) == 0)
1461 target
= "__idata5_magic__";
1467 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1469 false, false, true);
1472 /* Missing magic cookies. Something is very wrong. */
1476 val
= myh
->root
.u
.def
.value
+
1477 sec
->output_section
->vma
+ sec
->output_offset
;
1478 if (first_thunk_address
== 0)
1481 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1483 false, false, true);
1484 first_thunk_address
= myh
->root
.u
.def
.value
+
1485 sec
->output_section
->vma
+
1486 sec
->output_offset
-
1487 pe_data(output_bfd
)->pe_opthdr
.ImageBase
;
1489 idata5offset
= myh
->root
.u
.def
.value
;
1490 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1492 false, false, true);
1494 thunk_size
= myh
->root
.u
.def
.value
- idata5offset
;
1495 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1497 false, false, true);
1498 import_table_size
= myh
->root
.u
.def
.value
;
1503 rstat
= _bfd_relocate_contents (howto
,
1506 pe_data(output_bfd
)->pe_opthdr
.ImageBase
,
1511 case IMAGE_REL_PPC_REL24
:
1512 DUMP_RELOC2(howto
->name
, rel
);
1513 val
-= (input_section
->output_section
->vma
1514 + input_section
->output_offset
);
1516 rstat
= _bfd_relocate_contents (howto
,
1521 case IMAGE_REL_PPC_ADDR16
:
1522 case IMAGE_REL_PPC_ADDR24
:
1523 case IMAGE_REL_PPC_ADDR32
:
1524 DUMP_RELOC2(howto
->name
, rel
);
1525 rstat
= _bfd_relocate_contents (howto
,
1532 if ( info
->base_file
)
1534 /* So if this is non pcrelative, and is referenced
1535 to a section or a common symbol, then it needs a reloc */
1536 if (sym
&& pe_data(output_bfd
)->in_reloc_p(output_bfd
, howto
))
1538 /* relocation to a symbol in a section which
1539 isn't absolute - we output the address here
1541 bfd_vma addr
= rel
->r_vaddr
1542 - input_section
->vma
1543 + input_section
->output_offset
1544 + input_section
->output_section
->vma
;
1546 if (coff_data(output_bfd
)->pe
)
1548 addr
-= pe_data(output_bfd
)->pe_opthdr
.ImageBase
;
1550 fwrite (&addr
, 1,4, (FILE *) info
->base_file
);
1560 case bfd_reloc_overflow
:
1563 char buf
[SYMNMLEN
+ 1];
1568 name
= h
->root
.root
.root
.string
;
1569 else if (sym
== NULL
)
1571 else if (sym
->_n
._n_n
._n_zeroes
== 0
1572 && sym
->_n
._n_n
._n_offset
!= 0)
1573 name
= obj_coff_strings (input_bfd
) + sym
->_n
._n_n
._n_offset
;
1576 strncpy (buf
, sym
->_n
._n_name
, SYMNMLEN
);
1577 buf
[SYMNMLEN
] = '\0';
1581 if (! ((*info
->callbacks
->reloc_overflow
)
1582 (info
, name
, howto
->name
,
1583 (bfd_vma
) 0, input_bfd
,
1584 input_section
, rel
->r_vaddr
- input_section
->vma
)))
1597 #ifdef COFF_IMAGE_WITH_PE
1599 long int global_toc_size
= 4;
1601 bfd
* bfd_of_toc_owner
= 0;
1603 long int import_table_size
;
1604 long int first_thunk_address
;
1605 long int thunk_size
;
1607 struct list_ele
*head
;
1608 struct list_ele
*tail
;
1611 h1
= "\n\t\t\tTOC MAPPING\n\n";
1613 h2
= " TOC disassembly Comments Name\n";
1615 h3
= " Offset spelling (if present)\n";
1628 for(t
= head
; t
!= 0; t
=t
->next
)
1634 else if (t
->cat
== pub
)
1636 else if (t
->cat
== data
)
1637 cat
= "data-in-toc ";
1639 if (t
->offset
> global_toc_size
)
1641 if (t
->offset
<= global_toc_size
+ thunk_size
)
1642 cat
= "IAT reference ";
1646 "**** global_toc_size %ld(%lx), thunk_size %ld(%lx)\n",
1647 global_toc_size
, global_toc_size
, thunk_size
, thunk_size
);
1648 cat
= "Out of bounds!";
1653 " %04lx (%d)", (unsigned long) t
->offset
, t
->offset
- 32768);
1660 fprintf(file
, "\n");
1664 ppc_allocate_toc_section (info
)
1665 struct bfd_link_info
*info
;
1669 static char test_char
= '1';
1671 if ( global_toc_size
== 0 ) /* FIXME: does this get me in trouble? */
1674 if (bfd_of_toc_owner
== 0)
1676 /* No toc owner? Something is very wrong. */
1680 s
= bfd_get_section_by_name ( bfd_of_toc_owner
, TOC_SECTION_NAME
);
1683 /* No toc section? Something is very wrong. */
1687 foo
= (bfd_byte
*) bfd_alloc(bfd_of_toc_owner
, global_toc_size
);
1688 memset(foo
, test_char
, global_toc_size
);
1690 s
->_raw_size
= s
->_cooked_size
= global_toc_size
;
1697 ppc_process_before_allocation (abfd
, info
)
1699 struct bfd_link_info
*info
;
1702 struct internal_reloc
*i
, *rel
;
1704 /* here we have a bfd that is to be included on the link. We have a hook
1705 to do reloc rummaging, before section sizes are nailed down. */
1707 _bfd_coff_get_external_symbols(abfd
);
1709 /* rummage around all the relocs and map the toc */
1710 sec
= abfd
->sections
;
1717 for (; sec
!= 0; sec
= sec
->next
)
1719 if (sec
->reloc_count
== 0)
1722 /* load the relocs */
1723 /* FIXME: there may be a storage leak here */
1724 i
=_bfd_coff_read_internal_relocs(abfd
,sec
,1,0,0,0);
1729 for (rel
=i
;rel
<i
+sec
->reloc_count
;++rel
)
1731 unsigned short r_type
= EXTRACT_TYPE (rel
->r_type
);
1732 unsigned short r_flags
= EXTRACT_FLAGS(rel
->r_type
);
1735 DUMP_RELOC2(ppc_coff_howto_table
[r_type
].name
, rel
);
1739 case IMAGE_REL_PPC_TOCREL16
:
1740 /* if TOCDEFN is on, ignore as someone else has allocated the
1742 if ( (r_flags
& IMAGE_REL_PPC_TOCDEFN
) != IMAGE_REL_PPC_TOCDEFN
)
1743 ok
= ppc_record_toc_entry(abfd
, info
, sec
,
1744 rel
->r_symndx
, default_toc
);
1748 case IMAGE_REL_PPC_IMGLUE
:
1749 ppc_mark_symbol_as_glue(abfd
, rel
->r_symndx
, rel
);
1763 static bfd_reloc_status_type
1764 ppc_refhi_reloc (abfd
,
1772 arelent
*reloc_entry
;
1775 asection
*input_section
;
1777 char **error_message
;
1780 DUMP_RELOC("REFHI",reloc_entry
);
1782 if (output_bfd
== (bfd
*) NULL
)
1783 return bfd_reloc_continue
;
1785 return bfd_reloc_undefined
;
1790 static bfd_reloc_status_type
1791 ppc_reflo_reloc (abfd
,
1799 arelent
*reloc_entry
;
1802 asection
*input_section
;
1804 char **error_message
;
1807 DUMP_RELOC("REFLO",reloc_entry
);
1809 if (output_bfd
== (bfd
*) NULL
)
1810 return bfd_reloc_continue
;
1812 return bfd_reloc_undefined
;
1817 static bfd_reloc_status_type
1818 ppc_pair_reloc (abfd
,
1826 arelent
*reloc_entry
;
1829 asection
*input_section
;
1831 char **error_message
;
1834 DUMP_RELOC("PAIR",reloc_entry
);
1836 if (output_bfd
== (bfd
*) NULL
)
1837 return bfd_reloc_continue
;
1839 return bfd_reloc_undefined
;
1843 static bfd_reloc_status_type
1844 ppc_toc16_reloc (abfd
,
1852 arelent
*reloc_entry
;
1855 asection
*input_section
;
1857 char **error_message
;
1859 UN_IMPL("TOCREL16");
1860 DUMP_RELOC("TOCREL16",reloc_entry
);
1862 if (output_bfd
== (bfd
*) NULL
)
1864 return bfd_reloc_continue
;
1867 return bfd_reloc_ok
;
1872 /* ADDR32NB : 32 bit address relative to the virtual origin. */
1873 /* (On the alpha, this is always a linker generated thunk)*/
1874 /* (i.e. 32bit addr relative to the image base) */
1878 static bfd_reloc_status_type
1879 ppc_addr32nb_reloc (abfd
,
1887 arelent
*reloc_entry
;
1890 asection
*input_section
;
1892 char **error_message
;
1894 UN_IMPL("ADDR32NB");
1895 DUMP_RELOC("ADDR32NB",reloc_entry
);
1897 return bfd_reloc_ok
;
1902 static bfd_reloc_status_type
1903 ppc_secrel_reloc (abfd
,
1911 arelent
*reloc_entry
;
1914 asection
*input_section
;
1916 char **error_message
;
1919 DUMP_RELOC("SECREL",reloc_entry
);
1921 if (output_bfd
== (bfd
*) NULL
)
1922 return bfd_reloc_continue
;
1924 return bfd_reloc_ok
;
1927 static bfd_reloc_status_type
1928 ppc_section_reloc (abfd
,
1936 arelent
*reloc_entry
;
1939 asection
*input_section
;
1941 char **error_message
;
1944 DUMP_RELOC("SECTION",reloc_entry
);
1946 if (output_bfd
== (bfd
*) NULL
)
1947 return bfd_reloc_continue
;
1949 return bfd_reloc_ok
;
1952 static bfd_reloc_status_type
1953 ppc_imglue_reloc (abfd
,
1961 arelent
*reloc_entry
;
1964 asection
*input_section
;
1966 char **error_message
;
1969 DUMP_RELOC("IMGLUE",reloc_entry
);
1971 if (output_bfd
== (bfd
*) NULL
)
1972 return bfd_reloc_continue
;
1974 return bfd_reloc_ok
;
1979 #define MAX_RELOC_INDEX \
1980 (sizeof(ppc_coff_howto_table) / sizeof(ppc_coff_howto_table[0]) - 1)
1983 /* FIXME: There is a possiblity that when we read in a reloc from a file,
1984 that there are some bits encoded in the upper portion of the
1985 type field. Not yet implemented.
1987 static void ppc_coff_rtype2howto
PARAMS ((arelent
*relent
,
1988 struct internal_reloc
*internal
));
1991 ppc_coff_rtype2howto (relent
, internal
)
1993 struct internal_reloc
*internal
;
1996 /* We can encode one of three things in the type field, aside from the
1998 1. IMAGE_REL_PPC_NEG - indicates the value field is a subtraction
1999 value, rather than an addition value
2000 2. IMAGE_REL_PPC_BRTAKEN, IMAGE_REL_PPC_BRNTAKEN - indicates that
2001 the branch is expected to be taken or not.
2002 3. IMAGE_REL_PPC_TOCDEFN - toc slot definition in the file
2003 For now, we just strip this stuff to find the type, and ignore it other
2006 reloc_howto_type
*howto
;
2007 unsigned short r_type
= EXTRACT_TYPE (internal
->r_type
);
2008 unsigned short r_flags
= EXTRACT_FLAGS(internal
->r_type
);
2009 unsigned short junk
= EXTRACT_JUNK (internal
->r_type
);
2011 /* the masking process only slices off the bottom byte for r_type. */
2012 if ( r_type
> MAX_RELOC_INDEX
)
2015 /* check for absolute crap */
2021 case IMAGE_REL_PPC_ADDR16
:
2022 case IMAGE_REL_PPC_REL24
:
2023 case IMAGE_REL_PPC_ADDR24
:
2024 case IMAGE_REL_PPC_ADDR32
:
2025 case IMAGE_REL_PPC_IFGLUE
:
2026 case IMAGE_REL_PPC_ADDR32NB
:
2027 case IMAGE_REL_PPC_SECTION
:
2028 case IMAGE_REL_PPC_SECREL
:
2029 DUMP_RELOC2(ppc_coff_howto_table
[r_type
].name
, internal
);
2030 howto
= ppc_coff_howto_table
+ r_type
;
2032 case IMAGE_REL_PPC_IMGLUE
:
2033 DUMP_RELOC2(ppc_coff_howto_table
[r_type
].name
, internal
);
2034 howto
= ppc_coff_howto_table
+ r_type
;
2036 case IMAGE_REL_PPC_TOCREL16
:
2037 DUMP_RELOC2(ppc_coff_howto_table
[r_type
].name
, internal
);
2038 if (r_flags
& IMAGE_REL_PPC_TOCDEFN
)
2039 howto
= ppc_coff_howto_table
+ IMAGE_REL_PPC_TOCREL16_DEFN
;
2041 howto
= ppc_coff_howto_table
+ IMAGE_REL_PPC_TOCREL16
;
2045 "Warning: Unsupported reloc %s [%d] used -- it may not work.\n",
2046 ppc_coff_howto_table
[r_type
].name
,
2048 howto
= ppc_coff_howto_table
+ r_type
;
2052 relent
->howto
= howto
;
2056 static reloc_howto_type
*
2057 coff_ppc_rtype_to_howto (abfd
, sec
, rel
, h
, sym
, addendp
)
2060 struct internal_reloc
*rel
;
2061 struct coff_link_hash_entry
*h
;
2062 struct internal_syment
*sym
;
2065 reloc_howto_type
*howto
;
2067 /* We can encode one of three things in the type field, aside from the
2069 1. IMAGE_REL_PPC_NEG - indicates the value field is a subtraction
2070 value, rather than an addition value
2071 2. IMAGE_REL_PPC_BRTAKEN, IMAGE_REL_PPC_BRNTAKEN - indicates that
2072 the branch is expected to be taken or not.
2073 3. IMAGE_REL_PPC_TOCDEFN - toc slot definition in the file
2074 For now, we just strip this stuff to find the type, and ignore it other
2078 unsigned short r_type
= EXTRACT_TYPE (rel
->r_type
);
2079 unsigned short r_flags
= EXTRACT_FLAGS(rel
->r_type
);
2080 unsigned short junk
= EXTRACT_JUNK (rel
->r_type
);
2082 /* the masking process only slices off the bottom byte for r_type. */
2083 if ( r_type
> MAX_RELOC_INDEX
)
2086 /* check for absolute crap */
2092 case IMAGE_REL_PPC_ADDR32NB
:
2093 DUMP_RELOC2(ppc_coff_howto_table
[r_type
].name
, rel
);
2094 *addendp
-= pe_data(sec
->output_section
->owner
)->pe_opthdr
.ImageBase
;
2095 howto
= ppc_coff_howto_table
+ r_type
;
2097 case IMAGE_REL_PPC_TOCREL16
:
2098 DUMP_RELOC2(ppc_coff_howto_table
[r_type
].name
, rel
);
2099 if (r_flags
& IMAGE_REL_PPC_TOCDEFN
)
2100 howto
= ppc_coff_howto_table
+ IMAGE_REL_PPC_TOCREL16_DEFN
;
2102 howto
= ppc_coff_howto_table
+ IMAGE_REL_PPC_TOCREL16
;
2104 case IMAGE_REL_PPC_ADDR16
:
2105 case IMAGE_REL_PPC_REL24
:
2106 case IMAGE_REL_PPC_ADDR24
:
2107 case IMAGE_REL_PPC_ADDR32
:
2108 case IMAGE_REL_PPC_IFGLUE
:
2109 case IMAGE_REL_PPC_SECTION
:
2110 case IMAGE_REL_PPC_SECREL
:
2111 DUMP_RELOC2(ppc_coff_howto_table
[r_type
].name
, rel
);
2112 howto
= ppc_coff_howto_table
+ r_type
;
2114 case IMAGE_REL_PPC_IMGLUE
:
2115 DUMP_RELOC2(ppc_coff_howto_table
[r_type
].name
, rel
);
2116 howto
= ppc_coff_howto_table
+ r_type
;
2120 "Warning: Unsupported reloc %s [%d] used -- it may not work.\n",
2121 ppc_coff_howto_table
[r_type
].name
,
2123 howto
= ppc_coff_howto_table
+ r_type
;
2131 /* a cheesy little macro to make the code a little more readable */
2132 #define HOW2MAP(bfd_rtype,ppc_rtype) \
2133 case bfd_rtype: return &ppc_coff_howto_table[ppc_rtype]
2135 static reloc_howto_type
*ppc_coff_reloc_type_lookup
2136 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
2138 static reloc_howto_type
*
2139 ppc_coff_reloc_type_lookup (abfd
, code
)
2141 bfd_reloc_code_real_type code
;
2145 HOW2MAP(BFD_RELOC_32_GOTOFF
, IMAGE_REL_PPC_IMGLUE
);
2146 HOW2MAP(BFD_RELOC_16_GOT_PCREL
, IMAGE_REL_PPC_IFGLUE
);
2147 HOW2MAP(BFD_RELOC_16
, IMAGE_REL_PPC_ADDR16
);
2148 HOW2MAP(BFD_RELOC_PPC_B26
, IMAGE_REL_PPC_REL24
);
2149 HOW2MAP(BFD_RELOC_PPC_BA26
, IMAGE_REL_PPC_ADDR24
);
2150 HOW2MAP(BFD_RELOC_PPC_TOC16
, IMAGE_REL_PPC_TOCREL16
);
2151 HOW2MAP(BFD_RELOC_16_GOTOFF
, IMAGE_REL_PPC_TOCREL16_DEFN
);
2152 HOW2MAP(BFD_RELOC_32
, IMAGE_REL_PPC_ADDR32
);
2153 HOW2MAP(BFD_RELOC_RVA
, IMAGE_REL_PPC_ADDR32NB
);
2163 /* Tailor coffcode.h -- macro heaven. */
2165 #define RTYPE2HOWTO(cache_ptr, dst) ppc_coff_rtype2howto (cache_ptr, dst)
2167 #ifndef COFF_IMAGE_WITH_PE
2169 ppc_coff_swap_sym_in_hook ();
2172 /* We use the special COFF backend linker, with our own special touch. */
2174 #define coff_bfd_reloc_type_lookup ppc_coff_reloc_type_lookup
2175 #define coff_rtype_to_howto coff_ppc_rtype_to_howto
2176 #define coff_relocate_section coff_ppc_relocate_section
2177 #define coff_bfd_final_link ppc_bfd_coff_final_link
2179 #ifndef COFF_IMAGE_WITH_PE
2180 #define coff_swap_sym_in_hook ppc_coff_swap_sym_in_hook
2183 #define SELECT_RELOC(internal, howto) {internal.r_type=howto->type;}
2185 #define COFF_PAGE_SIZE 0x1000
2187 #define POWERPC_LE_PE
2189 #include "coffcode.h"
2193 #ifndef COFF_IMAGE_WITH_PE
2195 What we're trying to do here is allocate a toc section (early), and attach
2196 it to the last bfd to be processed. This avoids the problem of having a toc
2197 written out before all files have been processed. This code allocates
2198 a toc section for every file, and records the last one seen. There are
2199 at least two problems with this approach:
2200 1. We allocate whole bunches of toc sections that are ignored, but at
2201 at least we will not allocate a toc if no .toc is present.
2202 2. It's not clear to me that being the last bfd read necessarily means
2203 that you are the last bfd closed.
2204 3. Doing it on a "swap in" hook depends on when the "swap in" is called,
2205 and how often, etc. It's not clear to me that there isn't a hole here.
2209 ppc_coff_swap_sym_in_hook (abfd
, ext1
, in1
)
2214 struct internal_syment
*in
= (struct internal_syment
*)in1
;
2216 if (bfd_of_toc_owner
!= 0) /* we already have a toc, so go home */
2219 if (strcmp(in
->_n
._n_name
, ".toc") == 0)
2222 register asection
*s
;
2224 s
= bfd_get_section_by_name ( abfd
, TOC_SECTION_NAME
);
2230 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
2232 s
= bfd_make_section (abfd
, TOC_SECTION_NAME
);
2235 || !bfd_set_section_flags (abfd
, s
, flags
)
2236 || !bfd_set_section_alignment (abfd
, s
, 2))
2238 /* FIXME: set appropriate bfd error */
2242 /* save the bfd for later allocation */
2243 bfd_of_toc_owner
= abfd
;
2251 ppc_bfd_coff_final_link ();
2253 #ifndef COFF_IMAGE_WITH_PE
2259 if (abfd
== bfd_of_toc_owner
)
2268 return bfd_of_toc_owner
;
2271 /* this piece of machinery exists only to guarantee that the bfd that holds
2272 the toc section is written last.
2274 This does depend on bfd_make_section attaching a new section to the
2275 end of the section list for the bfd.
2277 This is otherwise intended to be functionally the same as
2278 cofflink.c:_bfd_coff_final_link(). It is specifically different only
2279 where the POWERPC_LE_PE macro modifies the code. It is left in as a
2280 precise form of comment. krk@cygnus.com
2282 #define POWERPC_LE_PE
2285 /* Do the final link step. */
2288 ppc_bfd_coff_final_link (abfd
, info
)
2290 struct bfd_link_info
*info
;
2292 bfd_size_type symesz
;
2293 struct coff_final_link_info finfo
;
2294 boolean debug_merge_allocated
;
2296 struct bfd_link_order
*p
;
2297 size_t max_sym_count
;
2298 size_t max_lineno_count
;
2299 size_t max_reloc_count
;
2300 size_t max_output_reloc_count
;
2301 size_t max_contents_size
;
2302 file_ptr rel_filepos
;
2304 file_ptr line_filepos
;
2305 unsigned int linesz
;
2307 bfd_byte
*external_relocs
= NULL
;
2308 char strbuf
[STRING_SIZE_SIZE
];
2310 symesz
= bfd_coff_symesz (abfd
);
2313 finfo
.output_bfd
= abfd
;
2314 finfo
.strtab
= NULL
;
2315 finfo
.section_info
= NULL
;
2316 finfo
.last_file_index
= -1;
2317 finfo
.last_bf_index
= -1;
2318 finfo
.internal_syms
= NULL
;
2319 finfo
.sec_ptrs
= NULL
;
2320 finfo
.sym_indices
= NULL
;
2321 finfo
.outsyms
= NULL
;
2322 finfo
.linenos
= NULL
;
2323 finfo
.contents
= NULL
;
2324 finfo
.external_relocs
= NULL
;
2325 finfo
.internal_relocs
= NULL
;
2326 debug_merge_allocated
= false;
2328 coff_data (abfd
)->link_info
= info
;
2330 finfo
.strtab
= _bfd_stringtab_init ();
2331 if (finfo
.strtab
== NULL
)
2334 if (! coff_debug_merge_hash_table_init (&finfo
.debug_merge
))
2336 debug_merge_allocated
= true;
2338 /* Compute the file positions for all the sections. */
2339 if (! abfd
->output_has_begun
)
2341 if (! bfd_coff_compute_section_file_positions (abfd
))
2345 /* Count the line numbers and relocation entries required for the
2346 output file. Set the file positions for the relocs. */
2347 rel_filepos
= obj_relocbase (abfd
);
2348 relsz
= bfd_coff_relsz (abfd
);
2349 max_contents_size
= 0;
2350 max_lineno_count
= 0;
2351 max_reloc_count
= 0;
2353 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2356 o
->lineno_count
= 0;
2357 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
2360 if (p
->type
== bfd_indirect_link_order
)
2364 sec
= p
->u
.indirect
.section
;
2366 /* Mark all sections which are to be included in the
2367 link. This will normally be every section. We need
2368 to do this so that we can identify any sections which
2369 the linker has decided to not include. */
2370 sec
->linker_mark
= true;
2372 if (info
->strip
== strip_none
2373 || info
->strip
== strip_some
)
2374 o
->lineno_count
+= sec
->lineno_count
;
2376 if (info
->relocateable
)
2377 o
->reloc_count
+= sec
->reloc_count
;
2379 if (sec
->_raw_size
> max_contents_size
)
2380 max_contents_size
= sec
->_raw_size
;
2381 if (sec
->lineno_count
> max_lineno_count
)
2382 max_lineno_count
= sec
->lineno_count
;
2383 if (sec
->reloc_count
> max_reloc_count
)
2384 max_reloc_count
= sec
->reloc_count
;
2386 else if (info
->relocateable
2387 && (p
->type
== bfd_section_reloc_link_order
2388 || p
->type
== bfd_symbol_reloc_link_order
))
2391 if (o
->reloc_count
== 0)
2395 o
->flags
|= SEC_RELOC
;
2396 o
->rel_filepos
= rel_filepos
;
2397 rel_filepos
+= o
->reloc_count
* relsz
;
2401 /* If doing a relocateable link, allocate space for the pointers we
2403 if (info
->relocateable
)
2407 /* We use section_count + 1, rather than section_count, because
2408 the target_index fields are 1 based. */
2409 finfo
.section_info
=
2410 ((struct coff_link_section_info
*)
2411 bfd_malloc ((abfd
->section_count
+ 1)
2412 * sizeof (struct coff_link_section_info
)));
2413 if (finfo
.section_info
== NULL
)
2415 for (i
= 0; i
<= abfd
->section_count
; i
++)
2417 finfo
.section_info
[i
].relocs
= NULL
;
2418 finfo
.section_info
[i
].rel_hashes
= NULL
;
2422 /* We now know the size of the relocs, so we can determine the file
2423 positions of the line numbers. */
2424 line_filepos
= rel_filepos
;
2425 linesz
= bfd_coff_linesz (abfd
);
2426 max_output_reloc_count
= 0;
2427 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2429 if (o
->lineno_count
== 0)
2430 o
->line_filepos
= 0;
2433 o
->line_filepos
= line_filepos
;
2434 line_filepos
+= o
->lineno_count
* linesz
;
2437 if (o
->reloc_count
!= 0)
2439 /* We don't know the indices of global symbols until we have
2440 written out all the local symbols. For each section in
2441 the output file, we keep an array of pointers to hash
2442 table entries. Each entry in the array corresponds to a
2443 reloc. When we find a reloc against a global symbol, we
2444 set the corresponding entry in this array so that we can
2445 fix up the symbol index after we have written out all the
2448 Because of this problem, we also keep the relocs in
2449 memory until the end of the link. This wastes memory,
2450 but only when doing a relocateable link, which is not the
2452 BFD_ASSERT (info
->relocateable
);
2453 finfo
.section_info
[o
->target_index
].relocs
=
2454 ((struct internal_reloc
*)
2455 bfd_malloc (o
->reloc_count
* sizeof (struct internal_reloc
)));
2456 finfo
.section_info
[o
->target_index
].rel_hashes
=
2457 ((struct coff_link_hash_entry
**)
2458 bfd_malloc (o
->reloc_count
2459 * sizeof (struct coff_link_hash_entry
*)));
2460 if (finfo
.section_info
[o
->target_index
].relocs
== NULL
2461 || finfo
.section_info
[o
->target_index
].rel_hashes
== NULL
)
2464 if (o
->reloc_count
> max_output_reloc_count
)
2465 max_output_reloc_count
= o
->reloc_count
;
2468 /* Reset the reloc and lineno counts, so that we can use them to
2469 count the number of entries we have output so far. */
2471 o
->lineno_count
= 0;
2474 obj_sym_filepos (abfd
) = line_filepos
;
2476 /* Figure out the largest number of symbols in an input BFD. Take
2477 the opportunity to clear the output_has_begun fields of all the
2480 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
2484 sub
->output_has_begun
= false;
2485 sz
= obj_raw_syment_count (sub
);
2486 if (sz
> max_sym_count
)
2490 /* Allocate some buffers used while linking. */
2491 finfo
.internal_syms
= ((struct internal_syment
*)
2492 bfd_malloc (max_sym_count
2493 * sizeof (struct internal_syment
)));
2494 finfo
.sec_ptrs
= (asection
**) bfd_malloc (max_sym_count
2495 * sizeof (asection
*));
2496 finfo
.sym_indices
= (long *) bfd_malloc (max_sym_count
* sizeof (long));
2497 finfo
.outsyms
= ((bfd_byte
*)
2498 bfd_malloc ((size_t) ((max_sym_count
+ 1) * symesz
)));
2499 finfo
.linenos
= (bfd_byte
*) bfd_malloc (max_lineno_count
2500 * bfd_coff_linesz (abfd
));
2501 finfo
.contents
= (bfd_byte
*) bfd_malloc (max_contents_size
);
2502 finfo
.external_relocs
= (bfd_byte
*) bfd_malloc (max_reloc_count
* relsz
);
2503 if (! info
->relocateable
)
2504 finfo
.internal_relocs
= ((struct internal_reloc
*)
2505 bfd_malloc (max_reloc_count
2506 * sizeof (struct internal_reloc
)));
2507 if ((finfo
.internal_syms
== NULL
&& max_sym_count
> 0)
2508 || (finfo
.sec_ptrs
== NULL
&& max_sym_count
> 0)
2509 || (finfo
.sym_indices
== NULL
&& max_sym_count
> 0)
2510 || finfo
.outsyms
== NULL
2511 || (finfo
.linenos
== NULL
&& max_lineno_count
> 0)
2512 || (finfo
.contents
== NULL
&& max_contents_size
> 0)
2513 || (finfo
.external_relocs
== NULL
&& max_reloc_count
> 0)
2514 || (! info
->relocateable
2515 && finfo
.internal_relocs
== NULL
2516 && max_reloc_count
> 0))
2519 /* We now know the position of everything in the file, except that
2520 we don't know the size of the symbol table and therefore we don't
2521 know where the string table starts. We just build the string
2522 table in memory as we go along. We process all the relocations
2523 for a single input file at once. */
2524 obj_raw_syment_count (abfd
) = 0;
2526 if (coff_backend_info (abfd
)->_bfd_coff_start_final_link
)
2528 if (! bfd_coff_start_final_link (abfd
, info
))
2532 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2534 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
2536 if (p
->type
== bfd_indirect_link_order
2537 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
2538 == bfd_target_coff_flavour
))
2540 sub
= p
->u
.indirect
.section
->owner
;
2541 #ifdef POWERPC_LE_PE
2542 if (! sub
->output_has_begun
&& !ppc_do_last(sub
))
2544 if (! sub
->output_has_begun
)
2547 if (! _bfd_coff_link_input_bfd (&finfo
, sub
))
2549 sub
->output_has_begun
= true;
2552 else if (p
->type
== bfd_section_reloc_link_order
2553 || p
->type
== bfd_symbol_reloc_link_order
)
2555 if (! _bfd_coff_reloc_link_order (abfd
, &finfo
, o
, p
))
2560 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
2566 #ifdef POWERPC_LE_PE
2568 extern bfd
* ppc_get_last();
2569 bfd
* last_one
= ppc_get_last();
2572 if (! _bfd_coff_link_input_bfd (&finfo
, last_one
))
2575 last_one
->output_has_begun
= true;
2579 /* Free up the buffers used by _bfd_coff_link_input_bfd. */
2581 coff_debug_merge_hash_table_free (&finfo
.debug_merge
);
2582 debug_merge_allocated
= false;
2584 if (finfo
.internal_syms
!= NULL
)
2586 free (finfo
.internal_syms
);
2587 finfo
.internal_syms
= NULL
;
2589 if (finfo
.sec_ptrs
!= NULL
)
2591 free (finfo
.sec_ptrs
);
2592 finfo
.sec_ptrs
= NULL
;
2594 if (finfo
.sym_indices
!= NULL
)
2596 free (finfo
.sym_indices
);
2597 finfo
.sym_indices
= NULL
;
2599 if (finfo
.linenos
!= NULL
)
2601 free (finfo
.linenos
);
2602 finfo
.linenos
= NULL
;
2604 if (finfo
.contents
!= NULL
)
2606 free (finfo
.contents
);
2607 finfo
.contents
= NULL
;
2609 if (finfo
.external_relocs
!= NULL
)
2611 free (finfo
.external_relocs
);
2612 finfo
.external_relocs
= NULL
;
2614 if (finfo
.internal_relocs
!= NULL
)
2616 free (finfo
.internal_relocs
);
2617 finfo
.internal_relocs
= NULL
;
2620 /* The value of the last C_FILE symbol is supposed to be the symbol
2621 index of the first external symbol. Write it out again if
2623 if (finfo
.last_file_index
!= -1
2624 && (unsigned int) finfo
.last_file
.n_value
!= obj_raw_syment_count (abfd
))
2626 finfo
.last_file
.n_value
= obj_raw_syment_count (abfd
);
2627 bfd_coff_swap_sym_out (abfd
, (PTR
) &finfo
.last_file
,
2628 (PTR
) finfo
.outsyms
);
2630 (obj_sym_filepos (abfd
)
2631 + finfo
.last_file_index
* symesz
),
2633 || bfd_write (finfo
.outsyms
, symesz
, 1, abfd
) != symesz
)
2637 /* Write out the global symbols. */
2638 finfo
.failed
= false;
2639 coff_link_hash_traverse (coff_hash_table (info
), _bfd_coff_write_global_sym
,
2644 /* The outsyms buffer is used by _bfd_coff_write_global_sym. */
2645 if (finfo
.outsyms
!= NULL
)
2647 free (finfo
.outsyms
);
2648 finfo
.outsyms
= NULL
;
2651 if (info
->relocateable
)
2653 /* Now that we have written out all the global symbols, we know
2654 the symbol indices to use for relocs against them, and we can
2655 finally write out the relocs. */
2656 external_relocs
= ((bfd_byte
*)
2657 bfd_malloc (max_output_reloc_count
* relsz
));
2658 if (external_relocs
== NULL
)
2661 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2663 struct internal_reloc
*irel
;
2664 struct internal_reloc
*irelend
;
2665 struct coff_link_hash_entry
**rel_hash
;
2668 if (o
->reloc_count
== 0)
2671 irel
= finfo
.section_info
[o
->target_index
].relocs
;
2672 irelend
= irel
+ o
->reloc_count
;
2673 rel_hash
= finfo
.section_info
[o
->target_index
].rel_hashes
;
2674 erel
= external_relocs
;
2675 for (; irel
< irelend
; irel
++, rel_hash
++, erel
+= relsz
)
2677 if (*rel_hash
!= NULL
)
2679 BFD_ASSERT ((*rel_hash
)->indx
>= 0);
2680 irel
->r_symndx
= (*rel_hash
)->indx
;
2682 bfd_coff_swap_reloc_out (abfd
, (PTR
) irel
, (PTR
) erel
);
2685 if (bfd_seek (abfd
, o
->rel_filepos
, SEEK_SET
) != 0
2686 || bfd_write ((PTR
) external_relocs
, relsz
, o
->reloc_count
,
2687 abfd
) != relsz
* o
->reloc_count
)
2691 free (external_relocs
);
2692 external_relocs
= NULL
;
2695 /* Free up the section information. */
2696 if (finfo
.section_info
!= NULL
)
2700 for (i
= 0; i
< abfd
->section_count
; i
++)
2702 if (finfo
.section_info
[i
].relocs
!= NULL
)
2703 free (finfo
.section_info
[i
].relocs
);
2704 if (finfo
.section_info
[i
].rel_hashes
!= NULL
)
2705 free (finfo
.section_info
[i
].rel_hashes
);
2707 free (finfo
.section_info
);
2708 finfo
.section_info
= NULL
;
2711 /* If we have optimized stabs strings, output them. */
2712 if (coff_hash_table (info
)->stab_info
!= NULL
)
2714 if (! _bfd_write_stab_strings (abfd
, &coff_hash_table (info
)->stab_info
))
2718 /* Write out the string table. */
2719 if (obj_raw_syment_count (abfd
) != 0)
2722 (obj_sym_filepos (abfd
)
2723 + obj_raw_syment_count (abfd
) * symesz
),
2727 #if STRING_SIZE_SIZE == 4
2729 _bfd_stringtab_size (finfo
.strtab
) + STRING_SIZE_SIZE
,
2730 (bfd_byte
*) strbuf
);
2732 #error Change bfd_h_put_32
2735 if (bfd_write (strbuf
, 1, STRING_SIZE_SIZE
, abfd
) != STRING_SIZE_SIZE
)
2738 if (! _bfd_stringtab_emit (abfd
, finfo
.strtab
))
2742 _bfd_stringtab_free (finfo
.strtab
);
2744 /* Setting bfd_get_symcount to 0 will cause write_object_contents to
2745 not try to write out the symbols. */
2746 bfd_get_symcount (abfd
) = 0;
2751 if (debug_merge_allocated
)
2752 coff_debug_merge_hash_table_free (&finfo
.debug_merge
);
2753 if (finfo
.strtab
!= NULL
)
2754 _bfd_stringtab_free (finfo
.strtab
);
2755 if (finfo
.section_info
!= NULL
)
2759 for (i
= 0; i
< abfd
->section_count
; i
++)
2761 if (finfo
.section_info
[i
].relocs
!= NULL
)
2762 free (finfo
.section_info
[i
].relocs
);
2763 if (finfo
.section_info
[i
].rel_hashes
!= NULL
)
2764 free (finfo
.section_info
[i
].rel_hashes
);
2766 free (finfo
.section_info
);
2768 if (finfo
.internal_syms
!= NULL
)
2769 free (finfo
.internal_syms
);
2770 if (finfo
.sec_ptrs
!= NULL
)
2771 free (finfo
.sec_ptrs
);
2772 if (finfo
.sym_indices
!= NULL
)
2773 free (finfo
.sym_indices
);
2774 if (finfo
.outsyms
!= NULL
)
2775 free (finfo
.outsyms
);
2776 if (finfo
.linenos
!= NULL
)
2777 free (finfo
.linenos
);
2778 if (finfo
.contents
!= NULL
)
2779 free (finfo
.contents
);
2780 if (finfo
.external_relocs
!= NULL
)
2781 free (finfo
.external_relocs
);
2782 if (finfo
.internal_relocs
!= NULL
)
2783 free (finfo
.internal_relocs
);
2784 if (external_relocs
!= NULL
)
2785 free (external_relocs
);
2791 /* The transfer vectors that lead the outside world to all of the above. */
2793 #ifdef TARGET_LITTLE_SYM
2797 TARGET_LITTLE_NAME
, /* name or coff-arm-little */
2798 bfd_target_coff_flavour
,
2799 BFD_ENDIAN_LITTLE
, /* data byte order is little */
2800 BFD_ENDIAN_LITTLE
, /* header byte order is little */
2802 (HAS_RELOC
| EXEC_P
| /* FIXME: object flags */
2803 HAS_LINENO
| HAS_DEBUG
|
2804 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
2806 #ifndef COFF_WITH_PE
2807 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
2809 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
/* section flags */
2810 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
),
2813 0, /* leading char */
2814 '/', /* ar_pad_char */
2815 15, /* ar_max_namelen??? FIXMEmgo */
2817 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2818 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2819 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
2821 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2822 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2823 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
2825 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
2826 bfd_generic_archive_p
, /* _bfd_dummy_target */ coff_object_p
},
2827 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
2829 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
2830 _bfd_write_archive_contents
, bfd_false
},
2832 BFD_JUMP_TABLE_GENERIC (coff
),
2833 BFD_JUMP_TABLE_COPY (coff
),
2834 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2835 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
2836 BFD_JUMP_TABLE_SYMBOLS (coff
),
2837 BFD_JUMP_TABLE_RELOCS (coff
),
2838 BFD_JUMP_TABLE_WRITE (coff
),
2839 BFD_JUMP_TABLE_LINK (coff
),
2840 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
2846 #ifdef TARGET_BIG_SYM
2851 bfd_target_coff_flavour
,
2852 BFD_ENDIAN_BIG
, /* data byte order is big */
2853 BFD_ENDIAN_BIG
, /* header byte order is big */
2855 (HAS_RELOC
| EXEC_P
| /* FIXME: object flags */
2856 HAS_LINENO
| HAS_DEBUG
|
2857 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
2859 #ifndef COFF_WITH_PE
2860 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
2862 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
/* section flags */
2863 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
),
2866 0, /* leading char */
2867 '/', /* ar_pad_char */
2868 15, /* ar_max_namelen??? FIXMEmgo */
2870 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
2871 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
2872 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
2874 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
2875 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
2876 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
2878 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
2879 bfd_generic_archive_p
, /* _bfd_dummy_target */ coff_object_p
},
2880 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
2882 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
2883 _bfd_write_archive_contents
, bfd_false
},
2885 BFD_JUMP_TABLE_GENERIC (coff
),
2886 BFD_JUMP_TABLE_COPY (coff
),
2887 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2888 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
2889 BFD_JUMP_TABLE_SYMBOLS (coff
),
2890 BFD_JUMP_TABLE_RELOCS (coff
),
2891 BFD_JUMP_TABLE_WRITE (coff
),
2892 BFD_JUMP_TABLE_LINK (coff
),
2893 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),