Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for PowerPC Microsoft Portable Executable files. |
7898deda | 2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
2ab1486e | 3 | 2000, 2001, 2002, 2003 |
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 | 56 | extern bfd_boolean ppc_bfd_coff_final_link |
252b5132 RH |
57 | PARAMS ((bfd *, struct bfd_link_info *)); |
58 | extern 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 | |
107 | struct 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 | ||
122 | struct ppc_coff_link_hash_table | |
123 | { | |
2ab1486e | 124 | struct coff_link_hash_table root; /* First entry, as required. */ |
252b5132 RH |
125 | }; |
126 | ||
127 | static struct bfd_hash_entry *ppc_coff_link_hash_newfunc | |
128 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, | |
129 | const char *)); | |
b34976b6 | 130 | static 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 *))); | |
135 | static struct bfd_link_hash_table *ppc_coff_link_hash_table_create | |
136 | PARAMS ((bfd *)); | |
b34976b6 | 137 | static 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 **)); | |
140 | static 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 | ||
147 | static struct bfd_hash_entry * | |
148 | ppc_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 | 186 | static bfd_boolean |
252b5132 RH |
187 | ppc_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 | ||
199 | static struct bfd_link_hash_table * | |
200 | ppc_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 | ||
322 | static 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 | |
330 | static 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 | |
338 | static 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 |
346 | static 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 | |
355 | static 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 | |
363 | static 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 | ||
371 | static 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 | ||
379 | static 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 | 387 | static 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 | |
422 | static 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 | 810 | extern bfd * bfd_of_toc_owner; |
252b5132 | 811 | extern long int global_toc_size; |
252b5132 RH |
812 | extern long int import_table_size; |
813 | extern long int first_thunk_address; | |
814 | extern long int thunk_size; | |
815 | ||
816 | enum toc_type | |
817 | { | |
818 | default_toc, | |
819 | toc_32, | |
820 | toc_64 | |
821 | }; | |
822 | ||
823 | enum ref_category | |
824 | { | |
825 | priv, | |
826 | pub, | |
dc810e39 | 827 | tocdata |
252b5132 RH |
828 | }; |
829 | ||
830 | struct 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 | ||
839 | extern struct list_ele *head; | |
840 | extern struct list_ele *tail; | |
841 | ||
842 | static void record_toc | |
dc810e39 | 843 | PARAMS ((asection *, bfd_signed_vma, enum ref_category, const char *)); |
252b5132 RH |
844 | |
845 | static void | |
846 | record_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 | 878 | static bfd_boolean ppc_record_toc_entry |
252b5132 RH |
879 | PARAMS ((bfd *, struct bfd_link_info *, asection *, int, enum toc_type)); |
880 | static void ppc_mark_symbol_as_glue | |
881 | PARAMS ((bfd *, int, struct internal_reloc *)); | |
882 | ||
2ab1486e | 883 | /* Record a toc offset against a symbol. */ |
b34976b6 | 884 | static bfd_boolean |
252b5132 RH |
885 | ppc_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 |
966 | static void |
967 | ppc_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 | 989 | static 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 | |
1014 | static bfd_reloc_status_type | |
1015 | pe_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 | 1071 | static bfd_boolean |
252b5132 RH |
1072 | coff_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) | |
1191 | (_("%s: unsupported relocation type 0x%02x"), | |
8f615d07 | 1192 | bfd_archive_filename (input_bfd), r_type); |
252b5132 | 1193 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 1194 | return FALSE; |
252b5132 RH |
1195 | case IMAGE_REL_PPC_TOCREL16: |
1196 | { | |
dc810e39 | 1197 | bfd_signed_vma our_toc_offset; |
252b5132 RH |
1198 | int fixit; |
1199 | ||
1200 | DUMP_RELOC2(howto->name, rel); | |
1201 | ||
43646c9d | 1202 | if (toc_section == 0) |
252b5132 | 1203 | { |
43646c9d | 1204 | toc_section = bfd_get_section_by_name (bfd_of_toc_owner, |
252b5132 RH |
1205 | TOC_SECTION_NAME); |
1206 | ||
43646c9d | 1207 | if ( toc_section == NULL ) |
252b5132 | 1208 | { |
43646c9d | 1209 | /* There is no toc section. Something is very wrong. */ |
c5930ee6 | 1210 | abort (); |
252b5132 RH |
1211 | } |
1212 | } | |
1213 | ||
2ab1486e NC |
1214 | /* Amazing bit tricks present. As we may have seen earlier, we |
1215 | use the 1 bit to tell us whether or not a toc offset has been | |
1216 | allocated. Now that they've all been allocated, we will use | |
1217 | the 1 bit to tell us if we've written this particular toc | |
1218 | entry out. */ | |
b34976b6 | 1219 | fixit = FALSE; |
252b5132 | 1220 | if (h == 0) |
2ab1486e NC |
1221 | { |
1222 | /* It is a file local symbol. */ | |
252b5132 RH |
1223 | int *local_toc_table; |
1224 | const char *name; | |
1225 | ||
1226 | sym = syms + symndx; | |
1227 | name = sym->_n._n_name; | |
1228 | ||
1229 | local_toc_table = obj_coff_local_toc_table(input_bfd); | |
1230 | our_toc_offset = local_toc_table[symndx]; | |
1231 | ||
1232 | if (IS_WRITTEN(our_toc_offset)) | |
1233 | { | |
2ab1486e | 1234 | /* If it has been written out, it is marked with the |
252b5132 | 1235 | 1 bit. Fix up our offset, but do not write it out |
2ab1486e | 1236 | again. */ |
252b5132 RH |
1237 | MAKE_ADDR_AGAIN(our_toc_offset); |
1238 | } | |
1239 | else | |
1240 | { | |
2ab1486e | 1241 | /* Write out the toc entry. */ |
dc810e39 AM |
1242 | record_toc (toc_section, our_toc_offset, priv, |
1243 | strdup (name)); | |
252b5132 | 1244 | |
dc810e39 | 1245 | bfd_put_32 (output_bfd, val, |
252b5132 RH |
1246 | toc_section->contents + our_toc_offset); |
1247 | ||
1248 | MARK_AS_WRITTEN(local_toc_table[symndx]); | |
b34976b6 | 1249 | fixit = TRUE; |
252b5132 RH |
1250 | } |
1251 | } | |
1252 | else | |
1253 | { | |
1254 | const char *name = h->root.root.root.string; | |
1255 | our_toc_offset = h->toc_offset; | |
1256 | ||
43646c9d | 1257 | if ((r_flags & IMAGE_REL_PPC_TOCDEFN) |
252b5132 RH |
1258 | == IMAGE_REL_PPC_TOCDEFN ) |
1259 | { | |
43646c9d KH |
1260 | /* This is unbelievable cheese. Some knowledgable asm |
1261 | hacker has decided to use r2 as a base for loading | |
1262 | a value. He/She does this by setting the tocdefn bit, | |
1263 | and not supplying a toc definition. The behaviour is | |
1264 | then to use the difference between the value of the | |
1265 | symbol and the actual location of the toc as the toc | |
1266 | index. | |
252b5132 RH |
1267 | |
1268 | In fact, what is usually happening is, because the | |
1269 | Import Address Table is mapped immediately following | |
1270 | the toc, some trippy library code trying for speed on | |
43646c9d | 1271 | dll linkage, takes advantage of that and considers |
2ab1486e | 1272 | the IAT to be part of the toc, thus saving a load. */ |
252b5132 | 1273 | |
dc810e39 AM |
1274 | our_toc_offset = val - (toc_section->output_section->vma |
1275 | + toc_section->output_offset); | |
252b5132 | 1276 | |
5c4491d3 | 1277 | /* The size must still fit in a 16-bit displacement. */ |
dc810e39 | 1278 | if ((bfd_vma) our_toc_offset >= 65535) |
252b5132 RH |
1279 | { |
1280 | (*_bfd_error_handler) | |
dc810e39 | 1281 | (_("%s: Relocation for %s of %lx exceeds Toc size limit"), |
8f615d07 | 1282 | bfd_archive_filename (input_bfd), name, |
dc810e39 | 1283 | (unsigned long) our_toc_offset); |
252b5132 | 1284 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 1285 | return FALSE; |
252b5132 RH |
1286 | } |
1287 | ||
dc810e39 AM |
1288 | record_toc (toc_section, our_toc_offset, pub, |
1289 | strdup (name)); | |
252b5132 | 1290 | } |
2ab1486e | 1291 | else if (IS_WRITTEN (our_toc_offset)) |
252b5132 | 1292 | { |
2ab1486e | 1293 | /* If it has been written out, it is marked with the |
252b5132 | 1294 | 1 bit. Fix up our offset, but do not write it out |
2ab1486e | 1295 | again. */ |
252b5132 RH |
1296 | MAKE_ADDR_AGAIN(our_toc_offset); |
1297 | } | |
1298 | else | |
1299 | { | |
dc810e39 AM |
1300 | record_toc(toc_section, our_toc_offset, pub, |
1301 | strdup (name)); | |
252b5132 | 1302 | |
2ab1486e | 1303 | /* Write out the toc entry. */ |
dc810e39 | 1304 | bfd_put_32 (output_bfd, val, |
252b5132 RH |
1305 | toc_section->contents + our_toc_offset); |
1306 | ||
1307 | MARK_AS_WRITTEN(h->toc_offset); | |
2ab1486e NC |
1308 | /* The tricky part is that this is the address that |
1309 | needs a .reloc entry for it. */ | |
b34976b6 | 1310 | fixit = TRUE; |
252b5132 RH |
1311 | } |
1312 | } | |
1313 | ||
43646c9d | 1314 | if (fixit && info->base_file) |
252b5132 RH |
1315 | { |
1316 | /* So if this is non pcrelative, and is referenced | |
2ab1486e | 1317 | to a section or a common symbol, then it needs a reloc. */ |
252b5132 | 1318 | |
2ab1486e | 1319 | /* Relocation to a symbol in a section which |
43646c9d | 1320 | isn't absolute - we output the address here |
2ab1486e | 1321 | to a file. */ |
dc810e39 AM |
1322 | bfd_vma addr = (toc_section->output_section->vma |
1323 | + toc_section->output_offset + our_toc_offset); | |
43646c9d | 1324 | |
2ab1486e | 1325 | if (coff_data (output_bfd)->pe) |
252b5132 RH |
1326 | addr -= pe_data(output_bfd)->pe_opthdr.ImageBase; |
1327 | ||
1328 | fwrite (&addr, 1,4, (FILE *) info->base_file); | |
1329 | } | |
1330 | ||
2ab1486e | 1331 | /* FIXME: this test is conservative. */ |
dc810e39 AM |
1332 | if ((r_flags & IMAGE_REL_PPC_TOCDEFN) != IMAGE_REL_PPC_TOCDEFN |
1333 | && (bfd_vma) our_toc_offset > toc_section->_raw_size) | |
252b5132 RH |
1334 | { |
1335 | (*_bfd_error_handler) | |
dc810e39 | 1336 | (_("%s: Relocation exceeds allocated TOC (%lx)"), |
8f615d07 | 1337 | bfd_archive_filename (input_bfd), |
dc810e39 | 1338 | (unsigned long) toc_section->_raw_size); |
252b5132 | 1339 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 1340 | return FALSE; |
252b5132 RH |
1341 | } |
1342 | ||
2ab1486e | 1343 | /* Now we know the relocation for this toc reference. */ |
252b5132 | 1344 | relocation = our_toc_offset + TOC_LOAD_ADJUSTMENT; |
dc810e39 | 1345 | rstat = _bfd_relocate_contents (howto, input_bfd, relocation, loc); |
252b5132 RH |
1346 | } |
1347 | break; | |
1348 | case IMAGE_REL_PPC_IFGLUE: | |
1349 | { | |
2ab1486e NC |
1350 | /* To solve this, we need to know whether or not the symbol |
1351 | appearing on the call instruction is a glue function or not. | |
1352 | A glue function must announce itself via a IMGLUE reloc, and | |
1353 | the reloc contains the required toc restore instruction. */ | |
252b5132 RH |
1354 | bfd_vma x; |
1355 | const char *my_name; | |
2ab1486e NC |
1356 | |
1357 | DUMP_RELOC2 (howto->name, rel); | |
252b5132 RH |
1358 | |
1359 | if (h != 0) | |
1360 | { | |
1361 | my_name = h->root.root.root.string; | |
43646c9d | 1362 | if (h->symbol_is_glue == 1) |
252b5132 | 1363 | { |
6e301b2b | 1364 | x = bfd_get_32 (input_bfd, loc); |
dc810e39 | 1365 | bfd_put_32 (input_bfd, (bfd_vma) h->glue_insn, loc); |
252b5132 RH |
1366 | } |
1367 | } | |
1368 | } | |
1369 | break; | |
1370 | case IMAGE_REL_PPC_SECREL: | |
2ab1486e | 1371 | /* Unimplemented: codeview debugging information. */ |
43646c9d KH |
1372 | /* For fast access to the header of the section |
1373 | containing the item. */ | |
252b5132 RH |
1374 | break; |
1375 | case IMAGE_REL_PPC_SECTION: | |
2ab1486e | 1376 | /* Unimplemented: codeview debugging information. */ |
252b5132 RH |
1377 | /* Is used to indicate that the value should be relative |
1378 | to the beginning of the section that contains the | |
2ab1486e | 1379 | symbol. */ |
252b5132 RH |
1380 | break; |
1381 | case IMAGE_REL_PPC_ABSOLUTE: | |
1382 | { | |
1383 | const char *my_name; | |
2ab1486e | 1384 | |
252b5132 | 1385 | if (h == 0) |
2ab1486e | 1386 | my_name = (syms+symndx)->_n._n_name; |
252b5132 | 1387 | else |
2ab1486e | 1388 | my_name = h->root.root.root.string; |
252b5132 | 1389 | |
6e301b2b | 1390 | fprintf (stderr, |
43646c9d | 1391 | _("Warning: unsupported reloc %s <file %s, section %s>\n"), |
252b5132 | 1392 | howto->name, |
8f615d07 | 1393 | bfd_archive_filename(input_bfd), |
252b5132 RH |
1394 | input_section->name); |
1395 | ||
6e301b2b | 1396 | fprintf (stderr,"sym %ld (%s), r_vaddr %ld (%lx)\n", |
252b5132 | 1397 | rel->r_symndx, my_name, (long) rel->r_vaddr, |
43646c9d | 1398 | (unsigned long) rel->r_vaddr); |
252b5132 RH |
1399 | } |
1400 | break; | |
1401 | case IMAGE_REL_PPC_IMGLUE: | |
1402 | { | |
1403 | /* There is nothing to do now. This reloc was noted in the first | |
2ab1486e | 1404 | pass over the relocs, and the glue instruction extracted. */ |
252b5132 | 1405 | const char *my_name; |
2ab1486e | 1406 | |
43646c9d | 1407 | if (h->symbol_is_glue == 1) |
252b5132 RH |
1408 | break; |
1409 | my_name = h->root.root.root.string; | |
1410 | ||
1411 | (*_bfd_error_handler) | |
43646c9d | 1412 | (_("%s: Out of order IMGLUE reloc for %s"), |
8f615d07 | 1413 | bfd_archive_filename (input_bfd), my_name); |
252b5132 | 1414 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 1415 | return FALSE; |
252b5132 RH |
1416 | } |
1417 | ||
1418 | case IMAGE_REL_PPC_ADDR32NB: | |
1419 | { | |
252b5132 | 1420 | const char *name = 0; |
2ab1486e NC |
1421 | |
1422 | DUMP_RELOC2 (howto->name, rel); | |
252b5132 RH |
1423 | |
1424 | if (strncmp(".idata$2",input_section->name,8) == 0 && first_thunk_address == 0) | |
1425 | { | |
2ab1486e | 1426 | /* Set magic values. */ |
252b5132 | 1427 | int idata5offset; |
dc810e39 | 1428 | struct coff_link_hash_entry *myh; |
2ab1486e | 1429 | |
252b5132 RH |
1430 | myh = coff_link_hash_lookup (coff_hash_table (info), |
1431 | "__idata5_magic__", | |
b34976b6 | 1432 | FALSE, FALSE, TRUE); |
43646c9d KH |
1433 | first_thunk_address = myh->root.u.def.value + |
1434 | sec->output_section->vma + | |
1435 | sec->output_offset - | |
252b5132 | 1436 | pe_data(output_bfd)->pe_opthdr.ImageBase; |
43646c9d | 1437 | |
252b5132 RH |
1438 | idata5offset = myh->root.u.def.value; |
1439 | myh = coff_link_hash_lookup (coff_hash_table (info), | |
1440 | "__idata6_magic__", | |
b34976b6 | 1441 | FALSE, FALSE, TRUE); |
43646c9d | 1442 | |
252b5132 RH |
1443 | thunk_size = myh->root.u.def.value - idata5offset; |
1444 | myh = coff_link_hash_lookup (coff_hash_table (info), | |
1445 | "__idata4_magic__", | |
b34976b6 | 1446 | FALSE, FALSE, TRUE); |
252b5132 RH |
1447 | import_table_size = myh->root.u.def.value; |
1448 | } | |
1449 | ||
1450 | if (h == 0) | |
2ab1486e NC |
1451 | { |
1452 | /* It is a file local symbol. */ | |
252b5132 RH |
1453 | sym = syms + symndx; |
1454 | name = sym->_n._n_name; | |
1455 | } | |
1456 | else | |
1457 | { | |
1458 | char *target = 0; | |
1459 | ||
1460 | name = h->root.root.root.string; | |
2ab1486e | 1461 | if (strcmp (".idata$2", name) == 0) |
252b5132 | 1462 | target = "__idata2_magic__"; |
2ab1486e | 1463 | else if (strcmp (".idata$4", name) == 0) |
252b5132 | 1464 | target = "__idata4_magic__"; |
2ab1486e | 1465 | else if (strcmp (".idata$5", name) == 0) |
252b5132 RH |
1466 | target = "__idata5_magic__"; |
1467 | ||
1468 | if (target != 0) | |
1469 | { | |
dc810e39 | 1470 | struct coff_link_hash_entry *myh; |
252b5132 RH |
1471 | |
1472 | myh = coff_link_hash_lookup (coff_hash_table (info), | |
1473 | target, | |
b34976b6 | 1474 | FALSE, FALSE, TRUE); |
43646c9d | 1475 | if (myh == 0) |
252b5132 | 1476 | { |
43646c9d | 1477 | /* Missing magic cookies. Something is very wrong. */ |
c5930ee6 | 1478 | abort (); |
252b5132 | 1479 | } |
43646c9d KH |
1480 | |
1481 | val = myh->root.u.def.value + | |
252b5132 RH |
1482 | sec->output_section->vma + sec->output_offset; |
1483 | if (first_thunk_address == 0) | |
1484 | { | |
1485 | int idata5offset; | |
1486 | myh = coff_link_hash_lookup (coff_hash_table (info), | |
1487 | "__idata5_magic__", | |
b34976b6 | 1488 | FALSE, FALSE, TRUE); |
43646c9d KH |
1489 | first_thunk_address = myh->root.u.def.value + |
1490 | sec->output_section->vma + | |
1491 | sec->output_offset - | |
252b5132 | 1492 | pe_data(output_bfd)->pe_opthdr.ImageBase; |
43646c9d | 1493 | |
252b5132 RH |
1494 | idata5offset = myh->root.u.def.value; |
1495 | myh = coff_link_hash_lookup (coff_hash_table (info), | |
1496 | "__idata6_magic__", | |
b34976b6 | 1497 | FALSE, FALSE, TRUE); |
43646c9d | 1498 | |
252b5132 RH |
1499 | thunk_size = myh->root.u.def.value - idata5offset; |
1500 | myh = coff_link_hash_lookup (coff_hash_table (info), | |
1501 | "__idata4_magic__", | |
b34976b6 | 1502 | FALSE, FALSE, TRUE); |
252b5132 RH |
1503 | import_table_size = myh->root.u.def.value; |
1504 | } | |
1505 | } | |
1506 | } | |
1507 | ||
1508 | rstat = _bfd_relocate_contents (howto, | |
2ab1486e NC |
1509 | input_bfd, |
1510 | val - | |
1511 | pe_data (output_bfd)->pe_opthdr.ImageBase, | |
1512 | loc); | |
252b5132 RH |
1513 | } |
1514 | break; | |
1515 | ||
1516 | case IMAGE_REL_PPC_REL24: | |
1517 | DUMP_RELOC2(howto->name, rel); | |
1518 | val -= (input_section->output_section->vma | |
1519 | + input_section->output_offset); | |
1520 | ||
1521 | rstat = _bfd_relocate_contents (howto, | |
43646c9d KH |
1522 | input_bfd, |
1523 | val, | |
252b5132 RH |
1524 | loc); |
1525 | break; | |
1526 | case IMAGE_REL_PPC_ADDR16: | |
1527 | case IMAGE_REL_PPC_ADDR24: | |
1528 | case IMAGE_REL_PPC_ADDR32: | |
1529 | DUMP_RELOC2(howto->name, rel); | |
1530 | rstat = _bfd_relocate_contents (howto, | |
43646c9d KH |
1531 | input_bfd, |
1532 | val, | |
252b5132 RH |
1533 | loc); |
1534 | break; | |
1535 | } | |
1536 | ||
2ab1486e | 1537 | if (info->base_file) |
252b5132 RH |
1538 | { |
1539 | /* So if this is non pcrelative, and is referenced | |
2ab1486e NC |
1540 | to a section or a common symbol, then it needs a reloc. */ |
1541 | if (sym && pe_data(output_bfd)->in_reloc_p (output_bfd, howto)) | |
252b5132 | 1542 | { |
2ab1486e | 1543 | /* Relocation to a symbol in a section which |
43646c9d | 1544 | isn't absolute - we output the address here |
2ab1486e | 1545 | to a file. */ |
43646c9d KH |
1546 | bfd_vma addr = rel->r_vaddr |
1547 | - input_section->vma | |
1548 | + input_section->output_offset | |
252b5132 RH |
1549 | + input_section->output_section->vma; |
1550 | ||
2ab1486e NC |
1551 | if (coff_data (output_bfd)->pe) |
1552 | addr -= pe_data (output_bfd)->pe_opthdr.ImageBase; | |
1553 | ||
252b5132 RH |
1554 | fwrite (&addr, 1,4, (FILE *) info->base_file); |
1555 | } | |
1556 | } | |
1557 | ||
1558 | switch (rstat) | |
1559 | { | |
1560 | default: | |
1561 | abort (); | |
1562 | case bfd_reloc_ok: | |
1563 | break; | |
1564 | case bfd_reloc_overflow: | |
1565 | { | |
1566 | const char *name; | |
1567 | char buf[SYMNMLEN + 1]; | |
1568 | ||
1569 | if (symndx == -1) | |
1570 | name = "*ABS*"; | |
1571 | else if (h != NULL) | |
1572 | name = h->root.root.root.string; | |
1573 | else if (sym == NULL) | |
1574 | name = "*unknown*"; | |
1575 | else if (sym->_n._n_n._n_zeroes == 0 | |
1576 | && sym->_n._n_n._n_offset != 0) | |
1577 | name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset; | |
1578 | else | |
1579 | { | |
1580 | strncpy (buf, sym->_n._n_name, SYMNMLEN); | |
1581 | buf[SYMNMLEN] = '\0'; | |
1582 | name = buf; | |
1583 | } | |
1584 | ||
1585 | if (! ((*info->callbacks->reloc_overflow) | |
43646c9d | 1586 | (info, name, howto->name, |
252b5132 RH |
1587 | (bfd_vma) 0, input_bfd, |
1588 | input_section, rel->r_vaddr - input_section->vma))) | |
2ab1486e | 1589 | return FALSE; |
252b5132 RH |
1590 | } |
1591 | } | |
43646c9d | 1592 | } |
252b5132 | 1593 | |
b34976b6 | 1594 | return TRUE; |
252b5132 RH |
1595 | } |
1596 | ||
1597 | #ifdef COFF_IMAGE_WITH_PE | |
1598 | ||
1599 | /* FIXME: BFD should not use global variables. This file is compiled | |
1600 | twice, and these variables are shared. This is confusing and | |
1601 | weird. */ | |
1602 | ||
1603 | long int global_toc_size = 4; | |
1604 | ||
1605 | bfd* bfd_of_toc_owner = 0; | |
1606 | ||
1607 | long int import_table_size; | |
1608 | long int first_thunk_address; | |
1609 | long int thunk_size; | |
1610 | ||
1611 | struct list_ele *head; | |
1612 | struct list_ele *tail; | |
1613 | ||
1614 | static char * | |
1615 | h1 = N_("\n\t\t\tTOC MAPPING\n\n"); | |
1616 | static char * | |
1617 | h2 = N_(" TOC disassembly Comments Name\n"); | |
1618 | static char * | |
1619 | h3 = N_(" Offset spelling (if present)\n"); | |
1620 | ||
1621 | void | |
1622 | dump_toc (vfile) | |
1623 | PTR vfile; | |
1624 | { | |
1625 | FILE *file = (FILE *) vfile; | |
1626 | struct list_ele *t; | |
1627 | ||
6e301b2b KH |
1628 | fprintf (file, _(h1)); |
1629 | fprintf (file, _(h2)); | |
1630 | fprintf (file, _(h3)); | |
252b5132 | 1631 | |
6e301b2b | 1632 | for (t = head; t != 0; t=t->next) |
252b5132 RH |
1633 | { |
1634 | const char *cat = ""; | |
1635 | ||
1636 | if (t->cat == priv) | |
1637 | cat = _("private "); | |
1638 | else if (t->cat == pub) | |
1639 | cat = _("public "); | |
dc810e39 | 1640 | else if (t->cat == tocdata) |
252b5132 RH |
1641 | cat = _("data-in-toc "); |
1642 | ||
1643 | if (t->offset > global_toc_size) | |
1644 | { | |
1645 | if (t->offset <= global_toc_size + thunk_size) | |
1646 | cat = _("IAT reference "); | |
1647 | else | |
1648 | { | |
6e301b2b | 1649 | fprintf (file, |
252b5132 | 1650 | _("**** global_toc_size %ld(%lx), thunk_size %ld(%lx)\n"), |
dc810e39 AM |
1651 | global_toc_size, global_toc_size, |
1652 | thunk_size, thunk_size); | |
252b5132 RH |
1653 | cat = _("Out of bounds!"); |
1654 | } | |
1655 | } | |
1656 | ||
6e301b2b | 1657 | fprintf (file, |
252b5132 | 1658 | " %04lx (%d)", (unsigned long) t->offset, t->offset - 32768); |
6e301b2b | 1659 | fprintf (file, |
252b5132 RH |
1660 | " %s %s\n", |
1661 | cat, t->name); | |
1662 | ||
1663 | } | |
1664 | ||
6e301b2b | 1665 | fprintf (file, "\n"); |
252b5132 RH |
1666 | } |
1667 | ||
b34976b6 | 1668 | bfd_boolean |
43646c9d | 1669 | ppc_allocate_toc_section (info) |
5f771d47 | 1670 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
252b5132 RH |
1671 | { |
1672 | asection *s; | |
1673 | bfd_byte *foo; | |
dc810e39 | 1674 | bfd_size_type amt; |
252b5132 RH |
1675 | static char test_char = '1'; |
1676 | ||
2ab1486e | 1677 | if ( global_toc_size == 0 ) /* FIXME: does this get me in trouble? */ |
b34976b6 | 1678 | return TRUE; |
252b5132 RH |
1679 | |
1680 | if (bfd_of_toc_owner == 0) | |
2ab1486e NC |
1681 | /* No toc owner? Something is very wrong. */ |
1682 | abort (); | |
252b5132 RH |
1683 | |
1684 | s = bfd_get_section_by_name ( bfd_of_toc_owner , TOC_SECTION_NAME); | |
43646c9d | 1685 | if (s == NULL) |
2ab1486e NC |
1686 | /* No toc section? Something is very wrong. */ |
1687 | abort (); | |
252b5132 | 1688 | |
dc810e39 AM |
1689 | amt = global_toc_size; |
1690 | foo = (bfd_byte *) bfd_alloc (bfd_of_toc_owner, amt); | |
1691 | memset(foo, test_char, (size_t) global_toc_size); | |
252b5132 RH |
1692 | |
1693 | s->_raw_size = s->_cooked_size = global_toc_size; | |
1694 | s->contents = foo; | |
1695 | ||
b34976b6 | 1696 | return TRUE; |
252b5132 RH |
1697 | } |
1698 | ||
b34976b6 | 1699 | bfd_boolean |
252b5132 RH |
1700 | ppc_process_before_allocation (abfd, info) |
1701 | bfd *abfd; | |
1702 | struct bfd_link_info *info; | |
1703 | { | |
1704 | asection *sec; | |
1705 | struct internal_reloc *i, *rel; | |
1706 | ||
2ab1486e | 1707 | /* Here we have a bfd that is to be included on the link. We have a hook |
43646c9d | 1708 | to do reloc rummaging, before section sizes are nailed down. */ |
2ab1486e | 1709 | _bfd_coff_get_external_symbols (abfd); |
252b5132 | 1710 | |
2ab1486e | 1711 | /* Rummage around all the relocs and map the toc. */ |
252b5132 RH |
1712 | sec = abfd->sections; |
1713 | ||
1714 | if (sec == 0) | |
2ab1486e | 1715 | return TRUE; |
252b5132 RH |
1716 | |
1717 | for (; sec != 0; sec = sec->next) | |
2ab1486e NC |
1718 | { |
1719 | if (sec->reloc_count == 0) | |
1720 | continue; | |
252b5132 | 1721 | |
2ab1486e NC |
1722 | /* load the relocs */ |
1723 | /* FIXME: there may be a storage leak here */ | |
1724 | i=_bfd_coff_read_internal_relocs(abfd,sec,1,0,0,0); | |
43646c9d | 1725 | |
2ab1486e NC |
1726 | if (i == 0) |
1727 | abort (); | |
252b5132 | 1728 | |
2ab1486e NC |
1729 | for (rel = i; rel < i + sec->reloc_count; ++rel) |
1730 | { | |
1731 | unsigned short r_type = EXTRACT_TYPE (rel->r_type); | |
1732 | unsigned short r_flags = EXTRACT_FLAGS (rel->r_type); | |
1733 | bfd_boolean ok = TRUE; | |
252b5132 | 1734 | |
2ab1486e | 1735 | DUMP_RELOC2 (ppc_coff_howto_table[r_type].name, rel); |
252b5132 | 1736 | |
2ab1486e NC |
1737 | switch(r_type) |
1738 | { | |
1739 | case IMAGE_REL_PPC_TOCREL16: | |
1740 | /* If TOCDEFN is on, ignore as someone else has allocated the | |
1741 | toc entry. */ | |
1742 | if ((r_flags & IMAGE_REL_PPC_TOCDEFN) != IMAGE_REL_PPC_TOCDEFN) | |
1743 | ok = ppc_record_toc_entry(abfd, info, sec, | |
1744 | rel->r_symndx, default_toc); | |
1745 | if (!ok) | |
1746 | return FALSE; | |
1747 | break; | |
1748 | case IMAGE_REL_PPC_IMGLUE: | |
1749 | ppc_mark_symbol_as_glue (abfd, rel->r_symndx, rel); | |
1750 | break; | |
1751 | default: | |
1752 | break; | |
1753 | } | |
1754 | } | |
1755 | } | |
252b5132 | 1756 | |
b34976b6 | 1757 | return TRUE; |
252b5132 RH |
1758 | } |
1759 | ||
1760 | #endif | |
1761 | ||
252b5132 | 1762 | static bfd_reloc_status_type |
2ab1486e NC |
1763 | ppc_refhi_reloc (abfd, reloc_entry, symbol, data, |
1764 | input_section, output_bfd, error_message) | |
5f771d47 ILT |
1765 | bfd *abfd ATTRIBUTE_UNUSED; |
1766 | arelent *reloc_entry ATTRIBUTE_UNUSED; | |
1767 | asymbol *symbol ATTRIBUTE_UNUSED; | |
1768 | PTR data ATTRIBUTE_UNUSED; | |
1769 | asection *input_section ATTRIBUTE_UNUSED; | |
252b5132 | 1770 | bfd *output_bfd; |
5f771d47 | 1771 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
1772 | { |
1773 | UN_IMPL("REFHI"); | |
1774 | DUMP_RELOC("REFHI",reloc_entry); | |
1775 | ||
1776 | if (output_bfd == (bfd *) NULL) | |
1777 | return bfd_reloc_continue; | |
1778 | ||
1779 | return bfd_reloc_undefined; | |
1780 | } | |
1781 | ||
1782 | #if 0 | |
1783 | ||
1784 | static bfd_reloc_status_type | |
2ab1486e NC |
1785 | ppc_reflo_reloc (abfd, reloc_entry, symbol, data, |
1786 | input_section, output_bfd, error_message) | |
252b5132 RH |
1787 | bfd *abfd; |
1788 | arelent *reloc_entry; | |
1789 | asymbol *symbol; | |
1790 | PTR data; | |
1791 | asection *input_section; | |
1792 | bfd *output_bfd; | |
1793 | char **error_message; | |
1794 | { | |
1795 | UN_IMPL("REFLO"); | |
1796 | DUMP_RELOC("REFLO",reloc_entry); | |
1797 | ||
1798 | if (output_bfd == (bfd *) NULL) | |
1799 | return bfd_reloc_continue; | |
1800 | ||
1801 | return bfd_reloc_undefined; | |
1802 | } | |
1803 | ||
1804 | #endif | |
1805 | ||
1806 | static bfd_reloc_status_type | |
2ab1486e NC |
1807 | ppc_pair_reloc (abfd, reloc_entry, symbol, data, |
1808 | input_section, output_bfd, error_message) | |
5f771d47 ILT |
1809 | bfd *abfd ATTRIBUTE_UNUSED; |
1810 | arelent *reloc_entry ATTRIBUTE_UNUSED; | |
1811 | asymbol *symbol ATTRIBUTE_UNUSED; | |
1812 | PTR data ATTRIBUTE_UNUSED; | |
1813 | asection *input_section ATTRIBUTE_UNUSED; | |
252b5132 | 1814 | bfd *output_bfd; |
5f771d47 | 1815 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
1816 | { |
1817 | UN_IMPL("PAIR"); | |
1818 | DUMP_RELOC("PAIR",reloc_entry); | |
1819 | ||
1820 | if (output_bfd == (bfd *) NULL) | |
1821 | return bfd_reloc_continue; | |
1822 | ||
1823 | return bfd_reloc_undefined; | |
1824 | } | |
252b5132 RH |
1825 | \f |
1826 | static bfd_reloc_status_type | |
2ab1486e NC |
1827 | ppc_toc16_reloc (abfd, reloc_entry, symbol, data, |
1828 | input_section, output_bfd, error_message) | |
5f771d47 ILT |
1829 | bfd *abfd ATTRIBUTE_UNUSED; |
1830 | arelent *reloc_entry ATTRIBUTE_UNUSED; | |
1831 | asymbol *symbol ATTRIBUTE_UNUSED; | |
1832 | PTR data ATTRIBUTE_UNUSED; | |
1833 | asection *input_section ATTRIBUTE_UNUSED; | |
252b5132 | 1834 | bfd *output_bfd; |
5f771d47 | 1835 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 | 1836 | { |
2ab1486e NC |
1837 | UN_IMPL ("TOCREL16"); |
1838 | DUMP_RELOC ("TOCREL16",reloc_entry); | |
252b5132 RH |
1839 | |
1840 | if (output_bfd == (bfd *) NULL) | |
2ab1486e | 1841 | return bfd_reloc_continue; |
252b5132 RH |
1842 | |
1843 | return bfd_reloc_ok; | |
1844 | } | |
1845 | ||
1846 | #if 0 | |
1847 | ||
2ab1486e NC |
1848 | /* ADDR32NB : 32 bit address relative to the virtual origin. |
1849 | (On the alpha, this is always a linker generated thunk) | |
1850 | (i.e. 32bit addr relative to the image base). */ | |
252b5132 RH |
1851 | |
1852 | static bfd_reloc_status_type | |
2ab1486e NC |
1853 | ppc_addr32nb_reloc (abfd, reloc_entry, symbol, data, |
1854 | input_section, output_bfd, error_message) | |
252b5132 RH |
1855 | bfd *abfd; |
1856 | arelent *reloc_entry; | |
1857 | asymbol *symbol; | |
1858 | PTR data; | |
1859 | asection *input_section; | |
1860 | bfd *output_bfd; | |
1861 | char **error_message; | |
1862 | { | |
1863 | UN_IMPL("ADDR32NB"); | |
1864 | DUMP_RELOC("ADDR32NB",reloc_entry); | |
1865 | ||
1866 | return bfd_reloc_ok; | |
1867 | } | |
1868 | ||
1869 | #endif | |
1870 | ||
1871 | static bfd_reloc_status_type | |
2ab1486e NC |
1872 | ppc_secrel_reloc (abfd, reloc_entry, symbol, data, |
1873 | input_section, output_bfd, error_message) | |
5f771d47 ILT |
1874 | bfd *abfd ATTRIBUTE_UNUSED; |
1875 | arelent *reloc_entry ATTRIBUTE_UNUSED; | |
1876 | asymbol *symbol ATTRIBUTE_UNUSED; | |
1877 | PTR data ATTRIBUTE_UNUSED; | |
1878 | asection *input_section ATTRIBUTE_UNUSED; | |
252b5132 | 1879 | bfd *output_bfd; |
5f771d47 | 1880 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
1881 | { |
1882 | UN_IMPL("SECREL"); | |
1883 | DUMP_RELOC("SECREL",reloc_entry); | |
1884 | ||
1885 | if (output_bfd == (bfd *) NULL) | |
1886 | return bfd_reloc_continue; | |
1887 | ||
1888 | return bfd_reloc_ok; | |
1889 | } | |
1890 | ||
1891 | static bfd_reloc_status_type | |
2ab1486e NC |
1892 | ppc_section_reloc (abfd, reloc_entry, symbol, data, |
1893 | input_section, output_bfd, error_message) | |
5f771d47 ILT |
1894 | bfd *abfd ATTRIBUTE_UNUSED; |
1895 | arelent *reloc_entry ATTRIBUTE_UNUSED; | |
1896 | asymbol *symbol ATTRIBUTE_UNUSED; | |
1897 | PTR data ATTRIBUTE_UNUSED; | |
1898 | asection *input_section ATTRIBUTE_UNUSED; | |
252b5132 | 1899 | bfd *output_bfd; |
5f771d47 | 1900 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
1901 | { |
1902 | UN_IMPL("SECTION"); | |
1903 | DUMP_RELOC("SECTION",reloc_entry); | |
1904 | ||
1905 | if (output_bfd == (bfd *) NULL) | |
1906 | return bfd_reloc_continue; | |
1907 | ||
1908 | return bfd_reloc_ok; | |
1909 | } | |
1910 | ||
1911 | static bfd_reloc_status_type | |
2ab1486e NC |
1912 | ppc_imglue_reloc (abfd, reloc_entry, symbol, data, |
1913 | input_section, output_bfd, error_message) | |
5f771d47 ILT |
1914 | bfd *abfd ATTRIBUTE_UNUSED; |
1915 | arelent *reloc_entry ATTRIBUTE_UNUSED; | |
1916 | asymbol *symbol ATTRIBUTE_UNUSED; | |
1917 | PTR data ATTRIBUTE_UNUSED; | |
1918 | asection *input_section ATTRIBUTE_UNUSED; | |
252b5132 | 1919 | bfd *output_bfd; |
5f771d47 | 1920 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
1921 | { |
1922 | UN_IMPL("IMGLUE"); | |
1923 | DUMP_RELOC("IMGLUE",reloc_entry); | |
1924 | ||
1925 | if (output_bfd == (bfd *) NULL) | |
1926 | return bfd_reloc_continue; | |
1927 | ||
1928 | return bfd_reloc_ok; | |
1929 | } | |
252b5132 | 1930 | \f |
252b5132 | 1931 | #define MAX_RELOC_INDEX \ |
c5930ee6 | 1932 | (sizeof (ppc_coff_howto_table) / sizeof (ppc_coff_howto_table[0]) - 1) |
252b5132 | 1933 | |
5c4491d3 | 1934 | /* FIXME: There is a possibility that when we read in a reloc from a file, |
43646c9d | 1935 | that there are some bits encoded in the upper portion of the |
2ab1486e NC |
1936 | type field. Not yet implemented. */ |
1937 | static void ppc_coff_rtype2howto PARAMS ((arelent *, struct internal_reloc *)); | |
252b5132 RH |
1938 | |
1939 | static void | |
1940 | ppc_coff_rtype2howto (relent, internal) | |
1941 | arelent *relent; | |
1942 | struct internal_reloc *internal; | |
43646c9d | 1943 | { |
252b5132 RH |
1944 | /* We can encode one of three things in the type field, aside from the |
1945 | type: | |
1946 | 1. IMAGE_REL_PPC_NEG - indicates the value field is a subtraction | |
1947 | value, rather than an addition value | |
1948 | 2. IMAGE_REL_PPC_BRTAKEN, IMAGE_REL_PPC_BRNTAKEN - indicates that | |
1949 | the branch is expected to be taken or not. | |
1950 | 3. IMAGE_REL_PPC_TOCDEFN - toc slot definition in the file | |
1951 | For now, we just strip this stuff to find the type, and ignore it other | |
2ab1486e | 1952 | than that. */ |
252b5132 RH |
1953 | reloc_howto_type *howto; |
1954 | unsigned short r_type = EXTRACT_TYPE (internal->r_type); | |
1955 | unsigned short r_flags = EXTRACT_FLAGS(internal->r_type); | |
1956 | unsigned short junk = EXTRACT_JUNK (internal->r_type); | |
1957 | ||
2ab1486e | 1958 | /* The masking process only slices off the bottom byte for r_type. */ |
43646c9d | 1959 | if ( r_type > MAX_RELOC_INDEX ) |
c5930ee6 | 1960 | abort (); |
252b5132 | 1961 | |
2ab1486e NC |
1962 | /* Check for absolute crap. */ |
1963 | if (junk != 0) | |
c5930ee6 | 1964 | abort (); |
252b5132 | 1965 | |
43646c9d | 1966 | switch(r_type) |
252b5132 RH |
1967 | { |
1968 | case IMAGE_REL_PPC_ADDR16: | |
1969 | case IMAGE_REL_PPC_REL24: | |
1970 | case IMAGE_REL_PPC_ADDR24: | |
1971 | case IMAGE_REL_PPC_ADDR32: | |
1972 | case IMAGE_REL_PPC_IFGLUE: | |
1973 | case IMAGE_REL_PPC_ADDR32NB: | |
1974 | case IMAGE_REL_PPC_SECTION: | |
1975 | case IMAGE_REL_PPC_SECREL: | |
2ab1486e | 1976 | DUMP_RELOC2 (ppc_coff_howto_table[r_type].name, internal); |
252b5132 RH |
1977 | howto = ppc_coff_howto_table + r_type; |
1978 | break; | |
1979 | case IMAGE_REL_PPC_IMGLUE: | |
2ab1486e | 1980 | DUMP_RELOC2 (ppc_coff_howto_table[r_type].name, internal); |
252b5132 RH |
1981 | howto = ppc_coff_howto_table + r_type; |
1982 | break; | |
1983 | case IMAGE_REL_PPC_TOCREL16: | |
2ab1486e | 1984 | DUMP_RELOC2 (ppc_coff_howto_table[r_type].name, internal); |
252b5132 RH |
1985 | if (r_flags & IMAGE_REL_PPC_TOCDEFN) |
1986 | howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16_DEFN; | |
1987 | else | |
1988 | howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16; | |
1989 | break; | |
1990 | default: | |
6e301b2b | 1991 | fprintf (stderr, |
252b5132 RH |
1992 | _("Warning: Unsupported reloc %s [%d] used -- it may not work.\n"), |
1993 | ppc_coff_howto_table[r_type].name, | |
1994 | r_type); | |
43646c9d | 1995 | howto = ppc_coff_howto_table + r_type; |
252b5132 RH |
1996 | break; |
1997 | } | |
43646c9d | 1998 | |
252b5132 | 1999 | relent->howto = howto; |
252b5132 RH |
2000 | } |
2001 | ||
2002 | static reloc_howto_type * | |
2003 | coff_ppc_rtype_to_howto (abfd, sec, rel, h, sym, addendp) | |
5f771d47 | 2004 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
2005 | asection *sec; |
2006 | struct internal_reloc *rel; | |
5f771d47 ILT |
2007 | struct coff_link_hash_entry *h ATTRIBUTE_UNUSED; |
2008 | struct internal_syment *sym ATTRIBUTE_UNUSED; | |
252b5132 RH |
2009 | bfd_vma *addendp; |
2010 | { | |
2011 | reloc_howto_type *howto; | |
2012 | ||
2013 | /* We can encode one of three things in the type field, aside from the | |
2014 | type: | |
2015 | 1. IMAGE_REL_PPC_NEG - indicates the value field is a subtraction | |
2016 | value, rather than an addition value | |
2017 | 2. IMAGE_REL_PPC_BRTAKEN, IMAGE_REL_PPC_BRNTAKEN - indicates that | |
2018 | the branch is expected to be taken or not. | |
2019 | 3. IMAGE_REL_PPC_TOCDEFN - toc slot definition in the file | |
2020 | For now, we just strip this stuff to find the type, and ignore it other | |
2ab1486e | 2021 | than that. */ |
252b5132 | 2022 | |
2ab1486e NC |
2023 | unsigned short r_type = EXTRACT_TYPE (rel->r_type); |
2024 | unsigned short r_flags = EXTRACT_FLAGS (rel->r_type); | |
2025 | unsigned short junk = EXTRACT_JUNK (rel->r_type); | |
252b5132 | 2026 | |
2ab1486e NC |
2027 | /* The masking process only slices off the bottom byte for r_type. */ |
2028 | if (r_type > MAX_RELOC_INDEX) | |
c5930ee6 | 2029 | abort (); |
43646c9d | 2030 | |
2ab1486e NC |
2031 | /* Check for absolute crap. */ |
2032 | if (junk != 0) | |
c5930ee6 | 2033 | abort (); |
43646c9d KH |
2034 | |
2035 | switch(r_type) | |
252b5132 RH |
2036 | { |
2037 | case IMAGE_REL_PPC_ADDR32NB: | |
2038 | DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel); | |
2039 | *addendp -= pe_data(sec->output_section->owner)->pe_opthdr.ImageBase; | |
2040 | howto = ppc_coff_howto_table + r_type; | |
2041 | break; | |
2042 | case IMAGE_REL_PPC_TOCREL16: | |
2043 | DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel); | |
2044 | if (r_flags & IMAGE_REL_PPC_TOCDEFN) | |
2045 | howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16_DEFN; | |
2046 | else | |
2047 | howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16; | |
2048 | break; | |
2049 | case IMAGE_REL_PPC_ADDR16: | |
2050 | case IMAGE_REL_PPC_REL24: | |
2051 | case IMAGE_REL_PPC_ADDR24: | |
2052 | case IMAGE_REL_PPC_ADDR32: | |
2053 | case IMAGE_REL_PPC_IFGLUE: | |
2054 | case IMAGE_REL_PPC_SECTION: | |
2055 | case IMAGE_REL_PPC_SECREL: | |
2056 | DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel); | |
2057 | howto = ppc_coff_howto_table + r_type; | |
2058 | break; | |
2059 | case IMAGE_REL_PPC_IMGLUE: | |
2060 | DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel); | |
2061 | howto = ppc_coff_howto_table + r_type; | |
2062 | break; | |
2063 | default: | |
6e301b2b | 2064 | fprintf (stderr, |
252b5132 RH |
2065 | _("Warning: Unsupported reloc %s [%d] used -- it may not work.\n"), |
2066 | ppc_coff_howto_table[r_type].name, | |
2067 | r_type); | |
2068 | howto = ppc_coff_howto_table + r_type; | |
2069 | break; | |
2070 | } | |
43646c9d | 2071 | |
252b5132 RH |
2072 | return howto; |
2073 | } | |
2074 | ||
2ab1486e | 2075 | /* A cheesy little macro to make the code a little more readable. */ |
252b5132 RH |
2076 | #define HOW2MAP(bfd_rtype,ppc_rtype) \ |
2077 | case bfd_rtype: return &ppc_coff_howto_table[ppc_rtype] | |
2078 | ||
2079 | static reloc_howto_type *ppc_coff_reloc_type_lookup | |
2080 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
2081 | ||
2082 | static reloc_howto_type * | |
2083 | ppc_coff_reloc_type_lookup (abfd, code) | |
5f771d47 | 2084 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
2085 | bfd_reloc_code_real_type code; |
2086 | { | |
2087 | switch (code) | |
2088 | { | |
2089 | HOW2MAP(BFD_RELOC_32_GOTOFF, IMAGE_REL_PPC_IMGLUE); | |
2090 | HOW2MAP(BFD_RELOC_16_GOT_PCREL, IMAGE_REL_PPC_IFGLUE); | |
2091 | HOW2MAP(BFD_RELOC_16, IMAGE_REL_PPC_ADDR16); | |
2092 | HOW2MAP(BFD_RELOC_PPC_B26, IMAGE_REL_PPC_REL24); | |
2093 | HOW2MAP(BFD_RELOC_PPC_BA26, IMAGE_REL_PPC_ADDR24); | |
2094 | HOW2MAP(BFD_RELOC_PPC_TOC16, IMAGE_REL_PPC_TOCREL16); | |
2095 | HOW2MAP(BFD_RELOC_16_GOTOFF, IMAGE_REL_PPC_TOCREL16_DEFN); | |
2096 | HOW2MAP(BFD_RELOC_32, IMAGE_REL_PPC_ADDR32); | |
2097 | HOW2MAP(BFD_RELOC_RVA, IMAGE_REL_PPC_ADDR32NB); | |
43646c9d | 2098 | default: |
252b5132 RH |
2099 | return NULL; |
2100 | } | |
252b5132 RH |
2101 | } |
2102 | ||
2103 | #undef HOW2MAP | |
252b5132 | 2104 | \f |
43646c9d | 2105 | /* Tailor coffcode.h -- macro heaven. */ |
252b5132 RH |
2106 | |
2107 | #define RTYPE2HOWTO(cache_ptr, dst) ppc_coff_rtype2howto (cache_ptr, dst) | |
2108 | ||
252b5132 RH |
2109 | /* We use the special COFF backend linker, with our own special touch. */ |
2110 | ||
2111 | #define coff_bfd_reloc_type_lookup ppc_coff_reloc_type_lookup | |
2112 | #define coff_rtype_to_howto coff_ppc_rtype_to_howto | |
2113 | #define coff_relocate_section coff_ppc_relocate_section | |
43646c9d | 2114 | #define coff_bfd_final_link ppc_bfd_coff_final_link |
252b5132 RH |
2115 | |
2116 | #ifndef COFF_IMAGE_WITH_PE | |
650f5dd8 | 2117 | /* FIXME: This no longer works. */ |
1e738b87 | 2118 | #if 0 |
252b5132 RH |
2119 | #define coff_swap_sym_in_hook ppc_coff_swap_sym_in_hook |
2120 | #endif | |
1e738b87 | 2121 | #endif |
252b5132 RH |
2122 | |
2123 | #define SELECT_RELOC(internal, howto) {internal.r_type=howto->type;} | |
2124 | ||
2125 | #define COFF_PAGE_SIZE 0x1000 | |
2126 | ||
650f5dd8 ILT |
2127 | /* FIXME: This controls some code that used to be in peicode.h and is |
2128 | now in peigen.c. It will not control the code in peigen.c. If | |
2129 | anybody wants to get this working, you will need to fix that. */ | |
252b5132 RH |
2130 | #define POWERPC_LE_PE |
2131 | ||
a50f8417 ILT |
2132 | #define COFF_SECTION_ALIGNMENT_ENTRIES \ |
2133 | { COFF_SECTION_NAME_EXACT_MATCH (".idata$2"), \ | |
2134 | COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \ | |
2135 | { COFF_SECTION_NAME_EXACT_MATCH (".idata$3"), \ | |
2136 | COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \ | |
2137 | { COFF_SECTION_NAME_EXACT_MATCH (".idata$4"), \ | |
2138 | COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \ | |
2139 | { COFF_SECTION_NAME_EXACT_MATCH (".idata$5"), \ | |
2140 | COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \ | |
2141 | { COFF_SECTION_NAME_EXACT_MATCH (".idata$6"), \ | |
2142 | COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 1 }, \ | |
2143 | { COFF_SECTION_NAME_EXACT_MATCH (".reloc"), \ | |
2144 | COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 1 } | |
2145 | ||
252b5132 | 2146 | #include "coffcode.h" |
252b5132 | 2147 | \f |
252b5132 | 2148 | #ifndef COFF_IMAGE_WITH_PE |
1e738b87 NC |
2149 | /* FIXME: This no longer works. */ |
2150 | #if 0 | |
252b5132 | 2151 | /* FIXME: |
43646c9d | 2152 | What we're trying to do here is allocate a toc section (early), and attach |
252b5132 RH |
2153 | it to the last bfd to be processed. This avoids the problem of having a toc |
2154 | written out before all files have been processed. This code allocates | |
2155 | a toc section for every file, and records the last one seen. There are | |
2156 | at least two problems with this approach: | |
2157 | 1. We allocate whole bunches of toc sections that are ignored, but at | |
2158 | at least we will not allocate a toc if no .toc is present. | |
2159 | 2. It's not clear to me that being the last bfd read necessarily means | |
2160 | that you are the last bfd closed. | |
2161 | 3. Doing it on a "swap in" hook depends on when the "swap in" is called, | |
2ab1486e | 2162 | and how often, etc. It's not clear to me that there isn't a hole here. */ |
1e738b87 | 2163 | static void ppc_coff_swap_sym_in_hook PARAMS ((bfd *, PTR, PTR)); |
252b5132 RH |
2164 | |
2165 | static void | |
2166 | ppc_coff_swap_sym_in_hook (abfd, ext1, in1) | |
2167 | bfd *abfd; | |
5f771d47 | 2168 | PTR ext1 ATTRIBUTE_UNUSED; |
252b5132 RH |
2169 | PTR in1; |
2170 | { | |
2ab1486e | 2171 | struct internal_syment * in = (struct internal_syment *)in1; |
252b5132 | 2172 | |
2ab1486e | 2173 | if (bfd_of_toc_owner != 0) /* We already have a toc, so go home. */ |
252b5132 RH |
2174 | return; |
2175 | ||
2ab1486e | 2176 | if (strcmp (in->_n._n_name, ".toc") == 0) |
252b5132 RH |
2177 | { |
2178 | flagword flags; | |
2179 | register asection *s; | |
2180 | ||
2ab1486e | 2181 | s = bfd_get_section_by_name (abfd, TOC_SECTION_NAME); |
43646c9d | 2182 | if (s != NULL) |
2ab1486e | 2183 | return; |
252b5132 RH |
2184 | |
2185 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY ; | |
2186 | ||
2187 | s = bfd_make_section (abfd, TOC_SECTION_NAME); | |
2188 | ||
2189 | if (s == NULL | |
2190 | || !bfd_set_section_flags (abfd, s, flags) | |
2191 | || !bfd_set_section_alignment (abfd, s, 2)) | |
2ab1486e NC |
2192 | /* FIXME: set appropriate bfd error. */ |
2193 | abort (); | |
252b5132 | 2194 | |
2ab1486e | 2195 | /* Save the bfd for later allocation. */ |
252b5132 RH |
2196 | bfd_of_toc_owner = abfd; |
2197 | } | |
2198 | ||
2199 | return; | |
2200 | } | |
2201 | #endif | |
1e738b87 | 2202 | #endif |
252b5132 RH |
2203 | |
2204 | #ifndef COFF_IMAGE_WITH_PE | |
2205 | ||
b34976b6 | 2206 | static bfd_boolean ppc_do_last PARAMS ((bfd *)); |
252b5132 RH |
2207 | static bfd *ppc_get_last PARAMS ((void)); |
2208 | ||
b34976b6 | 2209 | static bfd_boolean |
252b5132 RH |
2210 | ppc_do_last (abfd) |
2211 | bfd *abfd; | |
2212 | { | |
2213 | if (abfd == bfd_of_toc_owner) | |
b34976b6 | 2214 | return TRUE; |
252b5132 | 2215 | else |
b34976b6 | 2216 | return FALSE; |
252b5132 RH |
2217 | } |
2218 | ||
2219 | static bfd * | |
2220 | ppc_get_last() | |
2221 | { | |
2222 | return bfd_of_toc_owner; | |
2223 | } | |
2224 | ||
2ab1486e | 2225 | /* This piece of machinery exists only to guarantee that the bfd that holds |
43646c9d | 2226 | the toc section is written last. |
252b5132 RH |
2227 | |
2228 | This does depend on bfd_make_section attaching a new section to the | |
43646c9d | 2229 | end of the section list for the bfd. |
252b5132 | 2230 | |
43646c9d KH |
2231 | This is otherwise intended to be functionally the same as |
2232 | cofflink.c:_bfd_coff_final_link(). It is specifically different only | |
2233 | where the POWERPC_LE_PE macro modifies the code. It is left in as a | |
2ab1486e | 2234 | precise form of comment. krk@cygnus.com */ |
252b5132 | 2235 | |
252b5132 RH |
2236 | /* Do the final link step. */ |
2237 | ||
b34976b6 | 2238 | bfd_boolean |
252b5132 RH |
2239 | ppc_bfd_coff_final_link (abfd, info) |
2240 | bfd *abfd; | |
2241 | struct bfd_link_info *info; | |
2242 | { | |
2243 | bfd_size_type symesz; | |
2244 | struct coff_final_link_info finfo; | |
b34976b6 | 2245 | bfd_boolean debug_merge_allocated; |
252b5132 RH |
2246 | asection *o; |
2247 | struct bfd_link_order *p; | |
dc810e39 AM |
2248 | bfd_size_type max_sym_count; |
2249 | bfd_size_type max_lineno_count; | |
2250 | bfd_size_type max_reloc_count; | |
2251 | bfd_size_type max_output_reloc_count; | |
2252 | bfd_size_type max_contents_size; | |
252b5132 RH |
2253 | file_ptr rel_filepos; |
2254 | unsigned int relsz; | |
2255 | file_ptr line_filepos; | |
2256 | unsigned int linesz; | |
2257 | bfd *sub; | |
2258 | bfd_byte *external_relocs = NULL; | |
2259 | char strbuf[STRING_SIZE_SIZE]; | |
dc810e39 | 2260 | bfd_size_type amt; |
252b5132 RH |
2261 | |
2262 | symesz = bfd_coff_symesz (abfd); | |
2263 | ||
2264 | finfo.info = info; | |
2265 | finfo.output_bfd = abfd; | |
2266 | finfo.strtab = NULL; | |
2267 | finfo.section_info = NULL; | |
2268 | finfo.last_file_index = -1; | |
2269 | finfo.last_bf_index = -1; | |
2270 | finfo.internal_syms = NULL; | |
2271 | finfo.sec_ptrs = NULL; | |
2272 | finfo.sym_indices = NULL; | |
2273 | finfo.outsyms = NULL; | |
2274 | finfo.linenos = NULL; | |
2275 | finfo.contents = NULL; | |
2276 | finfo.external_relocs = NULL; | |
2277 | finfo.internal_relocs = NULL; | |
b34976b6 | 2278 | debug_merge_allocated = FALSE; |
252b5132 RH |
2279 | |
2280 | coff_data (abfd)->link_info = info; | |
2281 | ||
2282 | finfo.strtab = _bfd_stringtab_init (); | |
2283 | if (finfo.strtab == NULL) | |
2284 | goto error_return; | |
2285 | ||
2286 | if (! coff_debug_merge_hash_table_init (&finfo.debug_merge)) | |
2287 | goto error_return; | |
b34976b6 | 2288 | debug_merge_allocated = TRUE; |
252b5132 RH |
2289 | |
2290 | /* Compute the file positions for all the sections. */ | |
2291 | if (! abfd->output_has_begun) | |
2292 | { | |
2293 | if (! bfd_coff_compute_section_file_positions (abfd)) | |
b34976b6 | 2294 | return FALSE; |
252b5132 RH |
2295 | } |
2296 | ||
2297 | /* Count the line numbers and relocation entries required for the | |
2298 | output file. Set the file positions for the relocs. */ | |
2299 | rel_filepos = obj_relocbase (abfd); | |
2300 | relsz = bfd_coff_relsz (abfd); | |
2301 | max_contents_size = 0; | |
2302 | max_lineno_count = 0; | |
2303 | max_reloc_count = 0; | |
2304 | ||
2305 | for (o = abfd->sections; o != NULL; o = o->next) | |
2306 | { | |
2307 | o->reloc_count = 0; | |
2308 | o->lineno_count = 0; | |
2ab1486e | 2309 | |
252b5132 RH |
2310 | for (p = o->link_order_head; p != NULL; p = p->next) |
2311 | { | |
252b5132 RH |
2312 | if (p->type == bfd_indirect_link_order) |
2313 | { | |
2314 | asection *sec; | |
2315 | ||
2316 | sec = p->u.indirect.section; | |
2317 | ||
2318 | /* Mark all sections which are to be included in the | |
2319 | link. This will normally be every section. We need | |
2320 | to do this so that we can identify any sections which | |
2321 | the linker has decided to not include. */ | |
b34976b6 | 2322 | sec->linker_mark = TRUE; |
252b5132 RH |
2323 | |
2324 | if (info->strip == strip_none | |
2325 | || info->strip == strip_some) | |
2326 | o->lineno_count += sec->lineno_count; | |
2327 | ||
1049f94e | 2328 | if (info->relocatable) |
252b5132 RH |
2329 | o->reloc_count += sec->reloc_count; |
2330 | ||
2331 | if (sec->_raw_size > max_contents_size) | |
2332 | max_contents_size = sec->_raw_size; | |
2333 | if (sec->lineno_count > max_lineno_count) | |
2334 | max_lineno_count = sec->lineno_count; | |
2335 | if (sec->reloc_count > max_reloc_count) | |
2336 | max_reloc_count = sec->reloc_count; | |
2337 | } | |
1049f94e | 2338 | else if (info->relocatable |
252b5132 RH |
2339 | && (p->type == bfd_section_reloc_link_order |
2340 | || p->type == bfd_symbol_reloc_link_order)) | |
2341 | ++o->reloc_count; | |
2342 | } | |
2343 | if (o->reloc_count == 0) | |
2344 | o->rel_filepos = 0; | |
2345 | else | |
2346 | { | |
2347 | o->flags |= SEC_RELOC; | |
2348 | o->rel_filepos = rel_filepos; | |
2349 | rel_filepos += o->reloc_count * relsz; | |
2350 | } | |
2351 | } | |
2352 | ||
1049f94e | 2353 | /* If doing a relocatable link, allocate space for the pointers we |
252b5132 | 2354 | need to keep. */ |
1049f94e | 2355 | if (info->relocatable) |
252b5132 RH |
2356 | { |
2357 | unsigned int i; | |
2358 | ||
2359 | /* We use section_count + 1, rather than section_count, because | |
2360 | the target_index fields are 1 based. */ | |
dc810e39 AM |
2361 | amt = abfd->section_count + 1; |
2362 | amt *= sizeof (struct coff_link_section_info); | |
2363 | finfo.section_info = (struct coff_link_section_info *) bfd_malloc (amt); | |
2ab1486e | 2364 | |
252b5132 RH |
2365 | if (finfo.section_info == NULL) |
2366 | goto error_return; | |
2ab1486e | 2367 | |
252b5132 RH |
2368 | for (i = 0; i <= abfd->section_count; i++) |
2369 | { | |
2370 | finfo.section_info[i].relocs = NULL; | |
2371 | finfo.section_info[i].rel_hashes = NULL; | |
2372 | } | |
2373 | } | |
2374 | ||
2375 | /* We now know the size of the relocs, so we can determine the file | |
2376 | positions of the line numbers. */ | |
2377 | line_filepos = rel_filepos; | |
2378 | linesz = bfd_coff_linesz (abfd); | |
2379 | max_output_reloc_count = 0; | |
2ab1486e | 2380 | |
252b5132 RH |
2381 | for (o = abfd->sections; o != NULL; o = o->next) |
2382 | { | |
2383 | if (o->lineno_count == 0) | |
2384 | o->line_filepos = 0; | |
2385 | else | |
2386 | { | |
2387 | o->line_filepos = line_filepos; | |
2388 | line_filepos += o->lineno_count * linesz; | |
2389 | } | |
2390 | ||
2391 | if (o->reloc_count != 0) | |
2392 | { | |
2393 | /* We don't know the indices of global symbols until we have | |
2394 | written out all the local symbols. For each section in | |
2395 | the output file, we keep an array of pointers to hash | |
2396 | table entries. Each entry in the array corresponds to a | |
2397 | reloc. When we find a reloc against a global symbol, we | |
2398 | set the corresponding entry in this array so that we can | |
2399 | fix up the symbol index after we have written out all the | |
2400 | local symbols. | |
2401 | ||
2402 | Because of this problem, we also keep the relocs in | |
2403 | memory until the end of the link. This wastes memory, | |
1049f94e | 2404 | but only when doing a relocatable link, which is not the |
252b5132 | 2405 | common case. */ |
1049f94e | 2406 | BFD_ASSERT (info->relocatable); |
dc810e39 AM |
2407 | amt = o->reloc_count; |
2408 | amt *= sizeof (struct internal_reloc); | |
252b5132 | 2409 | finfo.section_info[o->target_index].relocs = |
dc810e39 AM |
2410 | (struct internal_reloc *) bfd_malloc (amt); |
2411 | amt = o->reloc_count; | |
2412 | amt *= sizeof (struct coff_link_hash_entry *); | |
252b5132 | 2413 | finfo.section_info[o->target_index].rel_hashes = |
dc810e39 | 2414 | (struct coff_link_hash_entry **) bfd_malloc (amt); |
252b5132 RH |
2415 | if (finfo.section_info[o->target_index].relocs == NULL |
2416 | || finfo.section_info[o->target_index].rel_hashes == NULL) | |
2417 | goto error_return; | |
2418 | ||
2419 | if (o->reloc_count > max_output_reloc_count) | |
2420 | max_output_reloc_count = o->reloc_count; | |
2421 | } | |
2422 | ||
2423 | /* Reset the reloc and lineno counts, so that we can use them to | |
2424 | count the number of entries we have output so far. */ | |
2425 | o->reloc_count = 0; | |
2426 | o->lineno_count = 0; | |
2427 | } | |
2428 | ||
2429 | obj_sym_filepos (abfd) = line_filepos; | |
2430 | ||
2431 | /* Figure out the largest number of symbols in an input BFD. Take | |
2432 | the opportunity to clear the output_has_begun fields of all the | |
2433 | input BFD's. */ | |
2434 | max_sym_count = 0; | |
2435 | for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) | |
2436 | { | |
dc810e39 | 2437 | bfd_size_type sz; |
252b5132 | 2438 | |
b34976b6 | 2439 | sub->output_has_begun = FALSE; |
252b5132 RH |
2440 | sz = obj_raw_syment_count (sub); |
2441 | if (sz > max_sym_count) | |
2442 | max_sym_count = sz; | |
2443 | } | |
2444 | ||
2445 | /* Allocate some buffers used while linking. */ | |
dc810e39 AM |
2446 | amt = max_sym_count * sizeof (struct internal_syment); |
2447 | finfo.internal_syms = (struct internal_syment *) bfd_malloc (amt); | |
2448 | amt = max_sym_count * sizeof (asection *); | |
2449 | finfo.sec_ptrs = (asection **) bfd_malloc (amt); | |
2450 | amt = max_sym_count * sizeof (long); | |
2451 | finfo.sym_indices = (long *) bfd_malloc (amt); | |
2452 | amt = (max_sym_count + 1) * symesz; | |
2453 | finfo.outsyms = (bfd_byte *) bfd_malloc (amt); | |
2454 | amt = max_lineno_count * bfd_coff_linesz (abfd); | |
2455 | finfo.linenos = (bfd_byte *) bfd_malloc (amt); | |
252b5132 RH |
2456 | finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size); |
2457 | finfo.external_relocs = (bfd_byte *) bfd_malloc (max_reloc_count * relsz); | |
1049f94e | 2458 | if (! info->relocatable) |
dc810e39 AM |
2459 | { |
2460 | amt = max_reloc_count * sizeof (struct internal_reloc); | |
2461 | finfo.internal_relocs = (struct internal_reloc *) bfd_malloc (amt); | |
2462 | } | |
252b5132 RH |
2463 | if ((finfo.internal_syms == NULL && max_sym_count > 0) |
2464 | || (finfo.sec_ptrs == NULL && max_sym_count > 0) | |
2465 | || (finfo.sym_indices == NULL && max_sym_count > 0) | |
2466 | || finfo.outsyms == NULL | |
2467 | || (finfo.linenos == NULL && max_lineno_count > 0) | |
2468 | || (finfo.contents == NULL && max_contents_size > 0) | |
2469 | || (finfo.external_relocs == NULL && max_reloc_count > 0) | |
1049f94e | 2470 | || (! info->relocatable |
252b5132 RH |
2471 | && finfo.internal_relocs == NULL |
2472 | && max_reloc_count > 0)) | |
2473 | goto error_return; | |
2474 | ||
2475 | /* We now know the position of everything in the file, except that | |
2476 | we don't know the size of the symbol table and therefore we don't | |
2477 | know where the string table starts. We just build the string | |
2478 | table in memory as we go along. We process all the relocations | |
2479 | for a single input file at once. */ | |
2480 | obj_raw_syment_count (abfd) = 0; | |
2481 | ||
2482 | if (coff_backend_info (abfd)->_bfd_coff_start_final_link) | |
2483 | { | |
2484 | if (! bfd_coff_start_final_link (abfd, info)) | |
2485 | goto error_return; | |
2486 | } | |
2487 | ||
2488 | for (o = abfd->sections; o != NULL; o = o->next) | |
2489 | { | |
2490 | for (p = o->link_order_head; p != NULL; p = p->next) | |
2491 | { | |
2492 | if (p->type == bfd_indirect_link_order | |
2493 | && (bfd_get_flavour (p->u.indirect.section->owner) | |
2494 | == bfd_target_coff_flavour)) | |
2495 | { | |
2496 | sub = p->u.indirect.section->owner; | |
2497 | #ifdef POWERPC_LE_PE | |
2498 | if (! sub->output_has_begun && !ppc_do_last(sub)) | |
2499 | #else | |
2500 | if (! sub->output_has_begun) | |
2501 | #endif | |
2502 | { | |
2503 | if (! _bfd_coff_link_input_bfd (&finfo, sub)) | |
2504 | goto error_return; | |
b34976b6 | 2505 | sub->output_has_begun = TRUE; |
252b5132 RH |
2506 | } |
2507 | } | |
2508 | else if (p->type == bfd_section_reloc_link_order | |
2509 | || p->type == bfd_symbol_reloc_link_order) | |
2510 | { | |
2511 | if (! _bfd_coff_reloc_link_order (abfd, &finfo, o, p)) | |
2512 | goto error_return; | |
2513 | } | |
2514 | else | |
2515 | { | |
2516 | if (! _bfd_default_link_order (abfd, info, o, p)) | |
2517 | goto error_return; | |
2518 | } | |
2519 | } | |
2520 | } | |
2521 | ||
2522 | #ifdef POWERPC_LE_PE | |
2523 | { | |
2524 | bfd* last_one = ppc_get_last(); | |
2525 | if (last_one) | |
2526 | { | |
2527 | if (! _bfd_coff_link_input_bfd (&finfo, last_one)) | |
2528 | goto error_return; | |
2529 | } | |
b34976b6 | 2530 | last_one->output_has_begun = TRUE; |
252b5132 RH |
2531 | } |
2532 | #endif | |
2533 | ||
2534 | /* Free up the buffers used by _bfd_coff_link_input_bfd. */ | |
252b5132 | 2535 | coff_debug_merge_hash_table_free (&finfo.debug_merge); |
b34976b6 | 2536 | debug_merge_allocated = FALSE; |
252b5132 RH |
2537 | |
2538 | if (finfo.internal_syms != NULL) | |
2539 | { | |
2540 | free (finfo.internal_syms); | |
2541 | finfo.internal_syms = NULL; | |
2542 | } | |
2543 | if (finfo.sec_ptrs != NULL) | |
2544 | { | |
2545 | free (finfo.sec_ptrs); | |
2546 | finfo.sec_ptrs = NULL; | |
2547 | } | |
2548 | if (finfo.sym_indices != NULL) | |
2549 | { | |
2550 | free (finfo.sym_indices); | |
2551 | finfo.sym_indices = NULL; | |
2552 | } | |
2553 | if (finfo.linenos != NULL) | |
2554 | { | |
2555 | free (finfo.linenos); | |
2556 | finfo.linenos = NULL; | |
2557 | } | |
2558 | if (finfo.contents != NULL) | |
2559 | { | |
2560 | free (finfo.contents); | |
2561 | finfo.contents = NULL; | |
2562 | } | |
2563 | if (finfo.external_relocs != NULL) | |
2564 | { | |
2565 | free (finfo.external_relocs); | |
2566 | finfo.external_relocs = NULL; | |
2567 | } | |
2568 | if (finfo.internal_relocs != NULL) | |
2569 | { | |
2570 | free (finfo.internal_relocs); | |
2571 | finfo.internal_relocs = NULL; | |
2572 | } | |
2573 | ||
2574 | /* The value of the last C_FILE symbol is supposed to be the symbol | |
2575 | index of the first external symbol. Write it out again if | |
2576 | necessary. */ | |
2577 | if (finfo.last_file_index != -1 | |
2578 | && (unsigned int) finfo.last_file.n_value != obj_raw_syment_count (abfd)) | |
2579 | { | |
dc810e39 AM |
2580 | file_ptr pos; |
2581 | ||
252b5132 RH |
2582 | finfo.last_file.n_value = obj_raw_syment_count (abfd); |
2583 | bfd_coff_swap_sym_out (abfd, (PTR) &finfo.last_file, | |
2584 | (PTR) finfo.outsyms); | |
dc810e39 AM |
2585 | pos = obj_sym_filepos (abfd) + finfo.last_file_index * symesz; |
2586 | if (bfd_seek (abfd, pos, SEEK_SET) != 0 | |
2587 | || bfd_bwrite (finfo.outsyms, symesz, abfd) != symesz) | |
b34976b6 | 2588 | return FALSE; |
252b5132 RH |
2589 | } |
2590 | ||
2591 | /* Write out the global symbols. */ | |
b34976b6 | 2592 | finfo.failed = FALSE; |
252b5132 RH |
2593 | coff_link_hash_traverse (coff_hash_table (info), _bfd_coff_write_global_sym, |
2594 | (PTR) &finfo); | |
2595 | if (finfo.failed) | |
2596 | goto error_return; | |
2597 | ||
2598 | /* The outsyms buffer is used by _bfd_coff_write_global_sym. */ | |
2599 | if (finfo.outsyms != NULL) | |
2600 | { | |
2601 | free (finfo.outsyms); | |
2602 | finfo.outsyms = NULL; | |
2603 | } | |
2604 | ||
1049f94e | 2605 | if (info->relocatable) |
252b5132 RH |
2606 | { |
2607 | /* Now that we have written out all the global symbols, we know | |
2608 | the symbol indices to use for relocs against them, and we can | |
2609 | finally write out the relocs. */ | |
dc810e39 AM |
2610 | amt = max_output_reloc_count * relsz; |
2611 | external_relocs = (bfd_byte *) bfd_malloc (amt); | |
252b5132 RH |
2612 | if (external_relocs == NULL) |
2613 | goto error_return; | |
2614 | ||
2615 | for (o = abfd->sections; o != NULL; o = o->next) | |
2616 | { | |
2617 | struct internal_reloc *irel; | |
2618 | struct internal_reloc *irelend; | |
2619 | struct coff_link_hash_entry **rel_hash; | |
2620 | bfd_byte *erel; | |
2621 | ||
2622 | if (o->reloc_count == 0) | |
2623 | continue; | |
2624 | ||
2625 | irel = finfo.section_info[o->target_index].relocs; | |
2626 | irelend = irel + o->reloc_count; | |
2627 | rel_hash = finfo.section_info[o->target_index].rel_hashes; | |
2628 | erel = external_relocs; | |
2629 | for (; irel < irelend; irel++, rel_hash++, erel += relsz) | |
2630 | { | |
2631 | if (*rel_hash != NULL) | |
2632 | { | |
2633 | BFD_ASSERT ((*rel_hash)->indx >= 0); | |
2634 | irel->r_symndx = (*rel_hash)->indx; | |
2635 | } | |
2636 | bfd_coff_swap_reloc_out (abfd, (PTR) irel, (PTR) erel); | |
2637 | } | |
2638 | ||
dc810e39 | 2639 | amt = relsz * o->reloc_count; |
252b5132 | 2640 | if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0 |
dc810e39 | 2641 | || bfd_bwrite ((PTR) external_relocs, amt, abfd) != amt) |
252b5132 RH |
2642 | goto error_return; |
2643 | } | |
2644 | ||
2645 | free (external_relocs); | |
2646 | external_relocs = NULL; | |
2647 | } | |
2648 | ||
2649 | /* Free up the section information. */ | |
2650 | if (finfo.section_info != NULL) | |
2651 | { | |
2652 | unsigned int i; | |
2653 | ||
2654 | for (i = 0; i < abfd->section_count; i++) | |
2655 | { | |
2656 | if (finfo.section_info[i].relocs != NULL) | |
2657 | free (finfo.section_info[i].relocs); | |
2658 | if (finfo.section_info[i].rel_hashes != NULL) | |
2659 | free (finfo.section_info[i].rel_hashes); | |
2660 | } | |
2661 | free (finfo.section_info); | |
2662 | finfo.section_info = NULL; | |
2663 | } | |
2664 | ||
2665 | /* If we have optimized stabs strings, output them. */ | |
2666 | if (coff_hash_table (info)->stab_info != NULL) | |
2667 | { | |
2668 | if (! _bfd_write_stab_strings (abfd, &coff_hash_table (info)->stab_info)) | |
b34976b6 | 2669 | return FALSE; |
252b5132 RH |
2670 | } |
2671 | ||
2672 | /* Write out the string table. */ | |
2673 | if (obj_raw_syment_count (abfd) != 0) | |
2674 | { | |
dc810e39 AM |
2675 | file_ptr pos; |
2676 | ||
2677 | pos = obj_sym_filepos (abfd) + obj_raw_syment_count (abfd) * symesz; | |
2678 | if (bfd_seek (abfd, pos, SEEK_SET) != 0) | |
b34976b6 | 2679 | return FALSE; |
252b5132 RH |
2680 | |
2681 | #if STRING_SIZE_SIZE == 4 | |
dc810e39 AM |
2682 | H_PUT_32 (abfd, |
2683 | _bfd_stringtab_size (finfo.strtab) + STRING_SIZE_SIZE, | |
2684 | strbuf); | |
252b5132 | 2685 | #else |
dc810e39 | 2686 | #error Change H_PUT_32 above |
252b5132 RH |
2687 | #endif |
2688 | ||
dc810e39 AM |
2689 | if (bfd_bwrite (strbuf, (bfd_size_type) STRING_SIZE_SIZE, abfd) |
2690 | != STRING_SIZE_SIZE) | |
b34976b6 | 2691 | return FALSE; |
252b5132 RH |
2692 | |
2693 | if (! _bfd_stringtab_emit (abfd, finfo.strtab)) | |
b34976b6 | 2694 | return FALSE; |
252b5132 RH |
2695 | } |
2696 | ||
2697 | _bfd_stringtab_free (finfo.strtab); | |
2698 | ||
2699 | /* Setting bfd_get_symcount to 0 will cause write_object_contents to | |
2700 | not try to write out the symbols. */ | |
2701 | bfd_get_symcount (abfd) = 0; | |
2702 | ||
b34976b6 | 2703 | return TRUE; |
252b5132 RH |
2704 | |
2705 | error_return: | |
2706 | if (debug_merge_allocated) | |
2707 | coff_debug_merge_hash_table_free (&finfo.debug_merge); | |
2708 | if (finfo.strtab != NULL) | |
2709 | _bfd_stringtab_free (finfo.strtab); | |
2710 | if (finfo.section_info != NULL) | |
2711 | { | |
2712 | unsigned int i; | |
2713 | ||
2714 | for (i = 0; i < abfd->section_count; i++) | |
2715 | { | |
2716 | if (finfo.section_info[i].relocs != NULL) | |
2717 | free (finfo.section_info[i].relocs); | |
2718 | if (finfo.section_info[i].rel_hashes != NULL) | |
2719 | free (finfo.section_info[i].rel_hashes); | |
2720 | } | |
2721 | free (finfo.section_info); | |
2722 | } | |
2723 | if (finfo.internal_syms != NULL) | |
2724 | free (finfo.internal_syms); | |
2725 | if (finfo.sec_ptrs != NULL) | |
2726 | free (finfo.sec_ptrs); | |
2727 | if (finfo.sym_indices != NULL) | |
2728 | free (finfo.sym_indices); | |
2729 | if (finfo.outsyms != NULL) | |
2730 | free (finfo.outsyms); | |
2731 | if (finfo.linenos != NULL) | |
2732 | free (finfo.linenos); | |
2733 | if (finfo.contents != NULL) | |
2734 | free (finfo.contents); | |
2735 | if (finfo.external_relocs != NULL) | |
2736 | free (finfo.external_relocs); | |
2737 | if (finfo.internal_relocs != NULL) | |
2738 | free (finfo.internal_relocs); | |
2739 | if (external_relocs != NULL) | |
2740 | free (external_relocs); | |
b34976b6 | 2741 | return FALSE; |
252b5132 RH |
2742 | } |
2743 | #endif | |
2744 | \f | |
c3c89269 NC |
2745 | /* Forward declaration for use by alternative_target field. */ |
2746 | #ifdef TARGET_BIG_SYM | |
2747 | extern const bfd_target TARGET_BIG_SYM; | |
2748 | #endif | |
2749 | ||
43646c9d | 2750 | /* The transfer vectors that lead the outside world to all of the above. */ |
252b5132 RH |
2751 | |
2752 | #ifdef TARGET_LITTLE_SYM | |
c3c89269 | 2753 | const bfd_target TARGET_LITTLE_SYM = |
252b5132 RH |
2754 | { |
2755 | TARGET_LITTLE_NAME, /* name or coff-arm-little */ | |
2756 | bfd_target_coff_flavour, | |
2757 | BFD_ENDIAN_LITTLE, /* data byte order is little */ | |
2758 | BFD_ENDIAN_LITTLE, /* header byte order is little */ | |
2759 | ||
2760 | (HAS_RELOC | EXEC_P | /* FIXME: object flags */ | |
2761 | HAS_LINENO | HAS_DEBUG | | |
2762 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
43646c9d | 2763 | |
252b5132 RH |
2764 | #ifndef COFF_WITH_PE |
2765 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
2766 | #else | |
2767 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */ | |
2768 | | SEC_LINK_ONCE | SEC_LINK_DUPLICATES), | |
2769 | #endif | |
2770 | ||
2771 | 0, /* leading char */ | |
2772 | '/', /* ar_pad_char */ | |
2773 | 15, /* ar_max_namelen??? FIXMEmgo */ | |
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, /* data */ | |
2778 | ||
2779 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
2780 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
2781 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ | |
43646c9d | 2782 | |
252b5132 RH |
2783 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ |
2784 | bfd_generic_archive_p, /* _bfd_dummy_target */ coff_object_p }, | |
2785 | {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ | |
2786 | bfd_false}, | |
2787 | {bfd_false, coff_write_object_contents, /* bfd_write_contents */ | |
2788 | _bfd_write_archive_contents, bfd_false}, | |
43646c9d | 2789 | |
252b5132 RH |
2790 | BFD_JUMP_TABLE_GENERIC (coff), |
2791 | BFD_JUMP_TABLE_COPY (coff), | |
2792 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
2793 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
2794 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
2795 | BFD_JUMP_TABLE_RELOCS (coff), | |
2796 | BFD_JUMP_TABLE_WRITE (coff), | |
2797 | BFD_JUMP_TABLE_LINK (coff), | |
2798 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
c3c89269 NC |
2799 | |
2800 | /* Alternative_target. */ | |
2801 | #ifdef TARGET_BIG_SYM | |
2802 | & TARGET_BIG_SYM, | |
2803 | #else | |
2804 | NULL, | |
2805 | #endif | |
43646c9d | 2806 | |
c3c89269 | 2807 | COFF_SWAP_TABLE |
252b5132 RH |
2808 | }; |
2809 | #endif | |
2810 | ||
2811 | #ifdef TARGET_BIG_SYM | |
c3c89269 | 2812 | const bfd_target TARGET_BIG_SYM = |
252b5132 RH |
2813 | { |
2814 | TARGET_BIG_NAME, | |
43646c9d | 2815 | bfd_target_coff_flavour, |
252b5132 RH |
2816 | BFD_ENDIAN_BIG, /* data byte order is big */ |
2817 | BFD_ENDIAN_BIG, /* header byte order is big */ | |
2818 | ||
2819 | (HAS_RELOC | EXEC_P | /* FIXME: object flags */ | |
2820 | HAS_LINENO | HAS_DEBUG | | |
2821 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
2822 | ||
2823 | #ifndef COFF_WITH_PE | |
2824 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
2825 | #else | |
2826 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */ | |
2827 | | SEC_LINK_ONCE | SEC_LINK_DUPLICATES), | |
2828 | #endif | |
2829 | ||
2830 | 0, /* leading char */ | |
2831 | '/', /* ar_pad_char */ | |
2832 | 15, /* ar_max_namelen??? FIXMEmgo */ | |
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, /* data */ | |
2837 | ||
2838 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, | |
2839 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
2840 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ | |
2841 | ||
2842 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ | |
2843 | bfd_generic_archive_p, /* _bfd_dummy_target */ coff_object_p }, | |
2844 | {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ | |
2845 | bfd_false}, | |
2846 | {bfd_false, coff_write_object_contents, /* bfd_write_contents */ | |
2847 | _bfd_write_archive_contents, bfd_false}, | |
2848 | ||
2849 | BFD_JUMP_TABLE_GENERIC (coff), | |
2850 | BFD_JUMP_TABLE_COPY (coff), | |
2851 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
2852 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
2853 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
2854 | BFD_JUMP_TABLE_RELOCS (coff), | |
2855 | BFD_JUMP_TABLE_WRITE (coff), | |
2856 | BFD_JUMP_TABLE_LINK (coff), | |
2857 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
2858 | ||
c3c89269 NC |
2859 | /* Alternative_target. */ |
2860 | #ifdef TARGET_LITTLE_SYM | |
2861 | & TARGET_LITTLE_SYM, | |
2862 | #else | |
2863 | NULL, | |
2864 | #endif | |
43646c9d | 2865 | |
c3c89269 | 2866 | COFF_SWAP_TABLE |
252b5132 RH |
2867 | }; |
2868 | ||
2869 | #endif |