Update to ISO-C90 and fix formatting
[external/binutils.git] / bfd / vms.c
1 /* vms.c -- BFD back-end for VAX (openVMS/VAX) and
2    EVAX (openVMS/Alpha) files.
3    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4    Free Software Foundation, Inc.
5
6    Written by Klaus K"ampf (kkaempf@rmi.de)
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
27 #include "vms.h"
28
29 #define vms_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
30 #define vms_make_empty_symbol             _bfd_generic_make_empty_symbol
31 #define vms_bfd_link_just_syms            _bfd_generic_link_just_syms
32 #define vms_bfd_is_group_section          bfd_generic_is_group_section
33 #define vms_bfd_discard_group             bfd_generic_discard_group
34 #define vms_section_already_linked        _bfd_generic_section_already_linked
35 #define vms_bfd_copy_private_header_data  _bfd_generic_bfd_copy_private_header_data
36 #define vms_get_synthetic_symtab          _bfd_nodynamic_get_synthetic_symtab
37
38 static unsigned int priv_section_count;
39 extern const bfd_target vms_vax_vec;
40 extern const bfd_target vms_alpha_vec;
41 \f
42 /* Initialize private data.  */
43
44 static bfd_boolean
45 vms_initialize (bfd * abfd)
46 {
47   int i;
48   bfd_size_type amt;
49
50   bfd_set_start_address (abfd, (bfd_vma) -1);
51
52   amt = sizeof (struct vms_private_data_struct);
53   abfd->tdata.any = bfd_alloc (abfd, amt);
54   if (abfd->tdata.any == NULL)
55     return FALSE;
56
57 #ifdef __ALPHA
58   PRIV (is_vax) = FALSE;
59 #else
60   PRIV (is_vax) = TRUE;
61 #endif
62   PRIV (vms_buf) = NULL;
63   PRIV (buf_size) = 0;
64   PRIV (rec_length) = 0;
65   PRIV (file_format) = FF_UNKNOWN;
66   PRIV (fixup_done) = FALSE;
67   PRIV (sections) = NULL;
68
69   amt = sizeof (struct stack_struct) * STACKSIZE;
70   PRIV (stack) = bfd_alloc (abfd, amt);
71   if (PRIV (stack) == NULL)
72     goto error_ret1;
73   PRIV (stackptr) = 0;
74
75   amt = sizeof (struct bfd_hash_table);
76   PRIV (vms_symbol_table) = bfd_alloc (abfd, amt);
77   if (PRIV (vms_symbol_table) == NULL)
78     goto error_ret1;
79
80   if (!bfd_hash_table_init (PRIV (vms_symbol_table), _bfd_vms_hash_newfunc))
81     goto error_ret1;
82
83   amt = sizeof (struct location_struct) * LOCATION_SAVE_SIZE;
84   PRIV (location_stack) = bfd_alloc (abfd, amt);
85   if (PRIV (location_stack) == NULL)
86     goto error_ret2;
87
88   for (i = 0; i < VMS_SECTION_COUNT; i++)
89     PRIV (vms_section_table)[i] = NULL;
90
91   amt = MAX_OUTREC_SIZE;
92   PRIV (output_buf) = bfd_alloc (abfd, amt);
93   if (PRIV (output_buf) == NULL)
94     goto error_ret2;
95
96   PRIV (push_level) = 0;
97   PRIV (pushed_size) = 0;
98   PRIV (length_pos) = 2;
99   PRIV (output_size) = 0;
100   PRIV (output_alignment) = 1;
101
102   return TRUE;
103
104  error_ret2:
105   bfd_hash_table_free (PRIV (vms_symbol_table));
106  error_ret1:
107   bfd_release (abfd, abfd->tdata.any);
108   abfd->tdata.any = NULL;
109   return FALSE;
110 }
111
112 /* Fill symbol->section with section ptr
113    symbol->section is filled with the section index for defined symbols
114    during reading the GSD/EGSD section. But we need the pointer to the
115    bfd section later.
116
117    It has the correct value for referenced (undefined section) symbols
118
119    called from bfd_hash_traverse in vms_fixup_sections.  */
120
121 static bfd_boolean
122 fill_section_ptr (struct bfd_hash_entry * entry, void * sections)
123 {
124   asection *sec;
125   asymbol *sym;
126
127   sym = ((vms_symbol_entry *) entry)->symbol;
128   sec = sym->section;
129
130 #if VMS_DEBUG
131   vms_debug (6, "fill_section_ptr: sym %p, sec %p\n", sym, sec);
132 #endif
133
134   /* Fill forward references (these contain section number, not section ptr).  */
135   if ((unsigned int) (size_t) sec < priv_section_count)
136     sec = ((vms_symbol_entry *) entry)->symbol->section =
137       ((asection **) sections)[(unsigned int) (size_t) sec];
138
139   if (strcmp (sym->name, sec->name) == 0)
140     sym->flags |= BSF_SECTION_SYM;
141
142   return TRUE;
143 }
144
145 /* Fixup sections
146    set up all pointers and arrays, counters and sizes are fixed now
147
148    we build a private sections vector for easy access since sections
149    are always referenced by an index number.
150
151    alloc PRIV(sections) according to abfd->section_count
152         copy abfd->sections to PRIV(sections).  */
153
154 static bfd_boolean
155 vms_fixup_sections (bfd * abfd)
156 {
157   if (PRIV (fixup_done))
158     return TRUE;
159
160   /* Traverse symbol table and fill in all section pointers.  */
161
162   /* Can't provide section count as argument to fill_section_ptr().  */
163   priv_section_count = PRIV (section_count);
164   bfd_hash_traverse (PRIV (vms_symbol_table), fill_section_ptr, (PRIV (sections)));
165
166   PRIV (fixup_done) = TRUE;
167
168   return TRUE;
169 }
170 \f
171 /* Check the format for a file being read.
172    Return a (bfd_target *) if it's an object file or zero if not.  */
173
174 static const struct bfd_target *
175 vms_object_p (bfd * abfd)
176 {
177   int err = 0;
178   int prev_type;
179   const struct bfd_target *target_vector = NULL;
180   const bfd_arch_info_type *arch = NULL;
181   void * tdata_save = abfd->tdata.any;
182   bfd_vma saddr_save = bfd_get_start_address (abfd);
183
184 #if VMS_DEBUG
185   vms_debug (1, "vms_object_p (%p)\n", abfd);
186 #endif
187
188   if (!vms_initialize (abfd))
189     goto error_ret;
190
191   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET))
192     goto err_wrong_format;
193
194   prev_type = -1;
195
196   do
197     {
198 #if VMS_DEBUG
199       vms_debug (7, "reading at %08lx\n", bfd_tell (abfd));
200 #endif
201       if (_bfd_vms_next_record (abfd) < 0)
202         {
203 #if VMS_DEBUG
204           vms_debug (2, "next_record failed\n");
205 #endif
206           goto err_wrong_format;
207         }
208
209       if ((prev_type == EOBJ_S_C_EGSD)
210            && (PRIV (rec_type) != EOBJ_S_C_EGSD))
211         {
212           if (! vms_fixup_sections (abfd))
213             {
214 #if VMS_DEBUG
215               vms_debug (2, "vms_fixup_sections failed\n");
216 #endif
217               goto err_wrong_format;
218             }
219         }
220
221       prev_type = PRIV (rec_type);
222
223       if (target_vector == NULL)
224         {
225           if (prev_type <= OBJ_S_C_MAXRECTYP)
226             target_vector = & vms_vax_vec;
227           else
228             target_vector = & vms_alpha_vec;
229         }
230
231       switch (prev_type)
232         {
233           case OBJ_S_C_HDR:
234           case EOBJ_S_C_EMH:
235             err = _bfd_vms_slurp_hdr (abfd, prev_type);
236             break;
237           case OBJ_S_C_EOM:
238           case OBJ_S_C_EOMW:
239           case EOBJ_S_C_EEOM:
240             err = _bfd_vms_slurp_eom (abfd, prev_type);
241             break;
242           case OBJ_S_C_GSD:
243           case EOBJ_S_C_EGSD:
244             err = _bfd_vms_slurp_gsd (abfd, prev_type);
245             break;
246           case OBJ_S_C_TIR:
247           case EOBJ_S_C_ETIR:
248             err = _bfd_vms_slurp_tir (abfd, prev_type);
249             break;
250           case OBJ_S_C_DBG:
251           case EOBJ_S_C_EDBG:
252             err = _bfd_vms_slurp_dbg (abfd, prev_type);
253             break;
254           case OBJ_S_C_TBT:
255           case EOBJ_S_C_ETBT:
256             err = _bfd_vms_slurp_tbt (abfd, prev_type);
257             break;
258           case OBJ_S_C_LNK:
259             err = _bfd_vms_slurp_lnk (abfd, prev_type);
260             break;
261           default:
262             err = -1;
263         }
264       if (err != 0)
265         {
266 #if VMS_DEBUG
267           vms_debug (2, "slurp type %d failed with %d\n", prev_type, err);
268 #endif
269           goto err_wrong_format;
270         }
271     }
272   while ((prev_type != EOBJ_S_C_EEOM) && (prev_type != OBJ_S_C_EOM) && (prev_type != OBJ_S_C_EOMW));
273
274   if (target_vector == & vms_vax_vec)
275     {
276       if (! vms_fixup_sections (abfd))
277         {
278 #if VMS_DEBUG
279           vms_debug (2, "vms_fixup_sections failed\n");
280 #endif
281           goto err_wrong_format;
282         }
283
284       /* Set arch_info to vax.  */
285
286       arch = bfd_scan_arch ("vax");
287       PRIV (is_vax) = TRUE;
288 #if VMS_DEBUG
289       vms_debug (2, "arch is vax\n");
290 #endif
291     }
292   else if (target_vector == & vms_alpha_vec)
293     {
294       /* Set arch_info to alpha.   */
295
296       arch = bfd_scan_arch ("alpha");
297       PRIV (is_vax) = FALSE;
298 #if VMS_DEBUG
299       vms_debug (2, "arch is alpha\n");
300 #endif
301     }
302
303   if (arch == NULL)
304     {
305 #if VMS_DEBUG
306       vms_debug (2, "arch not found\n");
307 #endif
308       goto err_wrong_format;
309     }
310   abfd->arch_info = arch;
311
312   return target_vector;
313
314  err_wrong_format:
315   bfd_set_error (bfd_error_wrong_format);
316  error_ret:
317   if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
318     bfd_release (abfd, abfd->tdata.any);
319   abfd->tdata.any = tdata_save;
320   bfd_set_start_address (abfd, saddr_save);
321   return NULL;
322 }
323
324 /* Check the format for a file being read.
325    Return a (bfd_target *) if it's an archive file or zero.  */
326
327 static const struct bfd_target *
328 vms_archive_p (bfd * abfd ATTRIBUTE_UNUSED)
329 {
330 #if VMS_DEBUG
331   vms_debug (1, "vms_archive_p (%p)\n", abfd);
332 #endif
333
334   return NULL;
335 }
336
337 /* Set the format of a file being written.  */
338
339 static bfd_boolean
340 vms_mkobject (bfd * abfd)
341 {
342 #if VMS_DEBUG
343   vms_debug (1, "vms_mkobject (%p)\n", abfd);
344 #endif
345
346   if (!vms_initialize (abfd))
347     return FALSE;
348
349   {
350 #ifdef __VAX
351     const bfd_arch_info_type *arch = bfd_scan_arch ("vax");
352 #else
353     const bfd_arch_info_type *arch = bfd_scan_arch ("alpha");
354 #endif
355     if (arch == NULL)
356       {
357         bfd_set_error (bfd_error_wrong_format);
358         return FALSE;
359       }
360     abfd->arch_info = arch;
361   }
362
363   return TRUE;
364 }
365
366 /* Write cached information into a file being written, at bfd_close.  */
367
368 static bfd_boolean
369 vms_write_object_contents (bfd * abfd)
370 {
371 #if VMS_DEBUG
372   vms_debug (1, "vms_write_object_contents (%p)\n", abfd);
373 #endif
374
375   if (abfd->section_count > 0)                  /* we have sections */
376     {
377       if (PRIV (is_vax))
378         {
379           if (_bfd_vms_write_hdr (abfd, OBJ_S_C_HDR) != 0)
380             return FALSE;
381           if (_bfd_vms_write_gsd (abfd, OBJ_S_C_GSD) != 0)
382             return FALSE;
383           if (_bfd_vms_write_tir (abfd, OBJ_S_C_TIR) != 0)
384             return FALSE;
385           if (_bfd_vms_write_tbt (abfd, OBJ_S_C_TBT) != 0)
386             return FALSE;
387           if (_bfd_vms_write_dbg (abfd, OBJ_S_C_DBG) != 0)
388             return FALSE;
389           if (abfd->section_count > 255)
390             {
391               if (_bfd_vms_write_eom (abfd, OBJ_S_C_EOMW) != 0)
392                 return FALSE;
393             }
394           else
395             {
396               if (_bfd_vms_write_eom (abfd, OBJ_S_C_EOM) != 0)
397                 return FALSE;
398             }
399         }
400       else
401         {
402           if (_bfd_vms_write_hdr (abfd, EOBJ_S_C_EMH) != 0)
403             return FALSE;
404           if (_bfd_vms_write_gsd (abfd, EOBJ_S_C_EGSD) != 0)
405             return FALSE;
406           if (_bfd_vms_write_tir (abfd, EOBJ_S_C_ETIR) != 0)
407             return FALSE;
408           if (_bfd_vms_write_tbt (abfd, EOBJ_S_C_ETBT) != 0)
409             return FALSE;
410           if (_bfd_vms_write_dbg (abfd, EOBJ_S_C_EDBG) != 0)
411             return FALSE;
412           if (_bfd_vms_write_eom (abfd, EOBJ_S_C_EEOM) != 0)
413             return FALSE;
414         }
415     }
416   return TRUE;
417 }
418
419 /* 4.1, generic.  */
420
421 /* Called when the BFD is being closed to do any necessary cleanup.  */
422
423 static bfd_boolean
424 vms_close_and_cleanup (bfd * abfd)
425 {
426 #if VMS_DEBUG
427   vms_debug (1, "vms_close_and_cleanup (%p)\n", abfd);
428 #endif
429   if (abfd == NULL)
430     return TRUE;
431
432   if (PRIV (vms_buf) != NULL)
433     free (PRIV (vms_buf));
434
435   if (PRIV (sections) != NULL)
436     free (PRIV (sections));
437
438   if (PRIV (vms_symbol_table))
439     bfd_hash_table_free (PRIV (vms_symbol_table));
440
441   bfd_release (abfd, abfd->tdata.any);
442   abfd->tdata.any = NULL;
443
444   return TRUE;
445 }
446
447 /* Ask the BFD to free all cached information.  */
448
449 static bfd_boolean
450 vms_bfd_free_cached_info (bfd * abfd ATTRIBUTE_UNUSED)
451 {
452 #if VMS_DEBUG
453   vms_debug (1, "vms_bfd_free_cached_info (%p)\n", abfd);
454 #endif
455   return TRUE;
456 }
457
458 /* Called when a new section is created.  */
459
460 static bfd_boolean
461 vms_new_section_hook (bfd * abfd, asection *section)
462 {
463   /* Count hasn't been incremented yet.  */
464   unsigned int section_count = abfd->section_count + 1;
465
466 #if VMS_DEBUG
467   vms_debug (1, "vms_new_section_hook (%p, [%d]%s), count %d\n",
468              abfd, section->index, section->name, section_count);
469 #endif
470   bfd_set_section_alignment (abfd, section, 4);
471
472   if (section_count > PRIV (section_count))
473     {
474       bfd_size_type amt = section_count;
475       amt *= sizeof (asection *);
476       PRIV (sections) = bfd_realloc (PRIV (sections), amt);
477       if (PRIV (sections) == NULL)
478         return FALSE;
479       PRIV (section_count) = section_count;
480     }
481 #if VMS_DEBUG
482   vms_debug (6, "section_count: %d\n", PRIV (section_count));
483 #endif
484   PRIV (sections)[section->index] = section;
485 #if VMS_DEBUG
486   vms_debug (7, "%d: %s\n", section->index, section->name);
487 #endif
488
489   return TRUE;
490 }
491
492 /* Read the contents of a section.
493    buf points to a buffer of buf_size bytes to be filled with
494    section data (starting at offset into section)  */
495
496 static bfd_boolean
497 vms_get_section_contents (bfd * abfd ATTRIBUTE_UNUSED,
498                           asection *section ATTRIBUTE_UNUSED,
499                           void * buf ATTRIBUTE_UNUSED,
500                           file_ptr offset ATTRIBUTE_UNUSED,
501                           bfd_size_type buf_size ATTRIBUTE_UNUSED)
502 {
503 #if VMS_DEBUG
504   vms_debug (1, "vms_get_section_contents (%p, %s, %p, off %ld, size %d)\n",
505                  abfd, section->name, buf, offset, (int)buf_size);
506 #endif
507
508   /* Shouldn't be called, since all sections are IN_MEMORY.  */
509   return FALSE;
510 }
511
512 /* Read the contents of a section.
513    buf points to a buffer of buf_size bytes to be filled with
514    section data (starting at offset into section).  */
515
516 static bfd_boolean
517 vms_get_section_contents_in_window (bfd * abfd ATTRIBUTE_UNUSED,
518                                     asection *section ATTRIBUTE_UNUSED,
519                                     bfd_window *w ATTRIBUTE_UNUSED,
520                                     file_ptr offset ATTRIBUTE_UNUSED,
521                                     bfd_size_type count ATTRIBUTE_UNUSED)
522 {
523 #if VMS_DEBUG
524   vms_debug (1, "vms_get_section_contents_in_window (%p, %s, %p, off %ld, count %d)\n",
525                  abfd, section->name, w, offset, (int)count);
526 #endif
527
528   /* Shouldn't be called, since all sections are IN_MEMORY.  */
529   return FALSE;
530 }
531
532 /* Part 4.2, copy private data.  */
533
534 /* Called to copy BFD general private data from one object file
535    to another.  */
536
537 static bfd_boolean
538 vms_bfd_copy_private_bfd_data (bfd *src ATTRIBUTE_UNUSED,
539                                bfd *dest ATTRIBUTE_UNUSED)
540 {
541 #if VMS_DEBUG
542   vms_debug (1, "vms_bfd_copy_private_bfd_data (%p, %p)\n", src, dest);
543 #endif
544   return TRUE;
545 }
546
547 /* Merge private BFD information from the BFD @var{ibfd} to the
548    the output file BFD @var{obfd} when linking.  Return <<TRUE>>
549    on success, <<FALSE>> on error.  Possible error returns are:
550
551    o <<bfd_error_no_memory>> -
552      Not enough memory exists to create private data for @var{obfd}.  */
553
554 static bfd_boolean
555 vms_bfd_merge_private_bfd_data (bfd * ibfd ATTRIBUTE_UNUSED,
556                                 bfd * obfd ATTRIBUTE_UNUSED)
557 {
558 #if VMS_DEBUG
559   vms_debug (1,"vms_bfd_merge_private_bfd_data (%p, %p)\n", ibfd, obfd);
560 #endif
561   return TRUE;
562 }
563
564 /* Set private BFD flag information in the BFD @var{abfd}.
565    Return <<TRUE>> on success, <<FALSE>> on error.  Possible error
566    returns are:
567
568    o <<bfd_error_no_memory>> -
569      Not enough memory exists to create private data for @var{obfd}.  */
570
571 static bfd_boolean
572 vms_bfd_set_private_flags (bfd * abfd ATTRIBUTE_UNUSED,
573                            flagword flags ATTRIBUTE_UNUSED)
574 {
575 #if VMS_DEBUG
576   vms_debug (1,"vms_bfd_set_private_flags (%p, %lx)\n", abfd, (long)flags);
577 #endif
578   return TRUE;
579 }
580
581 /* Called to copy BFD private section data from one object file
582    to another.  */
583
584 static bfd_boolean
585 vms_bfd_copy_private_section_data (bfd *srcbfd ATTRIBUTE_UNUSED,
586                                    asection *srcsec ATTRIBUTE_UNUSED,
587                                    bfd *dstbfd ATTRIBUTE_UNUSED,
588                                    asection *dstsec ATTRIBUTE_UNUSED)
589 {
590 #if VMS_DEBUG
591   vms_debug (1, "vms_bfd_copy_private_section_data (%p, %s, %p, %s)\n",
592                  srcbfd, srcsec->name, dstbfd, dstsec->name);
593 #endif
594   return TRUE;
595 }
596
597 /* Called to copy BFD private symbol data from one object file
598    to another.  */
599
600 static bfd_boolean
601 vms_bfd_copy_private_symbol_data (bfd *ibfd ATTRIBUTE_UNUSED,
602                                   asymbol *isym ATTRIBUTE_UNUSED,
603                                   bfd *obfd ATTRIBUTE_UNUSED,
604                                   asymbol *osym ATTRIBUTE_UNUSED)
605 {
606 #if VMS_DEBUG
607   vms_debug (1, "vms_bfd_copy_private_symbol_data (%p, %s, %p, %s)\n",
608                  ibfd, isym->name, obfd, osym->name);
609 #endif
610   return TRUE;
611 }
612
613 /* Part 4.3, core file.  */
614
615 /* Return a read-only string explaining which program was running
616    when it failed and produced the core file abfd.  */
617
618 static char *
619 vms_core_file_failing_command (bfd * abfd ATTRIBUTE_UNUSED)
620 {
621 #if VMS_DEBUG
622   vms_debug (1, "vms_core_file_failing_command (%p)\n", abfd);
623 #endif
624   return NULL;
625 }
626
627 /* Returns the signal number which caused the core dump which
628    generated the file the BFD abfd is attached to.  */
629
630 static int
631 vms_core_file_failing_signal (bfd * abfd ATTRIBUTE_UNUSED)
632 {
633 #if VMS_DEBUG
634   vms_debug (1, "vms_core_file_failing_signal (%p)\n", abfd);
635 #endif
636   return 0;
637 }
638
639 /* Return TRUE if the core file attached to core_bfd was generated
640    by a run of the executable file attached to exec_bfd, FALSE otherwise.  */
641
642 static bfd_boolean
643 vms_core_file_matches_executable_p (bfd * abfd ATTRIBUTE_UNUSED,
644                                     bfd *bbfd ATTRIBUTE_UNUSED)
645 {
646 #if VMS_DEBUG
647   vms_debug (1, "vms_core_file_matches_executable_p (%p, %p)\n", abfd, bbfd);
648 #endif
649   return FALSE;
650 }
651
652 /* Part 4.4, archive.  */
653
654 /* ???  do something with an archive map.
655    Return FALSE on error, TRUE otherwise.  */
656
657 static bfd_boolean
658 vms_slurp_armap (bfd * abfd ATTRIBUTE_UNUSED)
659 {
660 #if VMS_DEBUG
661   vms_debug (1, "vms_slurp_armap (%p)\n", abfd);
662 #endif
663   return FALSE;
664 }
665
666 /* ???  do something with an extended name table.
667    Return FALSE on error, TRUE otherwise.  */
668
669 static bfd_boolean
670 vms_slurp_extended_name_table (bfd * abfd ATTRIBUTE_UNUSED)
671 {
672 #if VMS_DEBUG
673   vms_debug (1, "vms_slurp_extended_name_table (%p)\n", abfd);
674 #endif
675   return FALSE;
676 }
677
678 /* ???  do something with an extended name table.
679    Return FALSE on error, TRUE otherwise.  */
680
681 static bfd_boolean
682 vms_construct_extended_name_table (bfd * abfd ATTRIBUTE_UNUSED,
683                                    char **tabloc ATTRIBUTE_UNUSED,
684                                    bfd_size_type *tablen ATTRIBUTE_UNUSED,
685                                    const char **name ATTRIBUTE_UNUSED)
686 {
687 #if VMS_DEBUG
688   vms_debug (1, "vms_construct_extended_name_table (%p)\n", abfd);
689 #endif
690   return FALSE;
691 }
692
693 /* Truncate the name of an archive to match system-dependent restrictions.  */
694
695 static void
696 vms_truncate_arname (bfd * abfd ATTRIBUTE_UNUSED,
697                      const char *pathname ATTRIBUTE_UNUSED,
698                      char *arhdr ATTRIBUTE_UNUSED)
699 {
700 #if VMS_DEBUG
701   vms_debug (1, "vms_truncate_arname (%p, %s, %s)\n", abfd, pathname, arhdr);
702 #endif
703   return;
704 }
705
706 /* ???  write archive map.  */
707
708 static bfd_boolean
709 vms_write_armap (bfd *arch ATTRIBUTE_UNUSED,
710                  unsigned int elength ATTRIBUTE_UNUSED,
711                  struct orl *map ATTRIBUTE_UNUSED,
712                  unsigned int orl_count ATTRIBUTE_UNUSED,
713                  int stridx ATTRIBUTE_UNUSED)
714 {
715 #if VMS_DEBUG
716   vms_debug (1, "vms_write_armap (%p, %d, %p, %d %d)\n",
717         arch, elength, map, orl_count, stridx);
718 #endif
719   return TRUE;
720 }
721
722 /* Read archive header ???  */
723
724 static void *
725 vms_read_ar_hdr (bfd * abfd ATTRIBUTE_UNUSED)
726 {
727 #if VMS_DEBUG
728   vms_debug (1, "vms_read_ar_hdr (%p)\n", abfd);
729 #endif
730   return NULL;
731 }
732
733 /* Provided a BFD, @var{archive}, containing an archive and NULL, open
734    an input BFD on the first contained element and returns that.
735    Subsequent calls should pass the archive and the previous return value
736    to return a created BFD to the next contained element.
737    NULL is returned when there are no more.  */
738
739 static bfd *
740 vms_openr_next_archived_file (bfd *arch ATTRIBUTE_UNUSED,
741                               bfd *prev ATTRIBUTE_UNUSED)
742 {
743 #if VMS_DEBUG
744   vms_debug (1, "vms_openr_next_archived_file (%p, %p)\n", arch, prev);
745 #endif
746   return NULL;
747 }
748
749 /* Return the BFD which is referenced by the symbol in ABFD indexed by
750    INDEX.  INDEX should have been returned by bfd_get_next_mapent.  */
751
752 static bfd *
753 vms_get_elt_at_index (bfd * abfd, symindex index)
754 {
755 #if VMS_DEBUG
756   vms_debug (1, "vms_get_elt_at_index (%p, %p)\n", abfd, index);
757 #endif
758   return _bfd_generic_get_elt_at_index (abfd, index);
759 }
760
761 /* ???
762    -> bfd_generic_stat_arch_elt.  */
763
764 static int
765 vms_generic_stat_arch_elt (bfd * abfd, struct stat *st)
766 {
767 #if VMS_DEBUG
768   vms_debug (1, "vms_generic_stat_arch_elt (%p, %p)\n", abfd, st);
769 #endif
770   return bfd_generic_stat_arch_elt (abfd, st);
771 }
772
773 /* This is a new function in bfd 2.5.  */
774
775 static bfd_boolean
776 vms_update_armap_timestamp (bfd * abfd ATTRIBUTE_UNUSED)
777 {
778 #if VMS_DEBUG
779   vms_debug (1, "vms_update_armap_timestamp (%p)\n", abfd);
780 #endif
781   return TRUE;
782 }
783
784 /* Part 4.5, symbols.  */
785
786 /* Return the number of bytes required to store a vector of pointers
787    to asymbols for all the symbols in the BFD abfd, including a
788    terminal NULL pointer. If there are no symbols in the BFD,
789    then return 0.  If an error occurs, return -1.  */
790
791 static long
792 vms_get_symtab_upper_bound (bfd * abfd)
793 {
794 #if VMS_DEBUG
795   vms_debug (1, "vms_get_symtab_upper_bound (%p), %d symbols\n", abfd, PRIV (gsd_sym_count));
796 #endif
797   return (PRIV (gsd_sym_count) + 1) * sizeof (asymbol *);
798 }
799
800 /* Copy symbols from hash table to symbol vector
801
802    called from bfd_hash_traverse in vms_canonicalize_symtab
803    init counter to 0 if entry == 0.  */
804
805 static bfd_boolean
806 copy_symbols (struct bfd_hash_entry *entry, void * arg)
807 {
808   bfd * abfd = (bfd *) arg;
809
810   if (entry == NULL)    /* Init counter.  */
811     PRIV (symnum) = 0;
812   else                  /* Fill vector, inc counter.  */
813     PRIV (symcache)[PRIV (symnum)++] = ((vms_symbol_entry *)entry)->symbol;
814
815   return TRUE;
816 }
817
818 /* Read the symbols from the BFD abfd, and fills in the vector
819    location with pointers to the symbols and a trailing NULL.
820
821    Return number of symbols read.   */
822
823 static long
824 vms_canonicalize_symtab (bfd * abfd, asymbol **symbols)
825 {
826 #if VMS_DEBUG
827   vms_debug (1, "vms_canonicalize_symtab (%p, <ret>)\n", abfd);
828 #endif
829
830   /* Init counter.  */
831   copy_symbols (NULL, abfd);
832
833   /* Traverse table and fill symbols vector.  */
834   PRIV (symcache) = symbols;
835   bfd_hash_traverse (PRIV (vms_symbol_table), copy_symbols, abfd);
836
837   symbols[PRIV (gsd_sym_count)] = NULL;
838
839   return PRIV (gsd_sym_count);
840 }
841
842 /* Print symbol to file according to how. how is one of
843    bfd_print_symbol_name        just print the name
844    bfd_print_symbol_more        print more (???)
845    bfd_print_symbol_all print all we know, which is not much right now :-).  */
846
847 static void
848 vms_print_symbol (bfd * abfd,
849                   void * file,
850                   asymbol *symbol,
851                   bfd_print_symbol_type how)
852 {
853 #if VMS_DEBUG
854   vms_debug (1, "vms_print_symbol (%p, %p, %p, %d)\n", abfd, file, symbol, how);
855 #endif
856
857   switch (how)
858     {
859       case bfd_print_symbol_name:
860       case bfd_print_symbol_more:
861         fprintf ((FILE *)file," %s", symbol->name);
862       break;
863
864       case bfd_print_symbol_all:
865         {
866           const char *section_name = symbol->section->name;
867
868           bfd_print_symbol_vandf (abfd, file, symbol);
869
870           fprintf ((FILE *) file," %-8s %s", section_name, symbol->name);
871         }
872       break;
873     }
874 }
875
876 /* Return information about symbol in ret.
877
878    fill type, value and name
879    type:
880         A       absolute
881         B       bss segment symbol
882         C       common symbol
883         D       data segment symbol
884         f       filename
885         t       a static function symbol
886         T       text segment symbol
887         U       undefined
888         -       debug.  */
889
890 static void
891 vms_get_symbol_info (bfd * abfd ATTRIBUTE_UNUSED,
892                      asymbol *symbol,
893                      symbol_info *ret)
894 {
895   asection *sec;
896
897 #if VMS_DEBUG
898   vms_debug (1, "vms_get_symbol_info (%p, %p, %p)\n", abfd, symbol, ret);
899 #endif
900
901   sec = symbol->section;
902
903   if (ret == NULL)
904     return;
905
906   if (bfd_is_com_section (sec))
907     ret->type = 'C';
908   else if (bfd_is_abs_section (sec))
909     ret->type = 'A';
910   else if (bfd_is_und_section (sec))
911     ret->type = 'U';
912   else if (bfd_is_ind_section (sec))
913     ret->type = 'I';
914   else if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
915     ret->type = 'T';
916   else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
917     ret->type = 'D';
918   else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
919     ret->type = 'B';
920   else
921     ret->type = '-';
922
923   if (ret->type != 'U')
924     ret->value = symbol->value + symbol->section->vma;
925   else
926     ret->value = 0;
927   ret->name = symbol->name;
928 }
929
930 /* Return TRUE if the given symbol sym in the BFD abfd is
931    a compiler generated local label, else return FALSE.  */
932
933 static bfd_boolean
934 vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED,
935                              const char *name)
936 {
937 #if VMS_DEBUG
938   vms_debug (1, "vms_bfd_is_local_label_name (%p, %s)\n", abfd, name);
939 #endif
940   return name[0] == '$';
941 }
942
943 /* Get source line number for symbol.  */
944
945 static alent *
946 vms_get_lineno (bfd * abfd ATTRIBUTE_UNUSED,
947                 asymbol *symbol ATTRIBUTE_UNUSED)
948 {
949 #if VMS_DEBUG
950   vms_debug (1, "vms_get_lineno (%p, %p)\n", abfd, symbol);
951 #endif
952   return NULL;
953 }
954
955 /* Provided a BFD, a section and an offset into the section, calculate and
956    return the name of the source file and the line nearest to the wanted
957    location.  */
958
959 static bfd_boolean
960 vms_find_nearest_line (bfd * abfd ATTRIBUTE_UNUSED,
961                        asection *section ATTRIBUTE_UNUSED,
962                        asymbol **symbols ATTRIBUTE_UNUSED,
963                        bfd_vma offset ATTRIBUTE_UNUSED,
964                        const char **file ATTRIBUTE_UNUSED,
965                        const char **func ATTRIBUTE_UNUSED,
966                        unsigned int *line ATTRIBUTE_UNUSED)
967 {
968 #if VMS_DEBUG
969   vms_debug (1, "vms_find_nearest_line (%p, %s, %p, %ld, <ret>, <ret>, <ret>)\n",
970               abfd, section->name, symbols, (long int)offset);
971 #endif
972   return FALSE;
973 }
974
975 /* Back-door to allow format-aware applications to create debug symbols
976    while using BFD for everything else.  Currently used by the assembler
977    when creating COFF files.  */
978
979 static asymbol *
980 vms_bfd_make_debug_symbol (bfd * abfd ATTRIBUTE_UNUSED,
981                            void *ptr ATTRIBUTE_UNUSED,
982                            unsigned long size ATTRIBUTE_UNUSED)
983 {
984 #if VMS_DEBUG
985   vms_debug (1, "vms_bfd_make_debug_symbol (%p, %p, %ld)\n", abfd, ptr, size);
986 #endif
987   return NULL;
988 }
989
990 /* Read minisymbols.  For minisymbols, we use the unmodified a.out
991    symbols.  The minisymbol_to_symbol function translates these into
992    BFD asymbol structures.  */
993
994 static long
995 vms_read_minisymbols (bfd * abfd,
996                       bfd_boolean dynamic,
997                       void * *minisymsp,
998                       unsigned int *sizep)
999 {
1000 #if VMS_DEBUG
1001   vms_debug (1, "vms_read_minisymbols (%p, %d, %p, %d)\n", abfd, dynamic, minisymsp, *sizep);
1002 #endif
1003   return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
1004 }
1005
1006 /* Convert a minisymbol to a BFD asymbol.  A minisymbol is just an
1007    unmodified a.out symbol.  The SYM argument is a structure returned
1008    by bfd_make_empty_symbol, which we fill in here.  */
1009
1010 static asymbol *
1011 vms_minisymbol_to_symbol (bfd * abfd,
1012                           bfd_boolean dynamic,
1013                           const void * minisym,
1014                           asymbol *sym)
1015 {
1016 #if VMS_DEBUG
1017   vms_debug (1, "vms_minisymbol_to_symbol (%p, %d, %p, %p)\n", abfd, dynamic, minisym, sym);
1018 #endif
1019   return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym);
1020 }
1021
1022 /* Part 4.6, relocations.  */
1023
1024 /* Return the number of bytes required to store the relocation information
1025    associated with section sect attached to bfd abfd.
1026    If an error occurs, return -1.  */
1027
1028 static long
1029 vms_get_reloc_upper_bound (bfd * abfd ATTRIBUTE_UNUSED,
1030                            asection *section ATTRIBUTE_UNUSED)
1031 {
1032 #if VMS_DEBUG
1033   vms_debug (1, "vms_get_reloc_upper_bound (%p, %s)\n", abfd, section->name);
1034 #endif
1035   return -1L;
1036 }
1037
1038 /* Call the back end associated with the open BFD abfd and translate the
1039    external form of the relocation information attached to sec into the
1040    internal canonical form.  Place the table into memory at loc, which has
1041    been preallocated, usually by a call to bfd_get_reloc_upper_bound.
1042    Returns the number of relocs, or -1 on error.  */
1043
1044 static long
1045 vms_canonicalize_reloc (bfd * abfd ATTRIBUTE_UNUSED,
1046                         asection *section ATTRIBUTE_UNUSED,
1047                         arelent **location ATTRIBUTE_UNUSED,
1048                         asymbol **symbols ATTRIBUTE_UNUSED)
1049 {
1050 #if VMS_DEBUG
1051   vms_debug (1, "vms_canonicalize_reloc (%p, %s, <ret>, <ret>)\n", abfd, section->name);
1052 #endif
1053   return FALSE;
1054 }
1055 \f
1056 /* This is just copied from ecoff-alpha, needs to be fixed probably.  */
1057
1058 /* How to process the various reloc types.  */
1059
1060 static bfd_reloc_status_type
1061 reloc_nil (bfd * abfd ATTRIBUTE_UNUSED,
1062            arelent *reloc ATTRIBUTE_UNUSED,
1063            asymbol *sym ATTRIBUTE_UNUSED,
1064            void * data ATTRIBUTE_UNUSED,
1065            asection *sec ATTRIBUTE_UNUSED,
1066            bfd *output_bfd ATTRIBUTE_UNUSED,
1067            char **error_message ATTRIBUTE_UNUSED)
1068 {
1069 #if VMS_DEBUG
1070   vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd, output_bfd);
1071   vms_debug (2, "In section %s, symbol %s\n",
1072         sec->name, sym->name);
1073   vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
1074                 reloc->sym_ptr_ptr[0]->name,
1075                 (unsigned long)reloc->address,
1076                 (unsigned long)reloc->addend, reloc->howto->name);
1077   vms_debug (2, "data at %p\n", data);
1078   /*  _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */
1079 #endif
1080
1081   return bfd_reloc_ok;
1082 }
1083
1084 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
1085    from smaller values.  Start with zero, widen, *then* decrement.  */
1086 #define MINUS_ONE       (((bfd_vma)0) - 1)
1087
1088 static reloc_howto_type alpha_howto_table[] =
1089 {
1090   HOWTO (ALPHA_R_IGNORE,        /* Type.  */
1091          0,                     /* Rightshift.  */
1092          0,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1093          8,                     /* Bitsize.  */
1094          TRUE,                  /* PC relative.  */
1095          0,                     /* Bitpos.  */
1096          complain_overflow_dont,/* Complain_on_overflow.  */
1097          reloc_nil,             /* Special_function.  */
1098          "IGNORE",              /* Name.  */
1099          TRUE,                  /* Partial_inplace.  */
1100          0,                     /* Source mask */
1101          0,                     /* Dest mask.  */
1102          TRUE),                 /* PC rel offset.  */
1103
1104   /* A 64 bit reference to a symbol.  */
1105   HOWTO (ALPHA_R_REFQUAD,       /* Type.  */
1106          0,                     /* Rightshift.  */
1107          4,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1108          64,                    /* Bitsize.  */
1109          FALSE,                 /* PC relative.  */
1110          0,                     /* Bitpos.  */
1111          complain_overflow_bitfield, /* Complain_on_overflow.  */
1112          reloc_nil,             /* Special_function.  */
1113          "REFQUAD",             /* Name.  */
1114          TRUE,                  /* Partial_inplace.  */
1115          MINUS_ONE,             /* Source mask.  */
1116          MINUS_ONE,             /* Dest mask.  */
1117          FALSE),                /* PC rel offset.  */
1118
1119   /* A 21 bit branch.  The native assembler generates these for
1120      branches within the text segment, and also fills in the PC
1121      relative offset in the instruction.  */
1122   HOWTO (ALPHA_R_BRADDR,        /* Type.  */
1123          2,                     /* Rightshift.  */
1124          2,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1125          21,                    /* Bitsize.  */
1126          TRUE,                  /* PC relative.  */
1127          0,                     /* Bitpos.  */
1128          complain_overflow_signed, /* Complain_on_overflow.  */
1129          reloc_nil,             /* Special_function.  */
1130          "BRADDR",              /* Name.  */
1131          TRUE,                  /* Partial_inplace.  */
1132          0x1fffff,              /* Source mask.  */
1133          0x1fffff,              /* Dest mask.  */
1134          FALSE),                /* PC rel offset.  */
1135
1136   /* A hint for a jump to a register.  */
1137   HOWTO (ALPHA_R_HINT,          /* Type.  */
1138          2,                     /* Rightshift.  */
1139          1,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1140          14,                    /* Bitsize.  */
1141          TRUE,                  /* PC relative.  */
1142          0,                     /* Bitpos.  */
1143          complain_overflow_dont,/* Complain_on_overflow.  */
1144          reloc_nil,             /* Special_function.  */
1145          "HINT",                /* Name.  */
1146          TRUE,                  /* Partial_inplace.  */
1147          0x3fff,                /* Source mask.  */
1148          0x3fff,                /* Dest mask.  */
1149          FALSE),                /* PC rel offset.  */
1150
1151   /* 16 bit PC relative offset.  */
1152   HOWTO (ALPHA_R_SREL16,        /* Type.  */
1153          0,                     /* Rightshift.  */
1154          1,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1155          16,                    /* Bitsize.  */
1156          TRUE,                  /* PC relative.  */
1157          0,                     /* Bitpos.  */
1158          complain_overflow_signed, /* Complain_on_overflow.  */
1159          reloc_nil,             /* Special_function.  */
1160          "SREL16",              /* Name.  */
1161          TRUE,                  /* Partial_inplace.  */
1162          0xffff,                /* Source mask.  */
1163          0xffff,                /* Dest mask.  */
1164          FALSE),                /* PC rel offset.  */
1165
1166   /* 32 bit PC relative offset.  */
1167   HOWTO (ALPHA_R_SREL32,        /* Type.  */
1168          0,                     /* Rightshift.  */
1169          2,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1170          32,                    /* Bitsize.  */
1171          TRUE,                  /* PC relative.  */
1172          0,                     /* Bitpos.  */
1173          complain_overflow_signed, /* Complain_on_overflow.  */
1174          reloc_nil,             /* Special_function.  */
1175          "SREL32",              /* Name.  */
1176          TRUE,                  /* Partial_inplace.  */
1177          0xffffffff,            /* Source mask.  */
1178          0xffffffff,            /* Dest mask.  */
1179          FALSE),                /* PC rel offset.  */
1180
1181   /* A 64 bit PC relative offset.  */
1182   HOWTO (ALPHA_R_SREL64,        /* Type.  */
1183          0,                     /* Rightshift.  */
1184          4,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1185          64,                    /* Bitsize.  */
1186          TRUE,                  /* PC relative.  */
1187          0,                     /* Bitpos.  */
1188          complain_overflow_signed, /* Complain_on_overflow.  */
1189          reloc_nil,             /* Special_function.  */
1190          "SREL64",              /* Name.  */
1191          TRUE,                  /* Partial_inplace.  */
1192          MINUS_ONE,             /* Source mask.  */
1193          MINUS_ONE,             /* Dest mask.  */
1194          FALSE),                /* PC rel offset.  */
1195
1196   /* Push a value on the reloc evaluation stack.  */
1197   HOWTO (ALPHA_R_OP_PUSH,       /* Type.  */
1198          0,                     /* Rightshift.  */
1199          0,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1200          0,                     /* Bitsize.  */
1201          FALSE,                 /* PC relative.  */
1202          0,                     /* Bitpos.  */
1203          complain_overflow_dont,/* Complain_on_overflow.  */
1204          reloc_nil,             /* Special_function.  */
1205          "OP_PUSH",             /* Name.  */
1206          FALSE,                 /* Partial_inplace.  */
1207          0,                     /* Source mask.  */
1208          0,                     /* Dest mask.  */
1209          FALSE),                /* PC rel offset.  */
1210
1211   /* Store the value from the stack at the given address.  Store it in
1212      a bitfield of size r_size starting at bit position r_offset.  */
1213   HOWTO (ALPHA_R_OP_STORE,      /* Type.  */
1214          0,                     /* Rightshift.  */
1215          4,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1216          64,                    /* Bitsize.  */
1217          FALSE,                 /* PC relative.  */
1218          0,                     /* Bitpos.  */
1219          complain_overflow_dont,/* Complain_on_overflow.  */
1220          reloc_nil,             /* Special_function.  */
1221          "OP_STORE",            /* Name.  */
1222          FALSE,                 /* Partial_inplace.  */
1223          0,                     /* Source mask.  */
1224          MINUS_ONE,             /* Dest mask.  */
1225          FALSE),                /* PC rel offset.  */
1226
1227   /* Subtract the reloc address from the value on the top of the
1228      relocation stack.  */
1229   HOWTO (ALPHA_R_OP_PSUB,       /* Type.  */
1230          0,                     /* Rightshift.  */
1231          0,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1232          0,                     /* Bitsize.  */
1233          FALSE,                 /* PC relative.  */
1234          0,                     /* Bitpos.  */
1235          complain_overflow_dont,/* Complain_on_overflow.  */
1236          reloc_nil,             /* Special_function.  */
1237          "OP_PSUB",             /* Name.  */
1238          FALSE,                 /* Partial_inplace.  */
1239          0,                     /* Source mask.  */
1240          0,                     /* Dest mask.  */
1241          FALSE),                /* PC rel offset.  */
1242
1243   /* Shift the value on the top of the relocation stack right by the
1244      given value.  */
1245   HOWTO (ALPHA_R_OP_PRSHIFT,    /* Type.  */
1246          0,                     /* Rightshift.  */
1247          0,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1248          0,                     /* Bitsize.  */
1249          FALSE,                 /* PC relative.  */
1250          0,                     /* Bitpos.  */
1251          complain_overflow_dont,/* Complain_on_overflow.  */
1252          reloc_nil,             /* Special_function.  */
1253          "OP_PRSHIFT",          /* Name.  */
1254          FALSE,                 /* Partial_inplace.  */
1255          0,                     /* Source mask.  */
1256          0,                     /* Dest mask.  */
1257          FALSE),                /* PC rel offset.  */
1258
1259   /* Hack. Linkage is done by linker.  */
1260   HOWTO (ALPHA_R_LINKAGE,       /* Type.  */
1261          0,                     /* Rightshift.  */
1262          8,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1263          256,                   /* Bitsize.  */
1264          FALSE,                 /* PC relative.  */
1265          0,                     /* Bitpos.  */
1266          complain_overflow_dont,/* Complain_on_overflow.  */
1267          reloc_nil,             /* Special_function.  */
1268          "LINKAGE",             /* Name.  */
1269          FALSE,                 /* Partial_inplace.  */
1270          0,                     /* Source mask.  */
1271          0,                     /* Dest mask.  */
1272          FALSE),                /* PC rel offset.  */
1273
1274   /* A 32 bit reference to a symbol.  */
1275   HOWTO (ALPHA_R_REFLONG,       /* Type.  */
1276          0,                     /* Rightshift.  */
1277          2,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1278          32,                    /* Bitsize.  */
1279          FALSE,                 /* PC relative.  */
1280          0,                     /* Bitpos.  */
1281          complain_overflow_bitfield, /* Complain_on_overflow.  */
1282          reloc_nil,             /* Special_function.  */
1283          "REFLONG",             /* Name.  */
1284          TRUE,                  /* Partial_inplace.  */
1285          0xffffffff,            /* Source mask.  */
1286          0xffffffff,            /* Dest mask.  */
1287          FALSE),                /* PC rel offset.  */
1288
1289   /* A 64 bit reference to a procedure, written as 32 bit value.  */
1290   HOWTO (ALPHA_R_CODEADDR,      /* Type.  */
1291          0,                     /* Rightshift.  */
1292          4,                     /* Size (0 = byte, 1 = short, 2 = long).  */
1293          64,                    /* Bitsize.  */
1294          FALSE,                 /* PC relative.  */
1295          0,                     /* Bitpos.  */
1296          complain_overflow_signed,/* Complain_on_overflow.  */
1297          reloc_nil,             /* Special_function.  */
1298          "CODEADDR",            /* Name.  */
1299          FALSE,                 /* Partial_inplace.  */
1300          0xffffffff,            /* Source mask.  */
1301          0xffffffff,            /* Dest mask.  */
1302          FALSE),                /* PC rel offset.  */
1303
1304 };
1305
1306 /* Return a pointer to a howto structure which, when invoked, will perform
1307    the relocation code on data from the architecture noted.  */
1308
1309 static const struct reloc_howto_struct *
1310 vms_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
1311                            bfd_reloc_code_real_type code)
1312 {
1313   int alpha_type;
1314
1315 #if VMS_DEBUG
1316   vms_debug (1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd, code);
1317 #endif
1318
1319   switch (code)
1320     {
1321       case BFD_RELOC_16:                alpha_type = ALPHA_R_SREL16;    break;
1322       case BFD_RELOC_32:                alpha_type = ALPHA_R_REFLONG;   break;
1323       case BFD_RELOC_64:                alpha_type = ALPHA_R_REFQUAD;   break;
1324       case BFD_RELOC_CTOR:              alpha_type = ALPHA_R_REFQUAD;   break;
1325       case BFD_RELOC_23_PCREL_S2:       alpha_type = ALPHA_R_BRADDR;    break;
1326       case BFD_RELOC_ALPHA_HINT:        alpha_type = ALPHA_R_HINT;      break;
1327       case BFD_RELOC_16_PCREL:          alpha_type = ALPHA_R_SREL16;    break;
1328       case BFD_RELOC_32_PCREL:          alpha_type = ALPHA_R_SREL32;    break;
1329       case BFD_RELOC_64_PCREL:          alpha_type = ALPHA_R_SREL64;    break;
1330       case BFD_RELOC_ALPHA_LINKAGE:     alpha_type = ALPHA_R_LINKAGE;   break;
1331       case BFD_RELOC_ALPHA_CODEADDR:    alpha_type = ALPHA_R_CODEADDR;  break;
1332       default:
1333         (*_bfd_error_handler) ("reloc (%d) is *UNKNOWN*", code);
1334         return NULL;
1335     }
1336 #if VMS_DEBUG
1337   vms_debug (2, "reloc is %s\n", alpha_howto_table[alpha_type].name);
1338 #endif
1339   return & alpha_howto_table[alpha_type];
1340 }
1341
1342 /* Part 4.7, writing an object file.  */
1343
1344 /* Set the architecture and machine type in BFD abfd to arch and mach.
1345    Find the correct pointer to a structure and insert it into the arch_info
1346    pointer.  */
1347
1348 static bfd_boolean
1349 vms_set_arch_mach (bfd * abfd,
1350                    enum bfd_architecture arch ATTRIBUTE_UNUSED,
1351                    unsigned long mach ATTRIBUTE_UNUSED)
1352 {
1353 #if VMS_DEBUG
1354   vms_debug (1, "vms_set_arch_mach (%p, %d, %ld)\n", abfd, arch, mach);
1355 #endif
1356   abfd->arch_info = bfd_scan_arch ("alpha");
1357
1358   return TRUE;
1359 }
1360
1361 /* Sets the contents of the section section in BFD abfd to the data starting
1362    in memory at data. The data is written to the output section starting at
1363    offset offset for count bytes.
1364
1365    Normally TRUE is returned, else FALSE. Possible error returns are:
1366    o bfd_error_no_contents - The output section does not have the
1367         SEC_HAS_CONTENTS attribute, so nothing can be written to it.
1368    o and some more too  */
1369
1370 static bfd_boolean
1371 vms_set_section_contents (bfd * abfd,
1372                           asection *section,
1373                           const void * location,
1374                           file_ptr offset,
1375                           bfd_size_type count)
1376 {
1377 #if VMS_DEBUG
1378   vms_debug (1, "vms_set_section_contents (%p, sec %s, loc %p, off %ld, count %d)\n",
1379              abfd, section->name, location, (long int)offset, (int)count);
1380   vms_debug (2, "size %d\n", (int) section->size);
1381 #endif
1382   return _bfd_save_vms_section (abfd, section, location, offset, count);
1383 }
1384
1385 /* Part 4.8, linker.  */
1386
1387 /* Get the size of the section headers.  */
1388
1389 static int
1390 vms_sizeof_headers (bfd * abfd ATTRIBUTE_UNUSED,
1391                     bfd_boolean reloc ATTRIBUTE_UNUSED)
1392 {
1393 #if VMS_DEBUG
1394   vms_debug (1, "vms_sizeof_headers (%p, %s)\n", abfd, (reloc)?"True":"False");
1395 #endif
1396   return 0;
1397 }
1398
1399 /* Provides default handling of relocation effort for back ends
1400    which can't be bothered to do it efficiently.  */
1401
1402 static bfd_byte *
1403 vms_bfd_get_relocated_section_contents (bfd * abfd ATTRIBUTE_UNUSED,
1404                                         struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
1405                                         struct bfd_link_order *link_order ATTRIBUTE_UNUSED,
1406                                         bfd_byte *data ATTRIBUTE_UNUSED,
1407                                         bfd_boolean relocatable ATTRIBUTE_UNUSED,
1408                                         asymbol **symbols ATTRIBUTE_UNUSED)
1409 {
1410 #if VMS_DEBUG
1411   vms_debug (1, "vms_bfd_get_relocated_section_contents (%p, %p, %p, %p, %s, %p)\n",
1412              abfd, link_info, link_order, data, (relocatable)?"True":"False", symbols);
1413 #endif
1414   return NULL;
1415 }
1416
1417 /* ???  */
1418
1419 static bfd_boolean
1420 vms_bfd_relax_section (bfd * abfd ATTRIBUTE_UNUSED,
1421                        asection *section ATTRIBUTE_UNUSED,
1422                        struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
1423                        bfd_boolean *again ATTRIBUTE_UNUSED)
1424 {
1425 #if VMS_DEBUG
1426   vms_debug (1, "vms_bfd_relax_section (%p, %s, %p, <ret>)\n",
1427              abfd, section->name, link_info);
1428 #endif
1429   return TRUE;
1430 }
1431
1432 static bfd_boolean
1433 vms_bfd_gc_sections (bfd * abfd ATTRIBUTE_UNUSED,
1434                      struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
1435 {
1436 #if VMS_DEBUG
1437   vms_debug (1, "vms_bfd_gc_sections (%p, %p)\n", abfd, link_info);
1438 #endif
1439   return TRUE;
1440 }
1441
1442 static bfd_boolean
1443 vms_bfd_merge_sections (bfd * abfd ATTRIBUTE_UNUSED,
1444                         struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
1445 {
1446 #if VMS_DEBUG
1447   vms_debug (1, "vms_bfd_merge_sections (%p, %p)\n", abfd, link_info);
1448 #endif
1449   return TRUE;
1450 }
1451
1452 /* Create a hash table for the linker.  Different backends store
1453    different information in this table.  */
1454
1455 static struct bfd_link_hash_table *
1456 vms_bfd_link_hash_table_create (bfd * abfd ATTRIBUTE_UNUSED)
1457 {
1458 #if VMS_DEBUG
1459   vms_debug (1, "vms_bfd_link_hash_table_create (%p)\n", abfd);
1460 #endif
1461   return NULL;
1462 }
1463
1464 /* Free a linker hash table.  */
1465
1466 static void
1467 vms_bfd_link_hash_table_free (struct bfd_link_hash_table *hash ATTRIBUTE_UNUSED)
1468 {
1469 #if VMS_DEBUG
1470   vms_debug (1, "vms_bfd_link_hash_table_free (%p)\n", abfd);
1471 #endif
1472 }
1473
1474 /* Add symbols from this object file into the hash table.  */
1475
1476 static bfd_boolean
1477 vms_bfd_link_add_symbols (bfd * abfd ATTRIBUTE_UNUSED,
1478                           struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
1479 {
1480 #if VMS_DEBUG
1481   vms_debug (1, "vms_bfd_link_add_symbols (%p, %p)\n", abfd, link_info);
1482 #endif
1483   return FALSE;
1484 }
1485
1486 /* Do a link based on the link_order structures attached to each
1487    section of the BFD.  */
1488
1489 static bfd_boolean
1490 vms_bfd_final_link (bfd * abfd ATTRIBUTE_UNUSED,
1491                     struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
1492 {
1493 #if VMS_DEBUG
1494   vms_debug (1, "vms_bfd_final_link (%p, %p)\n", abfd, link_info);
1495 #endif
1496   return TRUE;
1497 }
1498
1499 /* Should this section be split up into smaller pieces during linking.  */
1500
1501 static bfd_boolean
1502 vms_bfd_link_split_section (bfd * abfd ATTRIBUTE_UNUSED,
1503                             asection *section ATTRIBUTE_UNUSED)
1504 {
1505 #if VMS_DEBUG
1506   vms_debug (1, "vms_bfd_link_split_section (%p, %s)\n", abfd, section->name);
1507 #endif
1508   return FALSE;
1509 }
1510
1511 /* Part 4.9, dynamic symbols and relocations.  */
1512
1513 /* Get the amount of memory required to hold the dynamic symbols.  */
1514
1515 static long
1516 vms_get_dynamic_symtab_upper_bound (bfd * abfd ATTRIBUTE_UNUSED)
1517 {
1518 #if VMS_DEBUG
1519   vms_debug (1, "vms_get_dynamic_symtab_upper_bound (%p)\n", abfd);
1520 #endif
1521   return 0;
1522 }
1523
1524 static bfd_boolean
1525 vms_bfd_print_private_bfd_data (bfd * abfd ATTRIBUTE_UNUSED,
1526                                 void *file ATTRIBUTE_UNUSED)
1527 {
1528 #if VMS_DEBUG
1529   vms_debug (1, "vms_bfd_print_private_bfd_data (%p)\n", abfd);
1530 #endif
1531   return FALSE;
1532 }
1533
1534 /* Read in the dynamic symbols.  */
1535
1536 static long
1537 vms_canonicalize_dynamic_symtab (bfd * abfd ATTRIBUTE_UNUSED,
1538                                  asymbol **symbols ATTRIBUTE_UNUSED)
1539 {
1540 #if VMS_DEBUG
1541   vms_debug (1, "vms_canonicalize_dynamic_symtab (%p, <ret>)\n", abfd);
1542 #endif
1543   return 0L;
1544 }
1545
1546 /* Get the amount of memory required to hold the dynamic relocs.  */
1547
1548 static long
1549 vms_get_dynamic_reloc_upper_bound (bfd * abfd ATTRIBUTE_UNUSED)
1550 {
1551 #if VMS_DEBUG
1552   vms_debug (1, "vms_get_dynamic_reloc_upper_bound (%p)\n", abfd);
1553 #endif
1554   return 0L;
1555 }
1556
1557 /* Read in the dynamic relocs.  */
1558
1559 static long
1560 vms_canonicalize_dynamic_reloc (bfd * abfd ATTRIBUTE_UNUSED,
1561                                 arelent **arel ATTRIBUTE_UNUSED,
1562                                 asymbol **symbols ATTRIBUTE_UNUSED)
1563 {
1564 #if VMS_DEBUG
1565   vms_debug (1, "vms_canonicalize_dynamic_reloc (%p)\n", abfd);
1566 #endif
1567   return 0L;
1568 }
1569 \f
1570 const bfd_target vms_alpha_vec =
1571 {
1572   "vms-alpha",                  /* Name.  */
1573   bfd_target_evax_flavour,
1574   BFD_ENDIAN_LITTLE,            /* Data byte order is little.  */
1575   BFD_ENDIAN_LITTLE,            /* Header byte order is little.  */
1576
1577   (HAS_RELOC | HAS_SYMS
1578    | WP_TEXT | D_PAGED),        /* Object flags.  */
1579   (SEC_ALLOC | SEC_LOAD | SEC_RELOC
1580    | SEC_READONLY | SEC_CODE | SEC_DATA
1581    | SEC_HAS_CONTENTS | SEC_IN_MEMORY),         /* Sect flags.  */
1582   0,                            /* Symbol_leading_char.  */
1583   ' ',                          /* AR_pad_char.  */
1584   15,                           /* AR_max_namelen.  */
1585   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1586   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1587   bfd_getl16, bfd_getl_signed_16, bfd_putl16,
1588   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1589   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1590   bfd_getl16, bfd_getl_signed_16, bfd_putl16,
1591
1592   {_bfd_dummy_target, vms_object_p,             /* bfd_check_format.  */
1593    vms_archive_p, _bfd_dummy_target},
1594   {bfd_false, vms_mkobject,                     /* bfd_set_format.  */
1595    _bfd_generic_mkarchive, bfd_false},
1596   {bfd_false, vms_write_object_contents,        /* bfd_write_contents.  */
1597    _bfd_write_archive_contents, bfd_false},
1598
1599   BFD_JUMP_TABLE_GENERIC (vms),
1600   BFD_JUMP_TABLE_COPY (vms),
1601   BFD_JUMP_TABLE_CORE (vms),
1602   BFD_JUMP_TABLE_ARCHIVE (vms),
1603   BFD_JUMP_TABLE_SYMBOLS (vms),
1604   BFD_JUMP_TABLE_RELOCS (vms),
1605   BFD_JUMP_TABLE_WRITE (vms),
1606   BFD_JUMP_TABLE_LINK (vms),
1607   BFD_JUMP_TABLE_DYNAMIC (vms),
1608
1609   NULL,
1610
1611   NULL
1612 };
1613
1614 const bfd_target vms_vax_vec =
1615 {
1616   "vms-vax",                    /* Name.  */
1617   bfd_target_ovax_flavour,
1618   BFD_ENDIAN_LITTLE,            /* Data byte order is little.  */
1619   BFD_ENDIAN_LITTLE,            /* Header byte order is little.  */
1620
1621   (HAS_RELOC | HAS_SYMS         /* Object flags.  */
1622    | WP_TEXT | D_PAGED
1623    | HAS_LINENO | HAS_DEBUG | HAS_LOCALS),
1624
1625   (SEC_ALLOC | SEC_LOAD | SEC_RELOC
1626    | SEC_READONLY | SEC_CODE | SEC_DATA
1627    | SEC_HAS_CONTENTS | SEC_IN_MEMORY),         /* Sect flags.  */
1628   0,                            /* Symbol_leading_char.  */
1629   ' ',                          /* AR_pad_char.  */
1630   15,                           /* AR_max_namelen.  */
1631   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1632   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1633   bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Data.  */
1634   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1635   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1636   bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Headers.  */
1637
1638   {_bfd_dummy_target, vms_object_p,             /* bfd_check_format.  */
1639    vms_archive_p, _bfd_dummy_target},
1640   {bfd_false, vms_mkobject,                     /* bfd_set_format.  */
1641    _bfd_generic_mkarchive, bfd_false},
1642   {bfd_false, vms_write_object_contents,        /* bfd_write_contents.  */
1643    _bfd_write_archive_contents, bfd_false},
1644
1645   BFD_JUMP_TABLE_GENERIC (vms),
1646   BFD_JUMP_TABLE_COPY (vms),
1647   BFD_JUMP_TABLE_CORE (vms),
1648   BFD_JUMP_TABLE_ARCHIVE (vms),
1649   BFD_JUMP_TABLE_SYMBOLS (vms),
1650   BFD_JUMP_TABLE_RELOCS (vms),
1651   BFD_JUMP_TABLE_WRITE (vms),
1652   BFD_JUMP_TABLE_LINK (vms),
1653   BFD_JUMP_TABLE_DYNAMIC (vms),
1654
1655   NULL,
1656
1657   NULL
1658 };