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, 2002, 2003, 2005, 2006,
4 2007 Free Software Foundation, Inc.
6 HDR record handling functions
7 EMH record handling functions
9 EOM record handling functions
10 EEOM record handling functions
12 Written by Klaus K"ampf (kkaempf@rmi.de)
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
27 MA 02110-1301, USA. */
33 #include "safe-ctype.h"
42 /* Read & process emh record
43 return 0 on success, -1 on error. */
46 _bfd_vms_slurp_hdr (bfd
*abfd
, int objtype
)
49 unsigned char *vms_rec
;
52 vms_rec
= PRIV(vms_rec
);
55 vms_debug(2, "HDR/EMH\n");
64 subtype
= bfd_getl16 (vms_rec
+ 4) + EVAX_OFFSET
;
71 vms_debug(3, "subtype %d\n", subtype
);
78 PRIV (hdr_data
).hdr_b_strlvl
= vms_rec
[2];
79 PRIV (hdr_data
).hdr_l_recsiz
= bfd_getl16 (vms_rec
+ 3);
80 PRIV (hdr_data
).hdr_t_name
= _bfd_vms_save_counted_string (vms_rec
+ 5);
81 ptr
= vms_rec
+ 5 + vms_rec
[5] + 1;
82 PRIV (hdr_data
).hdr_t_version
= _bfd_vms_save_counted_string (ptr
);
84 PRIV (hdr_data
).hdr_t_date
= _bfd_vms_save_sized_string (ptr
, 17);
88 PRIV (hdr_data
).hdr_c_lnm
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_length
- 2));
92 PRIV (hdr_data
).hdr_c_src
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_length
- 2));
96 PRIV (hdr_data
).hdr_c_ttl
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_length
- 2));
99 case EMH_S_C_MHD
+ EVAX_OFFSET
:
101 PRIV (hdr_data
).hdr_b_strlvl
= vms_rec
[6];
102 PRIV (hdr_data
).hdr_l_arch1
= bfd_getl32 (vms_rec
+ 8);
103 PRIV (hdr_data
).hdr_l_arch2
= bfd_getl32 (vms_rec
+ 12);
104 PRIV (hdr_data
).hdr_l_recsiz
= bfd_getl32 (vms_rec
+ 16);
105 PRIV (hdr_data
).hdr_t_name
= _bfd_vms_save_counted_string (vms_rec
+ 20);
106 ptr
= vms_rec
+ 20 + vms_rec
[20] + 1;
107 PRIV (hdr_data
).hdr_t_version
=_bfd_vms_save_counted_string (ptr
);
109 PRIV (hdr_data
).hdr_t_date
= _bfd_vms_save_sized_string (ptr
, 17);
112 case EMH_S_C_LNM
+ EVAX_OFFSET
:
113 PRIV (hdr_data
).hdr_c_lnm
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_length
- 6));
116 case EMH_S_C_SRC
+ EVAX_OFFSET
:
117 PRIV (hdr_data
).hdr_c_src
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_length
- 6));
120 case EMH_S_C_TTL
+ EVAX_OFFSET
:
121 PRIV (hdr_data
).hdr_c_ttl
= _bfd_vms_save_sized_string (vms_rec
, PRIV (rec_length
- 6));
127 case EMH_S_C_CPR
+ EVAX_OFFSET
:
128 case EMH_S_C_MTC
+ EVAX_OFFSET
:
129 case EMH_S_C_GTX
+ EVAX_OFFSET
:
133 bfd_set_error (bfd_error_wrong_format
);
140 /* Output routines. */
142 /* Manufacture a VMS like time on a unix based system.
143 stolen from obj-vms.c. */
145 static unsigned char *
146 get_vms_time_string (void)
148 static unsigned char tbuf
[18];
156 pnt
= ctime (&timeb
);
162 sprintf ((char *) tbuf
, "%2s-%3s-%s %s",
163 pnt
+ 8, pnt
+ 4, pnt
+ 20, pnt
+ 11);
171 Descriptor
.Size
= 17;
172 Descriptor
.Ptr
= tbuf
;
173 SYS$
ASCTIM (0, &Descriptor
, 0, 0);
177 vms_debug (6, "vmstimestring:'%s'\n", tbuf
);
183 /* Write object header for bfd abfd. */
186 _bfd_vms_write_hdr (bfd
*abfd
, int objtype
)
194 vms_debug (2, "vms_write_hdr (%p)\n", abfd
);
197 _bfd_vms_output_alignment (abfd
, 2);
200 if (objtype
!= OBJ_S_C_HDR
)
202 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_MHD
);
203 _bfd_vms_output_short (abfd
, EOBJ_S_C_STRLVL
);
204 _bfd_vms_output_long (abfd
, 0);
205 _bfd_vms_output_long (abfd
, 0);
206 _bfd_vms_output_long (abfd
, MAX_OUTREC_SIZE
);
209 if (bfd_get_filename (abfd
) != 0)
211 /* Strip path and suffix information. */
212 char *fname
, *fout
, *fptr
;
214 fptr
= bfd_get_filename (abfd
);
215 fname
= alloca (strlen (fptr
) + 1);
216 strcpy (fname
, fptr
);
217 fout
= strrchr (fname
, ']');
219 fout
= strchr (fname
, ':');
225 /* Strip .obj suffix. */
226 fptr
= strrchr (fname
, '.');
228 && (strcasecmp (fptr
, ".OBJ") == 0))
234 *fptr
= TOUPPER (*fptr
);
237 || ((fptr
- fout
) > 31))
240 _bfd_vms_output_counted (abfd
, fout
);
243 _bfd_vms_output_counted (abfd
, "NONAME");
245 _bfd_vms_output_counted (abfd
, BFD_VERSION_STRING
);
246 _bfd_vms_output_dump (abfd
, get_vms_time_string (), 17);
247 _bfd_vms_output_fill (abfd
, 0, 17);
248 _bfd_vms_output_flush (abfd
);
251 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_LNM
);
252 _bfd_vms_output_dump (abfd
, (unsigned char *) STRING_COMMA_LEN ("GAS proGIS"));
253 _bfd_vms_output_flush (abfd
);
256 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_SRC
);
258 for (symnum
= 0; symnum
< abfd
->symcount
; symnum
++)
260 symbol
= abfd
->outsymbols
[symnum
];
262 if (symbol
->flags
& BSF_FILE
)
264 if (CONST_STRNEQ ((char *)symbol
->name
, "<CASE:"))
266 PRIV (flag_hash_long_names
) = symbol
->name
[6] - '0';
267 PRIV (flag_show_after_trunc
) = symbol
->name
[7] - '0';
275 _bfd_vms_output_dump (abfd
, (unsigned char *) symbol
->name
,
276 (int) strlen (symbol
->name
));
283 if (symnum
== abfd
->symcount
)
284 _bfd_vms_output_dump (abfd
, (unsigned char *) STRING_COMMA_LEN ("noname"));
286 _bfd_vms_output_flush (abfd
);
289 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_TTL
);
290 _bfd_vms_output_dump (abfd
, (unsigned char *) STRING_COMMA_LEN ("TTL"));
291 _bfd_vms_output_flush (abfd
);
294 _bfd_vms_output_begin (abfd
, EOBJ_S_C_EMH
, EMH_S_C_CPR
);
295 _bfd_vms_output_dump (abfd
,
296 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
298 _bfd_vms_output_flush (abfd
);
303 /* Process EOM/EEOM record
304 return 0 on success, -1 on error. */
307 _bfd_vms_slurp_eom (bfd
*abfd
, int objtype
)
309 unsigned char *vms_rec
;
312 vms_debug(2, "EOM/EEOM\n");
315 vms_rec
= PRIV (vms_rec
);
317 if ((objtype
== OBJ_S_C_EOM
)
318 || (objtype
== OBJ_S_C_EOMW
))
323 PRIV (eom_data
).eom_l_total_lps
= bfd_getl32 (vms_rec
+ 4);
324 PRIV (eom_data
).eom_b_comcod
= *(vms_rec
+ 8);
326 if (PRIV (eom_data
).eom_b_comcod
> 1)
328 (*_bfd_error_handler
) (_("Object module NOT error-free !\n"));
329 bfd_set_error (bfd_error_bad_value
);
332 PRIV (eom_data
).eom_has_transfer
= FALSE
;
333 if (PRIV (rec_size
) > 10)
335 PRIV (eom_data
).eom_has_transfer
= TRUE
;
336 PRIV (eom_data
).eom_b_tfrflg
= *(vms_rec
+ 9);
337 PRIV (eom_data
).eom_l_psindx
= bfd_getl32 (vms_rec
+ 12);
338 PRIV (eom_data
).eom_l_tfradr
= bfd_getl32 (vms_rec
+ 16);
340 abfd
->start_address
= PRIV (eom_data
).eom_l_tfradr
;
346 /* Write eom record for bfd abfd. */
349 _bfd_vms_write_eom (bfd
*abfd
, int objtype
)
352 vms_debug (2, "vms_write_eom (%p, %d)\n", abfd
, objtype
);
355 _bfd_vms_output_begin (abfd
, objtype
, -1);
356 _bfd_vms_output_long (abfd
, (unsigned long) (PRIV (vms_linkage_index
) >> 1));
357 _bfd_vms_output_byte (abfd
, 0); /* Completion code. */
358 _bfd_vms_output_byte (abfd
, 0); /* Fill byte. */
360 if (bfd_get_start_address (abfd
) != (bfd_vma
)-1)
364 section
= bfd_get_section_by_name (abfd
, ".link");
367 bfd_set_error (bfd_error_nonrepresentable_section
);
370 _bfd_vms_output_short (abfd
, 0);
371 _bfd_vms_output_long (abfd
, (unsigned long) (section
->index
));
372 _bfd_vms_output_long (abfd
,
373 (unsigned long) bfd_get_start_address (abfd
));
374 _bfd_vms_output_long (abfd
, 0);
377 _bfd_vms_output_end (abfd
);