bfd/
[deliverable/binutils-gdb.git] / bfd / coff-ppc.c
CommitLineData
252b5132 1/* BFD back-end for PowerPC Microsoft Portable Executable files.
7898deda 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
eea6121a 3 2000, 2001, 2002, 2003, 2004
252b5132
RH
4 Free Software Foundation, Inc.
5
6 Original version pieced together by Kim Knuttila (krk@cygnus.com)
7
8 There is nothing new under the sun. This file draws a lot on other
43646c9d 9 coff files, in particular, those for the rs/6000, alpha, mips, and
252b5132
RH
10 intel backends, and the PE work for the arm.
11
2ab1486e 12 This file is part of BFD, the Binary File Descriptor library.
252b5132 13
2ab1486e
NC
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
252b5132 18
2ab1486e
NC
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
252b5132 23
2ab1486e
NC
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
252b5132
RH
28
29/* Current State:
30 - objdump works
31 - relocs generated by gas
32 - ld will link files, but they do not run.
43646c9d 33 - dlltool will not produce correct output in some .reloc cases, and will
2ab1486e 34 not produce the right glue code for dll function calls. */
252b5132 35
252b5132
RH
36#include "bfd.h"
37#include "sysdep.h"
38
39#include "libbfd.h"
40
41#include "coff/powerpc.h"
42#include "coff/internal.h"
43
44#include "coff/pe.h"
45
46#ifdef BADMAG
47#undef BADMAG
48#endif
49
50#define BADMAG(x) PPCBADMAG(x)
51
52#include "libcoff.h"
53
54/* This file is compiled more than once, but we only compile the
55 final_link routine once. */
b34976b6 56extern bfd_boolean ppc_bfd_coff_final_link
252b5132
RH
57 PARAMS ((bfd *, struct bfd_link_info *));
58extern void dump_toc PARAMS ((PTR));
59
2ab1486e
NC
60/* The toc is a set of bfd_vma fields. We use the fact that valid
61 addresses are even (i.e. the bit representing "1" is off) to allow
62 us to encode a little extra information in the field
63 - Unallocated addresses are initialized to 1.
64 - Allocated addresses are even numbers.
65 The first time we actually write a reference to the toc in the bfd,
66 we want to record that fact in a fixup file (if it is asked for), so
67 we keep track of whether or not an address has been written by marking
68 the low order bit with a "1" upon writing. */
252b5132
RH
69
70#define SET_UNALLOCATED(x) ((x) = 1)
71#define IS_UNALLOCATED(x) ((x) == 1)
72
73#define IS_WRITTEN(x) ((x) & 1)
74#define MARK_AS_WRITTEN(x) ((x) |= 1)
75#define MAKE_ADDR_AGAIN(x) ((x) &= ~1)
76
2ab1486e 77/* Turn on this check if you suspect something amiss in the hash tables. */
252b5132
RH
78#ifdef DEBUG_HASH
79
2ab1486e 80/* Need a 7 char string for an eye catcher. */
252b5132
RH
81#define EYE "krkjunk"
82
83#define HASH_CHECK_DCL char eye_catcher[8];
84#define HASH_CHECK_INIT(ret) strcpy(ret->eye_catcher, EYE)
85#define HASH_CHECK(addr) \
86 if (strcmp(addr->eye_catcher, EYE) != 0) \
87 { \
6e301b2b 88 fprintf (stderr,\
252b5132
RH
89 _("File %s, line %d, Hash check failure, bad eye %8s\n"), \
90 __FILE__, __LINE__, addr->eye_catcher); \
c5930ee6 91 abort (); \
252b5132
RH
92 }
93
252b5132
RH
94#else
95
96#define HASH_CHECK_DCL
97#define HASH_CHECK_INIT(ret)
98#define HASH_CHECK(addr)
99
100#endif
101
102/* In order not to add an int to every hash table item for every coff
2ab1486e 103 linker, we define our own hash table, derived from the coff one. */
252b5132 104
43646c9d 105/* PE linker hash table entries. */
252b5132
RH
106
107struct ppc_coff_link_hash_entry
108{
2ab1486e 109 struct coff_link_hash_entry root; /* First entry, as required. */
252b5132
RH
110
111 /* As we wonder around the relocs, we'll keep the assigned toc_offset
2ab1486e
NC
112 here. */
113 bfd_vma toc_offset; /* Our addition, as required. */
252b5132
RH
114 int symbol_is_glue;
115 unsigned long int glue_insn;
116
117 HASH_CHECK_DCL
118};
119
252b5132
RH
120/* PE linker hash table. */
121
122struct ppc_coff_link_hash_table
123{
2ab1486e 124 struct coff_link_hash_table root; /* First entry, as required. */
252b5132
RH
125};
126
127static struct bfd_hash_entry *ppc_coff_link_hash_newfunc
128 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
129 const char *));
b34976b6 130static bfd_boolean ppc_coff_link_hash_table_init
252b5132
RH
131 PARAMS ((struct ppc_coff_link_hash_table *, bfd *,
132 struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
133 struct bfd_hash_table *,
134 const char *)));
135static struct bfd_link_hash_table *ppc_coff_link_hash_table_create
136 PARAMS ((bfd *));
b34976b6 137static bfd_boolean coff_ppc_relocate_section
252b5132
RH
138 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
139 struct internal_reloc *, struct internal_syment *, asection **));
140static reloc_howto_type *coff_ppc_rtype_to_howto
141 PARAMS ((bfd *, asection *, struct internal_reloc *,
142 struct coff_link_hash_entry *, struct internal_syment *,
143 bfd_vma *));
144
145/* Routine to create an entry in the link hash table. */
146
147static struct bfd_hash_entry *
148ppc_coff_link_hash_newfunc (entry, table, string)
149 struct bfd_hash_entry *entry;
150 struct bfd_hash_table *table;
151 const char *string;
152{
43646c9d 153 struct ppc_coff_link_hash_entry *ret =
252b5132
RH
154 (struct ppc_coff_link_hash_entry *) entry;
155
156 /* Allocate the structure if it has not already been allocated by a
157 subclass. */
158 if (ret == (struct ppc_coff_link_hash_entry *) NULL)
159 ret = (struct ppc_coff_link_hash_entry *)
43646c9d 160 bfd_hash_allocate (table,
252b5132
RH
161 sizeof (struct ppc_coff_link_hash_entry));
162
163 if (ret == (struct ppc_coff_link_hash_entry *) NULL)
164 return NULL;
165
166 /* Call the allocation method of the superclass. */
167 ret = ((struct ppc_coff_link_hash_entry *)
43646c9d 168 _bfd_coff_link_hash_newfunc ((struct bfd_hash_entry *) ret,
252b5132
RH
169 table, string));
170
171 if (ret)
172 {
173 /* Initialize the local fields. */
2ab1486e 174 SET_UNALLOCATED (ret->toc_offset);
252b5132
RH
175 ret->symbol_is_glue = 0;
176 ret->glue_insn = 0;
177
2ab1486e 178 HASH_CHECK_INIT (ret);
252b5132
RH
179 }
180
181 return (struct bfd_hash_entry *) ret;
182}
183
184/* Initialize a PE linker hash table. */
185
b34976b6 186static bfd_boolean
252b5132
RH
187ppc_coff_link_hash_table_init (table, abfd, newfunc)
188 struct ppc_coff_link_hash_table *table;
189 bfd *abfd;
190 struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
191 struct bfd_hash_table *,
192 const char *));
193{
194 return _bfd_coff_link_hash_table_init (&table->root, abfd, newfunc);
195}
196
197/* Create a PE linker hash table. */
198
199static struct bfd_link_hash_table *
200ppc_coff_link_hash_table_create (abfd)
201 bfd *abfd;
202{
203 struct ppc_coff_link_hash_table *ret;
dc810e39 204 bfd_size_type amt = sizeof (struct ppc_coff_link_hash_table);
252b5132 205
e2d34d7d 206 ret = (struct ppc_coff_link_hash_table *) bfd_malloc (amt);
252b5132
RH
207 if (ret == NULL)
208 return NULL;
209 if (! ppc_coff_link_hash_table_init (ret, abfd,
210 ppc_coff_link_hash_newfunc))
211 {
e2d34d7d 212 free (ret);
252b5132
RH
213 return (struct bfd_link_hash_table *) NULL;
214 }
215 return &ret->root.root;
216}
217
2ab1486e 218/* Now, tailor coffcode.h to use our hash stuff. */
252b5132
RH
219
220#define coff_bfd_link_hash_table_create ppc_coff_link_hash_table_create
252b5132 221\f
2ab1486e
NC
222/* The nt loader points the toc register to &toc + 32768, in order to
223 use the complete range of a 16-bit displacement. We have to adjust
224 for this when we fix up loads displaced off the toc reg. */
252b5132
RH
225#define TOC_LOAD_ADJUSTMENT (-32768)
226#define TOC_SECTION_NAME ".private.toc"
227
228/* The main body of code is in coffcode.h. */
229
230#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
231
232/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
233 from smaller values. Start with zero, widen, *then* decrement. */
234#define MINUS_ONE (((bfd_vma)0) - 1)
235
2ab1486e 236/* These should definitely go in a header file somewhere... */
252b5132
RH
237
238/* NOP */
239#define IMAGE_REL_PPC_ABSOLUTE 0x0000
240
241/* 64-bit address */
242#define IMAGE_REL_PPC_ADDR64 0x0001
243
244/* 32-bit address */
245#define IMAGE_REL_PPC_ADDR32 0x0002
246
247/* 26-bit address, shifted left 2 (branch absolute) */
248#define IMAGE_REL_PPC_ADDR24 0x0003
249
250/* 16-bit address */
251#define IMAGE_REL_PPC_ADDR16 0x0004
252
253/* 16-bit address, shifted left 2 (load doubleword) */
254#define IMAGE_REL_PPC_ADDR14 0x0005
255
256/* 26-bit PC-relative offset, shifted left 2 (branch relative) */
257#define IMAGE_REL_PPC_REL24 0x0006
258
259/* 16-bit PC-relative offset, shifted left 2 (br cond relative) */
260#define IMAGE_REL_PPC_REL14 0x0007
261
262/* 16-bit offset from TOC base */
263#define IMAGE_REL_PPC_TOCREL16 0x0008
264
265/* 16-bit offset from TOC base, shifted left 2 (load doubleword) */
266#define IMAGE_REL_PPC_TOCREL14 0x0009
267
268/* 32-bit addr w/o image base */
269#define IMAGE_REL_PPC_ADDR32NB 0x000A
270
271/* va of containing section (as in an image sectionhdr) */
272#define IMAGE_REL_PPC_SECREL 0x000B
273
274/* sectionheader number */
275#define IMAGE_REL_PPC_SECTION 0x000C
276
277/* substitute TOC restore instruction iff symbol is glue code */
278#define IMAGE_REL_PPC_IFGLUE 0x000D
279
280/* symbol is glue code; virtual address is TOC restore instruction */
281#define IMAGE_REL_PPC_IMGLUE 0x000E
282
283/* va of containing section (limited to 16 bits) */
284#define IMAGE_REL_PPC_SECREL16 0x000F
285
2ab1486e
NC
286/* Stuff to handle immediate data when the number of bits in the
287 data is greater than the number of bits in the immediate field
288 We need to do (usually) 32 bit arithmetic on 16 bit chunks. */
252b5132
RH
289#define IMAGE_REL_PPC_REFHI 0x0010
290#define IMAGE_REL_PPC_REFLO 0x0011
291#define IMAGE_REL_PPC_PAIR 0x0012
292
2ab1486e 293/* This is essentially the same as tocrel16, with TOCDEFN assumed. */
252b5132
RH
294#define IMAGE_REL_PPC_TOCREL16_DEFN 0x0013
295
2ab1486e 296/* Flag bits in IMAGE_RELOCATION.TYPE. */
252b5132 297
2ab1486e 298/* Subtract reloc value rather than adding it. */
252b5132
RH
299#define IMAGE_REL_PPC_NEG 0x0100
300
2ab1486e 301/* Fix branch prediction bit to predict branch taken. */
252b5132
RH
302#define IMAGE_REL_PPC_BRTAKEN 0x0200
303
2ab1486e 304/* Fix branch prediction bit to predict branch not taken. */
252b5132
RH
305#define IMAGE_REL_PPC_BRNTAKEN 0x0400
306
2ab1486e 307/* TOC slot defined in file (or, data in toc). */
252b5132
RH
308#define IMAGE_REL_PPC_TOCDEFN 0x0800
309
2ab1486e 310/* Masks to isolate above values in IMAGE_RELOCATION.Type. */
252b5132
RH
311#define IMAGE_REL_PPC_TYPEMASK 0x00FF
312#define IMAGE_REL_PPC_FLAGMASK 0x0F00
313
314#define EXTRACT_TYPE(x) ((x) & IMAGE_REL_PPC_TYPEMASK)
315#define EXTRACT_FLAGS(x) ((x) & IMAGE_REL_PPC_FLAGMASK)
316#define EXTRACT_JUNK(x) \
317 ((x) & ~(IMAGE_REL_PPC_TYPEMASK | IMAGE_REL_PPC_FLAGMASK))
252b5132 318\f
2ab1486e 319/* Static helper functions to make relocation work. */
252b5132
RH
320/* (Work In Progress) */
321
322static bfd_reloc_status_type ppc_refhi_reloc PARAMS ((bfd *abfd,
323 arelent *reloc,
324 asymbol *symbol,
325 PTR data,
326 asection *section,
327 bfd *output_bfd,
328 char **error));
329#if 0
330static bfd_reloc_status_type ppc_reflo_reloc PARAMS ((bfd *abfd,
331 arelent *reloc,
332 asymbol *symbol,
333 PTR data,
334 asection *section,
335 bfd *output_bfd,
336 char **error));
337#endif
338static bfd_reloc_status_type ppc_pair_reloc PARAMS ((bfd *abfd,
339 arelent *reloc,
340 asymbol *symbol,
341 PTR data,
342 asection *section,
343 bfd *output_bfd,
344 char **error));
252b5132
RH
345\f
346static bfd_reloc_status_type ppc_toc16_reloc PARAMS ((bfd *abfd,
347 arelent *reloc,
348 asymbol *symbol,
349 PTR data,
350 asection *section,
351 bfd *output_bfd,
352 char **error));
353
354#if 0
355static bfd_reloc_status_type ppc_addr32nb_reloc PARAMS ((bfd *abfd,
356 arelent *reloc,
357 asymbol *symbol,
358 PTR data,
359 asection *section,
360 bfd *output_bfd,
361 char **error));
362#endif
363static bfd_reloc_status_type ppc_section_reloc PARAMS ((bfd *abfd,
364 arelent *reloc,
365 asymbol *symbol,
366 PTR data,
367 asection *section,
368 bfd *output_bfd,
369 char **error));
370
371static bfd_reloc_status_type ppc_secrel_reloc PARAMS ((bfd *abfd,
372 arelent *reloc,
373 asymbol *symbol,
374 PTR data,
375 asection *section,
376 bfd *output_bfd,
377 char **error));
378
379static bfd_reloc_status_type ppc_imglue_reloc PARAMS ((bfd *abfd,
380 arelent *reloc,
381 asymbol *symbol,
382 PTR data,
383 asection *section,
384 bfd *output_bfd,
385 char **error));
386
b34976b6 387static bfd_boolean in_reloc_p PARAMS((bfd *abfd, reloc_howto_type *howto));
252b5132
RH
388\f
389/* FIXME: It'll take a while to get through all of these. I only need a few to
390 get us started, so those I'll make sure work. Those marked FIXME are either
2ab1486e
NC
391 completely unverified or have a specific unknown marked in the comment. */
392
393/* Relocation entries for Windows/NT on PowerPC.
394
395 From the document "" we find the following listed as used relocs:
396
397 ABSOLUTE : The noop
398 ADDR[64|32|16] : fields that hold addresses in data fields or the
399 16 bit displacement field on a load/store.
400 ADDR[24|14] : fields that hold addresses in branch and cond
401 branches. These represent [26|16] bit addresses.
402 The low order 2 bits are preserved.
403 REL[24|14] : branches relative to the Instruction Address
404 register. These represent [26|16] bit addresses,
405 as before. The instruction field will be zero, and
406 the address of the SYM will be inserted at link time.
407 TOCREL16 : 16 bit displacement field referring to a slot in
408 toc.
409 TOCREL14 : 16 bit displacement field, similar to REL14 or ADDR14.
410 ADDR32NB : 32 bit address relative to the virtual origin.
411 (On the alpha, this is always a linker generated thunk)
412 (i.e. 32bit addr relative to the image base)
413 SECREL : The value is relative to the start of the section
414 containing the symbol.
415 SECTION : access to the header containing the item. Supports the
416 codeview debugger.
417
418 In particular, note that the document does not indicate that the
419 relocations listed in the header file are used. */
420
252b5132
RH
421
422static reloc_howto_type ppc_coff_howto_table[] =
423{
424 /* IMAGE_REL_PPC_ABSOLUTE 0x0000 NOP */
425 /* Unused: */
43646c9d
KH
426 HOWTO (IMAGE_REL_PPC_ABSOLUTE, /* type */
427 0, /* rightshift */
428 0, /* size (0 = byte, 1 = short, 2 = long) */
429 0, /* bitsize */
b34976b6 430 FALSE, /* pc_relative */
43646c9d 431 0, /* bitpos */
252b5132 432 complain_overflow_dont, /* dont complain_on_overflow */
43646c9d 433 0, /* special_function */
252b5132 434 "ABSOLUTE", /* name */
b34976b6 435 FALSE, /* partial_inplace */
43646c9d
KH
436 0x00, /* src_mask */
437 0x00, /* dst_mask */
b34976b6 438 FALSE), /* pcrel_offset */
43646c9d 439
252b5132
RH
440 /* IMAGE_REL_PPC_ADDR64 0x0001 64-bit address */
441 /* Unused: */
43646c9d
KH
442 HOWTO(IMAGE_REL_PPC_ADDR64, /* type */
443 0, /* rightshift */
444 3, /* size (0 = byte, 1 = short, 2 = long) */
445 64, /* bitsize */
b34976b6 446 FALSE, /* pc_relative */
43646c9d 447 0, /* bitpos */
252b5132 448 complain_overflow_bitfield, /* complain_on_overflow */
43646c9d 449 0, /* special_function */
252b5132 450 "ADDR64", /* name */
b34976b6 451 TRUE, /* partial_inplace */
252b5132
RH
452 MINUS_ONE, /* src_mask */
453 MINUS_ONE, /* dst_mask */
b34976b6 454 FALSE), /* pcrel_offset */
252b5132
RH
455
456 /* IMAGE_REL_PPC_ADDR32 0x0002 32-bit address */
457 /* Used: */
458 HOWTO (IMAGE_REL_PPC_ADDR32, /* type */
43646c9d
KH
459 0, /* rightshift */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
461 32, /* bitsize */
b34976b6 462 FALSE, /* pc_relative */
43646c9d 463 0, /* bitpos */
252b5132 464 complain_overflow_bitfield, /* complain_on_overflow */
43646c9d 465 0, /* special_function */
252b5132 466 "ADDR32", /* name */
b34976b6 467 TRUE, /* partial_inplace */
43646c9d
KH
468 0xffffffff, /* src_mask */
469 0xffffffff, /* dst_mask */
b34976b6 470 FALSE), /* pcrel_offset */
43646c9d 471
252b5132
RH
472 /* IMAGE_REL_PPC_ADDR24 0x0003 26-bit address, shifted left 2 (branch absolute) */
473 /* the LI field is in bit 6 through bit 29 is 24 bits, + 2 for the shift */
474 /* Of course, That's the IBM approved bit numbering, which is not what */
43646c9d 475 /* anyone else uses.... The li field is in bit 2 thru 25 */
252b5132
RH
476 /* Used: */
477 HOWTO (IMAGE_REL_PPC_ADDR24, /* type */
43646c9d
KH
478 0, /* rightshift */
479 2, /* size (0 = byte, 1 = short, 2 = long) */
252b5132 480 26, /* bitsize */
b34976b6 481 FALSE, /* pc_relative */
43646c9d 482 0, /* bitpos */
252b5132 483 complain_overflow_bitfield, /* complain_on_overflow */
43646c9d 484 0, /* special_function */
252b5132 485 "ADDR24", /* name */
b34976b6 486 TRUE, /* partial_inplace */
43646c9d
KH
487 0x07fffffc, /* src_mask */
488 0x07fffffc, /* dst_mask */
b34976b6 489 FALSE), /* pcrel_offset */
43646c9d 490
252b5132
RH
491 /* IMAGE_REL_PPC_ADDR16 0x0004 16-bit address */
492 /* Used: */
43646c9d
KH
493 HOWTO (IMAGE_REL_PPC_ADDR16, /* type */
494 0, /* rightshift */
495 1, /* size (0 = byte, 1 = short, 2 = long) */
496 16, /* bitsize */
b34976b6 497 FALSE, /* pc_relative */
43646c9d 498 0, /* bitpos */
252b5132 499 complain_overflow_signed, /* complain_on_overflow */
43646c9d 500 0, /* special_function */
252b5132 501 "ADDR16", /* name */
b34976b6 502 TRUE, /* partial_inplace */
43646c9d
KH
503 0xffff, /* src_mask */
504 0xffff, /* dst_mask */
b34976b6 505 FALSE), /* pcrel_offset */
43646c9d 506
252b5132
RH
507 /* IMAGE_REL_PPC_ADDR14 0x0005 */
508 /* 16-bit address, shifted left 2 (load doubleword) */
509 /* FIXME: the mask is likely wrong, and the bit position may be as well */
510 /* Unused: */
43646c9d
KH
511 HOWTO (IMAGE_REL_PPC_ADDR14, /* type */
512 1, /* rightshift */
513 1, /* size (0 = byte, 1 = short, 2 = long) */
514 16, /* bitsize */
b34976b6 515 FALSE, /* pc_relative */
43646c9d 516 0, /* bitpos */
252b5132 517 complain_overflow_signed, /* complain_on_overflow */
43646c9d 518 0, /* special_function */
252b5132 519 "ADDR16", /* name */
b34976b6 520 TRUE, /* partial_inplace */
43646c9d
KH
521 0xffff, /* src_mask */
522 0xffff, /* dst_mask */
b34976b6 523 FALSE), /* pcrel_offset */
43646c9d 524
252b5132
RH
525 /* IMAGE_REL_PPC_REL24 0x0006 */
526 /* 26-bit PC-relative offset, shifted left 2 (branch relative) */
527 /* Used: */
528 HOWTO (IMAGE_REL_PPC_REL24, /* type */
43646c9d
KH
529 0, /* rightshift */
530 2, /* size (0 = byte, 1 = short, 2 = long) */
531 26, /* bitsize */
b34976b6 532 TRUE, /* pc_relative */
43646c9d 533 0, /* bitpos */
252b5132 534 complain_overflow_signed, /* complain_on_overflow */
43646c9d 535 0, /* special_function */
252b5132 536 "REL24", /* name */
b34976b6 537 TRUE, /* partial_inplace */
43646c9d
KH
538 0x3fffffc, /* src_mask */
539 0x3fffffc, /* dst_mask */
b34976b6 540 FALSE), /* pcrel_offset */
43646c9d 541
252b5132
RH
542 /* IMAGE_REL_PPC_REL14 0x0007 */
543 /* 16-bit PC-relative offset, shifted left 2 (br cond relative) */
544 /* FIXME: the mask is likely wrong, and the bit position may be as well */
545 /* FIXME: how does it know how far to shift? */
546 /* Unused: */
43646c9d
KH
547 HOWTO (IMAGE_REL_PPC_ADDR14, /* type */
548 1, /* rightshift */
549 1, /* size (0 = byte, 1 = short, 2 = long) */
550 16, /* bitsize */
b34976b6 551 FALSE, /* pc_relative */
43646c9d 552 0, /* bitpos */
252b5132 553 complain_overflow_signed, /* complain_on_overflow */
43646c9d 554 0, /* special_function */
252b5132 555 "ADDR16", /* name */
b34976b6 556 TRUE, /* partial_inplace */
43646c9d
KH
557 0xffff, /* src_mask */
558 0xffff, /* dst_mask */
b34976b6 559 TRUE), /* pcrel_offset */
43646c9d 560
252b5132
RH
561 /* IMAGE_REL_PPC_TOCREL16 0x0008 */
562 /* 16-bit offset from TOC base */
563 /* Used: */
43646c9d
KH
564 HOWTO (IMAGE_REL_PPC_TOCREL16,/* type */
565 0, /* rightshift */
566 1, /* size (0 = byte, 1 = short, 2 = long) */
567 16, /* bitsize */
b34976b6 568 FALSE, /* pc_relative */
43646c9d 569 0, /* bitpos */
252b5132 570 complain_overflow_dont, /* complain_on_overflow */
43646c9d 571 ppc_toc16_reloc, /* special_function */
252b5132 572 "TOCREL16", /* name */
b34976b6 573 FALSE, /* partial_inplace */
43646c9d
KH
574 0xffff, /* src_mask */
575 0xffff, /* dst_mask */
b34976b6 576 FALSE), /* pcrel_offset */
43646c9d 577
252b5132
RH
578 /* IMAGE_REL_PPC_TOCREL14 0x0009 */
579 /* 16-bit offset from TOC base, shifted left 2 (load doubleword) */
580 /* Unused: */
43646c9d
KH
581 HOWTO (IMAGE_REL_PPC_TOCREL14,/* type */
582 1, /* rightshift */
583 1, /* size (0 = byte, 1 = short, 2 = long) */
584 16, /* bitsize */
b34976b6 585 FALSE, /* pc_relative */
43646c9d 586 0, /* bitpos */
252b5132 587 complain_overflow_signed, /* complain_on_overflow */
43646c9d 588 0, /* special_function */
252b5132 589 "TOCREL14", /* name */
b34976b6 590 FALSE, /* partial_inplace */
43646c9d
KH
591 0xffff, /* src_mask */
592 0xffff, /* dst_mask */
b34976b6 593 FALSE), /* pcrel_offset */
43646c9d 594
252b5132
RH
595 /* IMAGE_REL_PPC_ADDR32NB 0x000A */
596 /* 32-bit addr w/ image base */
597 /* Unused: */
43646c9d
KH
598 HOWTO (IMAGE_REL_PPC_ADDR32NB,/* type */
599 0, /* rightshift */
600 2, /* size (0 = byte, 1 = short, 2 = long) */
601 32, /* bitsize */
b34976b6 602 FALSE, /* pc_relative */
43646c9d 603 0, /* bitpos */
252b5132 604 complain_overflow_signed, /* complain_on_overflow */
43646c9d 605 0, /* special_function */
252b5132 606 "ADDR32NB", /* name */
b34976b6 607 TRUE, /* partial_inplace */
43646c9d
KH
608 0xffffffff, /* src_mask */
609 0xffffffff, /* dst_mask */
b34976b6 610 FALSE), /* pcrel_offset */
43646c9d 611
252b5132
RH
612 /* IMAGE_REL_PPC_SECREL 0x000B */
613 /* va of containing section (as in an image sectionhdr) */
614 /* Unused: */
43646c9d
KH
615 HOWTO (IMAGE_REL_PPC_SECREL,/* type */
616 0, /* rightshift */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
618 32, /* bitsize */
b34976b6 619 FALSE, /* pc_relative */
43646c9d 620 0, /* bitpos */
252b5132 621 complain_overflow_signed, /* complain_on_overflow */
43646c9d 622 ppc_secrel_reloc, /* special_function */
252b5132 623 "SECREL", /* name */
b34976b6 624 TRUE, /* partial_inplace */
43646c9d
KH
625 0xffffffff, /* src_mask */
626 0xffffffff, /* dst_mask */
b34976b6 627 TRUE), /* pcrel_offset */
252b5132
RH
628
629 /* IMAGE_REL_PPC_SECTION 0x000C */
630 /* sectionheader number */
631 /* Unused: */
43646c9d
KH
632 HOWTO (IMAGE_REL_PPC_SECTION,/* type */
633 0, /* rightshift */
634 2, /* size (0 = byte, 1 = short, 2 = long) */
635 32, /* bitsize */
b34976b6 636 FALSE, /* pc_relative */
43646c9d 637 0, /* bitpos */
252b5132 638 complain_overflow_signed, /* complain_on_overflow */
43646c9d 639 ppc_section_reloc, /* special_function */
252b5132 640 "SECTION", /* name */
b34976b6 641 TRUE, /* partial_inplace */
43646c9d
KH
642 0xffffffff, /* src_mask */
643 0xffffffff, /* dst_mask */
b34976b6 644 TRUE), /* pcrel_offset */
252b5132
RH
645
646 /* IMAGE_REL_PPC_IFGLUE 0x000D */
647 /* substitute TOC restore instruction iff symbol is glue code */
648 /* Used: */
43646c9d
KH
649 HOWTO (IMAGE_REL_PPC_IFGLUE,/* type */
650 0, /* rightshift */
651 2, /* size (0 = byte, 1 = short, 2 = long) */
652 32, /* bitsize */
b34976b6 653 FALSE, /* pc_relative */
43646c9d 654 0, /* bitpos */
252b5132 655 complain_overflow_signed, /* complain_on_overflow */
43646c9d 656 0, /* special_function */
252b5132 657 "IFGLUE", /* name */
b34976b6 658 TRUE, /* partial_inplace */
43646c9d
KH
659 0xffffffff, /* src_mask */
660 0xffffffff, /* dst_mask */
b34976b6 661 FALSE), /* pcrel_offset */
252b5132
RH
662
663 /* IMAGE_REL_PPC_IMGLUE 0x000E */
664 /* symbol is glue code; virtual address is TOC restore instruction */
665 /* Unused: */
43646c9d
KH
666 HOWTO (IMAGE_REL_PPC_IMGLUE,/* type */
667 0, /* rightshift */
668 2, /* size (0 = byte, 1 = short, 2 = long) */
669 32, /* bitsize */
b34976b6 670 FALSE, /* pc_relative */
43646c9d 671 0, /* bitpos */
252b5132 672 complain_overflow_dont, /* complain_on_overflow */
43646c9d 673 ppc_imglue_reloc, /* special_function */
252b5132 674 "IMGLUE", /* name */
b34976b6 675 FALSE, /* partial_inplace */
43646c9d
KH
676 0xffffffff, /* src_mask */
677 0xffffffff, /* dst_mask */
b34976b6 678 FALSE), /* pcrel_offset */
252b5132
RH
679
680 /* IMAGE_REL_PPC_SECREL16 0x000F */
681 /* va of containing section (limited to 16 bits) */
682 /* Unused: */
43646c9d
KH
683 HOWTO (IMAGE_REL_PPC_SECREL16,/* type */
684 0, /* rightshift */
685 1, /* size (0 = byte, 1 = short, 2 = long) */
686 16, /* bitsize */
b34976b6 687 FALSE, /* pc_relative */
43646c9d 688 0, /* bitpos */
252b5132 689 complain_overflow_signed, /* complain_on_overflow */
43646c9d 690 0, /* special_function */
252b5132 691 "SECREL16", /* name */
b34976b6 692 TRUE, /* partial_inplace */
43646c9d
KH
693 0xffff, /* src_mask */
694 0xffff, /* dst_mask */
b34976b6 695 TRUE), /* pcrel_offset */
252b5132
RH
696
697 /* IMAGE_REL_PPC_REFHI 0x0010 */
698 /* Unused: */
43646c9d
KH
699 HOWTO (IMAGE_REL_PPC_REFHI, /* type */
700 0, /* rightshift */
701 1, /* size (0 = byte, 1 = short, 2 = long) */
702 16, /* bitsize */
b34976b6 703 FALSE, /* pc_relative */
43646c9d 704 0, /* bitpos */
252b5132 705 complain_overflow_signed, /* complain_on_overflow */
43646c9d 706 ppc_refhi_reloc, /* special_function */
252b5132 707 "REFHI", /* name */
b34976b6 708 TRUE, /* partial_inplace */
43646c9d
KH
709 0xffffffff, /* src_mask */
710 0xffffffff, /* dst_mask */
b34976b6 711 FALSE), /* pcrel_offset */
252b5132
RH
712
713 /* IMAGE_REL_PPC_REFLO 0x0011 */
714 /* Unused: */
43646c9d
KH
715 HOWTO (IMAGE_REL_PPC_REFLO, /* type */
716 0, /* rightshift */
717 1, /* size (0 = byte, 1 = short, 2 = long) */
718 16, /* bitsize */
b34976b6 719 FALSE, /* pc_relative */
43646c9d 720 0, /* bitpos */
252b5132 721 complain_overflow_signed, /* complain_on_overflow */
43646c9d 722 ppc_refhi_reloc, /* special_function */
252b5132 723 "REFLO", /* name */
b34976b6 724 TRUE, /* partial_inplace */
43646c9d
KH
725 0xffffffff, /* src_mask */
726 0xffffffff, /* dst_mask */
b34976b6 727 FALSE), /* pcrel_offset */
252b5132
RH
728
729 /* IMAGE_REL_PPC_PAIR 0x0012 */
730 /* Unused: */
43646c9d
KH
731 HOWTO (IMAGE_REL_PPC_PAIR, /* type */
732 0, /* rightshift */
733 1, /* size (0 = byte, 1 = short, 2 = long) */
734 16, /* bitsize */
b34976b6 735 FALSE, /* pc_relative */
43646c9d 736 0, /* bitpos */
252b5132 737 complain_overflow_signed, /* complain_on_overflow */
43646c9d 738 ppc_pair_reloc, /* special_function */
252b5132 739 "PAIR", /* name */
b34976b6 740 TRUE, /* partial_inplace */
43646c9d
KH
741 0xffffffff, /* src_mask */
742 0xffffffff, /* dst_mask */
b34976b6 743 FALSE), /* pcrel_offset */
252b5132
RH
744
745 /* IMAGE_REL_PPC_TOCREL16_DEFN 0x0013 */
746 /* 16-bit offset from TOC base, without causing a definition */
747 /* Used: */
43646c9d
KH
748 HOWTO ( (IMAGE_REL_PPC_TOCREL16 | IMAGE_REL_PPC_TOCDEFN), /* type */
749 0, /* rightshift */
750 1, /* size (0 = byte, 1 = short, 2 = long) */
751 16, /* bitsize */
b34976b6 752 FALSE, /* pc_relative */
43646c9d 753 0, /* bitpos */
252b5132 754 complain_overflow_dont, /* complain_on_overflow */
43646c9d 755 0, /* special_function */
252b5132 756 "TOCREL16, TOCDEFN", /* name */
b34976b6 757 FALSE, /* partial_inplace */
43646c9d
KH
758 0xffff, /* src_mask */
759 0xffff, /* dst_mask */
b34976b6 760 FALSE), /* pcrel_offset */
252b5132
RH
761
762};
252b5132 763\f
2ab1486e 764/* Some really cheezy macros that can be turned on to test stderr :-) */
252b5132
RH
765
766#ifdef DEBUG_RELOC
767#define UN_IMPL(x) \
768{ \
769 static int i; \
770 if (i == 0) \
771 { \
772 i = 1; \
6e301b2b 773 fprintf (stderr,_("Unimplemented Relocation -- %s\n"),x); \
252b5132
RH
774 } \
775}
776
777#define DUMP_RELOC(n,r) \
778{ \
6e301b2b 779 fprintf (stderr,"%s sym %d, addr %d, addend %d\n", \
252b5132
RH
780 n, (*(r->sym_ptr_ptr))->name, \
781 r->address, r->addend); \
782}
783
43646c9d
KH
784/* Given a reloc name, n, and a pointer to an internal_reloc,
785 dump out interesting information on the contents
252b5132
RH
786
787#define n_name _n._n_name
788#define n_zeroes _n._n_n._n_zeroes
2ab1486e 789#define n_offset _n._n_n._n_offset */
252b5132 790
2ab1486e
NC
791#define DUMP_RELOC2(n,r) \
792{ \
793 fprintf (stderr,"%s sym %d, r_vaddr %d %s\n", \
794 n, r->r_symndx, r->r_vaddr, \
252b5132 795 (((r->r_type) & IMAGE_REL_PPC_TOCDEFN) == 0) \
2ab1486e 796 ?" ":" TOCDEFN" ); \
252b5132
RH
797}
798
799#else
800#define UN_IMPL(x)
801#define DUMP_RELOC(n,r)
802#define DUMP_RELOC2(n,r)
803#endif
252b5132 804\f
2ab1486e 805/* TOC construction and management routines. */
252b5132
RH
806
807/* This file is compiled twice, and these variables are defined in one
808 of the compilations. FIXME: This is confusing and weird. Also,
809 BFD should not use global variables. */
2ab1486e 810extern bfd * bfd_of_toc_owner;
252b5132 811extern long int global_toc_size;
252b5132
RH
812extern long int import_table_size;
813extern long int first_thunk_address;
814extern long int thunk_size;
815
816enum toc_type
817{
818 default_toc,
819 toc_32,
820 toc_64
821};
822
823enum ref_category
824{
825 priv,
826 pub,
dc810e39 827 tocdata
252b5132
RH
828};
829
830struct list_ele
831{
832 struct list_ele *next;
833 bfd_vma addr;
834 enum ref_category cat;
835 int offset;
836 const char *name;
837};
838
839extern struct list_ele *head;
840extern struct list_ele *tail;
841
842static void record_toc
dc810e39 843 PARAMS ((asection *, bfd_signed_vma, enum ref_category, const char *));
252b5132
RH
844
845static void
846record_toc (toc_section, our_toc_offset, cat, name)
847 asection *toc_section;
dc810e39 848 bfd_signed_vma our_toc_offset;
252b5132
RH
849 enum ref_category cat;
850 const char *name;
851{
2ab1486e 852 /* Add this entry to our toc addr-offset-name list. */
dc810e39
AM
853 bfd_size_type amt = sizeof (struct list_ele);
854 struct list_ele *t = (struct list_ele *) bfd_malloc (amt);
855
252b5132
RH
856 if (t == NULL)
857 abort ();
858 t->next = 0;
859 t->offset = our_toc_offset;
860 t->name = name;
861 t->cat = cat;
862 t->addr = toc_section->output_offset + our_toc_offset;
863
864 if (head == 0)
865 {
866 head = t;
867 tail = t;
868 }
869 else
870 {
871 tail->next = t;
872 tail = t;
873 }
874}
875
876#ifdef COFF_IMAGE_WITH_PE
877
b34976b6 878static bfd_boolean ppc_record_toc_entry
252b5132
RH
879 PARAMS ((bfd *, struct bfd_link_info *, asection *, int, enum toc_type));
880static void ppc_mark_symbol_as_glue
881 PARAMS ((bfd *, int, struct internal_reloc *));
882
2ab1486e 883/* Record a toc offset against a symbol. */
b34976b6 884static bfd_boolean
252b5132
RH
885ppc_record_toc_entry(abfd, info, sec, sym, toc_kind)
886 bfd *abfd;
5f771d47
ILT
887 struct bfd_link_info *info ATTRIBUTE_UNUSED;
888 asection *sec ATTRIBUTE_UNUSED;
252b5132 889 int sym;
5f771d47 890 enum toc_type toc_kind ATTRIBUTE_UNUSED;
252b5132
RH
891{
892 struct ppc_coff_link_hash_entry *h;
893 const char *name;
894
895 int *local_syms;
896
897 h = 0;
898
899 h = (struct ppc_coff_link_hash_entry *) (obj_coff_sym_hashes (abfd)[sym]);
900 if (h != 0)
901 {
902 HASH_CHECK(h);
903 }
904
43646c9d
KH
905 if (h == 0)
906 {
252b5132 907 local_syms = obj_coff_local_toc_table(abfd);
2ab1486e 908
252b5132
RH
909 if (local_syms == 0)
910 {
911 unsigned int i;
dc810e39 912 bfd_size_type amt;
2ab1486e 913
252b5132 914 /* allocate a table */
dc810e39
AM
915 amt = (bfd_size_type) obj_raw_syment_count (abfd) * sizeof (int);
916 local_syms = (int *) bfd_zalloc (abfd, amt);
252b5132 917 if (local_syms == 0)
b34976b6 918 return FALSE;
dc810e39 919 obj_coff_local_toc_table (abfd) = local_syms;
2ab1486e 920
dc810e39 921 for (i = 0; i < obj_raw_syment_count (abfd); ++i)
252b5132 922 {
dc810e39 923 SET_UNALLOCATED (local_syms[i]);
252b5132
RH
924 }
925 }
926
43646c9d 927 if (IS_UNALLOCATED(local_syms[sym]))
252b5132
RH
928 {
929 local_syms[sym] = global_toc_size;
930 global_toc_size += 4;
931
5c4491d3 932 /* The size must fit in a 16-bit displacement. */
252b5132
RH
933 if (global_toc_size > 65535)
934 {
935 (*_bfd_error_handler) (_("TOC overflow"));
936 bfd_set_error (bfd_error_file_too_big);
b34976b6 937 return FALSE;
252b5132
RH
938 }
939 }
940 }
941 else
942 {
943 name = h->root.root.root.string;
944
2ab1486e
NC
945 /* Check to see if there's a toc slot allocated. If not, do it
946 here. It will be used in relocate_section. */
252b5132
RH
947 if (IS_UNALLOCATED(h->toc_offset))
948 {
949 h->toc_offset = global_toc_size;
950 global_toc_size += 4;
951
5c4491d3 952 /* The size must fit in a 16-bit displacement. */
252b5132
RH
953 if (global_toc_size >= 65535)
954 {
955 (*_bfd_error_handler) (_("TOC overflow"));
956 bfd_set_error (bfd_error_file_too_big);
b34976b6 957 return FALSE;
252b5132
RH
958 }
959 }
960 }
961
b34976b6 962 return TRUE;
252b5132
RH
963}
964
2ab1486e 965/* Record a toc offset against a symbol. */
252b5132
RH
966static void
967ppc_mark_symbol_as_glue(abfd, sym, rel)
968 bfd *abfd;
969 int sym;
970 struct internal_reloc *rel;
971{
972 struct ppc_coff_link_hash_entry *h;
973
974 h = (struct ppc_coff_link_hash_entry *) (obj_coff_sym_hashes (abfd)[sym]);
975
976 HASH_CHECK(h);
977
978 h->symbol_is_glue = 1;
979 h->glue_insn = bfd_get_32 (abfd, (bfd_byte *) &rel->r_vaddr);
980
981 return;
982}
983
984#endif /* COFF_IMAGE_WITH_PE */
985\f
b34976b6 986/* Return TRUE if this relocation should
43646c9d 987 appear in the output .reloc section. */
252b5132 988
b34976b6 989static bfd_boolean in_reloc_p(abfd, howto)
5f771d47 990 bfd * abfd ATTRIBUTE_UNUSED;
252b5132
RH
991 reloc_howto_type *howto;
992{
43646c9d
KH
993 return
994 (! howto->pc_relative)
252b5132
RH
995 && (howto->type != IMAGE_REL_PPC_ADDR32NB)
996 && (howto->type != IMAGE_REL_PPC_TOCREL16)
997 && (howto->type != IMAGE_REL_PPC_IMGLUE)
43646c9d 998 && (howto->type != IMAGE_REL_PPC_IFGLUE)
252b5132
RH
999 && (howto->type != IMAGE_REL_PPC_SECREL)
1000 && (howto->type != IMAGE_REL_PPC_SECTION)
1001 && (howto->type != IMAGE_REL_PPC_SECREL16)
1002 && (howto->type != IMAGE_REL_PPC_REFHI)
1003 && (howto->type != IMAGE_REL_PPC_REFLO)
1004 && (howto->type != IMAGE_REL_PPC_PAIR)
1005 && (howto->type != IMAGE_REL_PPC_TOCREL16_DEFN) ;
43646c9d 1006}
252b5132
RH
1007
1008#if 0
1009
2ab1486e
NC
1010/* This function is in charge of performing all the ppc PE relocations
1011 Don't yet know if we want to do this this particular way ... (krk). */
1012/* FIXME: (it is not yet enabled). */
252b5132
RH
1013
1014static bfd_reloc_status_type
1015pe_ppc_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd,
1016 error_message)
1017 bfd *abfd;
1018 arelent *reloc_entry;
1019 asymbol *symbol_in;
1020 PTR data;
1021 asection *input_section;
1022 bfd *output_bfd;
1023 char **error_message;
1024{
2ab1486e
NC
1025 /* The consth relocation comes in two parts, we have to remember
1026 the state between calls, in these variables. */
b34976b6 1027 static bfd_boolean part1_consth_active = FALSE;
252b5132
RH
1028 static unsigned long part1_consth_value;
1029
1030 unsigned long sym_value;
1031 unsigned short r_type;
1032 unsigned long addr = reloc_entry->address ; /*+ input_section->vma*/
43646c9d 1033
252b5132
RH
1034 r_type = reloc_entry->howto->type;
1035
43646c9d 1036 if (output_bfd)
252b5132 1037 {
2ab1486e 1038 /* Partial linking - do nothing. */
252b5132 1039 reloc_entry->address += input_section->output_offset;
43646c9d 1040 return bfd_reloc_ok;
252b5132
RH
1041 }
1042
1043 if (symbol_in != NULL
1044 && bfd_is_und_section (symbol_in->section))
1045 {
2ab1486e 1046 /* Keep the state machine happy in case we're called again. */
43646c9d 1047 if (r_type == IMAGE_REL_PPC_REFHI)
252b5132 1048 {
b34976b6 1049 part1_consth_active = TRUE;
252b5132
RH
1050 part1_consth_value = 0;
1051 }
1052 return(bfd_reloc_undefined);
1053 }
43646c9d
KH
1054
1055 if ((part1_consth_active) && (r_type != IMAGE_REL_PPC_PAIR))
252b5132 1056 {
b34976b6 1057 part1_consth_active = FALSE;
252b5132
RH
1058 *error_message = (char *) _("Missing PAIR");
1059 return(bfd_reloc_dangerous);
1060 }
1061
252b5132 1062 sym_value = get_symbol_value(symbol_in);
43646c9d
KH
1063
1064 return(bfd_reloc_ok);
252b5132
RH
1065}
1066
1067#endif /* 0 */
1068
1069/* The reloc processing routine for the optimized COFF linker. */
1070
b34976b6 1071static bfd_boolean
252b5132
RH
1072coff_ppc_relocate_section (output_bfd, info, input_bfd, input_section,
1073 contents, relocs, syms, sections)
1074 bfd *output_bfd;
1075 struct bfd_link_info *info;
1076 bfd *input_bfd;
1077 asection *input_section;
1078 bfd_byte *contents;
1079 struct internal_reloc *relocs;
1080 struct internal_syment *syms;
1081 asection **sections;
1082{
1083 struct internal_reloc *rel;
1084 struct internal_reloc *relend;
b34976b6 1085 bfd_boolean hihalf;
252b5132
RH
1086 bfd_vma hihalf_val;
1087 asection *toc_section = 0;
1088 bfd_vma relocation;
1089 reloc_howto_type *howto = 0;
43646c9d 1090
1049f94e 1091 /* If we are performing a relocatable link, we don't need to do a
252b5132
RH
1092 thing. The caller will take care of adjusting the reloc
1093 addresses and symbol indices. */
1049f94e 1094 if (info->relocatable)
b34976b6 1095 return TRUE;
43646c9d 1096
b34976b6 1097 hihalf = FALSE;
252b5132
RH
1098 hihalf_val = 0;
1099
1100 rel = relocs;
1101 relend = rel + input_section->reloc_count;
1102 for (; rel < relend; rel++)
1103 {
1104 long symndx;
1105 struct ppc_coff_link_hash_entry *h;
1106 struct internal_syment *sym;
1107 bfd_vma val;
1108
1109 asection *sec;
1110 bfd_reloc_status_type rstat;
1111 bfd_byte *loc;
1112
1113 unsigned short r_type = EXTRACT_TYPE (rel->r_type);
1114 unsigned short r_flags = EXTRACT_FLAGS(rel->r_type);
43646c9d 1115
252b5132
RH
1116 symndx = rel->r_symndx;
1117 loc = contents + rel->r_vaddr - input_section->vma;
1118
1119 /* FIXME: check bounds on r_type */
1120 howto = ppc_coff_howto_table + r_type;
1121
1122 if (symndx == -1)
1123 {
1124 h = NULL;
1125 sym = NULL;
1126 }
1127 else
1128 {
43646c9d 1129 h = (struct ppc_coff_link_hash_entry *)
252b5132 1130 (obj_coff_sym_hashes (input_bfd)[symndx]);
43646c9d 1131 if (h != 0)
252b5132
RH
1132 {
1133 HASH_CHECK(h);
1134 }
1135
1136 sym = syms + symndx;
1137 }
1138
1139 if (r_type == IMAGE_REL_PPC_IMGLUE && h == 0)
1140 {
43646c9d 1141 /* An IMGLUE reloc must have a name. Something is very wrong. */
c5930ee6 1142 abort ();
252b5132
RH
1143 }
1144
1145 sec = NULL;
1146 val = 0;
1147
2ab1486e 1148 /* FIXME: PAIR unsupported in the following code. */
252b5132
RH
1149 if (h == NULL)
1150 {
1151 if (symndx == -1)
1152 sec = bfd_abs_section_ptr;
1153 else
1154 {
1155 sec = sections[symndx];
1156 val = (sec->output_section->vma
1157 + sec->output_offset
1158 + sym->n_value);
1159 if (! obj_pe (output_bfd))
1160 val -= sec->vma;
1161 }
1162 }
1163 else
1164 {
1165 HASH_CHECK(h);
1166
1167 if (h->root.root.type == bfd_link_hash_defined
1168 || h->root.root.type == bfd_link_hash_defweak)
1169 {
1170 sec = h->root.root.u.def.section;
1171 val = (h->root.root.u.def.value
1172 + sec->output_section->vma
1173 + sec->output_offset);
1174 }
1175 else
1176 {
1177 if (! ((*info->callbacks->undefined_symbol)
1178 (info, h->root.root.root.string, input_bfd, input_section,
b34976b6
AM
1179 rel->r_vaddr - input_section->vma, TRUE)))
1180 return FALSE;
252b5132
RH
1181 }
1182 }
1183
1184 rstat = bfd_reloc_ok;
43646c9d 1185
2ab1486e 1186 /* Each case must do its own relocation, setting rstat appropriately. */
252b5132
RH
1187 switch (r_type)
1188 {
1189 default:
1190 (*_bfd_error_handler)
d003868e 1191 (_("%B: unsupported relocation type 0x%02x"), input_bfd, r_type);
252b5132 1192 bfd_set_error (bfd_error_bad_value);
b34976b6 1193 return FALSE;
252b5132
RH
1194 case IMAGE_REL_PPC_TOCREL16:
1195 {
dc810e39 1196 bfd_signed_vma our_toc_offset;
252b5132
RH
1197 int fixit;
1198
1199 DUMP_RELOC2(howto->name, rel);
1200
43646c9d 1201 if (toc_section == 0)
252b5132 1202 {
43646c9d 1203 toc_section = bfd_get_section_by_name (bfd_of_toc_owner,
252b5132
RH
1204 TOC_SECTION_NAME);
1205
43646c9d 1206 if ( toc_section == NULL )
252b5132 1207 {
43646c9d 1208 /* There is no toc section. Something is very wrong. */
c5930ee6 1209 abort ();
252b5132
RH
1210 }
1211 }
1212
2ab1486e
NC
1213 /* Amazing bit tricks present. As we may have seen earlier, we
1214 use the 1 bit to tell us whether or not a toc offset has been
1215 allocated. Now that they've all been allocated, we will use
1216 the 1 bit to tell us if we've written this particular toc
1217 entry out. */
b34976b6 1218 fixit = FALSE;
252b5132 1219 if (h == 0)
2ab1486e
NC
1220 {
1221 /* It is a file local symbol. */
252b5132
RH
1222 int *local_toc_table;
1223 const char *name;
1224
1225 sym = syms + symndx;
1226 name = sym->_n._n_name;
1227
1228 local_toc_table = obj_coff_local_toc_table(input_bfd);
1229 our_toc_offset = local_toc_table[symndx];
1230
1231 if (IS_WRITTEN(our_toc_offset))
1232 {
2ab1486e 1233 /* If it has been written out, it is marked with the
252b5132 1234 1 bit. Fix up our offset, but do not write it out
2ab1486e 1235 again. */
252b5132
RH
1236 MAKE_ADDR_AGAIN(our_toc_offset);
1237 }
1238 else
1239 {
2ab1486e 1240 /* Write out the toc entry. */
dc810e39
AM
1241 record_toc (toc_section, our_toc_offset, priv,
1242 strdup (name));
252b5132 1243
dc810e39 1244 bfd_put_32 (output_bfd, val,
252b5132
RH
1245 toc_section->contents + our_toc_offset);
1246
1247 MARK_AS_WRITTEN(local_toc_table[symndx]);
b34976b6 1248 fixit = TRUE;
252b5132
RH
1249 }
1250 }
1251 else
1252 {
1253 const char *name = h->root.root.root.string;
1254 our_toc_offset = h->toc_offset;
1255
43646c9d 1256 if ((r_flags & IMAGE_REL_PPC_TOCDEFN)
252b5132
RH
1257 == IMAGE_REL_PPC_TOCDEFN )
1258 {
43646c9d
KH
1259 /* This is unbelievable cheese. Some knowledgable asm
1260 hacker has decided to use r2 as a base for loading
1261 a value. He/She does this by setting the tocdefn bit,
1262 and not supplying a toc definition. The behaviour is
1263 then to use the difference between the value of the
1264 symbol and the actual location of the toc as the toc
1265 index.
252b5132
RH
1266
1267 In fact, what is usually happening is, because the
1268 Import Address Table is mapped immediately following
1269 the toc, some trippy library code trying for speed on
43646c9d 1270 dll linkage, takes advantage of that and considers
2ab1486e 1271 the IAT to be part of the toc, thus saving a load. */
252b5132 1272
dc810e39
AM
1273 our_toc_offset = val - (toc_section->output_section->vma
1274 + toc_section->output_offset);
252b5132 1275
5c4491d3 1276 /* The size must still fit in a 16-bit displacement. */
dc810e39 1277 if ((bfd_vma) our_toc_offset >= 65535)
252b5132
RH
1278 {
1279 (*_bfd_error_handler)
d003868e
AM
1280 (_("%B: Relocation for %s of %lx exceeds Toc size limit"),
1281 input_bfd, name,
dc810e39 1282 (unsigned long) our_toc_offset);
252b5132 1283 bfd_set_error (bfd_error_bad_value);
b34976b6 1284 return FALSE;
252b5132
RH
1285 }
1286
dc810e39
AM
1287 record_toc (toc_section, our_toc_offset, pub,
1288 strdup (name));
252b5132 1289 }
2ab1486e 1290 else if (IS_WRITTEN (our_toc_offset))
252b5132 1291 {
2ab1486e 1292 /* If it has been written out, it is marked with the
252b5132 1293 1 bit. Fix up our offset, but do not write it out
2ab1486e 1294 again. */
252b5132
RH
1295 MAKE_ADDR_AGAIN(our_toc_offset);
1296 }
1297 else
1298 {
dc810e39
AM
1299 record_toc(toc_section, our_toc_offset, pub,
1300 strdup (name));
252b5132 1301
2ab1486e 1302 /* Write out the toc entry. */
dc810e39 1303 bfd_put_32 (output_bfd, val,
252b5132
RH
1304 toc_section->contents + our_toc_offset);
1305
1306 MARK_AS_WRITTEN(h->toc_offset);
2ab1486e
NC
1307 /* The tricky part is that this is the address that
1308 needs a .reloc entry for it. */
b34976b6 1309 fixit = TRUE;
252b5132
RH
1310 }
1311 }
1312
43646c9d 1313 if (fixit && info->base_file)
252b5132
RH
1314 {
1315 /* So if this is non pcrelative, and is referenced
2ab1486e 1316 to a section or a common symbol, then it needs a reloc. */
252b5132 1317
2ab1486e 1318 /* Relocation to a symbol in a section which
43646c9d 1319 isn't absolute - we output the address here
2ab1486e 1320 to a file. */
dc810e39
AM
1321 bfd_vma addr = (toc_section->output_section->vma
1322 + toc_section->output_offset + our_toc_offset);
43646c9d 1323
2ab1486e 1324 if (coff_data (output_bfd)->pe)
252b5132
RH
1325 addr -= pe_data(output_bfd)->pe_opthdr.ImageBase;
1326
1327 fwrite (&addr, 1,4, (FILE *) info->base_file);
1328 }
1329
2ab1486e 1330 /* FIXME: this test is conservative. */
dc810e39 1331 if ((r_flags & IMAGE_REL_PPC_TOCDEFN) != IMAGE_REL_PPC_TOCDEFN
eea6121a 1332 && (bfd_vma) our_toc_offset > toc_section->size)
252b5132
RH
1333 {
1334 (*_bfd_error_handler)
d003868e
AM
1335 (_("%B: Relocation exceeds allocated TOC (%lx)"),
1336 input_bfd, (unsigned long) toc_section->size);
252b5132 1337 bfd_set_error (bfd_error_bad_value);
b34976b6 1338 return FALSE;
252b5132
RH
1339 }
1340
2ab1486e 1341 /* Now we know the relocation for this toc reference. */
252b5132 1342 relocation = our_toc_offset + TOC_LOAD_ADJUSTMENT;
dc810e39 1343 rstat = _bfd_relocate_contents (howto, input_bfd, relocation, loc);
252b5132
RH
1344 }
1345 break;
1346 case IMAGE_REL_PPC_IFGLUE:
1347 {
2ab1486e
NC
1348 /* To solve this, we need to know whether or not the symbol
1349 appearing on the call instruction is a glue function or not.
1350 A glue function must announce itself via a IMGLUE reloc, and
1351 the reloc contains the required toc restore instruction. */
252b5132
RH
1352 bfd_vma x;
1353 const char *my_name;
2ab1486e
NC
1354
1355 DUMP_RELOC2 (howto->name, rel);
252b5132
RH
1356
1357 if (h != 0)
1358 {
1359 my_name = h->root.root.root.string;
43646c9d 1360 if (h->symbol_is_glue == 1)
252b5132 1361 {
6e301b2b 1362 x = bfd_get_32 (input_bfd, loc);
dc810e39 1363 bfd_put_32 (input_bfd, (bfd_vma) h->glue_insn, loc);
252b5132
RH
1364 }
1365 }
1366 }
1367 break;
1368 case IMAGE_REL_PPC_SECREL:
2ab1486e 1369 /* Unimplemented: codeview debugging information. */
43646c9d
KH
1370 /* For fast access to the header of the section
1371 containing the item. */
252b5132
RH
1372 break;
1373 case IMAGE_REL_PPC_SECTION:
2ab1486e 1374 /* Unimplemented: codeview debugging information. */
252b5132
RH
1375 /* Is used to indicate that the value should be relative
1376 to the beginning of the section that contains the
2ab1486e 1377 symbol. */
252b5132
RH
1378 break;
1379 case IMAGE_REL_PPC_ABSOLUTE:
1380 {
1381 const char *my_name;
2ab1486e 1382
252b5132 1383 if (h == 0)
2ab1486e 1384 my_name = (syms+symndx)->_n._n_name;
252b5132 1385 else
2ab1486e 1386 my_name = h->root.root.root.string;
252b5132 1387
d003868e
AM
1388 (*_bfd_error_handler)
1389 (_("Warning: unsupported reloc %s <file %B, section %A>\n"
1390 "sym %ld (%s), r_vaddr %ld (%lx)"),
1391 input_bfd, input_section, howto->name,
1392 rel->r_symndx, my_name, (long) rel->r_vaddr,
1393 (unsigned long) rel->r_vaddr);
252b5132
RH
1394 }
1395 break;
1396 case IMAGE_REL_PPC_IMGLUE:
1397 {
1398 /* There is nothing to do now. This reloc was noted in the first
2ab1486e 1399 pass over the relocs, and the glue instruction extracted. */
252b5132 1400 const char *my_name;
2ab1486e 1401
43646c9d 1402 if (h->symbol_is_glue == 1)
252b5132
RH
1403 break;
1404 my_name = h->root.root.root.string;
1405
1406 (*_bfd_error_handler)
d003868e 1407 (_("%B: Out of order IMGLUE reloc for %s"), input_bfd, my_name);
252b5132 1408 bfd_set_error (bfd_error_bad_value);
b34976b6 1409 return FALSE;
252b5132
RH
1410 }
1411
1412 case IMAGE_REL_PPC_ADDR32NB:
1413 {
252b5132 1414 const char *name = 0;
2ab1486e
NC
1415
1416 DUMP_RELOC2 (howto->name, rel);
252b5132
RH
1417
1418 if (strncmp(".idata$2",input_section->name,8) == 0 && first_thunk_address == 0)
1419 {
2ab1486e 1420 /* Set magic values. */
252b5132 1421 int idata5offset;
dc810e39 1422 struct coff_link_hash_entry *myh;
2ab1486e 1423
252b5132
RH
1424 myh = coff_link_hash_lookup (coff_hash_table (info),
1425 "__idata5_magic__",
b34976b6 1426 FALSE, FALSE, TRUE);
43646c9d
KH
1427 first_thunk_address = myh->root.u.def.value +
1428 sec->output_section->vma +
1429 sec->output_offset -
252b5132 1430 pe_data(output_bfd)->pe_opthdr.ImageBase;
43646c9d 1431
252b5132
RH
1432 idata5offset = myh->root.u.def.value;
1433 myh = coff_link_hash_lookup (coff_hash_table (info),
1434 "__idata6_magic__",
b34976b6 1435 FALSE, FALSE, TRUE);
43646c9d 1436
252b5132
RH
1437 thunk_size = myh->root.u.def.value - idata5offset;
1438 myh = coff_link_hash_lookup (coff_hash_table (info),
1439 "__idata4_magic__",
b34976b6 1440 FALSE, FALSE, TRUE);
252b5132
RH
1441 import_table_size = myh->root.u.def.value;
1442 }
1443
1444 if (h == 0)
2ab1486e
NC
1445 {
1446 /* It is a file local symbol. */
252b5132
RH
1447 sym = syms + symndx;
1448 name = sym->_n._n_name;
1449 }
1450 else
1451 {
1452 char *target = 0;
1453
1454 name = h->root.root.root.string;
2ab1486e 1455 if (strcmp (".idata$2", name) == 0)
252b5132 1456 target = "__idata2_magic__";
2ab1486e 1457 else if (strcmp (".idata$4", name) == 0)
252b5132 1458 target = "__idata4_magic__";
2ab1486e 1459 else if (strcmp (".idata$5", name) == 0)
252b5132
RH
1460 target = "__idata5_magic__";
1461
1462 if (target != 0)
1463 {
dc810e39 1464 struct coff_link_hash_entry *myh;
252b5132
RH
1465
1466 myh = coff_link_hash_lookup (coff_hash_table (info),
1467 target,
b34976b6 1468 FALSE, FALSE, TRUE);
43646c9d 1469 if (myh == 0)
252b5132 1470 {
43646c9d 1471 /* Missing magic cookies. Something is very wrong. */
c5930ee6 1472 abort ();
252b5132 1473 }
43646c9d
KH
1474
1475 val = myh->root.u.def.value +
252b5132
RH
1476 sec->output_section->vma + sec->output_offset;
1477 if (first_thunk_address == 0)
1478 {
1479 int idata5offset;
1480 myh = coff_link_hash_lookup (coff_hash_table (info),
1481 "__idata5_magic__",
b34976b6 1482 FALSE, FALSE, TRUE);
43646c9d
KH
1483 first_thunk_address = myh->root.u.def.value +
1484 sec->output_section->vma +
1485 sec->output_offset -
252b5132 1486 pe_data(output_bfd)->pe_opthdr.ImageBase;
43646c9d 1487
252b5132
RH
1488 idata5offset = myh->root.u.def.value;
1489 myh = coff_link_hash_lookup (coff_hash_table (info),
1490 "__idata6_magic__",
b34976b6 1491 FALSE, FALSE, TRUE);
43646c9d 1492
252b5132
RH
1493 thunk_size = myh->root.u.def.value - idata5offset;
1494 myh = coff_link_hash_lookup (coff_hash_table (info),
1495 "__idata4_magic__",
b34976b6 1496 FALSE, FALSE, TRUE);
252b5132
RH
1497 import_table_size = myh->root.u.def.value;
1498 }
1499 }
1500 }
1501
1502 rstat = _bfd_relocate_contents (howto,
2ab1486e
NC
1503 input_bfd,
1504 val -
1505 pe_data (output_bfd)->pe_opthdr.ImageBase,
1506 loc);
252b5132
RH
1507 }
1508 break;
1509
1510 case IMAGE_REL_PPC_REL24:
1511 DUMP_RELOC2(howto->name, rel);
1512 val -= (input_section->output_section->vma
1513 + input_section->output_offset);
1514
1515 rstat = _bfd_relocate_contents (howto,
43646c9d
KH
1516 input_bfd,
1517 val,
252b5132
RH
1518 loc);
1519 break;
1520 case IMAGE_REL_PPC_ADDR16:
1521 case IMAGE_REL_PPC_ADDR24:
1522 case IMAGE_REL_PPC_ADDR32:
1523 DUMP_RELOC2(howto->name, rel);
1524 rstat = _bfd_relocate_contents (howto,
43646c9d
KH
1525 input_bfd,
1526 val,
252b5132
RH
1527 loc);
1528 break;
1529 }
1530
2ab1486e 1531 if (info->base_file)
252b5132
RH
1532 {
1533 /* So if this is non pcrelative, and is referenced
2ab1486e
NC
1534 to a section or a common symbol, then it needs a reloc. */
1535 if (sym && pe_data(output_bfd)->in_reloc_p (output_bfd, howto))
252b5132 1536 {
2ab1486e 1537 /* Relocation to a symbol in a section which
43646c9d 1538 isn't absolute - we output the address here
2ab1486e 1539 to a file. */
43646c9d
KH
1540 bfd_vma addr = rel->r_vaddr
1541 - input_section->vma
1542 + input_section->output_offset
252b5132
RH
1543 + input_section->output_section->vma;
1544
2ab1486e
NC
1545 if (coff_data (output_bfd)->pe)
1546 addr -= pe_data (output_bfd)->pe_opthdr.ImageBase;
1547
252b5132
RH
1548 fwrite (&addr, 1,4, (FILE *) info->base_file);
1549 }
1550 }
1551
1552 switch (rstat)
1553 {
1554 default:
1555 abort ();
1556 case bfd_reloc_ok:
1557 break;
1558 case bfd_reloc_overflow:
1559 {
1560 const char *name;
1561 char buf[SYMNMLEN + 1];
1562
1563 if (symndx == -1)
1564 name = "*ABS*";
1565 else if (h != NULL)
1566 name = h->root.root.root.string;
1567 else if (sym == NULL)
1568 name = "*unknown*";
1569 else if (sym->_n._n_n._n_zeroes == 0
1570 && sym->_n._n_n._n_offset != 0)
1571 name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset;
1572 else
1573 {
1574 strncpy (buf, sym->_n._n_name, SYMNMLEN);
1575 buf[SYMNMLEN] = '\0';
1576 name = buf;
1577 }
1578
1579 if (! ((*info->callbacks->reloc_overflow)
43646c9d 1580 (info, name, howto->name,
252b5132
RH
1581 (bfd_vma) 0, input_bfd,
1582 input_section, rel->r_vaddr - input_section->vma)))
2ab1486e 1583 return FALSE;
252b5132
RH
1584 }
1585 }
43646c9d 1586 }
252b5132 1587
b34976b6 1588 return TRUE;
252b5132
RH
1589}
1590
1591#ifdef COFF_IMAGE_WITH_PE
1592
1593/* FIXME: BFD should not use global variables. This file is compiled
1594 twice, and these variables are shared. This is confusing and
1595 weird. */
1596
1597long int global_toc_size = 4;
1598
1599bfd* bfd_of_toc_owner = 0;
1600
1601long int import_table_size;
1602long int first_thunk_address;
1603long int thunk_size;
1604
1605struct list_ele *head;
1606struct list_ele *tail;
1607
1608static char *
1609h1 = N_("\n\t\t\tTOC MAPPING\n\n");
1610static char *
1611h2 = N_(" TOC disassembly Comments Name\n");
1612static char *
1613h3 = N_(" Offset spelling (if present)\n");
1614
1615void
1616dump_toc (vfile)
1617 PTR vfile;
1618{
1619 FILE *file = (FILE *) vfile;
1620 struct list_ele *t;
1621
6e301b2b
KH
1622 fprintf (file, _(h1));
1623 fprintf (file, _(h2));
1624 fprintf (file, _(h3));
252b5132 1625
6e301b2b 1626 for (t = head; t != 0; t=t->next)
252b5132
RH
1627 {
1628 const char *cat = "";
1629
1630 if (t->cat == priv)
1631 cat = _("private ");
1632 else if (t->cat == pub)
1633 cat = _("public ");
dc810e39 1634 else if (t->cat == tocdata)
252b5132
RH
1635 cat = _("data-in-toc ");
1636
1637 if (t->offset > global_toc_size)
1638 {
1639 if (t->offset <= global_toc_size + thunk_size)
1640 cat = _("IAT reference ");
1641 else
1642 {
6e301b2b 1643 fprintf (file,
252b5132 1644 _("**** global_toc_size %ld(%lx), thunk_size %ld(%lx)\n"),
dc810e39
AM
1645 global_toc_size, global_toc_size,
1646 thunk_size, thunk_size);
252b5132
RH
1647 cat = _("Out of bounds!");
1648 }
1649 }
1650
6e301b2b 1651 fprintf (file,
252b5132 1652 " %04lx (%d)", (unsigned long) t->offset, t->offset - 32768);
6e301b2b 1653 fprintf (file,
252b5132
RH
1654 " %s %s\n",
1655 cat, t->name);
1656
1657 }
1658
6e301b2b 1659 fprintf (file, "\n");
252b5132
RH
1660}
1661
b34976b6 1662bfd_boolean
43646c9d 1663ppc_allocate_toc_section (info)
5f771d47 1664 struct bfd_link_info *info ATTRIBUTE_UNUSED;
252b5132
RH
1665{
1666 asection *s;
1667 bfd_byte *foo;
dc810e39 1668 bfd_size_type amt;
252b5132
RH
1669 static char test_char = '1';
1670
2ab1486e 1671 if ( global_toc_size == 0 ) /* FIXME: does this get me in trouble? */
b34976b6 1672 return TRUE;
252b5132
RH
1673
1674 if (bfd_of_toc_owner == 0)
2ab1486e
NC
1675 /* No toc owner? Something is very wrong. */
1676 abort ();
252b5132
RH
1677
1678 s = bfd_get_section_by_name ( bfd_of_toc_owner , TOC_SECTION_NAME);
43646c9d 1679 if (s == NULL)
2ab1486e
NC
1680 /* No toc section? Something is very wrong. */
1681 abort ();
252b5132 1682
dc810e39
AM
1683 amt = global_toc_size;
1684 foo = (bfd_byte *) bfd_alloc (bfd_of_toc_owner, amt);
1685 memset(foo, test_char, (size_t) global_toc_size);
252b5132 1686
eea6121a 1687 s->size = global_toc_size;
252b5132
RH
1688 s->contents = foo;
1689
b34976b6 1690 return TRUE;
252b5132
RH
1691}
1692
b34976b6 1693bfd_boolean
252b5132
RH
1694ppc_process_before_allocation (abfd, info)
1695 bfd *abfd;
1696 struct bfd_link_info *info;
1697{
1698 asection *sec;
1699 struct internal_reloc *i, *rel;
1700
2ab1486e 1701 /* Here we have a bfd that is to be included on the link. We have a hook
43646c9d 1702 to do reloc rummaging, before section sizes are nailed down. */
2ab1486e 1703 _bfd_coff_get_external_symbols (abfd);
252b5132 1704
2ab1486e 1705 /* Rummage around all the relocs and map the toc. */
252b5132
RH
1706 sec = abfd->sections;
1707
1708 if (sec == 0)
2ab1486e 1709 return TRUE;
252b5132
RH
1710
1711 for (; sec != 0; sec = sec->next)
2ab1486e
NC
1712 {
1713 if (sec->reloc_count == 0)
1714 continue;
252b5132 1715
2ab1486e
NC
1716 /* load the relocs */
1717 /* FIXME: there may be a storage leak here */
1718 i=_bfd_coff_read_internal_relocs(abfd,sec,1,0,0,0);
43646c9d 1719
2ab1486e
NC
1720 if (i == 0)
1721 abort ();
252b5132 1722
2ab1486e
NC
1723 for (rel = i; rel < i + sec->reloc_count; ++rel)
1724 {
1725 unsigned short r_type = EXTRACT_TYPE (rel->r_type);
1726 unsigned short r_flags = EXTRACT_FLAGS (rel->r_type);
1727 bfd_boolean ok = TRUE;
252b5132 1728
2ab1486e 1729 DUMP_RELOC2 (ppc_coff_howto_table[r_type].name, rel);
252b5132 1730
2ab1486e
NC
1731 switch(r_type)
1732 {
1733 case IMAGE_REL_PPC_TOCREL16:
1734 /* If TOCDEFN is on, ignore as someone else has allocated the
1735 toc entry. */
1736 if ((r_flags & IMAGE_REL_PPC_TOCDEFN) != IMAGE_REL_PPC_TOCDEFN)
1737 ok = ppc_record_toc_entry(abfd, info, sec,
1738 rel->r_symndx, default_toc);
1739 if (!ok)
1740 return FALSE;
1741 break;
1742 case IMAGE_REL_PPC_IMGLUE:
1743 ppc_mark_symbol_as_glue (abfd, rel->r_symndx, rel);
1744 break;
1745 default:
1746 break;
1747 }
1748 }
1749 }
252b5132 1750
b34976b6 1751 return TRUE;
252b5132
RH
1752}
1753
1754#endif
1755
252b5132 1756static bfd_reloc_status_type
2ab1486e
NC
1757ppc_refhi_reloc (abfd, reloc_entry, symbol, data,
1758 input_section, output_bfd, error_message)
5f771d47
ILT
1759 bfd *abfd ATTRIBUTE_UNUSED;
1760 arelent *reloc_entry ATTRIBUTE_UNUSED;
1761 asymbol *symbol ATTRIBUTE_UNUSED;
1762 PTR data ATTRIBUTE_UNUSED;
1763 asection *input_section ATTRIBUTE_UNUSED;
252b5132 1764 bfd *output_bfd;
5f771d47 1765 char **error_message ATTRIBUTE_UNUSED;
252b5132
RH
1766{
1767 UN_IMPL("REFHI");
1768 DUMP_RELOC("REFHI",reloc_entry);
1769
1770 if (output_bfd == (bfd *) NULL)
1771 return bfd_reloc_continue;
1772
1773 return bfd_reloc_undefined;
1774}
1775
1776#if 0
1777
1778static bfd_reloc_status_type
2ab1486e
NC
1779ppc_reflo_reloc (abfd, reloc_entry, symbol, data,
1780 input_section, output_bfd, error_message)
252b5132
RH
1781 bfd *abfd;
1782 arelent *reloc_entry;
1783 asymbol *symbol;
1784 PTR data;
1785 asection *input_section;
1786 bfd *output_bfd;
1787 char **error_message;
1788{
1789 UN_IMPL("REFLO");
1790 DUMP_RELOC("REFLO",reloc_entry);
1791
1792 if (output_bfd == (bfd *) NULL)
1793 return bfd_reloc_continue;
1794
1795 return bfd_reloc_undefined;
1796}
1797
1798#endif
1799
1800static bfd_reloc_status_type
2ab1486e
NC
1801ppc_pair_reloc (abfd, reloc_entry, symbol, data,
1802 input_section, output_bfd, error_message)
5f771d47
ILT
1803 bfd *abfd ATTRIBUTE_UNUSED;
1804 arelent *reloc_entry ATTRIBUTE_UNUSED;
1805 asymbol *symbol ATTRIBUTE_UNUSED;
1806 PTR data ATTRIBUTE_UNUSED;
1807 asection *input_section ATTRIBUTE_UNUSED;
252b5132 1808 bfd *output_bfd;
5f771d47 1809 char **error_message ATTRIBUTE_UNUSED;
252b5132
RH
1810{
1811 UN_IMPL("PAIR");
1812 DUMP_RELOC("PAIR",reloc_entry);
1813
1814 if (output_bfd == (bfd *) NULL)
1815 return bfd_reloc_continue;
1816
1817 return bfd_reloc_undefined;
1818}
252b5132
RH
1819\f
1820static bfd_reloc_status_type
2ab1486e
NC
1821ppc_toc16_reloc (abfd, reloc_entry, symbol, data,
1822 input_section, output_bfd, error_message)
5f771d47
ILT
1823 bfd *abfd ATTRIBUTE_UNUSED;
1824 arelent *reloc_entry ATTRIBUTE_UNUSED;
1825 asymbol *symbol ATTRIBUTE_UNUSED;
1826 PTR data ATTRIBUTE_UNUSED;
1827 asection *input_section ATTRIBUTE_UNUSED;
252b5132 1828 bfd *output_bfd;
5f771d47 1829 char **error_message ATTRIBUTE_UNUSED;
252b5132 1830{
2ab1486e
NC
1831 UN_IMPL ("TOCREL16");
1832 DUMP_RELOC ("TOCREL16",reloc_entry);
252b5132
RH
1833
1834 if (output_bfd == (bfd *) NULL)
2ab1486e 1835 return bfd_reloc_continue;
252b5132
RH
1836
1837 return bfd_reloc_ok;
1838}
1839
1840#if 0
1841
2ab1486e
NC
1842/* ADDR32NB : 32 bit address relative to the virtual origin.
1843 (On the alpha, this is always a linker generated thunk)
1844 (i.e. 32bit addr relative to the image base). */
252b5132
RH
1845
1846static bfd_reloc_status_type
2ab1486e
NC
1847ppc_addr32nb_reloc (abfd, reloc_entry, symbol, data,
1848 input_section, output_bfd, error_message)
252b5132
RH
1849 bfd *abfd;
1850 arelent *reloc_entry;
1851 asymbol *symbol;
1852 PTR data;
1853 asection *input_section;
1854 bfd *output_bfd;
1855 char **error_message;
1856{
1857 UN_IMPL("ADDR32NB");
1858 DUMP_RELOC("ADDR32NB",reloc_entry);
1859
1860 return bfd_reloc_ok;
1861}
1862
1863#endif
1864
1865static bfd_reloc_status_type
2ab1486e
NC
1866ppc_secrel_reloc (abfd, reloc_entry, symbol, data,
1867 input_section, output_bfd, error_message)
5f771d47
ILT
1868 bfd *abfd ATTRIBUTE_UNUSED;
1869 arelent *reloc_entry ATTRIBUTE_UNUSED;
1870 asymbol *symbol ATTRIBUTE_UNUSED;
1871 PTR data ATTRIBUTE_UNUSED;
1872 asection *input_section ATTRIBUTE_UNUSED;
252b5132 1873 bfd *output_bfd;
5f771d47 1874 char **error_message ATTRIBUTE_UNUSED;
252b5132
RH
1875{
1876 UN_IMPL("SECREL");
1877 DUMP_RELOC("SECREL",reloc_entry);
1878
1879 if (output_bfd == (bfd *) NULL)
1880 return bfd_reloc_continue;
1881
1882 return bfd_reloc_ok;
1883}
1884
1885static bfd_reloc_status_type
2ab1486e
NC
1886ppc_section_reloc (abfd, reloc_entry, symbol, data,
1887 input_section, output_bfd, error_message)
5f771d47
ILT
1888 bfd *abfd ATTRIBUTE_UNUSED;
1889 arelent *reloc_entry ATTRIBUTE_UNUSED;
1890 asymbol *symbol ATTRIBUTE_UNUSED;
1891 PTR data ATTRIBUTE_UNUSED;
1892 asection *input_section ATTRIBUTE_UNUSED;
252b5132 1893 bfd *output_bfd;
5f771d47 1894 char **error_message ATTRIBUTE_UNUSED;
252b5132
RH
1895{
1896 UN_IMPL("SECTION");
1897 DUMP_RELOC("SECTION",reloc_entry);
1898
1899 if (output_bfd == (bfd *) NULL)
1900 return bfd_reloc_continue;
1901
1902 return bfd_reloc_ok;
1903}
1904
1905static bfd_reloc_status_type
2ab1486e
NC
1906ppc_imglue_reloc (abfd, reloc_entry, symbol, data,
1907 input_section, output_bfd, error_message)
5f771d47
ILT
1908 bfd *abfd ATTRIBUTE_UNUSED;
1909 arelent *reloc_entry ATTRIBUTE_UNUSED;
1910 asymbol *symbol ATTRIBUTE_UNUSED;
1911 PTR data ATTRIBUTE_UNUSED;
1912 asection *input_section ATTRIBUTE_UNUSED;
252b5132 1913 bfd *output_bfd;
5f771d47 1914 char **error_message ATTRIBUTE_UNUSED;
252b5132
RH
1915{
1916 UN_IMPL("IMGLUE");
1917 DUMP_RELOC("IMGLUE",reloc_entry);
1918
1919 if (output_bfd == (bfd *) NULL)
1920 return bfd_reloc_continue;
1921
1922 return bfd_reloc_ok;
1923}
252b5132 1924\f
252b5132 1925#define MAX_RELOC_INDEX \
c5930ee6 1926 (sizeof (ppc_coff_howto_table) / sizeof (ppc_coff_howto_table[0]) - 1)
252b5132 1927
5c4491d3 1928/* FIXME: There is a possibility that when we read in a reloc from a file,
43646c9d 1929 that there are some bits encoded in the upper portion of the
2ab1486e
NC
1930 type field. Not yet implemented. */
1931static void ppc_coff_rtype2howto PARAMS ((arelent *, struct internal_reloc *));
252b5132
RH
1932
1933static void
1934ppc_coff_rtype2howto (relent, internal)
1935 arelent *relent;
1936 struct internal_reloc *internal;
43646c9d 1937{
252b5132
RH
1938 /* We can encode one of three things in the type field, aside from the
1939 type:
1940 1. IMAGE_REL_PPC_NEG - indicates the value field is a subtraction
1941 value, rather than an addition value
1942 2. IMAGE_REL_PPC_BRTAKEN, IMAGE_REL_PPC_BRNTAKEN - indicates that
1943 the branch is expected to be taken or not.
1944 3. IMAGE_REL_PPC_TOCDEFN - toc slot definition in the file
1945 For now, we just strip this stuff to find the type, and ignore it other
2ab1486e 1946 than that. */
252b5132
RH
1947 reloc_howto_type *howto;
1948 unsigned short r_type = EXTRACT_TYPE (internal->r_type);
1949 unsigned short r_flags = EXTRACT_FLAGS(internal->r_type);
1950 unsigned short junk = EXTRACT_JUNK (internal->r_type);
1951
2ab1486e 1952 /* The masking process only slices off the bottom byte for r_type. */
43646c9d 1953 if ( r_type > MAX_RELOC_INDEX )
c5930ee6 1954 abort ();
252b5132 1955
2ab1486e
NC
1956 /* Check for absolute crap. */
1957 if (junk != 0)
c5930ee6 1958 abort ();
252b5132 1959
43646c9d 1960 switch(r_type)
252b5132
RH
1961 {
1962 case IMAGE_REL_PPC_ADDR16:
1963 case IMAGE_REL_PPC_REL24:
1964 case IMAGE_REL_PPC_ADDR24:
1965 case IMAGE_REL_PPC_ADDR32:
1966 case IMAGE_REL_PPC_IFGLUE:
1967 case IMAGE_REL_PPC_ADDR32NB:
1968 case IMAGE_REL_PPC_SECTION:
1969 case IMAGE_REL_PPC_SECREL:
2ab1486e 1970 DUMP_RELOC2 (ppc_coff_howto_table[r_type].name, internal);
252b5132
RH
1971 howto = ppc_coff_howto_table + r_type;
1972 break;
1973 case IMAGE_REL_PPC_IMGLUE:
2ab1486e 1974 DUMP_RELOC2 (ppc_coff_howto_table[r_type].name, internal);
252b5132
RH
1975 howto = ppc_coff_howto_table + r_type;
1976 break;
1977 case IMAGE_REL_PPC_TOCREL16:
2ab1486e 1978 DUMP_RELOC2 (ppc_coff_howto_table[r_type].name, internal);
252b5132
RH
1979 if (r_flags & IMAGE_REL_PPC_TOCDEFN)
1980 howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16_DEFN;
1981 else
1982 howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16;
1983 break;
1984 default:
6e301b2b 1985 fprintf (stderr,
252b5132
RH
1986 _("Warning: Unsupported reloc %s [%d] used -- it may not work.\n"),
1987 ppc_coff_howto_table[r_type].name,
1988 r_type);
43646c9d 1989 howto = ppc_coff_howto_table + r_type;
252b5132
RH
1990 break;
1991 }
43646c9d 1992
252b5132 1993 relent->howto = howto;
252b5132
RH
1994}
1995
1996static reloc_howto_type *
1997coff_ppc_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
5f771d47 1998 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
1999 asection *sec;
2000 struct internal_reloc *rel;
5f771d47
ILT
2001 struct coff_link_hash_entry *h ATTRIBUTE_UNUSED;
2002 struct internal_syment *sym ATTRIBUTE_UNUSED;
252b5132
RH
2003 bfd_vma *addendp;
2004{
2005 reloc_howto_type *howto;
2006
2007 /* We can encode one of three things in the type field, aside from the
2008 type:
2009 1. IMAGE_REL_PPC_NEG - indicates the value field is a subtraction
2010 value, rather than an addition value
2011 2. IMAGE_REL_PPC_BRTAKEN, IMAGE_REL_PPC_BRNTAKEN - indicates that
2012 the branch is expected to be taken or not.
2013 3. IMAGE_REL_PPC_TOCDEFN - toc slot definition in the file
2014 For now, we just strip this stuff to find the type, and ignore it other
2ab1486e 2015 than that. */
252b5132 2016
2ab1486e
NC
2017 unsigned short r_type = EXTRACT_TYPE (rel->r_type);
2018 unsigned short r_flags = EXTRACT_FLAGS (rel->r_type);
2019 unsigned short junk = EXTRACT_JUNK (rel->r_type);
252b5132 2020
2ab1486e
NC
2021 /* The masking process only slices off the bottom byte for r_type. */
2022 if (r_type > MAX_RELOC_INDEX)
c5930ee6 2023 abort ();
43646c9d 2024
2ab1486e
NC
2025 /* Check for absolute crap. */
2026 if (junk != 0)
c5930ee6 2027 abort ();
43646c9d
KH
2028
2029 switch(r_type)
252b5132
RH
2030 {
2031 case IMAGE_REL_PPC_ADDR32NB:
2032 DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel);
2033 *addendp -= pe_data(sec->output_section->owner)->pe_opthdr.ImageBase;
2034 howto = ppc_coff_howto_table + r_type;
2035 break;
2036 case IMAGE_REL_PPC_TOCREL16:
2037 DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel);
2038 if (r_flags & IMAGE_REL_PPC_TOCDEFN)
2039 howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16_DEFN;
2040 else
2041 howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16;
2042 break;
2043 case IMAGE_REL_PPC_ADDR16:
2044 case IMAGE_REL_PPC_REL24:
2045 case IMAGE_REL_PPC_ADDR24:
2046 case IMAGE_REL_PPC_ADDR32:
2047 case IMAGE_REL_PPC_IFGLUE:
2048 case IMAGE_REL_PPC_SECTION:
2049 case IMAGE_REL_PPC_SECREL:
2050 DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel);
2051 howto = ppc_coff_howto_table + r_type;
2052 break;
2053 case IMAGE_REL_PPC_IMGLUE:
2054 DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel);
2055 howto = ppc_coff_howto_table + r_type;
2056 break;
2057 default:
6e301b2b 2058 fprintf (stderr,
252b5132
RH
2059 _("Warning: Unsupported reloc %s [%d] used -- it may not work.\n"),
2060 ppc_coff_howto_table[r_type].name,
2061 r_type);
2062 howto = ppc_coff_howto_table + r_type;
2063 break;
2064 }
43646c9d 2065
252b5132
RH
2066 return howto;
2067}
2068
2ab1486e 2069/* A cheesy little macro to make the code a little more readable. */
252b5132
RH
2070#define HOW2MAP(bfd_rtype,ppc_rtype) \
2071 case bfd_rtype: return &ppc_coff_howto_table[ppc_rtype]
2072
2073static reloc_howto_type *ppc_coff_reloc_type_lookup
2074PARAMS ((bfd *, bfd_reloc_code_real_type));
2075
2076static reloc_howto_type *
2077ppc_coff_reloc_type_lookup (abfd, code)
5f771d47 2078 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
2079 bfd_reloc_code_real_type code;
2080{
2081 switch (code)
2082 {
2083 HOW2MAP(BFD_RELOC_32_GOTOFF, IMAGE_REL_PPC_IMGLUE);
2084 HOW2MAP(BFD_RELOC_16_GOT_PCREL, IMAGE_REL_PPC_IFGLUE);
2085 HOW2MAP(BFD_RELOC_16, IMAGE_REL_PPC_ADDR16);
2086 HOW2MAP(BFD_RELOC_PPC_B26, IMAGE_REL_PPC_REL24);
2087 HOW2MAP(BFD_RELOC_PPC_BA26, IMAGE_REL_PPC_ADDR24);
2088 HOW2MAP(BFD_RELOC_PPC_TOC16, IMAGE_REL_PPC_TOCREL16);
2089 HOW2MAP(BFD_RELOC_16_GOTOFF, IMAGE_REL_PPC_TOCREL16_DEFN);
2090 HOW2MAP(BFD_RELOC_32, IMAGE_REL_PPC_ADDR32);
2091 HOW2MAP(BFD_RELOC_RVA, IMAGE_REL_PPC_ADDR32NB);
43646c9d 2092 default:
252b5132
RH
2093 return NULL;
2094 }
252b5132
RH
2095}
2096
2097#undef HOW2MAP
252b5132 2098\f
43646c9d 2099/* Tailor coffcode.h -- macro heaven. */
252b5132
RH
2100
2101#define RTYPE2HOWTO(cache_ptr, dst) ppc_coff_rtype2howto (cache_ptr, dst)
2102
252b5132
RH
2103/* We use the special COFF backend linker, with our own special touch. */
2104
2105#define coff_bfd_reloc_type_lookup ppc_coff_reloc_type_lookup
2106#define coff_rtype_to_howto coff_ppc_rtype_to_howto
2107#define coff_relocate_section coff_ppc_relocate_section
43646c9d 2108#define coff_bfd_final_link ppc_bfd_coff_final_link
252b5132
RH
2109
2110#ifndef COFF_IMAGE_WITH_PE
650f5dd8 2111/* FIXME: This no longer works. */
1e738b87 2112#if 0
252b5132
RH
2113#define coff_swap_sym_in_hook ppc_coff_swap_sym_in_hook
2114#endif
1e738b87 2115#endif
252b5132
RH
2116
2117#define SELECT_RELOC(internal, howto) {internal.r_type=howto->type;}
2118
2119#define COFF_PAGE_SIZE 0x1000
2120
650f5dd8
ILT
2121/* FIXME: This controls some code that used to be in peicode.h and is
2122 now in peigen.c. It will not control the code in peigen.c. If
2123 anybody wants to get this working, you will need to fix that. */
252b5132
RH
2124#define POWERPC_LE_PE
2125
a50f8417
ILT
2126#define COFF_SECTION_ALIGNMENT_ENTRIES \
2127{ COFF_SECTION_NAME_EXACT_MATCH (".idata$2"), \
2128 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
2129{ COFF_SECTION_NAME_EXACT_MATCH (".idata$3"), \
2130 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
2131{ COFF_SECTION_NAME_EXACT_MATCH (".idata$4"), \
2132 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
2133{ COFF_SECTION_NAME_EXACT_MATCH (".idata$5"), \
2134 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
2135{ COFF_SECTION_NAME_EXACT_MATCH (".idata$6"), \
2136 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 1 }, \
2137{ COFF_SECTION_NAME_EXACT_MATCH (".reloc"), \
2138 COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 1 }
2139
252b5132 2140#include "coffcode.h"
252b5132 2141\f
252b5132 2142#ifndef COFF_IMAGE_WITH_PE
1e738b87
NC
2143/* FIXME: This no longer works. */
2144#if 0
252b5132 2145/* FIXME:
43646c9d 2146 What we're trying to do here is allocate a toc section (early), and attach
252b5132
RH
2147 it to the last bfd to be processed. This avoids the problem of having a toc
2148 written out before all files have been processed. This code allocates
2149 a toc section for every file, and records the last one seen. There are
2150 at least two problems with this approach:
2151 1. We allocate whole bunches of toc sections that are ignored, but at
2152 at least we will not allocate a toc if no .toc is present.
2153 2. It's not clear to me that being the last bfd read necessarily means
2154 that you are the last bfd closed.
2155 3. Doing it on a "swap in" hook depends on when the "swap in" is called,
2ab1486e 2156 and how often, etc. It's not clear to me that there isn't a hole here. */
1e738b87 2157static void ppc_coff_swap_sym_in_hook PARAMS ((bfd *, PTR, PTR));
252b5132
RH
2158
2159static void
2160ppc_coff_swap_sym_in_hook (abfd, ext1, in1)
2161 bfd *abfd;
5f771d47 2162 PTR ext1 ATTRIBUTE_UNUSED;
252b5132
RH
2163 PTR in1;
2164{
2ab1486e 2165 struct internal_syment * in = (struct internal_syment *)in1;
252b5132 2166
2ab1486e 2167 if (bfd_of_toc_owner != 0) /* We already have a toc, so go home. */
252b5132
RH
2168 return;
2169
2ab1486e 2170 if (strcmp (in->_n._n_name, ".toc") == 0)
252b5132
RH
2171 {
2172 flagword flags;
2173 register asection *s;
2174
2ab1486e 2175 s = bfd_get_section_by_name (abfd, TOC_SECTION_NAME);
43646c9d 2176 if (s != NULL)
2ab1486e 2177 return;
252b5132
RH
2178
2179 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY ;
2180
2181 s = bfd_make_section (abfd, TOC_SECTION_NAME);
2182
2183 if (s == NULL
2184 || !bfd_set_section_flags (abfd, s, flags)
2185 || !bfd_set_section_alignment (abfd, s, 2))
2ab1486e
NC
2186 /* FIXME: set appropriate bfd error. */
2187 abort ();
252b5132 2188
2ab1486e 2189 /* Save the bfd for later allocation. */
252b5132
RH
2190 bfd_of_toc_owner = abfd;
2191 }
2192
2193 return;
2194}
2195#endif
1e738b87 2196#endif
252b5132
RH
2197
2198#ifndef COFF_IMAGE_WITH_PE
2199
b34976b6 2200static bfd_boolean ppc_do_last PARAMS ((bfd *));
252b5132
RH
2201static bfd *ppc_get_last PARAMS ((void));
2202
b34976b6 2203static bfd_boolean
252b5132
RH
2204ppc_do_last (abfd)
2205 bfd *abfd;
2206{
2207 if (abfd == bfd_of_toc_owner)
b34976b6 2208 return TRUE;
252b5132 2209 else
b34976b6 2210 return FALSE;
252b5132
RH
2211}
2212
2213static bfd *
2214ppc_get_last()
2215{
2216 return bfd_of_toc_owner;
2217}
2218
2ab1486e 2219/* This piece of machinery exists only to guarantee that the bfd that holds
43646c9d 2220 the toc section is written last.
252b5132
RH
2221
2222 This does depend on bfd_make_section attaching a new section to the
43646c9d 2223 end of the section list for the bfd.
252b5132 2224
43646c9d
KH
2225 This is otherwise intended to be functionally the same as
2226 cofflink.c:_bfd_coff_final_link(). It is specifically different only
2227 where the POWERPC_LE_PE macro modifies the code. It is left in as a
2ab1486e 2228 precise form of comment. krk@cygnus.com */
252b5132 2229
252b5132
RH
2230/* Do the final link step. */
2231
b34976b6 2232bfd_boolean
252b5132
RH
2233ppc_bfd_coff_final_link (abfd, info)
2234 bfd *abfd;
2235 struct bfd_link_info *info;
2236{
2237 bfd_size_type symesz;
2238 struct coff_final_link_info finfo;
b34976b6 2239 bfd_boolean debug_merge_allocated;
252b5132
RH
2240 asection *o;
2241 struct bfd_link_order *p;
dc810e39
AM
2242 bfd_size_type max_sym_count;
2243 bfd_size_type max_lineno_count;
2244 bfd_size_type max_reloc_count;
2245 bfd_size_type max_output_reloc_count;
2246 bfd_size_type max_contents_size;
252b5132
RH
2247 file_ptr rel_filepos;
2248 unsigned int relsz;
2249 file_ptr line_filepos;
2250 unsigned int linesz;
2251 bfd *sub;
2252 bfd_byte *external_relocs = NULL;
2253 char strbuf[STRING_SIZE_SIZE];
dc810e39 2254 bfd_size_type amt;
252b5132
RH
2255
2256 symesz = bfd_coff_symesz (abfd);
2257
2258 finfo.info = info;
2259 finfo.output_bfd = abfd;
2260 finfo.strtab = NULL;
2261 finfo.section_info = NULL;
2262 finfo.last_file_index = -1;
2263 finfo.last_bf_index = -1;
2264 finfo.internal_syms = NULL;
2265 finfo.sec_ptrs = NULL;
2266 finfo.sym_indices = NULL;
2267 finfo.outsyms = NULL;
2268 finfo.linenos = NULL;
2269 finfo.contents = NULL;
2270 finfo.external_relocs = NULL;
2271 finfo.internal_relocs = NULL;
b34976b6 2272 debug_merge_allocated = FALSE;
252b5132
RH
2273
2274 coff_data (abfd)->link_info = info;
2275
2276 finfo.strtab = _bfd_stringtab_init ();
2277 if (finfo.strtab == NULL)
2278 goto error_return;
2279
2280 if (! coff_debug_merge_hash_table_init (&finfo.debug_merge))
2281 goto error_return;
b34976b6 2282 debug_merge_allocated = TRUE;
252b5132
RH
2283
2284 /* Compute the file positions for all the sections. */
2285 if (! abfd->output_has_begun)
2286 {
2287 if (! bfd_coff_compute_section_file_positions (abfd))
b34976b6 2288 return FALSE;
252b5132
RH
2289 }
2290
2291 /* Count the line numbers and relocation entries required for the
2292 output file. Set the file positions for the relocs. */
2293 rel_filepos = obj_relocbase (abfd);
2294 relsz = bfd_coff_relsz (abfd);
2295 max_contents_size = 0;
2296 max_lineno_count = 0;
2297 max_reloc_count = 0;
2298
2299 for (o = abfd->sections; o != NULL; o = o->next)
2300 {
2301 o->reloc_count = 0;
2302 o->lineno_count = 0;
2ab1486e 2303
252b5132
RH
2304 for (p = o->link_order_head; p != NULL; p = p->next)
2305 {
252b5132
RH
2306 if (p->type == bfd_indirect_link_order)
2307 {
2308 asection *sec;
2309
2310 sec = p->u.indirect.section;
2311
2312 /* Mark all sections which are to be included in the
2313 link. This will normally be every section. We need
2314 to do this so that we can identify any sections which
2315 the linker has decided to not include. */
b34976b6 2316 sec->linker_mark = TRUE;
252b5132
RH
2317
2318 if (info->strip == strip_none
2319 || info->strip == strip_some)
2320 o->lineno_count += sec->lineno_count;
2321
1049f94e 2322 if (info->relocatable)
252b5132
RH
2323 o->reloc_count += sec->reloc_count;
2324
3722b82f
AM
2325 if (sec->rawsize > max_contents_size)
2326 max_contents_size = sec->rawsize;
eea6121a
AM
2327 if (sec->size > max_contents_size)
2328 max_contents_size = sec->size;
252b5132
RH
2329 if (sec->lineno_count > max_lineno_count)
2330 max_lineno_count = sec->lineno_count;
2331 if (sec->reloc_count > max_reloc_count)
2332 max_reloc_count = sec->reloc_count;
2333 }
1049f94e 2334 else if (info->relocatable
252b5132
RH
2335 && (p->type == bfd_section_reloc_link_order
2336 || p->type == bfd_symbol_reloc_link_order))
2337 ++o->reloc_count;
2338 }
2339 if (o->reloc_count == 0)
2340 o->rel_filepos = 0;
2341 else
2342 {
2343 o->flags |= SEC_RELOC;
2344 o->rel_filepos = rel_filepos;
2345 rel_filepos += o->reloc_count * relsz;
2346 }
2347 }
2348
1049f94e 2349 /* If doing a relocatable link, allocate space for the pointers we
252b5132 2350 need to keep. */
1049f94e 2351 if (info->relocatable)
252b5132
RH
2352 {
2353 unsigned int i;
2354
2355 /* We use section_count + 1, rather than section_count, because
2356 the target_index fields are 1 based. */
dc810e39
AM
2357 amt = abfd->section_count + 1;
2358 amt *= sizeof (struct coff_link_section_info);
2359 finfo.section_info = (struct coff_link_section_info *) bfd_malloc (amt);
2ab1486e 2360
252b5132
RH
2361 if (finfo.section_info == NULL)
2362 goto error_return;
2ab1486e 2363
252b5132
RH
2364 for (i = 0; i <= abfd->section_count; i++)
2365 {
2366 finfo.section_info[i].relocs = NULL;
2367 finfo.section_info[i].rel_hashes = NULL;
2368 }
2369 }
2370
2371 /* We now know the size of the relocs, so we can determine the file
2372 positions of the line numbers. */
2373 line_filepos = rel_filepos;
2374 linesz = bfd_coff_linesz (abfd);
2375 max_output_reloc_count = 0;
2ab1486e 2376
252b5132
RH
2377 for (o = abfd->sections; o != NULL; o = o->next)
2378 {
2379 if (o->lineno_count == 0)
2380 o->line_filepos = 0;
2381 else
2382 {
2383 o->line_filepos = line_filepos;
2384 line_filepos += o->lineno_count * linesz;
2385 }
2386
2387 if (o->reloc_count != 0)
2388 {
2389 /* We don't know the indices of global symbols until we have
2390 written out all the local symbols. For each section in
2391 the output file, we keep an array of pointers to hash
2392 table entries. Each entry in the array corresponds to a
2393 reloc. When we find a reloc against a global symbol, we
2394 set the corresponding entry in this array so that we can
2395 fix up the symbol index after we have written out all the
2396 local symbols.
2397
2398 Because of this problem, we also keep the relocs in
2399 memory until the end of the link. This wastes memory,
1049f94e 2400 but only when doing a relocatable link, which is not the
252b5132 2401 common case. */
1049f94e 2402 BFD_ASSERT (info->relocatable);
dc810e39
AM
2403 amt = o->reloc_count;
2404 amt *= sizeof (struct internal_reloc);
252b5132 2405 finfo.section_info[o->target_index].relocs =
dc810e39
AM
2406 (struct internal_reloc *) bfd_malloc (amt);
2407 amt = o->reloc_count;
2408 amt *= sizeof (struct coff_link_hash_entry *);
252b5132 2409 finfo.section_info[o->target_index].rel_hashes =
dc810e39 2410 (struct coff_link_hash_entry **) bfd_malloc (amt);
252b5132
RH
2411 if (finfo.section_info[o->target_index].relocs == NULL
2412 || finfo.section_info[o->target_index].rel_hashes == NULL)
2413 goto error_return;
2414
2415 if (o->reloc_count > max_output_reloc_count)
2416 max_output_reloc_count = o->reloc_count;
2417 }
2418
2419 /* Reset the reloc and lineno counts, so that we can use them to
2420 count the number of entries we have output so far. */
2421 o->reloc_count = 0;
2422 o->lineno_count = 0;
2423 }
2424
2425 obj_sym_filepos (abfd) = line_filepos;
2426
2427 /* Figure out the largest number of symbols in an input BFD. Take
2428 the opportunity to clear the output_has_begun fields of all the
2429 input BFD's. */
2430 max_sym_count = 0;
2431 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
2432 {
dc810e39 2433 bfd_size_type sz;
252b5132 2434
b34976b6 2435 sub->output_has_begun = FALSE;
252b5132
RH
2436 sz = obj_raw_syment_count (sub);
2437 if (sz > max_sym_count)
2438 max_sym_count = sz;
2439 }
2440
2441 /* Allocate some buffers used while linking. */
dc810e39
AM
2442 amt = max_sym_count * sizeof (struct internal_syment);
2443 finfo.internal_syms = (struct internal_syment *) bfd_malloc (amt);
2444 amt = max_sym_count * sizeof (asection *);
2445 finfo.sec_ptrs = (asection **) bfd_malloc (amt);
2446 amt = max_sym_count * sizeof (long);
2447 finfo.sym_indices = (long *) bfd_malloc (amt);
2448 amt = (max_sym_count + 1) * symesz;
2449 finfo.outsyms = (bfd_byte *) bfd_malloc (amt);
2450 amt = max_lineno_count * bfd_coff_linesz (abfd);
2451 finfo.linenos = (bfd_byte *) bfd_malloc (amt);
252b5132
RH
2452 finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size);
2453 finfo.external_relocs = (bfd_byte *) bfd_malloc (max_reloc_count * relsz);
1049f94e 2454 if (! info->relocatable)
dc810e39
AM
2455 {
2456 amt = max_reloc_count * sizeof (struct internal_reloc);
2457 finfo.internal_relocs = (struct internal_reloc *) bfd_malloc (amt);
2458 }
252b5132
RH
2459 if ((finfo.internal_syms == NULL && max_sym_count > 0)
2460 || (finfo.sec_ptrs == NULL && max_sym_count > 0)
2461 || (finfo.sym_indices == NULL && max_sym_count > 0)
2462 || finfo.outsyms == NULL
2463 || (finfo.linenos == NULL && max_lineno_count > 0)
2464 || (finfo.contents == NULL && max_contents_size > 0)
2465 || (finfo.external_relocs == NULL && max_reloc_count > 0)
1049f94e 2466 || (! info->relocatable
252b5132
RH
2467 && finfo.internal_relocs == NULL
2468 && max_reloc_count > 0))
2469 goto error_return;
2470
2471 /* We now know the position of everything in the file, except that
2472 we don't know the size of the symbol table and therefore we don't
2473 know where the string table starts. We just build the string
2474 table in memory as we go along. We process all the relocations
2475 for a single input file at once. */
2476 obj_raw_syment_count (abfd) = 0;
2477
2478 if (coff_backend_info (abfd)->_bfd_coff_start_final_link)
2479 {
2480 if (! bfd_coff_start_final_link (abfd, info))
2481 goto error_return;
2482 }
2483
2484 for (o = abfd->sections; o != NULL; o = o->next)
2485 {
2486 for (p = o->link_order_head; p != NULL; p = p->next)
2487 {
2488 if (p->type == bfd_indirect_link_order
2489 && (bfd_get_flavour (p->u.indirect.section->owner)
2490 == bfd_target_coff_flavour))
2491 {
2492 sub = p->u.indirect.section->owner;
2493#ifdef POWERPC_LE_PE
2494 if (! sub->output_has_begun && !ppc_do_last(sub))
2495#else
2496 if (! sub->output_has_begun)
2497#endif
2498 {
2499 if (! _bfd_coff_link_input_bfd (&finfo, sub))
2500 goto error_return;
b34976b6 2501 sub->output_has_begun = TRUE;
252b5132
RH
2502 }
2503 }
2504 else if (p->type == bfd_section_reloc_link_order
2505 || p->type == bfd_symbol_reloc_link_order)
2506 {
2507 if (! _bfd_coff_reloc_link_order (abfd, &finfo, o, p))
2508 goto error_return;
2509 }
2510 else
2511 {
2512 if (! _bfd_default_link_order (abfd, info, o, p))
2513 goto error_return;
2514 }
2515 }
2516 }
2517
2518#ifdef POWERPC_LE_PE
2519 {
2520 bfd* last_one = ppc_get_last();
2521 if (last_one)
2522 {
2523 if (! _bfd_coff_link_input_bfd (&finfo, last_one))
2524 goto error_return;
2525 }
b34976b6 2526 last_one->output_has_begun = TRUE;
252b5132
RH
2527 }
2528#endif
2529
2530 /* Free up the buffers used by _bfd_coff_link_input_bfd. */
252b5132 2531 coff_debug_merge_hash_table_free (&finfo.debug_merge);
b34976b6 2532 debug_merge_allocated = FALSE;
252b5132
RH
2533
2534 if (finfo.internal_syms != NULL)
2535 {
2536 free (finfo.internal_syms);
2537 finfo.internal_syms = NULL;
2538 }
2539 if (finfo.sec_ptrs != NULL)
2540 {
2541 free (finfo.sec_ptrs);
2542 finfo.sec_ptrs = NULL;
2543 }
2544 if (finfo.sym_indices != NULL)
2545 {
2546 free (finfo.sym_indices);
2547 finfo.sym_indices = NULL;
2548 }
2549 if (finfo.linenos != NULL)
2550 {
2551 free (finfo.linenos);
2552 finfo.linenos = NULL;
2553 }
2554 if (finfo.contents != NULL)
2555 {
2556 free (finfo.contents);
2557 finfo.contents = NULL;
2558 }
2559 if (finfo.external_relocs != NULL)
2560 {
2561 free (finfo.external_relocs);
2562 finfo.external_relocs = NULL;
2563 }
2564 if (finfo.internal_relocs != NULL)
2565 {
2566 free (finfo.internal_relocs);
2567 finfo.internal_relocs = NULL;
2568 }
2569
2570 /* The value of the last C_FILE symbol is supposed to be the symbol
2571 index of the first external symbol. Write it out again if
2572 necessary. */
2573 if (finfo.last_file_index != -1
2574 && (unsigned int) finfo.last_file.n_value != obj_raw_syment_count (abfd))
2575 {
dc810e39
AM
2576 file_ptr pos;
2577
252b5132
RH
2578 finfo.last_file.n_value = obj_raw_syment_count (abfd);
2579 bfd_coff_swap_sym_out (abfd, (PTR) &finfo.last_file,
2580 (PTR) finfo.outsyms);
dc810e39
AM
2581 pos = obj_sym_filepos (abfd) + finfo.last_file_index * symesz;
2582 if (bfd_seek (abfd, pos, SEEK_SET) != 0
2583 || bfd_bwrite (finfo.outsyms, symesz, abfd) != symesz)
b34976b6 2584 return FALSE;
252b5132
RH
2585 }
2586
2587 /* Write out the global symbols. */
b34976b6 2588 finfo.failed = FALSE;
252b5132
RH
2589 coff_link_hash_traverse (coff_hash_table (info), _bfd_coff_write_global_sym,
2590 (PTR) &finfo);
2591 if (finfo.failed)
2592 goto error_return;
2593
2594 /* The outsyms buffer is used by _bfd_coff_write_global_sym. */
2595 if (finfo.outsyms != NULL)
2596 {
2597 free (finfo.outsyms);
2598 finfo.outsyms = NULL;
2599 }
2600
1049f94e 2601 if (info->relocatable)
252b5132
RH
2602 {
2603 /* Now that we have written out all the global symbols, we know
2604 the symbol indices to use for relocs against them, and we can
2605 finally write out the relocs. */
dc810e39
AM
2606 amt = max_output_reloc_count * relsz;
2607 external_relocs = (bfd_byte *) bfd_malloc (amt);
252b5132
RH
2608 if (external_relocs == NULL)
2609 goto error_return;
2610
2611 for (o = abfd->sections; o != NULL; o = o->next)
2612 {
2613 struct internal_reloc *irel;
2614 struct internal_reloc *irelend;
2615 struct coff_link_hash_entry **rel_hash;
2616 bfd_byte *erel;
2617
2618 if (o->reloc_count == 0)
2619 continue;
2620
2621 irel = finfo.section_info[o->target_index].relocs;
2622 irelend = irel + o->reloc_count;
2623 rel_hash = finfo.section_info[o->target_index].rel_hashes;
2624 erel = external_relocs;
2625 for (; irel < irelend; irel++, rel_hash++, erel += relsz)
2626 {
2627 if (*rel_hash != NULL)
2628 {
2629 BFD_ASSERT ((*rel_hash)->indx >= 0);
2630 irel->r_symndx = (*rel_hash)->indx;
2631 }
2632 bfd_coff_swap_reloc_out (abfd, (PTR) irel, (PTR) erel);
2633 }
2634
dc810e39 2635 amt = relsz * o->reloc_count;
252b5132 2636 if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0
dc810e39 2637 || bfd_bwrite ((PTR) external_relocs, amt, abfd) != amt)
252b5132
RH
2638 goto error_return;
2639 }
2640
2641 free (external_relocs);
2642 external_relocs = NULL;
2643 }
2644
2645 /* Free up the section information. */
2646 if (finfo.section_info != NULL)
2647 {
2648 unsigned int i;
2649
2650 for (i = 0; i < abfd->section_count; i++)
2651 {
2652 if (finfo.section_info[i].relocs != NULL)
2653 free (finfo.section_info[i].relocs);
2654 if (finfo.section_info[i].rel_hashes != NULL)
2655 free (finfo.section_info[i].rel_hashes);
2656 }
2657 free (finfo.section_info);
2658 finfo.section_info = NULL;
2659 }
2660
2661 /* If we have optimized stabs strings, output them. */
3722b82f 2662 if (coff_hash_table (info)->stab_info.stabstr != NULL)
252b5132
RH
2663 {
2664 if (! _bfd_write_stab_strings (abfd, &coff_hash_table (info)->stab_info))
b34976b6 2665 return FALSE;
252b5132
RH
2666 }
2667
2668 /* Write out the string table. */
2669 if (obj_raw_syment_count (abfd) != 0)
2670 {
dc810e39
AM
2671 file_ptr pos;
2672
2673 pos = obj_sym_filepos (abfd) + obj_raw_syment_count (abfd) * symesz;
2674 if (bfd_seek (abfd, pos, SEEK_SET) != 0)
b34976b6 2675 return FALSE;
252b5132
RH
2676
2677#if STRING_SIZE_SIZE == 4
dc810e39
AM
2678 H_PUT_32 (abfd,
2679 _bfd_stringtab_size (finfo.strtab) + STRING_SIZE_SIZE,
2680 strbuf);
252b5132 2681#else
dc810e39 2682 #error Change H_PUT_32 above
252b5132
RH
2683#endif
2684
dc810e39
AM
2685 if (bfd_bwrite (strbuf, (bfd_size_type) STRING_SIZE_SIZE, abfd)
2686 != STRING_SIZE_SIZE)
b34976b6 2687 return FALSE;
252b5132
RH
2688
2689 if (! _bfd_stringtab_emit (abfd, finfo.strtab))
b34976b6 2690 return FALSE;
252b5132
RH
2691 }
2692
2693 _bfd_stringtab_free (finfo.strtab);
2694
2695 /* Setting bfd_get_symcount to 0 will cause write_object_contents to
2696 not try to write out the symbols. */
2697 bfd_get_symcount (abfd) = 0;
2698
b34976b6 2699 return TRUE;
252b5132
RH
2700
2701 error_return:
2702 if (debug_merge_allocated)
2703 coff_debug_merge_hash_table_free (&finfo.debug_merge);
2704 if (finfo.strtab != NULL)
2705 _bfd_stringtab_free (finfo.strtab);
2706 if (finfo.section_info != NULL)
2707 {
2708 unsigned int i;
2709
2710 for (i = 0; i < abfd->section_count; i++)
2711 {
2712 if (finfo.section_info[i].relocs != NULL)
2713 free (finfo.section_info[i].relocs);
2714 if (finfo.section_info[i].rel_hashes != NULL)
2715 free (finfo.section_info[i].rel_hashes);
2716 }
2717 free (finfo.section_info);
2718 }
2719 if (finfo.internal_syms != NULL)
2720 free (finfo.internal_syms);
2721 if (finfo.sec_ptrs != NULL)
2722 free (finfo.sec_ptrs);
2723 if (finfo.sym_indices != NULL)
2724 free (finfo.sym_indices);
2725 if (finfo.outsyms != NULL)
2726 free (finfo.outsyms);
2727 if (finfo.linenos != NULL)
2728 free (finfo.linenos);
2729 if (finfo.contents != NULL)
2730 free (finfo.contents);
2731 if (finfo.external_relocs != NULL)
2732 free (finfo.external_relocs);
2733 if (finfo.internal_relocs != NULL)
2734 free (finfo.internal_relocs);
2735 if (external_relocs != NULL)
2736 free (external_relocs);
b34976b6 2737 return FALSE;
252b5132
RH
2738}
2739#endif
2740\f
c3c89269
NC
2741/* Forward declaration for use by alternative_target field. */
2742#ifdef TARGET_BIG_SYM
2743extern const bfd_target TARGET_BIG_SYM;
2744#endif
2745
43646c9d 2746/* The transfer vectors that lead the outside world to all of the above. */
252b5132
RH
2747
2748#ifdef TARGET_LITTLE_SYM
c3c89269 2749const bfd_target TARGET_LITTLE_SYM =
252b5132
RH
2750{
2751 TARGET_LITTLE_NAME, /* name or coff-arm-little */
2752 bfd_target_coff_flavour,
2753 BFD_ENDIAN_LITTLE, /* data byte order is little */
2754 BFD_ENDIAN_LITTLE, /* header byte order is little */
2755
2756 (HAS_RELOC | EXEC_P | /* FIXME: object flags */
2757 HAS_LINENO | HAS_DEBUG |
2758 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
43646c9d 2759
252b5132
RH
2760#ifndef COFF_WITH_PE
2761 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2762#else
2763 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
2764 | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
2765#endif
2766
2767 0, /* leading char */
2768 '/', /* ar_pad_char */
2769 15, /* ar_max_namelen??? FIXMEmgo */
2770
2771 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
2772 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
2773 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
2774
2775 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
2776 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
2777 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
43646c9d 2778
252b5132
RH
2779 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
2780 bfd_generic_archive_p, /* _bfd_dummy_target */ coff_object_p },
2781 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
2782 bfd_false},
2783 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
2784 _bfd_write_archive_contents, bfd_false},
43646c9d 2785
252b5132
RH
2786 BFD_JUMP_TABLE_GENERIC (coff),
2787 BFD_JUMP_TABLE_COPY (coff),
2788 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2789 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
2790 BFD_JUMP_TABLE_SYMBOLS (coff),
2791 BFD_JUMP_TABLE_RELOCS (coff),
2792 BFD_JUMP_TABLE_WRITE (coff),
2793 BFD_JUMP_TABLE_LINK (coff),
2794 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
c3c89269
NC
2795
2796 /* Alternative_target. */
2797#ifdef TARGET_BIG_SYM
2798 & TARGET_BIG_SYM,
2799#else
2800 NULL,
2801#endif
43646c9d 2802
c3c89269 2803 COFF_SWAP_TABLE
252b5132
RH
2804};
2805#endif
2806
2807#ifdef TARGET_BIG_SYM
c3c89269 2808const bfd_target TARGET_BIG_SYM =
252b5132
RH
2809{
2810 TARGET_BIG_NAME,
43646c9d 2811 bfd_target_coff_flavour,
252b5132
RH
2812 BFD_ENDIAN_BIG, /* data byte order is big */
2813 BFD_ENDIAN_BIG, /* header byte order is big */
2814
2815 (HAS_RELOC | EXEC_P | /* FIXME: object flags */
2816 HAS_LINENO | HAS_DEBUG |
2817 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
2818
2819#ifndef COFF_WITH_PE
2820 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2821#else
2822 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
2823 | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
2824#endif
2825
2826 0, /* leading char */
2827 '/', /* ar_pad_char */
2828 15, /* ar_max_namelen??? FIXMEmgo */
2829
2830 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2831 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2832 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
2833
2834 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2835 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2836 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
2837
2838 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
2839 bfd_generic_archive_p, /* _bfd_dummy_target */ coff_object_p },
2840 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
2841 bfd_false},
2842 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
2843 _bfd_write_archive_contents, bfd_false},
2844
2845 BFD_JUMP_TABLE_GENERIC (coff),
2846 BFD_JUMP_TABLE_COPY (coff),
2847 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2848 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
2849 BFD_JUMP_TABLE_SYMBOLS (coff),
2850 BFD_JUMP_TABLE_RELOCS (coff),
2851 BFD_JUMP_TABLE_WRITE (coff),
2852 BFD_JUMP_TABLE_LINK (coff),
2853 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2854
c3c89269
NC
2855 /* Alternative_target. */
2856#ifdef TARGET_LITTLE_SYM
2857 & TARGET_LITTLE_SYM,
2858#else
2859 NULL,
2860#endif
43646c9d 2861
c3c89269 2862 COFF_SWAP_TABLE
252b5132
RH
2863};
2864
2865#endif
This page took 0.380462 seconds and 4 git commands to generate.