1 /* vms-hdr.c -- BFD back-end for VMS/VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 HDR record handling functions
6 EMH record handling functions
8 EOM record handling functions
9 EEOM record handling functions
11 Written by Klaus K"ampf (kkaempf@rmi.de)
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #include "safe-ctype.h"
40 static unsigned char *get_vms_time_string
PARAMS ((void));
43 /*---------------------------------------------------------------------------*/
45 /* Read & process emh record
46 return 0 on success, -1 on error */
49 _bfd_vms_slurp_hdr (abfd
, objtype
)
54 unsigned char *vms_rec
;
57 vms_rec
= PRIV(vms_rec
);
60 vms_debug(2, "HDR/EMH\n");
69 subtype
= bfd_getl16 (vms_rec
+ 4) + EVAX_OFFSET
;
76 vms_debug(3, "subtype %d\n", subtype
);
86 PRIV(hdr_data
).hdr_b_strlvl
= vms_rec
[2];
87 PRIV(hdr_data
).hdr_l_recsiz
= bfd_getl16 (vms_rec
+ 3);
88 PRIV(hdr_data
).hdr_t_name
= _bfd_vms_save_counted_string (vms_rec
+ 5);
89 ptr
= vms_rec
+ 5 + vms_rec
[5] + 1;
90 PRIV(hdr_data
).hdr_t_version
= _bfd_vms_save_counted_string (ptr
);
92 PRIV(hdr_data
).hdr_t_date
= _bfd_vms_save_sized_string (ptr
, 17);
100 PRIV(hdr_data
).hdr_c_lnm
= _bfd_vms_save_sized_string (vms_rec
, PRIV(rec_length
-2));
107 PRIV(hdr_data
).hdr_c_src
= _bfd_vms_save_sized_string (vms_rec
, PRIV(rec_length
-2));
114 PRIV(hdr_data
).hdr_c_ttl
= _bfd_vms_save_sized_string (vms_rec
, PRIV(rec_length
-2));
135 case EMH_S_C_MHD
+ EVAX_OFFSET
:
139 PRIV(hdr_data
).hdr_b_strlvl
= vms_rec
[6];
140 PRIV(hdr_data
).hdr_l_arch1
= bfd_getl32 (vms_rec
+ 8);
141 PRIV(hdr_data
).hdr_l_arch2
= bfd_getl32 (vms_rec
+ 12);
142 PRIV(hdr_data
).hdr_l_recsiz
= bfd_getl32 (vms_rec
+ 16);
143 PRIV(hdr_data
).hdr_t_name
=
144 _bfd_vms_save_counted_string (vms_rec
+ 20);
145 ptr
= vms_rec
+ 20 + vms_rec
[20] + 1;
146 PRIV(hdr_data
).hdr_t_version
=
147 _bfd_vms_save_counted_string (ptr
);
149 PRIV(hdr_data
).hdr_t_date
=
150 _bfd_vms_save_sized_string (ptr
, 17);
154 case EMH_S_C_LNM
+ EVAX_OFFSET
:
158 PRIV(hdr_data
).hdr_c_lnm
=
159 _bfd_vms_save_sized_string (vms_rec
, PRIV(rec_length
-6));
162 case EMH_S_C_SRC
+ EVAX_OFFSET
:
166 PRIV(hdr_data
).hdr_c_src
=
167 _bfd_vms_save_sized_string (vms_rec
, PRIV(rec_length
-6));
170 case EMH_S_C_TTL
+ EVAX_OFFSET
:
174 PRIV(hdr_data
).hdr_c_ttl
=
175 _bfd_vms_save_sized_string (vms_rec
, PRIV(rec_length
-6));
178 case EMH_S_C_CPR
+ EVAX_OFFSET
:
184 case EMH_S_C_MTC
+ EVAX_OFFSET
:
190 case EMH_S_C_GTX
+ EVAX_OFFSET
:
197 bfd_set_error (bfd_error_wrong_format
);
205 /*-----------------------------------------------------------------------------*/
206 /* Output routines. */
208 /* Manufacure a VMS like time on a unix based system.
209 stolen from obj-vms.c */
211 static unsigned char *
212 get_vms_time_string ()
214 static unsigned char tbuf
[18];
221 pnt
= ctime (&timeb
);
227 sprintf (tbuf
, "%2s-%3s-%s %s", pnt
+ 8, pnt
+ 4, pnt
+ 20, pnt
+ 11);
235 Descriptor
.Size
= 17;
236 Descriptor
.Ptr
= tbuf
;
237 SYS$
ASCTIM (0, &Descriptor
, 0, 0);
241 vms_debug (6, "vmstimestring:'%s'\n", tbuf
);
247 /* write object header for bfd abfd */
250 _bfd_vms_write_hdr (abfd
, objtype
)
260 vms_debug (2, "vms_write_hdr (%p)\n", abfd
);
263 _bfd_vms_output_alignment (abfd
, 2);
267 if (objtype
== OBJ_S_C_HDR
)
272 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_MHD
);
273 _bfd_vms_output_short (abfd
, EOBJ_S_C_STRLVL
);
274 _bfd_vms_output_long (abfd
, 0);
275 _bfd_vms_output_long (abfd
, 0);
276 _bfd_vms_output_long (abfd
, MAX_OUTREC_SIZE
);
279 if (bfd_get_filename (abfd
) != 0)
281 /* strip path and suffix information */
283 char *fname
, *fout
, *fptr
;
285 fptr
= bfd_get_filename (abfd
);
286 fname
= (char *) alloca (strlen (fptr
) + 1);
287 strcpy (fname
, fptr
);
288 fout
= strrchr (fname
, ']');
290 fout
= strchr (fname
, ':');
296 /* strip .obj suffix */
298 fptr
= strrchr (fname
, '.');
300 && (strcasecmp (fptr
, ".OBJ") == 0))
306 *fptr
= TOUPPER (*fptr
);
309 || ((fptr
- fout
) > 31))
312 _bfd_vms_output_counted (abfd
, fout
);
315 _bfd_vms_output_counted (abfd
, "NONAME");
317 _bfd_vms_output_counted (abfd
, BFD_VERSION_STRING
);
318 _bfd_vms_output_dump (abfd
, get_vms_time_string (), 17);
319 _bfd_vms_output_fill (abfd
, 0, 17);
320 _bfd_vms_output_flush (abfd
);
324 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_LNM
);
325 _bfd_vms_output_dump (abfd
, (unsigned char *)"GAS proGIS", 10);
326 _bfd_vms_output_flush (abfd
);
330 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_SRC
);
332 for (symnum
= 0; symnum
< abfd
->symcount
; symnum
++)
334 symbol
= abfd
->outsymbols
[symnum
];
336 if (symbol
->flags
& BSF_FILE
)
338 if (strncmp ((char *)symbol
->name
, "<CASE:", 6) == 0)
340 PRIV(flag_hash_long_names
) = symbol
->name
[6] - '0';
341 PRIV(flag_show_after_trunc
) = symbol
->name
[7] - '0';
349 _bfd_vms_output_dump (abfd
, (unsigned char *) symbol
->name
,
350 (int) strlen (symbol
->name
));
357 if (symnum
== abfd
->symcount
)
358 _bfd_vms_output_dump (abfd
, (unsigned char *)"noname", 6);
360 _bfd_vms_output_flush (abfd
);
364 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_TTL
);
365 _bfd_vms_output_dump (abfd
, (unsigned char *)"TTL", 3);
366 _bfd_vms_output_flush (abfd
);
370 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_CPR
);
371 _bfd_vms_output_dump (abfd
,
372 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
374 _bfd_vms_output_flush (abfd
);
379 /*-----------------------------------------------------------------------------*/
381 /* Process EOM/EEOM record
382 return 0 on success, -1 on error */
385 _bfd_vms_slurp_eom (abfd
, objtype
)
389 unsigned char *vms_rec
;
392 vms_debug(2, "EOM/EEOM\n");
395 vms_rec
= PRIV(vms_rec
);
397 if ((objtype
== OBJ_S_C_EOM
)
398 || (objtype
== OBJ_S_C_EOMW
))
403 PRIV(eom_data
).eom_l_total_lps
= bfd_getl32 (vms_rec
+ 4);
404 PRIV(eom_data
).eom_b_comcod
= *(vms_rec
+ 8);
405 if (PRIV(eom_data
).eom_b_comcod
> 1)
407 (*_bfd_error_handler
) (_("Object module NOT error-free !\n"));
408 bfd_set_error (bfd_error_bad_value
);
411 PRIV(eom_data
).eom_has_transfer
= false;
412 if (PRIV(rec_size
) > 10)
414 PRIV(eom_data
).eom_has_transfer
= true;
415 PRIV(eom_data
).eom_b_tfrflg
= *(vms_rec
+ 9);
416 PRIV(eom_data
).eom_l_psindx
= bfd_getl32 (vms_rec
+ 12);
417 PRIV(eom_data
).eom_l_tfradr
= bfd_getl32 (vms_rec
+ 16);
419 abfd
->start_address
= PRIV(eom_data
).eom_l_tfradr
;
425 /* Write eom record for bfd abfd */
428 _bfd_vms_write_eom (abfd
, objtype
)
433 vms_debug (2, "vms_write_eom (%p, %d)\n", abfd
, objtype
);
436 _bfd_vms_output_begin (abfd
, objtype
, -1);
437 _bfd_vms_output_long (abfd
, (unsigned long) (PRIV(vms_linkage_index
) >> 1));
438 _bfd_vms_output_byte (abfd
, 0); /* completion code */
439 _bfd_vms_output_byte (abfd
, 0); /* fill byte */
441 if (bfd_get_start_address (abfd
) != (bfd_vma
)-1)
445 section
= bfd_get_section_by_name (abfd
, ".link");
448 bfd_set_error (bfd_error_nonrepresentable_section
);
451 _bfd_vms_output_short (abfd
, 0);
452 _bfd_vms_output_long (abfd
, (unsigned long) (section
->index
));
453 _bfd_vms_output_long (abfd
,
454 (unsigned long) bfd_get_start_address (abfd
));
455 _bfd_vms_output_long (abfd
, 0);
458 _bfd_vms_output_end (abfd
);