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