home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gdb-4.12.tar.gz / gdb-4.12.tar / gdb-4.12 / bfd / coff-alpha.c < prev    next >
C/C++ Source or Header  |  1994-02-03  |  56KB  |  1,865 lines

  1. /* BFD back-end for ALPHA Extended-Coff files.
  2.    Copyright 1993 Free Software Foundation, Inc.
  3.    Modified from coff-mips.c by Steve Chamberlain <sac@cygnus.com> and
  4.    Ian Lance Taylor <ian@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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "bfd.h"
  23. #include "sysdep.h"
  24. #include "bfdlink.h"
  25. #include "libbfd.h"
  26. #include "coff/internal.h"
  27. #include "coff/sym.h"
  28. #include "coff/symconst.h"
  29. #include "coff/ecoff.h"
  30. #include "coff/alpha.h"
  31. #include "libcoff.h"
  32. #include "libecoff.h"
  33.  
  34. /* Prototypes for static functions.  */
  35.  
  36. static boolean alpha_ecoff_bad_format_hook PARAMS ((bfd *abfd, PTR filehdr));
  37. static void alpha_ecoff_swap_reloc_in PARAMS ((bfd *, PTR,
  38.                           struct internal_reloc *));
  39. static void alpha_ecoff_swap_reloc_out PARAMS ((bfd *,
  40.                            const struct internal_reloc *,
  41.                            PTR));
  42. static void alpha_adjust_reloc_in PARAMS ((bfd *,
  43.                        const struct internal_reloc *,
  44.                        arelent *));
  45. static void alpha_adjust_reloc_out PARAMS ((bfd *, const arelent *,
  46.                         struct internal_reloc *));
  47. static bfd_byte *alpha_ecoff_get_relocated_section_contents
  48.   PARAMS ((bfd *abfd, struct bfd_link_info *, struct bfd_link_order *,
  49.        bfd_byte *data, boolean relocateable, asymbol **symbols));
  50. static bfd_vma alpha_convert_external_reloc
  51.   PARAMS ((bfd *, struct bfd_link_info *, bfd *, struct external_reloc *,
  52.        struct ecoff_link_hash_entry *));
  53. static boolean alpha_relocate_section PARAMS ((bfd *, struct bfd_link_info *,
  54.                            bfd *, asection *,
  55.                            bfd_byte *, PTR));
  56.  
  57. /* ECOFF has COFF sections, but the debugging information is stored in
  58.    a completely different format.  ECOFF targets use some of the
  59.    swapping routines from coffswap.h, and some of the generic COFF
  60.    routines in coffgen.c, but, unlike the real COFF targets, do not
  61.    use coffcode.h itself.
  62.  
  63.    Get the generic COFF swapping routines, except for the reloc,
  64.    symbol, and lineno ones.  Give them ecoff names.  Define some
  65.    accessor macros for the large sizes used for Alpha ECOFF.  */
  66.  
  67. #define GET_FILEHDR_SYMPTR bfd_h_get_64
  68. #define PUT_FILEHDR_SYMPTR bfd_h_put_64
  69. #define GET_AOUTHDR_TSIZE bfd_h_get_64
  70. #define PUT_AOUTHDR_TSIZE bfd_h_put_64
  71. #define GET_AOUTHDR_DSIZE bfd_h_get_64
  72. #define PUT_AOUTHDR_DSIZE bfd_h_put_64
  73. #define GET_AOUTHDR_BSIZE bfd_h_get_64
  74. #define PUT_AOUTHDR_BSIZE bfd_h_put_64
  75. #define GET_AOUTHDR_ENTRY bfd_h_get_64
  76. #define PUT_AOUTHDR_ENTRY bfd_h_put_64
  77. #define GET_AOUTHDR_TEXT_START bfd_h_get_64
  78. #define PUT_AOUTHDR_TEXT_START bfd_h_put_64
  79. #define GET_AOUTHDR_DATA_START bfd_h_get_64
  80. #define PUT_AOUTHDR_DATA_START bfd_h_put_64
  81. #define GET_SCNHDR_PADDR bfd_h_get_64
  82. #define PUT_SCNHDR_PADDR bfd_h_put_64
  83. #define GET_SCNHDR_VADDR bfd_h_get_64
  84. #define PUT_SCNHDR_VADDR bfd_h_put_64
  85. #define GET_SCNHDR_SIZE bfd_h_get_64
  86. #define PUT_SCNHDR_SIZE bfd_h_put_64
  87. #define GET_SCNHDR_SCNPTR bfd_h_get_64
  88. #define PUT_SCNHDR_SCNPTR bfd_h_put_64
  89. #define GET_SCNHDR_RELPTR bfd_h_get_64
  90. #define PUT_SCNHDR_RELPTR bfd_h_put_64
  91. #define GET_SCNHDR_LNNOPTR bfd_h_get_64
  92. #define PUT_SCNHDR_LNNOPTR bfd_h_put_64
  93.  
  94. #define ALPHAECOFF
  95.  
  96. #define NO_COFF_RELOCS
  97. #define NO_COFF_SYMBOLS
  98. #define NO_COFF_LINENOS
  99. #define coff_swap_filehdr_in alpha_ecoff_swap_filehdr_in
  100. #define coff_swap_filehdr_out alpha_ecoff_swap_filehdr_out
  101. #define coff_swap_aouthdr_in alpha_ecoff_swap_aouthdr_in
  102. #define coff_swap_aouthdr_out alpha_ecoff_swap_aouthdr_out
  103. #define coff_swap_scnhdr_in alpha_ecoff_swap_scnhdr_in
  104. #define coff_swap_scnhdr_out alpha_ecoff_swap_scnhdr_out
  105. #include "coffswap.h"
  106.  
  107. /* Get the ECOFF swapping routines.  */
  108. #define ECOFF_64
  109. #include "ecoffswap.h"
  110.  
  111. /* How to process the various reloc types.  */
  112.  
  113. static reloc_howto_type alpha_howto_table[] =
  114. {
  115.   /* Reloc type 0 is ignored by itself.  However, it appears after a
  116.      GPDISP reloc to identify the location where the low order 16 bits
  117.      of the gp register are loaded.  */
  118.   HOWTO (ALPHA_R_IGNORE,    /* type */
  119.      0,            /* rightshift */
  120.      0,            /* size (0 = byte, 1 = short, 2 = long) */
  121.      8,            /* bitsize */
  122.      false,            /* pc_relative */
  123.      0,            /* bitpos */
  124.      complain_overflow_dont, /* complain_on_overflow */
  125.      0,            /* special_function */
  126.      "IGNORE",        /* name */
  127.      false,            /* partial_inplace */
  128.      0,            /* src_mask */
  129.      0,            /* dst_mask */
  130.      false),        /* pcrel_offset */
  131.  
  132.   /* A 32 bit reference to a symbol.  */
  133.   HOWTO (ALPHA_R_REFLONG,    /* type */
  134.      0,            /* rightshift */
  135.      2,            /* size (0 = byte, 1 = short, 2 = long) */
  136.      32,            /* bitsize */
  137.      false,            /* pc_relative */
  138.      0,            /* bitpos */
  139.      complain_overflow_bitfield, /* complain_on_overflow */
  140.      0,            /* special_function */
  141.      "REFLONG",        /* name */
  142.      true,            /* partial_inplace */
  143.      0xffffffff,        /* src_mask */
  144.      0xffffffff,        /* dst_mask */
  145.      false),        /* pcrel_offset */
  146.  
  147.   /* A 64 bit reference to a symbol.  */
  148.   HOWTO (ALPHA_R_REFQUAD,    /* type */
  149.      0,            /* rightshift */
  150.      4,            /* size (0 = byte, 1 = short, 2 = long) */
  151.      64,            /* bitsize */
  152.      false,            /* pc_relative */
  153.      0,            /* bitpos */
  154.      complain_overflow_bitfield, /* complain_on_overflow */
  155.      0,            /* special_function */
  156.      "REFQUAD",        /* name */
  157.      true,            /* partial_inplace */
  158.      0xffffffffffffffff,    /* src_mask */
  159.      0xffffffffffffffff,    /* dst_mask */
  160.      false),        /* pcrel_offset */
  161.  
  162.   /* A 32 bit GP relative offset.  This is just like REFLONG except
  163.      that when the value is used the value of the gp register will be
  164.      added in.  */
  165.   HOWTO (ALPHA_R_GPREL32,    /* type */
  166.      0,            /* rightshift */
  167.      2,            /* size (0 = byte, 1 = short, 2 = long) */
  168.      32,            /* bitsize */
  169.      false,            /* pc_relative */
  170.      0,            /* bitpos */
  171.      complain_overflow_bitfield, /* complain_on_overflow */
  172.      0,            /* special_function */
  173.      "GPREL32",        /* name */
  174.      true,            /* partial_inplace */
  175.      0xffffffff,        /* src_mask */
  176.      0xffffffff,        /* dst_mask */
  177.      false),        /* pcrel_offset */
  178.  
  179.   /* Used for an instruction that refers to memory off the GP
  180.      register.  The offset is 16 bits of the 32 bit instruction.  This
  181.      reloc always seems to be against the .lita section.  */
  182.   HOWTO (ALPHA_R_LITERAL,    /* type */
  183.      0,            /* rightshift */
  184.      2,            /* size (0 = byte, 1 = short, 2 = long) */
  185.      16,            /* bitsize */
  186.      false,            /* pc_relative */
  187.      0,            /* bitpos */
  188.      complain_overflow_signed, /* complain_on_overflow */
  189.      0,            /* special_function */
  190.      "LITERAL",        /* name */
  191.      true,            /* partial_inplace */
  192.      0xffff,        /* src_mask */
  193.      0xffff,        /* dst_mask */
  194.      false),        /* pcrel_offset */
  195.  
  196.   /* This reloc only appears immediately following a LITERAL reloc.
  197.      It identifies a use of the literal.  It seems that the linker can
  198.      use this to eliminate a portion of the .lita section.  The symbol
  199.      index is special: 1 means the literal address is in the base
  200.      register of a memory format instruction; 2 means the literal
  201.      address is in the byte offset register of a byte-manipulation
  202.      instruction; 3 means the literal address is in the target
  203.      register of a jsr instruction.  This does not actually do any
  204.      relocation.  */
  205.   HOWTO (ALPHA_R_LITUSE,    /* type */
  206.      0,            /* rightshift */
  207.      2,            /* size (0 = byte, 1 = short, 2 = long) */
  208.      32,            /* bitsize */
  209.      false,            /* pc_relative */
  210.      0,            /* bitpos */
  211.      complain_overflow_dont, /* complain_on_overflow */
  212.      0,            /* special_function */
  213.      "LITUSE",        /* name */
  214.      false,            /* partial_inplace */
  215.      0,            /* src_mask */
  216.      0,            /* dst_mask */
  217.      false),        /* pcrel_offset */
  218.  
  219.   /* Load the gp register.  This is always used for a ldah instruction
  220.      which loads the upper 16 bits of the gp register.  The next reloc
  221.      will be an IGNORE reloc which identifies the location of the lda
  222.      instruction which loads the lower 16 bits.  The symbol index of
  223.      the GPDISP instruction appears to actually be the number of bytes
  224.      between the ldah and lda instructions.  This gives two different
  225.      ways to determine where the lda instruction is; I don't know why
  226.      both are used.  The value to use for the relocation is the
  227.      difference between the GP value and the current location; the
  228.      load will always be done against a register holding the current
  229.      address.  */
  230.   HOWTO (ALPHA_R_GPDISP,    /* type */
  231.      16,            /* rightshift */
  232.      2,            /* size (0 = byte, 1 = short, 2 = long) */
  233.      16,            /* bitsize */
  234.      true,            /* pc_relative */
  235.      0,            /* bitpos */
  236.      complain_overflow_dont, /* complain_on_overflow */
  237.      0,            /* special_function */
  238.      "GPDISP",        /* name */
  239.      true,            /* partial_inplace */
  240.      0xffff,        /* src_mask */
  241.      0xffff,        /* dst_mask */
  242.      true),            /* pcrel_offset */
  243.  
  244.   /* A 21 bit branch.  The native assembler generates these for
  245.      branches within the text segment, and also fills in the PC
  246.      relative offset in the instruction.  */
  247.   HOWTO (ALPHA_R_BRADDR,    /* type */
  248.      2,            /* rightshift */
  249.      2,            /* size (0 = byte, 1 = short, 2 = long) */
  250.      21,            /* bitsize */
  251.      true,            /* pc_relative */
  252.      0,            /* bitpos */
  253.      complain_overflow_signed, /* complain_on_overflow */
  254.      0,            /* special_function */
  255.      "BRADDR",        /* name */
  256.      true,            /* partial_inplace */
  257.      0x1fffff,        /* src_mask */
  258.      0x1fffff,        /* dst_mask */
  259.      false),        /* pcrel_offset */
  260.  
  261.   /* A hint for a jump to a register.  */
  262.   HOWTO (ALPHA_R_HINT,        /* type */
  263.      2,            /* rightshift */
  264.      2,            /* size (0 = byte, 1 = short, 2 = long) */
  265.      14,            /* bitsize */
  266.      false,            /* pc_relative */
  267.      0,            /* bitpos */
  268.      complain_overflow_dont, /* complain_on_overflow */
  269.      0,            /* special_function */
  270.      "HINT",        /* name */
  271.      true,            /* partial_inplace */
  272.      0x3fff,        /* src_mask */
  273.      0x3fff,        /* dst_mask */
  274.      false),        /* pcrel_offset */
  275.  
  276.   /* 16 bit PC relative offset.  */
  277.   HOWTO (ALPHA_R_SREL16,    /* type */
  278.      0,            /* rightshift */
  279.      1,            /* size (0 = byte, 1 = short, 2 = long) */
  280.      16,            /* bitsize */
  281.      true,            /* pc_relative */
  282.      0,            /* bitpos */
  283.      complain_overflow_signed, /* complain_on_overflow */
  284.      0,            /* special_function */
  285.      "SREL16",        /* name */
  286.      true,            /* partial_inplace */
  287.      0xffff,        /* src_mask */
  288.      0xffff,        /* dst_mask */
  289.      false),        /* pcrel_offset */
  290.  
  291.   /* 32 bit PC relative offset.  */
  292.   HOWTO (ALPHA_R_SREL32,    /* type */
  293.      0,            /* rightshift */
  294.      2,            /* size (0 = byte, 1 = short, 2 = long) */
  295.      32,            /* bitsize */
  296.      true,            /* pc_relative */
  297.      0,            /* bitpos */
  298.      complain_overflow_signed, /* complain_on_overflow */
  299.      0,            /* special_function */
  300.      "SREL32",        /* name */
  301.      true,            /* partial_inplace */
  302.      0xffffffff,        /* src_mask */
  303.      0xffffffff,        /* dst_mask */
  304.      false),        /* pcrel_offset */
  305.  
  306.   /* A 64 bit PC relative offset.  */
  307.   HOWTO (ALPHA_R_SREL64,    /* type */
  308.      0,            /* rightshift */
  309.      4,            /* size (0 = byte, 1 = short, 2 = long) */
  310.      64,            /* bitsize */
  311.      true,            /* pc_relative */
  312.      0,            /* bitpos */
  313.      complain_overflow_signed, /* complain_on_overflow */
  314.      0,            /* special_function */
  315.      "SREL64",        /* name */
  316.      true,            /* partial_inplace */
  317.      0xffffffffffffffff,    /* src_mask */
  318.      0xffffffffffffffff,    /* dst_mask */
  319.      false),        /* pcrel_offset */
  320.  
  321.   /* Push a value on the reloc evaluation stack.  */
  322.   HOWTO (ALPHA_R_OP_PUSH,    /* type */
  323.      0,            /* rightshift */
  324.      0,            /* size (0 = byte, 1 = short, 2 = long) */
  325.      0,            /* bitsize */
  326.      false,            /* pc_relative */
  327.      0,            /* bitpos */
  328.      complain_overflow_dont, /* complain_on_overflow */
  329.      0,            /* special_function */
  330.      "OP_PUSH",        /* name */
  331.      false,            /* partial_inplace */
  332.      0,            /* src_mask */
  333.      0,            /* dst_mask */
  334.      false),        /* pcrel_offset */
  335.  
  336.   /* Store the value from the stack at the given address.  Store it in
  337.      a bitfield of size r_size starting at bit position r_offset.  */
  338.   HOWTO (ALPHA_R_OP_STORE,    /* type */
  339.      0,            /* rightshift */
  340.      4,            /* size (0 = byte, 1 = short, 2 = long) */
  341.      64,            /* bitsize */
  342.      false,            /* pc_relative */
  343.      0,            /* bitpos */
  344.      complain_overflow_dont, /* complain_on_overflow */
  345.      0,            /* special_function */
  346.      "OP_STORE",        /* name */
  347.      false,            /* partial_inplace */
  348.      0,            /* src_mask */
  349.      0xffffffffffffffff,    /* dst_mask */
  350.      false),        /* pcrel_offset */
  351.  
  352.   /* Subtract the reloc address from the value on the top of the
  353.      relocation stack.  */
  354.   HOWTO (ALPHA_R_OP_PSUB,    /* type */
  355.      0,            /* rightshift */
  356.      0,            /* size (0 = byte, 1 = short, 2 = long) */
  357.      0,            /* bitsize */
  358.      false,            /* pc_relative */
  359.      0,            /* bitpos */
  360.      complain_overflow_dont, /* complain_on_overflow */
  361.      0,            /* special_function */
  362.      "OP_PSUB",        /* name */
  363.      false,            /* partial_inplace */
  364.      0,            /* src_mask */
  365.      0,            /* dst_mask */
  366.      false),        /* pcrel_offset */
  367.  
  368.   /* Shift the value on the top of the relocation stack right by the
  369.      given value.  */
  370.   HOWTO (ALPHA_R_OP_PRSHIFT,    /* type */
  371.      0,            /* rightshift */
  372.      0,            /* size (0 = byte, 1 = short, 2 = long) */
  373.      0,            /* bitsize */
  374.      false,            /* pc_relative */
  375.      0,            /* bitpos */
  376.      complain_overflow_dont, /* complain_on_overflow */
  377.      0,             /* special_function */
  378.      "OP_PRSHIFT",        /* name */
  379.      false,            /* partial_inplace */
  380.      0,            /* src_mask */
  381.      0,            /* dst_mask */
  382.      false),        /* pcrel_offset */
  383.  
  384.   /* Adjust the GP value for a new range in the object file.  */
  385.   HOWTO (ALPHA_R_GPVALUE,    /* type */
  386.      0,            /* rightshift */
  387.      0,            /* size (0 = byte, 1 = short, 2 = long) */
  388.      0,            /* bitsize */
  389.      false,            /* pc_relative */
  390.      0,            /* bitpos */
  391.      complain_overflow_dont, /* complain_on_overflow */
  392.      0,            /* special_function */
  393.      "GPVALUE",        /* name */
  394.      false,            /* partial_inplace */
  395.      0,            /* src_mask */
  396.      0,            /* dst_mask */
  397.      false)            /* pcrel_offset */
  398. };
  399.  
  400. /* See whether the magic number matches.  */
  401.  
  402. static boolean
  403. alpha_ecoff_bad_format_hook (abfd, filehdr)
  404.      bfd *abfd;
  405.      PTR filehdr;
  406. {
  407.   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
  408.  
  409.   if (ALPHA_ECOFF_BADMAG (*internal_f))
  410.     return false;
  411.  
  412.   return true;
  413. }
  414.  
  415. /* Reloc handling.  */
  416.  
  417. /* Swap a reloc in.  */
  418.  
  419. static void
  420. alpha_ecoff_swap_reloc_in (abfd, ext_ptr, intern)
  421.      bfd *abfd;
  422.      PTR ext_ptr;
  423.      struct internal_reloc *intern;
  424. {
  425.   const RELOC *ext = (RELOC *) ext_ptr;
  426.  
  427.   intern->r_vaddr = bfd_h_get_64 (abfd, (bfd_byte *) ext->r_vaddr);
  428.   intern->r_symndx = bfd_h_get_32 (abfd, (bfd_byte *) ext->r_symndx);
  429.  
  430.   BFD_ASSERT (abfd->xvec->header_byteorder_big_p == false);
  431.  
  432.   intern->r_type = ((ext->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
  433.             >> RELOC_BITS0_TYPE_SH_LITTLE);
  434.   intern->r_extern = (ext->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
  435.   intern->r_offset = ((ext->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
  436.               >> RELOC_BITS1_OFFSET_SH_LITTLE);
  437.   /* Ignored the reserved bits.  */
  438.   intern->r_size = ((ext->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
  439.             >> RELOC_BITS3_SIZE_SH_LITTLE);
  440.  
  441.   if (intern->r_type == ALPHA_R_LITUSE
  442.       || intern->r_type == ALPHA_R_GPDISP)
  443.     {
  444.       /* Handle the LITUSE and GPDISP relocs specially.  Its symndx
  445.      value is not actually a symbol index, but is instead a
  446.      special code.  We put the code in the r_size field, and
  447.      clobber the symndx.  */
  448.       if (intern->r_size != 0)
  449.     abort ();
  450.       intern->r_size = intern->r_symndx;
  451.       intern->r_symndx = RELOC_SECTION_NONE;
  452.     }
  453.   else if (intern->r_type == ALPHA_R_IGNORE)
  454.     {
  455.       /* The IGNORE reloc generally follows a GPDISP reloc, and is
  456.      against the .lita section.  The section is irrelevant.  */
  457.       if (! intern->r_extern &&
  458.       (intern->r_symndx == RELOC_SECTION_NONE
  459.        || intern->r_symndx == RELOC_SECTION_ABS))
  460.     abort ();
  461.       if (! intern->r_extern && intern->r_symndx == RELOC_SECTION_LITA)
  462.     intern->r_symndx = RELOC_SECTION_NONE;
  463.     }
  464. }
  465.  
  466. /* Swap a reloc out.  */
  467.  
  468. static void
  469. alpha_ecoff_swap_reloc_out (abfd, intern, dst)
  470.      bfd *abfd;
  471.      const struct internal_reloc *intern;
  472.      PTR dst;
  473. {
  474.   RELOC *ext = (RELOC *) dst;
  475.   long symndx;
  476.   unsigned char size;
  477.  
  478.   /* Undo the hackery done in swap_reloc_in.  */
  479.   if (intern->r_type == ALPHA_R_LITUSE
  480.       || intern->r_type == ALPHA_R_GPDISP)
  481.     {
  482.       symndx = intern->r_size;
  483.       size = 0;
  484.     }
  485.   else if (intern->r_type == ALPHA_R_IGNORE
  486.        && ! intern->r_extern
  487.        && intern->r_symndx == RELOC_SECTION_NONE)
  488.     {
  489.       symndx = RELOC_SECTION_LITA;
  490.       size = intern->r_size;
  491.     }
  492.   else
  493.     {
  494.       symndx = intern->r_symndx;
  495.       size = intern->r_size;
  496.     }
  497.  
  498.   BFD_ASSERT (intern->r_extern
  499.           || (intern->r_symndx >= 0 && intern->r_symndx <= 14));
  500.  
  501.   bfd_h_put_64 (abfd, intern->r_vaddr, (bfd_byte *) ext->r_vaddr);
  502.   bfd_h_put_32 (abfd, symndx, (bfd_byte *) ext->r_symndx);
  503.  
  504.   BFD_ASSERT (abfd->xvec->header_byteorder_big_p == false);
  505.  
  506.   ext->r_bits[0] = ((intern->r_type << RELOC_BITS0_TYPE_SH_LITTLE)
  507.             & RELOC_BITS0_TYPE_LITTLE);
  508.   ext->r_bits[1] = ((intern->r_extern ? RELOC_BITS1_EXTERN_LITTLE : 0)
  509.             | ((intern->r_offset << RELOC_BITS1_OFFSET_SH_LITTLE)
  510.                & RELOC_BITS1_OFFSET_LITTLE));
  511.   ext->r_bits[2] = 0;
  512.   ext->r_bits[3] = ((size << RELOC_BITS3_SIZE_SH_LITTLE)
  513.             & RELOC_BITS3_SIZE_LITTLE);
  514. }
  515.  
  516. /* Finish canonicalizing a reloc.  Part of this is generic to all
  517.    ECOFF targets, and that part is in ecoff.c.  The rest is done in
  518.    this backend routine.  It must fill in the howto field.  */
  519.  
  520. static void
  521. alpha_adjust_reloc_in (abfd, intern, rptr)
  522.      bfd *abfd;
  523.      const struct internal_reloc *intern;
  524.      arelent *rptr;
  525. {
  526.   if (intern->r_type > ALPHA_R_GPVALUE)
  527.     abort ();
  528.  
  529.   switch (intern->r_type)
  530.     {
  531.     case ALPHA_R_BRADDR:
  532.     case ALPHA_R_SREL16:
  533.     case ALPHA_R_SREL32:
  534.     case ALPHA_R_SREL64:
  535.       /* The PC relative relocs do not seem to use the section VMA as
  536.      a negative addend.  */
  537.       rptr->addend = 0;
  538.       break;
  539.  
  540.     case ALPHA_R_GPREL32:
  541.     case ALPHA_R_LITERAL:
  542.       /* Copy the gp value for this object file into the addend, to
  543.      ensure that we are not confused by the linker.  */
  544.       if (! intern->r_extern)
  545.     rptr->addend += ecoff_data (abfd)->gp;
  546.       break;
  547.  
  548.     case ALPHA_R_LITUSE:
  549.     case ALPHA_R_GPDISP:
  550.       /* The LITUSE and GPDISP relocs do not use a symbol, or an
  551.      addend, but they do use a special code.  Put this code in the
  552.      addend field.  */
  553.       rptr->addend = intern->r_size;
  554.       break;
  555.  
  556.     case ALPHA_R_OP_STORE:
  557.       /* The STORE reloc needs the size and offset fields.  We store
  558.      them in the addend.  */
  559.       BFD_ASSERT (intern->r_offset <= 256 && intern->r_size <= 256);
  560.       rptr->addend = (intern->r_offset << 8) + intern->r_size;
  561.       break;
  562.  
  563.     case ALPHA_R_OP_PUSH:
  564.     case ALPHA_R_OP_PSUB:
  565.     case ALPHA_R_OP_PRSHIFT:
  566.       /* The PUSH, PSUB and PRSHIFT relocs do not actually use an
  567.      address.  I believe that the address supplied is really an
  568.      addend.  */
  569.       rptr->addend = intern->r_vaddr;
  570.       break;
  571.  
  572.     case ALPHA_R_GPVALUE:
  573.       /* Set the addend field to the new GP value.  */
  574.       rptr->addend = intern->r_symndx + ecoff_data (abfd)->gp;
  575.       break;
  576.  
  577.     case ALPHA_R_IGNORE:
  578.       /* If the type is ALPHA_R_IGNORE, make sure this is a reference
  579.      to the absolute section so that the reloc is ignored.  For
  580.      some reason the address of this reloc type is not adjusted by
  581.      the section vma.  We record the gp value for this object file
  582.      here, for convenience when doing the GPDISP relocation.  */
  583.       rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
  584.       rptr->address = intern->r_vaddr;
  585.       rptr->addend = ecoff_data (abfd)->gp;
  586.       break;
  587.  
  588.     default:
  589.       break;
  590.     }
  591.  
  592.   rptr->howto = &alpha_howto_table[intern->r_type];
  593. }
  594.  
  595. /* When writing out a reloc we need to pull some values back out of
  596.    the addend field into the reloc.  This is roughly the reverse of
  597.    alpha_adjust_reloc_in, except that there are several changes we do
  598.    not need to undo.  */
  599.  
  600. static void
  601. alpha_adjust_reloc_out (abfd, rel, intern)
  602.      bfd *abfd;
  603.      const arelent *rel;
  604.      struct internal_reloc *intern;
  605. {
  606.   switch (intern->r_type)
  607.     {
  608.     case ALPHA_R_LITUSE:
  609.     case ALPHA_R_GPDISP:
  610.       intern->r_size = rel->addend;
  611.       break;
  612.  
  613.     case ALPHA_R_OP_STORE:
  614.       intern->r_size = rel->addend & 0xff;
  615.       intern->r_offset = (rel->addend >> 8) & 0xff;
  616.       break;
  617.  
  618.     case ALPHA_R_OP_PUSH:
  619.     case ALPHA_R_OP_PSUB:
  620.     case ALPHA_R_OP_PRSHIFT:
  621.       intern->r_vaddr = rel->addend;
  622.       break;
  623.  
  624.     case ALPHA_R_IGNORE:
  625.       intern->r_vaddr = rel->address;
  626.       if (intern->r_symndx == RELOC_SECTION_ABS)
  627.     intern->r_symndx = RELOC_SECTION_NONE;
  628.       break;
  629.  
  630.     default:
  631.       break;
  632.     }
  633. }
  634.  
  635. /* The size of the stack for the relocation evaluator.  */
  636. #define RELOC_STACKSIZE (10)
  637.  
  638. /* Alpha ECOFF relocs have a built in expression evaluator as well as
  639.    other interdependencies.  Rather than use a bunch of special
  640.    functions and global variables, we use a single routine to do all
  641.    the relocation for a section.  I haven't yet worked out how the
  642.    assembler is going to handle this.  */
  643.  
  644. static bfd_byte *
  645. alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
  646.                         data, relocateable, symbols)
  647.      bfd *abfd;
  648.      struct bfd_link_info *link_info;
  649.      struct bfd_link_order *link_order;
  650.      bfd_byte *data;
  651.      boolean relocateable;
  652.      asymbol **symbols;
  653. {
  654.   bfd *input_bfd = link_order->u.indirect.section->owner;
  655.   asection *input_section = link_order->u.indirect.section;
  656.   size_t reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
  657.   arelent **reloc_vector = (arelent **) alloca (reloc_size);
  658.   bfd *output_bfd = relocateable ? abfd : (bfd *) NULL;
  659.   bfd_vma gp;
  660.   boolean gp_undefined;
  661.   bfd_vma stack[RELOC_STACKSIZE];
  662.   int tos = 0;
  663.  
  664.   if (! bfd_get_section_contents (input_bfd, input_section, data,
  665.                   (file_ptr) 0, input_section->_raw_size))
  666.     return NULL;
  667.  
  668.   /* The section size is not going to change.  */
  669.   input_section->_cooked_size = input_section->_raw_size;
  670.   input_section->reloc_done = true;
  671.  
  672.   if (bfd_canonicalize_reloc (input_bfd, input_section, reloc_vector,
  673.                   symbols)
  674.       == 0)
  675.     return data;
  676.  
  677.   /* Get the GP value for the output BFD.  */
  678.   gp_undefined = false;
  679.   if (ecoff_data (abfd)->gp == 0)
  680.     {
  681.       if (relocateable != false)
  682.     {
  683.       asection *sec;
  684.       bfd_vma lo;
  685.  
  686.       /* Make up a value.  */
  687.       lo = (bfd_vma) -1;
  688.       for (sec = abfd->sections; sec != NULL; sec = sec->next)
  689.         {
  690.           if (sec->vma < lo
  691.           && (strcmp (sec->name, ".sbss") == 0
  692.               || strcmp (sec->name, ".sdata") == 0
  693.               || strcmp (sec->name, ".lit4") == 0
  694.               || strcmp (sec->name, ".lit8") == 0
  695.               || strcmp (sec->name, ".lita") == 0))
  696.         lo = sec->vma;
  697.         }
  698.       ecoff_data (abfd)->gp = lo + 0x8000;
  699.     }
  700.       else
  701.     {
  702.       struct bfd_link_hash_entry *h;
  703.  
  704.       h = bfd_link_hash_lookup (link_info->hash, "_gp", false, false,
  705.                     true);
  706.       if (h == (struct bfd_link_hash_entry *) NULL
  707.           || h->type != bfd_link_hash_defined)
  708.         gp_undefined = true;
  709.       else
  710.         ecoff_data (abfd)->gp = (h->u.def.value
  711.                      + h->u.def.section->output_section->vma
  712.                      + h->u.def.section->output_offset);
  713.     }
  714.     }
  715.   gp = ecoff_data (abfd)->gp;
  716.  
  717.   for (; *reloc_vector != (arelent *) NULL; reloc_vector++)
  718.     {
  719.       arelent *rel;
  720.       bfd_reloc_status_type r;
  721.       char *err;
  722.  
  723.       rel = *reloc_vector;
  724.       r = bfd_reloc_ok;
  725.       switch (rel->howto->type)
  726.     {
  727.     case ALPHA_R_IGNORE:
  728.       rel->address += input_section->output_offset;
  729.       break;
  730.  
  731.     case ALPHA_R_REFLONG:
  732.     case ALPHA_R_REFQUAD:
  733.     case ALPHA_R_BRADDR:
  734.     case ALPHA_R_HINT:
  735.     case ALPHA_R_SREL16:
  736.     case ALPHA_R_SREL32:
  737.     case ALPHA_R_SREL64:
  738.       if (relocateable
  739.           && ((*rel->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0)
  740.         {
  741.           rel->address += input_section->output_offset;
  742.           break;
  743.         }
  744.       r = bfd_perform_relocation (input_bfd, rel, data, input_section,
  745.                       output_bfd, &err);
  746.       break;
  747.  
  748.     case ALPHA_R_GPREL32:
  749.       /* This relocation is used in a switch table.  It is a 32
  750.          bit offset from the current GP value.  We must adjust it
  751.          by the different between the original GP value and the
  752.          current GP value.  The original GP value is stored in the
  753.          addend.  We adjust the addend and let
  754.          bfd_perform_relocation finish the job.  */
  755.       rel->addend -= gp;
  756.       r = bfd_perform_relocation (input_bfd, rel, data, input_section,
  757.                       output_bfd, &err);
  758.       if (r == bfd_reloc_ok && gp_undefined)
  759.         {
  760.           r = bfd_reloc_dangerous;
  761.           err = (char *) "GP relative relocation used when GP not defined";
  762.         }
  763.       break;
  764.  
  765.     case ALPHA_R_LITERAL:
  766.       /* This is a reference to a literal value, generally
  767.          (always?) in the .lita section.  This is a 16 bit GP
  768.          relative relocation.  Sometimes the subsequent reloc is a
  769.          LITUSE reloc, which indicates how this reloc is used.
  770.          This sometimes permits rewriting the two instructions
  771.          referred to by the LITERAL and the LITUSE into different
  772.          instructions which do not refer to .lita.  This can save
  773.          a memory reference, and permits removing a value from
  774.          .lita thus saving GP relative space.
  775.  
  776.          We do not these optimizations.  To do them we would need
  777.          to arrange to link the .lita section first, so that by
  778.          the time we got here we would know the final values to
  779.          use.  This would not be particularly difficult, but it is
  780.          not currently implemented.  */
  781.  
  782.       {
  783.         unsigned long insn;
  784.  
  785.         /* I believe that the LITERAL reloc will only apply to a
  786.            ldq instruction, so check my assumption.  */
  787.         insn = bfd_get_32 (input_bfd, data + rel->address);
  788.         BFD_ASSERT (((insn >> 26) & 0x3f) == 0x29);
  789.  
  790.         rel->addend -= gp;
  791.         r = bfd_perform_relocation (input_bfd, rel, data, input_section,
  792.                     output_bfd, &err);
  793.         if (r == bfd_reloc_ok && gp_undefined)
  794.           {
  795.         r = bfd_reloc_dangerous;
  796.         err =
  797.           (char *) "GP relative relocation used when GP not defined";
  798.           }
  799.       }
  800.       break;
  801.  
  802.     case ALPHA_R_LITUSE:
  803.       /* See ALPHA_R_LITERAL above for the uses of this reloc.  It
  804.          does not cause anything to happen, itself.  */
  805.       rel->address += input_section->output_offset;
  806.       break;
  807.         
  808.     case ALPHA_R_GPDISP:
  809.       /* This marks the ldah of an ldah/lda pair which loads the
  810.          gp register with the difference of the gp value and the
  811.          current location.  The second of the pair is r_size bytes
  812.          ahead, and is marked with an ALPHA_R_IGNORE reloc.  */
  813.       {
  814.         unsigned long insn1, insn2;
  815.         bfd_vma addend;
  816.  
  817.         BFD_ASSERT (reloc_vector[1] != NULL
  818.             && reloc_vector[1]->howto->type == ALPHA_R_IGNORE
  819.             && (rel->address + rel->addend
  820.                 == reloc_vector[1]->address));
  821.  
  822.         /* Get the two instructions.  */
  823.         insn1 = bfd_get_32 (input_bfd, data + rel->address);
  824.         insn2 = bfd_get_32 (input_bfd, data + rel->address + rel->addend);
  825.  
  826.         BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
  827.         BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
  828.  
  829.         /* Get the existing addend.  We must account for the sign
  830.            extension done by lda and ldah.  */
  831.         addend = ((insn1 & 0xffff) << 16) + (insn2 & 0xffff);
  832.         if (insn1 & 0x8000)
  833.           {
  834.         addend -= 0x80000000;
  835.         addend -= 0x80000000;
  836.           }
  837.         if (insn2 & 0x8000)
  838.           addend -= 0x10000;
  839.  
  840.         /* The existing addend includes the different between the
  841.            gp of the input BFD and the address in the input BFD.
  842.            Subtract this out.  */
  843.         addend -= (reloc_vector[1]->addend
  844.                - (input_section->vma + rel->address));
  845.  
  846.         /* Now add in the final gp value, and subtract out the
  847.            final address.  */
  848.         addend += (gp
  849.                - (input_section->output_section->vma
  850.               + input_section->output_offset
  851.               + rel->address));
  852.  
  853.         /* Change the instructions, accounting for the sign
  854.            extension, and write them out.  */
  855.         if (addend & 0x8000)
  856.           addend += 0x10000;
  857.         insn1 = (insn1 & 0xffff0000) | ((addend >> 16) & 0xffff);
  858.         insn2 = (insn2 & 0xffff0000) | (addend & 0xffff);
  859.  
  860.         bfd_put_32 (input_bfd, (bfd_vma) insn1, data + rel->address);
  861.         bfd_put_32 (input_bfd, (bfd_vma) insn2,
  862.             data + rel->address + rel->addend);
  863.  
  864.         rel->address += input_section->output_offset;
  865.       }
  866.       break;
  867.       
  868.     case ALPHA_R_OP_PUSH:
  869.       /* Push a value on the reloc evaluation stack.  */
  870.       {
  871.         asymbol *symbol;
  872.         bfd_vma relocation;
  873.  
  874.         if (relocateable)
  875.           {
  876.         rel->address += input_section->output_offset;
  877.         break;
  878.           }
  879.  
  880.         /* Figure out the relocation of this symbol.  */
  881.         symbol = *rel->sym_ptr_ptr;
  882.  
  883.         if (symbol->section == &bfd_und_section)
  884.           r = bfd_reloc_undefined;
  885.  
  886.         if (bfd_is_com_section (symbol->section))
  887.           relocation = 0;
  888.         else
  889.           relocation = symbol->value;
  890.         relocation += symbol->section->output_section->vma;
  891.         relocation += symbol->section->output_offset;
  892.         relocation += rel->addend;
  893.  
  894.         if (tos >= RELOC_STACKSIZE)
  895.           abort ();
  896.  
  897.         stack[tos++] = relocation;
  898.       }
  899.       break;
  900.  
  901.     case ALPHA_R_OP_STORE:
  902.       /* Store a value from the reloc stack into a bitfield.  */
  903.       {
  904.         bfd_vma val;
  905.         int offset, size;
  906.  
  907.         if (relocateable)
  908.           {
  909.         rel->address += input_section->output_offset;
  910.         break;
  911.           }
  912.  
  913.         if (tos == 0)
  914.           abort ();
  915.  
  916.         /* The offset and size for this reloc are encoded into the
  917.            addend field by alpha_adjust_reloc_in.  */
  918.         offset = (rel->addend >> 8) & 0xff;
  919.         size = rel->addend & 0xff;
  920.  
  921.         val = bfd_get_64 (abfd, data + rel->address);
  922.         val &=~ (((1 << size) - 1) << offset);
  923.         val |= (stack[--tos] & ((1 << size) - 1)) << offset;
  924.         bfd_put_64 (abfd, val, data + rel->address);
  925.       }
  926.       break;
  927.  
  928.     case ALPHA_R_OP_PSUB:
  929.       /* Subtract a value from the top of the stack.  */
  930.       {
  931.         asymbol *symbol;
  932.         bfd_vma relocation;
  933.  
  934.         if (relocateable)
  935.           {
  936.         rel->address += input_section->output_offset;
  937.         break;
  938.           }
  939.  
  940.         /* Figure out the relocation of this symbol.  */
  941.         symbol = *rel->sym_ptr_ptr;
  942.  
  943.         if (symbol->section == &bfd_und_section)
  944.           r = bfd_reloc_undefined;
  945.  
  946.         if (bfd_is_com_section (symbol->section))
  947.           relocation = 0;
  948.         else
  949.           relocation = symbol->value;
  950.         relocation += symbol->section->output_section->vma;
  951.         relocation += symbol->section->output_offset;
  952.         relocation += rel->addend;
  953.  
  954.         if (tos == 0)
  955.           abort ();
  956.  
  957.         stack[tos - 1] -= relocation;
  958.       }
  959.       break;
  960.  
  961.     case ALPHA_R_OP_PRSHIFT:
  962.       /* Shift the value on the top of the stack.  */
  963.       {
  964.         asymbol *symbol;
  965.         bfd_vma relocation;
  966.  
  967.         if (relocateable)
  968.           {
  969.         rel->address += input_section->output_offset;
  970.         break;
  971.           }
  972.  
  973.         /* Figure out the relocation of this symbol.  */
  974.         symbol = *rel->sym_ptr_ptr;
  975.  
  976.         if (symbol->section == &bfd_und_section)
  977.           r = bfd_reloc_undefined;
  978.  
  979.         if (bfd_is_com_section (symbol->section))
  980.           relocation = 0;
  981.         else
  982.           relocation = symbol->value;
  983.         relocation += symbol->section->output_section->vma;
  984.         relocation += symbol->section->output_offset;
  985.         relocation += rel->addend;
  986.  
  987.         if (tos == 0)
  988.           abort ();
  989.  
  990.         stack[tos - 1] >>= relocation;
  991.       }
  992.       break;
  993.         
  994.     case ALPHA_R_GPVALUE:
  995.       /* I really don't know if this does the right thing.  */
  996.       gp = rel->addend;
  997.       gp_undefined = false;
  998.       break;
  999.  
  1000.     default:
  1001.       abort ();
  1002.     }
  1003.  
  1004.       if (relocateable)
  1005.     {
  1006.       asection *os = input_section->output_section;
  1007.  
  1008.       /* A partial link, so keep the relocs.  */
  1009.       os->orelocation[os->reloc_count] = rel;
  1010.       os->reloc_count++;
  1011.     }
  1012.  
  1013.       if (r != bfd_reloc_ok) 
  1014.     {
  1015.       switch (r)
  1016.         {
  1017.         case bfd_reloc_undefined:
  1018.           if (! ((*link_info->callbacks->undefined_symbol)
  1019.              (link_info, bfd_asymbol_name (*rel->sym_ptr_ptr),
  1020.               input_bfd, input_section, rel->address)))
  1021.         return NULL;
  1022.           break;
  1023.         case bfd_reloc_dangerous: 
  1024.           if (! ((*link_info->callbacks->reloc_dangerous)
  1025.              (link_info, err, input_bfd, input_section,
  1026.               rel->address)))
  1027.         return NULL;
  1028.           break;
  1029.         case bfd_reloc_overflow:
  1030.           if (! ((*link_info->callbacks->reloc_overflow)
  1031.              (link_info, input_bfd, input_section, rel->address)))
  1032.         return NULL;
  1033.           break;
  1034.         case bfd_reloc_outofrange:
  1035.         default:
  1036.           abort ();
  1037.           break;
  1038.         }
  1039.     }
  1040.     }
  1041.  
  1042.   if (tos != 0)
  1043.     abort ();
  1044.  
  1045.   return data;
  1046. }
  1047.  
  1048. /* Get the howto structure for a generic reloc type.  */
  1049.  
  1050. static CONST struct reloc_howto_struct *
  1051. alpha_bfd_reloc_type_lookup (abfd, code)
  1052.      bfd *abfd;
  1053.      bfd_reloc_code_real_type code;
  1054. {
  1055.   int alpha_type;
  1056.  
  1057.   switch (code)
  1058.     {
  1059.     case BFD_RELOC_32:
  1060.       alpha_type = ALPHA_R_REFLONG;
  1061.       break;
  1062.     default:
  1063.       return (CONST struct reloc_howto_struct *) NULL;
  1064.     }
  1065.  
  1066.   return &alpha_howto_table[alpha_type];
  1067. }
  1068.  
  1069. /* A helper routine for alpha_relocate_section which converts an
  1070.    external reloc when generating relocateable output.  Returns the
  1071.    relocation amount.  */
  1072.  
  1073. static bfd_vma
  1074. alpha_convert_external_reloc (output_bfd, info, input_bfd, ext_rel, h)
  1075.      bfd *output_bfd;
  1076.      struct bfd_link_info *info;
  1077.      bfd *input_bfd;
  1078.      struct external_reloc *ext_rel;
  1079.      struct ecoff_link_hash_entry *h;
  1080. {
  1081.   unsigned long r_symndx;
  1082.   bfd_vma relocation;
  1083.  
  1084.   BFD_ASSERT (info->relocateable);
  1085.  
  1086.   if (h->root.type == bfd_link_hash_defined)
  1087.     {
  1088.       asection *hsec;
  1089.       const char *name;
  1090.  
  1091.       /* This symbol is defined in the output.  Convert the reloc from
  1092.      being against the symbol to being against the section.  */
  1093.  
  1094.       /* Clear the r_extern bit.  */
  1095.       ext_rel->r_bits[1] &=~ RELOC_BITS1_EXTERN_LITTLE;
  1096.  
  1097.       /* Compute a new r_symndx value.  */
  1098.       hsec = h->root.u.def.section;
  1099.       name = bfd_get_section_name (output_bfd, hsec->output_section);
  1100.  
  1101.       r_symndx = -1;
  1102.       switch (name[1])
  1103.     {
  1104.     case 'A':
  1105.       if (strcmp (name, "*ABS*") == 0)
  1106.         r_symndx = RELOC_SECTION_ABS;
  1107.       break;
  1108.     case 'b':
  1109.       if (strcmp (name, ".bss") == 0)
  1110.         r_symndx = RELOC_SECTION_BSS;
  1111.       break;
  1112.     case 'd':
  1113.       if (strcmp (name, ".data") == 0)
  1114.         r_symndx = RELOC_SECTION_DATA;
  1115.       break;
  1116.     case 'f':
  1117.       if (strcmp (name, ".fini") == 0)
  1118.         r_symndx = RELOC_SECTION_FINI;
  1119.       break;
  1120.     case 'i':
  1121.       if (strcmp (name, ".init") == 0)
  1122.         r_symndx = RELOC_SECTION_INIT;
  1123.       break;
  1124.     case 'l':
  1125.       if (strcmp (name, ".lita") == 0)
  1126.         r_symndx = RELOC_SECTION_LITA;
  1127.       else if (strcmp (name, ".lit8") == 0)
  1128.         r_symndx = RELOC_SECTION_LIT8;
  1129.       else if (strcmp (name, ".lit4") == 0)
  1130.         r_symndx = RELOC_SECTION_LIT4;
  1131.       break;
  1132.     case 'p':
  1133.       if (strcmp (name, ".pdata") == 0)
  1134.         r_symndx = RELOC_SECTION_PDATA;
  1135.       break;
  1136.     case 'r':
  1137.       if (strcmp (name, ".rdata") == 0)
  1138.         r_symndx = RELOC_SECTION_RDATA;
  1139.       break;
  1140.     case 's':
  1141.       if (strcmp (name, ".sdata") == 0)
  1142.         r_symndx = RELOC_SECTION_SDATA;
  1143.       else if (strcmp (name, ".sbss") == 0)
  1144.         r_symndx = RELOC_SECTION_SBSS;
  1145.       break;
  1146.     case 't':
  1147.       if (strcmp (name, ".text") == 0)
  1148.         r_symndx = RELOC_SECTION_TEXT;
  1149.       break;
  1150.     case 'x':
  1151.       if (strcmp (name, ".xdata") == 0)
  1152.         r_symndx = RELOC_SECTION_XDATA;
  1153.       break;
  1154.     }
  1155.               
  1156.       if (r_symndx == -1)
  1157.     abort ();
  1158.  
  1159.       /* Add the section VMA and the symbol value.  */
  1160.       relocation = (h->root.u.def.value
  1161.             + hsec->output_section->vma
  1162.             + hsec->output_offset);
  1163.     }
  1164.   else
  1165.     {
  1166.       /* Change the symndx value to the right one for
  1167.      the output BFD.  */
  1168.       r_symndx = h->indx;
  1169.       if (r_symndx == -1)
  1170.     {
  1171.       /* Caller must give an error.  */
  1172.       r_symndx = 0;
  1173.     }
  1174.       relocation = 0;
  1175.     }
  1176.  
  1177.   /* Write out the new r_symndx value.  */
  1178.   bfd_h_put_32 (input_bfd, (bfd_vma) r_symndx,
  1179.         (bfd_byte *) ext_rel->r_symndx);
  1180.  
  1181.   return relocation;
  1182. }
  1183.  
  1184. /* Relocate a section while linking an Alpha ECOFF file.  This is
  1185.    quite similar to get_relocated_section_contents.  Perhaps they
  1186.    could be combined somehow.  */
  1187.  
  1188. static boolean
  1189. alpha_relocate_section (output_bfd, info, input_bfd, input_section,
  1190.             contents, external_relocs)
  1191.      bfd *output_bfd;
  1192.      struct bfd_link_info *info;
  1193.      bfd *input_bfd;
  1194.      asection *input_section;
  1195.      bfd_byte *contents;
  1196.      PTR external_relocs;
  1197. {
  1198.   asection **symndx_to_section;
  1199.   struct ecoff_link_hash_entry **sym_hashes;
  1200.   bfd_vma gp;
  1201.   boolean gp_undefined;
  1202.   bfd_vma stack[RELOC_STACKSIZE];
  1203.   int tos = 0;
  1204.   struct external_reloc *ext_rel;
  1205.   struct external_reloc *ext_rel_end;
  1206.  
  1207.   /* We keep a table mapping the symndx found in an internal reloc to
  1208.      the appropriate section.  This is faster than looking up the
  1209.      section by name each time.  */
  1210.   symndx_to_section = ecoff_data (input_bfd)->symndx_to_section;
  1211.   if (symndx_to_section == (asection **) NULL)
  1212.     {
  1213.       symndx_to_section = ((asection **)
  1214.                bfd_alloc (input_bfd,
  1215.                       (NUM_RELOC_SECTIONS
  1216.                        * sizeof (asection *))));
  1217.  
  1218.       symndx_to_section[RELOC_SECTION_NONE] = NULL;
  1219.       symndx_to_section[RELOC_SECTION_TEXT] =
  1220.     bfd_get_section_by_name (input_bfd, ".text");
  1221.       symndx_to_section[RELOC_SECTION_RDATA] =
  1222.     bfd_get_section_by_name (input_bfd, ".rdata");
  1223.       symndx_to_section[RELOC_SECTION_DATA] =
  1224.     bfd_get_section_by_name (input_bfd, ".data");
  1225.       symndx_to_section[RELOC_SECTION_SDATA] =
  1226.     bfd_get_section_by_name (input_bfd, ".sdata");
  1227.       symndx_to_section[RELOC_SECTION_SBSS] =
  1228.     bfd_get_section_by_name (input_bfd, ".sbss");
  1229.       symndx_to_section[RELOC_SECTION_BSS] =
  1230.     bfd_get_section_by_name (input_bfd, ".bss");
  1231.       symndx_to_section[RELOC_SECTION_INIT] =
  1232.     bfd_get_section_by_name (input_bfd, ".init");
  1233.       symndx_to_section[RELOC_SECTION_LIT8] =
  1234.     bfd_get_section_by_name (input_bfd, ".lit8");
  1235.       symndx_to_section[RELOC_SECTION_LIT4] =
  1236.     bfd_get_section_by_name (input_bfd, ".lit4");
  1237.       symndx_to_section[RELOC_SECTION_XDATA] =
  1238.     bfd_get_section_by_name (input_bfd, ".xdata");
  1239.       symndx_to_section[RELOC_SECTION_PDATA] =
  1240.     bfd_get_section_by_name (input_bfd, ".pdata");
  1241.       symndx_to_section[RELOC_SECTION_FINI] =
  1242.     bfd_get_section_by_name (input_bfd, ".fini");
  1243.       symndx_to_section[RELOC_SECTION_LITA] =
  1244.     bfd_get_section_by_name (input_bfd, ".lita");
  1245.       symndx_to_section[RELOC_SECTION_ABS] = &bfd_abs_section;
  1246.  
  1247.       ecoff_data (input_bfd)->symndx_to_section = symndx_to_section;
  1248.     }
  1249.  
  1250.   sym_hashes = ecoff_data (input_bfd)->sym_hashes;
  1251.  
  1252.   gp = ecoff_data (output_bfd)->gp;
  1253.   if (gp == 0)
  1254.     gp_undefined = true;
  1255.   else
  1256.     gp_undefined = false;
  1257.  
  1258.   BFD_ASSERT (output_bfd->xvec->header_byteorder_big_p == false);
  1259.   BFD_ASSERT (input_bfd->xvec->header_byteorder_big_p == false);
  1260.  
  1261.   ext_rel = (struct external_reloc *) external_relocs;
  1262.   ext_rel_end = ext_rel + input_section->reloc_count;
  1263.   for (; ext_rel < ext_rel_end; ext_rel++)
  1264.     {
  1265.       bfd_vma r_vaddr;
  1266.       unsigned long r_symndx;
  1267.       int r_type;
  1268.       int r_extern;
  1269.       int r_offset;
  1270.       int r_size;
  1271.       boolean relocatep;
  1272.       boolean adjust_addrp;
  1273.       boolean gp_usedp;
  1274.       bfd_vma addend;
  1275.  
  1276.       r_vaddr = bfd_h_get_64 (input_bfd, (bfd_byte *) ext_rel->r_vaddr);
  1277.       r_symndx = bfd_h_get_32 (input_bfd, (bfd_byte *) ext_rel->r_symndx);
  1278.  
  1279.       r_type = ((ext_rel->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
  1280.         >> RELOC_BITS0_TYPE_SH_LITTLE);
  1281.       r_extern = (ext_rel->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
  1282.       r_offset = ((ext_rel->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
  1283.           >> RELOC_BITS1_OFFSET_SH_LITTLE);
  1284.       /* Ignored the reserved bits.  */
  1285.       r_size = ((ext_rel->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
  1286.         >> RELOC_BITS3_SIZE_SH_LITTLE);
  1287.  
  1288.       relocatep = false;
  1289.       adjust_addrp = true;
  1290.       gp_usedp = false;
  1291.       addend = 0;
  1292.  
  1293.       switch (r_type)
  1294.     {
  1295.     default:
  1296.       abort ();
  1297.  
  1298.     case ALPHA_R_IGNORE:
  1299.       /* This reloc appears after a GPDISP reloc.  It marks the
  1300.          position of the second instruction to be altered by the
  1301.          GPDISP reloc, but is not otherwise used for anything.
  1302.          For some reason, the address of the relocation does not
  1303.          appear to include the section VMA, unlike the other
  1304.          relocation types.  */
  1305.       if (info->relocateable)
  1306.         bfd_h_put_64 (input_bfd,
  1307.               input_section->output_offset + r_vaddr,
  1308.               (bfd_byte *) ext_rel->r_vaddr);
  1309.       adjust_addrp = false;
  1310.       break;
  1311.  
  1312.     case ALPHA_R_REFLONG:
  1313.     case ALPHA_R_REFQUAD:
  1314.     case ALPHA_R_BRADDR:
  1315.     case ALPHA_R_HINT:
  1316.     case ALPHA_R_SREL16:
  1317.     case ALPHA_R_SREL32:
  1318.     case ALPHA_R_SREL64:
  1319.       relocatep = true;
  1320.       break;
  1321.  
  1322.     case ALPHA_R_GPREL32:
  1323.       /* This relocation is used in a switch table.  It is a 32
  1324.          bit offset from the current GP value.  We must adjust it
  1325.          by the different between the original GP value and the
  1326.          current GP value.  */
  1327.       relocatep = true;
  1328.       addend = ecoff_data (input_bfd)->gp - gp;
  1329.       gp_usedp = true;
  1330.       break;
  1331.  
  1332.     case ALPHA_R_LITERAL:
  1333.       /* This is a reference to a literal value, generally
  1334.          (always?) in the .lita section.  This is a 16 bit GP
  1335.          relative relocation.  Sometimes the subsequent reloc is a
  1336.          LITUSE reloc, which indicates how this reloc is used.
  1337.          This sometimes permits rewriting the two instructions
  1338.          referred to by the LITERAL and the LITUSE into different
  1339.          instructions which do not refer to .lita.  This can save
  1340.          a memory reference, and permits removing a value from
  1341.          .lita thus saving GP relative space.
  1342.  
  1343.          We do not these optimizations.  To do them we would need
  1344.          to arrange to link the .lita section first, so that by
  1345.          the time we got here we would know the final values to
  1346.          use.  This would not be particularly difficult, but it is
  1347.          not currently implemented.  */
  1348.  
  1349.       /* I believe that the LITERAL reloc will only apply to a ldq
  1350.          instruction, so check my assumption.  */
  1351.       BFD_ASSERT (((bfd_get_32 (input_bfd,
  1352.                     contents + r_vaddr - input_section->vma)
  1353.             >> 26)
  1354.                & 0x3f)
  1355.               == 0x29);
  1356.  
  1357.       relocatep = true;
  1358.       addend = ecoff_data (input_bfd)->gp - gp;
  1359.       gp_usedp = true;
  1360.       break;
  1361.  
  1362.     case ALPHA_R_LITUSE:
  1363.       /* See ALPHA_R_LITERAL above for the uses of this reloc.  It
  1364.          does not cause anything to happen, itself.  */
  1365.       break;
  1366.         
  1367.     case ALPHA_R_GPDISP:
  1368.       /* This marks the ldah of an ldah/lda pair which loads the
  1369.          gp register with the difference of the gp value and the
  1370.          current location.  The second of the pair is r_symndx
  1371.          bytes ahead, and is also marked with an ALPHA_R_IGNORE
  1372.          reloc.  */
  1373.       {
  1374.         unsigned long insn1, insn2;
  1375.  
  1376.         BFD_ASSERT (ext_rel + 1 < ext_rel_end
  1377.             && (((ext_rel + 1)->r_bits[0]
  1378.                  & RELOC_BITS0_TYPE_LITTLE)
  1379.                 >> RELOC_BITS0_TYPE_SH_LITTLE) == ALPHA_R_IGNORE
  1380.             && (bfd_h_get_64 (input_bfd,
  1381.                       (bfd_byte *) (ext_rel + 1)->r_vaddr)
  1382.                 == r_vaddr - input_section->vma + r_symndx));
  1383.  
  1384.         /* Get the two instructions.  */
  1385.         insn1 = bfd_get_32 (input_bfd,
  1386.                 contents + r_vaddr - input_section->vma);
  1387.         insn2 = bfd_get_32 (input_bfd,
  1388.                 (contents
  1389.                  + r_vaddr
  1390.                  - input_section->vma
  1391.                  + r_symndx));
  1392.  
  1393.         BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
  1394.         BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
  1395.  
  1396.         /* Get the existing addend.  We must account for the sign
  1397.            extension done by lda and ldah.  */
  1398.         addend = ((insn1 & 0xffff) << 16) + (insn2 & 0xffff);
  1399.         if (insn1 & 0x8000)
  1400.           {
  1401.         /* This is addend -= 0x100000000 without causing an
  1402.            integer overflow on a 32 bit host.  */
  1403.         addend -= 0x80000000;
  1404.         addend -= 0x80000000;
  1405.           }
  1406.         if (insn2 & 0x8000)
  1407.           addend -= 0x10000;
  1408.  
  1409.         /* The existing addend includes the difference between the
  1410.            gp of the input BFD and the address in the input BFD.
  1411.            We want to change this to the difference between the
  1412.            final GP and the final address.  */
  1413.         addend += (gp
  1414.                - ecoff_data (input_bfd)->gp
  1415.                + input_section->vma
  1416.                - (input_section->output_section->vma
  1417.               + input_section->output_offset));
  1418.  
  1419.         /* Change the instructions, accounting for the sign
  1420.            extension, and write them out.  */
  1421.         if (addend & 0x8000)
  1422.           addend += 0x10000;
  1423.         insn1 = (insn1 & 0xffff0000) | ((addend >> 16) & 0xffff);
  1424.         insn2 = (insn2 & 0xffff0000) | (addend & 0xffff);
  1425.  
  1426.         bfd_put_32 (input_bfd, (bfd_vma) insn1,
  1427.             contents + r_vaddr - input_section->vma);
  1428.         bfd_put_32 (input_bfd, (bfd_vma) insn2,
  1429.             contents + r_vaddr - input_section->vma + r_symndx);
  1430.  
  1431.         gp_usedp = true;
  1432.       }
  1433.       break;
  1434.       
  1435.     case ALPHA_R_OP_PUSH:
  1436.     case ALPHA_R_OP_PSUB:
  1437.     case ALPHA_R_OP_PRSHIFT:
  1438.       /* Manipulate values on the reloc evaluation stack.  The
  1439.          r_vaddr field is not an address in input_section, it is
  1440.          the current value (including any addend) of the object
  1441.          being used.  */
  1442.       if (! r_extern)
  1443.         {
  1444.           asection *s;
  1445.  
  1446.           s = symndx_to_section[r_symndx];
  1447.           if (s == (asection *) NULL)
  1448.         abort ();
  1449.           addend = s->output_section->vma + s->output_offset - s->vma;
  1450.         }
  1451.       else
  1452.         {
  1453.           struct ecoff_link_hash_entry *h;
  1454.  
  1455.           h = sym_hashes[r_symndx];
  1456.           if (h == (struct ecoff_link_hash_entry *) NULL)
  1457.         abort ();
  1458.  
  1459.           if (! info->relocateable)
  1460.         {
  1461.           if (h->root.type == bfd_link_hash_defined)
  1462.             addend = (h->root.u.def.value
  1463.                   + h->root.u.def.section->output_section->vma
  1464.                   + h->root.u.def.section->output_offset);
  1465.           else
  1466.             {
  1467.               /* Note that we pass the address as 0, since we
  1468.              do not have a meaningful number for the
  1469.              location within the section that is being
  1470.              relocated.  */
  1471.               if (! ((*info->callbacks->undefined_symbol)
  1472.                  (info, h->root.root.string, input_bfd,
  1473.                   input_section, (bfd_vma) 0)))
  1474.             return false;
  1475.               addend = 0;
  1476.             }
  1477.         }
  1478.           else
  1479.         {
  1480.           if (h->root.type != bfd_link_hash_defined
  1481.               && h->indx == -1)
  1482.             {
  1483.               /* This symbol is not being written out.  Pass
  1484.              the address as 0, as with undefined_symbol,
  1485.              above.  */
  1486.               if (! ((*info->callbacks->unattached_reloc)
  1487.                  (info, h->root.root.string, input_bfd,
  1488.                   input_section, (bfd_vma) 0)))
  1489.             return false;
  1490.             }
  1491.  
  1492.           addend = alpha_convert_external_reloc (output_bfd, info,
  1493.                              input_bfd,
  1494.                              ext_rel, h);
  1495.         }
  1496.         }
  1497.  
  1498.       addend += r_vaddr;
  1499.  
  1500.       if (info->relocateable)
  1501.         {
  1502.           /* Adjust r_vaddr by the addend.  */
  1503.           bfd_h_put_64 (input_bfd, addend,
  1504.                 (bfd_byte *) ext_rel->r_vaddr);
  1505.         }
  1506.       else
  1507.         {
  1508.           switch (r_type)
  1509.         {
  1510.         case ALPHA_R_OP_PUSH:
  1511.           if (tos >= RELOC_STACKSIZE)
  1512.             abort ();
  1513.           stack[tos++] = addend;
  1514.           break;
  1515.  
  1516.         case ALPHA_R_OP_PSUB:
  1517.           if (tos == 0)
  1518.             abort ();
  1519.           stack[tos - 1] -= addend;
  1520.           break;
  1521.  
  1522.         case ALPHA_R_OP_PRSHIFT:
  1523.           if (tos == 0)
  1524.             abort ();
  1525.           stack[tos - 1] >>= addend;
  1526.           break;
  1527.         }
  1528.         }
  1529.  
  1530.       adjust_addrp = false;
  1531.       break;
  1532.  
  1533.     case ALPHA_R_OP_STORE:
  1534.       /* Store a value from the reloc stack into a bitfield.  If
  1535.          we are generating relocateable output, all we do is
  1536.          adjust the address of the reloc.  */
  1537.       if (! info->relocateable)
  1538.         {
  1539.           bfd_vma val;
  1540.  
  1541.           if (tos == 0)
  1542.         abort ();
  1543.  
  1544.           /* FIXME: I don't know what kind of overflow checking,
  1545.          if any, should be done here.  */
  1546.           val = bfd_get_64 (input_bfd,
  1547.                 contents + r_vaddr - input_section->vma);
  1548.           val &=~ (((1 << r_size) - 1) << r_offset);
  1549.           val |= (stack[--tos] & ((1 << r_size) - 1)) << r_offset;
  1550.           bfd_put_64 (input_bfd, val,
  1551.               contents + r_vaddr - input_section->vma);
  1552.         }
  1553.       break;
  1554.  
  1555.     case ALPHA_R_GPVALUE:
  1556.       /* I really don't know if this does the right thing.  */
  1557.       gp = ecoff_data (input_bfd)->gp + r_symndx;
  1558.       gp_undefined = false;
  1559.       break;
  1560.     }
  1561.  
  1562.       if (relocatep)
  1563.     {
  1564.       reloc_howto_type *howto;
  1565.       struct ecoff_link_hash_entry *h = NULL;
  1566.       asection *s = NULL;
  1567.       bfd_vma relocation;
  1568.       bfd_reloc_status_type r;
  1569.  
  1570.       /* Perform a relocation.  */
  1571.  
  1572.       howto = &alpha_howto_table[r_type];
  1573.  
  1574.       if (r_extern)
  1575.         {
  1576.           h = sym_hashes[r_symndx];
  1577.           /* If h is NULL, that means that there is a reloc
  1578.          against an external symbol which we thought was just
  1579.          a debugging symbol.  This should not happen.  */
  1580.           if (h == (struct ecoff_link_hash_entry *) NULL)
  1581.         abort ();
  1582.         }
  1583.       else
  1584.         {
  1585.           if (r_symndx < 0 || r_symndx >= NUM_RELOC_SECTIONS)
  1586.         s = NULL;
  1587.           else
  1588.         s = symndx_to_section[r_symndx];
  1589.  
  1590.           if (s == (asection *) NULL)
  1591.         abort ();
  1592.         }
  1593.  
  1594.       if (info->relocateable)
  1595.         {
  1596.           /* We are generating relocateable output, and must
  1597.          convert the existing reloc.  */
  1598.           if (r_extern)
  1599.         {
  1600.           if (h->root.type != bfd_link_hash_defined
  1601.               && h->indx == -1)
  1602.             {
  1603.               /* This symbol is not being written out.  */
  1604.               if (! ((*info->callbacks->unattached_reloc)
  1605.                  (info, h->root.root.string, input_bfd,
  1606.                   input_section, r_vaddr - input_section->vma)))
  1607.             return false;
  1608.             }
  1609.  
  1610.           relocation = alpha_convert_external_reloc (output_bfd,
  1611.                                  info,
  1612.                                  input_bfd,
  1613.                                  ext_rel,
  1614.                                  h);
  1615.         }
  1616.           else
  1617.         {
  1618.           /* This is a relocation against a section.  Adjust
  1619.              the value by the amount the section moved.  */
  1620.           relocation = (s->output_section->vma
  1621.                 + s->output_offset
  1622.                 - s->vma);
  1623.         }
  1624.  
  1625.           /* If this is PC relative, the existing object file
  1626.          appears to already have the reloc worked out.  We
  1627.          must subtract out the old value and add in the new
  1628.          one.  */
  1629.           if (howto->pc_relative)
  1630.         relocation -= (input_section->output_section->vma
  1631.                    + input_section->output_offset
  1632.                    - input_section->vma);
  1633.  
  1634.           /* Put in any addend.  */
  1635.           relocation += addend;
  1636.  
  1637.           /* Adjust the contents.  */
  1638.           r = _bfd_relocate_contents (howto, input_bfd, relocation,
  1639.                       (contents
  1640.                        + r_vaddr
  1641.                        - input_section->vma));
  1642.         }
  1643.       else
  1644.         {
  1645.           /* We are producing a final executable.  */
  1646.           if (r_extern)
  1647.         {
  1648.           /* This is a reloc against a symbol.  */
  1649.           if (h->root.type == bfd_link_hash_defined)
  1650.             {
  1651.               asection *hsec;
  1652.  
  1653.               hsec = h->root.u.def.section;
  1654.               relocation = (h->root.u.def.value
  1655.                     + hsec->output_section->vma
  1656.                     + hsec->output_offset);
  1657.             }
  1658.           else
  1659.             {
  1660.               if (! ((*info->callbacks->undefined_symbol)
  1661.                  (info, h->root.root.string, input_bfd,
  1662.                   input_section,
  1663.                   r_vaddr - input_section->vma)))
  1664.             return false;
  1665.               relocation = 0;
  1666.             }
  1667.         }
  1668.           else
  1669.         {
  1670.           /* This is a reloc against a section.  */
  1671.           relocation = (s->output_section->vma
  1672.                 + s->output_offset
  1673.                 - s->vma);
  1674.  
  1675.           /* Adjust a PC relative relocation by removing the
  1676.              reference to the original source section.  */
  1677.           if (howto->pc_relative)
  1678.             relocation += input_section->vma;
  1679.         }
  1680.  
  1681.           r = _bfd_final_link_relocate (howto,
  1682.                         input_bfd,
  1683.                         input_section,
  1684.                         contents,
  1685.                         r_vaddr - input_section->vma,
  1686.                         relocation,
  1687.                         addend);
  1688.         }
  1689.  
  1690.       if (r != bfd_reloc_ok)
  1691.         {
  1692.           switch (r)
  1693.         {
  1694.         default:
  1695.         case bfd_reloc_outofrange:
  1696.           abort ();
  1697.         case bfd_reloc_overflow:
  1698.           if (! ((*info->callbacks->reloc_overflow)
  1699.              (info, input_bfd, input_section,
  1700.               r_vaddr - input_section->vma)))
  1701.             return false;
  1702.           break;
  1703.         }
  1704.         }
  1705.     }
  1706.  
  1707.       if (info->relocateable && adjust_addrp)
  1708.     {
  1709.       /* Change the address of the relocation.  */
  1710.       bfd_h_put_64 (input_bfd,
  1711.             (input_section->output_section->vma
  1712.              + input_section->output_offset
  1713.              - input_section->vma
  1714.              + r_vaddr),
  1715.             (bfd_byte *) ext_rel->r_vaddr);
  1716.     }
  1717.  
  1718.       if (gp_usedp && gp_undefined)
  1719.     {
  1720.       if (! ((*info->callbacks->reloc_dangerous)
  1721.          (info, "GP relative relocation when GP not defined",
  1722.           input_bfd, input_section, r_vaddr - input_section->vma)))
  1723.         return false;
  1724.       /* Only give the error once per link.  */
  1725.       ecoff_data (output_bfd)->gp = gp = 4;
  1726.       gp_undefined = false;
  1727.     }
  1728.     }
  1729.  
  1730.   if (tos != 0)
  1731.     abort ();
  1732.  
  1733.   return true;
  1734. }
  1735.  
  1736. #define ecoff_core_file_p _bfd_dummy_target
  1737. #define ecoff_core_file_failing_command    _bfd_dummy_core_file_failing_command
  1738. #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
  1739. #define ecoff_core_file_matches_executable_p \
  1740.   _bfd_dummy_core_file_matches_executable_p
  1741.  
  1742. /* This is the ECOFF backend structure.  The backend field of the
  1743.    target vector points to this.  */
  1744.  
  1745. static const struct ecoff_backend_data alpha_ecoff_backend_data =
  1746. {
  1747.   /* COFF backend structure.  */
  1748.   {
  1749.     (void (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_in */
  1750.     (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */
  1751.     (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */
  1752.     (unsigned (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_out */
  1753.     (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */
  1754.     (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */
  1755.     (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* reloc_out */
  1756.     alpha_ecoff_swap_filehdr_out, alpha_ecoff_swap_aouthdr_out,
  1757.     alpha_ecoff_swap_scnhdr_out,
  1758.     FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true,
  1759.     alpha_ecoff_swap_filehdr_in, alpha_ecoff_swap_aouthdr_in,
  1760.     alpha_ecoff_swap_scnhdr_in, alpha_ecoff_bad_format_hook,
  1761.     ecoff_set_arch_mach_hook, ecoff_mkobject_hook,
  1762.     ecoff_styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook,
  1763.     ecoff_slurp_symbol_table, NULL, NULL
  1764.   },
  1765.   /* Supported architecture.  */
  1766.   bfd_arch_alpha,
  1767.   /* Initial portion of armap string.  */
  1768.   "________64",
  1769.   /* The page boundary used to align sections in a demand-paged
  1770.      executable file.  E.g., 0x1000.  */
  1771.   0x2000,
  1772.   /* True if the .rdata section is part of the text segment, as on the
  1773.      Alpha.  False if .rdata is part of the data segment, as on the
  1774.      MIPS.  */
  1775.   true,
  1776.   /* Bitsize of constructor entries.  */
  1777.   64,
  1778.   /* Reloc to use for constructor entries.  */
  1779.   &alpha_howto_table[ALPHA_R_REFQUAD],
  1780.   {
  1781.     /* Symbol table magic number.  */
  1782.     magicSym2,
  1783.     /* Alignment of debugging information.  E.g., 4.  */
  1784.     8,
  1785.     /* Sizes of external symbolic information.  */
  1786.     sizeof (struct hdr_ext),
  1787.     sizeof (struct dnr_ext),
  1788.     sizeof (struct pdr_ext),
  1789.     sizeof (struct sym_ext),
  1790.     sizeof (struct opt_ext),
  1791.     sizeof (struct fdr_ext),
  1792.     sizeof (struct rfd_ext),
  1793.     sizeof (struct ext_ext),
  1794.     /* Functions to swap in external symbolic data.  */
  1795.     ecoff_swap_hdr_in,
  1796.     ecoff_swap_dnr_in,
  1797.     ecoff_swap_pdr_in,
  1798.     ecoff_swap_sym_in,
  1799.     ecoff_swap_opt_in,
  1800.     ecoff_swap_fdr_in,
  1801.     ecoff_swap_rfd_in,
  1802.     ecoff_swap_ext_in,
  1803.     /* Functions to swap out external symbolic data.  */
  1804.     ecoff_swap_hdr_out,
  1805.     ecoff_swap_dnr_out,
  1806.     ecoff_swap_pdr_out,
  1807.     ecoff_swap_sym_out,
  1808.     ecoff_swap_opt_out,
  1809.     ecoff_swap_fdr_out,
  1810.     ecoff_swap_rfd_out,
  1811.     ecoff_swap_ext_out
  1812.   },
  1813.   /* External reloc size.  */
  1814.   RELSZ,
  1815.   /* Reloc swapping functions.  */
  1816.   alpha_ecoff_swap_reloc_in,
  1817.   alpha_ecoff_swap_reloc_out,
  1818.   /* Backend reloc tweaking.  */
  1819.   alpha_adjust_reloc_in,
  1820.   alpha_adjust_reloc_out,
  1821.   /* Relocate section contents while linking.  */
  1822.   alpha_relocate_section
  1823. };
  1824.  
  1825. /* Looking up a reloc type is Alpha specific.  */
  1826. #define ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup
  1827.  
  1828. /* So is getting relocated section contents.  */
  1829. #define ecoff_bfd_get_relocated_section_contents \
  1830.   alpha_ecoff_get_relocated_section_contents
  1831.  
  1832. bfd_target ecoffalpha_little_vec =
  1833. {
  1834.   "ecoff-littlealpha",        /* name */
  1835.   bfd_target_ecoff_flavour,
  1836.   false,            /* data byte order is little */
  1837.   false,            /* header byte order is little */
  1838.  
  1839.   (HAS_RELOC | EXEC_P |        /* object flags */
  1840.    HAS_LINENO | HAS_DEBUG |
  1841.    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  1842.  
  1843.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect
  1844.                                 flags */
  1845.   0,                /* leading underscore */
  1846.   ' ',                /* ar_pad_char */
  1847.   15,                /* ar_max_namelen */
  1848.   4,                /* minimum alignment power */
  1849.   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  1850.      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  1851.      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
  1852.   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  1853.      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  1854.      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
  1855.  
  1856.   {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  1857.      ecoff_archive_p, _bfd_dummy_target},
  1858.   {bfd_false, ecoff_mkobject,  /* bfd_set_format */
  1859.      _bfd_generic_mkarchive, bfd_false},
  1860.   {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
  1861.      _bfd_write_archive_contents, bfd_false},
  1862.   JUMP_TABLE (ecoff),
  1863.   (PTR) &alpha_ecoff_backend_data
  1864. };
  1865.