Home | History | Annotate | Line # | Download | only in bfd
      1 /* BFD back-end for ALPHA Extended-Coff files.
      2    Copyright (C) 1993-2025 Free Software Foundation, Inc.
      3    Modified from coff-mips.c by Steve Chamberlain <sac (at) cygnus.com> and
      4    Ian Lance Taylor <ian (at) cygnus.com>.
      5 
      6    This file is part of BFD, the Binary File Descriptor library.
      7 
      8    This program is free software; you can redistribute it and/or modify
      9    it under the terms of the GNU General Public License as published by
     10    the Free Software Foundation; either version 3 of the License, or
     11    (at your option) any later version.
     12 
     13    This program is distributed in the hope that it will be useful,
     14    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16    GNU General Public License for more details.
     17 
     18    You should have received a copy of the GNU General Public License
     19    along with this program; if not, write to the Free Software
     20    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     21    MA 02110-1301, USA.  */
     22 
     23 #include "sysdep.h"
     24 #include "bfd.h"
     25 #include "bfdlink.h"
     26 #include "libbfd.h"
     27 #include "coff/internal.h"
     28 #include "coff/sym.h"
     29 #include "coff/symconst.h"
     30 #include "coff/ecoff.h"
     31 #include "coff/alpha.h"
     32 #include "aout/ar.h"
     33 #include "libcoff.h"
     34 #include "libecoff.h"
     35 
     36 /* Prototypes for static functions.  */
     38 
     39 
     40 
     41 /* ECOFF has COFF sections, but the debugging information is stored in
     43    a completely different format.  ECOFF targets use some of the
     44    swapping routines from coffswap.h, and some of the generic COFF
     45    routines in coffgen.c, but, unlike the real COFF targets, do not
     46    use coffcode.h itself.
     47 
     48    Get the generic COFF swapping routines, except for the reloc,
     49    symbol, and lineno ones.  Give them ecoff names.  Define some
     50    accessor macros for the large sizes used for Alpha ECOFF.  */
     51 
     52 #define GET_FILEHDR_SYMPTR H_GET_64
     53 #define PUT_FILEHDR_SYMPTR H_PUT_64
     54 #define GET_AOUTHDR_TSIZE H_GET_64
     55 #define PUT_AOUTHDR_TSIZE H_PUT_64
     56 #define GET_AOUTHDR_DSIZE H_GET_64
     57 #define PUT_AOUTHDR_DSIZE H_PUT_64
     58 #define GET_AOUTHDR_BSIZE H_GET_64
     59 #define PUT_AOUTHDR_BSIZE H_PUT_64
     60 #define GET_AOUTHDR_ENTRY H_GET_64
     61 #define PUT_AOUTHDR_ENTRY H_PUT_64
     62 #define GET_AOUTHDR_TEXT_START H_GET_64
     63 #define PUT_AOUTHDR_TEXT_START H_PUT_64
     64 #define GET_AOUTHDR_DATA_START H_GET_64
     65 #define PUT_AOUTHDR_DATA_START H_PUT_64
     66 #define GET_SCNHDR_PADDR H_GET_64
     67 #define PUT_SCNHDR_PADDR H_PUT_64
     68 #define GET_SCNHDR_VADDR H_GET_64
     69 #define PUT_SCNHDR_VADDR H_PUT_64
     70 #define GET_SCNHDR_SIZE H_GET_64
     71 #define PUT_SCNHDR_SIZE H_PUT_64
     72 #define GET_SCNHDR_SCNPTR H_GET_64
     73 #define PUT_SCNHDR_SCNPTR H_PUT_64
     74 #define GET_SCNHDR_RELPTR H_GET_64
     75 #define PUT_SCNHDR_RELPTR H_PUT_64
     76 #define GET_SCNHDR_LNNOPTR H_GET_64
     77 #define PUT_SCNHDR_LNNOPTR H_PUT_64
     78 
     79 #define ALPHAECOFF
     80 
     81 #define NO_COFF_RELOCS
     82 #define NO_COFF_SYMBOLS
     83 #define NO_COFF_LINENOS
     84 #define coff_swap_filehdr_in alpha_ecoff_swap_filehdr_in
     85 #define coff_swap_filehdr_out alpha_ecoff_swap_filehdr_out
     86 #define coff_swap_aouthdr_in alpha_ecoff_swap_aouthdr_in
     87 #define coff_swap_aouthdr_out alpha_ecoff_swap_aouthdr_out
     88 #define coff_swap_scnhdr_in alpha_ecoff_swap_scnhdr_in
     89 #define coff_swap_scnhdr_out alpha_ecoff_swap_scnhdr_out
     90 #include "coffswap.h"
     91 
     92 /* Get the ECOFF swapping routines.  */
     93 #define ECOFF_64
     94 #include "ecoffswap.h"
     95 
     96 /* How to process the various reloc types.  */
     98 
     99 static bfd_reloc_status_type
    100 reloc_nil (bfd *abfd ATTRIBUTE_UNUSED,
    101 	   arelent *reloc ATTRIBUTE_UNUSED,
    102 	   asymbol *sym ATTRIBUTE_UNUSED,
    103 	   void * data ATTRIBUTE_UNUSED,
    104 	   asection *sec ATTRIBUTE_UNUSED,
    105 	   bfd *output_bfd ATTRIBUTE_UNUSED,
    106 	   char **error_message ATTRIBUTE_UNUSED)
    107 {
    108   return bfd_reloc_ok;
    109 }
    110 
    111 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
    112    from smaller values.  Start with zero, widen, *then* decrement.  */
    113 #define MINUS_ONE	(((bfd_vma)0) - 1)
    114 
    115 static reloc_howto_type alpha_howto_table[] =
    116 {
    117   /* Reloc type 0 is ignored by itself.  However, it appears after a
    118      GPDISP reloc to identify the location where the low order 16 bits
    119      of the gp register are loaded.  */
    120   HOWTO (ALPHA_R_IGNORE,	/* type */
    121 	 0,			/* rightshift */
    122 	 1,			/* size */
    123 	 8,			/* bitsize */
    124 	 true,			/* pc_relative */
    125 	 0,			/* bitpos */
    126 	 complain_overflow_dont, /* complain_on_overflow */
    127 	 reloc_nil,		/* special_function */
    128 	 "IGNORE",		/* name */
    129 	 true,			/* partial_inplace */
    130 	 0,			/* src_mask */
    131 	 0,			/* dst_mask */
    132 	 true),			/* pcrel_offset */
    133 
    134   /* A 32 bit reference to a symbol.  */
    135   HOWTO (ALPHA_R_REFLONG,	/* type */
    136 	 0,			/* rightshift */
    137 	 4,			/* size */
    138 	 32,			/* bitsize */
    139 	 false,			/* pc_relative */
    140 	 0,			/* bitpos */
    141 	 complain_overflow_bitfield, /* complain_on_overflow */
    142 	 0,			/* special_function */
    143 	 "REFLONG",		/* name */
    144 	 true,			/* partial_inplace */
    145 	 0xffffffff,		/* src_mask */
    146 	 0xffffffff,		/* dst_mask */
    147 	 false),		/* pcrel_offset */
    148 
    149   /* A 64 bit reference to a symbol.  */
    150   HOWTO (ALPHA_R_REFQUAD,	/* type */
    151 	 0,			/* rightshift */
    152 	 8,			/* size */
    153 	 64,			/* bitsize */
    154 	 false,			/* pc_relative */
    155 	 0,			/* bitpos */
    156 	 complain_overflow_bitfield, /* complain_on_overflow */
    157 	 0,			/* special_function */
    158 	 "REFQUAD",		/* name */
    159 	 true,			/* partial_inplace */
    160 	 MINUS_ONE,		/* src_mask */
    161 	 MINUS_ONE,		/* dst_mask */
    162 	 false),		/* pcrel_offset */
    163 
    164   /* A 32 bit GP relative offset.  This is just like REFLONG except
    165      that when the value is used the value of the gp register will be
    166      added in.  */
    167   HOWTO (ALPHA_R_GPREL32,	/* type */
    168 	 0,			/* rightshift */
    169 	 4,			/* size */
    170 	 32,			/* bitsize */
    171 	 false,			/* pc_relative */
    172 	 0,			/* bitpos */
    173 	 complain_overflow_bitfield, /* complain_on_overflow */
    174 	 0,			/* special_function */
    175 	 "GPREL32",		/* name */
    176 	 true,			/* partial_inplace */
    177 	 0xffffffff,		/* src_mask */
    178 	 0xffffffff,		/* dst_mask */
    179 	 false),		/* pcrel_offset */
    180 
    181   /* Used for an instruction that refers to memory off the GP
    182      register.  The offset is 16 bits of the 32 bit instruction.  This
    183      reloc always seems to be against the .lita section.  */
    184   HOWTO (ALPHA_R_LITERAL,	/* type */
    185 	 0,			/* rightshift */
    186 	 4,			/* size */
    187 	 16,			/* bitsize */
    188 	 false,			/* pc_relative */
    189 	 0,			/* bitpos */
    190 	 complain_overflow_signed, /* complain_on_overflow */
    191 	 0,			/* special_function */
    192 	 "LITERAL",		/* name */
    193 	 true,			/* partial_inplace */
    194 	 0xffff,		/* src_mask */
    195 	 0xffff,		/* dst_mask */
    196 	 false),		/* pcrel_offset */
    197 
    198   /* This reloc only appears immediately following a LITERAL reloc.
    199      It identifies a use of the literal.  It seems that the linker can
    200      use this to eliminate a portion of the .lita section.  The symbol
    201      index is special: 1 means the literal address is in the base
    202      register of a memory format instruction; 2 means the literal
    203      address is in the byte offset register of a byte-manipulation
    204      instruction; 3 means the literal address is in the target
    205      register of a jsr instruction.  This does not actually do any
    206      relocation.  */
    207   HOWTO (ALPHA_R_LITUSE,	/* type */
    208 	 0,			/* rightshift */
    209 	 4,			/* size */
    210 	 32,			/* bitsize */
    211 	 false,			/* pc_relative */
    212 	 0,			/* bitpos */
    213 	 complain_overflow_dont, /* complain_on_overflow */
    214 	 reloc_nil,		/* special_function */
    215 	 "LITUSE",		/* name */
    216 	 false,			/* partial_inplace */
    217 	 0,			/* src_mask */
    218 	 0,			/* dst_mask */
    219 	 false),		/* pcrel_offset */
    220 
    221   /* Load the gp register.  This is always used for a ldah instruction
    222      which loads the upper 16 bits of the gp register.  The next reloc
    223      will be an IGNORE reloc which identifies the location of the lda
    224      instruction which loads the lower 16 bits.  The symbol index of
    225      the GPDISP instruction appears to actually be the number of bytes
    226      between the ldah and lda instructions.  This gives two different
    227      ways to determine where the lda instruction is; I don't know why
    228      both are used.  The value to use for the relocation is the
    229      difference between the GP value and the current location; the
    230      load will always be done against a register holding the current
    231      address.  */
    232   HOWTO (ALPHA_R_GPDISP,	/* type */
    233 	 16,			/* rightshift */
    234 	 4,			/* size */
    235 	 16,			/* bitsize */
    236 	 true,			/* pc_relative */
    237 	 0,			/* bitpos */
    238 	 complain_overflow_dont, /* complain_on_overflow */
    239 	 reloc_nil,		/* special_function */
    240 	 "GPDISP",		/* name */
    241 	 true,			/* partial_inplace */
    242 	 0xffff,		/* src_mask */
    243 	 0xffff,		/* dst_mask */
    244 	 true),			/* pcrel_offset */
    245 
    246   /* A 21 bit branch.  The native assembler generates these for
    247      branches within the text segment, and also fills in the PC
    248      relative offset in the instruction.  */
    249   HOWTO (ALPHA_R_BRADDR,	/* type */
    250 	 2,			/* rightshift */
    251 	 4,			/* size */
    252 	 21,			/* bitsize */
    253 	 true,			/* pc_relative */
    254 	 0,			/* bitpos */
    255 	 complain_overflow_signed, /* complain_on_overflow */
    256 	 0,			/* special_function */
    257 	 "BRADDR",		/* name */
    258 	 true,			/* partial_inplace */
    259 	 0x1fffff,		/* src_mask */
    260 	 0x1fffff,		/* dst_mask */
    261 	 false),		/* pcrel_offset */
    262 
    263   /* A hint for a jump to a register.  */
    264   HOWTO (ALPHA_R_HINT,		/* type */
    265 	 2,			/* rightshift */
    266 	 4,			/* size */
    267 	 14,			/* bitsize */
    268 	 true,			/* pc_relative */
    269 	 0,			/* bitpos */
    270 	 complain_overflow_dont, /* complain_on_overflow */
    271 	 0,			/* special_function */
    272 	 "HINT",		/* name */
    273 	 true,			/* partial_inplace */
    274 	 0x3fff,		/* src_mask */
    275 	 0x3fff,		/* dst_mask */
    276 	 false),		/* pcrel_offset */
    277 
    278   /* 16 bit PC relative offset.  */
    279   HOWTO (ALPHA_R_SREL16,	/* type */
    280 	 0,			/* rightshift */
    281 	 2,			/* size */
    282 	 16,			/* bitsize */
    283 	 true,			/* pc_relative */
    284 	 0,			/* bitpos */
    285 	 complain_overflow_signed, /* complain_on_overflow */
    286 	 0,			/* special_function */
    287 	 "SREL16",		/* name */
    288 	 true,			/* partial_inplace */
    289 	 0xffff,		/* src_mask */
    290 	 0xffff,		/* dst_mask */
    291 	 false),		/* pcrel_offset */
    292 
    293   /* 32 bit PC relative offset.  */
    294   HOWTO (ALPHA_R_SREL32,	/* type */
    295 	 0,			/* rightshift */
    296 	 4,			/* size */
    297 	 32,			/* bitsize */
    298 	 true,			/* pc_relative */
    299 	 0,			/* bitpos */
    300 	 complain_overflow_signed, /* complain_on_overflow */
    301 	 0,			/* special_function */
    302 	 "SREL32",		/* name */
    303 	 true,			/* partial_inplace */
    304 	 0xffffffff,		/* src_mask */
    305 	 0xffffffff,		/* dst_mask */
    306 	 false),		/* pcrel_offset */
    307 
    308   /* A 64 bit PC relative offset.  */
    309   HOWTO (ALPHA_R_SREL64,	/* type */
    310 	 0,			/* rightshift */
    311 	 8,			/* size */
    312 	 64,			/* bitsize */
    313 	 true,			/* pc_relative */
    314 	 0,			/* bitpos */
    315 	 complain_overflow_signed, /* complain_on_overflow */
    316 	 0,			/* special_function */
    317 	 "SREL64",		/* name */
    318 	 true,			/* partial_inplace */
    319 	 MINUS_ONE,		/* src_mask */
    320 	 MINUS_ONE,		/* dst_mask */
    321 	 false),		/* pcrel_offset */
    322 
    323   /* Push a value on the reloc evaluation stack.  */
    324   HOWTO (ALPHA_R_OP_PUSH,	/* type */
    325 	 0,			/* rightshift */
    326 	 0,			/* size */
    327 	 0,			/* bitsize */
    328 	 false,			/* pc_relative */
    329 	 0,			/* bitpos */
    330 	 complain_overflow_dont, /* complain_on_overflow */
    331 	 0,			/* special_function */
    332 	 "OP_PUSH",		/* name */
    333 	 false,			/* partial_inplace */
    334 	 0,			/* src_mask */
    335 	 0,			/* dst_mask */
    336 	 false),		/* pcrel_offset */
    337 
    338   /* Store the value from the stack at the given address.  Store it in
    339      a bitfield of size r_size starting at bit position r_offset.  */
    340   HOWTO (ALPHA_R_OP_STORE,	/* type */
    341 	 0,			/* rightshift */
    342 	 8,			/* size */
    343 	 64,			/* bitsize */
    344 	 false,			/* pc_relative */
    345 	 0,			/* bitpos */
    346 	 complain_overflow_dont, /* complain_on_overflow */
    347 	 0,			/* special_function */
    348 	 "OP_STORE",		/* name */
    349 	 false,			/* partial_inplace */
    350 	 0,			/* src_mask */
    351 	 MINUS_ONE,		/* dst_mask */
    352 	 false),		/* pcrel_offset */
    353 
    354   /* Subtract the reloc address from the value on the top of the
    355      relocation stack.  */
    356   HOWTO (ALPHA_R_OP_PSUB,	/* type */
    357 	 0,			/* rightshift */
    358 	 0,			/* size */
    359 	 0,			/* bitsize */
    360 	 false,			/* pc_relative */
    361 	 0,			/* bitpos */
    362 	 complain_overflow_dont, /* complain_on_overflow */
    363 	 0,			/* special_function */
    364 	 "OP_PSUB",		/* name */
    365 	 false,			/* partial_inplace */
    366 	 0,			/* src_mask */
    367 	 0,			/* dst_mask */
    368 	 false),		/* pcrel_offset */
    369 
    370   /* Shift the value on the top of the relocation stack right by the
    371      given value.  */
    372   HOWTO (ALPHA_R_OP_PRSHIFT,	/* type */
    373 	 0,			/* rightshift */
    374 	 0,			/* size */
    375 	 0,			/* bitsize */
    376 	 false,			/* pc_relative */
    377 	 0,			/* bitpos */
    378 	 complain_overflow_dont, /* complain_on_overflow */
    379 	 0,			/* special_function */
    380 	 "OP_PRSHIFT",		/* name */
    381 	 false,			/* partial_inplace */
    382 	 0,			/* src_mask */
    383 	 0,			/* dst_mask */
    384 	 false),		/* pcrel_offset */
    385 
    386   /* Adjust the GP value for a new range in the object file.  */
    387   HOWTO (ALPHA_R_GPVALUE,	/* type */
    388 	 0,			/* rightshift */
    389 	 0,			/* size */
    390 	 0,			/* bitsize */
    391 	 false,			/* pc_relative */
    392 	 0,			/* bitpos */
    393 	 complain_overflow_dont, /* complain_on_overflow */
    394 	 0,			/* special_function */
    395 	 "GPVALUE",		/* name */
    396 	 false,			/* partial_inplace */
    397 	 0,			/* src_mask */
    398 	 0,			/* dst_mask */
    399 	 false)			/* pcrel_offset */
    400 };
    401 
    402 /* Recognize an Alpha ECOFF file.  */
    404 
    405 static bfd_cleanup
    406 alpha_ecoff_object_p (bfd *abfd)
    407 {
    408   bfd_cleanup ret;
    409 
    410   ret = coff_object_p (abfd);
    411 
    412   if (ret != NULL)
    413     {
    414       asection *sec;
    415 
    416       /* Alpha ECOFF has a .pdata section.  The lnnoptr field of the
    417 	 .pdata section is the number of entries it contains.  Each
    418 	 entry takes up 8 bytes.  The number of entries is required
    419 	 since the section is aligned to a 16 byte boundary.  When we
    420 	 link .pdata sections together, we do not want to include the
    421 	 alignment bytes.  We handle this on input by faking the size
    422 	 of the .pdata section to remove the unwanted alignment bytes.
    423 	 On output we will set the lnnoptr field and force the
    424 	 alignment.  */
    425       sec = bfd_get_section_by_name (abfd, _PDATA);
    426       if (sec != (asection *) NULL)
    427 	{
    428 	  bfd_size_type size;
    429 
    430 	  size = (bfd_size_type) sec->line_filepos * 8;
    431 	  BFD_ASSERT (size == sec->size
    432 		      || size + 8 == sec->size);
    433 	  if (!bfd_set_section_size (sec, size))
    434 	    return NULL;
    435 	}
    436     }
    437 
    438   return ret;
    439 }
    440 
    441 /* See whether the magic number matches.  */
    442 
    443 static bool
    444 alpha_ecoff_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED,
    445 			     void * filehdr)
    446 {
    447   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
    448 
    449   if (! ALPHA_ECOFF_BADMAG (*internal_f))
    450     return true;
    451 
    452   if (ALPHA_ECOFF_COMPRESSEDMAG (*internal_f))
    453     _bfd_error_handler
    454       (_("%pB: cannot handle compressed Alpha binaries; "
    455 	 "use compiler flags, or objZ, to generate uncompressed binaries"),
    456        abfd);
    457 
    458   return false;
    459 }
    460 
    461 /* This is a hook called by coff_real_object_p to create any backend
    462    specific information.  */
    463 
    464 static void *
    465 alpha_ecoff_mkobject_hook (bfd *abfd, void * filehdr, void * aouthdr)
    466 {
    467   void * ecoff;
    468 
    469   ecoff = _bfd_ecoff_mkobject_hook (abfd, filehdr, aouthdr);
    470 
    471   if (ecoff != NULL)
    472     {
    473       struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
    474 
    475       /* Set additional BFD flags according to the object type from the
    476 	 machine specific file header flags.  */
    477       switch (internal_f->f_flags & F_ALPHA_OBJECT_TYPE_MASK)
    478 	{
    479 	case F_ALPHA_SHARABLE:
    480 	  abfd->flags |= DYNAMIC;
    481 	  break;
    482 	case F_ALPHA_CALL_SHARED:
    483 	  /* Always executable if using shared libraries as the run time
    484 	     loader might resolve undefined references.  */
    485 	  abfd->flags |= (DYNAMIC | EXEC_P);
    486 	  break;
    487 	}
    488     }
    489   return ecoff;
    490 }
    491 
    492 /* Reloc handling.  */
    494 
    495 /* Swap a reloc in.  */
    496 
    497 static void
    498 alpha_ecoff_swap_reloc_in (bfd *abfd,
    499 			   void * ext_ptr,
    500 			   struct internal_reloc *intern)
    501 {
    502   const RELOC *ext = (RELOC *) ext_ptr;
    503 
    504   intern->r_vaddr = H_GET_64 (abfd, ext->r_vaddr);
    505   intern->r_symndx = H_GET_32 (abfd, ext->r_symndx);
    506 
    507   BFD_ASSERT (bfd_header_little_endian (abfd));
    508 
    509   intern->r_type = ((ext->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
    510 		    >> RELOC_BITS0_TYPE_SH_LITTLE);
    511   intern->r_extern = (ext->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
    512   intern->r_offset = ((ext->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
    513 		      >> RELOC_BITS1_OFFSET_SH_LITTLE);
    514   /* Ignored the reserved bits.  */
    515   intern->r_size = ((ext->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
    516 		    >> RELOC_BITS3_SIZE_SH_LITTLE);
    517 
    518   if (intern->r_type == ALPHA_R_LITUSE
    519       || intern->r_type == ALPHA_R_GPDISP)
    520     {
    521       /* Handle the LITUSE and GPDISP relocs specially.  Its symndx
    522 	 value is not actually a symbol index, but is instead a
    523 	 special code.  We put the code in the r_size field, and
    524 	 clobber the symndx.  */
    525       BFD_ASSERT (intern->r_size == 0);
    526       intern->r_size = intern->r_symndx;
    527       intern->r_symndx = RELOC_SECTION_NONE;
    528     }
    529   else if (intern->r_type == ALPHA_R_IGNORE)
    530     {
    531       /* The IGNORE reloc generally follows a GPDISP reloc, and is
    532 	 against the .lita section.  The section is irrelevant.  */
    533       BFD_ASSERT (intern->r_extern || intern->r_symndx != RELOC_SECTION_ABS);
    534       if (! intern->r_extern && intern->r_symndx == RELOC_SECTION_LITA)
    535 	intern->r_symndx = RELOC_SECTION_ABS;
    536     }
    537   else if (intern->r_type == ALPHA_R_OP_STORE)
    538     {
    539       /* Size of 64 bits is encoded as 0 in this 6-bit field.  */
    540       if (intern->r_size == 0)
    541 	intern->r_size = 64;
    542     }
    543 }
    544 
    545 /* Swap a reloc out.  */
    546 
    547 static void
    548 alpha_ecoff_swap_reloc_out (bfd *abfd,
    549 			    const struct internal_reloc *intern,
    550 			    void * dst)
    551 {
    552   RELOC *ext = (RELOC *) dst;
    553   long symndx;
    554   unsigned char size;
    555 
    556   /* Undo the hackery done in swap_reloc_in.  */
    557   if (intern->r_type == ALPHA_R_LITUSE
    558       || intern->r_type == ALPHA_R_GPDISP)
    559     {
    560       symndx = intern->r_size;
    561       size = 0;
    562     }
    563   else if (intern->r_type == ALPHA_R_IGNORE
    564 	   && ! intern->r_extern
    565 	   && intern->r_symndx == RELOC_SECTION_ABS)
    566     {
    567       symndx = RELOC_SECTION_LITA;
    568       size = intern->r_size;
    569     }
    570   else
    571     {
    572       symndx = intern->r_symndx;
    573       size = intern->r_size;
    574     }
    575 
    576   /* XXX FIXME:  The maximum symndx value used to be 14 but this
    577      fails with object files produced by DEC's C++ compiler.
    578      Where does the value 14 (or 15) come from anyway ?  */
    579   BFD_ASSERT (intern->r_extern
    580 	      || (intern->r_symndx >= 0 && intern->r_symndx <= 15));
    581 
    582   H_PUT_64 (abfd, intern->r_vaddr, ext->r_vaddr);
    583   H_PUT_32 (abfd, symndx, ext->r_symndx);
    584 
    585   BFD_ASSERT (bfd_header_little_endian (abfd));
    586 
    587   ext->r_bits[0] = ((intern->r_type << RELOC_BITS0_TYPE_SH_LITTLE)
    588 		    & RELOC_BITS0_TYPE_LITTLE);
    589   ext->r_bits[1] = ((intern->r_extern ? RELOC_BITS1_EXTERN_LITTLE : 0)
    590 		    | ((intern->r_offset << RELOC_BITS1_OFFSET_SH_LITTLE)
    591 		       & RELOC_BITS1_OFFSET_LITTLE));
    592   ext->r_bits[2] = 0;
    593   ext->r_bits[3] = ((size << RELOC_BITS3_SIZE_SH_LITTLE)
    594 		    & RELOC_BITS3_SIZE_LITTLE);
    595 }
    596 
    597 /* Finish canonicalizing a reloc.  Part of this is generic to all
    598    ECOFF targets, and that part is in ecoff.c.  The rest is done in
    599    this backend routine.  It must fill in the howto field.  */
    600 
    601 static void
    602 alpha_adjust_reloc_in (bfd *abfd,
    603 		       const struct internal_reloc *intern,
    604 		       arelent *rptr)
    605 {
    606   if (intern->r_type > ALPHA_R_GPVALUE)
    607     {
    608       /* xgettext:c-format */
    609       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
    610 			  abfd, intern->r_type);
    611       bfd_set_error (bfd_error_bad_value);
    612       rptr->addend = 0;
    613       rptr->howto  = NULL;
    614       return;
    615     }
    616 
    617   switch (intern->r_type)
    618     {
    619     case ALPHA_R_BRADDR:
    620     case ALPHA_R_SREL16:
    621     case ALPHA_R_SREL32:
    622     case ALPHA_R_SREL64:
    623       /* This relocs appear to be fully resolved when they are against
    624 	 internal symbols.  Against external symbols, BRADDR at least
    625 	 appears to be resolved against the next instruction.  */
    626       if (! intern->r_extern)
    627 	rptr->addend = 0;
    628       else
    629 	rptr->addend = - (intern->r_vaddr + 4);
    630       break;
    631 
    632     case ALPHA_R_GPREL32:
    633     case ALPHA_R_LITERAL:
    634       /* Copy the gp value for this object file into the addend, to
    635 	 ensure that we are not confused by the linker.  */
    636       if (! intern->r_extern)
    637 	rptr->addend += ecoff_data (abfd)->gp;
    638       break;
    639 
    640     case ALPHA_R_LITUSE:
    641     case ALPHA_R_GPDISP:
    642       /* The LITUSE and GPDISP relocs do not use a symbol, or an
    643 	 addend, but they do use a special code.  Put this code in the
    644 	 addend field.  */
    645       rptr->addend = intern->r_size;
    646       break;
    647 
    648     case ALPHA_R_OP_STORE:
    649       /* The STORE reloc needs the size and offset fields.  We store
    650 	 them in the addend.  */
    651 #if 0
    652       BFD_ASSERT (intern->r_offset <= 256);
    653 #endif
    654       rptr->addend = (intern->r_offset << 8) + intern->r_size;
    655       break;
    656 
    657     case ALPHA_R_OP_PUSH:
    658     case ALPHA_R_OP_PSUB:
    659     case ALPHA_R_OP_PRSHIFT:
    660       /* The PUSH, PSUB and PRSHIFT relocs do not actually use an
    661 	 address.  I believe that the address supplied is really an
    662 	 addend.  */
    663       rptr->addend = intern->r_vaddr;
    664       break;
    665 
    666     case ALPHA_R_GPVALUE:
    667       /* Set the addend field to the new GP value.  */
    668       rptr->addend = intern->r_symndx + ecoff_data (abfd)->gp;
    669       break;
    670 
    671     case ALPHA_R_IGNORE:
    672       /* If the type is ALPHA_R_IGNORE, make sure this is a reference
    673 	 to the absolute section so that the reloc is ignored.  For
    674 	 some reason the address of this reloc type is not adjusted by
    675 	 the section vma.  We record the gp value for this object file
    676 	 here, for convenience when doing the GPDISP relocation.  */
    677       rptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
    678       rptr->address = intern->r_vaddr;
    679       rptr->addend = ecoff_data (abfd)->gp;
    680       break;
    681 
    682     default:
    683       break;
    684     }
    685 
    686   rptr->howto = &alpha_howto_table[intern->r_type];
    687 }
    688 
    689 /* When writing out a reloc we need to pull some values back out of
    690    the addend field into the reloc.  This is roughly the reverse of
    691    alpha_adjust_reloc_in, except that there are several changes we do
    692    not need to undo.  */
    693 
    694 static void
    695 alpha_adjust_reloc_out (bfd *abfd ATTRIBUTE_UNUSED,
    696 			const arelent *rel,
    697 			struct internal_reloc *intern)
    698 {
    699   switch (intern->r_type)
    700     {
    701     case ALPHA_R_LITUSE:
    702     case ALPHA_R_GPDISP:
    703       intern->r_size = rel->addend;
    704       break;
    705 
    706     case ALPHA_R_OP_STORE:
    707       intern->r_size = rel->addend & 0xff;
    708       intern->r_offset = (rel->addend >> 8) & 0xff;
    709       break;
    710 
    711     case ALPHA_R_OP_PUSH:
    712     case ALPHA_R_OP_PSUB:
    713     case ALPHA_R_OP_PRSHIFT:
    714       intern->r_vaddr = rel->addend;
    715       break;
    716 
    717     case ALPHA_R_IGNORE:
    718       intern->r_vaddr = rel->address;
    719       break;
    720 
    721     default:
    722       break;
    723     }
    724 }
    725 
    726 /* Write VAL to a little-endian bitfield specified by BITOFFSET and
    727    BITSIZE at CONTENTS + SECOFFSET.  Verify that these parameter are
    728    valid for SEC in ABFD.  */
    729 
    730 static bool
    731 write_bit_field (bfd *abfd, asection *sec,
    732 		 bfd_byte *contents, bfd_size_type secoffset,
    733 		 unsigned int bitoffset, unsigned int bitsize, uint64_t val)
    734 {
    735   if (bitsize == 0)
    736     return true;
    737 
    738   bfd_size_type secsize = bfd_get_section_limit_octets (abfd, sec);
    739   unsigned int startbyte = bitoffset >> 3;
    740   unsigned int endbyte = (bitoffset + bitsize - 1) >> 3;
    741 
    742   if (secoffset > secsize || secsize - secoffset <= endbyte)
    743     return false;
    744 
    745   unsigned int startbit = bitoffset & 7;
    746   unsigned int endbit = (bitoffset + bitsize - 1) & 7;
    747   unsigned int mask = -1u << startbit;
    748   unsigned char *p = contents + secoffset;
    749   if (startbyte != endbyte)
    750     {
    751       p[startbyte] = (p[startbyte] & ~mask) | ((val << startbit) & mask);
    752       val = val >> (8 - startbit);
    753 
    754       for (unsigned int off = startbyte + 1; off < endbyte; ++off)
    755 	{
    756 	  p[off] = val;
    757 	  val >>= 8;
    758 	}
    759       mask = ~(-1u << (1 + endbit));
    760     }
    761   else
    762     {
    763       val = val << startbit;
    764       mask = mask & ~(-1u << (1 + endbit));
    765     }
    766   p[endbyte] = (p[endbyte] & ~mask) | (val & mask);
    767   return true;
    768 }
    769 
    770 /* The size of the stack for the relocation evaluator.  */
    771 #define RELOC_STACKSIZE (10)
    772 
    773 /* Alpha ECOFF relocs have a built in expression evaluator as well as
    774    other interdependencies.  Rather than use a bunch of special
    775    functions and global variables, we use a single routine to do all
    776    the relocation for a section.  I haven't yet worked out how the
    777    assembler is going to handle this.  */
    778 
    779 static bfd_byte *
    780 alpha_ecoff_get_relocated_section_contents (bfd *abfd,
    781 					    struct bfd_link_info *link_info,
    782 					    struct bfd_link_order *link_order,
    783 					    bfd_byte *data,
    784 					    bool relocatable,
    785 					    asymbol **symbols)
    786 {
    787   bfd *input_bfd = link_order->u.indirect.section->owner;
    788   asection *input_section = link_order->u.indirect.section;
    789   long reloc_size;
    790   arelent **reloc_vector;
    791   long reloc_count;
    792   bfd *output_bfd = relocatable ? abfd : (bfd *) NULL;
    793   bfd_vma gp;
    794   bool gp_undefined;
    795   bfd_vma stack[RELOC_STACKSIZE];
    796   int tos = 0;
    797 
    798   reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
    799   if (reloc_size < 0)
    800     return NULL;
    801 
    802   bfd_byte *orig_data = data;
    803   if (!bfd_get_full_section_contents (input_bfd, input_section, &data))
    804     return NULL;
    805 
    806   if (data == NULL)
    807     return NULL;
    808 
    809   if (reloc_size == 0)
    810     return data;
    811 
    812   reloc_vector = (arelent **) bfd_malloc (reloc_size);
    813   if (reloc_vector == NULL)
    814     goto error_return;
    815 
    816   reloc_count = bfd_canonicalize_reloc (input_bfd, input_section,
    817 					reloc_vector, symbols);
    818   if (reloc_count < 0)
    819     goto error_return;
    820   if (reloc_count == 0)
    821     goto successful_return;
    822 
    823   /* Get the GP value for the output BFD.  */
    824   gp_undefined = false;
    825   gp = _bfd_get_gp_value (abfd);
    826   if (gp == 0)
    827     {
    828       if (relocatable)
    829 	{
    830 	  asection *sec;
    831 	  bfd_vma lo;
    832 
    833 	  /* Make up a value.  */
    834 	  lo = (bfd_vma) -1;
    835 	  for (sec = abfd->sections; sec != NULL; sec = sec->next)
    836 	    {
    837 	      if (sec->vma < lo
    838 		  && (strcmp (sec->name, ".sbss") == 0
    839 		      || strcmp (sec->name, ".sdata") == 0
    840 		      || strcmp (sec->name, ".lit4") == 0
    841 		      || strcmp (sec->name, ".lit8") == 0
    842 		      || strcmp (sec->name, ".lita") == 0))
    843 		lo = sec->vma;
    844 	    }
    845 	  gp = lo + 0x8000;
    846 	  _bfd_set_gp_value (abfd, gp);
    847 	}
    848       else
    849 	{
    850 	  struct bfd_link_hash_entry *h;
    851 
    852 	  h = bfd_link_hash_lookup (link_info->hash, "_gp", false, false,
    853 				    true);
    854 	  if (h == (struct bfd_link_hash_entry *) NULL
    855 	      || h->type != bfd_link_hash_defined)
    856 	    gp_undefined = true;
    857 	  else
    858 	    {
    859 	      gp = (h->u.def.value
    860 		    + h->u.def.section->output_section->vma
    861 		    + h->u.def.section->output_offset);
    862 	      _bfd_set_gp_value (abfd, gp);
    863 	    }
    864 	}
    865     }
    866 
    867   for (arelent **relp = reloc_vector; *relp != NULL; relp++)
    868     {
    869       arelent *rel;
    870       bfd_reloc_status_type r;
    871       char *err;
    872       unsigned int r_type;
    873 
    874       rel = *relp;
    875       if (rel->howto == NULL)
    876 	{
    877 	  r = bfd_reloc_notsupported;
    878 	  r_type = ALPHA_R_IGNORE;
    879 	}
    880       else
    881 	{
    882 	  r = bfd_reloc_ok;
    883 	  r_type = rel->howto->type;
    884 	}
    885       switch (r_type)
    886 	{
    887 	case ALPHA_R_IGNORE:
    888 	  rel->address += input_section->output_offset;
    889 	  break;
    890 
    891 	case ALPHA_R_REFLONG:
    892 	case ALPHA_R_REFQUAD:
    893 	case ALPHA_R_BRADDR:
    894 	case ALPHA_R_HINT:
    895 	case ALPHA_R_SREL16:
    896 	case ALPHA_R_SREL32:
    897 	case ALPHA_R_SREL64:
    898 	  if (relocatable
    899 	      && ((*rel->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0)
    900 	    {
    901 	      rel->address += input_section->output_offset;
    902 	      break;
    903 	    }
    904 	  r = bfd_perform_relocation (input_bfd, rel, data, input_section,
    905 				      output_bfd, &err);
    906 	  break;
    907 
    908 	case ALPHA_R_GPREL32:
    909 	  /* This relocation is used in a switch table.  It is a 32
    910 	     bit offset from the current GP value.  We must adjust it
    911 	     by the different between the original GP value and the
    912 	     current GP value.  The original GP value is stored in the
    913 	     addend.  We adjust the addend and let
    914 	     bfd_perform_relocation finish the job.  */
    915 	  rel->addend -= gp;
    916 	  r = bfd_perform_relocation (input_bfd, rel, data, input_section,
    917 				      output_bfd, &err);
    918 	  if (r == bfd_reloc_ok && gp_undefined)
    919 	    {
    920 	      r = bfd_reloc_dangerous;
    921 	      err = (char *) _("GP relative relocation used when GP not defined");
    922 	    }
    923 	  break;
    924 
    925 	case ALPHA_R_LITERAL:
    926 	  /* This is a reference to a literal value, generally
    927 	     (always?) in the .lita section.  This is a 16 bit GP
    928 	     relative relocation.  Sometimes the subsequent reloc is a
    929 	     LITUSE reloc, which indicates how this reloc is used.
    930 	     This sometimes permits rewriting the two instructions
    931 	     referred to by the LITERAL and the LITUSE into different
    932 	     instructions which do not refer to .lita.  This can save
    933 	     a memory reference, and permits removing a value from
    934 	     .lita thus saving GP relative space.
    935 
    936 	     We do not these optimizations.  To do them we would need
    937 	     to arrange to link the .lita section first, so that by
    938 	     the time we got here we would know the final values to
    939 	     use.  This would not be particularly difficult, but it is
    940 	     not currently implemented.  */
    941 
    942 	  rel->addend -= gp;
    943 	  r = bfd_perform_relocation (input_bfd, rel, data, input_section,
    944 				      output_bfd, &err);
    945 	  if (r == bfd_reloc_ok && gp_undefined)
    946 	    {
    947 	      r = bfd_reloc_dangerous;
    948 	      err = (char *) _("GP relative relocation used"
    949 			       " when GP not defined");
    950 	    }
    951 	  break;
    952 
    953 	case ALPHA_R_LITUSE:
    954 	  /* See ALPHA_R_LITERAL above for the uses of this reloc.  It
    955 	     does not cause anything to happen, itself.  */
    956 	  rel->address += input_section->output_offset;
    957 	  break;
    958 
    959 	case ALPHA_R_GPDISP:
    960 	  /* This marks the ldah of an ldah/lda pair which loads the
    961 	     gp register with the difference of the gp value and the
    962 	     current location.  The second of the pair is r_size bytes
    963 	     ahead; it used to be marked with an ALPHA_R_IGNORE reloc,
    964 	     but that no longer happens in OSF/1 3.2.  */
    965 	  if (bfd_reloc_offset_in_range (rel->howto, input_bfd, input_section,
    966 					 rel->address)
    967 	      && bfd_reloc_offset_in_range (rel->howto, input_bfd, input_section,
    968 					    rel->address + rel->addend))
    969 	    {
    970 	      /* Get the two instructions.  */
    971 	      bfd_byte *p = data + rel->address;
    972 	      bfd_vma insn1 = bfd_get_32 (input_bfd, p);
    973 	      bfd_vma insn2 = bfd_get_32 (input_bfd, p + rel->addend);
    974 
    975 	      BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
    976 	      BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
    977 
    978 	      /* Get the existing addend.  We must account for the sign
    979 		 extension done by lda and ldah.  */
    980 	      bfd_vma addend = (((((insn1 & 0xffff) ^ 0x8000) - 0x8000) << 16)
    981 				+ ((((insn2 & 0xffff) ^ 0x8000) - 0x8000)));
    982 
    983 	      /* The existing addend includes the different between the
    984 		 gp of the input BFD and the address in the input BFD.
    985 		 Subtract this out.  */
    986 	      addend -= ecoff_data (input_bfd)->gp - input_section->vma;
    987 
    988 	      /* Now add in the final gp value, and subtract out the
    989 		 final address.  */
    990 	      addend += gp - (input_section->output_section->vma
    991 			      + input_section->output_offset);
    992 
    993 	      /* Change the instructions, accounting for the sign
    994 		 extension, and write them out.  */
    995 	      insn1 = (insn1 & ~0xffff) | (((addend + 0x8000) >> 16) & 0xffff);
    996 	      insn2 = (insn2 & ~0xffff) | (addend & 0xffff);
    997 
    998 	      bfd_put_32 (input_bfd, insn1, p);
    999 	      bfd_put_32 (input_bfd, insn2, p + rel->addend);
   1000 	    }
   1001 	  else
   1002 	    r = bfd_reloc_outofrange;
   1003 
   1004 	  rel->address += input_section->output_offset;
   1005 	  break;
   1006 
   1007 	case ALPHA_R_OP_PUSH:
   1008 	  /* Push a value on the reloc evaluation stack.  */
   1009 	  {
   1010 	    asymbol *symbol;
   1011 	    bfd_vma relocation;
   1012 
   1013 	    if (relocatable)
   1014 	      {
   1015 		rel->address += input_section->output_offset;
   1016 		break;
   1017 	      }
   1018 
   1019 	    /* Figure out the relocation of this symbol.  */
   1020 	    symbol = *rel->sym_ptr_ptr;
   1021 
   1022 	    if (bfd_is_und_section (symbol->section))
   1023 	      r = bfd_reloc_undefined;
   1024 
   1025 	    if (bfd_is_com_section (symbol->section))
   1026 	      relocation = 0;
   1027 	    else
   1028 	      relocation = symbol->value;
   1029 	    relocation += symbol->section->output_section->vma;
   1030 	    relocation += symbol->section->output_offset;
   1031 	    relocation += rel->addend;
   1032 
   1033 	    if (tos >= RELOC_STACKSIZE)
   1034 	      {
   1035 		r = bfd_reloc_notsupported;
   1036 		break;
   1037 	      }
   1038 
   1039 	    stack[tos++] = relocation;
   1040 	  }
   1041 	  break;
   1042 
   1043 	case ALPHA_R_OP_STORE:
   1044 	  /* Store a value from the reloc stack into a bitfield.  */
   1045 	  {
   1046 	    if (relocatable)
   1047 	      {
   1048 		rel->address += input_section->output_offset;
   1049 		break;
   1050 	      }
   1051 
   1052 	    if (tos == 0)
   1053 	      {
   1054 		r = bfd_reloc_notsupported;
   1055 		break;
   1056 	      }
   1057 
   1058 	    /* The offset and size in bits for this reloc are encoded
   1059 	       into the addend field by alpha_adjust_reloc_in.  */
   1060 	    unsigned int offset = (rel->addend >> 8) & 0xff;
   1061 	    unsigned int size = rel->addend & 0xff;
   1062 
   1063 	    if (!write_bit_field (input_bfd, input_section,
   1064 				  data, rel->address,
   1065 				  offset, size, stack[--tos]))
   1066 	      r = bfd_reloc_outofrange;
   1067 	  }
   1068 	  break;
   1069 
   1070 	case ALPHA_R_OP_PSUB:
   1071 	  /* Subtract a value from the top of the stack.  */
   1072 	  {
   1073 	    asymbol *symbol;
   1074 	    bfd_vma relocation;
   1075 
   1076 	    if (relocatable)
   1077 	      {
   1078 		rel->address += input_section->output_offset;
   1079 		break;
   1080 	      }
   1081 
   1082 	    /* Figure out the relocation of this symbol.  */
   1083 	    symbol = *rel->sym_ptr_ptr;
   1084 
   1085 	    if (bfd_is_und_section (symbol->section))
   1086 	      r = bfd_reloc_undefined;
   1087 
   1088 	    if (bfd_is_com_section (symbol->section))
   1089 	      relocation = 0;
   1090 	    else
   1091 	      relocation = symbol->value;
   1092 	    relocation += symbol->section->output_section->vma;
   1093 	    relocation += symbol->section->output_offset;
   1094 	    relocation += rel->addend;
   1095 
   1096 	    if (tos == 0)
   1097 	      {
   1098 		r = bfd_reloc_notsupported;
   1099 		break;
   1100 	      }
   1101 
   1102 	    stack[tos - 1] -= relocation;
   1103 	  }
   1104 	  break;
   1105 
   1106 	case ALPHA_R_OP_PRSHIFT:
   1107 	  /* Shift the value on the top of the stack.  */
   1108 	  {
   1109 	    asymbol *symbol;
   1110 	    bfd_vma relocation;
   1111 
   1112 	    if (relocatable)
   1113 	      {
   1114 		rel->address += input_section->output_offset;
   1115 		break;
   1116 	      }
   1117 
   1118 	    /* Figure out the relocation of this symbol.  */
   1119 	    symbol = *rel->sym_ptr_ptr;
   1120 
   1121 	    if (bfd_is_und_section (symbol->section))
   1122 	      r = bfd_reloc_undefined;
   1123 
   1124 	    if (bfd_is_com_section (symbol->section))
   1125 	      relocation = 0;
   1126 	    else
   1127 	      relocation = symbol->value;
   1128 	    relocation += symbol->section->output_section->vma;
   1129 	    relocation += symbol->section->output_offset;
   1130 	    relocation += rel->addend;
   1131 
   1132 	    if (tos == 0)
   1133 	      {
   1134 		r = bfd_reloc_notsupported;
   1135 		break;
   1136 	      }
   1137 
   1138 	    stack[tos - 1] >>= relocation;
   1139 	  }
   1140 	  break;
   1141 
   1142 	case ALPHA_R_GPVALUE:
   1143 	  /* I really don't know if this does the right thing.  */
   1144 	  gp = rel->addend;
   1145 	  gp_undefined = false;
   1146 	  break;
   1147 
   1148 	default:
   1149 	  r = bfd_reloc_notsupported;
   1150 	  break;
   1151 	}
   1152 
   1153       if (relocatable)
   1154 	{
   1155 	  asection *os = input_section->output_section;
   1156 
   1157 	  /* A partial link, so keep the relocs.  */
   1158 	  os->orelocation[os->reloc_count] = rel;
   1159 	  os->reloc_count++;
   1160 	}
   1161 
   1162       if (r != bfd_reloc_ok)
   1163 	{
   1164 	  switch (r)
   1165 	    {
   1166 	    case bfd_reloc_undefined:
   1167 	      (*link_info->callbacks->undefined_symbol)
   1168 		(link_info, bfd_asymbol_name (*rel->sym_ptr_ptr),
   1169 		 input_bfd, input_section, rel->address, true);
   1170 	      break;
   1171 	    case bfd_reloc_dangerous:
   1172 	      (*link_info->callbacks->reloc_dangerous)
   1173 		(link_info, err, input_bfd, input_section, rel->address);
   1174 	      break;
   1175 	    case bfd_reloc_overflow:
   1176 	      (*link_info->callbacks->reloc_overflow)
   1177 		(link_info, NULL, bfd_asymbol_name (*rel->sym_ptr_ptr),
   1178 		 rel->howto->name, rel->addend, input_bfd,
   1179 		 input_section, rel->address);
   1180 	      break;
   1181 	    case bfd_reloc_outofrange:
   1182 	      (*link_info->callbacks->einfo)
   1183 		/* xgettext:c-format */
   1184 		(_("%X%P: %pB(%pA): relocation \"%pR\" goes out of range\n"),
   1185 		 input_bfd, input_section, rel);
   1186 	      goto error_return;
   1187 	    case bfd_reloc_notsupported:
   1188 	      (*link_info->callbacks->einfo)
   1189 		/* xgettext:c-format */
   1190 		(_("%X%P: %pB(%pA): relocation \"%pR\" is not supported\n"),
   1191 		 input_bfd, input_section, rel);
   1192 	      goto error_return;
   1193 	    default:
   1194 	      (*link_info->callbacks->einfo)
   1195 		/* xgettext:c-format */
   1196 		(_("%X%P: %pB(%pA): relocation \"%pR\""
   1197 		   " returns an unrecognized value %x\n"),
   1198 		 input_bfd, input_section, rel, r);
   1199 	      break;
   1200 	    }
   1201 	}
   1202     }
   1203 
   1204   if (tos != 0)
   1205     goto error_return;
   1206 
   1207  successful_return:
   1208   free (reloc_vector);
   1209   return data;
   1210 
   1211  error_return:
   1212   free (reloc_vector);
   1213   if (orig_data == NULL)
   1214     free (data);
   1215   return NULL;
   1216 }
   1217 
   1218 /* Get the howto structure for a generic reloc type.  */
   1219 
   1220 static reloc_howto_type *
   1221 alpha_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   1222 			     bfd_reloc_code_real_type code)
   1223 {
   1224   int alpha_type;
   1225 
   1226   switch (code)
   1227     {
   1228     case BFD_RELOC_32:
   1229       alpha_type = ALPHA_R_REFLONG;
   1230       break;
   1231     case BFD_RELOC_64:
   1232     case BFD_RELOC_CTOR:
   1233       alpha_type = ALPHA_R_REFQUAD;
   1234       break;
   1235     case BFD_RELOC_GPREL32:
   1236       alpha_type = ALPHA_R_GPREL32;
   1237       break;
   1238     case BFD_RELOC_ALPHA_LITERAL:
   1239       alpha_type = ALPHA_R_LITERAL;
   1240       break;
   1241     case BFD_RELOC_ALPHA_LITUSE:
   1242       alpha_type = ALPHA_R_LITUSE;
   1243       break;
   1244     case BFD_RELOC_ALPHA_GPDISP_HI16:
   1245       alpha_type = ALPHA_R_GPDISP;
   1246       break;
   1247     case BFD_RELOC_ALPHA_GPDISP_LO16:
   1248       alpha_type = ALPHA_R_IGNORE;
   1249       break;
   1250     case BFD_RELOC_23_PCREL_S2:
   1251       alpha_type = ALPHA_R_BRADDR;
   1252       break;
   1253     case BFD_RELOC_ALPHA_HINT:
   1254       alpha_type = ALPHA_R_HINT;
   1255       break;
   1256     case BFD_RELOC_16_PCREL:
   1257       alpha_type = ALPHA_R_SREL16;
   1258       break;
   1259     case BFD_RELOC_32_PCREL:
   1260       alpha_type = ALPHA_R_SREL32;
   1261       break;
   1262     case BFD_RELOC_64_PCREL:
   1263       alpha_type = ALPHA_R_SREL64;
   1264       break;
   1265     default:
   1266       return (reloc_howto_type *) NULL;
   1267     }
   1268 
   1269   return &alpha_howto_table[alpha_type];
   1270 }
   1271 
   1272 static reloc_howto_type *
   1273 alpha_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   1274 			     const char *r_name)
   1275 {
   1276   unsigned int i;
   1277 
   1278   for (i = 0;
   1279        i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]);
   1280        i++)
   1281     if (alpha_howto_table[i].name != NULL
   1282 	&& strcasecmp (alpha_howto_table[i].name, r_name) == 0)
   1283       return &alpha_howto_table[i];
   1284 
   1285   return NULL;
   1286 }
   1287 
   1288 /* A helper routine for alpha_relocate_section which converts an
   1290    external reloc when generating relocatable output.  Returns the
   1291    relocation amount.  */
   1292 
   1293 static bfd_vma
   1294 alpha_convert_external_reloc (bfd *output_bfd ATTRIBUTE_UNUSED,
   1295 			      struct bfd_link_info *info,
   1296 			      bfd *input_bfd,
   1297 			      struct external_reloc *ext_rel,
   1298 			      struct ecoff_link_hash_entry *h)
   1299 {
   1300   unsigned long r_symndx;
   1301   bfd_vma relocation;
   1302 
   1303   BFD_ASSERT (bfd_link_relocatable (info));
   1304 
   1305   if (h->root.type == bfd_link_hash_defined
   1306       || h->root.type == bfd_link_hash_defweak)
   1307     {
   1308       asection *hsec;
   1309       const char *name;
   1310 
   1311       /* This symbol is defined in the output.  Convert the reloc from
   1312 	 being against the symbol to being against the section.  */
   1313 
   1314       /* Clear the r_extern bit.  */
   1315       ext_rel->r_bits[1] &=~ RELOC_BITS1_EXTERN_LITTLE;
   1316 
   1317       /* Compute a new r_symndx value.  */
   1318       hsec = h->root.u.def.section;
   1319       name = bfd_section_name (hsec->output_section);
   1320 
   1321       r_symndx = (unsigned long) -1;
   1322       switch (name[1])
   1323 	{
   1324 	case 'A':
   1325 	  if (strcmp (name, "*ABS*") == 0)
   1326 	    r_symndx = RELOC_SECTION_ABS;
   1327 	  break;
   1328 	case 'b':
   1329 	  if (strcmp (name, ".bss") == 0)
   1330 	    r_symndx = RELOC_SECTION_BSS;
   1331 	  break;
   1332 	case 'd':
   1333 	  if (strcmp (name, ".data") == 0)
   1334 	    r_symndx = RELOC_SECTION_DATA;
   1335 	  break;
   1336 	case 'f':
   1337 	  if (strcmp (name, ".fini") == 0)
   1338 	    r_symndx = RELOC_SECTION_FINI;
   1339 	  break;
   1340 	case 'i':
   1341 	  if (strcmp (name, ".init") == 0)
   1342 	    r_symndx = RELOC_SECTION_INIT;
   1343 	  break;
   1344 	case 'l':
   1345 	  if (strcmp (name, ".lita") == 0)
   1346 	    r_symndx = RELOC_SECTION_LITA;
   1347 	  else if (strcmp (name, ".lit8") == 0)
   1348 	    r_symndx = RELOC_SECTION_LIT8;
   1349 	  else if (strcmp (name, ".lit4") == 0)
   1350 	    r_symndx = RELOC_SECTION_LIT4;
   1351 	  break;
   1352 	case 'p':
   1353 	  if (strcmp (name, ".pdata") == 0)
   1354 	    r_symndx = RELOC_SECTION_PDATA;
   1355 	  break;
   1356 	case 'r':
   1357 	  if (strcmp (name, ".rdata") == 0)
   1358 	    r_symndx = RELOC_SECTION_RDATA;
   1359 	  else if (strcmp (name, ".rconst") == 0)
   1360 	    r_symndx = RELOC_SECTION_RCONST;
   1361 	  break;
   1362 	case 's':
   1363 	  if (strcmp (name, ".sdata") == 0)
   1364 	    r_symndx = RELOC_SECTION_SDATA;
   1365 	  else if (strcmp (name, ".sbss") == 0)
   1366 	    r_symndx = RELOC_SECTION_SBSS;
   1367 	  break;
   1368 	case 't':
   1369 	  if (strcmp (name, ".text") == 0)
   1370 	    r_symndx = RELOC_SECTION_TEXT;
   1371 	  break;
   1372 	case 'x':
   1373 	  if (strcmp (name, ".xdata") == 0)
   1374 	    r_symndx = RELOC_SECTION_XDATA;
   1375 	  break;
   1376 	}
   1377 
   1378       if (r_symndx == (unsigned long) -1)
   1379 	abort ();
   1380 
   1381       /* Add the section VMA and the symbol value.  */
   1382       relocation = (h->root.u.def.value
   1383 		    + hsec->output_section->vma
   1384 		    + hsec->output_offset);
   1385     }
   1386   else
   1387     {
   1388       /* Change the symndx value to the right one for
   1389 	 the output BFD.  */
   1390       r_symndx = h->indx;
   1391       if (r_symndx == (unsigned long) -1)
   1392 	{
   1393 	  /* Caller must give an error.  */
   1394 	  r_symndx = 0;
   1395 	}
   1396       relocation = 0;
   1397     }
   1398 
   1399   /* Write out the new r_symndx value.  */
   1400   H_PUT_32 (input_bfd, r_symndx, ext_rel->r_symndx);
   1401 
   1402   return relocation;
   1403 }
   1404 
   1405 /* Relocate a section while linking an Alpha ECOFF file.  This is
   1406    quite similar to get_relocated_section_contents.  Perhaps they
   1407    could be combined somehow.  */
   1408 
   1409 static bool
   1410 alpha_relocate_section (bfd *output_bfd,
   1411 			struct bfd_link_info *info,
   1412 			bfd *input_bfd,
   1413 			asection *input_section,
   1414 			bfd_byte *contents,
   1415 			void * external_relocs)
   1416 {
   1417   asection **symndx_to_section, *lita_sec;
   1418   struct ecoff_link_hash_entry **sym_hashes;
   1419   bfd_vma gp;
   1420   bool gp_undefined;
   1421   bfd_vma stack[RELOC_STACKSIZE];
   1422   int tos = 0;
   1423   struct external_reloc *ext_rel;
   1424   struct external_reloc *ext_rel_end;
   1425   bfd_size_type amt;
   1426   bool ret = true;
   1427 
   1428   /* We keep a table mapping the symndx found in an internal reloc to
   1429      the appropriate section.  This is faster than looking up the
   1430      section by name each time.  */
   1431   symndx_to_section = ecoff_data (input_bfd)->symndx_to_section;
   1432   if (symndx_to_section == (asection **) NULL)
   1433     {
   1434       amt = NUM_RELOC_SECTIONS * sizeof (asection *);
   1435       symndx_to_section = (asection **) bfd_alloc (input_bfd, amt);
   1436       if (!symndx_to_section)
   1437 	return false;
   1438 
   1439       symndx_to_section[RELOC_SECTION_NONE] = NULL;
   1440       symndx_to_section[RELOC_SECTION_TEXT] =
   1441 	bfd_get_section_by_name (input_bfd, ".text");
   1442       symndx_to_section[RELOC_SECTION_RDATA] =
   1443 	bfd_get_section_by_name (input_bfd, ".rdata");
   1444       symndx_to_section[RELOC_SECTION_DATA] =
   1445 	bfd_get_section_by_name (input_bfd, ".data");
   1446       symndx_to_section[RELOC_SECTION_SDATA] =
   1447 	bfd_get_section_by_name (input_bfd, ".sdata");
   1448       symndx_to_section[RELOC_SECTION_SBSS] =
   1449 	bfd_get_section_by_name (input_bfd, ".sbss");
   1450       symndx_to_section[RELOC_SECTION_BSS] =
   1451 	bfd_get_section_by_name (input_bfd, ".bss");
   1452       symndx_to_section[RELOC_SECTION_INIT] =
   1453 	bfd_get_section_by_name (input_bfd, ".init");
   1454       symndx_to_section[RELOC_SECTION_LIT8] =
   1455 	bfd_get_section_by_name (input_bfd, ".lit8");
   1456       symndx_to_section[RELOC_SECTION_LIT4] =
   1457 	bfd_get_section_by_name (input_bfd, ".lit4");
   1458       symndx_to_section[RELOC_SECTION_XDATA] =
   1459 	bfd_get_section_by_name (input_bfd, ".xdata");
   1460       symndx_to_section[RELOC_SECTION_PDATA] =
   1461 	bfd_get_section_by_name (input_bfd, ".pdata");
   1462       symndx_to_section[RELOC_SECTION_FINI] =
   1463 	bfd_get_section_by_name (input_bfd, ".fini");
   1464       symndx_to_section[RELOC_SECTION_LITA] =
   1465 	bfd_get_section_by_name (input_bfd, ".lita");
   1466       symndx_to_section[RELOC_SECTION_ABS] = bfd_abs_section_ptr;
   1467       symndx_to_section[RELOC_SECTION_RCONST] =
   1468 	bfd_get_section_by_name (input_bfd, ".rconst");
   1469 
   1470       ecoff_data (input_bfd)->symndx_to_section = symndx_to_section;
   1471     }
   1472 
   1473   sym_hashes = ecoff_data (input_bfd)->sym_hashes;
   1474 
   1475   /* On the Alpha, the .lita section must be addressable by the global
   1476      pointer.  To support large programs, we need to allow multiple
   1477      global pointers.  This works as long as each input .lita section
   1478      is <64KB big.  This implies that when producing relocatable
   1479      output, the .lita section is limited to 64KB. .  */
   1480 
   1481   lita_sec = symndx_to_section[RELOC_SECTION_LITA];
   1482   gp = _bfd_get_gp_value (output_bfd);
   1483   if (! bfd_link_relocatable (info) && lita_sec != NULL)
   1484     {
   1485       struct ecoff_section_tdata *lita_sec_data;
   1486 
   1487       /* Make sure we have a section data structure to which we can
   1488 	 hang on to the gp value we pick for the section.  */
   1489       lita_sec_data = ecoff_section_data (input_bfd, lita_sec);
   1490       if (lita_sec_data == NULL)
   1491 	{
   1492 	  amt = sizeof (struct ecoff_section_tdata);
   1493 	  lita_sec_data = ((struct ecoff_section_tdata *)
   1494 			   bfd_zalloc (input_bfd, amt));
   1495 	  lita_sec->used_by_bfd = lita_sec_data;
   1496 	}
   1497 
   1498       if (lita_sec_data->gp != 0)
   1499 	{
   1500 	  /* If we already assigned a gp to this section, we better
   1501 	     stick with that value.  */
   1502 	  gp = lita_sec_data->gp;
   1503 	}
   1504       else
   1505 	{
   1506 	  bfd_vma lita_vma;
   1507 	  bfd_size_type lita_size;
   1508 
   1509 	  lita_vma = lita_sec->output_offset + lita_sec->output_section->vma;
   1510 	  lita_size = lita_sec->size;
   1511 
   1512 	  if (gp == 0
   1513 	      || lita_vma <  gp - 0x8000
   1514 	      || lita_vma + lita_size >= gp + 0x8000)
   1515 	    {
   1516 	      /* Either gp hasn't been set at all or the current gp
   1517 		 cannot address this .lita section.  In both cases we
   1518 		 reset the gp to point into the "middle" of the
   1519 		 current input .lita section.  */
   1520 	      if (gp && !ecoff_data (output_bfd)->issued_multiple_gp_warning)
   1521 		{
   1522 		  (*info->callbacks->warning) (info,
   1523 					       _("using multiple gp values"),
   1524 					       (char *) NULL, output_bfd,
   1525 					       (asection *) NULL, (bfd_vma) 0);
   1526 		  ecoff_data (output_bfd)->issued_multiple_gp_warning = true;
   1527 		}
   1528 	      if (lita_vma < gp - 0x8000)
   1529 		gp = lita_vma + lita_size - 0x8000;
   1530 	      else
   1531 		gp = lita_vma + 0x8000;
   1532 
   1533 	    }
   1534 
   1535 	  lita_sec_data->gp = gp;
   1536 	}
   1537 
   1538       _bfd_set_gp_value (output_bfd, gp);
   1539     }
   1540 
   1541   gp_undefined = (gp == 0);
   1542 
   1543   BFD_ASSERT (bfd_header_little_endian (output_bfd));
   1544   BFD_ASSERT (bfd_header_little_endian (input_bfd));
   1545 
   1546   ext_rel = (struct external_reloc *) external_relocs;
   1547   ext_rel_end = ext_rel + input_section->reloc_count;
   1548   for (; ext_rel < ext_rel_end; ext_rel++)
   1549     {
   1550       bfd_vma r_vaddr;
   1551       unsigned long r_symndx;
   1552       int r_type;
   1553       int r_extern;
   1554       int r_offset;
   1555       int r_size;
   1556       bool relocatep;
   1557       bool adjust_addrp;
   1558       bool gp_usedp;
   1559       bfd_vma addend;
   1560       bfd_reloc_status_type r;
   1561 
   1562       r_vaddr = H_GET_64 (input_bfd, ext_rel->r_vaddr);
   1563       r_symndx = H_GET_32 (input_bfd, ext_rel->r_symndx);
   1564 
   1565       r_type = ((ext_rel->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
   1566 		>> RELOC_BITS0_TYPE_SH_LITTLE);
   1567       r_extern = (ext_rel->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
   1568       r_offset = ((ext_rel->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
   1569 		  >> RELOC_BITS1_OFFSET_SH_LITTLE);
   1570       /* Ignored the reserved bits.  */
   1571       r_size = ((ext_rel->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
   1572 		>> RELOC_BITS3_SIZE_SH_LITTLE);
   1573 
   1574       relocatep = false;
   1575       adjust_addrp = true;
   1576       gp_usedp = false;
   1577       addend = 0;
   1578       r = bfd_reloc_ok;
   1579 
   1580       switch (r_type)
   1581 	{
   1582 	default:
   1583 	  r = bfd_reloc_notsupported;
   1584 	  break;
   1585 
   1586 	case ALPHA_R_IGNORE:
   1587 	  /* This reloc appears after a GPDISP reloc.  On earlier
   1588 	     versions of OSF/1, It marked the position of the second
   1589 	     instruction to be altered by the GPDISP reloc, but it is
   1590 	     not otherwise used for anything.  For some reason, the
   1591 	     address of the relocation does not appear to include the
   1592 	     section VMA, unlike the other relocation types.  */
   1593 	  if (bfd_link_relocatable (info))
   1594 	    H_PUT_64 (input_bfd, input_section->output_offset + r_vaddr,
   1595 		      ext_rel->r_vaddr);
   1596 	  adjust_addrp = false;
   1597 	  break;
   1598 
   1599 	case ALPHA_R_REFLONG:
   1600 	case ALPHA_R_REFQUAD:
   1601 	case ALPHA_R_HINT:
   1602 	  relocatep = true;
   1603 	  break;
   1604 
   1605 	case ALPHA_R_BRADDR:
   1606 	case ALPHA_R_SREL16:
   1607 	case ALPHA_R_SREL32:
   1608 	case ALPHA_R_SREL64:
   1609 	  if (r_extern)
   1610 	    addend += - (r_vaddr + 4);
   1611 	  relocatep = true;
   1612 	  break;
   1613 
   1614 	case ALPHA_R_GPREL32:
   1615 	  /* This relocation is used in a switch table.  It is a 32
   1616 	     bit offset from the current GP value.  We must adjust it
   1617 	     by the different between the original GP value and the
   1618 	     current GP value.  */
   1619 	  relocatep = true;
   1620 	  addend = ecoff_data (input_bfd)->gp - gp;
   1621 	  gp_usedp = true;
   1622 	  break;
   1623 
   1624 	case ALPHA_R_LITERAL:
   1625 	  /* This is a reference to a literal value, generally
   1626 	     (always?) in the .lita section.  This is a 16 bit GP
   1627 	     relative relocation.  Sometimes the subsequent reloc is a
   1628 	     LITUSE reloc, which indicates how this reloc is used.
   1629 	     This sometimes permits rewriting the two instructions
   1630 	     referred to by the LITERAL and the LITUSE into different
   1631 	     instructions which do not refer to .lita.  This can save
   1632 	     a memory reference, and permits removing a value from
   1633 	     .lita thus saving GP relative space.
   1634 
   1635 	     We do not these optimizations.  To do them we would need
   1636 	     to arrange to link the .lita section first, so that by
   1637 	     the time we got here we would know the final values to
   1638 	     use.  This would not be particularly difficult, but it is
   1639 	     not currently implemented.  */
   1640 
   1641 	  relocatep = true;
   1642 	  addend = ecoff_data (input_bfd)->gp - gp;
   1643 	  gp_usedp = true;
   1644 	  break;
   1645 
   1646 	case ALPHA_R_LITUSE:
   1647 	  /* See ALPHA_R_LITERAL above for the uses of this reloc.  It
   1648 	     does not cause anything to happen, itself.  */
   1649 	  break;
   1650 
   1651 	case ALPHA_R_GPDISP:
   1652 	  /* This marks the ldah of an ldah/lda pair which loads the
   1653 	     gp register with the difference of the gp value and the
   1654 	     current location.  The second of the pair is r_symndx
   1655 	     bytes ahead.  It used to be marked with an ALPHA_R_IGNORE
   1656 	     reloc, but OSF/1 3.2 no longer does that.  */
   1657 	  if (r_vaddr >= input_section->vma
   1658 	      && r_vaddr - input_section->vma < input_section->size
   1659 	      && input_section->size - (r_vaddr - input_section->vma) > r_symndx
   1660 	      && (input_section->size - (r_vaddr - input_section->vma)
   1661 		  - r_symndx >= 4))
   1662 	    {
   1663 	      /* Get the two instructions.  */
   1664 	      bfd_byte *p = contents + r_vaddr - input_section->vma;
   1665 	      bfd_vma insn1 = bfd_get_32 (input_bfd, p);
   1666 	      bfd_vma insn2 = bfd_get_32 (input_bfd, p + r_symndx);
   1667 
   1668 	      BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
   1669 	      BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
   1670 
   1671 	      /* Get the existing addend.  We must account for the sign
   1672 		 extension done by lda and ldah.  */
   1673 	      addend = (((((insn1 & 0xffff) ^ 0x8000) - 0x8000) << 16)
   1674 			+ (((insn2 & 0xffff) ^ 0x8000) - 0x8000));
   1675 
   1676 	      /* The existing addend includes the difference between the
   1677 		 gp of the input BFD and the address in the input BFD.
   1678 		 We want to change this to the difference between the
   1679 		 final GP and the final address.  */
   1680 	      addend -= ecoff_data (input_bfd)->gp - input_section->vma;
   1681 	      addend += gp - (input_section->output_section->vma
   1682 			      + input_section->output_offset);
   1683 
   1684 	      /* Change the instructions, accounting for the sign
   1685 		 extension, and write them out.  */
   1686 	      insn1 = (insn1 & ~0xffff) | (((addend + 0x8000) >> 16) & 0xffff);
   1687 	      insn2 = (insn2 & ~0xffff) | (addend & 0xffff);
   1688 
   1689 	      bfd_put_32 (input_bfd, insn1, p);
   1690 	      bfd_put_32 (input_bfd, insn2, p + r_symndx);
   1691 
   1692 	      gp_usedp = true;
   1693 	    }
   1694 	  else
   1695 	    r = bfd_reloc_outofrange;
   1696 	  break;
   1697 
   1698 	case ALPHA_R_OP_PUSH:
   1699 	case ALPHA_R_OP_PSUB:
   1700 	case ALPHA_R_OP_PRSHIFT:
   1701 	  /* Manipulate values on the reloc evaluation stack.  The
   1702 	     r_vaddr field is not an address in input_section, it is
   1703 	     the current value (including any addend) of the object
   1704 	     being used.  */
   1705 	  if (! r_extern)
   1706 	    {
   1707 	      asection *s;
   1708 
   1709 	      s = symndx_to_section[r_symndx];
   1710 	      if (s == NULL)
   1711 		{
   1712 		  r = bfd_reloc_notsupported;
   1713 		  break;
   1714 		}
   1715 	      addend = s->output_section->vma + s->output_offset - s->vma;
   1716 	    }
   1717 	  else
   1718 	    {
   1719 	      struct ecoff_link_hash_entry *h;
   1720 
   1721 	      h = sym_hashes[r_symndx];
   1722 	      if (h == NULL)
   1723 		{
   1724 		  r = bfd_reloc_notsupported;
   1725 		  break;
   1726 		}
   1727 
   1728 	      if (! bfd_link_relocatable (info))
   1729 		{
   1730 		  if (h->root.type == bfd_link_hash_defined
   1731 		      || h->root.type == bfd_link_hash_defweak)
   1732 		    addend = (h->root.u.def.value
   1733 			      + h->root.u.def.section->output_section->vma
   1734 			      + h->root.u.def.section->output_offset);
   1735 		  else
   1736 		    {
   1737 		      /* Note that we pass the address as 0, since we
   1738 			 do not have a meaningful number for the
   1739 			 location within the section that is being
   1740 			 relocated.  */
   1741 		      (*info->callbacks->undefined_symbol)
   1742 			(info, h->root.root.string, input_bfd,
   1743 			 input_section, (bfd_vma) 0, true);
   1744 		      addend = 0;
   1745 		    }
   1746 		}
   1747 	      else
   1748 		{
   1749 		  if (h->root.type != bfd_link_hash_defined
   1750 		      && h->root.type != bfd_link_hash_defweak
   1751 		      && h->indx == -1)
   1752 		    {
   1753 		      /* This symbol is not being written out.  Pass
   1754 			 the address as 0, as with undefined_symbol,
   1755 			 above.  */
   1756 		      (*info->callbacks->unattached_reloc)
   1757 			(info, h->root.root.string,
   1758 			 input_bfd, input_section, (bfd_vma) 0);
   1759 		    }
   1760 
   1761 		  addend = alpha_convert_external_reloc (output_bfd, info,
   1762 							 input_bfd,
   1763 							 ext_rel, h);
   1764 		}
   1765 	    }
   1766 
   1767 	  addend += r_vaddr;
   1768 
   1769 	  if (bfd_link_relocatable (info))
   1770 	    {
   1771 	      /* Adjust r_vaddr by the addend.  */
   1772 	      H_PUT_64 (input_bfd, addend, ext_rel->r_vaddr);
   1773 	    }
   1774 	  else
   1775 	    {
   1776 	      switch (r_type)
   1777 		{
   1778 		case ALPHA_R_OP_PUSH:
   1779 		  if (tos >= RELOC_STACKSIZE)
   1780 		    {
   1781 		      r = bfd_reloc_notsupported;
   1782 		      break;
   1783 		    }
   1784 		  stack[tos++] = addend;
   1785 		  break;
   1786 
   1787 		case ALPHA_R_OP_PSUB:
   1788 		  if (tos == 0)
   1789 		    {
   1790 		      r = bfd_reloc_notsupported;
   1791 		      break;
   1792 		    }
   1793 		  stack[tos - 1] -= addend;
   1794 		  break;
   1795 
   1796 		case ALPHA_R_OP_PRSHIFT:
   1797 		  if (tos == 0)
   1798 		    {
   1799 		      r = bfd_reloc_notsupported;
   1800 		      break;
   1801 		    }
   1802 		  stack[tos - 1] >>= addend;
   1803 		  break;
   1804 		}
   1805 	    }
   1806 
   1807 	  adjust_addrp = false;
   1808 	  break;
   1809 
   1810 	case ALPHA_R_OP_STORE:
   1811 	  /* Store a value from the reloc stack into a bitfield.  If
   1812 	     we are generating relocatable output, all we do is
   1813 	     adjust the address of the reloc.  */
   1814 	  if (! bfd_link_relocatable (info))
   1815 	    {
   1816 	      if (tos == 0)
   1817 		r = bfd_reloc_notsupported;
   1818 	      else if (!write_bit_field (input_bfd, input_section,
   1819 					 contents,
   1820 					 r_vaddr - input_section->vma,
   1821 					 r_offset, r_size, stack[--tos]))
   1822 		r = bfd_reloc_outofrange;
   1823 	    }
   1824 	  break;
   1825 
   1826 	case ALPHA_R_GPVALUE:
   1827 	  /* I really don't know if this does the right thing.  */
   1828 	  gp = ecoff_data (input_bfd)->gp + r_symndx;
   1829 	  gp_undefined = false;
   1830 	  break;
   1831 	}
   1832 
   1833       if (relocatep && r == bfd_reloc_ok)
   1834 	{
   1835 	  reloc_howto_type *howto;
   1836 	  struct ecoff_link_hash_entry *h = NULL;
   1837 	  asection *s = NULL;
   1838 	  bfd_vma relocation;
   1839 
   1840 	  /* Perform a relocation.  */
   1841 
   1842 	  howto = &alpha_howto_table[r_type];
   1843 
   1844 	  if (r_extern)
   1845 	    {
   1846 	      h = sym_hashes[r_symndx];
   1847 	      /* If h is NULL, that means that there is a reloc
   1848 		 against an external symbol which we thought was just
   1849 		 a debugging symbol.  This should not happen.  */
   1850 	      if (h == NULL)
   1851 		r = bfd_reloc_notsupported;
   1852 	    }
   1853 	  else
   1854 	    {
   1855 	      if (r_symndx >= NUM_RELOC_SECTIONS)
   1856 		s = NULL;
   1857 	      else
   1858 		s = symndx_to_section[r_symndx];
   1859 
   1860 	      if (s == NULL)
   1861 		r = bfd_reloc_notsupported;
   1862 
   1863 	    }
   1864 
   1865 	  if (r != bfd_reloc_ok)
   1866 	    ;
   1867 	  else if (bfd_link_relocatable (info))
   1868 	    {
   1869 	      /* We are generating relocatable output, and must
   1870 		 convert the existing reloc.  */
   1871 	      if (r_extern)
   1872 		{
   1873 		  if (h->root.type != bfd_link_hash_defined
   1874 		      && h->root.type != bfd_link_hash_defweak
   1875 		      && h->indx == -1)
   1876 		    {
   1877 		      /* This symbol is not being written out.  */
   1878 		      (*info->callbacks->unattached_reloc)
   1879 			(info, h->root.root.string, input_bfd,
   1880 			 input_section, r_vaddr - input_section->vma);
   1881 		    }
   1882 
   1883 		  relocation = alpha_convert_external_reloc (output_bfd,
   1884 							     info,
   1885 							     input_bfd,
   1886 							     ext_rel,
   1887 							     h);
   1888 		}
   1889 	      else
   1890 		{
   1891 		  /* This is a relocation against a section.  Adjust
   1892 		     the value by the amount the section moved.  */
   1893 		  relocation = (s->output_section->vma
   1894 				+ s->output_offset
   1895 				- s->vma);
   1896 		}
   1897 
   1898 	      /* If this is PC relative, the existing object file
   1899 		 appears to already have the reloc worked out.  We
   1900 		 must subtract out the old value and add in the new
   1901 		 one.  */
   1902 	      if (howto->pc_relative)
   1903 		relocation -= (input_section->output_section->vma
   1904 			       + input_section->output_offset
   1905 			       - input_section->vma);
   1906 
   1907 	      /* Put in any addend.  */
   1908 	      relocation += addend;
   1909 
   1910 	      /* Adjust the contents.  */
   1911 	      r = _bfd_relocate_contents (howto, input_bfd, relocation,
   1912 					  (contents
   1913 					   + r_vaddr
   1914 					   - input_section->vma));
   1915 	    }
   1916 	  else
   1917 	    {
   1918 	      /* We are producing a final executable.  */
   1919 	      if (r_extern)
   1920 		{
   1921 		  /* This is a reloc against a symbol.  */
   1922 		  if (h->root.type == bfd_link_hash_defined
   1923 		      || h->root.type == bfd_link_hash_defweak)
   1924 		    {
   1925 		      asection *hsec;
   1926 
   1927 		      hsec = h->root.u.def.section;
   1928 		      relocation = (h->root.u.def.value
   1929 				    + hsec->output_section->vma
   1930 				    + hsec->output_offset);
   1931 		    }
   1932 		  else
   1933 		    r = bfd_reloc_undefined;
   1934 		}
   1935 	      else
   1936 		{
   1937 		  /* This is a reloc against a section.  */
   1938 		  relocation = (s->output_section->vma
   1939 				+ s->output_offset
   1940 				- s->vma);
   1941 
   1942 		  /* Adjust a PC relative relocation by removing the
   1943 		     reference to the original source section.  */
   1944 		  if (howto->pc_relative)
   1945 		    relocation += input_section->vma;
   1946 		}
   1947 
   1948 	      if (r == bfd_reloc_ok)
   1949 		r = _bfd_final_link_relocate (howto,
   1950 					      input_bfd,
   1951 					      input_section,
   1952 					      contents,
   1953 					      r_vaddr - input_section->vma,
   1954 					      relocation,
   1955 					      addend);
   1956 	    }
   1957 	}
   1958 
   1959       if (bfd_link_relocatable (info) && adjust_addrp)
   1960 	{
   1961 	  /* Change the address of the relocation.  */
   1962 	  H_PUT_64 (input_bfd,
   1963 		    (input_section->output_section->vma
   1964 		     + input_section->output_offset
   1965 		     - input_section->vma
   1966 		     + r_vaddr),
   1967 		    ext_rel->r_vaddr);
   1968 	}
   1969 
   1970       if (gp_usedp && gp_undefined)
   1971 	{
   1972 	  r = bfd_reloc_dangerous;
   1973 	  /* Only give the error once per link.  */
   1974 	  gp = 4;
   1975 	  _bfd_set_gp_value (output_bfd, gp);
   1976 	  gp_undefined = false;
   1977 	}
   1978 
   1979       if (r != bfd_reloc_ok)
   1980 	{
   1981 	  switch (r)
   1982 	    {
   1983 	    case bfd_reloc_overflow:
   1984 	      {
   1985 		const char *name;
   1986 
   1987 		if (r_extern)
   1988 		  name = sym_hashes[r_symndx]->root.root.string;
   1989 		else
   1990 		  name = bfd_section_name (symndx_to_section[r_symndx]);
   1991 		(*info->callbacks->reloc_overflow)
   1992 		  (info, NULL, name, alpha_howto_table[r_type].name,
   1993 		   (bfd_vma) 0, input_bfd, input_section,
   1994 		   r_vaddr - input_section->vma);
   1995 	      }
   1996 	      break;
   1997 	    case bfd_reloc_outofrange:
   1998 	      (*info->callbacks->einfo)
   1999 		/* xgettext:c-format */
   2000 		(_("%X%P: %pB(%pA): relocation out of range\n"),
   2001 		 input_bfd, input_section);
   2002 	      break;
   2003 	    case bfd_reloc_undefined:
   2004 	      (*info->callbacks->undefined_symbol)
   2005 		(info, sym_hashes[r_symndx]->root.root.string,
   2006 		 input_bfd, input_section,
   2007 		 r_vaddr - input_section->vma, true);
   2008 	      break;
   2009 	    case bfd_reloc_notsupported:
   2010 	      (*info->callbacks->einfo)
   2011 		/* xgettext:c-format */
   2012 		(_("%X%P: %pB(%pA): relocation is not supported\n"),
   2013 		 input_bfd, input_section);
   2014 	      break;
   2015 	    case bfd_reloc_dangerous:
   2016 	      (*info->callbacks->reloc_dangerous)
   2017 		(info, _("GP relative relocation used when GP not defined"),
   2018 		 input_bfd, input_section, r_vaddr - input_section->vma);
   2019 	      break;
   2020 	    default:
   2021 	      abort ();
   2022 	    }
   2023 	  ret = false;
   2024 	}
   2025     }
   2026 
   2027   if (tos != 0)
   2028     ret = false;
   2029 
   2030   return ret;
   2031 }
   2032 
   2033 /* Do final adjustments to the filehdr and the aouthdr.  This routine
   2035    sets the dynamic bits in the file header.  */
   2036 
   2037 static bool
   2038 alpha_adjust_headers (bfd *abfd,
   2039 		      struct internal_filehdr *fhdr,
   2040 		      struct internal_aouthdr *ahdr ATTRIBUTE_UNUSED)
   2041 {
   2042   if ((abfd->flags & (DYNAMIC | EXEC_P)) == (DYNAMIC | EXEC_P))
   2043     fhdr->f_flags |= F_ALPHA_CALL_SHARED;
   2044   else if ((abfd->flags & DYNAMIC) != 0)
   2045     fhdr->f_flags |= F_ALPHA_SHARABLE;
   2046   return true;
   2047 }
   2048 
   2049 /* Archive handling.  In OSF/1 (or Digital Unix) v3.2, Digital
   2051    introduced archive packing, in which the elements in an archive are
   2052    optionally compressed using a simple dictionary scheme.  We know
   2053    how to read such archives, but we don't write them.  */
   2054 
   2055 #define alpha_ecoff_slurp_armap _bfd_ecoff_slurp_armap
   2056 #define alpha_ecoff_slurp_extended_name_table \
   2057   _bfd_ecoff_slurp_extended_name_table
   2058 #define alpha_ecoff_construct_extended_name_table \
   2059   _bfd_ecoff_construct_extended_name_table
   2060 #define alpha_ecoff_truncate_arname _bfd_ecoff_truncate_arname
   2061 #define alpha_ecoff_write_armap _bfd_ecoff_write_armap
   2062 #define alpha_ecoff_write_ar_hdr _bfd_generic_write_ar_hdr
   2063 #define alpha_ecoff_generic_stat_arch_elt _bfd_ecoff_generic_stat_arch_elt
   2064 #define alpha_ecoff_update_armap_timestamp _bfd_ecoff_update_armap_timestamp
   2065 
   2066 /* A compressed file uses this instead of ARFMAG.  */
   2067 
   2068 #define ARFZMAG "Z\012"
   2069 
   2070 /* Read an archive header.  This is like the standard routine, but it
   2071    also accepts ARFZMAG.  */
   2072 
   2073 static void *
   2074 alpha_ecoff_read_ar_hdr (bfd *abfd)
   2075 {
   2076   struct areltdata *ret;
   2077   struct ar_hdr *h;
   2078 
   2079   ret = (struct areltdata *) _bfd_generic_read_ar_hdr_mag (abfd, ARFZMAG);
   2080   if (ret == NULL)
   2081     return NULL;
   2082 
   2083   h = (struct ar_hdr *) ret->arch_header;
   2084   if (strncmp (h->ar_fmag, ARFZMAG, 2) == 0)
   2085     {
   2086       bfd_byte ab[8];
   2087 
   2088       /* This is a compressed file.  We must set the size correctly.
   2089 	 The size is the eight bytes after the dummy file header.  */
   2090       if (bfd_seek (abfd, FILHSZ, SEEK_CUR) != 0
   2091 	  || bfd_read (ab, 8, abfd) != 8
   2092 	  || bfd_seek (abfd, -(FILHSZ + 8), SEEK_CUR) != 0)
   2093 	{
   2094 	  free (ret);
   2095 	  return NULL;
   2096 	}
   2097 
   2098       ret->parsed_size = H_GET_64 (abfd, ab);
   2099     }
   2100 
   2101   return ret;
   2102 }
   2103 
   2104 /* Get an archive element at a specified file position.  This is where
   2105    we uncompress the archive element if necessary.  */
   2106 
   2107 static bfd *
   2108 alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos,
   2109 				struct bfd_link_info *info)
   2110 {
   2111   bfd *nbfd = NULL;
   2112   struct areltdata *tdata;
   2113   struct ar_hdr *hdr;
   2114   bfd_byte ab[8];
   2115   bfd_size_type size;
   2116   bfd_byte *buf, *p;
   2117   struct bfd_in_memory *bim;
   2118   ufile_ptr filesize;
   2119 
   2120   buf = NULL;
   2121   nbfd = _bfd_get_elt_at_filepos (archive, filepos, info);
   2122   if (nbfd == NULL)
   2123     goto error_return;
   2124 
   2125   if ((nbfd->flags & BFD_IN_MEMORY) != 0)
   2126     {
   2127       /* We have already expanded this BFD.  */
   2128       return nbfd;
   2129     }
   2130 
   2131   tdata = (struct areltdata *) nbfd->arelt_data;
   2132   hdr = (struct ar_hdr *) tdata->arch_header;
   2133   if (strncmp (hdr->ar_fmag, ARFZMAG, 2) != 0)
   2134     return nbfd;
   2135 
   2136   /* We must uncompress this element.  We do this by copying it into a
   2137      memory buffer, and making bfd_read and bfd_seek use that buffer.
   2138      This can use a lot of memory, but it's simpler than getting a
   2139      temporary file, making that work with the file descriptor caching
   2140      code, and making sure that it is deleted at all appropriate
   2141      times.  It can be changed if it ever becomes important.  */
   2142 
   2143   /* The compressed file starts with a dummy ECOFF file header.  */
   2144   if (bfd_seek (nbfd, FILHSZ, SEEK_SET) != 0)
   2145     goto error_return;
   2146 
   2147   /* The next eight bytes are the real file size.  */
   2148   if (bfd_read (ab, 8, nbfd) != 8)
   2149     goto error_return;
   2150   size = H_GET_64 (nbfd, ab);
   2151 
   2152   /* The decompression algorithm will at most expand by eight times.  */
   2153   filesize = bfd_get_file_size (archive);
   2154   if (filesize != 0 && size / 8 > filesize)
   2155     {
   2156       bfd_set_error (bfd_error_malformed_archive);
   2157       goto error_return;
   2158     }
   2159 
   2160   if (size != 0)
   2161     {
   2162       bfd_size_type left;
   2163       bfd_byte dict[4096];
   2164       unsigned int h;
   2165       bfd_byte b;
   2166 
   2167       buf = (bfd_byte *) bfd_malloc (size);
   2168       if (buf == NULL)
   2169 	goto error_return;
   2170       p = buf;
   2171 
   2172       left = size;
   2173 
   2174       /* I don't know what the next eight bytes are for.  */
   2175       if (bfd_read (ab, 8, nbfd) != 8)
   2176 	goto error_return;
   2177 
   2178       /* This is the uncompression algorithm.  It's a simple
   2179 	 dictionary based scheme in which each character is predicted
   2180 	 by a hash of the previous three characters.  A control byte
   2181 	 indicates whether the character is predicted or whether it
   2182 	 appears in the input stream; each control byte manages the
   2183 	 next eight bytes in the output stream.  */
   2184       memset (dict, 0, sizeof dict);
   2185       h = 0;
   2186       while (bfd_read (&b, 1, nbfd) == 1)
   2187 	{
   2188 	  unsigned int i;
   2189 
   2190 	  for (i = 0; i < 8; i++, b >>= 1)
   2191 	    {
   2192 	      bfd_byte n;
   2193 
   2194 	      if ((b & 1) == 0)
   2195 		n = dict[h];
   2196 	      else
   2197 		{
   2198 		  if (bfd_read (&n, 1, nbfd) != 1)
   2199 		    goto error_return;
   2200 		  dict[h] = n;
   2201 		}
   2202 
   2203 	      *p++ = n;
   2204 
   2205 	      --left;
   2206 	      if (left == 0)
   2207 		break;
   2208 
   2209 	      h <<= 4;
   2210 	      h ^= n;
   2211 	      h &= sizeof dict - 1;
   2212 	    }
   2213 
   2214 	  if (left == 0)
   2215 	    break;
   2216 	}
   2217     }
   2218 
   2219   /* Now the uncompressed file contents are in buf.  */
   2220   bim = ((struct bfd_in_memory *)
   2221 	 bfd_malloc ((bfd_size_type) sizeof (struct bfd_in_memory)));
   2222   if (bim == NULL)
   2223     goto error_return;
   2224   bim->size = size;
   2225   bim->buffer = buf;
   2226 
   2227   nbfd->mtime_set = true;
   2228   nbfd->mtime = strtol (hdr->ar_date, (char **) NULL, 10);
   2229 
   2230   nbfd->flags |= BFD_IN_MEMORY;
   2231   nbfd->iostream = bim;
   2232   nbfd->iovec = &_bfd_memory_iovec;
   2233   nbfd->origin = 0;
   2234   nbfd->size = 0;
   2235   BFD_ASSERT (! nbfd->cacheable);
   2236 
   2237   return nbfd;
   2238 
   2239  error_return:
   2240   free (buf);
   2241   if (nbfd != NULL)
   2242     bfd_close (nbfd);
   2243   return NULL;
   2244 }
   2245 
   2246 /* Open the next archived file.  */
   2247 
   2248 static bfd *
   2249 alpha_ecoff_openr_next_archived_file (bfd *archive, bfd *last_file)
   2250 {
   2251   ufile_ptr filestart;
   2252 
   2253   if (last_file == NULL)
   2254     filestart = bfd_ardata (archive)->first_file_filepos;
   2255   else
   2256     {
   2257       struct areltdata *t;
   2258       struct ar_hdr *h;
   2259       bfd_size_type size;
   2260 
   2261       /* We can't use arelt_size here, because that uses parsed_size,
   2262 	 which is the uncompressed size.  We need the compressed size.  */
   2263       t = (struct areltdata *) last_file->arelt_data;
   2264       h = (struct ar_hdr *) t->arch_header;
   2265       size = strtol (h->ar_size, (char **) NULL, 10);
   2266 
   2267       /* Pad to an even boundary...
   2268 	 Note that last_file->origin can be odd in the case of
   2269 	 BSD-4.4-style element with a long odd size.  */
   2270       filestart = last_file->proxy_origin + size;
   2271       filestart += filestart % 2;
   2272       if (filestart < last_file->proxy_origin)
   2273 	{
   2274 	  /* Prevent looping.  See PR19256.  */
   2275 	  bfd_set_error (bfd_error_malformed_archive);
   2276 	  return NULL;
   2277 	}
   2278     }
   2279 
   2280   return alpha_ecoff_get_elt_at_filepos (archive, filestart, NULL);
   2281 }
   2282 
   2283 /* Open the archive file given an index into the armap.  */
   2284 
   2285 static bfd *
   2286 alpha_ecoff_get_elt_at_index (bfd *abfd, symindex sym_index)
   2287 {
   2288   carsym *entry;
   2289 
   2290   entry = bfd_ardata (abfd)->symdefs + sym_index;
   2291   return alpha_ecoff_get_elt_at_filepos (abfd, entry->file_offset,
   2292 					 NULL);
   2293 }
   2294 
   2295 static void
   2296 alpha_ecoff_swap_coff_aux_in (bfd *abfd ATTRIBUTE_UNUSED,
   2297 			      void *ext1 ATTRIBUTE_UNUSED,
   2298 			      int type ATTRIBUTE_UNUSED,
   2299 			      int in_class ATTRIBUTE_UNUSED,
   2300 			      int indx ATTRIBUTE_UNUSED,
   2301 			      int numaux ATTRIBUTE_UNUSED,
   2302 			      void *in1 ATTRIBUTE_UNUSED)
   2303 {
   2304 }
   2305 
   2306 static void
   2307 alpha_ecoff_swap_coff_sym_in (bfd *abfd ATTRIBUTE_UNUSED,
   2308 			      void *ext1 ATTRIBUTE_UNUSED,
   2309 			      void *in1 ATTRIBUTE_UNUSED)
   2310 {
   2311 }
   2312 
   2313 static void
   2314 alpha_ecoff_swap_coff_lineno_in (bfd *abfd ATTRIBUTE_UNUSED,
   2315 				 void *ext1 ATTRIBUTE_UNUSED,
   2316 				 void *in1 ATTRIBUTE_UNUSED)
   2317 {
   2318 }
   2319 
   2320 static unsigned int
   2321 alpha_ecoff_swap_coff_aux_out (bfd *abfd ATTRIBUTE_UNUSED,
   2322 			       void *inp ATTRIBUTE_UNUSED,
   2323 			       int type ATTRIBUTE_UNUSED,
   2324 			       int in_class ATTRIBUTE_UNUSED,
   2325 			       int indx ATTRIBUTE_UNUSED,
   2326 			       int numaux ATTRIBUTE_UNUSED,
   2327 			       void *extp ATTRIBUTE_UNUSED)
   2328 {
   2329   return 0;
   2330 }
   2331 
   2332 static unsigned int
   2333 alpha_ecoff_swap_coff_sym_out (bfd *abfd ATTRIBUTE_UNUSED,
   2334 			       void *inp ATTRIBUTE_UNUSED,
   2335 			       void *extp ATTRIBUTE_UNUSED)
   2336 {
   2337   return 0;
   2338 }
   2339 
   2340 static unsigned int
   2341 alpha_ecoff_swap_coff_lineno_out (bfd *abfd ATTRIBUTE_UNUSED,
   2342 				  void *inp ATTRIBUTE_UNUSED,
   2343 				  void *extp ATTRIBUTE_UNUSED)
   2344 {
   2345   return 0;
   2346 }
   2347 
   2348 static unsigned int
   2349 alpha_ecoff_swap_coff_reloc_out (bfd *abfd ATTRIBUTE_UNUSED,
   2350 				 void *inp ATTRIBUTE_UNUSED,
   2351 				 void *extp ATTRIBUTE_UNUSED)
   2352 {
   2353   return 0;
   2354 }
   2355 
   2356 /* This is the ECOFF backend structure.  The backend field of the
   2358    target vector points to this.  */
   2359 
   2360 static const struct ecoff_backend_data alpha_ecoff_backend_data =
   2361 {
   2362   /* COFF backend structure.  */
   2363   {
   2364     alpha_ecoff_swap_coff_aux_in, alpha_ecoff_swap_coff_sym_in,
   2365     alpha_ecoff_swap_coff_lineno_in, alpha_ecoff_swap_coff_aux_out,
   2366     alpha_ecoff_swap_coff_sym_out, alpha_ecoff_swap_coff_lineno_out,
   2367     alpha_ecoff_swap_coff_reloc_out,
   2368     alpha_ecoff_swap_filehdr_out, alpha_ecoff_swap_aouthdr_out,
   2369     alpha_ecoff_swap_scnhdr_out,
   2370     FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, 0, FILNMLEN, true,
   2371     ECOFF_NO_LONG_SECTION_NAMES, 4, false, 2, 32768,
   2372     alpha_ecoff_swap_filehdr_in, alpha_ecoff_swap_aouthdr_in,
   2373     alpha_ecoff_swap_scnhdr_in, NULL,
   2374     alpha_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook,
   2375     alpha_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags,
   2376     _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table,
   2377     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
   2378     NULL, NULL, NULL,
   2379   },
   2380   /* Supported architecture.  */
   2381   bfd_arch_alpha,
   2382   /* Initial portion of armap string.  */
   2383   "________64",
   2384   /* The page boundary used to align sections in a demand-paged
   2385      executable file.  E.g., 0x1000.  */
   2386   0x2000,
   2387   /* TRUE if the .rdata section is part of the text segment, as on the
   2388      Alpha.  FALSE if .rdata is part of the data segment, as on the
   2389      MIPS.  */
   2390   true,
   2391   /* Bitsize of constructor entries.  */
   2392   64,
   2393   /* Reloc to use for constructor entries.  */
   2394   &alpha_howto_table[ALPHA_R_REFQUAD],
   2395   {
   2396     /* Symbol table magic number.  */
   2397     magicSym2,
   2398     /* Alignment of debugging information.  E.g., 4.  */
   2399     8,
   2400     /* Sizes of external symbolic information.  */
   2401     sizeof (struct hdr_ext),
   2402     sizeof (struct dnr_ext),
   2403     sizeof (struct pdr_ext),
   2404     sizeof (struct sym_ext),
   2405     sizeof (struct opt_ext),
   2406     sizeof (struct fdr_ext),
   2407     sizeof (struct rfd_ext),
   2408     sizeof (struct ext_ext),
   2409     /* Functions to swap in external symbolic data.  */
   2410     ecoff_swap_hdr_in,
   2411     ecoff_swap_dnr_in,
   2412     ecoff_swap_pdr_in,
   2413     ecoff_swap_sym_in,
   2414     ecoff_swap_opt_in,
   2415     ecoff_swap_fdr_in,
   2416     ecoff_swap_rfd_in,
   2417     ecoff_swap_ext_in,
   2418     _bfd_ecoff_swap_tir_in,
   2419     _bfd_ecoff_swap_rndx_in,
   2420     /* Functions to swap out external symbolic data.  */
   2421     ecoff_swap_hdr_out,
   2422     ecoff_swap_dnr_out,
   2423     ecoff_swap_pdr_out,
   2424     ecoff_swap_sym_out,
   2425     ecoff_swap_opt_out,
   2426     ecoff_swap_fdr_out,
   2427     ecoff_swap_rfd_out,
   2428     ecoff_swap_ext_out,
   2429     _bfd_ecoff_swap_tir_out,
   2430     _bfd_ecoff_swap_rndx_out,
   2431     /* Function to read in symbolic data.  */
   2432     _bfd_ecoff_slurp_symbolic_info
   2433   },
   2434   /* External reloc size.  */
   2435   RELSZ,
   2436   /* Reloc swapping functions.  */
   2437   alpha_ecoff_swap_reloc_in,
   2438   alpha_ecoff_swap_reloc_out,
   2439   /* Backend reloc tweaking.  */
   2440   alpha_adjust_reloc_in,
   2441   alpha_adjust_reloc_out,
   2442   /* Relocate section contents while linking.  */
   2443   alpha_relocate_section,
   2444   /* Do final adjustments to filehdr and aouthdr.  */
   2445   alpha_adjust_headers,
   2446   /* Read an element from an archive at a given file position.  */
   2447   alpha_ecoff_get_elt_at_filepos
   2448 };
   2449 
   2450 /* Looking up a reloc type is Alpha specific.  */
   2451 #define _bfd_ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup
   2452 #define _bfd_ecoff_bfd_reloc_name_lookup \
   2453   alpha_bfd_reloc_name_lookup
   2454 
   2455 /* So is getting relocated section contents.  */
   2456 #define _bfd_ecoff_bfd_get_relocated_section_contents \
   2457   alpha_ecoff_get_relocated_section_contents
   2458 
   2459 /* Input section flag lookup is generic.  */
   2460 #define _bfd_ecoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
   2461 
   2462 /* Relaxing sections is generic.  */
   2463 #define _bfd_ecoff_bfd_relax_section bfd_generic_relax_section
   2464 #define _bfd_ecoff_bfd_gc_sections bfd_generic_gc_sections
   2465 #define _bfd_ecoff_bfd_merge_sections bfd_generic_merge_sections
   2466 #define _bfd_ecoff_bfd_is_group_section bfd_generic_is_group_section
   2467 #define _bfd_ecoff_bfd_group_name bfd_generic_group_name
   2468 #define _bfd_ecoff_bfd_discard_group bfd_generic_discard_group
   2469 #define _bfd_ecoff_section_already_linked \
   2470   _bfd_coff_section_already_linked
   2471 #define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol
   2472 #define _bfd_ecoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
   2473 #define _bfd_ecoff_bfd_define_start_stop    bfd_generic_define_start_stop
   2474 #define _bfd_ecoff_bfd_link_check_relocs    _bfd_generic_link_check_relocs
   2475 
   2476 /* Installing internal relocations in a section is also generic.  */
   2477 #define _bfd_ecoff_set_reloc _bfd_generic_set_reloc
   2478 
   2479 const bfd_target alpha_ecoff_le_vec =
   2480 {
   2481   "ecoff-littlealpha",		/* name */
   2482   bfd_target_ecoff_flavour,
   2483   BFD_ENDIAN_LITTLE,		/* data byte order is little */
   2484   BFD_ENDIAN_LITTLE,		/* header byte order is little */
   2485 
   2486   (HAS_RELOC | EXEC_P		/* object flags */
   2487    | HAS_LINENO | HAS_DEBUG
   2488    | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
   2489 
   2490   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE
   2491    | SEC_DATA | SEC_SMALL_DATA),
   2492   0,				/* leading underscore */
   2493   ' ',				/* ar_pad_char */
   2494   15,				/* ar_max_namelen */
   2495   0,				/* match priority.  */
   2496   TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
   2497   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   2498      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   2499      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
   2500   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   2501      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   2502      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
   2503 
   2504   {				/* bfd_check_format */
   2505     _bfd_dummy_target,
   2506     alpha_ecoff_object_p,
   2507     bfd_generic_archive_p,
   2508     _bfd_dummy_target
   2509   },
   2510   {				/* bfd_set_format */
   2511     _bfd_bool_bfd_false_error,
   2512     _bfd_ecoff_mkobject,
   2513     _bfd_generic_mkarchive,
   2514     _bfd_bool_bfd_false_error
   2515   },
   2516   {				/* bfd_write_contents */
   2517     _bfd_bool_bfd_false_error,
   2518     _bfd_ecoff_write_object_contents,
   2519     _bfd_write_archive_contents,
   2520     _bfd_bool_bfd_false_error
   2521   },
   2522 
   2523   BFD_JUMP_TABLE_GENERIC (_bfd_ecoff),
   2524   BFD_JUMP_TABLE_COPY (_bfd_ecoff),
   2525   BFD_JUMP_TABLE_CORE (_bfd_nocore),
   2526   BFD_JUMP_TABLE_ARCHIVE (alpha_ecoff),
   2527   BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff),
   2528   BFD_JUMP_TABLE_RELOCS (_bfd_ecoff),
   2529   BFD_JUMP_TABLE_WRITE (_bfd_ecoff),
   2530   BFD_JUMP_TABLE_LINK (_bfd_ecoff),
   2531   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
   2532 
   2533   NULL,
   2534 
   2535   &alpha_ecoff_backend_data
   2536 };
   2537