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