home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / bfd / coff-alpha.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  71KB  |  2,400 lines

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