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