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