OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [bfd/] [vms.c] - Blame information for rev 635

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.